diff --git a/astrid/plugin-src/com/todoroo/astrid/subtasks/SubtasksListFragment.java b/astrid/plugin-src/com/todoroo/astrid/subtasks/SubtasksListFragment.java index 07cda7e5d..3b76b74f3 100644 --- a/astrid/plugin-src/com/todoroo/astrid/subtasks/SubtasksListFragment.java +++ b/astrid/plugin-src/com/todoroo/astrid/subtasks/SubtasksListFragment.java @@ -73,7 +73,8 @@ public class SubtasksListFragment extends TaskListFragment { unregisterForContextMenu(getListView()); } - public Property[] getProperties() { + @Override + public Property[] taskProperties() { ArrayList> properties = new ArrayList>(Arrays.asList(TaskAdapter.PROPERTIES)); properties.add(SubtasksMetadata.INDENT); return properties.toArray(new Property[properties.size()]); @@ -125,13 +126,13 @@ public class SubtasksListFragment extends TaskListFragment { private final GrabberClickListener rowClickListener = new GrabberClickListener() { @Override public void onLongClick(final View v) { - System.err.println(v); + registerForContextMenu(getListView()); getListView().showContextMenuForChild(v); + unregisterForContextMenu(getListView()); } @Override public void onClick(View v) { - System.err.println(v); ((DraggableTaskAdapter) taskAdapter).getListener().onClick(v); } }; @@ -167,7 +168,7 @@ public class SubtasksListFragment extends TaskListFragment { view.getLayoutParams().height = Math.round(45 * metrics.density); ViewHolder vh = (ViewHolder) view.getTag(); int indent = vh.task.getValue(SubtasksMetadata.INDENT); - vh.rowBody.setPadding(Math.round(indent * 10 * metrics.density), 0, 0, 0); + vh.rowBody.setPadding(Math.round(indent * 20 * metrics.density), 0, 0, 0); } @Override diff --git a/astrid/src/com/todoroo/astrid/activity/DraggableTaskListFragment.java b/astrid/src/com/todoroo/astrid/activity/DraggableTaskListFragment.java index 20dc69b25..680e9d385 100644 --- a/astrid/src/com/todoroo/astrid/activity/DraggableTaskListFragment.java +++ b/astrid/src/com/todoroo/astrid/activity/DraggableTaskListFragment.java @@ -66,7 +66,8 @@ public class DraggableTaskListFragment extends TaskListFragment { // --- task adapter - public Property[] getProperties() { + @Override + public Property[] taskProperties() { ArrayList> properties = new ArrayList>(Arrays.asList(TaskAdapter.PROPERTIES)); if(getIndentProperty() != null) properties.add(getIndentProperty()); diff --git a/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java b/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java index 35df389ed..796a28ec1 100644 --- a/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java +++ b/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java @@ -45,6 +45,7 @@ import android.widget.TextView; import com.crittercism.NewFeedbackSpringboardActivity; import com.timsu.astrid.R; +import com.todoroo.andlib.data.Property; import com.todoroo.andlib.data.TodorooCursor; import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.service.ContextManager; @@ -791,7 +792,7 @@ public class TaskListFragment extends ListFragment implements OnScrollListener, // perform query TodorooCursor currentCursor = taskService.fetchFiltered( - sqlQueryTemplate.get(), null, TaskAdapter.PROPERTIES); + sqlQueryTemplate.get(), null, taskProperties()); // set up list adapters taskAdapter = createTaskAdapter(currentCursor); @@ -804,6 +805,10 @@ public class TaskListFragment extends ListFragment implements OnScrollListener, loadTaskListContent(true); } + protected Property[] taskProperties() { + return TaskAdapter.PROPERTIES; + } + public Filter getFilter() { return filter; } @@ -835,7 +840,7 @@ public class TaskListFragment extends ListFragment implements OnScrollListener, "WHERE " + TaskCriteria.byId(withCustomId) + " OR ")); currentCursor = taskService.fetchFiltered(sqlQueryTemplate.get(), null, - TaskAdapter.PROPERTIES); + taskProperties()); getListView().setFilterText(""); taskAdapter.changeCursor(currentCursor); diff --git a/astrid/src/com/todoroo/astrid/ui/DraggableListView.java b/astrid/src/com/todoroo/astrid/ui/DraggableListView.java index 6ac8cb2e4..23f226acc 100644 --- a/astrid/src/com/todoroo/astrid/ui/DraggableListView.java +++ b/astrid/src/com/todoroo/astrid/ui/DraggableListView.java @@ -21,6 +21,7 @@ import android.content.Context; import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.PixelFormat; +import android.graphics.Point; import android.graphics.Rect; import android.os.Vibrator; import android.util.AttributeSet; @@ -43,9 +44,9 @@ import com.timsu.astrid.R; public class DraggableListView extends ListView { - private static final int SWIPE_THRESHOLD = 20; + private static final int SWIPE_THRESHOLD = 40; - private static final int MOVEMENT_THRESHOLD = 10; + private static final int MOVEMENT_THRESHOLD = 30; // --- drag status private float mTouchStartX, mTouchCurrentX, mTouchStartY, mTouchCurrentY; @@ -53,8 +54,8 @@ public class DraggableListView extends ListView { private int mDragPos; // which item is being dragged private int mFirstDragPos; // where was the dragged item originally - private int mDragPoint; // at what offset inside the item did the user grab it - private int mCoordOffset; // the difference between screen coordinates and coordinates in this view + private Point mDragPoint; // at what offset inside the item did the user grab it + private Point mCoordOffset; // the difference between screen coordinates and coordinates in this view // --- drag drawing private ImageView mDragView; @@ -102,7 +103,7 @@ public class DraggableListView extends ListView { a.recycle(); } - setSelector(null); + setSelector(R.drawable.none); } protected boolean isDraggableRow(@SuppressWarnings("unused") View view) { @@ -127,7 +128,7 @@ public class DraggableListView extends ListView { } private int getItemForPosition(int y) { - int adjustedy = y - mDragPoint - (mItemHeightNormal / 2); + int adjustedy = y - mDragPoint.y - (mItemHeightNormal / 2); int pos = myPointToPosition(0, adjustedy); if (pos >= 0) { if (pos <= mFirstDragPos) { @@ -250,8 +251,19 @@ public class DraggableListView extends ListView { if(mDragging) stopDragging(); - else if (dragThread != null && mClickListener != null) - mClickListener.onClick(viewAtPosition()); + else { + if (dragThread != null && mClickListener != null) + mClickListener.onClick(viewAtPosition()); + + else if (mSwipeListener != null && + Math.abs(mTouchCurrentY - mTouchStartY) < MOVEMENT_THRESHOLD) { + int dragPos = pointToPosition((int)mTouchCurrentX, (int)mTouchCurrentY); + if (mTouchCurrentX > mTouchStartX + SWIPE_THRESHOLD) + mSwipeListener.swipeRight(dragPos); + else if (mTouchCurrentX < mTouchStartX - SWIPE_THRESHOLD) + mSwipeListener.swipeLeft(dragPos); + } + } if(dragThread != null) { dragThread.interrupt(); @@ -309,10 +321,8 @@ public class DraggableListView extends ListView { public void run() { try { - System.err.println("<<< commence fire"); Thread.sleep(300L); - System.err.println("<<< initiate drag!"); post(new Runnable() { @Override public void run() { @@ -321,18 +331,17 @@ public class DraggableListView extends ListView { }); Thread.sleep(1000L); - System.err.println("<<< me love you long time!"); post(new Runnable() { public void run() { stopDragging(); + dragThread = null; mClickListener.onLongClick(viewAtPosition()); } }); } catch (InterruptedException e) { // bye! - System.err.println("<<< drag interrupted"); } } }; @@ -353,8 +362,8 @@ public class DraggableListView extends ListView { if(!isDraggableRow(item)) return false; - mDragPoint = y - item.getTop(); - mCoordOffset = ((int) ev.getRawY()) - y; + mDragPoint = new Point(x - item.getLeft(), y - item.getTop()); + mCoordOffset = new Point((int)ev.getRawX() - x, (int)ev.getRawY() - y); item.setDrawingCacheEnabled(true); @@ -386,7 +395,7 @@ public class DraggableListView extends ListView { mWindowParams = new WindowManager.LayoutParams(); mWindowParams.gravity = Gravity.TOP | Gravity.LEFT; mWindowParams.x = x; - mWindowParams.y = y - mDragPoint + mCoordOffset; + mWindowParams.y = y - mDragPoint.y + mCoordOffset.y; mWindowParams.height = WindowManager.LayoutParams.WRAP_CONTENT; mWindowParams.width = WindowManager.LayoutParams.WRAP_CONTENT; @@ -413,7 +422,15 @@ public class DraggableListView extends ListView { int x = (int) ev.getX(); int y = (int) ev.getY(); - mWindowParams.y = y - mDragPoint + mCoordOffset; + mWindowParams.y = y - mDragPoint.y + mCoordOffset.y; + + if (x > mTouchStartX + SWIPE_THRESHOLD) + mDragView.setPadding(30, 1, 0, 1); + else if (x < mTouchStartX - SWIPE_THRESHOLD) + mDragView.setPadding(-30, 1, 0, 1); + else + mDragView.setPadding(0, 0, 0, 0); + mWindowManager.updateViewLayout(mDragView, mWindowParams); int itemnum = getItemForPosition(y); @@ -470,11 +487,9 @@ public class DraggableListView extends ListView { if(mDragging) { if (mSwipeListener != null && mDragPos == mFirstDragPos) { - System.err.format("in swipe consideration - %.2f vs %.2f\n", - mTouchCurrentX , mTouchStartX); if (mTouchCurrentX > mTouchStartX + SWIPE_THRESHOLD) mSwipeListener.swipeRight(mFirstDragPos); - else if (mTouchStartX < mTouchStartX - SWIPE_THRESHOLD) + else if (mTouchCurrentX < mTouchStartX - SWIPE_THRESHOLD) mSwipeListener.swipeLeft(mFirstDragPos); } else if(mDropListener != null && mDragPos != mFirstDragPos && mDragPos >= 0 && mDragPos < getCount()) {