Do not use StateListDrawable with API < 21
This commit is contained in:
parent
76f395529a
commit
3a9c9d3be7
3 changed files with 25 additions and 11 deletions
|
@ -3,6 +3,7 @@ package net.osmand.plus.mapcontextmenu;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.graphics.drawable.StateListDrawable;
|
import android.graphics.drawable.StateListDrawable;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
import android.os.Build;
|
||||||
import android.support.annotation.DrawableRes;
|
import android.support.annotation.DrawableRes;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
@ -594,12 +595,13 @@ public abstract class MenuController extends BaseMenuController {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateStateListDrawableIcon(@DrawableRes int resId, boolean left) {
|
public void updateStateListDrawableIcon(@DrawableRes int resId, boolean left) {
|
||||||
|
boolean useStateList = enabled && Build.VERSION.SDK_INT >= 21;
|
||||||
if (left) {
|
if (left) {
|
||||||
leftIcon = enabled ? getStateListDrawable(resId) : null;
|
leftIcon = useStateList ? getStateListDrawable(resId) : null;
|
||||||
leftIconId = enabled ? 0 : resId;
|
leftIconId = useStateList ? 0 : resId;
|
||||||
} else {
|
} else {
|
||||||
rightIcon = enabled ? getStateListDrawable(resId) : null;
|
rightIcon = useStateList ? getStateListDrawable(resId) : null;
|
||||||
rightIconId = enabled ? 0 : resId;
|
rightIconId = useStateList ? 0 : resId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import android.content.Intent;
|
||||||
import android.content.res.ColorStateList;
|
import android.content.res.ColorStateList;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.Build;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v7.view.ContextThemeWrapper;
|
import android.support.v7.view.ContextThemeWrapper;
|
||||||
import android.text.Html;
|
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);
|
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,
|
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);
|
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));
|
button.setCompoundDrawablePadding(dpToPx(8f));
|
||||||
llText.addView(button);
|
llText.addView(button);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import android.graphics.drawable.LayerDrawable;
|
||||||
import android.graphics.drawable.ShapeDrawable;
|
import android.graphics.drawable.ShapeDrawable;
|
||||||
import android.graphics.drawable.StateListDrawable;
|
import android.graphics.drawable.StateListDrawable;
|
||||||
import android.graphics.drawable.shapes.OvalShape;
|
import android.graphics.drawable.shapes.OvalShape;
|
||||||
|
import android.os.Build;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
|
|
||||||
import net.osmand.AndroidUtils;
|
import net.osmand.AndroidUtils;
|
||||||
|
@ -27,6 +28,7 @@ public class MapMarkerMenuController extends MenuController {
|
||||||
public MapMarkerMenuController(MapActivity mapActivity, PointDescription pointDescription, MapMarker mapMarker) {
|
public MapMarkerMenuController(MapActivity mapActivity, PointDescription pointDescription, MapMarker mapMarker) {
|
||||||
super(new MenuBuilder(mapActivity), pointDescription, mapActivity);
|
super(new MenuBuilder(mapActivity), pointDescription, mapActivity);
|
||||||
final OsmandApplication app = mapActivity.getMyApplication();
|
final OsmandApplication app = mapActivity.getMyApplication();
|
||||||
|
final boolean useStateList = Build.VERSION.SDK_INT >= 21;
|
||||||
this.mapMarker = mapMarker;
|
this.mapMarker = mapMarker;
|
||||||
builder.setShowNearestWiki(true);
|
builder.setShowNearestWiki(true);
|
||||||
|
|
||||||
|
@ -39,7 +41,8 @@ public class MapMarkerMenuController extends MenuController {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
leftTitleButtonController.caption = getMapActivity().getString(R.string.mark_passed);
|
leftTitleButtonController.caption = getMapActivity().getString(R.string.mark_passed);
|
||||||
leftTitleButtonController.leftIcon = createStateListPassedIcon();
|
leftTitleButtonController.leftIcon = useStateList ? createStateListPassedIcon()
|
||||||
|
: createPassedIcon(getPassedIconBgNormalColorId(), 0);
|
||||||
|
|
||||||
rightTitleButtonController = new TitleButtonController() {
|
rightTitleButtonController = new TitleButtonController() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -54,16 +57,20 @@ public class MapMarkerMenuController extends MenuController {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
rightTitleButtonController.caption = getMapActivity().getString(R.string.make_active);
|
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() {
|
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
|
int bgPressed = isLight() ? R.color.ctx_menu_controller_button_text_color_light_p
|
||||||
: R.color.ctx_menu_controller_button_text_color_dark_p;
|
: R.color.ctx_menu_controller_button_text_color_dark_p;
|
||||||
int icPressed = isLight() ? R.color.ctx_menu_controller_button_text_color_light_n
|
int icPressed = isLight() ? R.color.ctx_menu_controller_button_text_color_light_n
|
||||||
: R.color.ctx_menu_controller_button_bg_color_dark_p;
|
: 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));
|
createPassedIcon(bgPressed, icPressed));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,12 +81,15 @@ public class MapMarkerMenuController extends MenuController {
|
||||||
return new LayerDrawable(new Drawable[]{bg, ic});
|
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() {
|
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
|
int bgPressed = isLight() ? R.color.ctx_menu_controller_button_text_color_light_p
|
||||||
: R.color.ctx_menu_controller_button_text_color_dark_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;
|
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));
|
createShowOnTopbarIcon(bgPressed, icPressed));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue