Fix for api 16, code cleanup ApplicationMode
This commit is contained in:
parent
533571724b
commit
20320ddc07
4 changed files with 62 additions and 44 deletions
|
@ -1,9 +1,9 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
<shape android:shape="rectangle"
|
android:shape="rectangle">
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
<solid android:color="@android:color/transparent" />
|
||||||
<corners android:radius="2dp" />
|
<corners android:radius="2dp" />
|
||||||
<stroke
|
<stroke
|
||||||
android:radius="5dp"
|
android:radius="5dp"
|
||||||
android:width="2dp"
|
android:width="2dp"
|
||||||
android:color="@color/A400red" />
|
android:color="@color/divider_color_light" />
|
||||||
</shape>
|
</shape>
|
|
@ -102,7 +102,7 @@ public class ApplicationMode {
|
||||||
public static final ApplicationMode BICYCLE = createBase(R.string.app_mode_bicycle, "bicycle")
|
public static final ApplicationMode BICYCLE = createBase(R.string.app_mode_bicycle, "bicycle")
|
||||||
.speed(2.77f, 15).arrivalDistance(60).offRouteDistance(50)
|
.speed(2.77f, 15).arrivalDistance(60).offRouteDistance(50)
|
||||||
.locationIcon(LocationIcon.BICYCLE).navigationIcon(NavigationIcon.CAR)
|
.locationIcon(LocationIcon.BICYCLE).navigationIcon(NavigationIcon.CAR)
|
||||||
.icon(R.drawable.ic_action_bicycle_dark, R.drawable.map_action_bicycle_dark,"ic_action_bicycle_dark")
|
.icon(R.drawable.ic_action_bicycle_dark, R.drawable.map_action_bicycle_dark, "ic_action_bicycle_dark")
|
||||||
.setRoutingProfile("bicycle").description(R.string.base_profile_descr_bicycle).reg();
|
.setRoutingProfile("bicycle").description(R.string.base_profile_descr_bicycle).reg();
|
||||||
|
|
||||||
public static final ApplicationMode PEDESTRIAN = createBase(R.string.app_mode_pedestrian, "pedestrian")
|
public static final ApplicationMode PEDESTRIAN = createBase(R.string.app_mode_pedestrian, "pedestrian")
|
||||||
|
@ -111,7 +111,7 @@ public class ApplicationMode {
|
||||||
.setRoutingProfile("pedestrian").description(R.string.base_profile_descr_pedestrian).reg();
|
.setRoutingProfile("pedestrian").description(R.string.base_profile_descr_pedestrian).reg();
|
||||||
|
|
||||||
public static final ApplicationMode PUBLIC_TRANSPORT = createBase(R.string.app_mode_public_transport, "public_transport")
|
public static final ApplicationMode PUBLIC_TRANSPORT = createBase(R.string.app_mode_public_transport, "public_transport")
|
||||||
.icon(R.drawable.ic_action_bus_dark, R.drawable.map_action_bus_dark,"ic_action_bus_dark")
|
.icon(R.drawable.ic_action_bus_dark, R.drawable.map_action_bus_dark, "ic_action_bus_dark")
|
||||||
.setRoutingProfile("public_transport").description(R.string.base_profile_descr_public_transport).reg();
|
.setRoutingProfile("public_transport").description(R.string.base_profile_descr_public_transport).reg();
|
||||||
|
|
||||||
public static final ApplicationMode BOAT = createBase(R.string.app_mode_boat, "boat")
|
public static final ApplicationMode BOAT = createBase(R.string.app_mode_boat, "boat")
|
||||||
|
@ -123,26 +123,36 @@ public class ApplicationMode {
|
||||||
public static final ApplicationMode AIRCRAFT = createBase(R.string.app_mode_aircraft, "aircraft")
|
public static final ApplicationMode AIRCRAFT = createBase(R.string.app_mode_aircraft, "aircraft")
|
||||||
.speed(40f, 100)
|
.speed(40f, 100)
|
||||||
.locationIcon(LocationIcon.CAR).navigationIcon(NavigationIcon.CAR)
|
.locationIcon(LocationIcon.CAR).navigationIcon(NavigationIcon.CAR)
|
||||||
.icon(R.drawable.ic_action_aircraft, R.drawable.map_action_aircraft,"ic_action_aircraft").setRouteService(RouteService.STRAIGHT)
|
.icon(R.drawable.ic_action_aircraft, R.drawable.map_action_aircraft, "ic_action_aircraft").setRouteService(RouteService.STRAIGHT)
|
||||||
.setRoutingProfile("STRAIGHT_LINE_MODE").description(R.string.base_profile_descr_aircraft).reg();
|
.setRoutingProfile("STRAIGHT_LINE_MODE").description(R.string.base_profile_descr_aircraft).reg();
|
||||||
|
|
||||||
public static final ApplicationMode SKI = createBase(R.string.app_mode_skiing, "ski")
|
public static final ApplicationMode SKI = createBase(R.string.app_mode_skiing, "ski")
|
||||||
.speed(1.38f, 15).arrivalDistance(60).offRouteDistance(50)
|
.speed(1.38f, 15).arrivalDistance(60).offRouteDistance(50)
|
||||||
.locationIcon(LocationIcon.BICYCLE).navigationIcon(NavigationIcon.CAR)
|
.locationIcon(LocationIcon.BICYCLE).navigationIcon(NavigationIcon.CAR)
|
||||||
.icon(R.drawable.ic_action_skiing, R.drawable.ic_action_skiing,"ic_action_skiing")
|
.icon(R.drawable.ic_action_skiing, R.drawable.ic_action_skiing, "ic_action_skiing")
|
||||||
.setRoutingProfile("ski").description(R.string.base_profile_descr_ski).reg();
|
.setRoutingProfile("ski").description(R.string.base_profile_descr_ski).reg();
|
||||||
|
|
||||||
private static class ApplicationModeBean {
|
private static class ApplicationModeBean {
|
||||||
@Expose String stringKey;
|
@Expose
|
||||||
@Expose String userProfileName;
|
String stringKey;
|
||||||
@Expose String parent;
|
@Expose
|
||||||
@Expose String iconName = "map_world_globe_dark";
|
String userProfileName;
|
||||||
@Expose ProfileIconColors iconColor = ProfileIconColors.DEFAULT;
|
@Expose
|
||||||
@Expose String routingProfile = null;
|
String parent;
|
||||||
@Expose RouteService routeService = RouteService.OSMAND;
|
@Expose
|
||||||
@Expose LocationIcon locationIcon = LocationIcon.DEFAULT;
|
String iconName = "map_world_globe_dark";
|
||||||
@Expose NavigationIcon navigationIcon = NavigationIcon.CAR;
|
@Expose
|
||||||
@Expose int order;
|
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() {
|
private static void initRegVisibility() {
|
||||||
|
@ -258,12 +268,12 @@ public class ApplicationMode {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApplicationModeBuilder locationIcon(LocationIcon locationIcon){
|
public ApplicationModeBuilder locationIcon(LocationIcon locationIcon) {
|
||||||
applicationMode.locationIcon = locationIcon;
|
applicationMode.locationIcon = locationIcon;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApplicationModeBuilder navigationIcon(NavigationIcon navigationIcon){
|
public ApplicationModeBuilder navigationIcon(NavigationIcon navigationIcon) {
|
||||||
applicationMode.navigationIcon = navigationIcon;
|
applicationMode.navigationIcon = navigationIcon;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -554,11 +564,13 @@ public class ApplicationMode {
|
||||||
return routingProfile;
|
return routingProfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@DrawableRes public int getIconRes() {
|
@DrawableRes
|
||||||
|
public int getIconRes() {
|
||||||
return iconRes;
|
return iconRes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@DrawableRes public int getMapIconRes() {
|
@DrawableRes
|
||||||
|
public int getMapIconRes() {
|
||||||
return iconMapRes;
|
return iconMapRes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -589,9 +601,9 @@ public class ApplicationMode {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void initDefaultSpeed(OsmandApplication app) {
|
private static void initDefaultSpeed(OsmandApplication app) {
|
||||||
for(ApplicationMode m : values) {
|
for (ApplicationMode m : values) {
|
||||||
float spd = app.getSettings().DEFAULT_SPEED.getModeValue(m);
|
float spd = app.getSettings().DEFAULT_SPEED.getModeValue(m);
|
||||||
if(spd > 0) {
|
if (spd > 0) {
|
||||||
m.defaultSpeed = spd;
|
m.defaultSpeed = spd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -650,7 +662,8 @@ public class ApplicationMode {
|
||||||
|
|
||||||
private static void initDefaultModesParams(OsmandApplication app) {
|
private static void initDefaultModesParams(OsmandApplication app) {
|
||||||
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
|
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);
|
List<ApplicationModeBean> defaultAppModeBeans = gson.fromJson(app.getSettings().DEFAULT_APP_PROFILES.get(), t);
|
||||||
|
|
||||||
if (!Algorithms.isEmpty(defaultAppModeBeans)) {
|
if (!Algorithms.isEmpty(defaultAppModeBeans)) {
|
||||||
|
@ -670,9 +683,10 @@ public class ApplicationMode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void initCustomModes(OsmandApplication app){
|
private static void initCustomModes(OsmandApplication app) {
|
||||||
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
|
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);
|
List<ApplicationModeBean> customProfiles = gson.fromJson(app.getSettings().CUSTOM_APP_PROFILES.get(), t);
|
||||||
|
|
||||||
if (!Algorithms.isEmpty(customProfiles)) {
|
if (!Algorithms.isEmpty(customProfiles)) {
|
||||||
|
@ -804,17 +818,20 @@ public class ApplicationMode {
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum ProfileIconColors {
|
public enum ProfileIconColors {
|
||||||
DEFAULT(R.string.rendering_value_default_name, R.color.profile_icon_color_blue_light_default, R.color.profile_icon_color_blue_dark_default),
|
DEFAULT(R.string.rendering_value_default_name, R.color.profile_icon_color_blue_light_default, R.color.profile_icon_color_blue_dark_default),
|
||||||
PURPLE(R.string.rendering_value_purple_name, R.color.profile_icon_color_purple_light, R.color.profile_icon_color_purple_dark),
|
PURPLE(R.string.rendering_value_purple_name, R.color.profile_icon_color_purple_light, R.color.profile_icon_color_purple_dark),
|
||||||
GREEN(R.string.rendering_value_green_name, R.color.profile_icon_color_green_light, R.color.profile_icon_color_green_dark),
|
GREEN(R.string.rendering_value_green_name, R.color.profile_icon_color_green_light, R.color.profile_icon_color_green_dark),
|
||||||
BLUE(R.string.rendering_value_blue_name, R.color.profile_icon_color_blue_light, R.color.profile_icon_color_blue_dark),
|
BLUE(R.string.rendering_value_blue_name, R.color.profile_icon_color_blue_light, R.color.profile_icon_color_blue_dark),
|
||||||
RED(R.string.rendering_value_red_name, R.color.profile_icon_color_red_light, R.color.profile_icon_color_red_dark),
|
RED(R.string.rendering_value_red_name, R.color.profile_icon_color_red_light, R.color.profile_icon_color_red_dark),
|
||||||
DARK_YELLOW(R.string.rendering_value_darkyellow_name, R.color.profile_icon_color_yellow_light, R.color.profile_icon_color_yellow_dark),
|
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);
|
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;
|
@StringRes
|
||||||
@ColorRes private int dayColor;
|
private int name;
|
||||||
@ColorRes private int nightColor;
|
@ColorRes
|
||||||
|
private int dayColor;
|
||||||
|
@ColorRes
|
||||||
|
private int nightColor;
|
||||||
|
|
||||||
ProfileIconColors(@StringRes int name, @ColorRes int dayColor, @ColorRes int nightColor) {
|
ProfileIconColors(@StringRes int name, @ColorRes int dayColor, @ColorRes int nightColor) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
@ -902,12 +919,12 @@ public class ApplicationMode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum LocationIcon{
|
public enum LocationIcon {
|
||||||
DEFAULT(R.drawable.map_default_location_xml,R.drawable.map_default_location_view_angle),
|
DEFAULT(R.drawable.map_default_location_xml, R.drawable.map_default_location_view_angle),
|
||||||
CAR(R.drawable.map_car_location_xml,R.drawable.map_car_location_view_angle),
|
CAR(R.drawable.map_car_location_xml, R.drawable.map_car_location_view_angle),
|
||||||
BICYCLE(R.drawable.map_bicycle_location_xml,R.drawable.map_bicycle_location_view_angle);
|
BICYCLE(R.drawable.map_bicycle_location_xml, R.drawable.map_bicycle_location_view_angle);
|
||||||
|
|
||||||
LocationIcon(@DrawableRes int iconId, @DrawableRes int headingIconId){
|
LocationIcon(@DrawableRes int iconId, @DrawableRes int headingIconId) {
|
||||||
this.iconId = iconId;
|
this.iconId = iconId;
|
||||||
this.headingIconId = headingIconId;
|
this.headingIconId = headingIconId;
|
||||||
}
|
}
|
||||||
|
@ -920,16 +937,17 @@ public class ApplicationMode {
|
||||||
public int getIconId() {
|
public int getIconId() {
|
||||||
return iconId;
|
return iconId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getHeadingIconId() {
|
public int getHeadingIconId() {
|
||||||
return headingIconId;
|
return headingIconId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum NavigationIcon{
|
public enum NavigationIcon {
|
||||||
CAR(R.drawable.map_car_navigation_xml),
|
CAR(R.drawable.map_car_navigation_xml),
|
||||||
NAUTICAL(R.drawable.map_nautical_navigation_xml);
|
NAUTICAL(R.drawable.map_nautical_navigation_xml);
|
||||||
|
|
||||||
NavigationIcon(@DrawableRes int iconId){
|
NavigationIcon(@DrawableRes int iconId) {
|
||||||
this.iconId = iconId;
|
this.iconId = iconId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -491,7 +491,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
|
||||||
int changedProfileColor = ContextCompat.getColor(app, changedProfile.color.getColor(
|
int changedProfileColor = ContextCompat.getColor(app, changedProfile.color.getColor(
|
||||||
app.getDaynightHelper().isNightModeForMapControls()));
|
app.getDaynightHelper().isNightModeForMapControls()));
|
||||||
LayerDrawable locationIconDrawable = (LayerDrawable) app.getResources().getDrawable(locationIcon.getIconId());
|
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);
|
locationIconView.<ImageView>findViewById(R.id.icon).setImageDrawable(locationIconDrawable);
|
||||||
ImageView headingIcon = locationIconView.findViewById(R.id.headingIcon);
|
ImageView headingIcon = locationIconView.findViewById(R.id.headingIcon);
|
||||||
headingIcon.setImageDrawable(ContextCompat.getDrawable(app, locationIcon.getHeadingIconId()));
|
headingIcon.setImageDrawable(ContextCompat.getDrawable(app, locationIcon.getHeadingIconId()));
|
||||||
|
@ -531,8 +531,8 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
|
||||||
FrameLayout navigationIconView = (FrameLayout) UiUtilities.getInflater(getContext(), isNightMode())
|
FrameLayout navigationIconView = (FrameLayout) UiUtilities.getInflater(getContext(), isNightMode())
|
||||||
.inflate(R.layout.preference_select_icon_button, rootView, false);
|
.inflate(R.layout.preference_select_icon_button, rootView, false);
|
||||||
LayerDrawable navigationIconDrawable = (LayerDrawable) app.getResources().getDrawable(navigationIcon.getIconId());
|
LayerDrawable navigationIconDrawable = (LayerDrawable) app.getResources().getDrawable(navigationIcon.getIconId());
|
||||||
DrawableCompat.setTint(navigationIconDrawable.getDrawable(1), ContextCompat.getColor(app, changedProfile.color.getColor(
|
DrawableCompat.setTint(DrawableCompat.wrap(navigationIconDrawable.getDrawable(1)),
|
||||||
app.getDaynightHelper().isNightModeForMapControls())));
|
ContextCompat.getColor(app, changedProfile.color.getColor(app.getDaynightHelper().isNightModeForMapControls())));
|
||||||
ImageView imageView = navigationIconView.findViewById(R.id.icon);
|
ImageView imageView = navigationIconView.findViewById(R.id.icon);
|
||||||
imageView.setImageDrawable(navigationIconDrawable);
|
imageView.setImageDrawable(navigationIconDrawable);
|
||||||
Matrix matrix = new Matrix();
|
Matrix matrix = new Matrix();
|
||||||
|
|
|
@ -165,7 +165,7 @@ public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLay
|
||||||
headingIcon = BitmapFactory.decodeResource(view.getResources(), appMode.getLocationIcon().getHeadingIconId());
|
headingIcon = BitmapFactory.decodeResource(view.getResources(), appMode.getLocationIcon().getHeadingIconId());
|
||||||
headingPaint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN));
|
headingPaint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN));
|
||||||
locationIcon = (LayerDrawable) view.getResources().getDrawable(appMode.getLocationIcon().getIconId());
|
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));
|
area.setColor(UiUtilities.getColorWithAlpha(color, 0.16f));
|
||||||
aroundArea.setColor(color);
|
aroundArea.setColor(color);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue