From f09c1f8d747bba8f41a6201a363152c902032461 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Fri, 10 Jan 2020 19:03:50 +0200 Subject: [PATCH] Implement new colored location icon on map --- OsmAnd/res/drawable/bg_select_icon_button.xml | 6 ++ .../bg_select_icon_button_outline.xml | 9 ++ .../res/drawable/map_bicycle_location_xml.xml | 18 ++++ OsmAnd/res/drawable/map_car_location_xml.xml | 18 ++++ .../res/drawable/map_default_location_xml.xml | 18 ++++ OsmAnd/res/layout/preference_circle_item.xml | 2 +- OsmAnd/res/layout/preference_color_select.xml | 2 +- .../layout/preference_select_icon_button.xml | 21 ++++ OsmAnd/res/xml/profile_appearance.xml | 11 +- .../src/net/osmand/plus/ApplicationMode.java | 100 +++++++++--------- .../settings/ProfileAppearanceFragment.java | 46 +++++++- .../osmand/plus/views/PointLocationLayer.java | 71 ++++++++----- 12 files changed, 234 insertions(+), 88 deletions(-) create mode 100644 OsmAnd/res/drawable/bg_select_icon_button.xml create mode 100644 OsmAnd/res/drawable/bg_select_icon_button_outline.xml create mode 100644 OsmAnd/res/drawable/map_bicycle_location_xml.xml create mode 100644 OsmAnd/res/drawable/map_car_location_xml.xml create mode 100644 OsmAnd/res/drawable/map_default_location_xml.xml create mode 100644 OsmAnd/res/layout/preference_select_icon_button.xml diff --git a/OsmAnd/res/drawable/bg_select_icon_button.xml b/OsmAnd/res/drawable/bg_select_icon_button.xml new file mode 100644 index 0000000000..f037ae97e1 --- /dev/null +++ b/OsmAnd/res/drawable/bg_select_icon_button.xml @@ -0,0 +1,6 @@ + + + + + diff --git a/OsmAnd/res/drawable/bg_select_icon_button_outline.xml b/OsmAnd/res/drawable/bg_select_icon_button_outline.xml new file mode 100644 index 0000000000..4b004aee51 --- /dev/null +++ b/OsmAnd/res/drawable/bg_select_icon_button_outline.xml @@ -0,0 +1,9 @@ + + + + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/map_bicycle_location_xml.xml b/OsmAnd/res/drawable/map_bicycle_location_xml.xml new file mode 100644 index 0000000000..0065008710 --- /dev/null +++ b/OsmAnd/res/drawable/map_bicycle_location_xml.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/map_car_location_xml.xml b/OsmAnd/res/drawable/map_car_location_xml.xml new file mode 100644 index 0000000000..7fec9f8839 --- /dev/null +++ b/OsmAnd/res/drawable/map_car_location_xml.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/map_default_location_xml.xml b/OsmAnd/res/drawable/map_default_location_xml.xml new file mode 100644 index 0000000000..ed1f37c833 --- /dev/null +++ b/OsmAnd/res/drawable/map_default_location_xml.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/preference_circle_item.xml b/OsmAnd/res/layout/preference_circle_item.xml index d6a3c6492b..54b61fe671 100644 --- a/OsmAnd/res/layout/preference_circle_item.xml +++ b/OsmAnd/res/layout/preference_circle_item.xml @@ -3,7 +3,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:padding="6dp"> + android:padding="7dp"> + android:layout_margin="4dp" /> \ No newline at end of file diff --git a/OsmAnd/res/layout/preference_select_icon_button.xml b/OsmAnd/res/layout/preference_select_icon_button.xml new file mode 100644 index 0000000000..702a83ad84 --- /dev/null +++ b/OsmAnd/res/layout/preference_select_icon_button.xml @@ -0,0 +1,21 @@ + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/xml/profile_appearance.xml b/OsmAnd/res/xml/profile_appearance.xml index 067429aaa9..f32a758ee3 100644 --- a/OsmAnd/res/xml/profile_appearance.xml +++ b/OsmAnd/res/xml/profile_appearance.xml @@ -49,15 +49,15 @@ android:layout="@layout/simple_divider_item" android:selectable="false" /> - + android:selectable="false"/> \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/ApplicationMode.java b/OsmAnd/src/net/osmand/plus/ApplicationMode.java index b1bae228da..8fa09ae1ef 100644 --- a/OsmAnd/src/net/osmand/plus/ApplicationMode.java +++ b/OsmAnd/src/net/osmand/plus/ApplicationMode.java @@ -79,13 +79,13 @@ public class ApplicationMode { private int arrivalDistance = 90; private int offRouteDistance = 350; private int bearingIconDay = R.drawable.map_pedestrian_bearing; - private int bearingIconNight = R.drawable.map_pedestrian_bearing_night; +// private int bearingIconNight = R.drawable.map_pedestrian_bearing_night; private int headingIconDay = R.drawable.map_pedestrian_location_view_angle; - private int headingIconNight = R.drawable.map_pedestrian_location_view_angle_night; - private int locationIconDay = R.drawable.map_pedestrian_location; - private int locationIconNight = R.drawable.map_pedestrian_location_night; - private int locationIconDayLost = R.drawable.map_pedestrian_location_lost; - private int locationIconNightLost = R.drawable.map_pedestrian_location_lost_night; +// private int headingIconNight = R.drawable.map_pedestrian_location_view_angle_night; + private int locationIcon = R.drawable.map_default_location_xml; +// private int locationIconNight = R.drawable.map_pedestrian_location_night; +// private int locationIconDayLost = R.drawable.map_pedestrian_location_lost; +// private int locationIconNightLost = R.drawable.map_pedestrian_location_lost_night; private ApplicationMode(int key, String stringKey) { this.keyName = key; @@ -207,13 +207,13 @@ public class ApplicationMode { m.arrivalDistance = m.parentAppMode.arrivalDistance; m.offRouteDistance = m.parentAppMode.offRouteDistance; m.bearingIconDay = m.parentAppMode.bearingIconDay; - m.bearingIconNight = m.parentAppMode.bearingIconNight; +// m.bearingIconNight = m.parentAppMode.bearingIconNight; m.headingIconDay = m.parentAppMode.headingIconDay; - m.headingIconNight = m.parentAppMode.headingIconNight; - m.locationIconDay = m.parentAppMode.locationIconDay; - m.locationIconNight = m.parentAppMode.locationIconNight; - m.locationIconDayLost = m.parentAppMode.locationIconDayLost; - m.locationIconNightLost = m.parentAppMode.locationIconNightLost; +// m.headingIconNight = m.parentAppMode.headingIconNight; + m.locationIcon = m.parentAppMode.locationIcon; +// m.locationIconNight = m.parentAppMode.locationIconNight; +// m.locationIconDayLost = m.parentAppMode.locationIconDayLost; +// m.locationIconNightLost = m.parentAppMode.locationIconNightLost; values.add(applicationMode); if (applicationMode.getOrder() == 0 && !values.isEmpty()) { applicationMode.setOrder(values.size()); @@ -264,47 +264,47 @@ public class ApplicationMode { public ApplicationModeBuilder carLocation() { applicationMode.bearingIconDay = R.drawable.map_car_bearing; - applicationMode.bearingIconNight = R.drawable.map_car_bearing_night; +// applicationMode.bearingIconNight = R.drawable.map_car_bearing_night; applicationMode.headingIconDay = R.drawable.map_car_location_view_angle; - applicationMode.headingIconNight = R.drawable.map_car_location_view_angle_night; - applicationMode.locationIconDay = R.drawable.map_car_location; - applicationMode.locationIconNight = R.drawable.map_car_location_night; - applicationMode.locationIconDayLost = R.drawable.map_car_location_lost; - applicationMode.locationIconNightLost = R.drawable.map_car_location_lost_night; +// applicationMode.headingIconNight = R.drawable.map_car_location_view_angle_night; + applicationMode.locationIcon = R.drawable.map_car_location_xml; +// applicationMode.locationIconNight = R.drawable.map_car_location_night; +// applicationMode.locationIconDayLost = R.drawable.map_car_location_lost; +// applicationMode.locationIconNightLost = R.drawable.map_car_location_lost_night; return this; } public ApplicationModeBuilder bicycleLocation() { applicationMode.bearingIconDay = R.drawable.map_bicycle_bearing; - applicationMode.bearingIconNight = R.drawable.map_bicycle_bearing_night; +// applicationMode.bearingIconNight = R.drawable.map_bicycle_bearing_night; applicationMode.headingIconDay = R.drawable.map_bicycle_location_view_angle; - applicationMode.headingIconNight = R.drawable.map_bicycle_location_view_angle_night; - applicationMode.locationIconDay = R.drawable.map_bicycle_location; - applicationMode.locationIconNight = R.drawable.map_bicycle_location_night; - applicationMode.locationIconDayLost = R.drawable.map_bicycle_location_lost; - applicationMode.locationIconNightLost = R.drawable.map_bicycle_location_lost_night; +// applicationMode.headingIconNight = R.drawable.map_bicycle_location_view_angle_night; + applicationMode.locationIcon = R.drawable.map_bicycle_location_xml; +// applicationMode.locationIconNight = R.drawable.map_bicycle_location_night; +// applicationMode.locationIconDayLost = R.drawable.map_bicycle_location_lost; +// applicationMode.locationIconNightLost = R.drawable.map_bicycle_location_lost_night; return this; } public ApplicationModeBuilder defLocation() { applicationMode.bearingIconDay = R.drawable.map_pedestrian_bearing; - applicationMode.bearingIconNight = R.drawable.map_pedestrian_bearing_night; +// applicationMode.bearingIconNight = R.drawable.map_pedestrian_bearing_night; applicationMode.headingIconDay = R.drawable.map_default_location_view_angle; - applicationMode.headingIconNight = R.drawable.map_default_location_view_angle_night; - applicationMode.locationIconDay = R.drawable.map_pedestrian_location; - applicationMode.locationIconNight = R.drawable.map_pedestrian_location_night; - applicationMode.locationIconDayLost = R.drawable.map_pedestrian_location_lost; - applicationMode.locationIconNightLost = R.drawable.map_pedestrian_location_lost_night; +// applicationMode.headingIconNight = R.drawable.map_default_location_view_angle_night; + applicationMode.locationIcon = R.drawable.map_default_location_xml; +// applicationMode.locationIconNight = R.drawable.map_pedestrian_location_night; +// applicationMode.locationIconDayLost = R.drawable.map_pedestrian_location_lost; +// applicationMode.locationIconNightLost = R.drawable.map_pedestrian_location_lost_night; return this; } public ApplicationModeBuilder nauticalLocation() { applicationMode.bearingIconDay = R.drawable.map_nautical_bearing; - applicationMode.bearingIconNight = R.drawable.map_nautical_bearing_night; +// applicationMode.bearingIconNight = R.drawable.map_nautical_bearing_night; applicationMode.headingIconDay = R.drawable.map_nautical_location_view_angle; - applicationMode.headingIconNight = R.drawable.map_nautical_location_view_angle_night; - applicationMode.locationIconDay = R.drawable.map_nautical_location; - applicationMode.locationIconNight = R.drawable.map_nautical_location_night; +// applicationMode.headingIconNight = R.drawable.map_nautical_location_view_angle_night; + applicationMode.locationIcon = R.drawable.map_nautical_location; +// applicationMode.locationIconNight = R.drawable.map_nautical_location_night; return this; } @@ -512,33 +512,33 @@ public class ApplicationMode { return bearingIconDay; } - public int getResourceBearingNight() { - return bearingIconNight; - } +// public int getResourceBearingNight() { +// return bearingIconNight; +// } public int getResourceHeadingDay() { return headingIconDay; } - public int getResourceHeadingNight() { - return headingIconNight; - } +// public int getResourceHeadingNight() { +// return headingIconNight; +// } public int getResourceLocationDay() { - return locationIconDay; + return locationIcon; } - public int getResourceLocationNight() { - return locationIconNight; - } +// public int getResourceLocationNight() { +// return locationIconNight; +// } - public int getResourceLocationDayLost() { - return locationIconDayLost; - } +// public int getResourceLocationDayLost() { +// return locationIconDayLost; +// } - public int getResourceLocationNightLost() { - return locationIconNightLost; - } +// public int getResourceLocationNightLost() { +// return locationIconNightLost; +// } public String getStringKey() { return stringKey; diff --git a/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java index d90ae9a914..231551b259 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java @@ -60,8 +60,10 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { private static final String SELECT_ICON = "select_icon"; private static final String COLOR_ITEMS = "color_items"; private static final String ICON_ITEMS = "icon_items"; -// private static final String SELECT_MAP_ICON = "select_map_icon"; -// private static final String SELECT_NAV_ICON = "select_nav_icon"; + private static final String SELECT_MAP_ICON = "select_map_icon"; + private static final String MAP_ICON_ITEMS = "map_icon_items"; + private static final String SELECT_NAV_ICON = "select_nav_icon"; + private static final String NAV_ICON_ITEMS = "nav_icon_items"; public static final String PROFILE_NAME_KEY = "profile_name_key"; public static final String PROFILE_STRINGKEY_KEY = "profile_stringkey_key"; @@ -76,6 +78,8 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { private EditText profileName; private FlowLayout colorItems; private FlowLayout iconItems; + private FlowLayout mapIconItems; + private FlowLayout navIconItems; private OsmandTextFieldBoxes profileNameOtfb; private View saveButton; @@ -166,8 +170,8 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { protected void setupPreferences() { findPreference(SELECT_COLOR).setIconSpaceReserved(false); findPreference(SELECT_ICON).setIconSpaceReserved(false); -// findPreference(SELECT_MAP_ICON).setIconSpaceReserved(false); -// findPreference(SELECT_NAV_ICON).setIconSpaceReserved(false); + findPreference(SELECT_MAP_ICON).setIconSpaceReserved(false); + findPreference(SELECT_NAV_ICON).setIconSpaceReserved(false); } @SuppressLint("InlinedApi") @@ -370,6 +374,40 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { outlineCircle.setVisibility(View.GONE); } setIconNewColor(changedProfile.iconRes); + } else if (MAP_ICON_ITEMS.equals(preference.getKey())) { + mapIconItems = (FlowLayout) holder.findViewById(R.id.color_items); + mapIconItems.removeAllViews(); + ArrayList icons = ApplicationMode.ProfileIcons.getIcons(); + for(int iconRes:icons) { + FrameLayout iconItemView = (FrameLayout) UiUtilities.getInflater(getContext(), isNightMode()) + .inflate(R.layout.preference_select_icon_button, mapIconItems, false); + mapIconItems.addView(iconItemView, new FlowLayout.LayoutParams(0, 0)); + ImageView coloredRect = mapIconItems.findViewById(R.id.backgroundRect); + AndroidUtils.setBackground(coloredRect, + UiUtilities.tintDrawable(ContextCompat.getDrawable(app, R.drawable.bg_select_icon_button), + UiUtilities.getColorWithAlpha(ContextCompat.getColor(app, R.color.icon_color_default_light), 0.1f))); + coloredRect.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { +// if (iconRes != changedProfile.iconRes) { +// updateIconSelector(iconRes); +// } + } + }); + + ImageView outlineCircle = mapIconItems.findViewById(R.id.outlineRect); + GradientDrawable circleContourDrawable = (GradientDrawable) ContextCompat.getDrawable(app, R.drawable.bg_select_icon_button_outline); + int changedProfileColor = ContextCompat.getColor(app, changedProfile.color.getColor( + app.getDaynightHelper().isNightModeForMapControls())); + if (circleContourDrawable != null) { + circleContourDrawable.setStroke(AndroidUtils.dpToPx(app, 2), changedProfileColor); + } + outlineCircle.setImageDrawable(circleContourDrawable); + outlineCircle.setVisibility(View.VISIBLE); + } + + } else if (NAV_ICON_ITEMS.equals(preference.getKey())) { + } } diff --git a/OsmAnd/src/net/osmand/plus/views/PointLocationLayer.java b/OsmAnd/src/net/osmand/plus/views/PointLocationLayer.java index 01f73e39a3..e031ac3e9a 100644 --- a/OsmAnd/src/net/osmand/plus/views/PointLocationLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/PointLocationLayer.java @@ -7,7 +7,12 @@ import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Paint.Style; import android.graphics.PointF; +import android.graphics.PorterDuff; +import android.graphics.PorterDuffColorFilter; import android.graphics.RectF; +import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.LayerDrawable; +import android.support.v4.content.ContextCompat; import net.osmand.Location; import net.osmand.PlatformUtil; @@ -23,6 +28,9 @@ import org.apache.commons.logging.Log; import java.util.List; +import static android.graphics.Paint.ANTI_ALIAS_FLAG; +import static android.graphics.Paint.FILTER_BITMAP_FLAG; + public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider { private static final Log LOG = PlatformUtil.getLog(PointLocationLayer.class); @@ -30,15 +38,19 @@ public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLay protected final static int RADIUS = 7; private Paint locationPaint; + private Paint headingPaint; private Paint area; private Paint aroundArea; private OsmandMapTileView view; private ApplicationMode appMode; + private int color; private Bitmap bearingIcon; private Bitmap headingIcon; - private Bitmap locationIcon; + private Bitmap locationIconCenter; + private Bitmap locationIconTop; + private Bitmap locationIconBottom; private OsmAndLocationProvider locationProvider; private MapViewTrackingUtilities mapViewTrackingUtilities; private boolean nm; @@ -53,6 +65,9 @@ public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLay locationPaint.setAntiAlias(true); locationPaint.setFilterBitmap(true); + headingPaint = new Paint(ANTI_ALIAS_FLAG | FILTER_BITMAP_FLAG); + + area = new Paint(); area.setColor(view.getResources().getColor(R.color.pos_area)); @@ -119,7 +134,7 @@ public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLay canvas.save(); canvas.rotate(heading - 180, locationX, locationY); canvas.drawBitmap(headingIcon, locationX - headingIcon.getWidth() / 2, - locationY - headingIcon.getHeight() / 2, locationPaint); + locationY - headingIcon.getHeight() / 2, headingPaint); canvas.restore(); } @@ -131,8 +146,18 @@ public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLay canvas.drawBitmap(bearingIcon, locationX - bearingIcon.getWidth() / 2, locationY - bearingIcon.getHeight() / 2, locationPaint); } else { - canvas.drawBitmap(locationIcon, locationX - locationIcon.getWidth() / 2, - locationY - locationIcon.getHeight() / 2, locationPaint); + if (locationIconTop != null) { + canvas.drawBitmap(locationIconTop, locationX - locationIconCenter.getWidth() / 2, + locationY - locationIconCenter.getHeight() / 2, headingPaint); + } + if (locationIconCenter != null) { + canvas.drawBitmap(locationIconCenter, locationX - locationIconCenter.getWidth() / 2, + locationY - locationIconCenter.getHeight() / 2, locationPaint); + } + if (locationIconBottom != null) { + canvas.drawBitmap(locationIconBottom, locationX - locationIconCenter.getWidth() / 2, + locationY - locationIconCenter.getHeight() / 2, headingPaint); + } } } @@ -147,32 +172,24 @@ public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLay public void destroyLayer() { } - public void updateIcons(ApplicationMode appMode, boolean nighMode, boolean locationOutdated) { - if (appMode != this.appMode || this.nm != nighMode || this.locationOutdated != locationOutdated) { + private void updateIcons(ApplicationMode appMode, boolean nighMode, boolean locationOutdated) { + if (appMode != this.appMode || this.nm != nighMode || this.locationOutdated != locationOutdated || + color != appMode.getIconColorInfo().getColor(nighMode)) { this.appMode = appMode; + this.color = appMode.getIconColorInfo().getColor(nighMode); this.nm = nighMode; this.locationOutdated = locationOutdated; - final int resourceBearingDay = appMode.getResourceBearingDay(); - final int resourceBearingNight = appMode.getResourceBearingNight(); - final int resourceBearing = nighMode ? resourceBearingNight : resourceBearingDay; - bearingIcon = BitmapFactory.decodeResource(view.getResources(), resourceBearing); - - final int resourceHeadingDay = appMode.getResourceHeadingDay(); - final int resourceHeadingNight = appMode.getResourceHeadingNight(); - final int resourceHeading = nighMode ? resourceHeadingNight : resourceHeadingDay; - headingIcon = BitmapFactory.decodeResource(view.getResources(), resourceHeading); - - final int resourceLocationDay; - final int resourceLocationNight; - if (locationOutdated) { - resourceLocationDay = appMode.getResourceLocationDayLost(); - resourceLocationNight = appMode.getResourceLocationNightLost(); - } else { - resourceLocationDay = appMode.getResourceLocationDay(); - resourceLocationNight = appMode.getResourceLocationNight(); - } - final int resourceLocation = nighMode ? resourceLocationNight : resourceLocationDay; - locationIcon = BitmapFactory.decodeResource(view.getResources(), resourceLocation); + bearingIcon = BitmapFactory.decodeResource(view.getResources(), appMode.getResourceBearingDay()); + headingIcon = BitmapFactory.decodeResource(view.getResources(), appMode.getResourceHeadingDay()); + final int resourceLocation = appMode.getResourceLocationDay(); + locationPaint.setColorFilter(new PorterDuffColorFilter(ContextCompat.getColor(view.getContext(), color), + PorterDuff.Mode.SRC_IN)); + LayerDrawable layerDrawable = (LayerDrawable) ContextCompat.getDrawable(view.getContext(), resourceLocation); + if (layerDrawable != null) { + locationIconTop = ((BitmapDrawable) layerDrawable.getDrawable(0)).getBitmap(); + locationIconCenter = ((BitmapDrawable) layerDrawable.getDrawable(1)).getBitmap(); + locationIconBottom = ((BitmapDrawable) layerDrawable.getDrawable(2)).getBitmap(); + } area.setColor(view.getResources().getColor(!nm ? R.color.pos_area : R.color.pos_area_night)); } }