use of net.osmand.plus.routepreparationmenu.cards.PublicTransportCard in project Osmand by osmandapp.
the class ChooseRouteFragment method onCreateView.
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
MapActivity mapActivity = (MapActivity) requireActivity();
nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
portrait = AndroidUiHelper.isOrientationPortrait(mapActivity);
OsmandApplication app = mapActivity.getMyApplication();
TransportRoutingHelper transportRoutingHelper = app.getTransportRoutingHelper();
List<TransportRouteResult> routes = transportRoutingHelper.getRoutes();
int routeIndex = 0;
int initialMenuState = MenuState.HEADER_ONLY;
Bundle args = getArguments();
if (args == null) {
args = savedInstanceState;
}
if (args != null) {
routeIndex = args.getInt(ROUTE_INDEX_KEY);
needAdjustMap = args.getBoolean(ADJUST_MAP_KEY, false);
initialMenuState = args.getInt(INITIAL_MENU_STATE_KEY, initialMenuState);
}
routesCount = 1;
if (routes != null && !routes.isEmpty()) {
publicTransportMode = true;
routesCount = routes.size();
}
ContextThemeWrapper context = new ContextThemeWrapper(mapActivity, !nightMode ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme);
View view = LayoutInflater.from(context).inflate(R.layout.fragment_show_all_routes, null);
AndroidUtils.addStatusBarPadding21v(mapActivity, view);
View solidToolbarView = view.findViewById(R.id.toolbar_layout);
this.solidToolbarView = solidToolbarView;
LockableViewPager viewPager = view.findViewById(R.id.pager);
this.viewPager = viewPager;
if (!portrait) {
initialMenuState = MenuState.FULL_SCREEN;
int width = getResources().getDimensionPixelSize(R.dimen.dashboard_land_width) - getResources().getDimensionPixelSize(R.dimen.dashboard_land_shadow_width);
solidToolbarView.setLayoutParams(new FrameLayout.LayoutParams(width, ViewGroup.LayoutParams.WRAP_CONTENT));
solidToolbarView.setVisibility(View.VISIBLE);
final TypedValue typedValueAttr = new TypedValue();
int bgAttrId = AndroidUtils.isLayoutRtl(mapActivity) ? R.attr.right_menu_view_bg : R.attr.left_menu_view_bg;
mapActivity.getTheme().resolveAttribute(bgAttrId, typedValueAttr, true);
view.findViewById(R.id.pager_container).setBackgroundResource(typedValueAttr.resourceId);
view.setLayoutParams(new FrameLayout.LayoutParams(getResources().getDimensionPixelSize(R.dimen.dashboard_land_width), ViewGroup.LayoutParams.MATCH_PARENT));
}
viewPager.setClipToPadding(false);
currentMenuState = initialMenuState;
final RoutesPagerAdapter pagerAdapter = new RoutesPagerAdapter(getChildFragmentManager(), routesCount);
viewPager.setAdapter(pagerAdapter);
viewPager.setCurrentItem(routeIndex);
viewPager.setOffscreenPageLimit(1);
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
public void onPageScrollStateChanged(int state) {
}
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
public void onPageSelected(int position) {
MapActivity mapActivity = getMapActivity();
View view = getView();
if (mapActivity != null && view != null) {
mapActivity.getMyApplication().getTransportRoutingHelper().setCurrentRoute(position);
mapActivity.refreshMap();
buildPagesControl(view);
List<WeakReference<RouteDetailsFragment>> routeDetailsFragments = ChooseRouteFragment.this.routeDetailsFragments;
RouteDetailsFragment current = getCurrentFragment();
for (WeakReference<RouteDetailsFragment> ref : routeDetailsFragments) {
RouteDetailsFragment f = ref.get();
if (f != null) {
PublicTransportCard card = f.getTransportCard();
if (card != null) {
card.updateButtons();
}
if (f == current) {
updateZoomButtonsPos(f, f.getViewY(), true);
updatePagesViewPos(f, f.getViewY(), true);
}
Bundle args = f.getArguments();
if (args != null) {
args.putInt(ContextMenuFragment.MENU_STATE_KEY, currentMenuState);
}
}
}
}
}
});
this.pagesView = (ViewGroup) view.findViewById(R.id.pages_control);
buildPagesControl(view);
buildZoomButtons(view);
buildMenuButtons(view);
return view;
}
use of net.osmand.plus.routepreparationmenu.cards.PublicTransportCard in project Osmand by osmandapp.
the class MapRouteInfoMenu method updateCards.
private void updateCards() {
MapActivity mapActivity = getMapActivity();
if (mapActivity == null) {
return;
}
OsmandApplication app = mapActivity.getMyApplication();
nightMode = app.getDaynightHelper().isNightModeForMapControls();
TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper();
RoutingHelper routingHelper = app.getRoutingHelper();
boolean hasPrecalculatedMissingMaps = hasPrecalculatedMissingMaps();
boolean hasCalculatedMissingMaps = hasCalculatedMissingMaps(app);
List<BaseCard> menuCards = new ArrayList<>();
boolean bottomShadowVisible = true;
if (isBasicRouteCalculated()) {
GPXFile gpx = GpxUiHelper.makeGpxFromRoute(routingHelper.getRoute(), app);
SimpleRouteCard simpleRouteCard = new SimpleRouteCard(mapActivity, gpx);
simpleRouteCard.setListener(this);
menuCards.add(simpleRouteCard);
bottomShadowVisible = false;
} else if (isTransportRouteCalculated()) {
TransportRoutingHelper transportRoutingHelper = app.getTransportRoutingHelper();
List<TransportRouteResult> routes = transportRoutingHelper.getRoutes();
if (routes != null && routes.size() > 0) {
TransportRouteResult route = routes.get(0);
int walkTimeReal = transportRoutingHelper.getWalkingTime(route.getSegments());
int walkTimePT = (int) route.getWalkTime();
int walkTime = walkTimeReal > 0 ? walkTimeReal : walkTimePT;
int travelTime = (int) route.getTravelTime() + walkTime;
LatLon startLocation = transportRoutingHelper.getStartLocation();
LatLon endLocation = transportRoutingHelper.getEndLocation();
int approxPedestrianTime = (int) MapUtils.getDistance(startLocation, endLocation);
boolean showPedestrianCard = approxPedestrianTime < travelTime + 60 && approxPedestrianTime < MAX_PEDESTRIAN_ROUTE_DURATION;
boolean hasTopCard = false;
if (routes.size() > 1 && routeSelected) {
int currentRoute = app.getTransportRoutingHelper().getCurrentRoute();
if (currentRoute >= 0 && currentRoute < routes.size()) {
route = routes.get(currentRoute);
PublicTransportCard card = new PublicTransportCard(mapActivity, startLocation, endLocation, route, currentRoute);
card.setRouteInfoVisible(false);
card.setRouteButtonsVisible(false);
card.setShowBottomShadow(false);
card.setShowTopShadow(false);
card.setListener(this);
menuCards.add(card);
hasTopCard = true;
}
}
for (int i = 0; i < routes.size(); i++) {
route = routes.get(i);
PublicTransportCard card = new PublicTransportCard(mapActivity, startLocation, endLocation, route, i);
card.setShowButtonCustomTitle(mapActivity.getString(R.string.shared_string_show_on_map));
card.setShowBottomShadow(i == routes.size() - 1 && !showPedestrianCard);
card.setShowTopShadow(i != 0 || hasTopCard);
card.setListener(this);
menuCards.add(card);
}
if (showPedestrianCard) {
PedestrianRouteCard pedestrianRouteCard = new PedestrianRouteCard(mapActivity, approxPedestrianTime);
pedestrianRouteCard.setListener(this);
menuCards.add(pedestrianRouteCard);
}
bottomShadowVisible = routes.size() == 0;
} else {
RouteMenuAppModes mode = app.getRoutingOptionsHelper().getRouteMenuAppMode(routingHelper.getAppMode());
boolean avoidPTTypesCustomized = false;
for (LocalRoutingParameter parameter : mode.parameters) {
if (parameter instanceof AvoidPTTypesRoutingParameter) {
avoidPTTypesCustomized = true;
break;
}
}
if (avoidPTTypesCustomized) {
PublicTransportNotFoundSettingsWarningCard warningCard = new PublicTransportNotFoundSettingsWarningCard(mapActivity);
warningCard.setListener(this);
menuCards.add(warningCard);
} else {
PublicTransportNotFoundWarningCard warningCard = new PublicTransportNotFoundWarningCard(mapActivity);
warningCard.setListener(this);
menuCards.add(warningCard);
}
}
} else if (routeCalculationInProgress) {
if (app.getRoutingHelper().isPublicTransportMode()) {
menuCards.add(new PublicTransportBetaWarningCard(mapActivity));
} else if (app.getRoutingHelper().isBoatMode()) {
menuCards.add(new NauticalBridgeHeightWarningCard(mapActivity));
} else if (hasPrecalculatedMissingMaps || suggestedMapsOnlineSearch) {
menuCards.add(new SuggestionsMapsDownloadWarningCard(mapActivity));
} else if (app.getTargetPointsHelper().hasTooLongDistanceToNavigate() && !hasCalculatedMissingMaps) {
menuCards.add(new LongDistanceWarningCard(mapActivity));
}
} else {
if (hasCalculatedMissingMaps) {
menuCards.add(new SuggestionsMapsDownloadWarningCard(mapActivity));
} else {
// Home/work card
HomeWorkCard homeWorkCard = new HomeWorkCard(mapActivity);
menuCards.add(homeWorkCard);
// Previous route card
boolean historyEnabled = app.getSettings().NAVIGATION_HISTORY.get();
if (historyEnabled) {
TargetPoint startBackup = targetPointsHelper.getPointToStartBackup();
if (startBackup == null) {
startBackup = targetPointsHelper.getMyLocationToStart();
}
TargetPoint destinationBackup = targetPointsHelper.getPointToNavigateBackup();
if (startBackup != null && destinationBackup != null) {
PreviousRouteCard previousRouteCard = new PreviousRouteCard(mapActivity);
previousRouteCard.setListener(this);
menuCards.add(previousRouteCard);
}
}
// Gpx card
List<SelectedGpxFile> selectedGPXFiles = app.getSelectedGpxHelper().getSelectedGPXFiles();
final List<GPXFile> gpxFiles = new ArrayList<>();
for (SelectedGpxFile gs : selectedGPXFiles) {
if (!gs.isShowCurrentTrack()) {
if (gs.getGpxFile().hasRtePt() || gs.getGpxFile().hasTrkPt()) {
gpxFiles.add(gs.getGpxFile());
}
}
}
if (gpxFiles.size() > 0) {
TracksCard tracksCard = new TracksCard(mapActivity, gpxFiles);
tracksCard.setListener(this);
menuCards.add(tracksCard);
}
// Map markers card
List<MapMarker> mapMarkers = app.getMapMarkersHelper().getMapMarkers();
if (mapMarkers.size() > 0) {
MapMarkersCard mapMarkersCard = new MapMarkersCard(mapActivity, mapMarkers);
menuCards.add(mapMarkersCard);
}
// History card
if (historyEnabled) {
try {
SearchResultCollection res = app.getSearchUICore().getCore().shallowSearch(SearchHistoryAPI.class, "", null, false, false);
if (res != null) {
List<SearchResult> results = res.getCurrentSearchResults();
if (results.size() > 0) {
HistoryCard historyCard = new HistoryCard(mapActivity, results);
historyCard.setListener(this);
menuCards.add(historyCard);
}
}
} catch (IOException e) {
LOG.error(e);
}
}
}
}
applyCardsState(menuCards, this.menuCards);
this.menuCards = menuCards;
setBottomShadowVisible(bottomShadowVisible);
setupCards();
}
use of net.osmand.plus.routepreparationmenu.cards.PublicTransportCard in project Osmand by osmandapp.
the class MapRouteInfoMenu method onCardPressed.
@Override
public void onCardPressed(@NonNull BaseCard card) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
if (card instanceof SimpleRouteCard) {
hide();
ChooseRouteFragment.showInstance(mapActivity.getSupportFragmentManager(), 0, MenuState.FULL_SCREEN);
} else if (card instanceof PublicTransportCard) {
hide();
ChooseRouteFragment.showInstance(mapActivity.getSupportFragmentManager(), ((PublicTransportCard) card).getRouteId(), MenuState.FULL_SCREEN);
}
}
}
use of net.osmand.plus.routepreparationmenu.cards.PublicTransportCard in project Osmand by osmandapp.
the class MapRouteInfoMenu method onCardButtonPressed.
@Override
public void onCardButtonPressed(@NonNull BaseCard card, int buttonIndex) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
OsmandApplication app = mapActivity.getMyApplication();
if (card instanceof PreviousRouteCard) {
ApplicationMode lastAppMode = app.getSettings().LAST_ROUTE_APPLICATION_MODE.get();
ApplicationMode currentAppMode = app.getRoutingHelper().getAppMode();
if (lastAppMode == ApplicationMode.DEFAULT) {
lastAppMode = currentAppMode;
}
updateApplicationMode(currentAppMode, lastAppMode);
updateFinishPointView();
updateOptionsButtons();
app.getTargetPointsHelper().restoreTargetPoints(true);
} else if (card instanceof PublicTransportCard) {
if (buttonIndex == PublicTransportCard.DETAILS_BUTTON_INDEX) {
hide();
ChooseRouteFragment.showInstance(mapActivity.getSupportFragmentManager(), ((PublicTransportCard) card).getRouteId(), MenuState.FULL_SCREEN);
} else if (buttonIndex == PublicTransportCard.SHOW_BUTTON_INDEX) {
showRouteOnMap(mapActivity, ((PublicTransportCard) card).getRouteId());
}
} else if (card instanceof SimpleRouteCard) {
hide();
ChooseRouteFragment.showInstance(mapActivity.getSupportFragmentManager(), 0, MenuState.FULL_SCREEN);
} else if (card instanceof PublicTransportNotFoundWarningCard) {
updateApplicationMode(null, ApplicationMode.PEDESTRIAN);
} else if (card instanceof PublicTransportNotFoundSettingsWarningCard) {
AvoidRoadsBottomSheetDialogFragment avoidRoadsFragment = new AvoidRoadsBottomSheetDialogFragment();
avoidRoadsFragment.setHideImpassableRoads(true);
avoidRoadsFragment.show(mapActivity.getSupportFragmentManager(), AvoidRoadsBottomSheetDialogFragment.TAG);
} else if (card instanceof PedestrianRouteCard) {
updateApplicationMode(null, ApplicationMode.PEDESTRIAN);
}
}
}
use of net.osmand.plus.routepreparationmenu.cards.PublicTransportCard in project Osmand by osmandapp.
the class RouteDetailsFragment method updateCards.
private void updateCards() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
OsmandApplication app = mapActivity.getMyApplication();
RoutingHelper routingHelper = app.getRoutingHelper();
LinearLayout cardsContainer = getCardsContainer();
cardsContainer.removeAllViews();
if (routeId != -1) {
List<TransportRouteResult> routes = routingHelper.getTransportRoutingHelper().getRoutes();
if (routes != null && routes.size() > routeId) {
TransportRouteResult routeResult = routingHelper.getTransportRoutingHelper().getRoutes().get(routeId);
TransportRoutingHelper transportRoutingHelper = app.getTransportRoutingHelper();
PublicTransportCard card = new PublicTransportCard(mapActivity, transportRoutingHelper.getStartLocation(), transportRoutingHelper.getEndLocation(), routeResult, routeId);
card.setShowTopShadow(false);
card.setShowBottomShadow(false);
card.setShowDivider(false);
card.setTransparentBackground(true);
card.setTransportCardListener(this);
card.setListener(this);
transportCard = card;
menuCards.add(card);
cardsContainer.addView(card.build(mapActivity));
buildRowDivider(cardsContainer, false);
buildTransportRouteRow(cardsContainer, routeResult, true);
buildRowDivider(cardsContainer, false);
} else {
transportCard = null;
makeGpx();
createRouteStatisticCards(cardsContainer);
createRouteDirectionsCard(cardsContainer);
}
}
}
}
Aggregations