From de4f334e24a0676aa21d577f229dfaa4f595f9a0 Mon Sep 17 00:00:00 2001 From: Fredrik Fornwall Date: Thu, 7 Dec 2017 01:46:16 +0100 Subject: [PATCH] Remove the fullscreen setting Trying to use fullscreen doesn't work well in a multi-windowed world and makes using translucent navigation and status bars more complicated. --- .../java/com/termux/app/FullScreenHelper.java | 67 ------------------- .../java/com/termux/app/TermuxActivity.java | 24 ++----- .../com/termux/app/TermuxPreferences.java | 12 ---- .../java/com/termux/app/TermuxViewClient.java | 2 - app/src/main/res/layout/drawer_layout.xml | 3 +- app/src/main/res/values/strings.xml | 1 - app/src/main/res/values/styles.xml | 3 + 7 files changed, 10 insertions(+), 102 deletions(-) delete mode 100644 app/src/main/java/com/termux/app/FullScreenHelper.java diff --git a/app/src/main/java/com/termux/app/FullScreenHelper.java b/app/src/main/java/com/termux/app/FullScreenHelper.java deleted file mode 100644 index 606b07f16d..0000000000 --- a/app/src/main/java/com/termux/app/FullScreenHelper.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.termux.app; - -import android.graphics.Color; -import android.graphics.drawable.ColorDrawable; -import android.os.Build; -import android.view.View; - -import com.termux.R; - -/** - * Utility to manage full screen immersive mode. - *

