Search in sources :

Example 21 with TargetPointsHelper

use of net.osmand.plus.helpers.TargetPointsHelper in project Osmand by osmandapp.

the class DestinationReachedMenuFragment method onCreateView.

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    MapActivity mapActivity = getMapActivity();
    if (mapActivity == null || menu == null) {
        return null;
    }
    ContextThemeWrapper ctx = new ContextThemeWrapper(mapActivity, menu.isLight() ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme);
    LayoutInflater inf = LayoutInflater.from(ctx);
    View view = inf.inflate(R.layout.dest_reached_menu_fragment, container, false);
    AndroidUtils.addStatusBarPadding21v(ctx, view);
    view.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            finishNavigation();
        }
    });
    UiUtilities iconsCache = mapActivity.getMyApplication().getUIUtilities();
    ImageButton closeImageButton = (ImageButton) view.findViewById(R.id.closeImageButton);
    closeImageButton.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_remove_dark, menu.isLight()));
    closeImageButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            finishNavigation();
        }
    });
    Button removeDestButton = (Button) view.findViewById(R.id.removeDestButton);
    removeDestButton.setCompoundDrawablesWithIntrinsicBounds(iconsCache.getIcon(R.drawable.ic_action_done, menu.isLight()), null, null, null);
    removeDestButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            finishNavigation();
        }
    });
    Button recalcDestButton = (Button) view.findViewById(R.id.recalcDestButton);
    recalcDestButton.setCompoundDrawablesWithIntrinsicBounds(iconsCache.getIcon(R.drawable.ic_action_gdirections_dark, menu.isLight()), null, null, null);
    recalcDestButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            MapActivity mapActivity = getMapActivity();
            if (mapActivity != null) {
                TargetPointsHelper helper = mapActivity.getMyApplication().getTargetPointsHelper();
                TargetPoint target = helper.getPointToNavigate();
                dismissMenu();
                if (target != null) {
                    helper.navigateToPoint(new LatLon(target.getLatitude(), target.getLongitude()), true, -1, target.getOriginalPointDescription());
                    mapActivity.getMapActions().recalculateRoute(false);
                    mapActivity.getMapLayers().getMapControlsLayer().startNavigation();
                }
            }
        }
    });
    Button findParkingButton = (Button) view.findViewById(R.id.findParkingButton);
    ApplicationMode appMode = mapActivity.getMyApplication().getRoutingHelper().getAppMode();
    if (!appMode.isDerivedRoutingFrom(ApplicationMode.CAR)) {
        findParkingButton.setVisibility(View.GONE);
    }
    findParkingButton.setCompoundDrawablesWithIntrinsicBounds(iconsCache.getIcon(R.drawable.ic_action_parking_dark, menu.isLight()), null, null, null);
    findParkingButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            MapActivity mapActivity = getMapActivity();
            if (mapActivity != null) {
                PoiFiltersHelper helper = mapActivity.getMyApplication().getPoiFilters();
                PoiUIFilter parkingFilter = helper.getFilterById(PoiUIFilter.STD_PREFIX + "parking");
                mapActivity.showQuickSearch(parkingFilter);
            }
            dismissMenu();
        }
    });
    View mainView = view.findViewById(R.id.main_view);
    if (menu.isLandscapeLayout()) {
        AndroidUtils.setBackground(view.getContext(), mainView, !menu.isLight(), R.drawable.bg_left_menu_light, R.drawable.bg_left_menu_dark);
    } else {
        AndroidUtils.setBackground(view.getContext(), mainView, !menu.isLight(), R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark);
    }
    return view;
}
Also used : ApplicationMode(net.osmand.plus.settings.backend.ApplicationMode) PoiFiltersHelper(net.osmand.plus.poi.PoiFiltersHelper) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) View(android.view.View) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter) UiUtilities(net.osmand.plus.utils.UiUtilities) LatLon(net.osmand.data.LatLon) ImageButton(android.widget.ImageButton) ContextThemeWrapper(androidx.appcompat.view.ContextThemeWrapper) ImageButton(android.widget.ImageButton) Button(android.widget.Button) LayoutInflater(android.view.LayoutInflater) TargetPointsHelper(net.osmand.plus.helpers.TargetPointsHelper) MapActivity(net.osmand.plus.activities.MapActivity) Nullable(androidx.annotation.Nullable)

Example 22 with TargetPointsHelper

use of net.osmand.plus.helpers.TargetPointsHelper in project Osmand by osmandapp.

the class FavouritesBottomSheetMenuFragment method selectFavorite.

