Merge branch 'r3.3'

This commit is contained in:
crimean 2019-04-17 22:24:47 +03:00
commit 573b941c22
3 changed files with 63 additions and 14 deletions

View file

@ -1,5 +1,6 @@
package net.osmand.plus.routepreparationmenu;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
@ -20,12 +21,14 @@ import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.github.mikephil.charting.charts.HorizontalBarChart;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.highlight.Highlight;
@ -112,6 +115,7 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT
private PublicTransportCard transportCard;
private RouteDetailsFragmentListener routeDetailsListener;
private RouteStatisticCard statisticCard;
private List<RouteInfoCard> routeInfoCards = new ArrayList<>();
private TrackDetailsMenu trackDetailsMenu;
public interface RouteDetailsFragmentListener {
@ -308,7 +312,7 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT
return;
}
OsmandApplication app = mapActivity.getMyApplication();
statisticCard = new RouteStatisticCard(mapActivity, gpx, new View.OnTouchListener() {
statisticCard = new RouteStatisticCard(mapActivity, gpx, new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
InterceptorLinearLayout mainView = getMainView();
@ -361,7 +365,10 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT
}
}
trackDetailsMenu = new TrackDetailsMenu();
trackDetailsMenu.setGpxItem(statisticCard.getGpxItem());
GpxDisplayItem gpxItem = statisticCard.getGpxItem();
if (gpxItem != null) {
trackDetailsMenu.setGpxItem(gpxItem);
}
trackDetailsMenu.setMapActivity(mapActivity);
LineChart chart = statisticCard.getChart();
if (chart != null) {
@ -382,12 +389,39 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT
buildRowDivider(cardsContainer, false);
}
private void addRouteCard(LinearLayout cardsContainer, RouteInfoCard routeInfoCard) {
private OnTouchListener getChartTouchListener() {
return new OnTouchListener() {
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouch(View v, MotionEvent ev) {
if (ev.getSource() != 0) {
for (RouteInfoCard card : routeInfoCards) {
final HorizontalBarChart ch = card.getChart();
if (ch != null && v instanceof HorizontalBarChart && ch != v) {
final MotionEvent event = MotionEvent.obtainNoHistory(ev);
event.setSource(0);
ch.dispatchTouchEvent(event);
}
}
}
return false;
}
};
}
@SuppressLint("ClickableViewAccessibility")
private void addRouteCard(final LinearLayout cardsContainer, RouteInfoCard routeInfoCard) {
OsmandApplication app = requireMyApplication();
menuCards.add(routeInfoCard);
routeInfoCard.setListener(this);
cardsContainer.addView(routeInfoCard.build(app));
buildRowDivider(cardsContainer, false);
routeInfoCards.add(routeInfoCard);
HorizontalBarChart chart = routeInfoCard.getChart();
if (chart != null) {
chart.setOnTouchListener(getChartTouchListener());
}
}
public Drawable getCollapseIcon(boolean collapsed) {
@ -1564,7 +1598,6 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT
@Override
public void onCardPressed(@NonNull BaseCard card) {
}
@Override

View file

@ -6,6 +6,7 @@ import android.support.annotation.ColorInt;
import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v7.view.ContextThemeWrapper;
import android.view.LayoutInflater;
@ -45,6 +46,11 @@ public abstract class BaseCard {
public abstract int getCardLayoutId();
@Nullable
public View getView() {
return view;
}
public int getViewHeight() {
return view != null ? view.getHeight() : 0;
}

View file

@ -1,6 +1,7 @@
package net.osmand.plus.routepreparationmenu.cards;
import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v4.graphics.ColorUtils;
import android.support.v7.view.ContextThemeWrapper;
@ -26,6 +27,7 @@ import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.SettingsNavigationActivity;
import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.router.RouteStatistics;
import net.osmand.router.RouteStatistics.Boundaries;
import net.osmand.router.RouteStatistics.RouteSegmentAttribute;
import net.osmand.router.RouteStatistics.Statistics;
@ -65,6 +67,11 @@ public class RouteInfoCard extends BaseCard {
updateContent(routeStatistics);
}
@Nullable
public HorizontalBarChart getChart() {
return (HorizontalBarChart) view.findViewById(R.id.chart);
}
private <E> void updateContent(final Statistics<E> routeStatistics) {
updateHeader();
final HorizontalBarChart chart = (HorizontalBarChart) view.findViewById(R.id.chart);
@ -78,22 +85,18 @@ public class RouteInfoCard extends BaseCard {
int i = h.getStackIndex();
if (elems.size() > i) {
selectedPropertyName = elems.get(i).getPropertyName();
LinearLayout container = (LinearLayout) view.findViewById(R.id.route_items);
if (!showLegend) {
showLegend = true;
if (showLegend) {
updateLegend(routeStatistics);
}
container.removeAllViews();
attachLegend(container, routeStatistics);
setLayoutNeeded();
}
}
@Override
public void onNothingSelected() {
LinearLayout container = (LinearLayout) view.findViewById(R.id.route_items);
showLegend = false;
container.removeAllViews();
setLayoutNeeded();
selectedPropertyName = null;
if (showLegend) {
updateLegend(routeStatistics);
}
}
});
LinearLayout container = (LinearLayout) view.findViewById(R.id.route_items);
@ -113,6 +116,13 @@ public class RouteInfoCard extends BaseCard {
});
}
protected <E> void updateLegend(Statistics<E> routeStatistics) {
LinearLayout container = (LinearLayout) view.findViewById(R.id.route_items);
container.removeAllViews();
attachLegend(container, routeStatistics);
setLayoutNeeded();
}
private Drawable getCollapseIcon(boolean collapsed) {
return collapsed ? getContentIcon(R.drawable.ic_action_arrow_down) : getActiveIcon(R.drawable.ic_action_arrow_up);
}