From 39b5b3e0b2c57d4e4e4306b4f5f9ab9cc1dd3ce9 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Thu, 28 Dec 2017 13:35:30 +0200 Subject: [PATCH] Add previous and next icons --- .../MapContextMenuFragment.java | 29 ++++++++++++------- .../plus/mapcontextmenu/MenuController.java | 16 ++++++++++ .../controllers/TransportRouteController.java | 2 ++ 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java index 8637b83204..c0b7ee1f4d 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java @@ -14,6 +14,7 @@ import android.support.v4.content.ContextCompat; import android.text.TextUtils; import android.util.TypedValue; import android.view.GestureDetector; +import android.view.Gravity; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.VelocityTracker; @@ -735,10 +736,10 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo if (leftTitleButtonController.visible) { leftTitleButtonView.setVisibility(View.VISIBLE); Drawable leftIcon = leftTitleButtonController.getLeftIcon(); - if (leftIcon != null) { - leftTitleButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, null, null); - leftTitleButton.setCompoundDrawablePadding(dpToPx(8f)); - } + Drawable rightIcon = leftTitleButtonController.getRightIcon(); + leftTitleButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, rightIcon, null); + leftTitleButton.setCompoundDrawablePadding(dpToPx(8f)); + ((LinearLayout) leftTitleButtonView).setGravity(rightIcon != null ? Gravity.END : Gravity.START); if (leftTitleButtonController.needRightText) { titleButtonRightText.setText(leftTitleButtonController.rightTextCaption); @@ -762,8 +763,10 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo rightTitleButtonView.setVisibility(rightTitleButtonController.visible ? View.VISIBLE : View.INVISIBLE); Drawable leftIcon = rightTitleButtonController.getLeftIcon(); - rightTitleButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, null, null); + Drawable rightIcon = rightTitleButtonController.getRightIcon(); + rightTitleButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, rightIcon, null); rightTitleButton.setCompoundDrawablePadding(dpToPx(8f)); + ((LinearLayout) rightTitleButtonView).setGravity(rightIcon != null ? Gravity.END : Gravity.START); } else { rightTitleButtonView.setVisibility(View.INVISIBLE); } @@ -776,8 +779,10 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo bottomTitleButtonView.setVisibility(bottomTitleButtonController.visible ? View.VISIBLE : View.GONE); Drawable leftIcon = bottomTitleButtonController.getLeftIcon(); - bottomTitleButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, null, null); + Drawable rightIcon = bottomTitleButtonController.getRightIcon(); + bottomTitleButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, rightIcon, null); bottomTitleButton.setCompoundDrawablePadding(dpToPx(8f)); + ((LinearLayout) bottomTitleButtonView).setGravity(rightIcon != null ? Gravity.END : Gravity.START); } else { bottomTitleButtonView.setVisibility(View.GONE); } @@ -798,10 +803,10 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo leftDownloadButtonView.setVisibility(leftDownloadButtonController.visible ? View.VISIBLE : View.INVISIBLE); Drawable leftIcon = leftDownloadButtonController.getLeftIcon(); - if (leftIcon != null) { - leftDownloadButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, null, null); - leftDownloadButton.setCompoundDrawablePadding(dpToPx(8f)); - } + Drawable rightIcon = leftDownloadButtonController.getRightIcon(); + leftDownloadButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, rightIcon, null); + leftDownloadButton.setCompoundDrawablePadding(dpToPx(8f)); + ((LinearLayout) leftDownloadButtonView).setGravity(rightIcon != null ? Gravity.END : Gravity.START); } else { leftDownloadButtonView.setVisibility(View.INVISIBLE); } @@ -814,8 +819,10 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo rightDownloadButtonView.setVisibility(rightDownloadButtonController.visible ? View.VISIBLE : View.INVISIBLE); Drawable leftIcon = rightDownloadButtonController.getLeftIcon(); - rightDownloadButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, null, null); + Drawable rightIcon = rightDownloadButtonController.getRightIcon(); + rightDownloadButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, rightIcon, null); rightDownloadButton.setCompoundDrawablePadding(dpToPx(8f)); + ((LinearLayout) rightDownloadButtonView).setGravity(rightIcon != null ? Gravity.END : Gravity.START); } else { rightDownloadButtonView.setVisibility(View.INVISIBLE); } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java index a5b55f27fd..5e2d731f4f 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java @@ -531,11 +531,13 @@ public abstract class MenuController extends BaseMenuController { public abstract class TitleButtonController { public String caption = ""; public int leftIconId = 0; + public int rightIconId = 0; public boolean needRightText = false; public String rightTextCaption = ""; public boolean visible = true; public boolean needColorizeIcon = true; public Drawable leftIcon; + public Drawable rightIcon; public Drawable getLeftIcon() { if (leftIcon != null) { @@ -551,6 +553,20 @@ public abstract class MenuController extends BaseMenuController { } } + public Drawable getRightIcon() { + if (rightIcon != null) { + return rightIcon; + } + if (rightIconId != 0) { + if (needColorizeIcon) { + return getIcon(rightIconId, isLight() ? R.color.map_widget_blue : R.color.osmand_orange); + } + return ContextCompat.getDrawable(getMapActivity(), rightIconId); + } else { + return null; + } + } + public abstract void buttonPressed(); } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportRouteController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportRouteController.java index aebdb2453f..c018ee5b00 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportRouteController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportRouteController.java @@ -58,6 +58,7 @@ public class TransportRouteController extends MenuController { } }; leftTitleButtonController.caption = mapActivity.getString(R.string.shared_string_previous); + leftTitleButtonController.leftIconId = R.drawable.ic_arrow_back; rightTitleButtonController = new TitleButtonController() { @Override @@ -69,6 +70,7 @@ public class TransportRouteController extends MenuController { } }; rightTitleButtonController.caption = mapActivity.getString(R.string.shared_string_next); + rightTitleButtonController.rightIconId = R.drawable.ic_arrow_forward; } @Override