Cleanup code
This commit is contained in:
parent
b1535477af
commit
b8d0dad2c3
2 changed files with 0 additions and 516 deletions
|
@ -3,26 +3,11 @@ package net.osmand.plus.helpers;
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
import android.content.Context;
|
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.DialogInterface.OnClickListener;
|
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.graphics.drawable.ShapeDrawable;
|
|
||||||
import android.graphics.drawable.shapes.Shape;
|
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.app.FragmentActivity;
|
|
||||||
import android.support.v4.content.ContextCompat;
|
|
||||||
import android.support.v7.app.AlertDialog;
|
|
||||||
import android.support.v7.widget.ListPopupWindow;
|
|
||||||
import android.view.Gravity;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.AdapterView;
|
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.CompoundButton;
|
|
||||||
import android.widget.ImageButton;
|
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
@ -33,14 +18,12 @@ import net.osmand.data.FavouritePoint;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
import net.osmand.data.LocationPoint;
|
import net.osmand.data.LocationPoint;
|
||||||
import net.osmand.data.PointDescription;
|
import net.osmand.data.PointDescription;
|
||||||
import net.osmand.plus.GeocodingLookupService;
|
|
||||||
import net.osmand.plus.OsmAndFormatter;
|
import net.osmand.plus.OsmAndFormatter;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.TargetPointsHelper;
|
import net.osmand.plus.TargetPointsHelper;
|
||||||
import net.osmand.plus.TargetPointsHelper.TargetPoint;
|
import net.osmand.plus.TargetPointsHelper.TargetPoint;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.activities.MapActivityLayers;
|
|
||||||
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
||||||
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
||||||
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
|
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
|
||||||
|
@ -48,12 +31,7 @@ import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem;
|
||||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
||||||
import net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper;
|
import net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper;
|
||||||
import net.osmand.plus.routepreparationmenu.AddPointBottomSheetDialog;
|
import net.osmand.plus.routepreparationmenu.AddPointBottomSheetDialog;
|
||||||
import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu;
|
|
||||||
import net.osmand.plus.poi.PoiUIFilter;
|
|
||||||
import net.osmand.plus.views.controls.DynamicListView.DragIcon;
|
|
||||||
import net.osmand.plus.views.controls.ListDividerShape;
|
|
||||||
import net.osmand.plus.views.controls.StableArrayAdapter;
|
import net.osmand.plus.views.controls.StableArrayAdapter;
|
||||||
import net.osmand.plus.widgets.TextViewEx;
|
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
import net.osmand.util.MapUtils;
|
import net.osmand.util.MapUtils;
|
||||||
|
|
||||||
|
@ -75,16 +53,6 @@ public class WaypointDialogHelper {
|
||||||
void reloadAdapter();
|
void reloadAdapter();
|
||||||
|
|
||||||
void deleteWaypoint(int position);
|
void deleteWaypoint(int position);
|
||||||
|
|
||||||
void exchangeWaypoints(int pos1, int pos2);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class RadiusItem {
|
|
||||||
int type;
|
|
||||||
|
|
||||||
public RadiusItem(int type) {
|
|
||||||
this.type = type;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addHelperCallbacks(WaypointDialogHelperCallbacks callbacks) {
|
public void addHelperCallbacks(WaypointDialogHelperCallbacks callbacks) {
|
||||||
|
@ -211,16 +179,6 @@ public class WaypointDialogHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Object> getPoints() {
|
|
||||||
final List<Object> points;
|
|
||||||
if (flat) {
|
|
||||||
points = new ArrayList<Object>(waypointHelper.getAllPoints());
|
|
||||||
} else {
|
|
||||||
points = getStandardPoints();
|
|
||||||
}
|
|
||||||
return points;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Object> getTargetPoints() {
|
public List<Object> getTargetPoints() {
|
||||||
final List<Object> points = new ArrayList<>();
|
final List<Object> points = new ArrayList<>();
|
||||||
for (int i = 0; i < WaypointHelper.MAX; i++) {
|
for (int i = 0; i < WaypointHelper.MAX; i++) {
|
||||||
|
@ -273,123 +231,6 @@ public class WaypointDialogHelper {
|
||||||
return activePoints;
|
return activePoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static View updateWaypointItemView(final boolean edit, final List<LocationPointWrapper> deletedPoints,
|
|
||||||
final OsmandApplication app, final Activity ctx,
|
|
||||||
final WaypointDialogHelper helper, View v,
|
|
||||||
final LocationPointWrapper point,
|
|
||||||
final ArrayAdapter adapter, final boolean nightMode,
|
|
||||||
final boolean flat) {
|
|
||||||
if (v == null || v.findViewById(R.id.info_close) == null) {
|
|
||||||
v = ctx.getLayoutInflater().inflate(R.layout.waypoint_reached, null);
|
|
||||||
}
|
|
||||||
updatePointInfoView(app, ctx, v, point, true, nightMode, edit, false);
|
|
||||||
|
|
||||||
v.findViewById(R.id.all_points).setVisibility(View.GONE);
|
|
||||||
final ImageView move = (ImageView) v.findViewById(R.id.info_move);
|
|
||||||
final ImageButton remove = (ImageButton) v.findViewById(R.id.info_close);
|
|
||||||
|
|
||||||
if (!edit) {
|
|
||||||
remove.setVisibility(View.GONE);
|
|
||||||
move.setVisibility(View.GONE);
|
|
||||||
} else {
|
|
||||||
boolean targets = point.type == WaypointHelper.TARGETS;
|
|
||||||
boolean notFlatTargets = targets && !flat;
|
|
||||||
boolean startPoint = notFlatTargets && ((TargetPoint) point.point).start;
|
|
||||||
final TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper();
|
|
||||||
boolean canRemove = !targets || !targetPointsHelper.getIntermediatePoints().isEmpty();
|
|
||||||
int iconResId = nightMode ? R.color.marker_circle_button_color_dark : R.color.ctx_menu_title_color_dark;
|
|
||||||
|
|
||||||
remove.setVisibility(View.VISIBLE);
|
|
||||||
remove.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_remove_dark, iconResId));
|
|
||||||
remove.setEnabled(canRemove);
|
|
||||||
remove.setAlpha(canRemove ? 1 : .5f);
|
|
||||||
if (canRemove) {
|
|
||||||
if (notFlatTargets && startPoint) {
|
|
||||||
remove.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
if (targetPointsHelper.getPointToStart() == null) {
|
|
||||||
if (!targetPointsHelper.getIntermediatePoints().isEmpty()) {
|
|
||||||
replaceStartWithFirstIntermediate(targetPointsHelper, ctx, helper);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
targetPointsHelper.setStartPoint(null, true, null);
|
|
||||||
updateControls(ctx, helper);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
remove.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
deletePoint(app, ctx, adapter, helper, point, deletedPoints, true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
move.setVisibility(notFlatTargets ? View.VISIBLE : View.GONE);
|
|
||||||
if (notFlatTargets) {
|
|
||||||
move.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_reorder, iconResId));
|
|
||||||
move.setTag(new DragIcon() {
|
|
||||||
@Override
|
|
||||||
public void onClick() {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void updateRouteInfoMenu(Activity ctx) {
|
private static void updateRouteInfoMenu(Activity ctx) {
|
||||||
if (ctx instanceof MapActivity) {
|
if (ctx instanceof MapActivity) {
|
||||||
((MapActivity) ctx).getMapLayers().getMapControlsLayer().getMapRouteInfoMenu().updateMenu();
|
((MapActivity) ctx).getMapLayers().getMapControlsLayer().getMapRouteInfoMenu().updateMenu();
|
||||||
|
@ -440,21 +281,6 @@ public class WaypointDialogHelper {
|
||||||
updateControls(ctx, helper);
|
updateControls(ctx, helper);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void deletePoint(final OsmandApplication app, Activity ctx,
|
public static void deletePoint(final OsmandApplication app, Activity ctx,
|
||||||
final ArrayAdapter adapter,
|
final ArrayAdapter adapter,
|
||||||
final WaypointDialogHelper helper,
|
final WaypointDialogHelper helper,
|
||||||
|
@ -491,342 +317,6 @@ public class WaypointDialogHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected View createItemForRadiusProximity(final FragmentActivity ctx, final int type, final int[] running,
|
|
||||||
final int position, final ArrayAdapter<Object> thisAdapter, boolean nightMode) {
|
|
||||||
View v;
|
|
||||||
if (type == WaypointHelper.POI) {
|
|
||||||
v = ctx.getLayoutInflater().inflate(R.layout.drawer_list_radius_ex, null);
|
|
||||||
AndroidUtils.setTextPrimaryColor(mapActivity, (TextView) v.findViewById(R.id.titleEx), nightMode);
|
|
||||||
String descEx = app.getPoiFilters().isShowingAnyPoi() ? ctx.getString(R.string.poi) : app.getPoiFilters().getSelectedPoiFiltersName();
|
|
||||||
((TextView) v.findViewById(R.id.title)).setText(ctx.getString(R.string.search_radius_proximity) + ":");
|
|
||||||
((TextView) v.findViewById(R.id.titleEx)).setText(ctx.getString(R.string.shared_string_type) + ":");
|
|
||||||
final TextView radiusEx = (TextView) v.findViewById(R.id.descriptionEx);
|
|
||||||
radiusEx.setText(descEx);
|
|
||||||
v.findViewById(R.id.secondCellContainer).setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View view) {
|
|
||||||
running[0] = position;
|
|
||||||
thisAdapter.notifyDataSetInvalidated();
|
|
||||||
MapActivity map = (MapActivity) ctx;
|
|
||||||
map.getMapLayers().showSingleChoicePoiFilterDialog(map.getMapView(),
|
|
||||||
new MapActivityLayers.DismissListener() {
|
|
||||||
@Override
|
|
||||||
public void dismiss() {
|
|
||||||
enableType(running, thisAdapter, type, true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
AndroidUtils.setTextPrimaryColor(mapActivity, (TextView) v.findViewById(R.id.title), nightMode);
|
|
||||||
final TextView radius = (TextView) v.findViewById(R.id.description);
|
|
||||||
radius.setText(OsmAndFormatter.getFormattedDistance(waypointHelper.getSearchDeviationRadius(type), app));
|
|
||||||
v.findViewById(R.id.firstCellContainer).setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View view) {
|
|
||||||
selectDifferentRadius(type, running, position, thisAdapter, mapActivity);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
v = ctx.getLayoutInflater().inflate(R.layout.drawer_list_radius, null);
|
|
||||||
((TextView) v.findViewById(R.id.title)).setText(ctx.getString(R.string.search_radius_proximity));
|
|
||||||
AndroidUtils.setTextPrimaryColor(mapActivity, (TextView) v.findViewById(R.id.title), nightMode);
|
|
||||||
final TextView radius = (TextView) v.findViewById(R.id.description);
|
|
||||||
radius.setText(OsmAndFormatter.getFormattedDistance(waypointHelper.getSearchDeviationRadius(type), app));
|
|
||||||
radius.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View view) {
|
|
||||||
selectDifferentRadius(type, running, position, thisAdapter, mapActivity);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void selectPoi(final int[] running, final ArrayAdapter<Object> listAdapter, final int type,
|
|
||||||
final boolean enable, Activity ctx) {
|
|
||||||
if (ctx instanceof MapActivity &&
|
|
||||||
!app.getPoiFilters().isPoiFilterSelected(PoiUIFilter.CUSTOM_FILTER_ID)) {
|
|
||||||
MapActivity map = (MapActivity) ctx;
|
|
||||||
map.getMapLayers().showSingleChoicePoiFilterDialog(map.getMapView(),
|
|
||||||
new MapActivityLayers.DismissListener() {
|
|
||||||
@Override
|
|
||||||
public void dismiss() {
|
|
||||||
if (app.getPoiFilters().isShowingAnyPoi()) {
|
|
||||||
enableType(running, listAdapter, type, enable);
|
|
||||||
} else {
|
|
||||||
running[0] = -1;
|
|
||||||
if (!helperCallbacks.isEmpty()) {
|
|
||||||
for (WaypointDialogHelperCallbacks callback : helperCallbacks) {
|
|
||||||
callback.reloadAdapter();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
reloadListAdapter(listAdapter);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
enableType(running, listAdapter, type, enable);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void enableType(final int[] running, final ArrayAdapter<Object> listAdapter, final int type,
|
|
||||||
final boolean enable) {
|
|
||||||
new AsyncTask<Void, Void, Void>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Void doInBackground(Void... params) {
|
|
||||||
app.getWaypointHelper().enableWaypointType(type, enable);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void onPostExecute(Void result) {
|
|
||||||
running[0] = -1;
|
|
||||||
if (!helperCallbacks.isEmpty()) {
|
|
||||||
for (WaypointDialogHelperCallbacks callback : helperCallbacks) {
|
|
||||||
callback.reloadAdapter();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
reloadListAdapter(listAdapter);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void selectDifferentRadius(final int type, final int[] running, final int position,
|
|
||||||
final ArrayAdapter<Object> thisAdapter, Activity ctx) {
|
|
||||||
int length = WaypointHelper.SEARCH_RADIUS_VALUES.length;
|
|
||||||
String[] names = new String[length];
|
|
||||||
int selected = 0;
|
|
||||||
for (int i = 0; i < length; i++) {
|
|
||||||
names[i] = OsmAndFormatter.getFormattedDistance(WaypointHelper.SEARCH_RADIUS_VALUES[i], app);
|
|
||||||
if (WaypointHelper.SEARCH_RADIUS_VALUES[i] == waypointHelper.getSearchDeviationRadius(type)) {
|
|
||||||
selected = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
new AlertDialog.Builder(ctx)
|
|
||||||
.setSingleChoiceItems(names, selected, new OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialogInterface, int i) {
|
|
||||||
int value = WaypointHelper.SEARCH_RADIUS_VALUES[i];
|
|
||||||
if (waypointHelper.getSearchDeviationRadius(type) != value) {
|
|
||||||
running[0] = position;
|
|
||||||
waypointHelper.setSearchDeviationRadius(type, value);
|
|
||||||
recalculatePoints(running, thisAdapter, type);
|
|
||||||
dialogInterface.dismiss();
|
|
||||||
thisAdapter.notifyDataSetInvalidated();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}).setTitle(app.getString(R.string.search_radius_proximity))
|
|
||||||
.setNegativeButton(R.string.shared_string_cancel, null)
|
|
||||||
.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void recalculatePoints(final int[] running, final ArrayAdapter<Object> listAdapter, final int type) {
|
|
||||||
new AsyncTask<Void, Void, Void>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Void doInBackground(Void... params) {
|
|
||||||
app.getWaypointHelper().recalculatePoints(type);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void onPostExecute(Void result) {
|
|
||||||
running[0] = -1;
|
|
||||||
if (!helperCallbacks.isEmpty()) {
|
|
||||||
for (WaypointDialogHelperCallbacks callback : helperCallbacks) {
|
|
||||||
callback.reloadAdapter();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
reloadListAdapter(listAdapter);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void reloadListAdapter(ArrayAdapter<Object> listAdapter) {
|
|
||||||
mapActivity.getMyApplication().getWaypointHelper().removeVisibleLocationPoint(deletedPoints);
|
|
||||||
|
|
||||||
listAdapter.setNotifyOnChange(false);
|
|
||||||
listAdapter.clear();
|
|
||||||
List<Object> points = getPoints();
|
|
||||||
for (Object point : points) {
|
|
||||||
listAdapter.add(point);
|
|
||||||
}
|
|
||||||
if (listAdapter instanceof StableArrayAdapter) {
|
|
||||||
((StableArrayAdapter) listAdapter).updateObjects(points, getActivePoints(points));
|
|
||||||
}
|
|
||||||
listAdapter.notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getHeader(int type, boolean checked, Activity ctx) {
|
|
||||||
String str = ctx.getString(R.string.shared_string_waypoints);
|
|
||||||
switch (type) {
|
|
||||||
case WaypointHelper.TARGETS:
|
|
||||||
str = ctx.getString(R.string.shared_string_target_points);
|
|
||||||
break;
|
|
||||||
case WaypointHelper.ALARMS:
|
|
||||||
str = ctx.getString(R.string.way_alarms);
|
|
||||||
break;
|
|
||||||
case WaypointHelper.FAVORITES:
|
|
||||||
str = ctx.getString(R.string.shared_string_my_favorites);
|
|
||||||
break;
|
|
||||||
case WaypointHelper.WAYPOINTS:
|
|
||||||
str = ctx.getString(R.string.shared_string_waypoints);
|
|
||||||
break;
|
|
||||||
case WaypointHelper.POI:
|
|
||||||
str = ctx.getString(R.string.poi);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void showOnMap(OsmandApplication app, Activity a, LocationPoint locationPoint, boolean center) {
|
public static void showOnMap(OsmandApplication app, Activity a, LocationPoint locationPoint, boolean center) {
|
||||||
if (!(a instanceof MapActivity)) {
|
if (!(a instanceof MapActivity)) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -378,7 +378,6 @@ public class WaypointsFragment extends BaseOsmAndFragment implements ObservableS
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onWindowVisibilityChanged(int visibility) {
|
public void onWindowVisibilityChanged(int visibility) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -386,11 +385,6 @@ public class WaypointsFragment extends BaseOsmAndFragment implements ObservableS
|
||||||
deleteSwipeItem(position);
|
deleteSwipeItem(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void exchangeWaypoints(int pos1, int pos2) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public void onItemsSwapped(final List<Object> items) {
|
public void onItemsSwapped(final List<Object> items) {
|
||||||
|
|
Loading…
Reference in a new issue