Merge pull request #9860 from osmandapp/FixCustomRadioButtonRtl

Fix CustomRadioButton in RTL
This commit is contained in:
Vitaliy 2020-09-21 18:13:03 +03:00 committed by GitHub
commit 7eeb0aa5c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 30 deletions

View file

@ -93,8 +93,8 @@ public class UiUtilities {
} }
public enum CustomRadioButtonType { public enum CustomRadioButtonType {
LEFT, START,
RIGHT, END,
} }
public UiUtilities(OsmandApplication app) { public UiUtilities(OsmandApplication app) {
@ -459,26 +459,35 @@ public class UiUtilities {
? R.color.text_color_primary_dark ? R.color.text_color_primary_dark
: R.color.text_color_primary_light); : R.color.text_color_primary_light);
int radius = AndroidUtils.dpToPx(app, 4); int radius = AndroidUtils.dpToPx(app, 4);
boolean isLayoutRtl = AndroidUtils.isLayoutRtl(app);
TextView leftButtonText = buttonsView.findViewById(R.id.left_button); TextView startButtonText = buttonsView.findViewById(R.id.left_button);
View leftButtonContainer = buttonsView.findViewById(R.id.left_button_container); View startButtonContainer = buttonsView.findViewById(R.id.left_button_container);
TextView rightButtonText = buttonsView.findViewById(R.id.right_button); TextView endButtonText = buttonsView.findViewById(R.id.right_button);
View rightButtonContainer = buttonsView.findViewById(R.id.right_button_container); View endButtonContainer = buttonsView.findViewById(R.id.right_button_container);
GradientDrawable background = new GradientDrawable(); GradientDrawable background = new GradientDrawable();
background.setColor(UiUtilities.getColorWithAlpha(activeColor, 0.1f)); background.setColor(UiUtilities.getColorWithAlpha(activeColor, 0.1f));
background.setStroke(AndroidUtils.dpToPx(app, 1), UiUtilities.getColorWithAlpha(activeColor, 0.5f)); background.setStroke(AndroidUtils.dpToPx(app, 1), UiUtilities.getColorWithAlpha(activeColor, 0.5f));
if (buttonType == CustomRadioButtonType.LEFT) { 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 {
if (isLayoutRtl) {
background.setCornerRadii(new float[]{radius, radius, 0, 0, 0, 0, radius, radius}); 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);
} else { } else {
background.setCornerRadii(new float[]{0, 0, radius, radius, radius, radius, 0, 0}); background.setCornerRadii(new float[]{0, 0, radius, radius, radius, radius, 0, 0});
rightButtonContainer.setBackgroundDrawable(background); }
rightButtonText.setTextColor(textColor); endButtonContainer.setBackgroundDrawable(background);
leftButtonContainer.setBackgroundColor(Color.TRANSPARENT); endButtonText.setTextColor(textColor);
leftButtonText.setTextColor(activeColor); startButtonContainer.setBackgroundColor(Color.TRANSPARENT);
startButtonText.setTextColor(activeColor);
} }
} }

View file

@ -27,8 +27,8 @@ import org.apache.commons.logging.Log;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static net.osmand.plus.UiUtilities.CustomRadioButtonType.LEFT; import static net.osmand.plus.UiUtilities.CustomRadioButtonType.START;
import static net.osmand.plus.UiUtilities.CustomRadioButtonType.RIGHT; import static net.osmand.plus.UiUtilities.CustomRadioButtonType.END;
import static net.osmand.plus.measurementtool.MeasurementEditingContext.DEFAULT_APP_MODE; import static net.osmand.plus.measurementtool.MeasurementEditingContext.DEFAULT_APP_MODE;
import static net.osmand.plus.measurementtool.SelectFileBottomSheet.BOTTOM_SHEET_HEIGHT_DP; import static net.osmand.plus.measurementtool.SelectFileBottomSheet.BOTTOM_SHEET_HEIGHT_DP;
@ -136,7 +136,7 @@ public class RouteBetweenPointsBottomSheetDialogFragment extends BottomSheetBeha
public void updateModeButtons() { public void updateModeButtons() {
UiUtilities.updateCustomRadioButtons(getMyApplication(), customRadioButton, nightMode, UiUtilities.updateCustomRadioButtons(getMyApplication(), customRadioButton, nightMode,
defaultDialogMode == RouteBetweenPointsDialogMode.SINGLE ? LEFT : RIGHT); defaultDialogMode == RouteBetweenPointsDialogMode.SINGLE ? START : END);
btnDescription.setText(getButtonDescr(defaultDialogMode)); btnDescription.setText(getButtonDescr(defaultDialogMode));
} }

