From dc59603f9bde5bc30d671f71a5044ffe18778b52 Mon Sep 17 00:00:00 2001 From: Nazar-Kutz Date: Fri, 21 Aug 2020 13:58:30 +0300 Subject: [PATCH 1/4] Fix #8545 Supporting System Default theme --- OsmAnd/res/values/strings.xml | 1 + .../net/osmand/plus/OsmandApplication.java | 16 +++++----- .../ActionBarPreferenceActivity.java | 9 ++---- .../activities/FavoritesSearchFragment.java | 2 +- .../dialogs/HelpArticleDialogFragment.java | 4 +-- .../download/ui/SearchDialogFragment.java | 3 +- .../mapmarkers/MapMarkersDialogFragment.java | 3 +- .../myplaces/SplitSegmentDialogFragment.java | 3 +- .../plus/osmedit/EditPoiDialogFragment.java | 2 +- .../QuickSearchCoordinatesFragment.java | 3 +- .../search/QuickSearchCustomPoiFragment.java | 3 +- .../search/QuickSearchDialogFragment.java | 2 +- .../search/QuickSearchPoiFilterFragment.java | 3 +- .../plus/settings/backend/OsmandSettings.java | 25 ++++++++++++++++ .../GeneralProfileSettingsFragment.java | 30 ++++++++++++++++--- 15 files changed, 73 insertions(+), 36 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index c6dc99c303..68b276d2b5 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,7 @@ Thx - Hardy --> + System Default Enter address Add address Delete address diff --git a/OsmAnd/src/net/osmand/plus/OsmandApplication.java b/OsmAnd/src/net/osmand/plus/OsmandApplication.java index 10d52563d1..43c3a17f09 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandApplication.java +++ b/OsmAnd/src/net/osmand/plus/OsmandApplication.java @@ -760,23 +760,23 @@ public class OsmandApplication extends MultiDexApplication { } public void applyTheme(Context c) { - int t = R.style.OsmandDarkTheme; + int themeResId; boolean doNotUseAnimations = osmandSettings.DO_NOT_USE_ANIMATIONS.get(); - if (osmandSettings.OSMAND_THEME.get() == OsmandSettings.OSMAND_DARK_THEME) { + if (!osmandSettings.isLightContent()) { if (doNotUseAnimations) { - t = R.style.OsmandDarkTheme_NoAnimation; + themeResId = R.style.OsmandDarkTheme_NoAnimation; } else { - t = R.style.OsmandDarkTheme; + themeResId = R.style.OsmandDarkTheme; } - } else if (osmandSettings.OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME) { + } else { if (doNotUseAnimations) { - t = R.style.OsmandLightTheme_NoAnimation; + themeResId = R.style.OsmandLightTheme_NoAnimation; } else { - t = R.style.OsmandLightTheme; + themeResId = R.style.OsmandLightTheme; } } setLanguage(c); - c.setTheme(t); + c.setTheme(themeResId); } public IBRouterService getBRouterService() { diff --git a/OsmAnd/src/net/osmand/plus/activities/ActionBarPreferenceActivity.java b/OsmAnd/src/net/osmand/plus/activities/ActionBarPreferenceActivity.java index df340fe7b4..02ed96daba 100644 --- a/OsmAnd/src/net/osmand/plus/activities/ActionBarPreferenceActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/ActionBarPreferenceActivity.java @@ -33,12 +33,9 @@ public abstract class ActionBarPreferenceActivity extends AppCompatPreferenceAct protected void onCreate(final Bundle savedInstanceState) { //settings needed it's own theme because of check boxes not styled properly OsmandSettings settings = ((OsmandApplication) getApplication()).getSettings(); - int t = R.style.OsmandLightTheme_NoActionbar_Preferences; - if (settings.OSMAND_THEME.get() == OsmandSettings.OSMAND_DARK_THEME) { - t = R.style.OsmandDarkTheme_NoActionbar_Preferences; - } else if (settings.OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME) { - t = R.style.OsmandLightTheme_NoActionbar_Preferences; - } + int t = settings.isLightContent() + ? R.style.OsmandLightTheme_NoActionbar_Preferences + : R.style.OsmandDarkTheme_NoActionbar_Preferences; setTheme(t); super.onCreate(savedInstanceState); boolean lightTheme = settings.isLightContent(); diff --git a/OsmAnd/src/net/osmand/plus/activities/FavoritesSearchFragment.java b/OsmAnd/src/net/osmand/plus/activities/FavoritesSearchFragment.java index 82bcc813b1..b6a03fa1cd 100644 --- a/OsmAnd/src/net/osmand/plus/activities/FavoritesSearchFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/FavoritesSearchFragment.java @@ -83,7 +83,7 @@ public class FavoritesSearchFragment extends DialogFragment { super.onCreate(savedInstanceState); app = getMyApplication(); accessibilityAssistant = new AccessibilityAssistant(getActivity()); - boolean isLightTheme = app.getSettings().OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME; + boolean isLightTheme = app.getSettings().isLightContent(); int themeId = isLightTheme ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme; setStyle(STYLE_NO_FRAME, themeId); } diff --git a/OsmAnd/src/net/osmand/plus/dialogs/HelpArticleDialogFragment.java b/OsmAnd/src/net/osmand/plus/dialogs/HelpArticleDialogFragment.java index fc1a917058..42a036599c 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/HelpArticleDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/HelpArticleDialogFragment.java @@ -16,7 +16,6 @@ import androidx.fragment.app.DialogFragment; import net.osmand.AndroidUtils; import net.osmand.PlatformUtil; import net.osmand.plus.OsmandApplication; -import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.R; import org.apache.commons.logging.Log; @@ -44,8 +43,7 @@ public class HelpArticleDialogFragment extends DialogFragment { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - boolean isLightTheme = (getOsmandApplication()) - .getSettings().OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME; + boolean isLightTheme = (getOsmandApplication()).getSettings().isLightContent(); int themeId = isLightTheme ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme; setStyle(STYLE_NO_FRAME, themeId); } diff --git a/OsmAnd/src/net/osmand/plus/download/ui/SearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/download/ui/SearchDialogFragment.java index afb24f06e5..ac9a87b32e 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/SearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/SearchDialogFragment.java @@ -40,7 +40,6 @@ import net.osmand.data.Amenity; import net.osmand.map.OsmandRegions; import net.osmand.map.WorldRegion; import net.osmand.plus.OsmandApplication; -import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.download.CityItem; import net.osmand.plus.download.DownloadActivity; @@ -87,7 +86,7 @@ public class SearchDialogFragment extends DialogFragment implements DownloadEven @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - boolean isLightTheme = getMyApplication().getSettings().OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME; + boolean isLightTheme = getMyApplication().getSettings().isLightContent(); int themeId = isLightTheme ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme; setStyle(STYLE_NO_FRAME, themeId); } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java index 45c57ed935..e84f7cbfc4 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java @@ -33,7 +33,6 @@ import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper.MapMarkersSortByDef; import net.osmand.plus.MapMarkersHelper.OnGroupSyncedListener; import net.osmand.plus.OsmandApplication; -import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; @@ -79,7 +78,7 @@ public class MapMarkersDialogFragment extends DialogFragment implements OnGroupS public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); OsmandApplication app = getMyApplication(); - lightTheme = app.getSettings().OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME; + lightTheme = app.getSettings().isLightContent(); int themeId = lightTheme ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme; setStyle(STYLE_NO_FRAME, themeId); } diff --git a/OsmAnd/src/net/osmand/plus/myplaces/SplitSegmentDialogFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/SplitSegmentDialogFragment.java index c7b3d0ba18..5115e7f63e 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/SplitSegmentDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/SplitSegmentDialogFragment.java @@ -38,7 +38,6 @@ import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; -import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.TrackActivity; @@ -83,7 +82,7 @@ public class SplitSegmentDialogFragment extends DialogFragment { TrackActivity trackActivity = requireTrackActivity(); app = trackActivity.getMyApplication(); ic = app.getUIUtilities(); - boolean isLightTheme = app.getSettings().OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME; + boolean isLightTheme = app.getSettings().isLightContent(); int themeId = isLightTheme ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme; setStyle(STYLE_NO_FRAME, themeId); } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java index ace09d8c3d..d3feb79ddb 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java @@ -139,7 +139,7 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { view = inflater.inflate(R.layout.fragment_edit_poi, container, false); - boolean isLightTheme = getSettings().OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME; + boolean isLightTheme = getSettings().isLightContent(); if (savedInstanceState != null) { @SuppressWarnings("unchecked") diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchCoordinatesFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchCoordinatesFragment.java index 613d7be98f..902f4bea4b 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchCoordinatesFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchCoordinatesFragment.java @@ -44,7 +44,6 @@ import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener; import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener; import net.osmand.plus.OsmandApplication; -import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.UiUtilities.UpdateLocationViewCache; @@ -119,7 +118,7 @@ public class QuickSearchCoordinatesFragment extends DialogFragment implements Os @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - isLightTheme = getMyApplication().getSettings().OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME; + isLightTheme = getMyApplication().getSettings().isLightContent(); int themeId = isLightTheme ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme; setStyle(STYLE_NO_FRAME, themeId); } diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchCustomPoiFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchCustomPoiFragment.java index 4b0f54a25e..e211569f4c 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchCustomPoiFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchCustomPoiFragment.java @@ -47,7 +47,6 @@ import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.poi.PoiFiltersHelper; import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.render.RenderingIcons; -import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.search.SearchUICore; import net.osmand.search.SearchUICore.SearchResultCollection; import net.osmand.search.core.ObjectType; @@ -112,7 +111,7 @@ public class QuickSearchCustomPoiFragment extends DialogFragment implements OnFi app = getMyApplication(); uiUtilities = app.getUIUtilities(); searchUICore = app.getSearchUICore().getCore(); - this.nightMode = app.getSettings().OSMAND_THEME.get() == OsmandSettings.OSMAND_DARK_THEME; + this.nightMode = !app.getSettings().isLightContent(); setStyle(STYLE_NO_FRAME, nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme); poiCategoryList = app.getPoiTypes().getCategories(false); Collections.sort(poiCategoryList, new Comparator() { diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java index 5be1d95cee..6b306003d0 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java @@ -236,7 +236,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC nightMode = !app.getSettings().isLightContent(); navigationInfo = new NavigationInfo(app); accessibilityAssistant = new AccessibilityAssistant(getActivity()); - boolean isLightTheme = app.getSettings().OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME; + boolean isLightTheme = app.getSettings().isLightContent(); int themeId = isLightTheme ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme; setStyle(STYLE_NO_FRAME, themeId); } diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchPoiFilterFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchPoiFilterFragment.java index d932d50557..4edc8fa0d1 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchPoiFilterFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchPoiFilterFragment.java @@ -38,7 +38,6 @@ import net.osmand.osm.PoiCategory; import net.osmand.osm.PoiFilter; import net.osmand.osm.PoiType; import net.osmand.plus.OsmandApplication; -import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.dialogs.DirectionsDialogs; @@ -97,7 +96,7 @@ public class QuickSearchPoiFilterFragment extends DialogFragment { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - isLightTheme = getMyApplication().getSettings().OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME; + isLightTheme = getMyApplication().getSettings().isLightContent(); int themeId = isLightTheme ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme; setStyle(STYLE_NO_FRAME, themeId); } diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java index d6cdc2c813..95d7748a88 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java @@ -3895,6 +3895,7 @@ public class OsmandSettings { public static final int OSMAND_DARK_THEME = 0; public static final int OSMAND_LIGHT_THEME = 1; + public static final int SYSTEM_DEFAULT_THEME = 2; public static final int NO_EXTERNAL_DEVICE = 0; public static final int GENERIC_EXTERNAL_DEVICE = 1; @@ -3923,9 +3924,33 @@ public class OsmandSettings { } public boolean isLightContentForMode(ApplicationMode mode) { + if (isSupportSystemDefaultTheme() && OSMAND_THEME.getModeValue(mode) == SYSTEM_DEFAULT_THEME) { + return isLightSystemDefaultTheme(); + } return OSMAND_THEME.getModeValue(mode) != OSMAND_DARK_THEME; } + private boolean isLightSystemDefaultTheme() { + Configuration config = ctx.getResources().getConfiguration(); + int systemNightModeState = config.uiMode & Configuration.UI_MODE_NIGHT_MASK; + if (systemNightModeState == Configuration.UI_MODE_NIGHT_YES) { + return false; + } + return true; + } + + public boolean isSystemDefaultThemeUsed() { + return isSystemDefaultThemeUsedForMode(APPLICATION_MODE.get()); + } + + public boolean isSystemDefaultThemeUsedForMode(ApplicationMode mode) { + return isSupportSystemDefaultTheme() && OSMAND_THEME.getModeValue(mode) == SYSTEM_DEFAULT_THEME; + } + + public boolean isSupportSystemDefaultTheme() { + return Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; + } + public final CommonPreference FLUORESCENT_OVERLAYS = new BooleanPreference("fluorescent_overlays", false).makeGlobal().cache(); diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/GeneralProfileSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/GeneralProfileSettingsFragment.java index 80488797ec..cbd682cf9d 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/GeneralProfileSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/GeneralProfileSettingsFragment.java @@ -95,14 +95,36 @@ public class GeneralProfileSettingsFragment extends BaseSettingsFragment impleme }; private void setupAppThemePref() { - final ListPreferenceEx appTheme = (ListPreferenceEx) findPreference(settings.OSMAND_THEME.getId()); - appTheme.setEntries(new String[] {getString(R.string.dark_theme), getString(R.string.light_theme)}); - appTheme.setEntryValues(new Integer[] {OsmandSettings.OSMAND_DARK_THEME, OsmandSettings.OSMAND_LIGHT_THEME}); + final ListPreferenceEx appTheme = + (ListPreferenceEx) findPreference(settings.OSMAND_THEME.getId()); + + ArrayList entries = new ArrayList<>(); + entries.add(getString(R.string.dark_theme)); + entries.add(getString(R.string.light_theme)); + + ArrayList values = new ArrayList<>(); + values.add(OsmandSettings.OSMAND_DARK_THEME); + values.add(OsmandSettings.OSMAND_LIGHT_THEME); + + if (settings.isSupportSystemDefaultTheme()) { + entries.add(getString(R.string.system_default_theme)); + values.add(OsmandSettings.SYSTEM_DEFAULT_THEME); + } + + String[] entriesStrings = new String[entries.size()]; + appTheme.setEntries(entries.toArray(entriesStrings)); + appTheme.setEntryValues(values.toArray()); appTheme.setIcon(getOsmandThemeIcon()); } private Drawable getOsmandThemeIcon() { - return getActiveIcon(settings.isLightContent() ? R.drawable.ic_action_sun : R.drawable.ic_action_moon); + int iconId; + if (settings.isSystemDefaultThemeUsed()) { + iconId = R.drawable.ic_action_android; + } else { + iconId = settings.isLightContent() ? R.drawable.ic_action_sun : R.drawable.ic_action_moon; + } + return getActiveIcon(iconId); } private void setupRotateMapPref() { From be01ba260f9b4e6ae0ef844aa7ec60ec4d160976 Mon Sep 17 00:00:00 2001 From: Nazar-Kutz Date: Fri, 21 Aug 2020 15:39:59 +0300 Subject: [PATCH 2/4] setup Light theme instead of System default when importing a profile for devices with android less than 10 --- .../osmand/plus/settings/backend/OsmandSettings.java | 11 ++++++++++- .../fragments/GeneralProfileSettingsFragment.java | 3 ++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java index 95d7748a88..bd46c48673 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java @@ -3909,7 +3909,16 @@ public class OsmandSettings { new IntPreference("FAVORITES_TAB", 0).makeGlobal().cache(); public final CommonPreference OSMAND_THEME = - new IntPreference("osmand_theme", OSMAND_LIGHT_THEME).makeProfile().cache(); + new IntPreference("osmand_theme", OSMAND_LIGHT_THEME) { + @Override + public void readFromJson(JSONObject json, ApplicationMode appMode) throws JSONException { + Integer theme = parseString(json.getString(getId())); + if (theme == SYSTEM_DEFAULT_THEME && !isSupportSystemDefaultTheme()) { + theme = OSMAND_LIGHT_THEME; + } + setModeValue(appMode, theme); + } + }.makeProfile().cache(); public final OsmandPreference OPEN_ONLY_HEADER_STATE_ROUTE_CALCULATED = new BooleanPreference("open_only_header_route_calculated", false).makeProfile(); diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/GeneralProfileSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/GeneralProfileSettingsFragment.java index cbd682cf9d..e870fed149 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/GeneralProfileSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/GeneralProfileSettingsFragment.java @@ -119,7 +119,8 @@ public class GeneralProfileSettingsFragment extends BaseSettingsFragment impleme private Drawable getOsmandThemeIcon() { int iconId; - if (settings.isSystemDefaultThemeUsed()) { + ApplicationMode mode = getSelectedAppMode(); + if (settings.isSystemDefaultThemeUsedForMode(mode)) { iconId = R.drawable.ic_action_android; } else { iconId = settings.isLightContent() ? R.drawable.ic_action_sun : R.drawable.ic_action_moon; From 62a15f27593bc9d9270296c9f4c5c723096ee631 Mon Sep 17 00:00:00 2001 From: Nazar-Kutz Date: Mon, 24 Aug 2020 13:10:31 +0300 Subject: [PATCH 3/4] Fix #8040 Add a dark splash screen for global dark app theme --- .../drawable-sw600dp-v21/first_splash_screen_free.xml | 2 +- .../first_splash_screen_free_dev.xml | 2 +- .../drawable-sw600dp-v21/first_splash_screen_plus.xml | 2 +- .../res/drawable-sw600dp/first_splash_screen_free.xml | 2 +- .../drawable-sw600dp/first_splash_screen_free_dev.xml | 2 +- .../res/drawable-sw600dp/first_splash_screen_plus.xml | 2 +- OsmAnd/res/drawable/first_splash_screen_free.xml | 2 +- OsmAnd/res/drawable/first_splash_screen_free_dev.xml | 2 +- OsmAnd/res/drawable/first_splash_screen_plus.xml | 2 +- OsmAnd/res/values-night/colors.xml | 4 ++++ OsmAnd/res/values-night/styles.xml | 4 ++++ OsmAnd/res/values/colors.xml | 2 ++ OsmAnd/res/values/styles.xml | 10 ++++++---- OsmAnd/src/net/osmand/SecondSplashScreenFragment.java | 7 ++++++- .../osmand/plus/settings/backend/OsmandSettings.java | 2 +- 15 files changed, 32 insertions(+), 15 deletions(-) create mode 100644 OsmAnd/res/values-night/colors.xml create mode 100644 OsmAnd/res/values-night/styles.xml diff --git a/OsmAnd/res/drawable-sw600dp-v21/first_splash_screen_free.xml b/OsmAnd/res/drawable-sw600dp-v21/first_splash_screen_free.xml index ed3f0e5956..31032dc8b4 100644 --- a/OsmAnd/res/drawable-sw600dp-v21/first_splash_screen_free.xml +++ b/OsmAnd/res/drawable-sw600dp-v21/first_splash_screen_free.xml @@ -1,7 +1,7 @@ - + - + - + - + \ No newline at end of file diff --git a/OsmAnd/res/drawable-sw600dp/first_splash_screen_free_dev.xml b/OsmAnd/res/drawable-sw600dp/first_splash_screen_free_dev.xml index 20d4cde2ea..aae2c9955e 100644 --- a/OsmAnd/res/drawable-sw600dp/first_splash_screen_free_dev.xml +++ b/OsmAnd/res/drawable-sw600dp/first_splash_screen_free_dev.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/OsmAnd/res/drawable-sw600dp/first_splash_screen_plus.xml b/OsmAnd/res/drawable-sw600dp/first_splash_screen_plus.xml index 20d4cde2ea..aae2c9955e 100644 --- a/OsmAnd/res/drawable-sw600dp/first_splash_screen_plus.xml +++ b/OsmAnd/res/drawable-sw600dp/first_splash_screen_plus.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/OsmAnd/res/drawable/first_splash_screen_free.xml b/OsmAnd/res/drawable/first_splash_screen_free.xml index b3d6f99388..4a413970b5 100644 --- a/OsmAnd/res/drawable/first_splash_screen_free.xml +++ b/OsmAnd/res/drawable/first_splash_screen_free.xml @@ -1,7 +1,7 @@ - + - + - + + + @color/map_background_color_dark + \ No newline at end of file diff --git a/OsmAnd/res/values-night/styles.xml b/OsmAnd/res/values-night/styles.xml new file mode 100644 index 0000000000..aa6decf779 --- /dev/null +++ b/OsmAnd/res/values-night/styles.xml @@ -0,0 +1,4 @@ + + + - - - - diff --git a/OsmAnd/src/net/osmand/SecondSplashScreenFragment.java b/OsmAnd/src/net/osmand/SecondSplashScreenFragment.java index 147c4b80cc..b5265a89ce 100644 --- a/OsmAnd/src/net/osmand/SecondSplashScreenFragment.java +++ b/OsmAnd/src/net/osmand/SecondSplashScreenFragment.java @@ -78,7 +78,12 @@ public class SecondSplashScreenFragment extends BaseOsmAndFragment { RelativeLayout view = new RelativeLayout(activity); view.setOnClickListener(null); - view.setBackgroundColor(getResources().getColor(R.color.map_background_color_light)); + int backgroundColorId = R.color.map_background_color_light; + if (app.getSettings().isSupportSystemDefaultTheme() + && !app.getSettings().isLightSystemDefaultTheme()) { + backgroundColorId = R.color.map_background_color_dark; + } + view.setBackgroundColor(getResources().getColor(backgroundColorId)); ImageView logo = new ImageView(getContext()); logo.setId(LOGO_ID); diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java index bd46c48673..f3c5b7b367 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java @@ -3939,7 +3939,7 @@ public class OsmandSettings { return OSMAND_THEME.getModeValue(mode) != OSMAND_DARK_THEME; } - private boolean isLightSystemDefaultTheme() { + public boolean isLightSystemDefaultTheme() { Configuration config = ctx.getResources().getConfiguration(); int systemNightModeState = config.uiMode & Configuration.UI_MODE_NIGHT_MASK; if (systemNightModeState == Configuration.UI_MODE_NIGHT_YES) { From 8aa52864c524517fed3a40570f37fb1a60326fde Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Tue, 25 Aug 2020 14:44:37 +0300 Subject: [PATCH 4/4] Minor fixes --- .../net/osmand/plus/settings/backend/OsmandSettings.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java index f3c5b7b367..4afce65383 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java @@ -3927,7 +3927,6 @@ public class OsmandSettings { return isLightContent(); } - public boolean isLightContent() { return isLightContentForMode(APPLICATION_MODE.get()); } @@ -3942,10 +3941,7 @@ public class OsmandSettings { public boolean isLightSystemDefaultTheme() { Configuration config = ctx.getResources().getConfiguration(); int systemNightModeState = config.uiMode & Configuration.UI_MODE_NIGHT_MASK; - if (systemNightModeState == Configuration.UI_MODE_NIGHT_YES) { - return false; - } - return true; + return systemNightModeState != Configuration.UI_MODE_NIGHT_YES; } public boolean isSystemDefaultThemeUsed() {