mirror of
https://github.com/xdsopl/robot36.git
synced 2025-12-06 07:12:07 +01:00
reduce frequency plot height when in portrait mode
This commit is contained in:
parent
774bcf9f18
commit
9b32ac8924
|
|
@ -68,9 +68,10 @@ public class MainActivity extends AppCompatActivity {
|
||||||
@Override
|
@Override
|
||||||
public void onPeriodicNotification(AudioRecord audioRecord) {
|
public void onPeriodicNotification(AudioRecord audioRecord) {
|
||||||
audioRecord.read(recordBuffer, 0, recordBuffer.length, AudioRecord.READ_BLOCKING);
|
audioRecord.read(recordBuffer, 0, recordBuffer.length, AudioRecord.READ_BLOCKING);
|
||||||
if (decoder.process(recordBuffer, recordChannel)) {
|
boolean newLines = decoder.process(recordBuffer, recordChannel);
|
||||||
|
processFreqPlot();
|
||||||
|
if (newLines) {
|
||||||
processScope();
|
processScope();
|
||||||
processFreqPlot();
|
|
||||||
setStatus(decoder.lastMode.getName());
|
setStatus(decoder.lastMode.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -296,21 +297,15 @@ public class MainActivity extends AppCompatActivity {
|
||||||
audioSource = state.getInt("audioSource", defaultAudioSource);
|
audioSource = state.getInt("audioSource", defaultAudioSource);
|
||||||
}
|
}
|
||||||
super.onCreate(state);
|
super.onCreate(state);
|
||||||
|
Configuration config = getResources().getConfiguration();
|
||||||
EdgeToEdge.enable(this);
|
EdgeToEdge.enable(this);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(config.orientation == Configuration.ORIENTATION_LANDSCAPE ? R.layout.activity_main_land : R.layout.activity_main);
|
||||||
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
|
handleInsets();
|
||||||
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
|
|
||||||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
|
|
||||||
return insets;
|
|
||||||
});
|
|
||||||
tint = getColor(R.color.tint);
|
tint = getColor(R.color.tint);
|
||||||
scopeView = findViewById(R.id.scope);
|
|
||||||
scopeBuffer = new PixelBuffer(640, 2 * 1280);
|
scopeBuffer = new PixelBuffer(640, 2 * 1280);
|
||||||
createScope(getResources().getConfiguration());
|
createScope(config);
|
||||||
freqPlotView = findViewById(R.id.freq_plot);
|
|
||||||
freqPlotBuffer = new PixelBuffer(640, 2 * 640);
|
freqPlotBuffer = new PixelBuffer(640, 2 * 640);
|
||||||
freqPlotBitmap = Bitmap.createBitmap(freqPlotBuffer.width, freqPlotBuffer.height / 2, Bitmap.Config.ARGB_8888);
|
createFreqPlot(config);
|
||||||
freqPlotView.setImageBitmap(freqPlotBitmap);
|
|
||||||
List<String> permissions = new ArrayList<>();
|
List<String> permissions = new ArrayList<>();
|
||||||
if (ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
|
if (ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
|
||||||
permissions.add(Manifest.permission.RECORD_AUDIO);
|
permissions.add(Manifest.permission.RECORD_AUDIO);
|
||||||
|
|
@ -322,6 +317,14 @@ public class MainActivity extends AppCompatActivity {
|
||||||
ActivityCompat.requestPermissions(this, permissions.toArray(new String[0]), permissionID);
|
ActivityCompat.requestPermissions(this, permissions.toArray(new String[0]), permissionID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void handleInsets() {
|
||||||
|
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
|
||||||
|
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
|
||||||
|
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
|
||||||
|
return insets;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
getMenuInflater().inflate(R.menu.menu_main, menu);
|
getMenuInflater().inflate(R.menu.menu_main, menu);
|
||||||
|
|
@ -423,13 +426,30 @@ public class MainActivity extends AppCompatActivity {
|
||||||
int stride = scopeBuffer.width;
|
int stride = scopeBuffer.width;
|
||||||
int offset = stride * (scopeBuffer.line + scopeBuffer.height / 2 - height);
|
int offset = stride * (scopeBuffer.line + scopeBuffer.height / 2 - height);
|
||||||
scopeBitmap.setPixels(scopeBuffer.pixels, offset, stride, 0, 0, width, height);
|
scopeBitmap.setPixels(scopeBuffer.pixels, offset, stride, 0, 0, width, height);
|
||||||
|
scopeView = findViewById(R.id.scope);
|
||||||
scopeView.setImageBitmap(scopeBitmap);
|
scopeView.setImageBitmap(scopeBitmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void createFreqPlot(Configuration config) {
|
||||||
|
int width = freqPlotBuffer.width;
|
||||||
|
int height = freqPlotBuffer.height / 2;
|
||||||
|
if (config.orientation != Configuration.ORIENTATION_LANDSCAPE)
|
||||||
|
height /= 4;
|
||||||
|
freqPlotBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||||
|
int stride = freqPlotBuffer.width;
|
||||||
|
int offset = stride * (freqPlotBuffer.line + freqPlotBuffer.height / 2 - height);
|
||||||
|
freqPlotBitmap.setPixels(freqPlotBuffer.pixels, offset, stride, 0, 0, width, height);
|
||||||
|
freqPlotView = findViewById(R.id.freq_plot);
|
||||||
|
freqPlotView.setImageBitmap(freqPlotBitmap);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConfigurationChanged(@NonNull Configuration config) {
|
public void onConfigurationChanged(@NonNull Configuration config) {
|
||||||
super.onConfigurationChanged(config);
|
super.onConfigurationChanged(config);
|
||||||
|
setContentView(config.orientation == Configuration.ORIENTATION_LANDSCAPE ? R.layout.activity_main_land : R.layout.activity_main);
|
||||||
|
handleInsets();
|
||||||
createScope(config);
|
createScope(config);
|
||||||
|
createFreqPlot(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showTextPage(String title, String message) {
|
private void showTextPage(String title, String message) {
|
||||||
|
|
|
||||||
|
|
@ -13,18 +13,18 @@
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
android:contentDescription="@string/scope_description"
|
android:contentDescription="@string/scope_description"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toTopOf="@+id/freq_plot"
|
||||||
app:layout_constraintEnd_toStartOf="@+id/freq_plot"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/freq_plot"
|
android:id="@+id/freq_plot"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="0dp"
|
android:layout_height="wrap_content"
|
||||||
android:contentDescription="@string/freq_plot_description"
|
android:contentDescription="@string/freq_plot_description"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toEndOf="@+id/scope"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toBottomOf="@+id/scope" />
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
30
app/src/main/res/layout/activity_main_land.xml
Normal file
30
app/src/main/res/layout/activity_main_land.xml
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/main"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:keepScreenOn="true"
|
||||||
|
tools:context=".MainActivity">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/scope"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:contentDescription="@string/scope_description"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toStartOf="@+id/freq_plot"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/freq_plot"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:contentDescription="@string/freq_plot_description"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toEndOf="@+id/scope"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
Loading…
Reference in a new issue