private void selectFavorite(FavouritePoint point) {
    OsmandApplication app = getMyApplication();
    TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper();
    FavouritesHelper favorites = app.getFavoritesHelper();
    LatLon ll = new LatLon(point.getLatitude(), point.getLongitude());
    switch(pointType) {
        case START:
            targetPointsHelper.setStartPoint(ll, true, point.getPointDescription(app));
            break;
        case TARGET:
            if (getActivity() != null) {
                targetPointsHelper.navigateToPoint(ll, true, -1, point.getPointDescription(app));
                OsmAndLocationProvider.requestFineLocationPermissionIfNeeded(getActivity());
            }
            break;
        case INTERMEDIATE:
            targetPointsHelper.navigateToPoint(ll, true, targetPointsHelper.getIntermediatePoints().size(), point.getPointDescription(app));
            break;
        case HOME:
            favorites.setSpecialPoint(ll, FavouritePoint.SpecialPointType.HOME, null);
            break;
        case WORK:
            favorites.setSpecialPoint(ll, FavouritePoint.SpecialPointType.WORK, null);
            break;
    }
    MapRouteInfoMenu routeMenu = getMapRouteInfoMenu();
    if (routeMenu != null) {
        setupMapRouteInfoMenuSpinners(routeMenu);
        updateMapRouteInfoMenuFromIcon(routeMenu);
    }
    Fragment fragment = getTargetFragment();
    if (fragment != null) {
        fragment.onActivityResult(getTargetRequestCode(), 0, null);
    }
    dismiss();
}
Also used : LatLon(net.osmand.data.LatLon) MapRouteInfoMenu(net.osmand.plus.routepreparationmenu.MapRouteInfoMenu) OsmandApplication(net.osmand.plus.OsmandApplication) FavouritesHelper(net.osmand.plus.myplaces.FavouritesHelper) TargetPointsHelper(net.osmand.plus.helpers.TargetPointsHelper) Fragment(androidx.fragment.app.Fragment) MenuBottomSheetDialogFragment(net.osmand.plus.base.MenuBottomSheetDialogFragment)

Example 23 with TargetPointsHelper

use of net.osmand.plus.helpers.TargetPointsHelper in project Osmand by osmandapp.

the class DirectionsDialogs method directionsToDialogAndLaunchMap.

public static void directionsToDialogAndLaunchMap(final Activity act, final double lat, final double lon, final PointDescription name) {
    final OsmandApplication ctx = (OsmandApplication) act.getApplication();
    final TargetPointsHelper targetPointsHelper = ctx.getTargetPointsHelper();
    if (targetPointsHelper.getIntermediatePoints().size() > 0) {
        AlertDialog.Builder builder = new AlertDialog.Builder(act);
        builder.setTitle(R.string.new_directions_point_dialog);
        builder.setItems(new String[] { act.getString(R.string.keep_intermediate_points), act.getString(R.string.clear_intermediate_points) }, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (which == 1) {
                    targetPointsHelper.clearPointToNavigate(false);
                }
                ctx.getSettings().navigateDialog();
                targetPointsHelper.navigateToPoint(new LatLon(lat, lon), true, -1, name);
                MapActivity.launchMapActivityMoveToTop(act);
            }
        });
        builder.show();
    } else {
        ctx.getSettings().navigateDialog();
        targetPointsHelper.navigateToPoint(new LatLon(lat, lon), true, -1, name);
        MapActivity.launchMapActivityMoveToTop(act);
    }
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) LatLon(net.osmand.data.LatLon) OsmandApplication(net.osmand.plus.OsmandApplication) DialogInterface(android.content.DialogInterface) TargetPointsHelper(net.osmand.plus.helpers.TargetPointsHelper)

Example 24 with TargetPointsHelper

use of net.osmand.plus.helpers.TargetPointsHelper in project Osmand by osmandapp.

the class DashWaypointsFragment method setupTargets.

