Search in sources :

Example 11 with TargetPoint

use of net.osmand.plus.TargetPointsHelper.TargetPoint 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 12 with TargetPoint

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

the class WaypointDialogHelper method updatePointInfoView.

public static void updatePointInfoView(final OsmandApplication app, final Activity activity, View localView, final LocationPointWrapper ps, final boolean mapCenter, final boolean nightMode, final boolean edit, final boolean topBar) {
    WaypointHelper wh = app.getWaypointHelper();
    final LocationPoint point = ps.getPoint();
    TextView text = (TextView) localView.findViewById(R.id.waypoint_text);
    if (!topBar) {
        AndroidUtils.setTextPrimaryColor(activity, text, nightMode);
    }
    TextView textShadow = (TextView) localView.findViewById(R.id.waypoint_text_shadow);
    if (!edit) {
        localView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                showOnMap(app, activity, point, mapCenter);
            }
        });
    }
    TextView textDist = (TextView) localView.findViewById(R.id.waypoint_dist);
    ((ImageView) localView.findViewById(R.id.waypoint_icon)).setImageDrawable(ps.getDrawable(activity, app, nightMode));
    int dist = -1;
    boolean startPoint = ps.type == WaypointHelper.TARGETS && ((TargetPoint) ps.point).start;
    if (!startPoint) {
        if (!wh.isRouteCalculated()) {
            if (activity instanceof MapActivity) {
                dist = (int) MapUtils.getDistance(((MapActivity) activity).getMapView().getLatitude(), ((MapActivity) activity).getMapView().getLongitude(), point.getLatitude(), point.getLongitude());
            }
        } else {
            dist = wh.getRouteDistance(ps);
        }
    }
    if (dist > 0) {
        textDist.setText(OsmAndFormatter.getFormattedDistance(dist, app));
    } else {
        textDist.setText("");
    }
    TextView textDeviation = (TextView) localView.findViewById(R.id.waypoint_deviation);
    if (textDeviation != null) {
        if (dist > 0 && ps.deviationDistance > 0) {
            String devStr = "+" + OsmAndFormatter.getFormattedDistance(ps.deviationDistance, app);
            textDeviation.setText(devStr);
            if (!topBar) {
                int colorId = nightMode ? R.color.secondary_text_dark : R.color.secondary_text_light;
                AndroidUtils.setTextSecondaryColor(activity, textDeviation, nightMode);
                if (ps.deviationDirectionRight) {
                    textDeviation.setCompoundDrawablesWithIntrinsicBounds(app.getIconsCache().getIcon(R.drawable.ic_small_turn_right, colorId), null, null, null);
                } else {
                    textDeviation.setCompoundDrawablesWithIntrinsicBounds(app.getIconsCache().getIcon(R.drawable.ic_small_turn_left, colorId), null, null, null);
                }
            }
            textDeviation.setVisibility(View.VISIBLE);
        } else {
            textDeviation.setText("");
            textDeviation.setVisibility(View.GONE);
        }
    }
    String descr;
    PointDescription pd = point.getPointDescription(app);
    if (Algorithms.isEmpty(pd.getName())) {
        descr = pd.getTypeName();
    } else {
        descr = pd.getName();
    }
    if (textShadow != null) {
        textShadow.setText(descr);
    }
    text.setText(descr);
    String pointDescription = "";
    TextView descText = (TextView) localView.findViewById(R.id.waypoint_desc_text);
    if (descText != null) {
        AndroidUtils.setTextSecondaryColor(activity, descText, nightMode);
        switch(ps.type) {
            case WaypointHelper.TARGETS:
                TargetPoint targetPoint = (TargetPoint) ps.point;
                if (targetPoint.start) {
                    pointDescription = activity.getResources().getString(R.string.starting_point);
                } else {
                    pointDescription = targetPoint.getPointDescription(activity).getTypeName();
                }
                break;
            case WaypointHelper.FAVORITES:
                FavouritePoint favPoint = (FavouritePoint) ps.point;
                pointDescription = Algorithms.isEmpty(favPoint.getCategory()) ? activity.getResources().getString(R.string.shared_string_favorites) : favPoint.getCategory();
                break;
        }
    }
    if (Algorithms.objectEquals(descr, pointDescription)) {
        pointDescription = "";
    }
    if (dist > 0 && !Algorithms.isEmpty(pointDescription)) {
        pointDescription = "  •  " + pointDescription;
    }
    if (descText != null) {
        descText.setText(pointDescription);
    }
}
Also used : FavouritePoint(net.osmand.data.FavouritePoint) LocationPoint(net.osmand.data.LocationPoint) 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) PointDescription(net.osmand.data.PointDescription) TextView(android.widget.TextView) ImageView(android.widget.ImageView) MapActivity(net.osmand.plus.activities.MapActivity)

