Search in sources :

Example 1 with LocationPointWrapper

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

the class DashWaypointsFragment method setupWaypoints.

private void setupWaypoints() {
    View mainView = getView();
    WaypointHelper wh = getMyApplication().getWaypointHelper();
    List<LocationPointWrapper> allPoints = wh.getAllPoints();
    if (allPoints.size() == 0) {
        (mainView.findViewById(R.id.main_fav)).setVisibility(View.GONE);
        return;
    } else {
        (mainView.findViewById(R.id.main_fav)).setVisibility(View.VISIBLE);
    }
    ((TextView) mainView.findViewById(R.id.fav_text)).setText(getString(R.string.waypoints));
    ((Button) mainView.findViewById(R.id.show_all)).setText(getString(R.string.shared_string_show_all));
    ((Button) mainView.findViewById(R.id.show_all)).setVisibility(View.VISIBLE);
    ((Button) mainView.findViewById(R.id.show_all)).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            dashboard.setDashboardVisibility(true, DashboardType.WAYPOINTS, AndroidUtils.getCenterViewCoordinates(v));
        }
    });
    LinearLayout favorites = (LinearLayout) mainView.findViewById(R.id.items);
    favorites.removeAllViews();
    List<DashLocationView> distances = new ArrayList<DashLocationFragment.DashLocationView>();
    for (int i = 0; i < 3 && i < allPoints.size(); i++) {
        LocationPointWrapper ps = allPoints.get(i);
        View dv = getActivity().getLayoutInflater().inflate(R.layout.divider, null);
        favorites.addView(dv);
        View v = WaypointDialogHelper.updateWaypointItemView(false, null, getMyApplication(), getActivity(), null, null, ps, null, !getMyApplication().getSettings().isLightContent(), true);
        favorites.addView(v);
    }
    this.distances = distances;
}
Also used : WaypointHelper(net.osmand.plus.helpers.WaypointHelper) LocationPointWrapper(net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper) ArrayList(java.util.ArrayList) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) ImageButton(android.widget.ImageButton) Button(android.widget.Button) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout)

Example 2 with LocationPointWrapper

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

the class WaypointDialogHelper method getCustomDividers.

private List<Drawable> getCustomDividers(Context ctx, List<Object> points, boolean nightMode) {
    int color = ContextCompat.getColor(ctx, nightMode ? R.color.dashboard_divider_dark : R.color.dashboard_divider_light);
    Shape fullDividerShape = new ListDividerShape(color, 0);
    Shape halfDividerShape = new ListDividerShape(color, AndroidUtils.dpToPx(ctx, 56f));
    Shape headerDividerShape = new ListDividerShape(color, AndroidUtils.dpToPx(ctx, 16f));
    final ShapeDrawable fullDivider = new ShapeDrawable(fullDividerShape);
    final ShapeDrawable halfDivider = new ShapeDrawable(halfDividerShape);
    final ShapeDrawable headerDivider = new ShapeDrawable(headerDividerShape);
    int divHeight = AndroidUtils.dpToPx(ctx, 1f);
    fullDivider.setIntrinsicHeight(divHeight);
    halfDivider.setIntrinsicHeight(divHeight);
    headerDivider.setIntrinsicHeight(divHeight);
    List<Drawable> res = new ArrayList<>();
    for (int i = 0; i < points.size(); i++) {
        Object obj = points.get(i);
        Object objNext = i + 1 < points.size() ? points.get(i + 1) : null;
        if (objNext == null) {
            break;
        }
        boolean labelView = (obj instanceof Integer);
        boolean bottomDividerViewNext = (objNext instanceof Boolean) && !((Boolean) objNext);
        boolean locationPoint = (obj instanceof LocationPointWrapper);
        boolean locationPointNext = (objNext instanceof LocationPointWrapper);
        Drawable d = null;
        if (locationPointNext) {
            d = locationPoint ? halfDivider : fullDivider;
        } else if (objNext instanceof RadiusItem && labelView) {
            d = headerDivider;
        } else if (locationPoint && !bottomDividerViewNext) {
            d = fullDivider;
        }
        res.add(d);
    }
    return res;
}
Also used : ListDividerShape(net.osmand.plus.views.controls.ListDividerShape) Shape(android.graphics.drawable.shapes.Shape) Drawable(android.graphics.drawable.Drawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) ArrayList(java.util.ArrayList) LocationPointWrapper(net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper) ListDividerShape(net.osmand.plus.views.controls.ListDividerShape) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) LocationPoint(net.osmand.data.LocationPoint) SuppressLint(android.annotation.SuppressLint) FavouritePoint(net.osmand.data.FavouritePoint) ShapeDrawable(android.graphics.drawable.ShapeDrawable)

Example 3 with LocationPointWrapper

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

the class WaypointDialogHelper method getWaypointsDrawerAdapter.

public StableArrayAdapter getWaypointsDrawerAdapter(final boolean edit, final List<LocationPointWrapper> deletedPoints, final MapActivity ctx, final int[] running, final boolean flat, final boolean nightMode) {
    this.flat = flat;
    this.deletedPoints = deletedPoints;
    final List<Object> points = getPoints();
    List<Object> activePoints = getActivePoints(points);
    final WaypointDialogHelper helper = this;
    final StableArrayAdapter listAdapter = new StableArrayAdapter(ctx, R.layout.waypoint_reached, R.id.title, points, activePoints) {

        @Override
        public void buildDividers() {
            dividers = getCustomDividers(ctx, getObjects(), nightMode);
        }

        @Override
        public boolean isEnabled(int position) {
            Object obj = getItem(position);
            boolean labelView = (obj instanceof Integer);
            boolean topDividerView = (obj instanceof Boolean) && ((Boolean) obj);
            boolean bottomDividerView = (obj instanceof Boolean) && !((Boolean) obj);
            boolean enabled = !labelView && !topDividerView && !bottomDividerView;
            if (enabled && obj instanceof RadiusItem) {
                int type = ((RadiusItem) obj).type;
                enabled = type != WaypointHelper.POI;
            }
            return enabled;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            // User super class to create the View
            View v = convertView;
            final ArrayAdapter<Object> thisAdapter = this;
            Object obj = getItem(position);
            boolean labelView = (obj instanceof Integer);
            boolean topDividerView = (obj instanceof Boolean) && ((Boolean) obj);
            boolean bottomDividerView = (obj instanceof Boolean) && !((Boolean) obj);
            if (obj instanceof RadiusItem) {
                final int type = ((RadiusItem) obj).type;
                v = createItemForRadiusProximity(ctx, type, running, position, thisAdapter, nightMode);
                // Drawable d = new ColorDrawable(mapActivity.getResources().getColor(R.color.dashboard_divider_light));
                AndroidUtils.setListItemBackground(mapActivity, v, nightMode);
            } else if (labelView) {
                v = createItemForCategory(ctx, (Integer) obj, running, position, thisAdapter, nightMode, helper);
                AndroidUtils.setListItemBackground(mapActivity, v, nightMode);
            } else if (topDividerView) {
                v = ctx.getLayoutInflater().inflate(R.layout.card_top_divider, null);
                AndroidUtils.setListBackground(mapActivity, v, nightMode);
            } else if (bottomDividerView) {
                v = ctx.getLayoutInflater().inflate(R.layout.card_bottom_divider, null);
                AndroidUtils.setListBackground(mapActivity, v, nightMode);
            } else if (obj instanceof LocationPointWrapper) {
                LocationPointWrapper point = (LocationPointWrapper) obj;
                v = updateWaypointItemView(edit, deletedPoints, app, ctx, helper, v, point, this, nightMode, flat);
                AndroidUtils.setListItemBackground(mapActivity, v, nightMode);
            }
            return v;
        }
    };
    for (Object p : points) {
        if (p instanceof LocationPointWrapper) {
            LocationPointWrapper w = (LocationPointWrapper) p;
            if (w.type == WaypointHelper.TARGETS) {
                final TargetPoint t = (TargetPoint) w.point;
                if (t.getOriginalPointDescription() != null && t.getOriginalPointDescription().isSearchingAddress(mapActivity)) {
                    GeocodingLookupService.AddressLookupRequest lookupRequest = new GeocodingLookupService.AddressLookupRequest(t.point, new GeocodingLookupService.OnAddressLookupResult() {

                        @Override
                        public void geocodingDone(String address) {
                            if (helperCallbacks != null) {
                                helperCallbacks.reloadAdapter();
                            } else {
                                reloadListAdapter(listAdapter);
                            }
                        // updateRouteInfoMenu(ctx);
                        }
                    }, null);
                    app.getGeocodingLookupService().lookupAddress(lookupRequest);
                }
            }
        }
    }
    return listAdapter;
}
Also used : StableArrayAdapter(net.osmand.plus.views.controls.StableArrayAdapter) GeocodingLookupService(net.osmand.plus.GeocodingLookupService) ViewGroup(android.view.ViewGroup) LocationPointWrapper(net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) LocationPoint(net.osmand.data.LocationPoint) SuppressLint(android.annotation.SuppressLint) FavouritePoint(net.osmand.data.FavouritePoint)

Example 4 with LocationPointWrapper

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

the class WaypointDialogHelper method getDrawerItemClickListener.

