diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index 86bdadc494..0a7e8fb475 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -343,10 +343,13 @@
+
android:screenOrientation="fullUser"/>
@@ -399,6 +402,7 @@
android:name="app.organicmaps.help.HelpActivity"
android:label="@string/about_menu_title"
android:parentActivityName="app.organicmaps.MwmActivity"
+ android:configChanges="uiMode"
android:exported="false">
@@ -408,7 +412,7 @@
+ android:name="app.organicmaps.MapPlaceholderActivity"
+ android:configChanges="uiMode" />
getScreenManager().push(new ThemeScreen(getCarContext(), getSurfaceRenderer())));
builder.setBrowsable(true);
diff --git a/android/app/src/main/java/app/organicmaps/car/screens/settings/ThemeScreen.java b/android/app/src/main/java/app/organicmaps/car/screens/settings/ThemeScreen.java
index 530a3259b5..f2a83959e8 100644
--- a/android/app/src/main/java/app/organicmaps/car/screens/settings/ThemeScreen.java
+++ b/android/app/src/main/java/app/organicmaps/car/screens/settings/ThemeScreen.java
@@ -47,7 +47,7 @@ public class ThemeScreen extends BaseMapScreen
{
final Header.Builder builder = new Header.Builder();
builder.setStartHeaderAction(Action.BACK);
- builder.setTitle(getCarContext().getString(R.string.pref_map_style_title));
+ builder.setTitle(getCarContext().getString(R.string.pref_appearance_title));
return builder.build();
}
@@ -56,7 +56,7 @@ public class ThemeScreen extends BaseMapScreen
{
final ItemList.Builder builder = new ItemList.Builder();
final ThemeUtils.ThemeMode currentThemeMode = ThemeUtils.getThemeMode(getCarContext());
- builder.addItem(createRadioButton(ThemeUtils.ThemeMode.AUTO, currentThemeMode));
+ builder.addItem(createRadioButton(ThemeUtils.ThemeMode.FOLLOW_SYSTEM, currentThemeMode));
builder.addItem(createRadioButton(ThemeUtils.ThemeMode.NIGHT, currentThemeMode));
builder.addItem(createRadioButton(ThemeUtils.ThemeMode.LIGHT, currentThemeMode));
return new ListTemplate.Builder().setHeader(createHeader()).setSingleList(builder.build()).build();
diff --git a/android/app/src/main/java/app/organicmaps/car/util/ThemeUtils.java b/android/app/src/main/java/app/organicmaps/car/util/ThemeUtils.java
index cb6806cfd5..f38dc77add 100644
--- a/android/app/src/main/java/app/organicmaps/car/util/ThemeUtils.java
+++ b/android/app/src/main/java/app/organicmaps/car/util/ThemeUtils.java
@@ -17,9 +17,9 @@ public final class ThemeUtils
{
public enum ThemeMode
{
- AUTO(R.string.auto, R.string.theme_auto),
- LIGHT(R.string.off, R.string.theme_default),
- NIGHT(R.string.on, R.string.theme_night);
+ LIGHT(R.string.light, R.string.theme_default),
+ NIGHT(R.string.dark, R.string.theme_night),
+ FOLLOW_SYSTEM(R.string.follow_system, R.string.theme_follow_system);
ThemeMode(@StringRes int titleId, @StringRes int prefsKeyId)
{
@@ -58,7 +58,7 @@ public final class ThemeUtils
@UiThread
public static void update(@NonNull CarContext context, @NonNull ThemeMode oldThemeMode)
{
- final ThemeMode newThemeMode = oldThemeMode == ThemeMode.AUTO ? (context.isDarkMode() ? ThemeMode.NIGHT : ThemeMode.LIGHT) : oldThemeMode;
+ final ThemeMode newThemeMode = oldThemeMode == ThemeMode.FOLLOW_SYSTEM ? (context.isDarkMode() ? ThemeMode.NIGHT : ThemeMode.LIGHT) : oldThemeMode;
@Framework.MapStyle
int newMapStyle;
@@ -74,7 +74,7 @@ public final class ThemeUtils
public static boolean isNightMode(@NonNull CarContext context)
{
final ThemeMode themeMode = getThemeMode(context);
- return themeMode == ThemeMode.NIGHT || (themeMode == ThemeMode.AUTO && context.isDarkMode());
+ return themeMode == ThemeMode.NIGHT || (themeMode == ThemeMode.FOLLOW_SYSTEM && context.isDarkMode());
}
@SuppressLint("ApplySharedPref")
@@ -88,13 +88,13 @@ public final class ThemeUtils
@NonNull
public static ThemeMode getThemeMode(@NonNull CarContext context)
{
- final String autoTheme = context.getString(R.string.theme_auto);
+ final String followSystemTheme = context.getString(R.string.theme_follow_system);
final String lightTheme = context.getString(R.string.theme_default);
final String nightTheme = context.getString(R.string.theme_night);
- final String themeMode = getSharedPreferences(context).getString(THEME_KEY, autoTheme);
+ final String themeMode = getSharedPreferences(context).getString(THEME_KEY, followSystemTheme);
- if (themeMode.equals(autoTheme))
- return ThemeMode.AUTO;
+ if (themeMode.equals(followSystemTheme))
+ return ThemeMode.FOLLOW_SYSTEM;
else if (themeMode.equals(lightTheme))
return ThemeMode.LIGHT;
else if (themeMode.equals(nightTheme))
diff --git a/android/app/src/main/java/app/organicmaps/settings/SettingsPrefsFragment.java b/android/app/src/main/java/app/organicmaps/settings/SettingsPrefsFragment.java
index b7d8e35f69..2597c3fd4c 100644
--- a/android/app/src/main/java/app/organicmaps/settings/SettingsPrefsFragment.java
+++ b/android/app/src/main/java/app/organicmaps/settings/SettingsPrefsFragment.java
@@ -507,10 +507,9 @@ public class SettingsPrefsFragment extends BaseXmlSettingsFragment implements La
enum ThemeMode
{
+ FOLLOW_SYSTEM(R.string.theme_follow_system),
DEFAULT(R.string.theme_default),
- NIGHT(R.string.theme_night),
- AUTO(R.string.theme_auto),
- NAV_AUTO(R.string.theme_nav_auto);
+ NIGHT(R.string.theme_night);
private final int mModeStringId;
@@ -527,7 +526,7 @@ public class SettingsPrefsFragment extends BaseXmlSettingsFragment implements La
if (context.getResources().getString(each.mModeStringId).equals(src))
return each;
}
- return AUTO;
+ return FOLLOW_SYSTEM;
}
}
diff --git a/android/app/src/main/java/app/organicmaps/util/Config.java b/android/app/src/main/java/app/organicmaps/util/Config.java
index 2f9cdbf882..55670340d9 100644
--- a/android/app/src/main/java/app/organicmaps/util/Config.java
+++ b/android/app/src/main/java/app/organicmaps/util/Config.java
@@ -275,12 +275,12 @@ public final class Config
@NonNull
public static String getUiThemeSettings(@NonNull Context context)
{
- String autoTheme = MwmApplication.from(context).getString(R.string.theme_auto);
- String res = getString(KEY_MISC_UI_THEME_SETTINGS, autoTheme);
- if (ThemeUtils.isValidTheme(context, res) || ThemeUtils.isAutoTheme(context, res) || ThemeUtils.isNavAutoTheme(context, res))
+ String followSystemTheme = MwmApplication.from(context).getString(R.string.theme_follow_system);
+ String res = getString(KEY_MISC_UI_THEME_SETTINGS, followSystemTheme);
+ if (ThemeUtils.isValidTheme(context, res) || ThemeUtils.isFollowSystemTheme(context, res))
return res;
- return autoTheme;
+ return followSystemTheme;
}
public static boolean setUiThemeSettings(@NonNull Context context, String theme)
diff --git a/android/app/src/main/java/app/organicmaps/util/ThemeSwitcher.java b/android/app/src/main/java/app/organicmaps/util/ThemeSwitcher.java
index d70055b0f9..b1bdc24177 100644
--- a/android/app/src/main/java/app/organicmaps/util/ThemeSwitcher.java
+++ b/android/app/src/main/java/app/organicmaps/util/ThemeSwitcher.java
@@ -1,21 +1,15 @@
package app.organicmaps.util;
import android.app.Activity;
-import android.app.UiModeManager;
import android.content.Context;
-import android.location.Location;
-import android.os.Build;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatDelegate;
import app.organicmaps.Framework;
import app.organicmaps.MwmApplication;
-import app.organicmaps.R;
import app.organicmaps.display.DisplayManager;
import app.organicmaps.downloader.DownloaderStatusIcon;
-import app.organicmaps.location.LocationHelper;
import app.organicmaps.routing.RoutingController;
-import app.organicmaps.util.concurrency.UiThread;
public enum ThemeSwitcher
{
@@ -24,37 +18,37 @@ public enum ThemeSwitcher
private static final long CHECK_INTERVAL_MS = 30 * 60 * 1000;
private static boolean mRendererActive = false;
- private final Runnable mAutoThemeChecker = new Runnable()
- {
- @Override
- public void run()
- {
- String nightTheme = MwmApplication.from(mContext).getString(R.string.theme_night);
- String defaultTheme = MwmApplication.from(mContext).getString(R.string.theme_default);
- String theme = defaultTheme;
- Location last = LocationHelper.from(mContext).getSavedLocation();
-
- boolean navAuto = RoutingController.get().isNavigating() && ThemeUtils.isNavAutoTheme(mContext);
-
- if (navAuto || ThemeUtils.isAutoTheme(mContext))
- {
- if (last == null)
- theme = Config.getCurrentUiTheme(mContext);
- else
- {
- long currentTime = System.currentTimeMillis() / 1000;
- boolean day = Framework.nativeIsDayTime(currentTime, last.getLatitude(), last.getLongitude());
- theme = (day ? defaultTheme : nightTheme);
- }
- }
-
- setThemeAndMapStyle(theme);
- UiThread.cancelDelayedTasks(mAutoThemeChecker);
-
- if (navAuto || ThemeUtils.isAutoTheme(mContext))
- UiThread.runLater(mAutoThemeChecker, CHECK_INTERVAL_MS);
- }
- };
+// private final Runnable mAutoThemeChecker = new Runnable()
+// {
+// @Override
+// public void run()
+// {
+// String nightTheme = MwmApplication.from(mContext).getString(R.string.theme_night);
+// String defaultTheme = MwmApplication.from(mContext).getString(R.string.theme_default);
+// String theme = defaultTheme;
+// Location last = LocationHelper.from(mContext).getSavedLocation();
+//
+// boolean navAuto = RoutingController.get().isNavigating() && ThemeUtils.isNavAutoTheme(mContext);
+//
+// if (navAuto || ThemeUtils.isAutoTheme(mContext))
+// {
+// if (last == null)
+// theme = Config.getCurrentUiTheme(mContext);
+// else
+// {
+// long currentTime = System.currentTimeMillis() / 1000;
+// boolean day = Framework.nativeIsDayTime(currentTime, last.getLatitude(), last.getLongitude());
+// theme = (day ? defaultTheme : nightTheme);
+// }
+// }
+//
+// setThemeAndMapStyle(theme);
+// UiThread.cancelDelayedTasks(mAutoThemeChecker);
+//
+// if (navAuto || ThemeUtils.isAutoTheme(mContext))
+// UiThread.runLater(mAutoThemeChecker, CHECK_INTERVAL_MS);
+// }
+// };
@SuppressWarnings("NotNullFieldNotInitialized")
@NonNull
@@ -79,32 +73,34 @@ public enum ThemeSwitcher
{
mRendererActive = isRendererActive;
String theme = Config.getUiThemeSettings(mContext);
- if (ThemeUtils.isAutoTheme(mContext, theme) || ThemeUtils.isNavAutoTheme(mContext, theme))
- {
- mAutoThemeChecker.run();
- return;
- }
+// if (ThemeUtils.isAutoTheme(mContext, theme) || ThemeUtils.isNavAutoTheme(mContext, theme))
+// {
+// mAutoThemeChecker.run();
+// return;
+// }
+ setAndroidTheme(theme);
- UiThread.cancelDelayedTasks(mAutoThemeChecker);
- setThemeAndMapStyle(theme);
+ final String themeToApply = ThemeUtils.getAndroidTheme(mContext);
+ final int style = getStyle(themeToApply);
+ setThemeAndMapStyle(themeToApply, style);
}
- private void setThemeAndMapStyle(@NonNull String theme)
+ private void setAndroidTheme(@NonNull String theme)
{
- UiModeManager uiModeManager = (UiModeManager) mContext.getSystemService(Context.UI_MODE_SERVICE);
- String oldTheme = Config.getCurrentUiTheme(mContext);
- @Framework.MapStyle
- int oldStyle = Framework.nativeGetMapStyle();
+ if (ThemeUtils.isFollowSystemTheme(mContext, theme))
+ AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
+ else if (ThemeUtils.isNightTheme(mContext, theme))
+ AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
+ else if (ThemeUtils.isDefaultTheme(mContext, theme))
+ AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
+ }
+ private int getStyle(@NonNull String theme)
+ {
@Framework.MapStyle
int style;
if (ThemeUtils.isNightTheme(mContext, theme))
{
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
- uiModeManager.setApplicationNightMode(UiModeManager.MODE_NIGHT_YES);
- else
- AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
-
if (RoutingController.get().isVehicleNavigation())
style = Framework.MAP_STYLE_VEHICLE_DARK;
else if (Framework.nativeIsOutdoorsLayerEnabled())
@@ -114,11 +110,6 @@ public enum ThemeSwitcher
}
else
{
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
- uiModeManager.setApplicationNightMode(UiModeManager.MODE_NIGHT_NO);
- else
- AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
-
if (RoutingController.get().isVehicleNavigation())
style = Framework.MAP_STYLE_VEHICLE_CLEAR;
else if (Framework.nativeIsOutdoorsLayerEnabled())
@@ -127,6 +118,13 @@ public enum ThemeSwitcher
style = Framework.MAP_STYLE_CLEAR;
}
+ return style;
+ }
+
+ private void setThemeAndMapStyle(@NonNull String theme, @Framework.MapStyle int style)
+ {
+ String oldTheme = Config.getCurrentUiTheme(mContext);
+
if (!theme.equals(oldTheme))
{
Config.setCurrentUiTheme(mContext, theme);
diff --git a/android/app/src/main/java/app/organicmaps/util/ThemeUtils.java b/android/app/src/main/java/app/organicmaps/util/ThemeUtils.java
index c121c8d313..b3613e7cab 100644
--- a/android/app/src/main/java/app/organicmaps/util/ThemeUtils.java
+++ b/android/app/src/main/java/app/organicmaps/util/ThemeUtils.java
@@ -1,6 +1,7 @@
package app.organicmaps.util;
import android.content.Context;
+import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.util.TypedValue;
@@ -8,7 +9,7 @@ import androidx.annotation.AttrRes;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.StyleRes;
-
+import androidx.appcompat.app.AppCompatDelegate;
import app.organicmaps.R;
public final class ThemeUtils
@@ -45,6 +46,25 @@ public final class ThemeUtils
return VALUE_BUFFER.resourceId;
}
+ public static String getAndroidTheme(@NonNull Context context)
+ {
+ String nightTheme = context.getString(R.string.theme_night);
+ String defaultTheme = context.getString(R.string.theme_default);
+
+ if (AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_YES)
+ return nightTheme;
+
+ if (AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_NO)
+ return defaultTheme;
+
+ int nightModeFlags = context.getResources()
+ .getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
+ if (nightModeFlags == Configuration.UI_MODE_NIGHT_YES)
+ return nightTheme;
+ else
+ return defaultTheme;
+ }
+
public static boolean isDefaultTheme(@NonNull Context context)
{
return isDefaultTheme(context, Config.getCurrentUiTheme(context));
@@ -67,15 +87,15 @@ public final class ThemeUtils
return nightTheme.equals(theme);
}
- public static boolean isAutoTheme(@NonNull Context context)
+ public static boolean isFollowSystemTheme(@NonNull Context context)
{
- return isAutoTheme(context, Config.getUiThemeSettings(context));
+ return isFollowSystemTheme(context, Config.getCurrentUiTheme(context));
}
- public static boolean isAutoTheme(@NonNull Context context, String theme)
+ public static boolean isFollowSystemTheme(@NonNull Context context, String theme)
{
- String autoTheme = context.getString(R.string.theme_auto);
- return autoTheme.equals(theme);
+ String followSystemTheme = context.getString(R.string.theme_follow_system);
+ return followSystemTheme.equals(theme);
}
public static boolean isNavAutoTheme(@NonNull Context context)
diff --git a/android/app/src/main/res/values/donottranslate.xml b/android/app/src/main/res/values/donottranslate.xml
index 976c1ecd7c..79c9be7f89 100644
--- a/android/app/src/main/res/values/donottranslate.xml
+++ b/android/app/src/main/res/values/donottranslate.xml
@@ -53,6 +53,7 @@
night
auto
nav-auto
+ follow-system
collapse
diff --git a/android/app/src/main/res/values/string-arrays.xml b/android/app/src/main/res/values/string-arrays.xml
index ee0e6210fd..a5e7c4fd81 100644
--- a/android/app/src/main/res/values/string-arrays.xml
+++ b/android/app/src/main/res/values/string-arrays.xml
@@ -23,20 +23,16 @@
- 0
- 1
-
-
- - @string/off
- - @string/on
- - @string/auto
- - @string/nav_auto
+
+ - @string/follow_system
+ - @string/light
+ - @string/dark
-
-
+ - @string/theme_follow_system
- @string/theme_default
- @string/theme_night
- - @string/theme_auto
- - @string/theme_nav_auto
diff --git a/android/app/src/main/res/xml/prefs_main.xml b/android/app/src/main/res/xml/prefs_main.xml
index e162e025d6..6f278ca16c 100644
--- a/android/app/src/main/res/xml/prefs_main.xml
+++ b/android/app/src/main/res/xml/prefs_main.xml
@@ -14,6 +14,13 @@
android:key="@string/pref_settings_general"
android:title="@string/prefs_group_general"
android:order="2">
+
+ android:order="2"/>
+ android:order="3"/>
+ android:order="4"/>
+ android:order="5"/>
+ android:order="9"/>
+ android:order="10"/>
+ android:order="11"/>
+ android:order="12"/>
+ android:order="13"/>
+ android:order="14"/>
+ android:key="@string/pref_map_locale"
+ android:title="@string/change_map_locale"
+ app:singleLineTitle="false"
+ android:persistent="false"
+ android:order="15"/>
-
+ android:order="1" />
+ android:order="2" />
+ android:order="3">