From 2390c2a1f0c45a3d851969ea841757830c55ac14 Mon Sep 17 00:00:00 2001 From: AbdullahFaqeir Date: Sun, 15 Sep 2024 15:48:07 +0300 Subject: [PATCH 1/4] fix(android): override user interface style --- android/titanium/res/values/values.xml | 12 ++++++- .../appcelerator/titanium/TiBaseActivity.java | 33 ++++++++++++++++--- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/android/titanium/res/values/values.xml b/android/titanium/res/values/values.xml index cb8b56ca832..f9932a4c11f 100644 --- a/android/titanium/res/values/values.xml +++ b/android/titanium/res/values/values.xml @@ -48,6 +48,7 @@ false false false + @style/WindowAnimationTransition @@ -109,6 +110,13 @@ false false false + @style/WindowAnimationTransition + + + + @@ -206,7 +214,9 @@ - diff --git a/android/titanium/src/java/org/appcelerator/titanium/TiBaseActivity.java b/android/titanium/src/java/org/appcelerator/titanium/TiBaseActivity.java index 8421b066570..0d799c32d5d 100644 --- a/android/titanium/src/java/org/appcelerator/titanium/TiBaseActivity.java +++ b/android/titanium/src/java/org/appcelerator/titanium/TiBaseActivity.java @@ -55,6 +55,7 @@ import android.content.Intent; import android.content.IntentSender; import android.content.pm.ActivityInfo; +import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.res.Configuration; import android.graphics.PixelFormat; @@ -68,7 +69,6 @@ import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; -import androidx.core.app.ActivityCompat; import android.text.Spannable; import android.text.SpannableStringBuilder; @@ -133,7 +133,7 @@ void onRequestPermissionsResult( protected int msgId = -1; //Storing the activity's dialogs and their persistence private final CopyOnWriteArrayList dialogs = new CopyOnWriteArrayList<>(); - + private static int selectedTheme = R.style.Theme_Titanium_Light; public TiWindowProxy lwWindow; public boolean isResumed = false; @@ -671,7 +671,7 @@ protected void attachBaseContext(Context newBase) protected void onCreate(Bundle savedInstanceState) { Log.d(TAG, "Activity " + this + " onCreate", Log.DEBUG_MODE); - + setTheme(selectedTheme); this.inForeground = true; this.launchIntent = getIntent(); this.safeAreaMonitor = new TiActivitySafeAreaMonitor(this); @@ -1239,7 +1239,8 @@ public void onConfigurationChanged(@NonNull Configuration newConfig) final int NIGHT_MASK = Configuration.UI_MODE_NIGHT_MASK; if ((newConfig.uiMode & NIGHT_MASK) != (this.lastUIModeFlags & NIGHT_MASK)) { this.lastNightMode = AppCompatDelegate.getDefaultNightMode(); - ActivityCompat.recreate(this); + this.setSelectedTheme(this.lastNightMode); + this.recreate(); } this.lastUIModeFlags = newConfig.uiMode; } @@ -1254,9 +1255,31 @@ protected void onNightModeChanged(int mode) public void applyNightMode() { int mode = AppCompatDelegate.getDefaultNightMode(); + this.setSelectedTheme(mode); if (this.inForeground && (mode != this.lastNightMode)) { this.lastNightMode = mode; - ActivityCompat.recreate(this); + this.recreate(); + } + } + + private void setSelectedTheme(int lastNightMode) + { + if (this.lastNightMode == AppCompatDelegate.MODE_NIGHT_YES) { + selectedTheme = R.style.Theme_Titanium_Dark; + } else { + /** + * At first,try to read the app them from the is defined by + * the user from the manifest. + */ + try { + ApplicationInfo app = getPackageManager().getApplicationInfo( + TiApplication.getInstance().getPackageName(), + PackageManager.GET_META_DATA + ); + selectedTheme = app.theme; + } catch (PackageManager.NameNotFoundException e) { + selectedTheme = R.style.Theme_Titanium_App; + } } } From e921e5241c2afa214f1fd785914091bba9cff09b Mon Sep 17 00:00:00 2001 From: AbdullahFaqeir Date: Mon, 16 Sep 2024 00:47:27 +0300 Subject: [PATCH 2/4] fix(android): retracing and assure the fix --- .../org/appcelerator/titanium/TiBaseActivity.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/android/titanium/src/java/org/appcelerator/titanium/TiBaseActivity.java b/android/titanium/src/java/org/appcelerator/titanium/TiBaseActivity.java index 0d799c32d5d..f932bd3fa9c 100644 --- a/android/titanium/src/java/org/appcelerator/titanium/TiBaseActivity.java +++ b/android/titanium/src/java/org/appcelerator/titanium/TiBaseActivity.java @@ -1240,11 +1240,21 @@ public void onConfigurationChanged(@NonNull Configuration newConfig) if ((newConfig.uiMode & NIGHT_MASK) != (this.lastUIModeFlags & NIGHT_MASK)) { this.lastNightMode = AppCompatDelegate.getDefaultNightMode(); this.setSelectedTheme(this.lastNightMode); - this.recreate(); + this.updateActivity(); } this.lastUIModeFlags = newConfig.uiMode; } + private void updateActivity() + { + /** + * Set root activity to null to avoid duplication which causes the window + * to lose all it's content when the activity is recreated. + */ + getTiApp().setRootActivity(null); + this.recreate(); + } + @Override protected void onNightModeChanged(int mode) { @@ -1258,7 +1268,7 @@ public void applyNightMode() this.setSelectedTheme(mode); if (this.inForeground && (mode != this.lastNightMode)) { this.lastNightMode = mode; - this.recreate(); + this.updateActivity(); } } From 4ba34d43f277b8c1b77b4c66d6276556002495a0 Mon Sep 17 00:00:00 2001 From: AbdullahFaqeir Date: Sat, 9 Nov 2024 22:26:59 +0300 Subject: [PATCH 3/4] fix(android): remove parts that needs to be moved to another PR --- android/titanium/res/values/values.xml | 14 ---------- .../appcelerator/titanium/TiBaseActivity.java | 26 ------------------- 2 files changed, 40 deletions(-) diff --git a/android/titanium/res/values/values.xml b/android/titanium/res/values/values.xml index f9932a4c11f..d24e3e0d93d 100644 --- a/android/titanium/res/values/values.xml +++ b/android/titanium/res/values/values.xml @@ -48,7 +48,6 @@ false false false - @style/WindowAnimationTransition @@ -110,13 +109,6 @@ false false false - @style/WindowAnimationTransition - - - - @@ -212,12 +204,6 @@ true - - - - + + +