|
1 | 1 | package com.termux.app; |
2 | 2 |
|
3 | 3 | import android.annotation.SuppressLint; |
4 | | -import android.app.Activity; |
5 | 4 | import android.app.AlertDialog; |
6 | 5 | import android.content.ActivityNotFoundException; |
7 | 6 | import android.content.BroadcastReceiver; |
|
10 | 9 | import android.content.Intent; |
11 | 10 | import android.content.IntentFilter; |
12 | 11 | import android.content.ServiceConnection; |
13 | | -import android.graphics.Color; |
14 | 12 | import android.net.Uri; |
15 | 13 | import android.os.Build; |
16 | 14 | import android.os.Bundle; |
|
34 | 32 | import com.termux.app.terminal.TermuxActivityRootView; |
35 | 33 | import com.termux.shared.activities.ReportActivity; |
36 | 34 | import com.termux.shared.activity.ActivityUtils; |
| 35 | +import com.termux.shared.activity.media.AppCompatActivityUtils; |
37 | 36 | import com.termux.shared.data.IntentUtils; |
38 | 37 | import com.termux.shared.android.PermissionUtils; |
39 | 38 | import com.termux.shared.termux.TermuxConstants; |
|
52 | 51 | import com.termux.shared.termux.TermuxUtils; |
53 | 52 | import com.termux.shared.termux.theme.TermuxThemeUtils; |
54 | 53 | import com.termux.shared.theme.NightMode; |
55 | | -import com.termux.shared.theme.ThemeUtils; |
56 | 54 | import com.termux.shared.view.ViewUtils; |
57 | 55 | import com.termux.terminal.TerminalSession; |
58 | 56 | import com.termux.terminal.TerminalSessionClient; |
|
62 | 60 |
|
63 | 61 | import androidx.annotation.NonNull; |
64 | 62 | import androidx.annotation.Nullable; |
65 | | -import androidx.core.content.ContextCompat; |
| 63 | +import androidx.appcompat.app.AppCompatActivity; |
66 | 64 | import androidx.drawerlayout.widget.DrawerLayout; |
67 | 65 | import androidx.viewpager.widget.ViewPager; |
68 | 66 |
|
|
78 | 76 | * </ul> |
79 | 77 | * about memory leaks. |
80 | 78 | */ |
81 | | -public final class TermuxActivity extends Activity implements ServiceConnection { |
| 79 | +public final class TermuxActivity extends AppCompatActivity implements ServiceConnection { |
82 | 80 |
|
83 | 81 | /** |
84 | 82 | * The connection to the {@link TermuxService}. Requested in {@link #onCreate(Bundle)} with a call to |
@@ -228,8 +226,6 @@ public void onCreate(Bundle savedInstanceState) { |
228 | 226 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); |
229 | 227 | } |
230 | 228 |
|
231 | | - setDrawerTheme(); |
232 | | - |
233 | 229 | setTermuxTerminalViewAndClients(); |
234 | 230 |
|
235 | 231 | setTerminalToolbarView(savedInstanceState); |
@@ -340,6 +336,8 @@ public void onDestroy() { |
340 | 336 |
|
341 | 337 | @Override |
342 | 338 | public void onSaveInstanceState(@NonNull Bundle savedInstanceState) { |
| 339 | + Logger.logVerbose(LOG_TAG, "onSaveInstanceState"); |
| 340 | + |
343 | 341 | super.onSaveInstanceState(savedInstanceState); |
344 | 342 | saveTerminalToolbarTextInput(savedInstanceState); |
345 | 343 | } |
@@ -413,19 +411,10 @@ private void setActivityTheme() { |
413 | 411 | // Update NightMode.APP_NIGHT_MODE |
414 | 412 | TermuxThemeUtils.setAppNightMode(mProperties.getNightMode()); |
415 | 413 |
|
416 | | - if (ThemeUtils.shouldEnableDarkTheme(this, NightMode.getAppNightMode().getName())) { |
417 | | - this.setTheme(R.style.Theme_Termux_Black); |
418 | | - } else { |
419 | | - this.setTheme(R.style.Theme_Termux); |
420 | | - } |
421 | | - } |
422 | | - |
423 | | - private void setDrawerTheme() { |
424 | | - if (ThemeUtils.shouldEnableDarkTheme(this, NightMode.getAppNightMode().getName())) { |
425 | | - findViewById(R.id.left_drawer).setBackgroundColor(ContextCompat.getColor(this, |
426 | | - android.R.color.background_dark)); |
427 | | - ((ImageButton) findViewById(R.id.settings_button)).setColorFilter(Color.WHITE); |
428 | | - } |
| 414 | + // Set activity night mode. If NightMode.SYSTEM is set, then android will automatically |
| 415 | + // trigger recreation of activity when uiMode/dark mode configuration is changed so that |
| 416 | + // day or night theme takes affect. |
| 417 | + AppCompatActivityUtils.setNightMode(this, NightMode.getAppNightMode().getName(), true); |
429 | 418 | } |
430 | 419 |
|
431 | 420 | private void setMargins() { |
@@ -518,7 +507,7 @@ public void toggleTerminalToolbar() { |
518 | 507 | private void saveTerminalToolbarTextInput(Bundle savedInstanceState) { |
519 | 508 | if (savedInstanceState == null) return; |
520 | 509 |
|
521 | | - final EditText textInputView = findViewById(R.id.terminal_toolbar_text_input); |
| 510 | + final EditText textInputView = findViewById(R.id.terminal_toolbar_text_input); |
522 | 511 | if (textInputView != null) { |
523 | 512 | String textInput = textInputView.getText().toString(); |
524 | 513 | if (!textInput.isEmpty()) savedInstanceState.putString(ARG_TERMINAL_TOOLBAR_TEXT_INPUT, textInput); |
@@ -934,12 +923,9 @@ private void reloadActivityStyling() { |
934 | 923 | mTermuxService.setTerminalTranscriptRows(); |
935 | 924 |
|
936 | 925 | // To change the activity and drawer theme, activity needs to be recreated. |
937 | | - // But this will destroy the activity, and will call the onCreate() again. |
938 | | - // We need to investigate if enabling this is wise, since all stored variables and |
939 | | - // views will be destroyed and bindService() will be called again. Extra keys input |
940 | | - // text will we restored since that has already been implemented. Terminal sessions |
941 | | - // and transcripts are also already preserved. Theme does change properly too. |
942 | | - // TermuxActivity.this.recreate(); |
| 926 | + // It will destroy the activity, including all stored variables and views, and onCreate() |
| 927 | + // will be called again. Extra keys input text, terminal sessions and transcripts will be preserved. |
| 928 | + TermuxActivity.this.recreate(); |
943 | 929 | } |
944 | 930 |
|
945 | 931 |
|
|
0 commit comments