fix bug if already in landscape mode, and improve tablet support

This commit is contained in:
adbenitez
2023-09-25 01:20:20 +02:00
parent ae48c40f8d
commit 287e1d25b0
4 changed files with 22 additions and 6 deletions
+5
View File
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- in small devices (e.i. not tablets) in landscape height is low, better enter fullscreen -->
<bool name="webxdcFullscreen">true</bool>
</resources>
+5
View File
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- if the device is big enough (ex. a tablet), there is no need to enter fullscreen -->
<bool name="webxdcFullscreen">false</bool>
</resources>
+2
View File
@@ -258,4 +258,6 @@
<attr name="compact" format="boolean" />
</declare-styleable>
<!-- in portrait mode there is enough height, no need to enter fullscreen -->
<bool name="webxdcFullscreen">false</bool>
</resources>
@@ -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();