View file

@ -11,8 +11,8 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.LocalRoutingParameter; import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.LocalRoutingParameter;
import static net.osmand.plus.UiUtilities.CustomRadioButtonType; import static net.osmand.plus.UiUtilities.CustomRadioButtonType;
import static net.osmand.plus.UiUtilities.CustomRadioButtonType.LEFT; import static net.osmand.plus.UiUtilities.CustomRadioButtonType.START;
import static net.osmand.plus.UiUtilities.CustomRadioButtonType.RIGHT; import static net.osmand.plus.UiUtilities.CustomRadioButtonType.END;
public class NavigateTrackOptionsCard extends BaseCard { public class NavigateTrackOptionsCard extends BaseCard {
@ -45,7 +45,7 @@ public class NavigateTrackOptionsCard extends BaseCard {
TextView description = parameterView.findViewById(R.id.description); TextView description = parameterView.findViewById(R.id.description);
boolean enabled = passWholeRoute.isSelected(app.getSettings()); boolean enabled = passWholeRoute.isSelected(app.getSettings());
CustomRadioButtonType buttonType = enabled ? LEFT : RIGHT; CustomRadioButtonType buttonType = enabled ? START : END;
UiUtilities.updateCustomRadioButtons(app, buttonsView, nightMode, buttonType); UiUtilities.updateCustomRadioButtons(app, buttonsView, nightMode, buttonType);
leftButton.setText(R.string.start_of_the_track); leftButton.setText(R.string.start_of_the_track);
@ -56,7 +56,7 @@ public class NavigateTrackOptionsCard extends BaseCard {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (!passWholeRoute.isSelected(app.getSettings())) { 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 @Override
public void onClick(View v) { public void onClick(View v) {
if (passWholeRoute.isSelected(app.getSettings())) { 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()); rightButton.setText(app.getRoutingHelper().getAppMode().toHumanString());
boolean enabled = navigationType.isSelected(app.getSettings()); boolean enabled = navigationType.isSelected(app.getSettings());
CustomRadioButtonType buttonType = enabled ? RIGHT : LEFT; CustomRadioButtonType buttonType = enabled ? END : START;
UiUtilities.updateCustomRadioButtons(app, buttonsView, nightMode, buttonType); UiUtilities.updateCustomRadioButtons(app, buttonsView, nightMode, buttonType);
leftButton.setOnClickListener(new View.OnClickListener() { leftButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (navigationType.isSelected(app.getSettings())) { 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 @Override
public void onClick(View v) { public void onClick(View v) {
if (!navigationType.isSelected(app.getSettings())) { if (!navigationType.isSelected(app.getSettings())) {
applyParameter(parameterView, navigationType, RIGHT, true); applyParameter(parameterView, navigationType, END, true);
} }
} }
}); });

View file

@ -291,9 +291,9 @@ public class TerrainFragment extends BaseOsmAndFragment implements View.OnClickL
private void adjustModeButtons(TerrainMode mode) { private void adjustModeButtons(TerrainMode mode) {
if (mode == SLOPE) { if (mode == SLOPE) {
UiUtilities.updateCustomRadioButtons(app, customRadioButton, nightMode, RIGHT); UiUtilities.updateCustomRadioButtons(app, customRadioButton, nightMode, END);
} else { } else {
UiUtilities.updateCustomRadioButtons(app, customRadioButton, nightMode, LEFT); UiUtilities.updateCustomRadioButtons(app, customRadioButton, nightMode, START);
} }
} }