Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2018-01-12 09:57:23 +01:00
commit 424b9cf8b0
3 changed files with 52 additions and 25 deletions

View file

@ -138,17 +138,14 @@ public class AndroidUtils {
public static StateListDrawable createStateListDrawable(Context ctx, boolean night, public static StateListDrawable createStateListDrawable(Context ctx, boolean night,
@DrawableRes int lightNormal, @DrawableRes int lightPressed, @DrawableRes int lightNormal, @DrawableRes int lightPressed,
@DrawableRes int darkNormal, @DrawableRes int darkPressed) { @DrawableRes int darkNormal, @DrawableRes int darkPressed) {
return createStateListDrawable(night, return createStateListDrawable(ContextCompat.getDrawable(ctx, night ? darkNormal : lightNormal),
ContextCompat.getDrawable(ctx, lightNormal), ContextCompat.getDrawable(ctx, lightPressed), ContextCompat.getDrawable(ctx, night ? darkPressed : lightPressed));
ContextCompat.getDrawable(ctx, darkNormal), ContextCompat.getDrawable(ctx, darkPressed));
} }
public static StateListDrawable createStateListDrawable(boolean night, public static StateListDrawable createStateListDrawable(Drawable normal, Drawable pressed) {
Drawable lightNormal, Drawable lightPressed,
Drawable darkNormal, Drawable darkPressed) {
StateListDrawable res = new StateListDrawable(); StateListDrawable res = new StateListDrawable();
res.addState(new int[]{android.R.attr.state_pressed}, night ? darkPressed : lightPressed); res.addState(new int[]{android.R.attr.state_pressed}, pressed);
res.addState(new int[]{}, night ? darkNormal : lightNormal); res.addState(new int[]{}, normal);
return res; return res;
} }

View file

@ -1,7 +1,9 @@
package net.osmand.plus.mapcontextmenu; package net.osmand.plus.mapcontextmenu;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;
import android.os.AsyncTask; import android.os.AsyncTask;
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;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
@ -9,6 +11,7 @@ import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import net.osmand.AndroidUtils;
import net.osmand.IndexConstants; import net.osmand.IndexConstants;
import net.osmand.NativeLibrary.RenderedObject; import net.osmand.NativeLibrary.RenderedObject;
import net.osmand.aidl.maplayer.point.AMapPoint; import net.osmand.aidl.maplayer.point.AMapPoint;
@ -573,18 +576,39 @@ public abstract class MenuController extends BaseMenuController {
int resId = left ? leftIconId : rightIconId; int resId = left ? leftIconId : rightIconId;
if (resId != 0) { if (resId != 0) {
if (needColorizeIcon) { if (needColorizeIcon) {
return getIcon(resId, getColorRes()); return enabled ? getNormalIcon(resId) : getDisabledIcon(resId);
} }
return ContextCompat.getDrawable(getMapActivity(), resId); return ContextCompat.getDrawable(getMapActivity(), resId);
} }
return null; return null;
} }
private int getColorRes() { public void updateStateListDrawableIcon(@DrawableRes int resId, boolean left) {
if (enabled) { if (left) {
return isLight() ? R.color.map_widget_blue : R.color.osmand_orange; leftIcon = enabled ? getStateListDrawable(resId) : null;
leftIconId = enabled ? 0 : resId;
} else {
rightIcon = enabled ? getStateListDrawable(resId) : null;
rightIconId = enabled ? 0 : resId;
} }
return isLight() ? R.color.ctx_menu_controller_disabled_text_color_light : R.color.ctx_menu_controller_disabled_text_color_dark; }
private Drawable getDisabledIcon(@DrawableRes int iconResId) {
return getIcon(iconResId, isLight() ? R.color.ctx_menu_controller_disabled_text_color_light
: R.color.ctx_menu_controller_disabled_text_color_dark);
}
private Drawable getNormalIcon(@DrawableRes int iconResId) {
return getIcon(iconResId, isLight() ? R.color.map_widget_blue : R.color.osmand_orange);
}
private Drawable getPressedIcon(@DrawableRes int iconResId) {
return getIcon(iconResId, isLight() ? R.color.ctx_menu_controller_button_text_color_light_p
: R.color.ctx_menu_controller_button_text_color_dark_p);
}
private StateListDrawable getStateListDrawable(@DrawableRes int iconResId) {
return AndroidUtils.createStateListDrawable(getNormalIcon(iconResId), getPressedIcon(iconResId));
} }
public abstract void buttonPressed(); public abstract void buttonPressed();

View file

@ -58,7 +58,7 @@ public class TransportRouteController extends MenuController {
} }
}; };
leftTitleButtonController.caption = mapActivity.getString(R.string.shared_string_previous); leftTitleButtonController.caption = mapActivity.getString(R.string.shared_string_previous);
leftTitleButtonController.leftIconId = R.drawable.ic_arrow_back; updateLeftTitleButtonIcon();
rightTitleButtonController = new TitleButtonController() { rightTitleButtonController = new TitleButtonController() {
@Override @Override
@ -70,7 +70,7 @@ public class TransportRouteController extends MenuController {
} }
}; };
rightTitleButtonController.caption = mapActivity.getString(R.string.shared_string_next); rightTitleButtonController.caption = mapActivity.getString(R.string.shared_string_next);
rightTitleButtonController.rightIconId = R.drawable.ic_arrow_forward; updateRightTitleButtonIcon();
} }
@Override @Override
@ -144,6 +144,14 @@ public class TransportRouteController extends MenuController {
resetRoute(); resetRoute();
} }
private void updateLeftTitleButtonIcon() {
leftTitleButtonController.updateStateListDrawableIcon(R.drawable.ic_arrow_back, true);
}
private void updateRightTitleButtonIcon() {
rightTitleButtonController.updateStateListDrawableIcon(R.drawable.ic_arrow_forward, false);
}
public void onAcquireNewController(PointDescription pointDescription, Object object) { public void onAcquireNewController(PointDescription pointDescription, Object object) {
if (object instanceof TransportRouteStop) { if (object instanceof TransportRouteStop) {
resetRoute(); resetRoute();
@ -151,19 +159,17 @@ public class TransportRouteController extends MenuController {
} }
private void updateControllers() { private void updateControllers() {
boolean previousStopEnabled = false; boolean previousStopEnabled = getPreviousStop() != -1;
final int previousStop = getPreviousStop(); if (leftTitleButtonController.enabled != previousStopEnabled) {
if (previousStop != -1) {
previousStopEnabled = true;
}
leftTitleButtonController.enabled = previousStopEnabled; leftTitleButtonController.enabled = previousStopEnabled;
updateLeftTitleButtonIcon();
boolean nextStopEnabled = false;
final int nextStop = getNextStop();
if (nextStop != -1) {
nextStopEnabled = true;
} }
boolean nextStopEnabled = getNextStop() != -1;
if (rightTitleButtonController.enabled != nextStopEnabled) {
rightTitleButtonController.enabled = nextStopEnabled; rightTitleButtonController.enabled = nextStopEnabled;
updateRightTitleButtonIcon();
}
} }
private void showTransportStop(TransportStop stop) { private void showTransportStop(TransportStop stop) {