Implemented card swiping with volume buttons mechanism

This commit is contained in:
Filip Rzuhovský
2024-10-06 15:40:15 +02:00
committed by Sylvia van Os
parent d472948201
commit 09dc0e4c15
4 changed files with 34 additions and 1 deletions

View File

@@ -19,6 +19,7 @@ import android.text.method.DigitsKeyListener;
import android.text.style.ForegroundColorSpan;
import android.text.util.Linkify;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@@ -104,6 +105,22 @@ public class LoyaltyCardViewActivity extends CatimaAppCompatActivity implements
final private TaskHandler mTasks = new TaskHandler();
Runnable barcodeImageGenerationFinishedCallback;
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (settings.useVolumeKeysForNavigation()) {
if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
// Navigate to the previous card
prevNextCard(false);
return true;
} else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
// Navigate to the next card
prevNextCard(true);
return true;
}
}
return super.onKeyDown(keyCode, event);
}
public void onMainImageTap() {
// If we're in fullscreen, leave fullscreen
if (isFullscreen) {

View File

@@ -91,4 +91,8 @@ public class Settings {
public String getColor() {
return getString(R.string.setting_key_theme_color, mContext.getResources().getString(R.string.settings_key_system_theme));
}
public boolean useVolumeKeysForNavigation() {
return getBoolean(R.string.settings_key_use_volume_keys_navigation, false);
}
}

View File

@@ -121,6 +121,9 @@
<string name="settings_key_disable_lockscreen_while_viewing_card" translatable="false">pref_disable_lockscreen_while_viewing_card</string>
<string name="settings_key_allow_content_provider_read" translatable="false">pref_allow_content_provider_read</string>
<string name="settings_key_oled_dark" translatable="false">pref_oled_dark</string>
<string name="settings_use_volume_keys_navigation">Use volume keys to switch visible card</string>
<string name="settings_use_volume_keys_navigation_summary">Use the volume up/down buttons to navigate between saved cards.</string>
<string name="settings_key_use_volume_keys_navigation" translatable="false">pref_use_volume_keys_navigation</string>
<string name="sharedpreference_active_tab" translatable="false">sharedpreference_active_tab</string>
<string name="sharedpreference_sort" translatable="false">sharedpreference_sort</string>
<string name="sharedpreference_sort_order" translatable="false">sharedpreference_sort_order</string>

View File

@@ -50,6 +50,15 @@
android:title="@string/settings_category_title_cards"
app:iconSpaceReserved="false">
<SwitchPreferenceCompat
android:widgetLayout="@layout/preference_material_switch"
android:defaultValue="false"
android:key="@string/settings_key_use_volume_keys_navigation"
android:summary="@string/settings_use_volume_keys_navigation_summary"
android:title="@string/settings_use_volume_keys_navigation"
app:iconSpaceReserved="false"
app:singleLineTitle="false" />
<SwitchPreferenceCompat
android:widgetLayout="@layout/preference_material_switch"
android:defaultValue="true"
@@ -102,5 +111,5 @@
app:singleLineTitle="false" />
</PreferenceCategory>
</PreferenceScreen>
</PreferenceScreen>