From 3a9c9d3be76d08a781447335ed100058e3b120d8 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Thu, 18 Jan 2018 13:58:20 +0200 Subject: [PATCH] Do not use StateListDrawable with API < 21 --- .../plus/mapcontextmenu/MenuController.java | 10 +++++---- .../builders/AmenityMenuBuilder.java | 4 +++- .../controllers/MapMarkerMenuController.java | 22 ++++++++++++++----- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java index 4bda4d120e..c02974f397 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java @@ -3,6 +3,7 @@ package net.osmand.plus.mapcontextmenu; import android.graphics.drawable.Drawable; import android.graphics.drawable.StateListDrawable; import android.os.AsyncTask; +import android.os.Build; import android.support.annotation.DrawableRes; import android.support.annotation.NonNull; import android.support.annotation.Nullable; @@ -594,12 +595,13 @@ public abstract class MenuController extends BaseMenuController { } public void updateStateListDrawableIcon(@DrawableRes int resId, boolean left) { + boolean useStateList = enabled && Build.VERSION.SDK_INT >= 21; if (left) { - leftIcon = enabled ? getStateListDrawable(resId) : null; - leftIconId = enabled ? 0 : resId; + leftIcon = useStateList ? getStateListDrawable(resId) : null; + leftIconId = useStateList ? 0 : resId; } else { - rightIcon = enabled ? getStateListDrawable(resId) : null; - rightIconId = enabled ? 0 : resId; + rightIcon = useStateList ? getStateListDrawable(resId) : null; + rightIconId = useStateList ? 0 : resId; } } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java index 6fec9e2f51..5d716cc754 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java @@ -5,6 +5,7 @@ import android.content.Intent; import android.content.res.ColorStateList; import android.graphics.drawable.Drawable; import android.net.Uri; +import android.os.Build; import android.support.v7.app.AlertDialog; import android.support.v7.view.ContextThemeWrapper; import android.text.Html; @@ -238,7 +239,8 @@ public class AmenityMenuBuilder extends MenuBuilder { light ? R.color.ctx_menu_controller_button_text_color_light_n : R.color.ctx_menu_controller_button_text_color_dark_n); Drawable pressed = app.getIconsCache().getIcon(R.drawable.ic_action_read_text, light ? R.color.ctx_menu_controller_button_text_color_light_p : R.color.ctx_menu_controller_button_text_color_dark_p); - button.setCompoundDrawablesWithIntrinsicBounds(AndroidUtils.createStateListDrawable(normal, pressed), null, null, null); + button.setCompoundDrawablesWithIntrinsicBounds(Build.VERSION.SDK_INT >= 21 + ? AndroidUtils.createStateListDrawable(normal, pressed) : normal, null, null, null); button.setCompoundDrawablePadding(dpToPx(8f)); llText.addView(button); } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapMarkerMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapMarkerMenuController.java index 89c5474b7b..1fdd4a7a44 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapMarkerMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapMarkerMenuController.java @@ -5,6 +5,7 @@ import android.graphics.drawable.LayerDrawable; import android.graphics.drawable.ShapeDrawable; import android.graphics.drawable.StateListDrawable; import android.graphics.drawable.shapes.OvalShape; +import android.os.Build; import android.support.v4.content.ContextCompat; import net.osmand.AndroidUtils; @@ -27,6 +28,7 @@ public class MapMarkerMenuController extends MenuController { public MapMarkerMenuController(MapActivity mapActivity, PointDescription pointDescription, MapMarker mapMarker) { super(new MenuBuilder(mapActivity), pointDescription, mapActivity); final OsmandApplication app = mapActivity.getMyApplication(); + final boolean useStateList = Build.VERSION.SDK_INT >= 21; this.mapMarker = mapMarker; builder.setShowNearestWiki(true); @@ -39,7 +41,8 @@ public class MapMarkerMenuController extends MenuController { } }; leftTitleButtonController.caption = getMapActivity().getString(R.string.mark_passed); - leftTitleButtonController.leftIcon = createStateListPassedIcon(); + leftTitleButtonController.leftIcon = useStateList ? createStateListPassedIcon() + : createPassedIcon(getPassedIconBgNormalColorId(), 0); rightTitleButtonController = new TitleButtonController() { @Override @@ -54,16 +57,20 @@ public class MapMarkerMenuController extends MenuController { } }; rightTitleButtonController.caption = getMapActivity().getString(R.string.make_active); - rightTitleButtonController.leftIcon = createStateListShowOnTopbarIcon(); + rightTitleButtonController.leftIcon = useStateList ? createStateListShowOnTopbarIcon() + : createShowOnTopbarIcon(getDeviceTopNormalColorId(), R.color.dashboard_blue); + } + + private int getPassedIconBgNormalColorId() { + return isLight() ? R.color.map_widget_blue : R.color.osmand_orange; } 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), + return AndroidUtils.createStateListDrawable(createPassedIcon(getPassedIconBgNormalColorId(), 0), createPassedIcon(bgPressed, icPressed)); } @@ -74,12 +81,15 @@ public class MapMarkerMenuController extends MenuController { return new LayerDrawable(new Drawable[]{bg, ic}); } + private int getDeviceTopNormalColorId() { + return isLight() ? R.color.on_map_icon_color : R.color.ctx_menu_info_text_dark; + } + 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), + return AndroidUtils.createStateListDrawable(createShowOnTopbarIcon(getDeviceTopNormalColorId(), R.color.dashboard_blue), createShowOnTopbarIcon(bgPressed, icPressed)); }