Search in sources :

Example 26 with TargetPoint

use of net.osmand.plus.TargetPointsHelper.TargetPoint 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(R.color.searchbar_text_hint_light).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(R.color.searchbar_text_hint_light).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) {
            TargetPoint start = targetPointsHelper.getPointToStart();
            if (start != null) {
                targetPointsHelper.navigateToPoint(new LatLon(start.getLatitude(), start.getLongitude()), false, 0, start.getOriginalPointDescription());
            }
            targetPointsHelper.setStartPoint(latLon, true, name);
            dismiss();
        }
    }).create();
    items.add(replaceStartItem);
    items.add(new DividerHalfItem(getContext(), getBottomDividerColorId()));
    BaseBottomSheetItem subsequentDestItem = new BottomSheetItemWithDescription.Builder().setDescription(getString(R.string.subsequent_dest_description)).setDescriptionColorId(R.color.searchbar_text_hint_light).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(R.color.searchbar_text_hint_light).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(R.color.searchbar_text_hint_light).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) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) TargetPointsHelper(net.osmand.plus.TargetPointsHelper) View(android.view.View) BottomSheetItemWithDescription(net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription)

Example 27 with TargetPoint

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

the class WaypointDialogHelper method replaceStartWithFirstIntermediate.

private static void replaceStartWithFirstIntermediate(TargetPointsHelper targetPointsHelper, Activity ctx, WaypointDialogHelper helper) {
    List<TargetPoint> intermediatePoints = targetPointsHelper.getIntermediatePointsWithTarget();
    TargetPoint firstIntermediate = intermediatePoints.remove(0);
    targetPointsHelper.setStartPoint(new LatLon(firstIntermediate.getLatitude(), firstIntermediate.getLongitude()), false, firstIntermediate.getPointDescription(ctx));
    targetPointsHelper.reorderAllTargetPoints(intermediatePoints, true);
    updateControls(ctx, helper);
}
Also used : LatLon(net.osmand.data.LatLon) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint)

Example 28 with TargetPoint

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

the class WaypointHelper method getTargets.

protected List<LocationPointWrapper> getTargets(List<LocationPointWrapper> points) {
    List<TargetPoint> wts = app.getTargetPointsHelper().getIntermediatePointsWithTarget();
    for (int k = 0; k < wts.size(); k++) {
        final int index = wts.size() - k - 1;
        TargetPoint tp = wts.get(index);
        int routeIndex;
        if (route == null) {
            routeIndex = k == 0 ? Integer.MAX_VALUE : index;
        } else {
            routeIndex = k == 0 ? route.getImmutableAllLocations().size() - 1 : route.getIndexOfIntermediate(k - 1);
        }
        points.add(new LocationPointWrapper(route, TARGETS, tp, 0, routeIndex));
    }
    Collections.reverse(points);
    return points;
}
Also used : TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) AmenityRoutePoint(net.osmand.data.Amenity.AmenityRoutePoint) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) LocationPoint(net.osmand.data.LocationPoint)

Example 29 with TargetPoint

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

the class DashboardOnMap method createDashboardView.

