Skip to content

Commit

Permalink
Implementing new preference "Force screen orientation"
Browse files Browse the repository at this point in the history
Removing preference "Force landscape orientation".
[no ci]
  • Loading branch information
twaik committed Jul 4, 2024
1 parent aa9d538 commit 1e8c824
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
18 changes: 10 additions & 8 deletions app/src/main/java/com/termux/x11/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ void onPreferencesChanged(String key) {
lorieView.reloadPreferences(prefs);

setTerminalToolbarView();
onWindowFocusChanged(true);
onWindowFocusChanged(hasWindowFocus());

lorieView.triggerCallback();

Expand All @@ -530,11 +530,6 @@ else if (checkSelfPermission(WRITE_SECURE_SETTINGS) == PERMISSION_GRANTED)
useTermuxEKBarBehaviour = prefs.useTermuxEKBarBehaviour.get();
showIMEWhileExternalConnected = prefs.showIMEWhileExternalConnected.get();

int requestedOrientation = prefs.forceLandscape.get() ?
ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE : ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
if (getRequestedOrientation() != requestedOrientation)
setRequestedOrientation(requestedOrientation);

findViewById(R.id.mouse_buttons).setVisibility(prefs.showMouseHelper.get() && "1".equals(prefs.touchMode.get()) && mClientConnected ? View.VISIBLE : View.GONE);
showMouseAuxButtons(prefs.showMouseHelper.get());
showStylusAuxButtons(prefs.showStylusClickOverride.get());
Expand Down Expand Up @@ -705,8 +700,15 @@ public void onWindowFocusChanged(boolean hasFocus) {
return;
}

int requestedOrientation = prefs.forceLandscape.get() ?
ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE : ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
int requestedOrientation;
switch (prefs.forceOrientation.get()) {
case "portrait": requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; break;
case "landscape": requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; break;
case "reverse portrait": requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; break;
case "reverse landscape": requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; break;
default: requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
}

if (getRequestedOrientation() != requestedOrientation)
setRequestedOrientation(requestedOrientation);

Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,11 @@
<item>open preferences</item>
<item>release pointer and keyboard capture</item>
</string-array>
<string-array name="forceOrientationVariants">
<item>no</item>
<item>portrait</item>
<item>landscape</item>
<item>reverse portrait</item>
<item>reverse landscape</item>
</string-array>
</resources>
10 changes: 6 additions & 4 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@
android:defaultValue="false"
android:key="fullscreen" />

<SwitchPreferenceCompat
android:title="Force landscape orientation"
android:defaultValue="false"
android:key="forceLandscape" />
<ListPreference
android:title="Force screen orientation"
android:key="forceOrientation"
android:defaultValue="no"
android:entries="@array/forceOrientationVariants"
android:entryValues="@array/forceOrientationVariants" />

<SwitchPreferenceCompat
android:title="Hide display cutout (if any)"
Expand Down

0 comments on commit 1e8c824

Please sign in to comment.