Merge pull request #10293 from osmandapp/PlanRouteFixUiBugs

Fix Plan Route Ui bugs, add HorizontalRadioGroup
This commit is contained in:
Vitaliy 2020-11-30 07:56:53 +00:00 committed by GitHub
commit 5cfefc7f34
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 396 additions and 192 deletions

View file

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/selectableItemBackground"
android:gravity="center"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_medium"
tools:text="@string/shared_string_left"/>
</FrameLayout>

View file

@ -130,25 +130,32 @@
tools:text="@string/add_point_after"/>
</RelativeLayout>
<LinearLayout
android:id="@+id/additional_info_container"
<FrameLayout
android:id="@+id/info_type_buttons_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone" >
android:layout_height="wrap_content">
<include layout="@layout/custom_radio_buttons" />
<View
<include
layout="@layout/custom_radio_buttons"
android:layout_width="match_parent"
android:layout_height="@dimen/content_padding_small" />
android:layout_height="@dimen/measurement_tool_button_height"
android:layout_marginStart="@dimen/content_padding"
android:layout_marginEnd="@dimen/content_padding"
android:layout_marginBottom="@dimen/measurement_tool_content_padding_medium" />
</FrameLayout>
<FrameLayout
android:id="@+id/cards_container"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_height="@dimen/measurement_tool_info_cards_container_height"
android:visibility="gone" />
</LinearLayout>
<View
android:id="@+id/bottom_panel_divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/dashboard_divider" />
<LinearLayout
android:id="@+id/measure_mode_controls"

View file

@ -32,7 +32,7 @@
<FrameLayout
android:id="@+id/markers_list_container"
android:layout_width="match_parent"
android:layout_height="@dimen/measurement_tool_points_list_container_height"
android:layout_height="@dimen/measurement_tool_info_cards_container_height"
tools:background="@color/activity_background_color_dark">
<androidx.recyclerview.widget.RecyclerView

View file

@ -136,8 +136,8 @@
<View
android:layout_width="@dimen/standard_icon_size"
android:layout_height="@dimen/standard_icon_size"
android:layout_marginLeft="@dimen/content_padding"
android:layout_marginStart="@dimen/content_padding"
android:layout_marginLeft="@dimen/content_padding"
android:layout_marginEnd="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:visibility="invisible" />
@ -173,12 +173,4 @@
</LinearLayout>
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="match_parent"
android:layout_height="5dp"
android:layout_gravity="bottom"
android:alpha="0.5"
android:scaleType="fitXY"
osmand:srcCompat="@drawable/bg_shadow_onmap" />
</LinearLayout>

View file

@ -3,7 +3,7 @@
xmlns:osmand="http://schemas.android.com/apk/res-auto"
android:id="@+id/points_list_container"
android:layout_width="match_parent"
android:layout_height="@dimen/measurement_tool_points_list_container_height"
android:layout_height="wrap_content"
android:background="?attr/activity_background_color">
<androidx.recyclerview.widget.RecyclerView

View file

@ -78,7 +78,7 @@
<dimen name="measurement_tool_divider_margin">12dp</dimen>
<dimen name="measurement_tool_content_padding_medium">18dp</dimen>
<dimen name="measurement_tool_text_margin">12dp</dimen>
<dimen name="measurement_tool_points_list_container_height">330dp</dimen>
<dimen name="measurement_tool_info_cards_container_height">330dp</dimen>
<dimen name="measurement_tool_up_down_row_height">48dp</dimen>
<dimen name="measurement_tool_text_button_padding_small">18dp</dimen>
<dimen name="measurement_tool_text_button_padding">24dp</dimen>

View file

@ -257,7 +257,7 @@
<dimen name="measurement_tool_content_padding_medium">12dp</dimen>
<dimen name="text_margin_small">4dp</dimen>
<dimen name="measurement_tool_text_margin">8dp</dimen>
<dimen name="measurement_tool_points_list_container_height">220dp</dimen>
<dimen name="measurement_tool_info_cards_container_height">220dp</dimen>
<dimen name="measurement_tool_up_down_row_height">60dp</dimen>
<dimen name="measurement_tool_controls_height">52dp</dimen>
<dimen name="measurement_tool_text_button_padding_small">8dp</dimen>