public void createDashboardView() {
    baseColor = ContextCompat.getColor(mapActivity, R.color.osmand_orange) & 0x00ffffff;
    waypointDialogHelper = new WaypointDialogHelper(mapActivity);
    waypointDialogHelper.setHelperCallbacks(this);
    landscape = !AndroidUiHelper.isOrientationPortrait(mapActivity);
    dashboardView = (FrameLayout) mapActivity.findViewById(R.id.dashboard);
    AndroidUtils.addStatusBarPadding21v(mapActivity, dashboardView);
    final View.OnClickListener listener = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            hideDashboard();
        }
    };
    toolbar = ((Toolbar) dashboardView.findViewById(R.id.toolbar));
    ObservableScrollView scrollView = ((ObservableScrollView) dashboardView.findViewById(R.id.main_scroll));
    listView = (DynamicListView) dashboardView.findViewById(R.id.dash_list_view);
    // listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    listView.setDrawSelectorOnTop(true);
    listView.setDynamicListViewCallbacks(this);
    listEmptyTextView = (TextView) dashboardView.findViewById(R.id.emptyTextView);
    // Create a ListView-specific touch listener. ListViews are given special treatment because
    // by default they handle touches for their list items... i.e. they're in charge of drawing
    // the pressed state (the list selector), handling list item clicks, etc.
    swipeDismissListener = new SwipeDismissListViewTouchListener(mapActivity, listView, new DismissCallbacks() {

        @Override
        public boolean canDismiss(int position) {
            if (listAdapter instanceof StableArrayAdapter && (visibleType == DashboardType.WAYPOINTS || visibleType == DashboardType.WAYPOINTS_FLAT)) {
                List<Object> activeObjects = ((StableArrayAdapter) listAdapter).getActiveObjects();
                Object obj = listAdapter.getItem(position);
                if (obj instanceof LocationPointWrapper) {
                    LocationPointWrapper w = (LocationPointWrapper) obj;
                    if (w.getPoint() instanceof TargetPoint) {
                        return !((TargetPoint) w.getPoint()).start;
                    }
                }
                return activeObjects.contains(obj);
            }
            return false;
        }

        @Override
        public Undoable onDismiss(final int position) {
            final Object item;
            final StableArrayAdapter stableAdapter;
            final int activeObjPos;
            if (listAdapter instanceof StableArrayAdapter) {
                stableAdapter = (StableArrayAdapter) listAdapter;
                item = stableAdapter.getItem(position);
                stableAdapter.setNotifyOnChange(false);
                stableAdapter.remove(item);
                stableAdapter.getObjects().remove(item);
                activeObjPos = stableAdapter.getActiveObjects().indexOf(item);
                stableAdapter.getActiveObjects().remove(item);
                stableAdapter.refreshData();
                stableAdapter.notifyDataSetChanged();
            } else {
                item = null;
                stableAdapter = null;
                activeObjPos = 0;
            }
            return new Undoable() {

                @Override
                public void undo() {
                    if (item != null) {
                        stableAdapter.setNotifyOnChange(false);
                        stableAdapter.insert(item, position);
                        stableAdapter.getObjects().add(position, item);
                        stableAdapter.getActiveObjects().add(activeObjPos, item);
                        stableAdapter.refreshData();
                        if (visibleType == DashboardType.WAYPOINTS || visibleType == DashboardType.WAYPOINTS_FLAT) {
                            onItemsSwapped(stableAdapter.getActiveObjects());
                        }
                    }
                }

                @Override
                public String getTitle() {
                    List<Object> activeObjects;
                    if ((visibleType == DashboardType.WAYPOINTS || visibleType == DashboardType.WAYPOINTS_FLAT) && (getMyApplication().getRoutingHelper().isRoutePlanningMode() || getMyApplication().getRoutingHelper().isFollowingMode()) && item != null && ((activeObjects = stableAdapter.getActiveObjects()).isEmpty() || isContainsOnlyStart(activeObjects))) {
                        return mapActivity.getResources().getString(R.string.cancel_navigation);
                    } else {
                        return null;
                    }
                }
            };
        }

        @Override
        public void onHidePopup() {
            if (listAdapter instanceof StableArrayAdapter) {
                StableArrayAdapter stableAdapter = (StableArrayAdapter) listAdapter;
                stableAdapter.refreshData();
                if (visibleType == DashboardType.WAYPOINTS || visibleType == DashboardType.WAYPOINTS_FLAT) {
                    onItemsSwapped(stableAdapter.getActiveObjects());
                }
                List<Object> activeObjects = stableAdapter.getActiveObjects();
                if (activeObjects.isEmpty() || isContainsOnlyStart(activeObjects)) {
                    hideDashboard();
                    if (visibleType == DashboardType.WAYPOINTS || visibleType == DashboardType.WAYPOINTS_FLAT) {
                        mapActivity.getMapActions().stopNavigationWithoutConfirm();
                        getMyApplication().getTargetPointsHelper().removeAllWayPoints(false, true);
                        mapActivity.getMapLayers().getMapControlsLayer().getMapRouteInfoMenu().hide();
                    }
                }
            }
        }

        private boolean isContainsOnlyStart(List<Object> items) {
            if (items.size() == 1) {
                Object item = items.get(0);
                if (item instanceof LocationPointWrapper) {
                    LocationPointWrapper w = (LocationPointWrapper) item;
                    if (w.getPoint() instanceof TargetPoint) {
                        return ((TargetPoint) w.getPoint()).start;
                    }
                }
            }
            return false;
        }
    });
    gradientToolbar = ContextCompat.getDrawable(mapActivity, R.drawable.gradient_toolbar).mutate();
    if (AndroidUiHelper.isOrientationPortrait(mapActivity)) {
        this.portrait = true;
        scrollView.setScrollViewCallbacks(this);
        listView.setScrollViewCallbacks(this);
        mFlexibleSpaceImageHeight = mapActivity.getResources().getDimensionPixelSize(R.dimen.dashboard_map_top_padding);
        mFlexibleBlurSpaceHeight = mapActivity.getResources().getDimensionPixelSize(R.dimen.dashboard_map_toolbar);
        // Set padding view for ListView. This is the flexible space.
        paddingView = new FrameLayout(mapActivity);
        AbsListView.LayoutParams lp = new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, mFlexibleSpaceImageHeight);
        paddingView.setLayoutParams(lp);
        // This is required to disable header's list selector effect
        paddingView.setClickable(true);
        paddingView.setOnClickListener(listener);
        FrameLayout shadowContainer = new FrameLayout(mapActivity);
        FrameLayout.LayoutParams fl = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
        fl.gravity = Gravity.BOTTOM;
        shadowContainer.setLayoutParams(fl);
        ImageView shadow = new ImageView(mapActivity);
        shadow.setImageDrawable(ContextCompat.getDrawable(mapActivity, R.drawable.bg_shadow_onmap));
        shadow.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.BOTTOM));
        shadow.setScaleType(ScaleType.FIT_XY);
        shadowContainer.addView(shadow);
        ((FrameLayout) paddingView).addView(shadowContainer);
        listView.addHeaderView(paddingView);
        listBackgroundView = mapActivity.findViewById(R.id.dash_list_background);
    }
    dashboardView.findViewById(R.id.animateContent).setOnClickListener(listener);
    dashboardView.findViewById(R.id.map_part_dashboard).setOnClickListener(listener);
    initActionButtons();
    dashboardView.addView(actionButton);
}
Also used : Undoable(net.osmand.plus.views.controls.SwipeDismissListViewTouchListener.Undoable) StableArrayAdapter(net.osmand.plus.views.controls.StableArrayAdapter) ObservableScrollView(com.github.ksoichiro.android.observablescrollview.ObservableScrollView) WaypointDialogHelper(net.osmand.plus.helpers.WaypointDialogHelper) LocationPointWrapper(net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper) AbsListView(android.widget.AbsListView) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) ImageView(android.widget.ImageView) DynamicListView(net.osmand.plus.views.controls.DynamicListView) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) ScrollView(android.widget.ScrollView) ObservableScrollView(com.github.ksoichiro.android.observablescrollview.ObservableScrollView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) SuppressLint(android.annotation.SuppressLint) SwipeDismissListViewTouchListener(net.osmand.plus.views.controls.SwipeDismissListViewTouchListener) FrameLayout(android.widget.FrameLayout) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) ImageView(android.widget.ImageView) DismissCallbacks(net.osmand.plus.views.controls.SwipeDismissListViewTouchListener.DismissCallbacks) Toolbar(android.support.v7.widget.Toolbar)

