reduce frequency plot height when in portrait mode

This commit is contained in:
Ahmet Inan 2024-04-26 13:38:33 +02:00
parent 774bcf9f18
commit 9b32ac8924
3 changed files with 68 additions and 18 deletions

View file

@ -68,9 +68,10 @@ public class MainActivity extends AppCompatActivity {
@Override
public void onPeriodicNotification(AudioRecord audioRecord) {
audioRecord.read(recordBuffer, 0, recordBuffer.length, AudioRecord.READ_BLOCKING);
if (decoder.process(recordBuffer, recordChannel)) {
processScope();
boolean newLines = decoder.process(recordBuffer, recordChannel);
processFreqPlot();
if (newLines) {
processScope();
setStatus(decoder.lastMode.getName());
}
}
@ -296,21 +297,15 @@ public class MainActivity extends AppCompatActivity {
audioSource = state.getInt("audioSource", defaultAudioSource);
}
super.onCreate(state);
Configuration config = getResources().getConfiguration();
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
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;
});
setContentView(config.orientation == Configuration.ORIENTATION_LANDSCAPE ? R.layout.activity_main_land : R.layout.activity_main);
handleInsets();
tint = getColor(R.color.tint);
scopeView = findViewById(R.id.scope);
scopeBuffer = new PixelBuffer(640, 2 * 1280);
createScope(getResources().getConfiguration());
freqPlotView = findViewById(R.id.freq_plot);
createScope(config);
freqPlotBuffer = new PixelBuffer(640, 2 * 640);
freqPlotBitmap = Bitmap.createBitmap(freqPlotBuffer.width, freqPlotBuffer.height / 2, Bitmap.Config.ARGB_8888);
freqPlotView.setImageBitmap(freqPlotBitmap);
createFreqPlot(config);
List<String> permissions = new ArrayList<>();
if (ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
permissions.add(Manifest.permission.RECORD_AUDIO);
@ -322,6 +317,14 @@ public class MainActivity extends AppCompatActivity {
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
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
@ -423,13 +426,30 @@ public class MainActivity extends AppCompatActivity {
int stride = scopeBuffer.width;
int offset = stride * (scopeBuffer.line + scopeBuffer.height / 2 - height);
scopeBitmap.setPixels(scopeBuffer.pixels, offset, stride, 0, 0, width, height);
scopeView = findViewById(R.id.scope);
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
public void onConfigurationChanged(@NonNull Configuration config) {
super.onConfigurationChanged(config);
setContentView(config.orientation == Configuration.ORIENTATION_LANDSCAPE ? R.layout.activity_main_land : R.layout.activity_main);
handleInsets();
createScope(config);
createFreqPlot(config);
}
private void showTextPage(String title, String message) {

View file

@ -13,18 +13,18 @@
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_constraintBottom_toTopOf="@+id/freq_plot"
app:layout_constraintEnd_toEndOf="parent"
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:layout_height="wrap_content"
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" />
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/scope" />
</androidx.constraintlayout.widget.ConstraintLayout>

View 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>