Added analyse on map to route details

This commit is contained in:
crimean 2019-03-29 15:57:14 +03:00
parent e0f9aaf6bf
commit d7592a693b
6 changed files with 109 additions and 38 deletions

View file

@ -9,7 +9,7 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:baselineAligned="false" android:baselineAligned="false"
android:orientation="horizontal" android:orientation="horizontal"
android:paddingTop="8dp" android:paddingTop="8dp"
@ -20,6 +20,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:orientation="horizontal" android:orientation="horizontal"
android:paddingStart="16dp"
android:paddingLeft="16dp"> android:paddingLeft="16dp">
<ImageView <ImageView
@ -32,6 +33,7 @@
<LinearLayout <LinearLayout
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="18dp"
android:layout_marginLeft="18dp" android:layout_marginLeft="18dp"
android:orientation="vertical"> android:orientation="vertical">
@ -63,6 +65,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:orientation="horizontal" android:orientation="horizontal"
android:paddingStart="16dp"
android:paddingLeft="16dp"> android:paddingLeft="16dp">
<ImageView <ImageView
@ -75,6 +78,7 @@
<LinearLayout <LinearLayout
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="18dp"
android:layout_marginLeft="18dp" android:layout_marginLeft="18dp"
android:orientation="vertical"> android:orientation="vertical">
@ -105,7 +109,7 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical">
<com.github.mikephil.charting.charts.LineChart <com.github.mikephil.charting.charts.LineChart
@ -118,7 +122,7 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:baselineAligned="false" android:baselineAligned="false"
android:orientation="horizontal" android:orientation="horizontal"
android:paddingBottom="4dp"> android:paddingBottom="4dp">
@ -128,6 +132,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:orientation="horizontal" android:orientation="horizontal"
android:paddingStart="16dp"
android:paddingLeft="16dp"> android:paddingLeft="16dp">
<ImageView <ImageView
@ -140,6 +145,7 @@
<LinearLayout <LinearLayout
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="18dp"
android:layout_marginLeft="18dp" android:layout_marginLeft="18dp"
android:orientation="vertical"> android:orientation="vertical">
@ -171,6 +177,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:orientation="horizontal" android:orientation="horizontal"
android:paddingStart="16dp"
android:paddingLeft="16dp"> android:paddingLeft="16dp">
<ImageView <ImageView
@ -183,6 +190,7 @@
<LinearLayout <LinearLayout
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="18dp"
android:layout_marginLeft="18dp" android:layout_marginLeft="18dp"
android:orientation="vertical"> android:orientation="vertical">
@ -213,7 +221,7 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:baselineAligned="false" android:baselineAligned="false"
android:orientation="horizontal" android:orientation="horizontal"
android:paddingTop="4dp" android:paddingTop="4dp"
@ -224,7 +232,9 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:orientation="horizontal" android:orientation="horizontal"
android:paddingStart="16dp"
android:paddingLeft="16dp" android:paddingLeft="16dp"
android:paddingEnd="8dp"
android:paddingRight="8dp"> android:paddingRight="8dp">
<View <View
@ -239,7 +249,9 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:orientation="horizontal" android:orientation="horizontal"
android:paddingStart="8dp"
android:paddingLeft="8dp" android:paddingLeft="8dp"
android:paddingEnd="16dp"
android:paddingRight="16dp"> android:paddingRight="16dp">
<View <View
@ -253,7 +265,7 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:baselineAligned="false" android:baselineAligned="false"
android:orientation="horizontal" android:orientation="horizontal"
android:paddingTop="4dp" android:paddingTop="4dp"
@ -264,6 +276,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:orientation="horizontal" android:orientation="horizontal"
android:paddingStart="16dp"
android:paddingLeft="16dp"> android:paddingLeft="16dp">
<ImageView <ImageView
@ -276,6 +289,7 @@
<LinearLayout <LinearLayout
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="18dp"
android:layout_marginLeft="18dp" android:layout_marginLeft="18dp"
android:orientation="vertical"> android:orientation="vertical">
@ -307,6 +321,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:orientation="horizontal" android:orientation="horizontal"
android:paddingStart="16dp"
android:paddingLeft="16dp"> android:paddingLeft="16dp">
<ImageView <ImageView
@ -319,6 +334,7 @@
<LinearLayout <LinearLayout
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="18dp"
android:layout_marginLeft="18dp" android:layout_marginLeft="18dp"
android:orientation="vertical"> android:orientation="vertical">
@ -347,4 +363,40 @@
</LinearLayout> </LinearLayout>
<LinearLayout
android:id="@+id/buttons_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/route_info_buttons_padding_top_bottom"
android:layout_marginTop="@dimen/route_info_details_padding"
android:layout_marginRight="@dimen/route_info_buttons_padding_top_bottom"
android:layout_marginBottom="@dimen/route_info_details_padding"
android:visibility="visible">
<FrameLayout
android:id="@+id/analyse_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="horizontal">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/analyse_button_descr"
android:layout_width="match_parent"
android:layout_height="36dp"
android:layout_gravity="center"
android:ellipsize="end"
android:gravity="center"
android:letterSpacing="@dimen/text_button_letter_spacing"
android:maxLines="1"
android:text="@string/analyze_on_map"
android:textColor="?attr/active_color_basic"
android:textSize="@dimen/text_button_text_size"
osmand:typeface="@string/font_roboto_medium"
tools:ignore="UnusedAttribute" />
</FrameLayout>
</LinearLayout>
</LinearLayout> </LinearLayout>

