feature: allow to keep screen on

This commit is contained in:
Leonid Plyushch 2019-01-15 15:51:41 +02:00 committed by Fredrik Fornwall
parent b38ae24908
commit 743225ab6a
3 changed files with 26 additions and 0 deletions

View File

@ -90,6 +90,7 @@ public final class TermuxActivity extends Activity implements ServiceConnection
private static final int CONTEXTMENU_RESET_TERMINAL_ID = 5;
private static final int CONTEXTMENU_STYLING_ID = 6;
private static final int CONTEXTMENU_HELP_ID = 8;
private static final int CONTEXTMENU_TOGGLE_KEEP_SCREEN_ON = 9;
private static final int MAX_SESSIONS = 8;
@ -210,6 +211,7 @@ public final class TermuxActivity extends Activity implements ServiceConnection
mTerminalView.setOnKeyListener(new TermuxViewClient(this));
mTerminalView.setTextSize(mSettings.getFontSize());
mTerminalView.setKeepScreenOn(mSettings.isScreenAlwaysOn());
mTerminalView.requestFocus();
final ViewPager viewPager = findViewById(R.id.viewpager);
@ -637,6 +639,7 @@ public final class TermuxActivity extends Activity implements ServiceConnection
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_STYLING_ID, Menu.NONE, R.string.style_terminal);
menu.add(Menu.NONE, CONTEXTMENU_HELP_ID, Menu.NONE, R.string.help);
menu.add(Menu.NONE, CONTEXTMENU_TOGGLE_KEEP_SCREEN_ON, Menu.NONE, R.string.toggle_keep_screen_on).setCheckable(true).setChecked(mSettings.isScreenAlwaysOn());
}
/** Hook system menu to show context menu instead. */
@ -756,6 +759,16 @@ public final class TermuxActivity extends Activity implements ServiceConnection
case CONTEXTMENU_HELP_ID:
startActivity(new Intent(this, TermuxHelpActivity.class));
return true;
case CONTEXTMENU_TOGGLE_KEEP_SCREEN_ON: {
if(mTerminalView.getKeepScreenOn()) {
mTerminalView.setKeepScreenOn(false);
mSettings.setScreenAlwaysOn(this, false);
} else {
mTerminalView.setKeepScreenOn(true);
mSettings.setScreenAlwaysOn(this, true);
}
return true;
}
default:
return super.onContextItemSelected(item);
}

View File

@ -40,7 +40,9 @@ final class TermuxPreferences {
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 static final String SCREEN_ALWAYS_ON_KEY = "screen_always_on";
private boolean mScreenAlwaysOn;
private int mFontSize;
@AsciiBellBehaviour
@ -67,6 +69,7 @@ final class TermuxPreferences {
MIN_FONTSIZE = (int) (4f * dipInPixels);
mShowExtraKeys = prefs.getBoolean(SHOW_EXTRA_KEYS_KEY, true);
mScreenAlwaysOn = prefs.getBoolean(SCREEN_ALWAYS_ON_KEY, false);
// http://www.google.com/design/spec/style/typography.html#typography-line-height
int defaultFontSize = Math.round(12 * dipInPixels);
@ -103,6 +106,15 @@ final class TermuxPreferences {
prefs.edit().putString(FONTSIZE_KEY, Integer.toString(mFontSize)).apply();
}
boolean isScreenAlwaysOn() {
return mScreenAlwaysOn;
}
void setScreenAlwaysOn(Context context, boolean newValue) {
mScreenAlwaysOn = newValue;
PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean(SCREEN_ALWAYS_ON_KEY, newValue).apply();
}
static void storeCurrentSession(Context context, TerminalSession session) {
PreferenceManager.getDefaultSharedPreferences(context).edit().putString(TermuxPreferences.CURRENT_SESSION_KEY, session.mHandle).apply();
}

View File

@ -9,6 +9,7 @@
<string name="style_terminal">Style</string>
<string name="share_transcript_title">Terminal transcript</string>
<string name="help">Help</string>
<string name="toggle_keep_screen_on">Keep screen on</string>
<string name="bootstrap_installer_body">Installing…</string>
<string name="bootstrap_error_title">Unable to install</string>