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;
}
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;
}
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;
}
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);
}
}
};
}
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;
}
Aggregations