Change button icon color on tap in map markers context menu

This commit is contained in:
Alexander Sytnyk 2018-01-15 13:05:24 +02:00
parent a7ee6cb942
commit b8ec9b1dfd
4 changed files with 38 additions and 33 deletions

View file

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@color/osmand_orange"/>
</shape>
</item>
<item android:drawable="@drawable/ic_action_marker_passed"/>
</layer-list>

View file

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@color/map_widget_blue"/>
</shape>
</item>
<item android:drawable="@drawable/ic_action_marker_passed"/>
</layer-list>

View file

@ -325,11 +325,11 @@
<color name="ctx_menu_controller_button_outline_color_light_n">#e6e6e6</color>
<color name="ctx_menu_controller_button_outline_color_light_p">#4c63e6</color>
<color name="ctx_menu_controller_button_outline_color_dark_n">#2d3133</color>
<color name="ctx_menu_controller_button_outline_color_dark_p">#b36a0b</color>
<color name="ctx_menu_controller_button_outline_color_dark_p">#d28521</color>
<color name="ctx_menu_controller_button_bg_color_light_n">#fafafa</color>
<color name="ctx_menu_controller_button_bg_color_light_p">#6d82fc</color>
<color name="ctx_menu_controller_button_bg_color_dark_n">#222526</color>
<color name="ctx_menu_controller_button_bg_color_dark_p">#d28521</color>
<color name="ctx_menu_controller_button_bg_color_dark_p">#b36a0b</color>
<color name="ctx_menu_buttons_bg_light">#f2f2f2</color>
<color name="ctx_menu_buttons_bg_dark">#222526</color>
<color name="ctx_menu_buttons_divider_light">#e6e6e6</color>

View file

@ -2,9 +2,13 @@ package net.osmand.plus.mapcontextmenu.controllers;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.StateListDrawable;
import android.graphics.drawable.shapes.OvalShape;
import android.support.v4.content.ContextCompat;
import net.osmand.AndroidUtils;
import net.osmand.data.PointDescription;
import net.osmand.plus.IconsCache;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmandApplication;
@ -34,9 +38,8 @@ public class MapMarkerMenuController extends MenuController {
getMapActivity().getContextMenu().close();
}
};
leftTitleButtonController.needColorizeIcon = false;
leftTitleButtonController.caption = getMapActivity().getString(R.string.mark_passed);
leftTitleButtonController.leftIconId = isLight() ? R.drawable.passed_icon_light : R.drawable.passed_icon_dark;
leftTitleButtonController.leftIcon = createStateListPassedIcon();
rightTitleButtonController = new TitleButtonController() {
@Override
@ -51,14 +54,38 @@ public class MapMarkerMenuController extends MenuController {
}
};
rightTitleButtonController.caption = getMapActivity().getString(R.string.make_active);
rightTitleButtonController.leftIcon = createShowOnTopbarIcon();
rightTitleButtonController.leftIcon = createStateListShowOnTopbarIcon();
}
private Drawable createShowOnTopbarIcon() {
IconsCache ic = getMapActivity().getMyApplication().getIconsCache();
Drawable background = ic.getIcon(R.drawable.ic_action_device_top,
isLight() ? R.color.on_map_icon_color : R.color.ctx_menu_info_text_dark);
Drawable topbar = ic.getIcon(R.drawable.ic_action_device_topbar, R.color.dashboard_blue);
private StateListDrawable createStateListPassedIcon() {
int bgNormal = isLight() ? R.color.map_widget_blue : R.color.osmand_orange;
int bgPressed = isLight() ? R.color.ctx_menu_controller_button_text_color_light_p
: R.color.ctx_menu_controller_button_text_color_dark_p;
int icPressed = isLight() ? R.color.ctx_menu_controller_button_text_color_light_n
: R.color.ctx_menu_controller_button_bg_color_dark_p;
return AndroidUtils.createStateListDrawable(createPassedIcon(bgNormal, 0),
createPassedIcon(bgPressed, icPressed));
}
private LayerDrawable createPassedIcon(int bgColorRes, int icColorRes) {
ShapeDrawable bg = new ShapeDrawable(new OvalShape());
bg.getPaint().setColor(ContextCompat.getColor(getMapActivity(), bgColorRes));
Drawable ic = getIcon(R.drawable.ic_action_marker_passed, icColorRes);
return new LayerDrawable(new Drawable[]{bg, ic});
}
private StateListDrawable createStateListShowOnTopbarIcon() {
int bgNormal = isLight() ? R.color.on_map_icon_color : R.color.ctx_menu_info_text_dark;
int bgPressed = isLight() ? R.color.ctx_menu_controller_button_text_color_light_p
: R.color.ctx_menu_controller_button_text_color_dark_p;
int icPressed = isLight() ? R.color.osmand_orange : R.color.route_info_go_btn_bg_dark_p;
return AndroidUtils.createStateListDrawable(createShowOnTopbarIcon(bgNormal, R.color.dashboard_blue),
createShowOnTopbarIcon(bgPressed, icPressed));
}
private LayerDrawable createShowOnTopbarIcon(int bgColorRes, int icColorRes) {
Drawable background = getIcon(R.drawable.ic_action_device_top, bgColorRes);
Drawable topbar = getIcon(R.drawable.ic_action_device_topbar, icColorRes);
return new LayerDrawable(new Drawable[]{background, topbar});
}