From ae48c40f8da87d31538d2a798abc8da20083912d Mon Sep 17 00:00:00 2001 From: adbenitez Date: Sun, 24 Sep 2023 22:17:36 +0200 Subject: [PATCH 1/3] improve landscape mode for webxdc --- .../securesms/WebxdcActivity.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/org/thoughtcrime/securesms/WebxdcActivity.java b/src/org/thoughtcrime/securesms/WebxdcActivity.java index 22ea131a9..5656d158a 100644 --- a/src/org/thoughtcrime/securesms/WebxdcActivity.java +++ b/src/org/thoughtcrime/securesms/WebxdcActivity.java @@ -3,6 +3,7 @@ package org.thoughtcrime.securesms; import android.app.Activity; import android.content.Context; import android.content.Intent; +import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; @@ -14,6 +15,7 @@ import android.util.Base64; import android.util.Log; import android.view.Menu; import android.view.MenuItem; +import android.view.View; import android.webkit.JavascriptInterface; import android.webkit.MimeTypeMap; import android.webkit.ValueCallback; @@ -197,6 +199,26 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE return false; } + @Override + public void onConfigurationChanged(Configuration newConfig) { + Log.i(TAG, "onConfigurationChanged(" + newConfig.orientation + ")"); + super.onConfigurationChanged(newConfig); + if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { + setFullscreen(true); + } else { + setFullscreen(false); + } + } + + private void setFullscreen(boolean enable) { + getWindow().getDecorView().setSystemUiVisibility(enable? View.SYSTEM_UI_FLAG_FULLSCREEN : 0); + if (enable) { + getSupportActionBar().hide(); + } else { + getSupportActionBar().show(); + } + } + @Override protected boolean openOnlineUrl(String url) { if (url.startsWith("mailto:")) { From 287e1d25b0f6ba3750f427ffc1c4e9acfe132fe4 Mon Sep 17 00:00:00 2001 From: adbenitez Date: Mon, 25 Sep 2023 01:20:20 +0200 Subject: [PATCH 2/3] fix bug if already in landscape mode, and improve tablet support --- res/values-land/attrs.xml | 5 +++++ res/values-sw600dp/attrs.xml | 5 +++++ res/values/attrs.xml | 2 ++ .../thoughtcrime/securesms/WebxdcActivity.java | 16 ++++++++++------ 4 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 res/values-land/attrs.xml create mode 100644 res/values-sw600dp/attrs.xml diff --git a/res/values-land/attrs.xml b/res/values-land/attrs.xml new file mode 100644 index 000000000..358acf850 --- /dev/null +++ b/res/values-land/attrs.xml @@ -0,0 +1,5 @@ + + + + true + diff --git a/res/values-sw600dp/attrs.xml b/res/values-sw600dp/attrs.xml new file mode 100644 index 000000000..57cda87ce --- /dev/null +++ b/res/values-sw600dp/attrs.xml @@ -0,0 +1,5 @@ + + + + false + diff --git a/res/values/attrs.xml b/res/values/attrs.xml index 56cd66a8f..c2ab65b84 100644 --- a/res/values/attrs.xml +++ b/res/values/attrs.xml @@ -258,4 +258,6 @@ + + false diff --git a/src/org/thoughtcrime/securesms/WebxdcActivity.java b/src/org/thoughtcrime/securesms/WebxdcActivity.java index 5656d158a..585445d5f 100644 --- a/src/org/thoughtcrime/securesms/WebxdcActivity.java +++ b/src/org/thoughtcrime/securesms/WebxdcActivity.java @@ -101,6 +101,10 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE protected void onCreate(Bundle state, boolean ready) { super.onCreate(state, ready); + // enter fullscreen mode if necessary, + // this is needed here because if the app is opened while already in landscape mode, onConfigurationChanged() is not triggered + setScreenMode(); + webView.setWebChromeClient(new WebChromeClient() { @Override @RequiresApi(21) @@ -203,14 +207,14 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE public void onConfigurationChanged(Configuration newConfig) { Log.i(TAG, "onConfigurationChanged(" + newConfig.orientation + ")"); super.onConfigurationChanged(newConfig); - if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { - setFullscreen(true); - } else { - setFullscreen(false); - } + // orientation might have changed, enter/exit fullscreen mode if needed + setScreenMode(); } - private void setFullscreen(boolean enable) { + private void setScreenMode() { + // enter/exit fullscreen mode depending on orientation (landscape/portrait), + // on tablets there is enought height so fullscreen mode is never enabled there + boolean enable = getResources().getBoolean(R.bool.webxdcFullscreen); getWindow().getDecorView().setSystemUiVisibility(enable? View.SYSTEM_UI_FLAG_FULLSCREEN : 0); if (enable) { getSupportActionBar().hide(); From b4fe0b30e73e3777352edb514e57ff734db61a7c Mon Sep 17 00:00:00 2001 From: adbenitez Date: Mon, 25 Sep 2023 13:17:55 +0200 Subject: [PATCH 3/3] use isBigScreen and isLandscape attrs --- res/values-land/attrs.xml | 3 +-- res/values-sw600dp/attrs.xml | 3 +-- res/values/attrs.xml | 5 +++-- src/org/thoughtcrime/securesms/WebxdcActivity.java | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/res/values-land/attrs.xml b/res/values-land/attrs.xml index 358acf850..833469019 100644 --- a/res/values-land/attrs.xml +++ b/res/values-land/attrs.xml @@ -1,5 +1,4 @@ - - true + true diff --git a/res/values-sw600dp/attrs.xml b/res/values-sw600dp/attrs.xml index 57cda87ce..2a56cbc7e 100644 --- a/res/values-sw600dp/attrs.xml +++ b/res/values-sw600dp/attrs.xml @@ -1,5 +1,4 @@ - - false + true diff --git a/res/values/attrs.xml b/res/values/attrs.xml index c2ab65b84..93e3cc8bd 100644 --- a/res/values/attrs.xml +++ b/res/values/attrs.xml @@ -258,6 +258,7 @@ - - false + false + + false diff --git a/src/org/thoughtcrime/securesms/WebxdcActivity.java b/src/org/thoughtcrime/securesms/WebxdcActivity.java index 585445d5f..ec52d14fc 100644 --- a/src/org/thoughtcrime/securesms/WebxdcActivity.java +++ b/src/org/thoughtcrime/securesms/WebxdcActivity.java @@ -214,7 +214,7 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE private void setScreenMode() { // enter/exit fullscreen mode depending on orientation (landscape/portrait), // on tablets there is enought height so fullscreen mode is never enabled there - boolean enable = getResources().getBoolean(R.bool.webxdcFullscreen); + boolean enable = getResources().getBoolean(R.bool.isLandscape) && !getResources().getBoolean(R.bool.isBigScreen); getWindow().getDecorView().setSystemUiVisibility(enable? View.SYSTEM_UI_FLAG_FULLSCREEN : 0); if (enable) { getSupportActionBar().hide();