private void setupTargets() {
    OsmandApplication app = getMyApplication();
    View mainView = getView();
    if (mainView == null || app == null) {
        return;
    }
    final TargetPointsHelper helper = app.getTargetPointsHelper();
    if (helper.getPointToNavigate() == null) {
        AndroidUiHelper.updateVisibility(mainView.findViewById(R.id.main_fav), false);
        return;
    } else {
        AndroidUiHelper.updateVisibility(mainView.findViewById(R.id.main_fav), true);
    }
    String collapseOrShowAll = SHOW_ALL ? getString(R.string.shared_string_collapse) : getString(R.string.shared_string_show_all);
    ((Button) mainView.findViewById(R.id.show_all)).setText(collapseOrShowAll);
    mainView.findViewById(R.id.show_all).setOnClickListener(v -> {
        SHOW_ALL = !SHOW_ALL;
        setupView();
    });
    mainView.findViewById(R.id.show_all).setVisibility(helper.getIntermediatePoints().size() == 0 ? View.INVISIBLE : View.VISIBLE);
    ((TextView) mainView.findViewById(R.id.fav_text)).setText(getString(R.string.shared_string_waypoints) + " (" + helper.getIntermediatePointsWithTarget().size() + ")");
    LinearLayout favorites = mainView.findViewById(R.id.items);
    favorites.removeAllViews();
    List<TargetPoint> targetPoints = SHOW_ALL ? helper.getIntermediatePointsWithTarget() : Collections.singletonList(helper.getPointToNavigate());
    List<DashLocationView> distances = new ArrayList<>();
    for (final TargetPoint point : targetPoints) {
        LayoutInflater inflater = getActivity().getLayoutInflater();
        View view = inflater.inflate(R.layout.favorites_list_item, null, false);
        TextView name = view.findViewById(R.id.favourite_label);
        TextView label = view.findViewById(R.id.distance);
        ImageView direction = view.findViewById(R.id.direction);
        direction.setVisibility(View.VISIBLE);
        label.setVisibility(View.VISIBLE);
        view.findViewById(R.id.divider).setVisibility(View.VISIBLE);
        view.findViewById(R.id.group_image).setVisibility(View.GONE);
        boolean target = helper.getPointToNavigate() == point;
        int id;
        if (!target) {
            id = R.drawable.list_intermediate;
        } else {
            id = R.drawable.list_destination;
        }
        ((ImageView) view.findViewById(R.id.favourite_icon)).setImageDrawable(app.getUIUtilities().getIcon(id, 0));
        DashLocationView dv = new DashLocationView(direction, label, new LatLon(point.getLatitude(), point.getLongitude()));
        distances.add(dv);
        name.setText(PointDescription.getSimpleName(point, getActivity()));
        ImageButton options = view.findViewById(R.id.options);
        options.setVisibility(View.VISIBLE);
        final boolean optionsVisible = (SHOW_ALL && app.getTargetPointsHelper().getIntermediatePoints().size() > 0);
        options.setImageDrawable(app.getUIUtilities().getThemedIcon(optionsVisible ? R.drawable.ic_overflow_menu_white : R.drawable.ic_action_remove_dark));
        options.setOnClickListener(v -> {
            if (optionsVisible) {
                selectTargetModel(point, v);
            } else {
                deletePointConfirm(point, v);
            }
        });
        ImageButton navigate = view.findViewById(R.id.navigate_to);
        navigate.setImageDrawable(app.getUIUtilities().getThemedIcon(R.drawable.ic_action_gdirections_dark));
        navigate.setVisibility(target ? View.VISIBLE : View.GONE);
        navigate.setOnClickListener(v -> dashboard.navigationAction());
        view.setOnClickListener(v -> {
            if (getActivity() != null) {
                getMyApplication().getSettings().setMapLocationToShow(point.getLatitude(), point.getLongitude(), 15, point.getPointDescription(getActivity()), false, point);
                MapActivity.launchMapActivityMoveToTop(getActivity());
            }
        });
        favorites.addView(view);
    }
    this.distances = distances;
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) ArrayList(java.util.ArrayList) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) LatLon(net.osmand.data.LatLon) ImageButton(android.widget.ImageButton) ImageButton(android.widget.ImageButton) Button(android.widget.Button) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) ImageView(android.widget.ImageView) TargetPointsHelper(net.osmand.plus.helpers.TargetPointsHelper) LinearLayout(android.widget.LinearLayout)

Example 25 with TargetPointsHelper

use of net.osmand.plus.helpers.TargetPointsHelper in project Osmand by osmandapp.

the class AddWaypointBottomSheetDialogFragment method createMenuItems.