View file

@ -288,7 +288,7 @@ public class TrackDetailsMenu {
tileBoxHeightPx = tb.getPixHeight() - f.getHeight(); tileBoxHeightPx = tb.getPixHeight() - f.getHeight();
} }
} }
if (tileBoxHeightPx > 0) { if (tileBoxHeightPx > 0 || tileBoxWidthPx > 0) {
if (forceFit) { if (forceFit) {
mapActivity.getMapView().fitRectToMap(rect.left, rect.right, rect.top, rect.bottom, mapActivity.getMapView().fitRectToMap(rect.left, rect.right, rect.top, rect.bottom,
tileBoxWidthPx, tileBoxHeightPx, topMarginPx); tileBoxWidthPx, tileBoxHeightPx, topMarginPx);

View file

@ -31,10 +31,14 @@ import android.widget.ImageButton;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.GPXUtilities; import net.osmand.GPXUtilities;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
import net.osmand.plus.LockableViewPager; import net.osmand.plus.LockableViewPager;
import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmAndLocationProvider; import net.osmand.plus.OsmAndLocationProvider;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.MapActivityActions; import net.osmand.plus.activities.MapActivityActions;
@ -90,6 +94,7 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe
private boolean publicTransportMode; private boolean publicTransportMode;
private int routeInfoMenuState = -1; private int routeInfoMenuState = -1;
private boolean openingAnalyseOnMap = false;
@Nullable @Nullable
@Override @Override
@ -236,12 +241,26 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe
return getIcon(id, nightMode ? R.color.ctx_menu_info_text_dark : R.color.icon_color); return getIcon(id, nightMode ? R.color.ctx_menu_info_text_dark : R.color.icon_color);
} }
public void analyseOnMap(LatLon location, GpxDisplayItem gpxItem) {
openingAnalyseOnMap = true;
OsmandApplication app = requireMyApplication();
final OsmandSettings settings = app.getSettings();
settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(),
settings.getLastKnownMapZoom(),
new PointDescription(PointDescription.POINT_TYPE_WPT, gpxItem.name),
false,
gpxItem);
dismiss();
MapActivity.launchMapActivityMoveToTop(getMapActivity());
}
public void dismiss() { public void dismiss() {
try { try {
MapActivity mapActivity = getMapActivity(); MapActivity mapActivity = getMapActivity();
if (mapActivity != null) { if (mapActivity != null) {
mapActivity.getSupportFragmentManager().beginTransaction().remove(this).commitAllowingStateLoss(); mapActivity.getSupportFragmentManager().beginTransaction().remove(this).commitAllowingStateLoss();
if (routeInfoMenuState != -1) { if (routeInfoMenuState != -1 && !openingAnalyseOnMap) {
mapActivity.getMapLayers().getMapControlsLayer().showRouteInfoControlDialog(routeInfoMenuState); mapActivity.getMapLayers().getMapControlsLayer().showRouteInfoControlDialog(routeInfoMenuState);
} }
} }

View file

@ -255,10 +255,10 @@ public class MapRouteInfoMenuFragment extends ContextMenuFragment {
@Override @Override
protected void calculateLayout(View view) { protected void calculateLayout(View view) {
super.calculateLayout(view);
menuTitleHeight = view.findViewById(R.id.route_menu_top_shadow_all).getHeight() menuTitleHeight = view.findViewById(R.id.route_menu_top_shadow_all).getHeight()
+ view.findViewById(R.id.control_buttons).getHeight() + view.findViewById(R.id.control_buttons).getHeight()
- view.findViewById(R.id.buttons_shadow).getHeight(); - view.findViewById(R.id.buttons_shadow).getHeight();
super.calculateLayout(view);
} }
private void adjustMapPosition(int y) { private void adjustMapPosition(int y) {

View file

@ -12,6 +12,7 @@ import android.os.Bundle;
import android.support.annotation.ColorInt; import android.support.annotation.ColorInt;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.support.v7.view.ContextThemeWrapper; import android.support.v7.view.ContextThemeWrapper;
import android.text.Spannable; import android.text.Spannable;
@ -320,6 +321,11 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT
} }
return false; return false;
} }
}, new OnClickListener() {
@Override
public void onClick(View v) {
openDetails();
}
}); });
statisticCard.setTransparentBackground(true); statisticCard.setTransparentBackground(true);
menuCards.add(statisticCard); menuCards.add(statisticCard);
@ -1444,7 +1450,6 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT
void openDetails() { void openDetails() {
if (gpxItem != null && elevationDataSet != null) { if (gpxItem != null && elevationDataSet != null) {
OsmandApplication app = requireMyApplication();
LatLon location = null; LatLon location = null;
WptPt wpt = null; WptPt wpt = null;
gpxItem.chartTypes = new GPXDataSetType[]{GPXDataSetType.ALTITUDE, GPXDataSetType.SLOPE}; gpxItem.chartTypes = new GPXDataSetType[]{GPXDataSetType.ALTITUDE, GPXDataSetType.SLOPE};
@ -1473,33 +1478,9 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT
gpxItem.locationOnMap = gpxItem.locationStart; gpxItem.locationOnMap = gpxItem.locationStart;
} }
final MapActivity activity = (MapActivity) getActivity(); ChooseRouteFragment parent = (ChooseRouteFragment) getParentFragment();
if (activity != null) { if (parent != null) {
dismiss(); parent.analyseOnMap(location, gpxItem);
final OsmandSettings settings = app.getSettings();
settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(),
settings.getLastKnownMapZoom(),
new PointDescription(PointDescription.POINT_TYPE_WPT, gpxItem.name),
false,
gpxItem);
final MapRouteInfoMenu mapRouteInfoMenu = activity.getMapRouteInfoMenu();
if (mapRouteInfoMenu.isVisible()) {
// We arrived here by the route info menu.
// First, we close it and then show the details.
mapRouteInfoMenu.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
mapRouteInfoMenu.setOnDismissListener(null);
MapActivity.launchMapActivityMoveToTop(activity);
}
});
mapRouteInfoMenu.hide();
} else {
// We arrived here by the dashboard.
MapActivity.launchMapActivityMoveToTop(activity);
}
} }
} }
} }

