diff --git a/OsmAnd/res/layout/waypoint_reached.xml b/OsmAnd/res/layout/waypoint_reached.xml index 50a4772d9e..cb7b9df929 100644 --- a/OsmAnd/res/layout/waypoint_reached.xml +++ b/OsmAnd/res/layout/waypoint_reached.xml @@ -99,7 +99,6 @@ android:clickable="false" android:scaleType="center" android:src="@drawable/ic_flat_list_dark" - android:tag="DragIcon" android:visibility="gone"/> \ No newline at end of file diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 91f80b908c..b2b735f893 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,7 @@ 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> + Switch start & finish Item deleted items deleted UNDO ALL diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index fb7dd9f67f..9c19de02c2 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -86,7 +86,7 @@ public class MapActivityActions implements DialogProvider { routingHelper = mapActivity.getMyApplication().getRoutingHelper(); } - + /* public void addAsWaypoint(double latitude, double longitude, PointDescription pd) { TargetPointsHelper targets = getMyApplication().getTargetPointsHelper(); boolean destination = (targets.getPointToNavigate() == null); @@ -97,7 +97,8 @@ public class MapActivityActions implements DialogProvider { openIntermediateEditPointsDialog(); } - + */ + public void addAsTarget(double latitude, double longitude, PointDescription pd) { TargetPointsHelper targets = getMyApplication().getTargetPointsHelper(); targets.navigateToPoint(new LatLon(latitude, longitude), true, targets.getIntermediatePoints().size() + 1, @@ -736,9 +737,11 @@ public class MapActivityActions implements DialogProvider { mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.WAYPOINTS); } + /* public void openIntermediateEditPointsDialog() { mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.WAYPOINTS_EDIT); } + */ public void openRoutePreferencesDialog() { mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.ROUTE_PREFERENCES); @@ -758,6 +761,7 @@ public class MapActivityActions implements DialogProvider { settings.LAST_ROUTING_APPLICATION_MODE = settings.APPLICATION_MODE.get(); settings.APPLICATION_MODE.set(settings.DEFAULT_APPLICATION_MODE.get()); mapActivity.updateApplicationModeSettings(); + mapActivity.getDashboard().clearDeletedPoints(); } public AlertDialog stopNavigationActionConfirm() { diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashWaypointsFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashWaypointsFragment.java index 0d5a723f89..edace008cf 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashWaypointsFragment.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashWaypointsFragment.java @@ -96,7 +96,7 @@ public class DashWaypointsFragment extends DashLocationFragment { View dv = getActivity().getLayoutInflater().inflate(R.layout.divider, null); favorites.addView(dv); View v = WaypointDialogHelper.updateWaypointItemView(false, null, getMyApplication(), - getActivity(), null, ps, null, !getMyApplication().getSettings().isLightContent(), true); + getActivity(), null, null, ps, null, !getMyApplication().getSettings().isLightContent(), true); favorites.addView(v); } diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java b/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java index 364efa4192..c1f3373e18 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java @@ -54,6 +54,7 @@ import net.osmand.plus.dialogs.ConfigureMapMenu; import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.WaypointDialogHelper; +import net.osmand.plus.helpers.WaypointDialogHelper.PointDeleteCallback; import net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper; import net.osmand.plus.mapcontextmenu.other.RoutePreferencesMenu; import net.osmand.plus.mapcontextmenu.other.RoutePreferencesMenu.LocalRoutingParameter; @@ -79,7 +80,8 @@ import static android.util.TypedValue.COMPLEX_UNIT_DIP; /** */ -public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicListViewCallbacks, IRouteInformationListener { +public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicListViewCallbacks, + IRouteInformationListener, PointDeleteCallback { private static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(DashboardOnMap.class); private static final String TAG = "DashboardOnMap"; @@ -149,7 +151,6 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis public enum DashboardType { WAYPOINTS, WAYPOINTS_FLAT, - WAYPOINTS_EDIT, CONFIGURE_SCREEN, CONFIGURE_MAP, LIST_MENU, @@ -178,6 +179,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis public void createDashboardView() { baseColor = mapActivity.getResources().getColor(R.color.osmand_orange) & 0x00ffffff; waypointDialogHelper = new WaypointDialogHelper(mapActivity); + waypointDialogHelper.setPointDeleteCallback(this); landscape = !AndroidUiHelper.isOrientationPortrait(mapActivity); dashboardView = (FrameLayout) mapActivity.findViewById(R.id.dashboard); final View.OnClickListener listener = new View.OnClickListener() { @@ -202,7 +204,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis @Override public boolean canDismiss(int position) { boolean res = false; - if (listAdapter instanceof StableArrayAdapter) { + if (visibleType == DashboardType.WAYPOINTS && listAdapter instanceof StableArrayAdapter) { List activeObjects = ((StableArrayAdapter) listAdapter).getActiveObjects(); Object obj = listAdapter.getItem(position); res = activeObjects.contains(obj); @@ -232,7 +234,6 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis stableAdapter = null; activeObjPos = 0; } - return new Undoable() { @Override public void undo() { @@ -242,7 +243,6 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis stableAdapter.getObjects().add(position, item); stableAdapter.getActiveObjects().add(activeObjPos, item); stableAdapter.refreshData(); - onItemsSwapped(stableAdapter.getActiveObjects()); } } @@ -380,7 +380,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis // // @Override // public void onClick(View v) { - mapActivity.getMyApplication().getWaypointHelper().removeVisibleLocationPoint(deletedPoints); +// mapActivity.getMyApplication().getWaypointHelper().removeVisibleLocationPoint(deletedPoints); // hideDashboard(); // } // }); @@ -473,7 +473,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis button = actionButtons.get(DashboardActionButtonType.MY_LOCATION); } else if (type == DashboardType.ROUTE_PREFERENCES) { button = actionButtons.get(DashboardActionButtonType.NAVIGATE); - } else if (type == DashboardType.WAYPOINTS || type == DashboardType.WAYPOINTS_EDIT || type == DashboardType.WAYPOINTS_FLAT) { + } else if (type == DashboardType.WAYPOINTS || type == DashboardType.WAYPOINTS_FLAT) { boolean routePlanningMode = false; RoutingHelper rh = mapActivity.getRoutingHelper(); if (rh.isRoutePlanningMode()) { @@ -679,13 +679,6 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis dynamicListView.setActiveItemsList(listAdapter.getActiveObjects()); updateListAdapter(listAdapter, listener); - } else if (DashboardType.WAYPOINTS_EDIT == visibleType) { - deletedPoints.clear(); - ArrayAdapter listAdapter = waypointDialogHelper.getWaypointsDrawerAdapter(true, deletedPoints, mapActivity, running, - DashboardType.WAYPOINTS_FLAT == visibleType, nightMode); - OnItemClickListener listener = waypointDialogHelper.getDrawerItemClickListener(mapActivity, running, - listAdapter); - updateListAdapter(listAdapter, listener); } else { if (DashboardType.CONFIGURE_SCREEN == visibleType) { @@ -718,8 +711,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis } public void refreshContent(boolean force) { - if (visibleType == DashboardType.WAYPOINTS || visibleType == DashboardType.WAYPOINTS_EDIT - || force) { + if (visibleType == DashboardType.WAYPOINTS || force) { updateListAdapter(); } else if (visibleType == DashboardType.CONFIGURE_MAP || visibleType == DashboardType.ROUTE_PREFERENCES) { int index = listView.getFirstVisiblePosition(); @@ -981,7 +973,6 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis private boolean isActionButtonVisible() { return visibleType == DashboardType.DASHBOARD || visibleType == DashboardType.WAYPOINTS - || visibleType == DashboardType.WAYPOINTS_EDIT || visibleType == DashboardType.WAYPOINTS_FLAT || visibleType == DashboardType.LIST_MENU || visibleType == DashboardType.ROUTE_PREFERENCES @@ -1132,6 +1123,10 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis transaction.show(frag).commit(); } + public void clearDeletedPoints() { + deletedPoints.clear(); + } + View getParentView() { return dashboardView; } @@ -1167,7 +1162,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis getMyApplication().runInUIThread(new Runnable() { @Override public void run() { - if (visibleType == DashboardType.WAYPOINTS) { + if (visibleType == DashboardType.WAYPOINTS || visibleType == DashboardType.WAYPOINTS_FLAT) { List allTargets = new ArrayList<>(); if (items != null) { for (Object obj : items) { @@ -1203,6 +1198,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis if ((DashboardType.WAYPOINTS == visibleType || DashboardType.WAYPOINTS_FLAT == visibleType) && listAdapter != null && listAdapter instanceof StableArrayAdapter) { StableArrayAdapter stableAdapter = (StableArrayAdapter) listAdapter; + getMyApplication().getWaypointHelper().removeVisibleLocationPoint(deletedPoints); waypointDialogHelper.reloadListAdapter(stableAdapter); if (listView instanceof DynamicListView) { DynamicListView dynamicListView = (DynamicListView) listView; @@ -1223,4 +1219,11 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis swipeDismissListener.discardUndo(); } } + + @Override + public void deleteWaypoint(int position) { + if (swipeDismissListener != null) { + swipeDismissListener.delete(position); + } + } } diff --git a/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java b/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java index fce524441e..f526b0ed6b 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java @@ -5,13 +5,14 @@ import android.content.Context; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.content.DialogInterface.OnDismissListener; -import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.ShapeDrawable; import android.graphics.drawable.shapes.Shape; import android.os.AsyncTask; import android.support.v4.app.FragmentActivity; import android.support.v7.app.AlertDialog; +import android.support.v7.widget.PopupMenu; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; @@ -31,10 +32,11 @@ import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.TargetPointsHelper.TargetPoint; -import net.osmand.plus.activities.IntermediatePointsDialog; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.dialogs.DirectionsDialogs; import net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper; 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.util.Algorithms; @@ -49,7 +51,12 @@ public class WaypointDialogHelper { private MapActivity mapActivity; private OsmandApplication app; private WaypointHelper waypointHelper; + private PointDeleteCallback dCallback; + private boolean flat; + public interface PointDeleteCallback { + void deleteWaypoint(int position); + } private static class RadiusItem { int type; @@ -59,6 +66,10 @@ public class WaypointDialogHelper { } } + public void setPointDeleteCallback(PointDeleteCallback callback) { + this.dCallback = callback; + } + public WaypointDialogHelper(MapActivity mapActivity) { this.app = mapActivity.getMyApplication(); waypointHelper = this.app.getWaypointHelper(); @@ -154,6 +165,16 @@ public class WaypointDialogHelper { // 0); } + private List getPoints() { + final List points; + if (flat) { + points = new ArrayList(waypointHelper.getAllPoints()); + } else { + points = getStandardPoints(); + } + return points; + } + private List getActivePoints(List points) { List activePoints = new ArrayList<>(); for (Object p : points) { @@ -250,14 +271,13 @@ public class WaypointDialogHelper { final boolean edit, final List deletedPoints, final MapActivity ctx, final int[] running, final boolean flat, final boolean nightMode) { - final List points; - if (flat) { - points = new ArrayList(waypointHelper.getAllPoints()); - } else { - points = getPoints(); - } + this.flat = flat; + + final List points = getPoints(); List activePoints = getActivePoints(points); + final WaypointDialogHelper helper = this; + return new StableArrayAdapter(ctx, R.layout.waypoint_reached, R.id.title, points, activePoints) { @@ -306,7 +326,7 @@ public class WaypointDialogHelper { v = ctx.getLayoutInflater().inflate(R.layout.card_bottom_divider, null); } else if (obj instanceof LocationPointWrapper) { LocationPointWrapper point = (LocationPointWrapper) obj; - v = updateWaypointItemView(edit, deletedPoints, app, ctx, v, point, this, + v = updateWaypointItemView(edit, deletedPoints, app, ctx, helper, v, point, this, nightMode, flat); AndroidUtils.setListItemBackground(mapActivity, v, nightMode); } @@ -317,7 +337,8 @@ public class WaypointDialogHelper { public static View updateWaypointItemView(final boolean edit, final List deletedPoints, - final OsmandApplication app, final Activity ctx, View v, + final OsmandApplication app, final Activity ctx, + final WaypointDialogHelper helper, View v, final LocationPointWrapper point, final ArrayAdapter adapter, final boolean nightMode, final boolean flat) { @@ -325,9 +346,9 @@ public class WaypointDialogHelper { v = ctx.getLayoutInflater().inflate(R.layout.waypoint_reached, null); } updatePointInfoView(app, ctx, v, point, true, nightMode, edit); - View more = v.findViewById(R.id.all_points); - View move = v.findViewById(R.id.info_move); - View remove = v.findViewById(R.id.info_close); + final View more = v.findViewById(R.id.all_points); + final View move = v.findViewById(R.id.info_move); + final View remove = v.findViewById(R.id.info_close); if (!edit) { remove.setVisibility(View.GONE); move.setVisibility(View.GONE); @@ -342,8 +363,31 @@ public class WaypointDialogHelper { more.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - //hideDashboard(); - IntermediatePointsDialog.openIntermediatePointsDialog(ctx, app, true); + final PopupMenu optionsMenu = new PopupMenu(ctx, more); + DirectionsDialogs.setupPopUpMenuIcon(optionsMenu); + MenuItem item; + item = optionsMenu.getMenu().add( + R.string.intermediate_items_sort_by_distance).setIcon(app.getIconsCache(). + getContentIcon(R.drawable.ic_sort_waypoint_dark)); + item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem item) { + // sort + //IntermediatePointsDialog.openIntermediatePointsDialog(ctx, app, true); + return true; + } + }); + item = optionsMenu.getMenu().add( + R.string.switch_start_finish).setIcon(app.getIconsCache(). + getContentIcon(R.drawable.ic_action_undo_dark)); + item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem item) { + // switch start & finish + return true; + } + }); + optionsMenu.show(); } }); } else { @@ -352,6 +396,25 @@ public class WaypointDialogHelper { more.setVisibility(View.GONE); ((ImageView) move).setImageDrawable(app.getIconsCache().getContentIcon( R.drawable.ic_flat_list_dark, !nightMode)); + move.setTag(new DragIcon() { + @Override + public void onClick() { + final PopupMenu optionsMenu = new PopupMenu(ctx, move); + DirectionsDialogs.setupPopUpMenuIcon(optionsMenu); + MenuItem item; + item = optionsMenu.getMenu().add( + R.string.shared_string_delete).setIcon(app.getIconsCache(). + getContentIcon(R.drawable.ic_action_remove_dark)); + item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem item) { + deletePoint(app, adapter, helper, point, deletedPoints, true); + return true; + } + }); + optionsMenu.show(); + } + }); } } else { remove.setVisibility(View.VISIBLE); @@ -362,22 +425,40 @@ public class WaypointDialogHelper { remove.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - ArrayList arr = new ArrayList<>(); - arr.add(point); - app.getWaypointHelper().removeVisibleLocationPoint(arr); - - deletedPoints.add(point); - if (adapter != null) { - adapter.setNotifyOnChange(false); - adapter.remove(point); - adapter.notifyDataSetChanged(); - } + deletePoint(app, adapter, helper, point, deletedPoints, true); } }); } return v; } + public static void deletePoint(final OsmandApplication app, final ArrayAdapter adapter, + final WaypointDialogHelper helper, + final Object item, + final List deletedPoints, + final boolean needCallback) { + + if (item instanceof LocationPointWrapper && adapter != null) { + LocationPointWrapper point = (LocationPointWrapper) item; + if (point.type == WaypointHelper.TARGETS && adapter instanceof StableArrayAdapter) { + StableArrayAdapter stableAdapter = (StableArrayAdapter) adapter; + if (helper != null && helper.dCallback != null && needCallback) { + helper.dCallback.deleteWaypoint(stableAdapter.getPosition(item)); + } + } else { + ArrayList arr = new ArrayList<>(); + arr.add(point); + app.getWaypointHelper().removeVisibleLocationPoint(arr); + + deletedPoints.add(point); + + adapter.setNotifyOnChange(false); + adapter.remove(point); + adapter.notifyDataSetChanged(); + } + } + } + protected View createItemForRadiusProximity(final FragmentActivity ctx, final int type, final int[] running, final int position, final ArrayAdapter thisAdapter, boolean nightMode) { @@ -603,8 +684,8 @@ public class WaypointDialogHelper { return str; } - protected List getPoints() { - final List points = new ArrayList(); + protected List getStandardPoints() { + final List points = new ArrayList<>(); boolean rc = waypointHelper.isRouteCalculated(); for (int i = 0; i < WaypointHelper.MAX; i++) { List tp = waypointHelper.getWaypoints(i); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java index a6163d1003..dbe811f5e5 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java @@ -12,7 +12,6 @@ import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.util.TypedValue; import android.view.GestureDetector; -import android.view.GestureDetector.OnGestureListener; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.VelocityTracker; @@ -45,6 +44,7 @@ import net.osmand.plus.mapcontextmenu.MenuController.TitleButtonController; import net.osmand.plus.mapcontextmenu.MenuController.TitleProgressController; import net.osmand.plus.views.AnimateDraggingMapThread; import net.osmand.plus.views.OsmandMapTileView; +import net.osmand.plus.views.controls.SingleTapConfirm; import net.osmand.util.Algorithms; import static android.util.TypedValue.COMPLEX_UNIT_DIP; @@ -98,41 +98,6 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents { private int screenOrientation; - private class SingleTapConfirm implements OnGestureListener { - - @Override - public boolean onDown(MotionEvent e) { - return false; - } - - @Override - public void onShowPress(MotionEvent e) { - - } - - @Override - public boolean onSingleTapUp(MotionEvent e) { - return true; - } - - @Override - public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { - return false; - } - - @Override - public void onLongPress(MotionEvent e) { - - } - - @Override - public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { - return false; - } - - - } - @TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, diff --git a/OsmAnd/src/net/osmand/plus/views/controls/DynamicListView.java b/OsmAnd/src/net/osmand/plus/views/controls/DynamicListView.java index 2c7f6efe07..741bdce1d2 100644 --- a/OsmAnd/src/net/osmand/plus/views/controls/DynamicListView.java +++ b/OsmAnd/src/net/osmand/plus/views/controls/DynamicListView.java @@ -32,6 +32,8 @@ import android.support.annotation.NonNull; import android.support.v4.view.ViewCompat; import android.util.AttributeSet; import android.util.DisplayMetrics; +import android.util.Log; +import android.view.GestureDetector; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; @@ -46,7 +48,6 @@ import java.util.List; public class DynamicListView extends ObservableListView { - public final String TAG_DRAG_ICON = "DragIcon"; protected final int SMOOTH_SCROLL_AMOUNT_AT_EDGE = 15; protected final int MOVE_DURATION = 150; @@ -82,6 +83,13 @@ public class DynamicListView extends ObservableListView { private boolean mIsWaitingForScrollFinish = false; private int mScrollState = OnScrollListener.SCROLL_STATE_IDLE; + private GestureDetector singleTapDetector; + private DragIcon tag; + + public interface DragIcon { + void onClick(); + } + public DynamicListView(Context context) { super(context); init(context); @@ -101,6 +109,7 @@ public class DynamicListView extends ObservableListView { setOnScrollListener(mScrollListener); DisplayMetrics metrics = context.getResources().getDisplayMetrics(); mSmoothScrollAmountAtEdge = (int) (SMOOTH_SCROLL_AMOUNT_AT_EDGE / metrics.density); + singleTapDetector = new GestureDetector(context, new SingleTapConfirm()); } public void setDynamicListViewCallbacks(DynamicListViewCallbacks callbacks) { @@ -249,7 +258,7 @@ public class DynamicListView extends ObservableListView { // Draw dividers StableArrayAdapter stableAdapter = getStableAdapter(); - if (stableAdapter != null && stableAdapter.hasDividers()) { + if (getDivider() == null && stableAdapter != null && stableAdapter.hasDividers()) { List dividers = stableAdapter.getDividers(); final int count = getChildCount(); @@ -296,20 +305,28 @@ public class DynamicListView extends ObservableListView { @Override public boolean onTouchEvent(@NonNull MotionEvent event) { + if (singleTapDetector.onTouchEvent(event)) { + if (tag != null) { + tag.onClick(); + } + touchEventsCancelled(); + return true; + } + switch (event.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: if (!mCellIsMobile && mHoverCell == null) { - mDownX = (int) event.getX(); - mDownY = (int) event.getY(); - mActivePointerId = event.getPointerId(0); - // Find the view that the user pressed their finger down on. - View v = findViewAtPositionWithTag(getRootView(), (int) event.getRawX(), (int) event.getRawY(), TAG_DRAG_ICON); + View v = findViewAtPositionWithDragIconTag(getRootView(), (int) event.getRawX(), (int) event.getRawY()); - // If the view contains a tag set to "DragIcon", it means that the user wants to + // If the view contains a tag set to "DragIcon" class, it means that the user wants to // reorder the list item. - if ((v != null) && (v.getTag() != null) && (v.getTag().equals(TAG_DRAG_ICON))) { + if ((v != null) && (v.getTag() != null) && (v.getTag() instanceof DragIcon)) { + mDownX = (int) event.getX(); + mDownY = (int) event.getY(); + mActivePointerId = event.getPointerId(0); mTotalOffset = 0; + tag = (DragIcon) v.getTag(); int position = pointToPosition(mDownX, mDownY); if (position != INVALID_POSITION) { @@ -564,6 +581,7 @@ public class DynamicListView extends ObservableListView { mBelowItemId = INVALID_ID; setAllVisible(); mHoverCell = null; + tag = null; setEnabled(true); invalidate(); processSwapped(); @@ -718,7 +736,7 @@ public class DynamicListView extends ObservableListView { * @param y The Y location to be tested. * @return Returns the most inner view that contains the XY coordinate or null if no view could be found. */ - private View findViewAtPositionWithTag(View v, int x, int y, String tag) { + private View findViewAtPositionWithDragIconTag(View v, int x, int y) { View vXY = null; if (v instanceof ViewGroup) { @@ -732,9 +750,9 @@ public class DynamicListView extends ObservableListView { if ((x >= loc[0] && (x <= (loc[0] + c.getWidth()))) && (y >= loc[1] && (y <= (loc[1] + c.getHeight())))) { vXY = c; - View viewAtPosition = findViewAtPositionWithTag(c, x, y, tag); + View viewAtPosition = findViewAtPositionWithDragIconTag(c, x, y); - if ((viewAtPosition != null) && (viewAtPosition.getTag() != null) && viewAtPosition.getTag().equals(tag)) { + if ((viewAtPosition != null) && (viewAtPosition.getTag() != null) && viewAtPosition.getTag() instanceof DragIcon) { vXY = viewAtPosition; break; } diff --git a/OsmAnd/src/net/osmand/plus/views/controls/SingleTapConfirm.java b/OsmAnd/src/net/osmand/plus/views/controls/SingleTapConfirm.java new file mode 100644 index 0000000000..bbda5f2a72 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/views/controls/SingleTapConfirm.java @@ -0,0 +1,37 @@ +package net.osmand.plus.views.controls; + +import android.view.GestureDetector; +import android.view.MotionEvent; + +public class SingleTapConfirm implements GestureDetector.OnGestureListener { + + @Override + public boolean onDown(MotionEvent e) { + return false; + } + + @Override + public void onShowPress(MotionEvent e) { + + } + + @Override + public boolean onSingleTapUp(MotionEvent e) { + return true; + } + + @Override + public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { + return false; + } + + @Override + public void onLongPress(MotionEvent e) { + + } + + @Override + public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { + return false; + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/views/controls/SwipeDismissListViewTouchListener.java b/OsmAnd/src/net/osmand/plus/views/controls/SwipeDismissListViewTouchListener.java index 8aa5c84d42..c4b65ab3be 100644 --- a/OsmAnd/src/net/osmand/plus/views/controls/SwipeDismissListViewTouchListener.java +++ b/OsmAnd/src/net/osmand/plus/views/controls/SwipeDismissListViewTouchListener.java @@ -472,20 +472,18 @@ public class SwipeDismissListViewTouchListener implements View.OnTouchListener { * Delete the list item at the specified position. This will animate the item sliding out of the * list and then collapsing until it vanished (same as if the user slides out an item). *

- * NOTE: If you are using list headers, be aware, that the position argument must take care of - * them. Meaning 0 references the first list header. So if you want to delete the first list - * item, you have to pass the number of list headers as {@code position}. Most of the times - * that shouldn't be a problem, since you most probably will evaluate the position which should - * be deleted in a way, that respects the list headers. */ public void delete(int position) { if (mCallbacks == null) { throw new IllegalStateException("You must set an OnDismissCallback, before deleting items."); } - if (position < 0 || position >= mListView.getCount()) { - throw new IndexOutOfBoundsException(String.format("Tried to delete item %d. #items in list: %d", position, mListView.getCount())); + + int pos = position + mListView.getHeaderViewsCount(); + + if (pos < 0 || pos >= mListView.getCount()) { + throw new IndexOutOfBoundsException(String.format("Tried to delete item %d. #items in list: %d", pos, mListView.getCount())); } - View childView = mListView.getChildAt(position - mListView.getFirstVisiblePosition()); + View childView = mListView.getChildAt(pos - mListView.getFirstVisiblePosition()); View view = null; if (mSwipingLayout > 0) { view = childView.findViewById(mSwipingLayout);