public AdapterView.OnItemClickListener getDrawerItemClickListener(final FragmentActivity ctx, final int[] running, final ArrayAdapter<Object> listAdapter) {
    return new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int item, long l) {
            if (listAdapter.getItem(item) instanceof LocationPointWrapper) {
                LocationPointWrapper ps = (LocationPointWrapper) listAdapter.getItem(item);
                showOnMap(app, ctx, ps.getPoint(), false);
            // } else if (new Integer(WaypointHelper.TARGETS).equals(listAdapter.getItem(item))) {
            // IntermediatePointsDialog.openIntermediatePointsDialog(ctx, app, true);
            } else if (listAdapter.getItem(item) instanceof RadiusItem) {
                selectDifferentRadius(((RadiusItem) listAdapter.getItem(item)).type, running, item, listAdapter, ctx);
            }
        }
    };
}
Also used : LocationPointWrapper(net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper) AdapterView(android.widget.AdapterView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView)

Example 5 with LocationPointWrapper

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

the class WaypointDialogHelper method getStandardPoints.

protected List<Object> getStandardPoints() {
    final List<Object> points = new ArrayList<>();
    boolean rc = waypointHelper.isRouteCalculated();
    for (int i = 0; i < WaypointHelper.MAX; i++) {
        List<LocationPointWrapper> tp = waypointHelper.getWaypoints(i);
        if ((rc || i == WaypointHelper.WAYPOINTS || i == WaypointHelper.TARGETS) && waypointHelper.isTypeVisible(i)) {
            if (points.size() > 0) {
                points.add(true);
            }
            points.add(i);
            if (i == WaypointHelper.TARGETS) {
                TargetPoint start = app.getTargetPointsHelper().getPointToStart();
                if (start == null) {
                    LatLon latLon;
                    Location loc = app.getLocationProvider().getLastKnownLocation();
                    if (loc != null) {
                        latLon = new LatLon(loc.getLatitude(), loc.getLongitude());
                    } else {
                        latLon = new LatLon(mapActivity.getMapView().getLatitude(), mapActivity.getMapView().getLongitude());
                    }
                    start = TargetPoint.createStartPoint(latLon, new PointDescription(PointDescription.POINT_TYPE_MY_LOCATION, mapActivity.getString(R.string.shared_string_my_location)));
                } else {
                    String oname = start.getOnlyName().length() > 0 ? start.getOnlyName() : (mapActivity.getString(R.string.route_descr_map_location) + " " + mapActivity.getString(R.string.route_descr_lat_lon, start.getLatitude(), start.getLongitude()));
                    start = TargetPoint.createStartPoint(new LatLon(start.getLatitude(), start.getLongitude()), new PointDescription(PointDescription.POINT_TYPE_LOCATION, oname));
                }
                points.add(new LocationPointWrapper(null, WaypointHelper.TARGETS, start, 0f, 0));
            } else if ((i == WaypointHelper.POI || i == WaypointHelper.FAVORITES || i == WaypointHelper.WAYPOINTS) && rc) {
                if (waypointHelper.isTypeEnabled(i)) {
                    points.add(new RadiusItem(i));
                }
            }
            if (tp != null && tp.size() > 0) {
                points.addAll(tp);
            }
            points.add(false);
        }
    }
    return points;
}
Also used : ArrayList(java.util.ArrayList) LocationPointWrapper(net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) LocationPoint(net.osmand.data.LocationPoint) SuppressLint(android.annotation.SuppressLint) FavouritePoint(net.osmand.data.FavouritePoint) LatLon(net.osmand.data.LatLon) PointDescription(net.osmand.data.PointDescription) Location(net.osmand.Location)

Aggregations

LocationPointWrapper (net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper)8 ArrayList (java.util.ArrayList)6 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)6 View (android.view.View)5 ImageView (android.widget.ImageView)5 TextView (android.widget.TextView)5 SuppressLint (android.annotation.SuppressLint)4 AdapterView (android.widget.AdapterView)4 StableArrayAdapter (net.osmand.plus.views.controls.StableArrayAdapter)4 FavouritePoint (net.osmand.data.FavouritePoint)3 LocationPoint (net.osmand.data.LocationPoint)3 List (java.util.List)2 Drawable (android.graphics.drawable.Drawable)1 ShapeDrawable (android.graphics.drawable.ShapeDrawable)1 Shape (android.graphics.drawable.shapes.Shape)1 Toolbar (android.support.v7.widget.Toolbar)1 ViewGroup (android.view.ViewGroup)1 AbsListView (android.widget.AbsListView)1 Button (android.widget.Button)1 CompoundButton (android.widget.CompoundButton)1