From 27345198225facfb778f0368de593bd97ac50a21 Mon Sep 17 00:00:00 2001 From: Nazar-Kutz Date: Mon, 21 Sep 2020 17:12:56 +0300 Subject: [PATCH] Fix CustomRadioButton in RTL --- OsmAnd/src/net/osmand/plus/UiUtilities.java | 43 +++++++++++-------- ...etweenPointsBottomSheetDialogFragment.java | 6 +-- .../cards/NavigateTrackOptionsCard.java | 16 +++---- .../plus/srtmplugin/TerrainFragment.java | 4 +- 4 files changed, 39 insertions(+), 30 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/UiUtilities.java b/OsmAnd/src/net/osmand/plus/UiUtilities.java index a435bd975e..5af06d9f23 100644 --- a/OsmAnd/src/net/osmand/plus/UiUtilities.java +++ b/OsmAnd/src/net/osmand/plus/UiUtilities.java @@ -93,8 +93,8 @@ public class UiUtilities { } public enum CustomRadioButtonType { - LEFT, - RIGHT, + START, + END, } public UiUtilities(OsmandApplication app) { @@ -459,26 +459,35 @@ public class UiUtilities { ? R.color.text_color_primary_dark : R.color.text_color_primary_light); int radius = AndroidUtils.dpToPx(app, 4); + boolean isLayoutRtl = AndroidUtils.isLayoutRtl(app); - TextView leftButtonText = buttonsView.findViewById(R.id.left_button); - View leftButtonContainer = buttonsView.findViewById(R.id.left_button_container); - TextView rightButtonText = buttonsView.findViewById(R.id.right_button); - View rightButtonContainer = buttonsView.findViewById(R.id.right_button_container); + TextView startButtonText = buttonsView.findViewById(R.id.left_button); + View startButtonContainer = buttonsView.findViewById(R.id.left_button_container); + TextView endButtonText = buttonsView.findViewById(R.id.right_button); + View endButtonContainer = buttonsView.findViewById(R.id.right_button_container); GradientDrawable background = new GradientDrawable(); background.setColor(UiUtilities.getColorWithAlpha(activeColor, 0.1f)); background.setStroke(AndroidUtils.dpToPx(app, 1), UiUtilities.getColorWithAlpha(activeColor, 0.5f)); - if (buttonType == CustomRadioButtonType.LEFT) { - background.setCornerRadii(new float[]{radius, radius, 0, 0, 0, 0, radius, radius}); - rightButtonContainer.setBackgroundColor(Color.TRANSPARENT); - rightButtonText.setTextColor(activeColor); - leftButtonContainer.setBackgroundDrawable(background); - leftButtonText.setTextColor(textColor); + if (buttonType == CustomRadioButtonType.START) { + if (isLayoutRtl) { + background.setCornerRadii(new float[]{0, 0, radius, radius, radius, radius, 0, 0}); + } else { + background.setCornerRadii(new float[]{radius, radius, 0, 0, 0, 0, radius, radius}); + } + endButtonContainer.setBackgroundColor(Color.TRANSPARENT); + endButtonText.setTextColor(activeColor); + startButtonContainer.setBackgroundDrawable(background); + startButtonText.setTextColor(textColor); } else { - background.setCornerRadii(new float[]{0, 0, radius, radius, radius, radius, 0, 0}); - rightButtonContainer.setBackgroundDrawable(background); - rightButtonText.setTextColor(textColor); - leftButtonContainer.setBackgroundColor(Color.TRANSPARENT); - leftButtonText.setTextColor(activeColor); + if (isLayoutRtl) { + background.setCornerRadii(new float[]{radius, radius, 0, 0, 0, 0, radius, radius}); + } else { + background.setCornerRadii(new float[]{0, 0, radius, radius, radius, radius, 0, 0}); + } + endButtonContainer.setBackgroundDrawable(background); + endButtonText.setTextColor(textColor); + startButtonContainer.setBackgroundColor(Color.TRANSPARENT); + startButtonText.setTextColor(activeColor); } } diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/RouteBetweenPointsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/RouteBetweenPointsBottomSheetDialogFragment.java index 77f3909e62..8feb1ecf5c 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/RouteBetweenPointsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/RouteBetweenPointsBottomSheetDialogFragment.java @@ -27,8 +27,8 @@ import org.apache.commons.logging.Log; import java.util.ArrayList; import java.util.List; -import static net.osmand.plus.UiUtilities.CustomRadioButtonType.LEFT; -import static net.osmand.plus.UiUtilities.CustomRadioButtonType.RIGHT; +import static net.osmand.plus.UiUtilities.CustomRadioButtonType.START; +import static net.osmand.plus.UiUtilities.CustomRadioButtonType.END; import static net.osmand.plus.measurementtool.MeasurementEditingContext.DEFAULT_APP_MODE; import static net.osmand.plus.measurementtool.SelectFileBottomSheet.BOTTOM_SHEET_HEIGHT_DP; @@ -136,7 +136,7 @@ public class RouteBetweenPointsBottomSheetDialogFragment extends BottomSheetBeha public void updateModeButtons() { UiUtilities.updateCustomRadioButtons(getMyApplication(), customRadioButton, nightMode, - defaultDialogMode == RouteBetweenPointsDialogMode.SINGLE ? LEFT : RIGHT); + defaultDialogMode == RouteBetweenPointsDialogMode.SINGLE ? START : END); btnDescription.setText(getButtonDescr(defaultDialogMode)); } diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/NavigateTrackOptionsCard.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/NavigateTrackOptionsCard.java index 4e3adfa29e..b2b819d269 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/NavigateTrackOptionsCard.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/NavigateTrackOptionsCard.java @@ -11,8 +11,8 @@ import net.osmand.plus.activities.MapActivity; import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.LocalRoutingParameter; import static net.osmand.plus.UiUtilities.CustomRadioButtonType; -import static net.osmand.plus.UiUtilities.CustomRadioButtonType.LEFT; -import static net.osmand.plus.UiUtilities.CustomRadioButtonType.RIGHT; +import static net.osmand.plus.UiUtilities.CustomRadioButtonType.START; +import static net.osmand.plus.UiUtilities.CustomRadioButtonType.END; public class NavigateTrackOptionsCard extends BaseCard { @@ -45,7 +45,7 @@ public class NavigateTrackOptionsCard extends BaseCard { TextView description = parameterView.findViewById(R.id.description); boolean enabled = passWholeRoute.isSelected(app.getSettings()); - CustomRadioButtonType buttonType = enabled ? LEFT : RIGHT; + CustomRadioButtonType buttonType = enabled ? START : END; UiUtilities.updateCustomRadioButtons(app, buttonsView, nightMode, buttonType); leftButton.setText(R.string.start_of_the_track); @@ -56,7 +56,7 @@ public class NavigateTrackOptionsCard extends BaseCard { @Override public void onClick(View v) { if (!passWholeRoute.isSelected(app.getSettings())) { - applyParameter(parameterView, passWholeRoute, LEFT, true); + applyParameter(parameterView, passWholeRoute, START, true); } } }); @@ -64,7 +64,7 @@ public class NavigateTrackOptionsCard extends BaseCard { @Override public void onClick(View v) { if (passWholeRoute.isSelected(app.getSettings())) { - applyParameter(parameterView, passWholeRoute, RIGHT, false); + applyParameter(parameterView, passWholeRoute, END, false); } } }); @@ -81,14 +81,14 @@ public class NavigateTrackOptionsCard extends BaseCard { rightButton.setText(app.getRoutingHelper().getAppMode().toHumanString()); boolean enabled = navigationType.isSelected(app.getSettings()); - CustomRadioButtonType buttonType = enabled ? RIGHT : LEFT; + CustomRadioButtonType buttonType = enabled ? END : START; UiUtilities.updateCustomRadioButtons(app, buttonsView, nightMode, buttonType); leftButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (navigationType.isSelected(app.getSettings())) { - applyParameter(parameterView, navigationType, LEFT, false); + applyParameter(parameterView, navigationType, START, false); } } }); @@ -96,7 +96,7 @@ public class NavigateTrackOptionsCard extends BaseCard { @Override public void onClick(View v) { if (!navigationType.isSelected(app.getSettings())) { - applyParameter(parameterView, navigationType, RIGHT, true); + applyParameter(parameterView, navigationType, END, true); } } }); diff --git a/OsmAnd/src/net/osmand/plus/srtmplugin/TerrainFragment.java b/OsmAnd/src/net/osmand/plus/srtmplugin/TerrainFragment.java index f1517bbaea..b613d2ba13 100644 --- a/OsmAnd/src/net/osmand/plus/srtmplugin/TerrainFragment.java +++ b/OsmAnd/src/net/osmand/plus/srtmplugin/TerrainFragment.java @@ -291,9 +291,9 @@ public class TerrainFragment extends BaseOsmAndFragment implements View.OnClickL private void adjustModeButtons(TerrainMode mode) { if (mode == SLOPE) { - UiUtilities.updateCustomRadioButtons(app, customRadioButton, nightMode, RIGHT); + UiUtilities.updateCustomRadioButtons(app, customRadioButton, nightMode, END); } else { - UiUtilities.updateCustomRadioButtons(app, customRadioButton, nightMode, LEFT); + UiUtilities.updateCustomRadioButtons(app, customRadioButton, nightMode, START); } }