added toggle to switch between auto and forced current mode

This commit is contained in:
Ahmet Inan 2024-05-07 08:52:35 +02:00
parent 74389205ea
commit 1de7e40330
5 changed files with 56 additions and 14 deletions

View file

@ -437,23 +437,28 @@ public class Decoder {
}
public void forceMode(String name) {
lockMode = true;
if (rawMode.getName().equals(name)) {
lockMode = true;
imageBuffer.line = -1;
currentMode = rawMode;
return;
}
Mode mode = findMode(syncPulse5msModes, name);
if (mode == null)
mode = findMode(syncPulse9msModes, name);
if (mode == null)
mode = findMode(syncPulse20msModes, name);
if (mode == currentMode)
if (mode == currentMode) {
lockMode = true;
return;
imageBuffer.line = -1;
if (mode == null)
mode = rawMode;
else
}
if (mode != null) {
lockMode = true;
imageBuffer.line = -1;
currentMode = mode;
currentScanLineSamples = mode.getScanLineSamples();
currentMode = mode;
}
public void autoMode() {
return;
}
lockMode = false;
}
}

View file

@ -69,6 +69,7 @@ public class MainActivity extends AppCompatActivity {
private AudioRecord audioRecord;
private Decoder decoder;
private Menu menu;
private String forceMode;
private int recordRate;
private int recordChannel;
private int audioSource;
@ -84,13 +85,24 @@ public class MainActivity extends AppCompatActivity {
}
private void forceMode(int id) {
menu.findItem(R.id.action_auto_mode).setIcon(R.drawable.baseline_lock_24);
forceMode = getString(id);
if (decoder != null)
decoder.forceMode(getString(id));
decoder.forceMode(forceMode);
}
private void autoMode() {
int icon;
if (decoder == null || forceMode != null && !forceMode.equals(getString(R.string.auto_mode))) {
icon = R.drawable.baseline_auto_mode_24;
forceMode = getString(R.string.auto_mode);
} else {
icon = R.drawable.baseline_lock_24;
forceMode = decoder.currentMode.getName();
}
menu.findItem(R.id.action_auto_mode).setIcon(icon);
if (decoder != null)
decoder.autoMode();
decoder.forceMode(forceMode);
}
private final AudioRecord.OnRecordPositionUpdateListener recordListener = new AudioRecord.OnRecordPositionUpdateListener() {
@ -197,8 +209,10 @@ public class MainActivity extends AppCompatActivity {
if (audioRecord.getState() == AudioRecord.STATE_INITIALIZED) {
audioRecord.setRecordPositionUpdateListener(recordListener);
audioRecord.setPositionNotificationPeriod(frameCount);
if (rateChanged)
if (rateChanged) {
decoder = new Decoder(scopeBuffer, imageBuffer, recordRate);
decoder.forceMode(forceMode);
}
startListening();
} else {
setStatus(R.string.audio_init_failed);

View file

@ -0,0 +1,15 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
<path android:fillColor="@android:color/white" android:pathData="M19.03,3.56c-1.67,-1.39 -3.74,-2.3 -6.03,-2.51v2.01c1.73,0.19 3.31,0.88 4.61,1.92L19.03,3.56z"/>
<path android:fillColor="@android:color/white" android:pathData="M11,3.06V1.05C8.71,1.25 6.64,2.17 4.97,3.56l1.42,1.42C7.69,3.94 9.27,3.25 11,3.06z"/>
<path android:fillColor="@android:color/white" android:pathData="M4.98,6.39L3.56,4.97C2.17,6.64 1.26,8.71 1.05,11h2.01C3.25,9.27 3.94,7.69 4.98,6.39z"/>
<path android:fillColor="@android:color/white" android:pathData="M20.94,11h2.01c-0.21,-2.29 -1.12,-4.36 -2.51,-6.03l-1.42,1.42C20.06,7.69 20.75,9.27 20.94,11z"/>
<path android:fillColor="@android:color/white" android:pathData="M7,12l3.44,1.56l1.56,3.44l1.56,-3.44l3.44,-1.56l-3.44,-1.56l-1.56,-3.44l-1.56,3.44z"/>
<path android:fillColor="@android:color/white" android:pathData="M12,21c-3.11,0 -5.85,-1.59 -7.46,-4H7v-2H1v6h2v-2.7c1.99,2.84 5.27,4.7 9,4.7c4.87,0 9,-3.17 10.44,-7.56l-1.96,-0.45C19.25,18.48 15.92,21 12,21z"/>
</vector>

View file

@ -0,0 +1,5 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
<path android:fillColor="@android:color/white" android:pathData="M18,8h-1L17,6c0,-2.76 -2.24,-5 -5,-5S7,3.24 7,6v2L6,8c-1.1,0 -2,0.9 -2,2v10c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2L20,10c0,-1.1 -0.9,-2 -2,-2zM12,17c-1.1,0 -2,-0.9 -2,-2s0.9,-2 2,-2 2,0.9 2,2 -0.9,2 -2,2zM15.1,8L8.9,8L8.9,6c0,-1.71 1.39,-3.1 3.1,-3.1 1.71,0 3.1,1.39 3.1,3.1v2z"/>
</vector>

View file

@ -17,7 +17,10 @@
app:showAsAction="always" />
<item
android:id="@+id/action_auto_mode"
android:title="@string/auto_mode" />
android:icon="@drawable/baseline_auto_mode_24"
android:title="@string/auto_mode"
app:iconTint="@color/tint"
app:showAsAction="always"/>
<item android:title="@string/force_mode">
<menu>
<item