- * See https://code.google.com/p/android/issues/detail?id=5497 - */ -final class FullScreenHelper { - - private boolean mEnabled = false; - final TermuxActivity mActivity; - - public FullScreenHelper(TermuxActivity activity) { - this.mActivity = activity; - } - - public void setImmersive(boolean enabled) { - if (enabled == mEnabled) return; - mEnabled = enabled; - - View decorView = mActivity.getWindow().getDecorView(); - - if (enabled) { - decorView.setOnSystemUiVisibilityChangeListener - (new View.OnSystemUiVisibilityChangeListener() { - @Override - public void onSystemUiVisibilityChange(int visibility) { - if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) { - if (mActivity.mSettings.isShowExtraKeys()) { - mActivity.findViewById(R.id.viewpager).setVisibility(View.VISIBLE); - } - setImmersiveMode(); - } else { - mActivity.findViewById(R.id.viewpager).setVisibility(View.GONE); - } - } - }); - setImmersiveMode(); - } else { - decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); - decorView.setOnSystemUiVisibilityChangeListener(null); - } - } - - private static boolean isColorLight(int color) { - double darkness = 1 - (0.299 * Color.red(color) + 0.587 * Color.green(color) + 0.114 * Color.blue(color)) / 255; - return darkness < 0.5; - } - - void setImmersiveMode() { - int flags = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION - | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY - | View.SYSTEM_UI_FLAG_FULLSCREEN; - int color = ((ColorDrawable) mActivity.getWindow().getDecorView().getBackground()).getColor(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isColorLight(color)) - flags |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; - mActivity.getWindow().getDecorView().setSystemUiVisibility(flags); - } - -} diff --git a/app/src/main/java/com/termux/app/TermuxActivity.java b/app/src/main/java/com/termux/app/TermuxActivity.java index 5eafeba847..d50ab4304e 100644 --- a/app/src/main/java/com/termux/app/TermuxActivity.java +++ b/app/src/main/java/com/termux/app/TermuxActivity.java @@ -73,6 +73,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.LinkedHashSet; +import java.util.List; import java.util.Properties; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -95,7 +96,6 @@ public final class TermuxActivity extends Activity implements ServiceConnection private static final int CONTEXTMENU_KILL_PROCESS_ID = 4; private static final int CONTEXTMENU_RESET_TERMINAL_ID = 5; private static final int CONTEXTMENU_STYLING_ID = 6; - private static final int CONTEXTMENU_TOGGLE_FULLSCREEN_ID = 7; private static final int CONTEXTMENU_HELP_ID = 8; private static final int MAX_SESSIONS = 8; @@ -111,8 +111,6 @@ public final class TermuxActivity extends Activity implements ServiceConnection ExtraKeysView mExtraKeysView; - final FullScreenHelper mFullScreenHelper = new FullScreenHelper(this); - TermuxPreferences mSettings; /** @@ -215,7 +213,6 @@ public void onCreate(Bundle bundle) { mTerminalView.setOnKeyListener(new TermuxViewClient(this)); mTerminalView.setTextSize(mSettings.getFontSize()); - mFullScreenHelper.setImmersive(mSettings.isFullScreen()); mTerminalView.requestFocus(); final ViewPager viewPager = findViewById(R.id.viewpager); @@ -642,7 +639,7 @@ void noteSessionInfo() { TerminalSession session = getCurrentTermSession(); final int indexOfSession = mTermService.getSessions().indexOf(session); showToast(toToastTitle(session), false); - mListViewAdapter.notifyDataSetChanged(); + mListViewAdapter.notifyDataSetChanged(); final ListView lv = findViewById(R.id.left_drawer_list); lv.setItemChecked(indexOfSession, true); lv.smoothScrollToPosition(indexOfSession); @@ -657,7 +654,6 @@ public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuIn menu.add(Menu.NONE, CONTEXTMENU_SHARE_TRANSCRIPT_ID, Menu.NONE, R.string.select_all_and_share); menu.add(Menu.NONE, CONTEXTMENU_RESET_TERMINAL_ID, Menu.NONE, R.string.reset_terminal); menu.add(Menu.NONE, CONTEXTMENU_KILL_PROCESS_ID, Menu.NONE, getResources().getString(R.string.kill_process, getCurrentTermSession().getPid())).setEnabled(currentSession.isRunning()); - menu.add(Menu.NONE, CONTEXTMENU_TOGGLE_FULLSCREEN_ID, Menu.NONE, R.string.toggle_fullscreen).setCheckable(true).setChecked(mSettings.isFullScreen()); menu.add(Menu.NONE, CONTEXTMENU_STYLING_ID, Menu.NONE, R.string.style_terminal); menu.add(Menu.NONE, CONTEXTMENU_HELP_ID, Menu.NONE, R.string.help); } @@ -791,11 +787,8 @@ public void onClick(DialogInterface dialog, int which) { } }).setNegativeButton(android.R.string.cancel, null).show(); } - } - return true; - case CONTEXTMENU_TOGGLE_FULLSCREEN_ID: - toggleImmersive(); return true; + } case CONTEXTMENU_HELP_ID: startActivity(new Intent(this, TermuxHelpActivity.class)); return true; @@ -811,12 +804,6 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String permissi } } - void toggleImmersive() { - boolean newValue = !mSettings.isFullScreen(); - mSettings.setFullScreen(this, newValue); - mFullScreenHelper.setImmersive(newValue); - } - void changeFontSize(boolean increase) { mSettings.changeFontSize(this, increase); mTerminalView.setTextSize(mSettings.getFontSize()); @@ -835,9 +822,8 @@ void doPaste() { public TerminalSession getStoredCurrentSessionOrLast() { TerminalSession stored = TermuxPreferences.getCurrentSession(this); if (stored != null) return stored; - int numberOfSessions = mTermService.getSessions().size(); - if (numberOfSessions == 0) return null; - return mTermService.getSessions().get(numberOfSessions - 1); + List sessions = mTermService.getSessions(); + return sessions.isEmpty() ? null : sessions.get(sessions.size() - 1); } /** Show a toast and dismiss the last one if still visible. */ diff --git a/app/src/main/java/com/termux/app/TermuxPreferences.java b/app/src/main/java/com/termux/app/TermuxPreferences.java index b187cf3adb..3ab729fcb6 100644 --- a/app/src/main/java/com/termux/app/TermuxPreferences.java +++ b/app/src/main/java/com/termux/app/TermuxPreferences.java @@ -32,12 +32,10 @@ final class TermuxPreferences { private final int MIN_FONTSIZE; private static final int MAX_FONTSIZE = 256; - private static final String FULLSCREEN_KEY = "fullscreen"; private static final String SHOW_EXTRA_KEYS_KEY = "show_extra_keys"; private static final String FONTSIZE_KEY = "fontsize"; private static final String CURRENT_SESSION_KEY = "current_session"; - private boolean mFullScreen; private int mFontSize; @AsciiBellBehaviour @@ -56,7 +54,6 @@ final class TermuxPreferences { // to prevent invisible text due to zoom be mistake: MIN_FONTSIZE = (int) (4f * dipInPixels); - mFullScreen = prefs.getBoolean(FULLSCREEN_KEY, false); mShowExtraKeys = prefs.getBoolean(SHOW_EXTRA_KEYS_KEY, false); // http://www.google.com/design/spec/style/typography.html#typography-line-height @@ -72,15 +69,6 @@ final class TermuxPreferences { mFontSize = Math.max(MIN_FONTSIZE, Math.min(mFontSize, MAX_FONTSIZE)); } - boolean isFullScreen() { - return mFullScreen; - } - - void setFullScreen(Context context, boolean newValue) { - mFullScreen = newValue; - PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean(FULLSCREEN_KEY, newValue).apply(); - } - boolean isShowExtraKeys() { return mShowExtraKeys; } diff --git a/app/src/main/java/com/termux/app/TermuxViewClient.java b/app/src/main/java/com/termux/app/TermuxViewClient.java index f02451d55b..75a9673176 100644 --- a/app/src/main/java/com/termux/app/TermuxViewClient.java +++ b/app/src/main/java/com/termux/app/TermuxViewClient.java @@ -73,8 +73,6 @@ public boolean onKeyDown(int keyCode, KeyEvent e, TerminalSession currentSession mActivity.getDrawer().openDrawer(Gravity.LEFT); } else if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) { mActivity.getDrawer().closeDrawers(); - } else if (unicodeChar == 'f'/* full screen */) { - mActivity.toggleImmersive(); } else if (unicodeChar == 'k'/* keyboard */) { InputMethodManager imm = (InputMethodManager) mActivity.getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); diff --git a/app/src/main/res/layout/drawer_layout.xml b/app/src/main/res/layout/drawer_layout.xml index abb00b6fb4..a0f41cb1b2 100644 --- a/app/src/main/res/layout/drawer_layout.xml +++ b/app/src/main/res/layout/drawer_layout.xml @@ -1,7 +1,8 @@ + android:orientation="vertical" + android:fitsSystemWindows="true"> Keyboard Reset Style - Fullscreen Terminal transcript Help diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index f59aec39fb..f7c5cc3a0f 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -15,6 +15,9 @@ selecting text on pre-6.0 (non-floating toolbar). --> true + true + true + true true