Merge pull request #9678 from osmandapp/Android10DarkTheme

Fix #8545 Supporting System Default theme
This commit is contained in:
Vitaliy 2020-08-25 14:47:00 +03:00 committed by GitHub
commit 5d8fa71d31
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 112 additions and 52 deletions

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:opacity="opaque">
<item android:drawable="@color/map_background_color_light"/>
<item android:drawable="@color/splash_screen_background_color"/>
<item android:top="@dimen/splash_screen_logo_top">
<bitmap
android:gravity="center"

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:opacity="opaque">
<item android:drawable="@color/map_background_color_light"/>
<item android:drawable="@color/splash_screen_background_color"/>
<item android:top="@dimen/splash_screen_logo_top">
<bitmap
android:gravity="center"

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:opacity="opaque">
<item android:drawable="@color/map_background_color_light"/>
<item android:drawable="@color/splash_screen_background_color"/>
<item android:top="@dimen/splash_screen_logo_top">
<bitmap
android:gravity="center"

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/map_background_color_light"/>
<solid android:color="@color/splash_screen_background_color"/>
</shape>

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/map_background_color_light"/>
<solid android:color="@color/splash_screen_background_color"/>
</shape>

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/map_background_color_light"/>
<solid android:color="@color/splash_screen_background_color"/>
</shape>

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:opacity="opaque">
<item android:drawable="@color/map_background_color_light"/>
<item android:drawable="@color/splash_screen_background_color"/>
<item android:top="@dimen/splash_screen_logo_top">
<bitmap
android:gravity="center_horizontal|top"

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:opacity="opaque">
<item android:drawable="@color/map_background_color_light"/>
<item android:drawable="@color/splash_screen_background_color"/>
<item android:top="@dimen/splash_screen_logo_top">
<bitmap
android:gravity="center_horizontal|top"

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:opacity="opaque">
<item android:drawable="@color/map_background_color_light"/>
<item android:drawable="@color/splash_screen_background_color"/>
<item android:top="@dimen/splash_screen_logo_top">
<bitmap
android:gravity="center_horizontal|top"

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="splash_screen_background_color">@color/map_background_color_dark</color>
</resources>

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="SplashScreenBaseTheme" parent="OsmandDarkTheme.NoActionbar" />
</resources>

View file

@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="splash_screen_background_color">@color/map_background_color_light</color>
<color name="text_color_primary_light">#212121</color>
<color name="text_color_primary_dark">#cccccc</color>
<color name="text_color_secondary_light">#727272</color>

View file

@ -11,6 +11,7 @@
Thx - Hardy
-->
<string name="system_default_theme">System Default</string>
<string name="gpx_monitoring_start">Resume trip recording</string>
<string name="gpx_monitoring_stop">Pause trip recording</string>
<string name="save_global_track_interval_descr">Specify the logging interval for the general track recording (enabled via the Trip recording widget on the map).</string>

View file

@ -40,19 +40,21 @@
<item name="android:background">?attr/btn_round</item>
</style>
<style name="FirstSplashScreenCustom" parent="OsmandLightTheme.NoActionbar">
<style name="SplashScreenBaseTheme" parent="OsmandLightTheme.NoActionbar" />
<style name="FirstSplashScreenCustom" parent="SplashScreenBaseTheme">
<item name="android:windowBackground">@drawable/first_splash_screen_free</item>
</style>
<style name="FirstSplashScreenPlus" parent="OsmandLightTheme.NoActionbar">
<style name="FirstSplashScreenPlus" parent="SplashScreenBaseTheme">
<item name="android:windowBackground">@drawable/first_splash_screen_plus</item>
</style>
<style name="FirstSplashScreenFree" parent="OsmandLightTheme.NoActionbar">
<style name="FirstSplashScreenFree" parent="SplashScreenBaseTheme">
<item name="android:windowBackground">@drawable/first_splash_screen_free</item>
</style>
<style name="FirstSplashScreenFreeDev" parent="OsmandLightTheme.NoActionbar">
<style name="FirstSplashScreenFreeDev" parent="SplashScreenBaseTheme">
<item name="android:windowBackground">@drawable/first_splash_screen_free_dev</item>
</style>

View file

@ -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);

View file

@ -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) {
if (doNotUseAnimations) {
t = R.style.OsmandLightTheme_NoAnimation;
} else {
t = R.style.OsmandLightTheme;
if (doNotUseAnimations) {
themeResId = R.style.OsmandLightTheme_NoAnimation;
} else {
themeResId = R.style.OsmandLightTheme;
}
}
setLanguage(c);
c.setTheme(t);
c.setTheme(themeResId);
}
public IBRouterService getBRouterService() {

View file

@ -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();

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -140,7 +140,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")

View file

@ -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);
}

View file

@ -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<PoiCategory>() {

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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;
@ -3908,7 +3909,16 @@ public class OsmandSettings {
new IntPreference("FAVORITES_TAB", 0).makeGlobal().cache();
public final CommonPreference<Integer> 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<Boolean> OPEN_ONLY_HEADER_STATE_ROUTE_CALCULATED =
new BooleanPreference("open_only_header_route_calculated", false).makeProfile();
@ -3917,15 +3927,35 @@ public class OsmandSettings {
return isLightContent();
}
public boolean isLightContent() {
return isLightContentForMode(APPLICATION_MODE.get());
}
public boolean isLightContentForMode(ApplicationMode mode) {
if (isSupportSystemDefaultTheme() && OSMAND_THEME.getModeValue(mode) == SYSTEM_DEFAULT_THEME) {
return isLightSystemDefaultTheme();
}
return OSMAND_THEME.getModeValue(mode) != OSMAND_DARK_THEME;
}
public boolean isLightSystemDefaultTheme() {
Configuration config = ctx.getResources().getConfiguration();
int systemNightModeState = config.uiMode & Configuration.UI_MODE_NIGHT_MASK;
return systemNightModeState != Configuration.UI_MODE_NIGHT_YES;
}
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<Boolean> FLUORESCENT_OVERLAYS =
new BooleanPreference("fluorescent_overlays", false).makeGlobal().cache();

View file

@ -95,14 +95,37 @@ 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<String> entries = new ArrayList<>();
entries.add(getString(R.string.dark_theme));
entries.add(getString(R.string.light_theme));
ArrayList<Integer> 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;
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;
}
return getActiveIcon(iconId);
}
private void setupRotateMapPref() {