View file

@ -1,11 +1,15 @@
package net.osmand.plus.routepreparationmenu.cards; package net.osmand.plus.routepreparationmenu.cards;
import android.graphics.Matrix; import android.graphics.Matrix;
import android.os.Build;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.text.SpannableStringBuilder; import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan; import android.text.style.ForegroundColorSpan;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.FrameLayout;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
@ -16,6 +20,7 @@ import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import com.github.mikephil.charting.listener.ChartTouchListener.ChartGesture; import com.github.mikephil.charting.listener.ChartTouchListener.ChartGesture;
import com.github.mikephil.charting.listener.OnChartGestureListener; import com.github.mikephil.charting.listener.OnChartGestureListener;
import net.osmand.AndroidUtils;
import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.GPXTrackAnalysis; import net.osmand.GPXUtilities.GPXTrackAnalysis;
import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.GpxSelectionHelper;
@ -40,12 +45,15 @@ public class RouteStatisticCard extends BaseCard {
private OrderedLineDataSet slopeDataSet; private OrderedLineDataSet slopeDataSet;
@Nullable @Nullable
private OrderedLineDataSet elevationDataSet; private OrderedLineDataSet elevationDataSet;
private View.OnTouchListener onTouchListener; private OnTouchListener onTouchListener;
private OnClickListener onAnalyseClickListener;
public RouteStatisticCard(MapActivity mapActivity, GPXFile gpx, View.OnTouchListener onTouchListener) { public RouteStatisticCard(MapActivity mapActivity, GPXFile gpx, OnTouchListener onTouchListener,
OnClickListener onAnalyseClickListener) {
super(mapActivity); super(mapActivity);
this.gpx = gpx; this.gpx = gpx;
this.onTouchListener = onTouchListener; this.onTouchListener = onTouchListener;
this.onAnalyseClickListener = onAnalyseClickListener;
makeGpxDisplayItem(); makeGpxDisplayItem();
} }
@ -115,6 +123,17 @@ public class RouteStatisticCard extends BaseCard {
if (isTransparentBackground()) { if (isTransparentBackground()) {
view.setBackgroundDrawable(null); view.setBackgroundDrawable(null);
} }
FrameLayout analyseButton = (FrameLayout) view.findViewById(R.id.analyse_button);
TextView analyseButtonDescr = (TextView) view.findViewById(R.id.analyse_button_descr);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
AndroidUtils.setBackground(app, analyseButton, nightMode, R.drawable.btn_border_light, R.drawable.btn_border_dark);
AndroidUtils.setBackground(app, analyseButtonDescr, nightMode, R.drawable.ripple_light, R.drawable.ripple_dark);
} else {
AndroidUtils.setBackground(app, analyseButton, nightMode, R.drawable.btn_border_trans_light, R.drawable.btn_border_trans_dark);
}
analyseButton.setOnClickListener(onAnalyseClickListener);
} }
@Nullable @Nullable