Added details/start buttons at route details screen

This commit is contained in:
crimean 2019-04-13 18:06:45 +03:00
parent fd02b44dd8
commit 431a1a9863
5 changed files with 165 additions and 4 deletions

View file

@ -120,6 +120,72 @@
</LinearLayout>
<LinearLayout
android:id="@+id/top_buttons_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
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_buttons_padding_top_bottom"
android:orientation="horizontal">
<FrameLayout
android:id="@+id/details_button"
android:layout_width="0dp"
android:layout_height="@dimen/route_info_buttons_height"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:orientation="horizontal">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/details_button_descr"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:ellipsize="end"
android:gravity="center"
android:letterSpacing="@dimen/text_button_letter_spacing"
android:maxLines="1"
android:text="@string/rendering_category_details"
android:textColor="?attr/active_color_basic"
android:textSize="@dimen/text_button_text_size"
osmand:typeface="@string/font_roboto_medium"
tools:ignore="UnusedAttribute" />
</FrameLayout>
<FrameLayout
android:id="@+id/start_button"
android:layout_width="0dp"
android:layout_height="@dimen/route_info_buttons_height"
android:layout_gravity="center_vertical"
android:layout_marginStart="@dimen/content_padding"
android:layout_marginLeft="@dimen/content_padding"
android:layout_weight="1"
android:orientation="horizontal">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/start_button_descr"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="?attr/selectableItemBackgroundBorderless"
android:ellipsize="end"
android:gravity="center"
android:letterSpacing="@dimen/text_button_letter_spacing"
android:maxLines="1"
android:text="@string/shared_string_control_start"
android:textColor="@color/card_and_list_background_light"
android:textSize="@dimen/text_button_text_size"
osmand:typeface="@string/font_roboto_medium"
tools:ignore="UnusedAttribute" />
</FrameLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/altitude_container"
android:layout_width="match_parent"

View file

@ -51,6 +51,7 @@ import net.osmand.plus.base.ContextMenuFragment.ContextMenuFragmentListener;
import net.osmand.plus.base.ContextMenuFragment.MenuState;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.routepreparationmenu.RouteDetailsFragment.CumulativeInfo;
import net.osmand.plus.routepreparationmenu.RouteDetailsFragment.RouteDetailsFragmentListener;
import net.osmand.plus.routepreparationmenu.cards.PublicTransportCard;
import net.osmand.plus.routing.RouteDirectionInfo;
import net.osmand.plus.routing.RoutingHelper;
@ -70,7 +71,8 @@ import java.util.Date;
import java.util.List;
import java.util.Locale;
public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMenuFragmentListener {
public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMenuFragmentListener,
RouteDetailsFragmentListener {
public static final String TAG = "ChooseRouteFragment";
public static final String ROUTE_INDEX_KEY = "route_index_key";
@ -193,6 +195,7 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe
RouteDetailsFragment detailsFragment = (RouteDetailsFragment) childFragment;
routeDetailsFragments.add(new WeakReference<>(detailsFragment));
detailsFragment.setListener(this);
detailsFragment.setRouteDetailsListener(this);
}
}
@ -861,6 +864,16 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe
}
}
@Override
public void onNavigationRequested() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
useRouteInfoMenu = false;
dismiss();
mapActivity.getMapLayers().getMapControlsLayer().startNavigation();
}
}
public class RoutesPagerAdapter extends FragmentPagerAdapter {
private int routesCount;

View file

@ -29,8 +29,8 @@ import android.widget.TextView;
import com.github.mikephil.charting.data.Entry;
import net.osmand.AndroidUtils;
import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.GPXTrackAnalysis;
import net.osmand.GPXUtilities.TrkSegment;
import net.osmand.GPXUtilities.WptPt;
import net.osmand.Location;
@ -105,6 +105,11 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT
private List<BaseCard> menuCards = new ArrayList<>();
@Nullable
private PublicTransportCard transportCard;
private RouteDetailsFragmentListener routeDetailsListener;
public interface RouteDetailsFragmentListener {
void onNavigationRequested();
}
@Override
public int getMainLayoutId() {
@ -113,7 +118,7 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT
@Override
public int getHeaderViewHeight() {
return !menuCards.isEmpty() ? menuCards.get(0).getViewHeight() : 0;
return !menuCards.isEmpty() ? menuCards.get(0).getTopViewHeight() : 0;
}
@Override
@ -201,6 +206,14 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT
}
}
public RouteDetailsFragmentListener getRouteDetailsListener() {
return routeDetailsListener;
}
public void setRouteDetailsListener(RouteDetailsFragmentListener routeDetailsListener) {
this.routeDetailsListener = routeDetailsListener;
}
private void updateCardsLayout() {
View mainView = getMainView();
if (mainView != null) {
@ -298,6 +311,7 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT
}
});
statisticCard.setTransparentBackground(true);
statisticCard.setListener(this);
menuCards.add(statisticCard);
cardsContainer.addView(statisticCard.build(mapActivity));
buildRowDivider(cardsContainer, false);
@ -314,7 +328,7 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT
RenderingRuleSearchRequest defaultSearchRequest = maps.getSearchRequestWithAppliedCustomRules(defaultRender, isNightMode());
RouteStatistics routeStatistics = RouteStatistics.newRouteStatistic(route, currentRenderer, defaultRender, currentSearchRequest, defaultSearchRequest);
GPXUtilities.GPXTrackAnalysis analysis = gpx.getAnalysis(0);
GPXTrackAnalysis analysis = gpx.getAnalysis(0);
RouteInfoCard routeClassCard = new RouteInfoCard(mapActivity, routeStatistics.getRouteClassStatistic(), analysis);
addRouteCard(cardsContainer, routeClassCard);
@ -1525,6 +1539,18 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT
openMenuFullScreen();
} else if (card instanceof RouteDirectionsCard && buttonIndex >= 0) {
showDirectionsInfo(buttonIndex);
} else if (card instanceof RouteStatisticCard) {
switch (buttonIndex) {
case RouteStatisticCard.DETAILS_BUTTON_INDEX:
openMenuFullScreen();
break;
case RouteStatisticCard.START_BUTTON_INDEX:
RouteDetailsFragmentListener listener = getRouteDetailsListener();
if (listener != null) {
listener.onNavigationRequested();
}
break;
}
}
}

