Fix for api 16, code cleanup ApplicationMode

This commit is contained in:
Dima-1 2020-01-16 14:25:27 +02:00
parent 533571724b
commit 20320ddc07
4 changed files with 62 additions and 44 deletions

View file

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle"
xmlns:android="http://schemas.android.com/apk/res/android">
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@android:color/transparent" />
<corners android:radius="2dp" />
<stroke
android:radius="5dp"
android:width="2dp"
android:color="@color/A400red" />
android:color="@color/divider_color_light" />
</shape>

View file

@ -133,16 +133,26 @@ public class ApplicationMode {
.setRoutingProfile("ski").description(R.string.base_profile_descr_ski).reg();
private static class ApplicationModeBean {
@Expose String stringKey;
@Expose String userProfileName;
@Expose String parent;
@Expose String iconName = "map_world_globe_dark";
@Expose ProfileIconColors iconColor = ProfileIconColors.DEFAULT;
@Expose String routingProfile = null;
@Expose RouteService routeService = RouteService.OSMAND;
@Expose LocationIcon locationIcon = LocationIcon.DEFAULT;
@Expose NavigationIcon navigationIcon = NavigationIcon.CAR;
@Expose int order;
@Expose
String stringKey;
@Expose
String userProfileName;
@Expose
String parent;
@Expose
String iconName = "map_world_globe_dark";
@Expose
ProfileIconColors iconColor = ProfileIconColors.DEFAULT;
@Expose
String routingProfile = null;
@Expose
RouteService routeService = RouteService.OSMAND;
@Expose
LocationIcon locationIcon = LocationIcon.DEFAULT;
@Expose
NavigationIcon navigationIcon = NavigationIcon.CAR;
@Expose
int order;
}
private static void initRegVisibility() {
@ -554,11 +564,13 @@ public class ApplicationMode {
return routingProfile;
}
@DrawableRes public int getIconRes() {
@DrawableRes
public int getIconRes() {
return iconRes;
}
@DrawableRes public int getMapIconRes() {
@DrawableRes
public int getMapIconRes() {
return iconMapRes;
}
@ -650,7 +662,8 @@ public class ApplicationMode {
private static void initDefaultModesParams(OsmandApplication app) {
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
Type t = new TypeToken<ArrayList<ApplicationModeBean>>() {}.getType();
Type t = new TypeToken<ArrayList<ApplicationModeBean>>() {
}.getType();
List<ApplicationModeBean> defaultAppModeBeans = gson.fromJson(app.getSettings().DEFAULT_APP_PROFILES.get(), t);
if (!Algorithms.isEmpty(defaultAppModeBeans)) {
@ -672,7 +685,8 @@ public class ApplicationMode {
private static void initCustomModes(OsmandApplication app) {
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
Type t = new TypeToken<ArrayList<ApplicationModeBean>>() {}.getType();
Type t = new TypeToken<ArrayList<ApplicationModeBean>>() {
}.getType();
List<ApplicationModeBean> customProfiles = gson.fromJson(app.getSettings().CUSTOM_APP_PROFILES.get(), t);
if (!Algorithms.isEmpty(customProfiles)) {
@ -812,9 +826,12 @@ public class ApplicationMode {
DARK_YELLOW(R.string.rendering_value_darkyellow_name, R.color.profile_icon_color_yellow_light, R.color.profile_icon_color_yellow_dark),
MAGENTA(R.string.shared_string_color_magenta, R.color.profile_icon_color_magenta_light, R.color.profile_icon_color_magenta_dark);
@StringRes private int name;
@ColorRes private int dayColor;
@ColorRes private int nightColor;
@StringRes
private int name;
@ColorRes
private int dayColor;
@ColorRes
private int nightColor;
ProfileIconColors(@StringRes int name, @ColorRes int dayColor, @ColorRes int nightColor) {
this.name = name;
@ -920,6 +937,7 @@ public class ApplicationMode {
public int getIconId() {
return iconId;
}
public int getHeadingIconId() {
return headingIconId;
}

View file

@ -491,7 +491,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
int changedProfileColor = ContextCompat.getColor(app, changedProfile.color.getColor(
app.getDaynightHelper().isNightModeForMapControls()));
LayerDrawable locationIconDrawable = (LayerDrawable) app.getResources().getDrawable(locationIcon.getIconId());
DrawableCompat.setTint(locationIconDrawable.getDrawable(1), changedProfileColor);
DrawableCompat.setTint(DrawableCompat.wrap(locationIconDrawable.getDrawable(1)), changedProfileColor);
locationIconView.<ImageView>findViewById(R.id.icon).setImageDrawable(locationIconDrawable);
ImageView headingIcon = locationIconView.findViewById(R.id.headingIcon);
headingIcon.setImageDrawable(ContextCompat.getDrawable(app, locationIcon.getHeadingIconId()));
@ -531,8 +531,8 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
FrameLayout navigationIconView = (FrameLayout) UiUtilities.getInflater(getContext(), isNightMode())
.inflate(R.layout.preference_select_icon_button, rootView, false);
LayerDrawable navigationIconDrawable = (LayerDrawable) app.getResources().getDrawable(navigationIcon.getIconId());
DrawableCompat.setTint(navigationIconDrawable.getDrawable(1), ContextCompat.getColor(app, changedProfile.color.getColor(
app.getDaynightHelper().isNightModeForMapControls())));
DrawableCompat.setTint(DrawableCompat.wrap(navigationIconDrawable.getDrawable(1)),
ContextCompat.getColor(app, changedProfile.color.getColor(app.getDaynightHelper().isNightModeForMapControls())));
ImageView imageView = navigationIconView.findViewById(R.id.icon);
imageView.setImageDrawable(navigationIconDrawable);
Matrix matrix = new Matrix();

View file

@ -165,7 +165,7 @@ public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLay
headingIcon = BitmapFactory.decodeResource(view.getResources(), appMode.getLocationIcon().getHeadingIconId());
headingPaint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN));
locationIcon = (LayerDrawable) view.getResources().getDrawable(appMode.getLocationIcon().getIconId());
DrawableCompat.setTint(locationIcon.getDrawable(1), color);
DrawableCompat.setTint(DrawableCompat.wrap(locationIcon.getDrawable(1)), color);
area.setColor(UiUtilities.getColorWithAlpha(color, 0.16f));
aroundArea.setColor(color);
}