Example 13 with TargetPoint

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

the class WaypointDialogHelper method switchStartAndFirstIntermediate.

// switch start & first intermediate point
private static void switchStartAndFirstIntermediate(TargetPointsHelper targetPointsHelper, Activity ctx, TargetPoint start, WaypointDialogHelper helper) {
    List<TargetPoint> intermediatePoints = targetPointsHelper.getIntermediatePointsWithTarget();
    TargetPoint firstIntermediate = intermediatePoints.remove(0);
    targetPointsHelper.setStartPoint(new LatLon(firstIntermediate.getLatitude(), firstIntermediate.getLongitude()), false, firstIntermediate.getPointDescription(ctx));
    TargetPoint destination = new TargetPoint(new LatLon(start.getLatitude(), start.getLongitude()), start.getPointDescription(ctx));
    intermediatePoints.add(0, destination);
    targetPointsHelper.reorderAllTargetPoints(intermediatePoints, true);
    updateControls(ctx, helper);
}
Also used : LatLon(net.osmand.data.LatLon) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint)

Example 14 with TargetPoint

use of net.osmand.plus.TargetPointsHelper.TargetPoint 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)

Example 15 with TargetPoint

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

the class WaypointDialogHelper method createItemForCategory.

protected View createItemForCategory(final FragmentActivity ctx, final int type, final int[] running, final int position, final ArrayAdapter<Object> thisAdapter, boolean nightMode, final WaypointDialogHelper helper) {
    View v;
    v = ctx.getLayoutInflater().inflate(R.layout.waypoint_header, null);
    final CompoundButton btn = (CompoundButton) v.findViewById(R.id.toggle_item);
    btn.setVisibility(waypointHelper.isTypeConfigurable(type) ? View.VISIBLE : View.GONE);
    btn.setOnCheckedChangeListener(null);
    final boolean checked = waypointHelper.isTypeEnabled(type);
    btn.setChecked(checked);
    btn.setEnabled(running[0] == -1);
    v.findViewById(R.id.ProgressBar).setVisibility(position == running[0] ? View.VISIBLE : View.GONE);
    btn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            running[0] = position;
            thisAdapter.notifyDataSetInvalidated();
            if (type == WaypointHelper.POI && isChecked) {
                selectPoi(running, thisAdapter, type, isChecked, ctx);
            } else {
                enableType(running, thisAdapter, type, isChecked);
            }
        }
    });
    final TextViewEx optionsButton = (TextViewEx) v.findViewById(R.id.text_button);
    if (type == WaypointHelper.TARGETS) {
        optionsButton.setVisibility(View.VISIBLE);
        optionsButton.setTextColor(ContextCompat.getColor(ctx, nightMode ? R.color.color_dialog_buttons_dark : R.color.color_dialog_buttons_light));
        optionsButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                boolean hasActivePoints = false;
                if (thisAdapter instanceof StableArrayAdapter) {
                    List<Object> items = ((StableArrayAdapter) thisAdapter).getActiveObjects();
                    if (items.size() > 0) {
                        if (items.size() > 1) {
                            hasActivePoints = true;
                        } else {
                            Object item = items.get(0);
                            if (item instanceof LocationPointWrapper) {
                                LocationPointWrapper w = (LocationPointWrapper) item;
                                if (w.getPoint() instanceof TargetPoint) {
                                    hasActivePoints = !((TargetPoint) w.point).start;
                                }
                            } else {
                                hasActivePoints = true;
                            }
                        }
                    }
                }
                if (hasActivePoints) {
                    TargetOptionsBottomSheetDialogFragment fragment = new TargetOptionsBottomSheetDialogFragment();
                    fragment.setUsedOnMap(true);
                    fragment.show(ctx.getSupportFragmentManager(), TargetOptionsBottomSheetDialogFragment.TAG);
                }
            }
        });
    } else {
        optionsButton.setVisibility(View.GONE);
    }
    TextView tv = (TextView) v.findViewById(R.id.header_text);
    AndroidUtils.setTextPrimaryColor(mapActivity, tv, nightMode);
    tv.setText(getHeader(type, checked, ctx));
    return v;
}
Also used : StableArrayAdapter(net.osmand.plus.views.controls.StableArrayAdapter) 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) TextViewEx(net.osmand.plus.widgets.TextViewEx) List(java.util.List) ArrayList(java.util.ArrayList) TextView(android.widget.TextView) CompoundButton(android.widget.CompoundButton)

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