View file

@ -48,6 +48,10 @@ public abstract class BaseCard {
return view != null ? view.getHeight() : 0;
}
public int getTopViewHeight() {
return getViewHeight();
}
public void update() {
if (view != null) {
updateContent();

View file

@ -3,6 +3,7 @@ package net.osmand.plus.routepreparationmenu.cards;
import android.graphics.Matrix;
import android.os.Build;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.view.MotionEvent;
@ -11,6 +12,7 @@ import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.github.mikephil.charting.charts.LineChart;
@ -39,6 +41,9 @@ import java.util.List;
public class RouteStatisticCard extends BaseCard {
public static final int DETAILS_BUTTON_INDEX = 0;
public static final int START_BUTTON_INDEX = 1;
private GPXFile gpx;
private GpxDisplayItem gpxItem;
@Nullable
@ -101,12 +106,59 @@ public class RouteStatisticCard extends BaseCard {
arriveTimeTv.setText(arriveStr);
buildSlopeInfo();
updateButtons();
if (isTransparentBackground()) {
view.setBackgroundDrawable(null);
}
}
@Override
public int getTopViewHeight() {
View altitudeContainer = view.findViewById(R.id.altitude_container);
return (int) altitudeContainer.getY();
}
private void updateButtons() {
FrameLayout detailsButton = (FrameLayout) view.findViewById(R.id.details_button);
TextView detailsButtonDescr = (TextView) view.findViewById(R.id.details_button_descr);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
AndroidUtils.setBackground(app, detailsButton, nightMode, R.drawable.btn_border_light, R.drawable.btn_border_dark);
AndroidUtils.setBackground(app, detailsButtonDescr, nightMode, R.drawable.ripple_light, R.drawable.ripple_dark);
} else {
AndroidUtils.setBackground(app, detailsButton, nightMode, R.drawable.btn_border_trans_light, R.drawable.btn_border_trans_dark);
}
detailsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CardListener listener = getListener();
if (listener != null) {
listener.onCardButtonPressed(RouteStatisticCard.this, DETAILS_BUTTON_INDEX);
}
}
});
FrameLayout startButton = (FrameLayout) view.findViewById(R.id.start_button);
TextView startButtonDescr = (TextView) view.findViewById(R.id.start_button_descr);
AndroidUtils.setBackground(app, startButton, nightMode, R.drawable.btn_active_light, R.drawable.btn_active_dark);
int color = ContextCompat.getColor(app, R.color.card_and_list_background_light);
startButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CardListener listener = getListener();
if (listener != null) {
listener.onCardButtonPressed(RouteStatisticCard.this, START_BUTTON_INDEX);
}
}
});
RoutingHelper helper = app.getRoutingHelper();
if (helper.isFollowingMode() || helper.isPauseNavigation()) {
startButtonDescr.setText(R.string.shared_string_continue);
} else {
startButtonDescr.setText(R.string.shared_string_control_start);
}
startButtonDescr.setTextColor(color);
}
private void buildSlopeInfo() {
GPXTrackAnalysis analysis = gpx.getAnalysis(0);