48
48
49
49
import com .termux .R ;
50
50
import com .termux .app .TermuxConstants .TERMUX_APP .TERMUX_ACTIVITY ;
51
+ import com .termux .app .settings .preferences .TermuxSharedPreferences ;
51
52
import com .termux .app .terminal .BellHandler ;
52
53
import com .termux .app .terminal .TermuxViewClient ;
53
54
import com .termux .app .terminal .extrakeys .ExtraKeysView ;
@@ -119,9 +120,9 @@ public final class TermuxActivity extends Activity implements ServiceConnection
119
120
120
121
ExtraKeysView mExtraKeysView ;
121
122
122
- TermuxPreferences mSettings ;
123
+ private TermuxSharedPreferences mPreferences ;
123
124
124
- TermuxSharedProperties mProperties ;
125
+ private TermuxSharedProperties mProperties ;
125
126
126
127
/** Initialized in {@link #onServiceConnected(ComponentName, IBinder)}. */
127
128
ArrayAdapter <TerminalSession > mListViewAdapter ;
@@ -212,7 +213,7 @@ public boolean ensureStoragePermissionGranted() {
212
213
213
214
@ Override
214
215
public void onCreate (Bundle bundle ) {
215
- mSettings = new TermuxPreferences (this );
216
+ mPreferences = new TermuxSharedPreferences (this );
216
217
mProperties = new TermuxSharedProperties (this );
217
218
218
219
mIsUsingBlackUI = mProperties .isUsingBlackUI ();
@@ -246,12 +247,12 @@ public void onCreate(Bundle bundle) {
246
247
mTerminalView = findViewById (R .id .terminal_view );
247
248
mTerminalView .setOnKeyListener (new TermuxViewClient (this ));
248
249
249
- mTerminalView .setTextSize (mSettings .getFontSize ());
250
- mTerminalView .setKeepScreenOn (mSettings . isScreenAlwaysOn ());
250
+ mTerminalView .setTextSize (mPreferences .getFontSize ());
251
+ mTerminalView .setKeepScreenOn (mPreferences . getKeepScreenOn ());
251
252
mTerminalView .requestFocus ();
252
253
253
254
final ViewPager viewPager = findViewById (R .id .viewpager );
254
- if (mSettings . mShowExtraKeys ) viewPager .setVisibility (View .VISIBLE );
255
+ if (mPreferences . getShowExtraKeys () ) viewPager .setVisibility (View .VISIBLE );
255
256
256
257
257
258
ViewGroup .LayoutParams layoutParams = viewPager .getLayoutParams ();
@@ -382,7 +383,7 @@ void sendOpenedBroadcast() {
382
383
383
384
public void toggleShowExtraKeys () {
384
385
final ViewPager viewPager = findViewById (R .id .viewpager );
385
- final boolean showNow = mSettings .toggleShowExtraKeys (TermuxActivity . this );
386
+ final boolean showNow = mPreferences .toggleShowExtraKeys ();
386
387
viewPager .setVisibility (showNow ? View .VISIBLE : View .GONE );
387
388
if (showNow && viewPager .getCurrentItem () == 1 ) {
388
389
// Focus the text input view if just revealed.
@@ -636,7 +637,7 @@ protected void onStop() {
636
637
super .onStop ();
637
638
mIsVisible = false ;
638
639
TerminalSession currentSession = getCurrentTermSession ();
639
- if (currentSession != null ) TermuxPreferences . storeCurrentSession ( this , currentSession );
640
+ if (currentSession != null ) mPreferences . setCurrentSession ( currentSession . mHandle );
640
641
unregisterReceiver (mBroadcastReceiever );
641
642
getDrawer ().closeDrawers ();
642
643
}
@@ -739,7 +740,7 @@ public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuIn
739
740
menu .add (Menu .NONE , CONTEXTMENU_RESET_TERMINAL_ID , Menu .NONE , R .string .reset_terminal );
740
741
menu .add (Menu .NONE , CONTEXTMENU_KILL_PROCESS_ID , Menu .NONE , getResources ().getString (R .string .kill_process , getCurrentTermSession ().getPid ())).setEnabled (currentSession .isRunning ());
741
742
menu .add (Menu .NONE , CONTEXTMENU_STYLING_ID , Menu .NONE , R .string .style_terminal );
742
- menu .add (Menu .NONE , CONTEXTMENU_TOGGLE_KEEP_SCREEN_ON , Menu .NONE , R .string .toggle_keep_screen_on ).setCheckable (true ).setChecked (mSettings . isScreenAlwaysOn ());
743
+ menu .add (Menu .NONE , CONTEXTMENU_TOGGLE_KEEP_SCREEN_ON , Menu .NONE , R .string .toggle_keep_screen_on ).setCheckable (true ).setChecked (mPreferences . getKeepScreenOn ());
743
744
menu .add (Menu .NONE , CONTEXTMENU_HELP_ID , Menu .NONE , R .string .help );
744
745
}
745
746
@@ -950,10 +951,10 @@ public boolean onContextItemSelected(MenuItem item) {
950
951
case CONTEXTMENU_TOGGLE_KEEP_SCREEN_ON : {
951
952
if (mTerminalView .getKeepScreenOn ()) {
952
953
mTerminalView .setKeepScreenOn (false );
953
- mSettings . setScreenAlwaysOn ( this , false );
954
+ mPreferences . setKeepScreenOn ( false );
954
955
} else {
955
956
mTerminalView .setKeepScreenOn (true );
956
- mSettings . setScreenAlwaysOn ( this , true );
957
+ mPreferences . setKeepScreenOn ( true );
957
958
}
958
959
return true ;
959
960
}
@@ -978,8 +979,8 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
978
979
}
979
980
980
981
public void changeFontSize (boolean increase ) {
981
- mSettings .changeFontSize (this , increase );
982
- mTerminalView .setTextSize (mSettings .getFontSize ());
982
+ mPreferences .changeFontSize (this , increase );
983
+ mTerminalView .setTextSize (mPreferences .getFontSize ());
983
984
}
984
985
985
986
public void doPaste () {
@@ -995,12 +996,21 @@ public void doPaste() {
995
996
996
997
/** The current session as stored or the last one if that does not exist. */
997
998
public TerminalSession getStoredCurrentSessionOrLast () {
998
- TerminalSession stored = TermuxPreferences . getCurrentSession (this );
999
+ TerminalSession stored = getCurrentSession (this );
999
1000
if (stored != null ) return stored ;
1000
1001
List <TerminalSession > sessions = mTermService .getSessions ();
1001
1002
return sessions .isEmpty () ? null : sessions .get (sessions .size () - 1 );
1002
1003
}
1003
1004
1005
+ private TerminalSession getCurrentSession (TermuxActivity context ) {
1006
+ String sessionHandle = mPreferences .getCurrentSession ();
1007
+ for (int i = 0 , len = context .getTermService ().getSessions ().size (); i < len ; i ++) {
1008
+ TerminalSession session = context .getTermService ().getSessions ().get (i );
1009
+ if (session .mHandle .equals (sessionHandle )) return session ;
1010
+ }
1011
+ return null ;
1012
+ }
1013
+
1004
1014
/** Show a toast and dismiss the last one if still visible. */
1005
1015
void showToast (String text , boolean longDuration ) {
1006
1016
if (mLastToast != null ) mLastToast .cancel ();
0 commit comments