Merge branch 'r3.3'

This commit is contained in:
crimean 2019-04-20 18:03:54 +03:00
commit 4b5240586b
6 changed files with 99 additions and 26 deletions

View file

@ -878,7 +878,7 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment {
if (getActivity() == null) {
return;
}
calculateLayout(view);
calculateLayout(view, initLayout);
if (!moving) {
doLayoutMenu();
@ -895,7 +895,7 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment {
}
}
protected void calculateLayout(View view) {
protected void calculateLayout(View view, boolean initLayout) {
menuFullHeight = mainView.getHeight();
menuBottomViewHeight = menuFullHeight;
menuFullHeightMax = view.findViewById(R.id.route_menu_cards_container).getHeight() +

View file

@ -338,14 +338,13 @@ public class TrackDetailsMenu {
int tileBoxWidthPx = 0;
int tileBoxHeightPx = 0;
TrackDetailsMenuFragment fragment = getMenuFragment();
if (fragment != null) {
boolean portrait = AndroidUiHelper.isOrientationPortrait(mapActivity);
if (!portrait) {
tileBoxWidthPx = tb.getPixWidth() - fragment.getWidth();
} else {
tileBoxHeightPx = tb.getPixHeight() - fragment.getHeight();
}
boolean portrait = AndroidUiHelper.isOrientationPortrait(mapActivity);
if (!portrait) {
int width = getFragmentWidth();
tileBoxWidthPx = width != -1 ? tb.getPixWidth() - width : 0;
} else {
int height = getFragmentHeight();
tileBoxHeightPx = height != -1 ? tb.getPixHeight() - height : 0;
}
if (tileBoxHeightPx > 0 || tileBoxWidthPx > 0) {
if (forceFit) {
@ -363,6 +362,22 @@ public class TrackDetailsMenu {
}
}
protected int getFragmentWidth() {
TrackDetailsMenuFragment fragment = getMenuFragment();
if (fragment != null) {
return fragment.getWidth();
}
return -1;
}
protected int getFragmentHeight() {
TrackDetailsMenuFragment fragment = getMenuFragment();
if (fragment != null) {
return fragment.getHeight();
}
return -1;
}
public void refreshChart(LineChart chart, boolean forceFit) {
MapActivity mapActivity = getMapActivity();
GpxDisplayItem gpxItem = getGpxItem();

View file

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

View file

@ -35,6 +35,8 @@ import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.dataprovider.BarDataProvider;
import com.github.mikephil.charting.listener.ChartTouchListener;
import com.github.mikephil.charting.listener.ChartTouchListener.ChartGesture;
import com.github.mikephil.charting.renderer.HorizontalBarChartRenderer;
import com.github.mikephil.charting.utils.ViewPortHandler;
@ -120,12 +122,25 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT
private RouteDetailsFragmentListener routeDetailsListener;
private RouteStatisticCard statisticCard;
private List<RouteInfoCard> routeInfoCards = new ArrayList<>();
private TrackDetailsMenu trackDetailsMenu;
private RouteDetailsMenu routeDetailsMenu;
public interface RouteDetailsFragmentListener {
void onNavigationRequested();
}
private class RouteDetailsMenu extends TrackDetailsMenu {
@Override
protected int getFragmentWidth() {
return getWidth();
}
@Override
protected int getFragmentHeight() {
return getMenuFullHeight();
}
}
@Override
public int getMainLayoutId() {
return R.layout.route_info_layout;
@ -186,8 +201,8 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT
MapActivity mapActivity = getMapActivity();
if (mapActivity != null && isPortrait()) {
mapActivity.findViewById(R.id.bottom_controls_container).setVisibility(View.GONE);
if (trackDetailsMenu != null) {
trackDetailsMenu.setMapActivity(mapActivity);
if (routeDetailsMenu != null) {
routeDetailsMenu.setMapActivity(mapActivity);
}
}
}
@ -197,8 +212,8 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT
MapActivity mapActivity = getMapActivity();
if (mapActivity != null && isPortrait()) {
mapActivity.findViewById(R.id.bottom_controls_container).setVisibility(View.VISIBLE);
if (trackDetailsMenu != null) {
trackDetailsMenu.setMapActivity(null);
if (routeDetailsMenu != null) {
routeDetailsMenu.setMapActivity(null);
}
}
super.onPause();
@ -376,17 +391,24 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT
addRouteCard(cardsContainer, routeSmoothnessCard);
}
}
trackDetailsMenu = new TrackDetailsMenu();
routeDetailsMenu = new RouteDetailsMenu();
GpxDisplayItem gpxItem = statisticCard.getGpxItem();
if (gpxItem != null) {
trackDetailsMenu.setGpxItem(gpxItem);
routeDetailsMenu.setGpxItem(gpxItem);
}
trackDetailsMenu.setMapActivity(mapActivity);
routeDetailsMenu.setMapActivity(mapActivity);
LineChart chart = statisticCard.getChart();
if (chart != null) {
chart.setExtraRightOffset(16);
chart.setExtraLeftOffset(16);
trackDetailsMenu.refreshChart(chart, true);
}
}
@Override
protected void calculateLayout(View view, boolean initLayout) {
super.calculateLayout(view, initLayout);
if (!initLayout && getCurrentMenuState() != MenuState.FULL_SCREEN) {
refreshChart(false);
}
}
@ -1644,12 +1666,13 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT
}
}
private void refreshChart() {
private void refreshChart(boolean forceFit) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null && trackDetailsMenu != null && statisticCard != null) {
if (mapActivity != null && routeDetailsMenu != null && statisticCard != null &&
!mapActivity.getMyApplication().getRoutingHelper().isFollowingMode()) {
LineChart chart = statisticCard.getChart();
if (chart != null) {
trackDetailsMenu.refreshChart(chart, false);
routeDetailsMenu.refreshChart(chart, forceFit);
mapActivity.refreshMap();
}
}
@ -1670,7 +1693,7 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT
@Override
public void onValueSelected(BaseCard card, Entry e, Highlight h) {
refreshChart();
refreshChart(false);
highlightRouteInfoCharts(h);
}
@ -1679,6 +1702,23 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT
highlightRouteInfoCharts(null);
}
@Override
public void onChartGestureStart(BaseCard card, MotionEvent me, ChartGesture lastPerformedGesture) {
}
@Override
public void onChartGestureEnd(BaseCard card, MotionEvent me, ChartGesture lastPerformedGesture, boolean hasTranslated) {
if ((lastPerformedGesture == ChartGesture.DRAG && hasTranslated) ||
lastPerformedGesture == ChartGesture.X_ZOOM ||
lastPerformedGesture == ChartGesture.Y_ZOOM ||
lastPerformedGesture == ChartGesture.PINCH_ZOOM ||
lastPerformedGesture == ChartGesture.DOUBLE_TAP ||
lastPerformedGesture == ChartGesture.ROTATE) {
refreshChart(true);
}
}
public static class CumulativeInfo {
public int distance;
public int time;

View file

@ -1,7 +1,11 @@
package net.osmand.plus.routepreparationmenu.cards;
import android.view.MotionEvent;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.listener.ChartTouchListener;
import com.github.mikephil.charting.listener.ChartTouchListener.ChartGesture;
public interface CardChartListener {
/**
@ -17,4 +21,8 @@ public interface CardChartListener {
* Called when nothing has been selected or an "un-select" has been made.
*/
void onNothingSelected(BaseCard card);
void onChartGestureStart(BaseCard card, MotionEvent me, ChartGesture lastPerformedGesture);
void onChartGestureEnd(BaseCard card, MotionEvent me, ChartGesture lastPerformedGesture, boolean hasTranslated);
}

View file

@ -278,16 +278,21 @@ public class RouteStatisticCard extends BaseCard {
});
mChart.setOnChartGestureListener(new OnChartGestureListener() {
boolean hasTranslated = false;
float highlightDrawX = -1;
@Override
public void onChartGestureStart(MotionEvent me, ChartGesture lastPerformedGesture) {
hasTranslated = false;
if (mChart.getHighlighted() != null && mChart.getHighlighted().length > 0) {
highlightDrawX = mChart.getHighlighted()[0].getDrawX();
} else {
highlightDrawX = -1;
}
CardChartListener chartListener = getChartListener();
if (chartListener != null) {
chartListener.onChartGestureStart(RouteStatisticCard.this, me, lastPerformedGesture);
}
}
@Override
@ -299,6 +304,10 @@ public class RouteStatisticCard extends BaseCard {
} else {
gpxItem.chartHighlightPos = -1;
}
CardChartListener chartListener = getChartListener();
if (chartListener != null) {
chartListener.onChartGestureEnd(RouteStatisticCard.this, me, lastPerformedGesture, hasTranslated);
}
}
@Override
@ -323,6 +332,7 @@ public class RouteStatisticCard extends BaseCard {
@Override
public void onChartTranslate(MotionEvent me, float dX, float dY) {
hasTranslated = true;
if (highlightDrawX != -1) {
Highlight h = mChart.getHighlightByTouchPoint(highlightDrawX, 0f);
if (h != null) {