View file

@ -63,6 +63,8 @@ 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);
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()) {
AndroidUtils.setBackground(holder.button, app.getUIUtilities().getPaintedIcon(

View file

@ -518,7 +518,9 @@ public class TrackDetailsMenu {
} else {
gpxItem.chartHighlightPos = -1;
}
if (shouldShowXAxisPoints()) {
trackChartPoints.setXAxisPoints(getXAxisPoints(chart));
}
if (gpxItem.route) {
mapActivity.getMapLayers().getMapInfoLayer().setTrackChartPoints(trackChartPoints);
} else {
@ -530,6 +532,10 @@ public class TrackDetailsMenu {
fitTrackOnMap(chart, location, forceFit);
}
public boolean shouldShowXAxisPoints () {
return true;
}
public void reset() {
segment = null;
trackChartPoints = null;

View file

@ -29,7 +29,7 @@ import net.osmand.plus.helpers.GpxUiHelper.LineGraphType;
import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter;
import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter.HorizontalSelectionAdapterListener;
import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenu;
import net.osmand.plus.measurementtool.MeasurementToolFragment.OnUpdateAdditionalInfoListener;
import net.osmand.plus.measurementtool.MeasurementToolFragment.OnUpdateInfoListener;
import net.osmand.plus.measurementtool.graph.CommonGraphAdapter;
import net.osmand.plus.measurementtool.graph.CustomGraphAdapter;
import net.osmand.plus.measurementtool.graph.CustomGraphAdapter.LegendViewType;
@ -53,7 +53,7 @@ import static net.osmand.plus.helpers.GpxUiHelper.LineGraphType.SPEED;
import static net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter.HorizontalSelectionItem;
import static net.osmand.router.RouteStatisticsHelper.RouteStatistics;
public class GraphsCard extends BaseCard implements OnUpdateAdditionalInfoListener {
public class GraphsCard extends BaseCard implements OnUpdateInfoListener {
private static String GRAPH_DATA_GPX_FILE_NAME = "graph_data_tmp";
private static int INVALID_ID = -1;
@ -114,11 +114,11 @@ public class GraphsCard extends BaseCard implements OnUpdateAdditionalInfoListen
@Override
public int getCardLayoutId() {
return R.layout.fragment_measurement_tool_graph;
return R.layout.measurement_tool_graph_card;
}
@Override
public void onUpdateAdditionalInfo() {
public void onUpdateInfo() {
if (editingCtx != null) {
fullUpdate();
}

View file

@ -75,6 +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.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;
@ -88,8 +91,6 @@ import java.util.Locale;
import static net.osmand.IndexConstants.GPX_FILE_EXT;
import static net.osmand.IndexConstants.GPX_INDEX_DIR;
import static net.osmand.plus.UiUtilities.CustomRadioButtonType.END;
import static net.osmand.plus.UiUtilities.CustomRadioButtonType.START;
import static net.osmand.plus.measurementtool.MeasurementEditingContext.CalculationMode;
import static net.osmand.plus.measurementtool.MeasurementEditingContext.SnapToRoadProgressListener;
import static net.osmand.plus.measurementtool.SaveAsNewTrackBottomSheetDialogFragment.SaveAsNewTrackFragmentListener;
@ -113,25 +114,25 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
private TextView pointsTv;
private TextView distanceToCenterTv;
private String pointsSt;
private View additionalInfoContainer;
private ViewGroup cardsContainer;
private BaseCard visibleCard;
private PointsCard pointsCard;
private GraphsCard graphsCard;
private LinearLayout customRadioButton;
private MultiStateToggleButton infoTypeBtn;
private RadioItem pointsBtn;
private RadioItem graphBtn;
private View mainView;
private ImageView upDownBtn;
private ImageView undoBtn;
private ImageView redoBtn;
private ImageView mainIcon;
private Snackbar snackbar;
private String fileName;
private AdditionalInfoType currentAdditionalInfoType;
private InfoType currentInfoType;
private boolean wasCollapseButtonVisible;
private boolean progressBarVisible;
private boolean additionalInfoExpanded;
private boolean infoExpanded;
private static final int PLAN_ROUTE_MODE = 0x1;
private static final int DIRECTION_MODE = 0x2;
@ -148,18 +149,13 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
private LatLon initialPoint;
enum SaveType {
ROUTE,
LINE
}
enum FinalSaveAction {
SHOW_SNACK_BAR_AND_CLOSE,
SHOW_TOAST,
SHOW_IS_SAVED_FRAGMENT
}
private enum AdditionalInfoType {
private enum InfoType {
POINTS,
GRAPH
}
@ -175,6 +171,10 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
protected int getFragmentHeight() {
return mainView.getHeight();
}
public boolean shouldShowXAxisPoints () {
return false;
}
}
private void setEditingCtx(MeasurementEditingContext editingCtx) {
@ -230,13 +230,14 @@ 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() {
@Override
public void showProgressBar() {
MeasurementToolFragment.this.showProgressBar();
updateAdditionalInfoView();
updateInfoView();
}
@Override
@ -248,7 +249,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
public void hideProgressBar() {
((ProgressBar) mainView.findViewById(R.id.snap_to_road_progress_bar)).setVisibility(View.GONE);
progressBarVisible = false;
updateAdditionalInfoView();
updateInfoView();
}
@Override
@ -262,6 +263,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
portrait = AndroidUiHelper.isOrientationPortrait(mapActivity);
int btnWidth = getResources().getDimensionPixelOffset(R.dimen.gpx_group_button_width);
pointsSt = getString(R.string.shared_string_gpx_points).toLowerCase();
@ -271,30 +273,19 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
mainView = view.findViewById(R.id.main_view);
AndroidUtils.setBackground(mapActivity, mainView, nightMode, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark);
detailsMenu = new GraphDetailsMenu();
additionalInfoContainer = mainView.findViewById(R.id.additional_info_container);
cardsContainer = mainView.findViewById(R.id.cards_container);
if (portrait) {
customRadioButton = mainView.findViewById(R.id.custom_radio_buttons);
String pointsBtnTitle = getString(R.string.shared_string_gpx_points);
pointsBtn = new RadioItem(pointsBtnTitle);
pointsBtn.setOnClickListener(getInfoTypeBtnListener(InfoType.POINTS));
View pointListBtn = customRadioButton.findViewById(R.id.left_button_container);
TextView tvPointListBtn = customRadioButton.findViewById(R.id.left_button);
tvPointListBtn.setText(R.string.shared_string_gpx_points);
pointListBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
changeAdditionalInfoType(AdditionalInfoType.POINTS);
}
});
String graphBtnTitle = getString(R.string.shared_string_graph);
graphBtn = new RadioItem(graphBtnTitle);
graphBtn.setOnClickListener(getInfoTypeBtnListener(InfoType.GRAPH));
View graphBtn = customRadioButton.findViewById(R.id.right_button_container);
TextView tvGraphBtn = customRadioButton.findViewById(R.id.right_button);
tvGraphBtn.setText(R.string.shared_string_graph);
graphBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
changeAdditionalInfoType(AdditionalInfoType.GRAPH);
}
});
LinearLayout infoButtonsContainer = mainView.findViewById(R.id.custom_radio_buttons);
infoTypeBtn = new MultiStateToggleButton(app, infoButtonsContainer, nightMode);
infoTypeBtn.setItems(pointsBtn, graphBtn);
}
pointsCard = new PointsCard(mapActivity, this);
graphsCard = new GraphsCard(mapActivity, detailsMenu, this);
@ -328,18 +319,21 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
View upDownRow = mainView.findViewById(R.id.up_down_row);
upDownRow.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
if (!additionalInfoExpanded && editingCtx.getPointsCount() > 0 && editingCtx.getSelectedPointPosition() == -1) {
expandAdditionalInfoView();
} else {
collapseAdditionalInfoView();
public void onClick(View v) {
if (portrait) {
if (infoExpanded) {
collapseInfoView();
} else if (setInfoType(InfoType.POINTS)) {
infoTypeBtn.setSelectedItem(pointsBtn);
}
}
}
});
View applyMovePointButton = mainView.findViewById(R.id.apply_move_point_button);
UiUtilities.setupDialogButton(nightMode, applyMovePointButton, UiUtilities.DialogButtonType.PRIMARY,
R.string.shared_string_apply);
UiUtilities.setupDialogButton(nightMode, applyMovePointButton,
UiUtilities.DialogButtonType.PRIMARY, R.string.shared_string_apply);
applyMovePointButton.setMinimumWidth(btnWidth);
applyMovePointButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
@ -349,8 +343,9 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
View applyPointBeforeAfterButton = mainView.findViewById(R.id.apply_point_before_after_point_button);
UiUtilities.setupDialogButton(nightMode, applyPointBeforeAfterButton, UiUtilities.DialogButtonType.PRIMARY,
R.string.shared_string_apply);
UiUtilities.setupDialogButton(nightMode, applyPointBeforeAfterButton,
UiUtilities.DialogButtonType.PRIMARY, R.string.shared_string_apply);
applyPointBeforeAfterButton.setMinimumWidth(btnWidth);
applyPointBeforeAfterButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
@ -359,8 +354,9 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
});
View addPointBeforeAfterButton = mainView.findViewById(R.id.add_point_before_after_button);
UiUtilities.setupDialogButton(nightMode, addPointBeforeAfterButton, UiUtilities.DialogButtonType.PRIMARY,
R.string.shared_string_add);
UiUtilities.setupDialogButton(nightMode, addPointBeforeAfterButton,
UiUtilities.DialogButtonType.PRIMARY, R.string.shared_string_add);
addPointBeforeAfterButton.setMinimumWidth(btnWidth);
addPointBeforeAfterButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
@ -408,8 +404,9 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
});
View addPointButton = mainView.findViewById(R.id.add_point_button);
UiUtilities.setupDialogButton(nightMode, addPointButton, UiUtilities.DialogButtonType.PRIMARY,
R.string.shared_string_add);
UiUtilities.setupDialogButton(nightMode, addPointButton,
UiUtilities.DialogButtonType.PRIMARY, R.string.shared_string_add);
addPointButton.setMinimumWidth(btnWidth);
addPointButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
@ -425,9 +422,6 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
@Override
public void onSelectPoint(int selectedPointPos) {
if (additionalInfoExpanded) {
collapseAdditionalInfoView();
}
if (selectedPointPos != -1) {
openSelectedPointMenu(mapActivity);
}
@ -449,9 +443,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
measurementLayer.setOnEnterMovePointModeListener(new MeasurementToolLayer.OnEnterMovePointModeListener() {
@Override
public void onEnterMovePointMode() {
if (additionalInfoExpanded) {
collapseAdditionalInfoView();
}
collapseInfoViewIfExpanded();
switchMovePointMode(true);
}
});
@ -529,37 +521,90 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
return view;
}
private void changeAdditionalInfoType(@NonNull AdditionalInfoType type) {
if (!additionalInfoExpanded || !isCurrentAdditionalInfoType(type)) {
MapActivity ma = getMapActivity();
if (ma == null) return;
private OnRadioItemClickListener getInfoTypeBtnListener(@NonNull final InfoType type) {
return new OnRadioItemClickListener() {
@Override
public boolean onRadioItemClick(RadioItem radioItem, View view) {
if (isCurrentInfoType(type)) {
collapseInfoView();
return false;
}
return setInfoType(type);
}
};
}
OsmandApplication app = ma.getMyApplication();
if (AdditionalInfoType.POINTS == type) {
private boolean setInfoType(@NonNull InfoType type) {
OsmandApplication app = getMyApplication();
if ((!infoExpanded || !isCurrentInfoType(type)) && app != null) {
if (editingCtx.getPointsCount() > 0 && editingCtx.getSelectedPointPosition() == -1) {
expandInfoView();
currentInfoType = type;
if (InfoType.POINTS == type) {
visibleCard = pointsCard;
UiUtilities.updateCustomRadioButtons(app, customRadioButton, nightMode, START);
} else if (AdditionalInfoType.GRAPH == type) {
} else if (InfoType.GRAPH == type) {
visibleCard = graphsCard;
UiUtilities.updateCustomRadioButtons(app, customRadioButton, nightMode, END);
}
cardsContainer.removeAllViews();
View cardView = visibleCard.getView() != null ? visibleCard.getView() : visibleCard.build(ma);
View cardView = visibleCard.getView() != null ? visibleCard.getView() : visibleCard.build(app);
cardsContainer.addView(cardView);
return true;
} else {
collapseInfoView();
}
}
return false;
}
currentAdditionalInfoType = type;
additionalInfoExpanded = true;
private void expandInfoView() {
if (portrait) {
infoExpanded = true;
cardsContainer.setVisibility(View.VISIBLE);
setMapPosition(portrait
? OsmandSettings.MIDDLE_TOP_CONSTANT
: OsmandSettings.LANDSCAPE_MIDDLE_RIGHT_CONSTANT);
updateUpDownBtn();
}
}
private void updateAdditionalInfoView() {
updateAdditionalInfoView(pointsCard);
updateAdditionalInfoView(graphsCard);
private void collapseInfoViewIfExpanded() {
if (infoExpanded) {
collapseInfoView();
}
}
private void updateAdditionalInfoView(OnUpdateAdditionalInfoListener listener) {
private void collapseInfoView() {
if (portrait) {
infoExpanded = false;
currentInfoType = null;
infoTypeBtn.setSelectedItem(null);
cardsContainer.setVisibility(View.GONE);
setDefaultMapPosition();
updateUpDownBtn();
}
}
private void collapseInfoIfNotEnoughPoints() {
MeasurementToolLayer measurementLayer = getMeasurementLayer();
if (measurementLayer != null) {
int pointsCount = editingCtx.getPointsCount();
if (isCurrentInfoType(InfoType.GRAPH) && pointsCount < 2) {
collapseInfoView();
} else if (pointsCount < 1) {
disable(upDownBtn);
collapseInfoViewIfExpanded();
}
}
}
private void updateInfoView() {
updateInfoView(pointsCard);
updateInfoView(graphsCard);
}
private void updateInfoView(OnUpdateInfoListener listener) {
if (listener != null) {
listener.onUpdateAdditionalInfo();
listener.onUpdateInfo();
}
}
@ -576,11 +621,11 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
}
private void updateUndoRedoCommonStuff() {
collapseAdditionalInfoIfNoPointsEnough();
collapseInfoIfNotEnoughPoints();
if (editingCtx.getPointsCount() > 0) {
enable(upDownBtn);
}
updateAdditionalInfoView();
updateInfoView();
updateDistancePointsText();
updateSnapToRoadControls();
}
@ -638,9 +683,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
super.onDestroyView();
cancelModes();
exitMeasurementMode();
if (additionalInfoExpanded) {
collapseAdditionalInfoView();
}
collapseInfoViewIfExpanded();
MeasurementToolLayer layer = getMeasurementLayer();
if (layer != null) {
layer.setOnSingleTapListener(null);
@ -891,9 +934,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
MeasurementToolLayer measurementLayer = getMeasurementLayer();
editingCtx.getCommandManager().execute(new ClearPointsCommand(measurementLayer, ALL));
editingCtx.cancelSnapToRoad();
if (additionalInfoExpanded) {
collapseAdditionalInfoView();
}
collapseInfoViewIfExpanded();
updateUndoRedoButton(false, redoBtn);
disable(upDownBtn);
updateDistancePointsText();
@ -907,9 +948,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
if (points.size() > 1) {
MeasurementToolLayer measurementLayer = getMeasurementLayer();
editingCtx.getCommandManager().execute(new ReversePointsCommand(measurementLayer));
if (additionalInfoExpanded) {
collapseAdditionalInfoView();
}
collapseInfoViewIfExpanded();
updateUndoRedoButton(false, redoBtn);
updateUndoRedoButton(true, undoBtn);
updateDistancePointsText();
@ -976,9 +1015,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
private void trimRoute(ClearCommandMode before) {
MeasurementToolLayer measurementLayer = getMeasurementLayer();
editingCtx.getCommandManager().execute(new ClearPointsCommand(measurementLayer, before));
if (additionalInfoExpanded) {
collapseAdditionalInfoView();
}
collapseInfoViewIfExpanded();
editingCtx.setSelectedPointPosition(-1);
editingCtx.splitSegments(editingCtx.getBeforePoints().size() + editingCtx.getAfterPoints().size());
updateUndoRedoButton(false, redoBtn);
@ -1130,11 +1167,11 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
private void removePoint(MeasurementToolLayer measurementLayer, int position) {
if (measurementLayer != null) {
editingCtx.getCommandManager().execute(new RemovePointCommand(measurementLayer, position));
updateAdditionalInfoView();
updateInfoView();
updateUndoRedoButton(true, undoBtn);
updateUndoRedoButton(false, redoBtn);
updateDistancePointsText();
collapseAdditionalInfoIfNoPointsEnough();
collapseInfoIfNotEnoughPoints();
}
}
@ -1159,9 +1196,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
@Override
public void onItemClick(int position) {
if (mapActivity != null && measurementLayer != null) {
if (additionalInfoExpanded) {
collapseAdditionalInfoView();
}
collapseInfoViewIfExpanded();
if (portrait) {
setMapPosition(OsmandSettings.MIDDLE_TOP_CONSTANT);
}
@ -1182,7 +1217,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
toPosition = holder.getAdapterPosition();
if (toPosition >= 0 && fromPosition >= 0 && toPosition != fromPosition) {
editingCtx.getCommandManager().execute(new ReorderPointCommand(measurementLayer, fromPosition, toPosition));
updateAdditionalInfoView();
updateInfoView();
updateUndoRedoButton(false, redoBtn);
updateDistancePointsText();
mapActivity.refreshMap();
@ -1248,7 +1283,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
if (!isUndoMode()) {
editingCtx.addPoints();
}
updateAdditionalInfoView();
updateInfoView();
updateDistancePointsText();
}
}
@ -1406,7 +1441,9 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
R.id.measurement_points_text_view,
R.id.distance_to_center_text_view,
R.id.up_down_button,
R.id.measure_mode_controls);
R.id.measure_mode_controls,
R.id.info_type_buttons_container,
R.id.bottom_panel_divider);
}
}
@ -1444,46 +1481,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
updateUndoRedoButton(true, undoBtn);
updateUndoRedoButton(false, redoBtn);
updateDistancePointsText();
updateAdditionalInfoView();
}
private void expandAdditionalInfoView() {
if (portrait) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
additionalInfoContainer.setVisibility(View.VISIBLE);
AdditionalInfoType typeToShow = currentAdditionalInfoType == null
? AdditionalInfoType.POINTS : currentAdditionalInfoType;
changeAdditionalInfoType(typeToShow);
setMapPosition(portrait
? OsmandSettings.MIDDLE_TOP_CONSTANT
: OsmandSettings.LANDSCAPE_MIDDLE_RIGHT_CONSTANT);
}
}
}
private void collapseAdditionalInfoView() {
if (portrait) {
additionalInfoExpanded = false;
updateUpDownBtn();
additionalInfoContainer.setVisibility(View.GONE);
setDefaultMapPosition();
}
}
private void collapseAdditionalInfoIfNoPointsEnough() {
MeasurementToolLayer measurementLayer = getMeasurementLayer();
if (measurementLayer != null) {
int pointsCount = editingCtx.getPointsCount();
if (isCurrentAdditionalInfoType(AdditionalInfoType.GRAPH) && pointsCount < 2) {
collapseAdditionalInfoView();
} else if (pointsCount < 1) {
disable(upDownBtn);
if (additionalInfoExpanded) {
collapseAdditionalInfoView();
}
}
}
updateInfoView();
}
private void setDefaultMapPosition() {
@ -1510,13 +1508,13 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
}
private void updateUpDownBtn() {
Drawable icon = getContentIcon(additionalInfoExpanded
Drawable icon = getContentIcon(infoExpanded
? R.drawable.ic_action_arrow_down : R.drawable.ic_action_arrow_up);
upDownBtn.setImageDrawable(icon);
}
private boolean isCurrentAdditionalInfoType(@NonNull AdditionalInfoType type) {
return type.equals(currentAdditionalInfoType);
private boolean isCurrentInfoType(@NonNull InfoType type) {
return Algorithms.objectEquals(currentInfoType, type);
}
public boolean hasVisibleGraph() {
@ -1600,7 +1598,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
switch (finalSaveAction) {
case SHOW_SNACK_BAR_AND_CLOSE:
final WeakReference<MapActivity> mapActivityRef = new WeakReference<>(mapActivity);
snackbar = Snackbar.make(mapActivity.getLayout(),
Snackbar snackbar = Snackbar.make(mapActivity.getLayout(),
MessageFormat.format(getString(R.string.gpx_saved_sucessfully), outFile.getName()),
Snackbar.LENGTH_LONG)
.setAction(R.string.shared_string_undo, new OnClickListener() {
@ -1778,7 +1776,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
}
}
public void quit(boolean hidePointsListFirst) {
public void quit(boolean hideInfoViewFirst) {
if (editingCtx.getOriginalPointToMove() != null) {
cancelMovePointMode();
return;
@ -1793,16 +1791,16 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
dismiss(mapActivity);
}
} else {
showQuitDialog(hidePointsListFirst);
showQuitDialog(hideInfoViewFirst);
}
}
private void showQuitDialog(boolean hidePointsListFirst) {
private void showQuitDialog(boolean hideInfoViewFirst) {
final MapActivity mapActivity = getMapActivity();
MeasurementToolLayer measurementLayer = getMeasurementLayer();
if (mapActivity != null && measurementLayer != null) {
if (additionalInfoExpanded && hidePointsListFirst) {
collapseAdditionalInfoView();
if (infoExpanded && hideInfoViewFirst) {
collapseInfoView();
return;
}
if (!editingCtx.hasChanges()) {
@ -1822,9 +1820,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
if (clearContext) {
editingCtx.clearSegments();
}
if (additionalInfoExpanded) {
collapseAdditionalInfoView();
}
collapseInfoViewIfExpanded();
resetAppMode();
hideSnapToRoadIcon();
if (isInEditMode()) {
@ -1961,9 +1957,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
if (!approximationMode || !editingCtx.getCommandManager().update(command)) {
editingCtx.getCommandManager().execute(command);
}
if (additionalInfoExpanded) {
collapseAdditionalInfoView();
}
collapseInfoViewIfExpanded();
updateSnapToRoadControls();
}
}
@ -2036,7 +2030,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
return nightMode;
}
public interface OnUpdateAdditionalInfoListener {
void onUpdateAdditionalInfo();
public interface OnUpdateInfoListener {
void onUpdateInfo();
}
}

View file

@ -7,12 +7,12 @@ import androidx.recyclerview.widget.RecyclerView;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.measurementtool.MeasurementToolFragment.OnUpdateAdditionalInfoListener;
import net.osmand.plus.measurementtool.MeasurementToolFragment.OnUpdateInfoListener;
import net.osmand.plus.measurementtool.adapter.MeasurementToolAdapter;
import net.osmand.plus.routepreparationmenu.cards.BaseCard;
import net.osmand.plus.views.controls.ReorderItemTouchHelperCallback;
public class PointsCard extends BaseCard implements OnUpdateAdditionalInfoListener {
public class PointsCard extends BaseCard implements OnUpdateInfoListener {
private MeasurementToolAdapter adapter;
private MeasurementToolFragment fragment;
@ -23,7 +23,7 @@ public class PointsCard extends BaseCard implements OnUpdateAdditionalInfoListen
}
@Override
public void onUpdateAdditionalInfo() {
public void onUpdateInfo() {
if (adapter != null) {
adapter.notifyDataSetChanged();
}
@ -31,7 +31,7 @@ public class PointsCard extends BaseCard implements OnUpdateAdditionalInfoListen
@Override
public int getCardLayoutId() {
return R.layout.fragment_measurement_tool_points_list;
return R.layout.measurement_tool_points_card;
}
@Override

View file

@ -0,0 +1,183 @@
package net.osmand.plus.widgets;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import net.osmand.AndroidUtils;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
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;
private LinearLayout container;
private boolean nightMode;
public MultiStateToggleButton(OsmandApplication app, LinearLayout container, boolean nightMode) {
this.app = app;
this.container = container;
this.nightMode = nightMode;
}
public void setItems(RadioItem firstBtn, RadioItem secondBtn, RadioItem ... other) {
items.clear();
items.add(firstBtn);
items.add(secondBtn);
if (other != null && other.length > 0) {
items.addAll(Arrays.asList(other));
}
initView();
}
private void initView() {
buttons.clear();
dividers.clear();
container.removeAllViews();
for (int i = 0; i < items.size(); i++) {
createBtn(items.get(i));
if (!isLastItem(i)) {
createDivider();
}
}
updateView();
}
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();
if (l != null && l.onRadioItemClick(item, container)) {
setSelectedItem(item);
}
}
});
buttons.add(button);
container.addView(button);
}
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(app, 1.0f);
View divider = new View(app);
divider.setLayoutParams(new ViewGroup.LayoutParams(width, ViewGroup.LayoutParams.MATCH_PARENT));
divider.setBackgroundColor(ContextCompat.getColor(app, dividerColor));
dividers.add(divider);
container.addView(divider);
}
public void setSelectedItem(RadioItem selectedItem) {
this.selectedItem = selectedItem;
updateView();
}
private void updateView() {
int activeColor = ContextCompat.getColor(app, nightMode
? R.color.active_color_primary_dark
: R.color.active_color_primary_light);
int textColor = ContextCompat.getColor(app, nightMode
? R.color.text_color_primary_dark
: R.color.text_color_primary_light);
int radius = AndroidUtils.dpToPx(app, 4);
float[] leftBtnRadii = new float[]{radius, radius, 0, 0, 0, 0, radius, radius};
float[] rightBtnRadii = new float[]{0, 0, radius, radius, radius, radius, 0, 0};
float[] centerBtnRadii = new float[]{0, 0, 0, 0, 0, 0, 0, 0};
boolean isLayoutRtl = AndroidUtils.isLayoutRtl(app);
GradientDrawable background = new GradientDrawable();
background.setColor(UiUtilities.getColorWithAlpha(activeColor, 0.1f));
background.setStroke(AndroidUtils.dpToPx(app, 1), UiUtilities.getColorWithAlpha(activeColor, 0.5f));
showAllDividers();
for (int i = 0; i < items.size(); i++) {
RadioItem item = items.get(i);
ViewGroup container = buttons.get(i);
TextView tvTitle = (TextView) container.findViewById(R.id.title);
if (selectedItem == item) {
if (i == 0) {
background.setCornerRadii(isLayoutRtl ? rightBtnRadii : leftBtnRadii);
hideDividers(0);
} else if (i == items.size() - 1) {
background.setCornerRadii(isLayoutRtl ? leftBtnRadii : rightBtnRadii);
hideDividers(dividers.size() - 1);
} else {
background.setCornerRadii(centerBtnRadii);
hideDividers(i - 1, i);
}
container.setBackgroundDrawable(background);
tvTitle.setTextColor(textColor);
} else {
container.setBackgroundColor(Color.TRANSPARENT);
tvTitle.setTextColor(activeColor);
}
}
}
private void showAllDividers() {
for (View divider : dividers) {
divider.setVisibility(View.VISIBLE);
}
}
private void hideDividers(int ... dividerIndexes) {
for (int dividerIndex : dividerIndexes) {
if (dividerIndex >= 0 && dividerIndex < dividers.size()) {
dividers.get(dividerIndex).setVisibility(View.GONE);
}
}
}
public static class RadioItem {
private String title;
private OnRadioItemClickListener listener;
public RadioItem(String title) {
this.title = title;
}
public void setOnClickListener(OnRadioItemClickListener listener) {
this.listener = listener;
}
public String getTitle() {
return title;
}
public OnRadioItemClickListener getListener() {
return listener;
}
}
public interface OnRadioItemClickListener {
boolean onRadioItemClick(RadioItem radioItem, View view);
}
}