Example 30 with TargetPoint

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

the class IntermediatePointsDialog method commitChangePointsOrder.

private static void commitChangePointsOrder(OsmandApplication app, List<TargetPoint> target) {
    TargetPointsHelper targets = app.getTargetPointsHelper();
    List<TargetPoint> cur = targets.getIntermediatePointsWithTarget();
    boolean eq = true;
    for (int j = 0; j < cur.size() && j < target.size(); j++) {
        if (cur.get(j) != target.get(j)) {
            eq = false;
            break;
        }
    }
    if (!eq) {
        targets.reorderAllTargetPoints(target, true);
    }
}
Also used : TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) TargetPointsHelper(net.osmand.plus.TargetPointsHelper) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint)

Aggregations

TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)39 TargetPointsHelper (net.osmand.plus.TargetPointsHelper)18 LatLon (net.osmand.data.LatLon)17 View (android.view.View)13 TextView (android.widget.TextView)13 Location (net.osmand.Location)10 PointDescription (net.osmand.data.PointDescription)10 AdapterView (android.widget.AdapterView)9 ArrayList (java.util.ArrayList)9 ImageView (android.widget.ImageView)8 SuppressLint (android.annotation.SuppressLint)6 LocationPoint (net.osmand.data.LocationPoint)6 FavouritePoint (net.osmand.data.FavouritePoint)5 OsmandApplication (net.osmand.plus.OsmandApplication)5 Paint (android.graphics.Paint)4 ImageButton (android.widget.ImageButton)4 ListView (android.widget.ListView)4 List (java.util.List)4 RoutingHelper (net.osmand.plus.routing.RoutingHelper)4 DialogInterface (android.content.DialogInterface)3