@Override
public void createMenuItems(Bundle savedInstanceState) {
    Bundle args = getArguments();
    final LatLon latLon = new LatLon(args.getDouble(LAT_KEY), args.getDouble(LON_KEY));
    final PointDescription name = PointDescription.deserializeFromString(args.getString(POINT_DESCRIPTION_KEY), latLon);
    final TargetPointsHelper targetPointsHelper = getMyApplication().getTargetPointsHelper();
    items.add(new TitleItem(getString(R.string.new_destination_point_dialog)));
    BaseBottomSheetItem replaceDestItem = new BottomSheetItemWithDescription.Builder().setDescription(getCurrentPointName(targetPointsHelper.getPointToNavigate(), false)).setDescriptionColorId(ColorUtilities.getSecondaryTextColorId(nightMode)).setIcon(getIcon(R.drawable.list_destination, 0)).setTitle(getString(R.string.replace_destination_point)).setLayoutId(R.layout.bottom_sheet_item_with_descr_56dp).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            targetPointsHelper.navigateToPoint(latLon, true, -1, name);
            dismiss();
        }
    }).create();
    items.add(replaceDestItem);
    BaseBottomSheetItem replaceStartItem = new BottomSheetItemWithDescription.Builder().setDescription(getCurrentPointName(targetPointsHelper.getPointToStart(), true)).setDescriptionColorId(ColorUtilities.getSecondaryTextColorId(nightMode)).setIcon(getIcon(R.drawable.list_startpoint, 0)).setTitle(getString(R.string.make_as_start_point)).setLayoutId(R.layout.bottom_sheet_item_with_descr_56dp).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            targetPointsHelper.setStartPoint(latLon, true, name);
            dismiss();
        }
    }).create();
    items.add(replaceStartItem);
    items.add(new DividerHalfItem(getContext(), getDividerColorId()));
    BaseBottomSheetItem subsequentDestItem = new BottomSheetItemWithDescription.Builder().setDescription(getString(R.string.subsequent_dest_description)).setDescriptionColorId(ColorUtilities.getSecondaryTextColorId(nightMode)).setIcon(getSubsequentDestIcon()).setTitle(getString(R.string.keep_and_add_destination_point)).setLayoutId(R.layout.bottom_sheet_item_with_descr_56dp).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            targetPointsHelper.navigateToPoint(latLon, true, targetPointsHelper.getIntermediatePoints().size() + 1, name);
            dismiss();
        }
    }).create();
    items.add(subsequentDestItem);
    BaseBottomSheetItem firstIntermItem = new BottomSheetItemWithDescription.Builder().setDescription(getString(R.string.first_intermediate_dest_description)).setDescriptionColorId(ColorUtilities.getSecondaryTextColorId(nightMode)).setIcon(getFirstIntermDestIcon()).setTitle(getString(R.string.add_as_first_destination_point)).setLayoutId(R.layout.bottom_sheet_item_with_descr_56dp).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            targetPointsHelper.navigateToPoint(latLon, true, 0, name);
            dismiss();
        }
    }).create();
    items.add(firstIntermItem);
    BaseBottomSheetItem lastIntermItem = new BottomSheetItemWithDescription.Builder().setDescription(getString(R.string.last_intermediate_dest_description)).setDescriptionColorId(ColorUtilities.getSecondaryTextColorId(nightMode)).setIcon(getLastIntermDistIcon()).setTitle(getString(R.string.add_as_last_destination_point)).setLayoutId(R.layout.bottom_sheet_item_with_descr_56dp).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            targetPointsHelper.navigateToPoint(latLon, true, targetPointsHelper.getIntermediatePoints().size(), name);
            dismiss();
        }
    }).create();
    items.add(lastIntermItem);
}
Also used : BaseBottomSheetItem(net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem) LatLon(net.osmand.data.LatLon) Bundle(android.os.Bundle) PointDescription(net.osmand.data.PointDescription) DividerHalfItem(net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem) TitleItem(net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem) TargetPointsHelper(net.osmand.plus.helpers.TargetPointsHelper) View(android.view.View) BottomSheetItemWithDescription(net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription)

Aggregations

TargetPointsHelper (net.osmand.plus.helpers.TargetPointsHelper)42 TargetPoint (net.osmand.plus.helpers.TargetPointsHelper.TargetPoint)24 LatLon (net.osmand.data.LatLon)22 OsmandApplication (net.osmand.plus.OsmandApplication)19 MapActivity (net.osmand.plus.activities.MapActivity)14 View (android.view.View)11 RoutingHelper (net.osmand.plus.routing.RoutingHelper)11 TextView (android.widget.TextView)10 PointDescription (net.osmand.data.PointDescription)9 ImageView (android.widget.ImageView)8 ArrayList (java.util.ArrayList)8 Location (net.osmand.Location)8 ApplicationMode (net.osmand.plus.settings.backend.ApplicationMode)7 Bundle (android.os.Bundle)4 OnClickListener (android.view.View.OnClickListener)4 FavouritePoint (net.osmand.data.FavouritePoint)4 DialogInterface (android.content.DialogInterface)3 HorizontalScrollView (android.widget.HorizontalScrollView)3 ImageButton (android.widget.ImageButton)3 LinearLayout (android.widget.LinearLayout)3