rename and refactoring

This commit is contained in:
nazar-kutz 2020-11-30 09:53:55 +02:00
parent b03899c4ff
commit 435f06bf5e
3 changed files with 45 additions and 67 deletions

View file

@ -63,7 +63,7 @@ public class HorizontalSelectionAdapter extends RecyclerView.Adapter<HorizontalS
public void onBindViewHolder(@NonNull ItemViewHolder holder, final int position) {
final HorizontalSelectionItem item = items.get(holder.getAdapterPosition());
TextView textView = holder.buttonText;
int innerPadding = app.getResources().getDimensionPixelSize(R.dimen.content_padding);//AndroidUtils.dpToPx(app, 16);
int innerPadding = app.getResources().getDimensionPixelSize(R.dimen.content_padding);
textView.setPadding(innerPadding, 0, innerPadding, 0);
int activeColorResId = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light;
if (item.equals(selectedItem) && item.isEnabled()) {

View file

@ -75,9 +75,9 @@ import net.osmand.plus.views.layers.MapControlsLayer;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarControllerType;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarView;
import net.osmand.plus.widgets.HorizontalRadioGroup;
import net.osmand.plus.widgets.HorizontalRadioGroup.RadioItem;
import net.osmand.plus.widgets.HorizontalRadioGroup.OnRadioItemClickListener;
import net.osmand.plus.widgets.MultiStateToggleButton;
import net.osmand.plus.widgets.MultiStateToggleButton.RadioItem;
import net.osmand.plus.widgets.MultiStateToggleButton.OnRadioItemClickListener;
import net.osmand.router.RoutePlannerFrontEnd.GpxRouteApproximation;
import net.osmand.util.Algorithms;
@ -118,7 +118,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
private BaseCard visibleCard;
private PointsCard pointsCard;
private GraphsCard graphsCard;
private HorizontalRadioGroup infoTypeBtn;
private MultiStateToggleButton infoTypeBtn;
private RadioItem pointsBtn;
private RadioItem graphBtn;
private View mainView;
@ -140,7 +140,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
private static final int UNDO_MODE = 0x8;
private int modes = 0x0;
private boolean isPortrait;
private boolean portrait;
private boolean nightMode;
private int cachedMapPosition;
@ -230,6 +230,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
return null;
}
final MeasurementToolLayer measurementLayer = mapActivity.getMapLayers().getMeasurementToolLayer();
OsmandApplication app = mapActivity.getMyApplication();
editingCtx.setApplication(mapActivity.getMyApplication());
editingCtx.setProgressListener(new SnapToRoadProgressListener() {
@ -261,7 +262,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
measurementLayer.setEditingCtx(editingCtx);
nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
isPortrait = AndroidUiHelper.isOrientationPortrait(mapActivity);
portrait = AndroidUiHelper.isOrientationPortrait(mapActivity);
int btnWidth = getResources().getDimensionPixelOffset(R.dimen.gpx_group_button_width);
pointsSt = getString(R.string.shared_string_gpx_points).toLowerCase();
@ -273,7 +274,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
AndroidUtils.setBackground(mapActivity, mainView, nightMode, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark);
detailsMenu = new GraphDetailsMenu();
cardsContainer = mainView.findViewById(R.id.cards_container);
if (isPortrait) {
if (portrait) {
String pointsBtnTitle = getString(R.string.shared_string_gpx_points);
pointsBtn = new RadioItem(pointsBtnTitle);
pointsBtn.setOnClickListener(getInfoTypeBtnListener(InfoType.POINTS));
@ -282,8 +283,8 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
graphBtn = new RadioItem(graphBtnTitle);
graphBtn.setOnClickListener(getInfoTypeBtnListener(InfoType.GRAPH));
LinearLayout customRadioButtons = mainView.findViewById(R.id.custom_radio_buttons);
infoTypeBtn = new HorizontalRadioGroup(customRadioButtons, nightMode);
LinearLayout infoButtonsContainer = mainView.findViewById(R.id.custom_radio_buttons);
infoTypeBtn = new MultiStateToggleButton(app, infoButtonsContainer, nightMode);
infoTypeBtn.setItems(pointsBtn, graphBtn);
}
pointsCard = new PointsCard(mapActivity, this);
@ -319,7 +320,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
upDownRow.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (isPortrait) {
if (portrait) {
if (infoExpanded) {
collapseInfoView();
} else if (setInfoType(InfoType.POINTS)) {
@ -556,10 +557,10 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
}
private void expandInfoView() {
if (isPortrait) {
if (portrait) {
infoExpanded = true;
cardsContainer.setVisibility(View.VISIBLE);
setMapPosition(isPortrait
setMapPosition(portrait
? OsmandSettings.MIDDLE_TOP_CONSTANT
: OsmandSettings.LANDSCAPE_MIDDLE_RIGHT_CONSTANT);
updateUpDownBtn();
@ -573,7 +574,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
}
private void collapseInfoView() {
if (isPortrait) {
if (portrait) {
infoExpanded = false;
currentInfoType = null;
infoTypeBtn.setSelectedItem(null);
@ -1196,7 +1197,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
public void onItemClick(int position) {
if (mapActivity != null && measurementLayer != null) {
collapseInfoViewIfExpanded();
if (isPortrait) {
if (portrait) {
setMapPosition(OsmandSettings.MIDDLE_TOP_CONSTANT);
}
measurementLayer.moveMapToPoint(position);
@ -1690,7 +1691,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
if (measurementLayer != null) {
String distanceStr = OsmAndFormatter.getFormattedDistance((float) editingCtx.getRouteDistance(), requireMyApplication());
distanceTv.setText(distanceStr + ",");
pointsTv.setText((isPortrait ? pointsSt + ": " : "") + editingCtx.getPointsCount());
pointsTv.setText((portrait ? pointsSt + ": " : "") + editingCtx.getPointsCount());
}
updateToolbar();
}
@ -1721,7 +1722,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
mapActivity.refreshMap();
mapActivity.disableDrawer();
AndroidUiHelper.setVisibility(mapActivity, isPortrait ? View.INVISIBLE : View.GONE,
AndroidUiHelper.setVisibility(mapActivity, portrait ? View.INVISIBLE : View.GONE,
R.id.map_left_widgets_panel,
R.id.map_right_widgets_panel,
R.id.map_center_info);

View file

@ -1,6 +1,5 @@
package net.osmand.plus.widgets;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.view.LayoutInflater;
@ -21,9 +20,10 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class HorizontalRadioGroup {
public class MultiStateToggleButton {
private List<RadioItem> items = new ArrayList<>();
private OsmandApplication app;
private List<ViewGroup> buttons = new ArrayList<>();
private List<View> dividers = new ArrayList<>();
private RadioItem selectedItem;
@ -31,7 +31,8 @@ public class HorizontalRadioGroup {
private LinearLayout container;
private boolean nightMode;
public HorizontalRadioGroup(LinearLayout container, boolean nightMode) {
public MultiStateToggleButton(OsmandApplication app, LinearLayout container, boolean nightMode) {
this.app = app;
this.container = container;
this.nightMode = nightMode;
}
@ -51,27 +52,25 @@ public class HorizontalRadioGroup {
dividers.clear();
container.removeAllViews();
for (int i = 0; i < items.size(); i++) {
RadioItem item = items.get(i);
ViewGroup button = createBtn();
TextView title = button.findViewById(R.id.title);
title.setText(item.getTitle());
button.setOnClickListener(getSelectClickListener(item));
buttons.add(button);
container.addView(button);
boolean lastItem = i == items.size() - 1;
if (!lastItem) {
View divider = createDivider();
dividers.add(divider);
container.addView(divider);
createBtn(items.get(i));
if (!isLastItem(i)) {
createDivider();
}
}
updateView();
}
private View.OnClickListener getSelectClickListener(final RadioItem item) {
return new View.OnClickListener() {
private boolean isLastItem(int index) {
return index == items.size() - 1;
}
private void createBtn(@NonNull final RadioItem item) {
LayoutInflater inflater = UiUtilities.getInflater(app, nightMode);
ViewGroup button = (ViewGroup) inflater.inflate(
R.layout.custom_radio_btn_text_item, container, false);
TextView title = button.findViewById(R.id.title);
title.setText(item.getTitle());
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
OnRadioItemClickListener l = item.getListener();
@ -79,27 +78,21 @@ public class HorizontalRadioGroup {
setSelectedItem(item);
}
}
};
});
buttons.add(button);
container.addView(button);
}
@NonNull
private ViewGroup createBtn() {
Context ctx = getThemedCtx();
LayoutInflater inflater = LayoutInflater.from(ctx);
return (ViewGroup) inflater.inflate(R.layout.custom_radio_btn_text_item, container, false);
}
@NonNull
private View createDivider() {
Context ctx = getThemedCtx();
private void createDivider() {
int dividerColor = nightMode ?
R.color.stroked_buttons_and_links_outline_dark :
R.color.stroked_buttons_and_links_outline_light;
int width = AndroidUtils.dpToPx(ctx, 1.0f);
View divider = new View(ctx);
int width = AndroidUtils.dpToPx(app, 1.0f);
View divider = new View(app);
divider.setLayoutParams(new ViewGroup.LayoutParams(width, ViewGroup.LayoutParams.MATCH_PARENT));
divider.setBackgroundColor(ContextCompat.getColor(ctx, dividerColor));
return divider;
divider.setBackgroundColor(ContextCompat.getColor(app, dividerColor));
dividers.add(divider);
container.addView(divider);
}
public void setSelectedItem(RadioItem selectedItem) {
@ -108,10 +101,6 @@ public class HorizontalRadioGroup {
}
private void updateView() {
OsmandApplication app = getMyApplication();
if (app == null) {
return;
}
int activeColor = ContextCompat.getColor(app, nightMode
? R.color.active_color_primary_dark
: R.color.active_color_primary_light);
@ -167,18 +156,6 @@ public class HorizontalRadioGroup {
}
}
private Context getThemedCtx() {
Context ctx = container.getContext();
return UiUtilities.getThemedContext(ctx, nightMode);
}
private OsmandApplication getMyApplication() {
if (container != null) {
return (OsmandApplication) container.getContext().getApplicationContext();
}
return null;
}
public static class RadioItem {
private String title;
private OnRadioItemClickListener listener;