Skip to content

Commit

Permalink
Making ListPreferences show their value in summary natively.
Browse files Browse the repository at this point in the history
  • Loading branch information
twaik committed Jul 4, 2024
1 parent 1e8c824 commit 9e422b7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
6 changes: 0 additions & 6 deletions app/src/main/java/com/termux/x11/LoriePreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -264,18 +264,12 @@ void updatePreferencesLayout() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P)
findPreference("hideCutout").setVisible(false);

findPreference("displayResolutionMode").setSummary(prefs.displayResolutionMode.get());
findPreference("displayResolutionExact").setSummary(prefs.displayResolutionExact.get());
findPreference("displayResolutionCustom").setSummary(prefs.displayResolutionCustom.get());
boolean displayStretchEnabled = "exact".contentEquals(prefs.displayResolutionMode.get()) || "custom".contentEquals(prefs.displayResolutionMode.get());
findPreference("displayStretch").setEnabled(displayStretchEnabled);
findPreference("displayStretch").setSummary(displayStretchEnabled ? "" : "Requires \"display resolution mode\" to be \"exact\" or \"custom\"");
findPreference("adjustResolution").setEnabled(displayStretchEnabled);
findPreference("adjustResolution").setSummary(displayStretchEnabled ? "" : "Requires \"display resolution mode\" to be \"exact\" or \"custom\"");

int modeValue = Integer.parseInt(prefs.touchMode.get()) - 1;
String mode = getResources().getStringArray(R.array.touchscreenInputModesEntries)[modeValue];
findPreference("touchMode").setSummary(mode);
boolean scaleTouchpadEnabled = "1".equals(prefs.touchMode.get()) && !"native".equals(prefs.displayResolutionMode.get());
findPreference("scaleTouchpad").setEnabled(scaleTouchpadEnabled);
findPreference("scaleTouchpad").setSummary(scaleTouchpadEnabled ? "" : "Requires \"Touchscreen input mode\" to be \"Trackpad\" and \"Display resolution mode\" to be not \"native\"");
Expand Down
18 changes: 15 additions & 3 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
<PreferenceScreen xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceCategory android:key="output" android:title="Output" android:singleLineTitle="false" android:iconSpaceReserved="false" >
<ListPreference
android:title="Display resolution mode"
android:key="displayResolutionMode"
android:summary="%s"
android:defaultValue="native"
android:entries="@array/displayResolutionVariants"
android:entryValues="@array/displayResolutionVariants" />
Expand All @@ -18,15 +20,17 @@
<ListPreference
android:title="Display resolution"
android:key="displayResolutionExact"
android:summary="%s"
android:defaultValue="1280x1024"
android:entries="@array/displayResolution"
android:entryValues="@array/displayResolution" />
android:entryValues="@array/displayResolution"
tools:ignore="DuplicateSpeakableTextCheck" />

<EditTextPreference
android:title="Display resolution"
android:key="displayResolutionCustom"
android:defaultValue="1280x1024"
android:summary="Example: 1280x1024" />
app:useSimpleSummaryProvider="true" />

<SwitchPreferenceCompat
android:title="Adjust the set resolution to fit screen orientation"
Expand Down Expand Up @@ -60,6 +64,7 @@
android:title="Force screen orientation"
android:key="forceOrientation"
android:defaultValue="no"
android:summary="%s"
android:entries="@array/forceOrientationVariants"
android:entryValues="@array/forceOrientationVariants" />

Expand All @@ -77,6 +82,7 @@
<ListPreference
android:title="Touchscreen input mode"
android:key="touchMode"
android:summary="%s"
android:defaultValue="1"
android:entries="@array/touchscreenInputModesEntries"
android:entryValues="@array/touchscreenInputModesValues" />
Expand Down Expand Up @@ -119,6 +125,7 @@
<ListPreference
android:title="Transform captured pointer movements"
android:key="transformCapturedPointer"
android:summary="%s"
android:defaultValue="no"
android:entries="@array/transformCapturedPointerEntries"
android:entryValues="@array/transformCapturedPointerValues" />
Expand Down Expand Up @@ -251,34 +258,39 @@
<ListPreference
android:title="Three finger swipe up"
android:key="swipeUpAction"
android:summary="%s"
android:defaultValue="no action"
android:entries="@array/userActionsValues"
android:entryValues="@array/userActionsValues" />

<ListPreference
android:title="Three finger swipe down"
android:key="swipeDownAction"
android:summary="%s"
android:defaultValue="toggle additional key bar"
android:entries="@array/userActionsValues"
android:entryValues="@array/userActionsValues" />

<ListPreference
android:title="Volume up"
android:key="volumeUpAction"
android:summary="%s"
android:defaultValue="no action"
android:entries="@array/userActionsVolumeUpValues"
android:entryValues="@array/userActionsVolumeUpValues" />

<ListPreference
android:title="Volume down"
android:key="volumeDownAction"
android:summary="%s"
android:defaultValue="no action"
android:entries="@array/userActionsVolumeDownValues"
android:entryValues="@array/userActionsVolumeDownValues" />

<ListPreference
android:title="Back button"
android:key="backButtonAction"
android:summary="%s"
android:defaultValue="toggle soft keyboard"
android:entries="@array/userActionsValues"
android:entryValues="@array/userActionsValues" />
Expand Down

0 comments on commit 9e422b7

Please sign in to comment.