Fix CustomRadioButton in RTL

This commit is contained in:
Nazar-Kutz 2020-09-21 17:12:56 +03:00
parent 55dc681600
commit 2734519822
4 changed files with 39 additions and 30 deletions

View file

@ -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);
}
}

View file

@ -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));
}

View file

@ -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);
}
}
});

View file

@ -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);
}
}