Added a swipe listener to touch list view, extended gtasks to use it

pull/14/head
Tim Su 15 years ago
parent 48c7761568
commit 6d127a8071

@ -78,15 +78,6 @@
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<!-- Activity that displays draggable task list -->
<activity android:name="com.todoroo.astrid.activity.DraggableTaskListActivity"
android:windowSoftInputMode="stateHidden"
android:theme="@style/Theme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<!-- Activity launched from shortcut -->
<activity android:name="com.todoroo.astrid.activity.ShortcutActivity"
android:clearTaskOnLaunch="true">
@ -230,6 +221,14 @@
</receiver>
<!-- gtasks -->
<activity android:name="com.todoroo.astrid.gtasks.GtasksListActivity"
android:windowSoftInputMode="stateHidden"
android:theme="@style/Theme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<receiver android:name="com.todoroo.astrid.gtasks.GtasksFilterExposer">
<intent-filter>
<action android:name="com.todoroo.astrid.REQUEST_FILTERS" />

@ -24,7 +24,6 @@ import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
@ -47,7 +46,7 @@ public class TouchListView extends ListView {
private int mCoordOffset; // the difference between screen coordinates and coordinates in this view
private DragListener mDragListener;
private DropListener mDropListener;
private RemoveListener mRemoveListener;
private SwipeListener mSwipeListener;
private int mUpperBound;
private int mLowerBound;
private int mHeight;
@ -91,31 +90,6 @@ public class TouchListView extends ListView {
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (mRemoveListener != null && mGestureDetector == null) {
if (mRemoveMode == FLING) {
mGestureDetector = new GestureDetector(getContext(), new SimpleOnGestureListener() {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
if (mDragView != null) {
if (velocityX > 1000) {
Rect r = mTempRect;
mDragView.getDrawingRect(r);
if ( e2.getX() > r.right * 2 / 3) {
// fast fling right with release near the right edge of the screen
stopDragging();
mRemoveListener.remove(mFirstDragPos);
unExpandViews(true);
}
}
// flinging while dragging should have no effect
return true;
}
return false;
}
});
}
}
if (mDragListener != null || mDropListener != null) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
@ -288,14 +262,14 @@ public class TouchListView extends ListView {
stopDragging();
if (mRemoveMode == SLIDE_RIGHT && ev.getX() > r.left+(r.width()*3/4)) {
if (mRemoveListener != null) {
mRemoveListener.remove(mFirstDragPos);
if (mSwipeListener!= null) {
mSwipeListener.swipeRight(mFirstDragPos);
}
unExpandViews(true);
} else if (mRemoveMode == SLIDE_LEFT && ev.getX() < r.left+(r.width()/4)) {
if (mRemoveListener != null) {
mRemoveListener.remove(mFirstDragPos);
}
if (mSwipeListener!= null) {
mSwipeListener.swipeLeft(mFirstDragPos);
}
unExpandViews(true);
} else {
if (mDropListener != null && mDragPos >= 0 && mDragPos < getCount()) {
@ -417,8 +391,8 @@ public class TouchListView extends ListView {
mDropListener = l;
}
public void setRemoveListener(RemoveListener l) {
mRemoveListener = l;
public void setSwipeListener(SwipeListener l) {
mSwipeListener = l;
}
public interface DragListener {
@ -427,7 +401,8 @@ public class TouchListView extends ListView {
public interface DropListener {
void drop(int from, int to);
}
public interface RemoveListener {
void remove(int which);
public interface SwipeListener {
void swipeLeft(int which);
void swipeRight(int which);
}
}

@ -0,0 +1,76 @@
package com.todoroo.astrid.gtasks;
import android.os.Bundle;
import com.commonsware.cwac.tlv.TouchListView;
import com.commonsware.cwac.tlv.TouchListView.DropListener;
import com.commonsware.cwac.tlv.TouchListView.SwipeListener;
import com.todoroo.andlib.data.Property.IntegerProperty;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Functions;
import com.todoroo.andlib.sql.Join;
import com.todoroo.andlib.sql.Order;
import com.todoroo.andlib.sql.QueryTemplate;
import com.todoroo.astrid.activity.DraggableTaskListActivity;
import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria;
import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.Task;
public class GtasksListActivity extends DraggableTaskListActivity {
@Autowired private GtasksTaskListUpdater gtasksTaskListUpdater;
// --- gtasks temp stuff
private final String listId = "17816916813445155620:0:0"; //$NON-NLS-1$
Filter builtInFilter = new Filter("Tim's Tasks", "Tim's Tasks", new QueryTemplate().join( //$NON-NLS-1$ //$NON-NLS-2$
Join.left(Metadata.TABLE, Task.ID.eq(Metadata.TASK))).where(Criterion.and(
MetadataCriteria.withKey("gtasks"), //$NON-NLS-1$
TaskCriteria.isVisible(),
TaskCriteria.notDeleted(),
Metadata.VALUE2.eq(listId))).orderBy(
Order.asc(Functions.cast(Metadata.VALUE5, "INTEGER"))), //$NON-NLS-1$
null);
// --- end
@Override
protected IntegerProperty getIndentProperty() {
return GtasksMetadata.INDENT;
}
@Override
public void onCreate(Bundle icicle) {
getIntent().putExtra(TOKEN_FILTER, builtInFilter);
super.onCreate(icicle);
getTouchListView().setDropListener(dropListener);
getTouchListView().setSwipeListener(swipeListener);
}
private final TouchListView.DropListener dropListener = new DropListener() {
@Override
public void drop(int from, int to) {
// meep
}
};
private final TouchListView.SwipeListener swipeListener = new SwipeListener() {
@Override
public void swipeRight(int which) {
long targetTaskId = taskAdapter.getItemId(which);
gtasksTaskListUpdater.indent(listId, targetTaskId, 1);
taskAdapter.notifyDataSetChanged();
}
@Override
public void swipeLeft(int which) {
long targetTaskId = taskAdapter.getItemId(which);
gtasksTaskListUpdater.indent(listId, targetTaskId, -1);
taskAdapter.notifyDataSetChanged();
}
};
}

@ -16,16 +16,7 @@ import com.timsu.astrid.R;
import com.todoroo.andlib.data.Property;
import com.todoroo.andlib.data.Property.IntegerProperty;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Functions;
import com.todoroo.andlib.sql.Join;
import com.todoroo.andlib.sql.Order;
import com.todoroo.andlib.sql.QueryTemplate;
import com.todoroo.astrid.adapter.TaskAdapter;
import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria;
import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.Task;
/**
@ -36,40 +27,24 @@ import com.todoroo.astrid.data.Task;
*/
public class DraggableTaskListActivity extends TaskListActivity {
// --- gtasks temp stuff
private final String listId = "17816916813445155620:0:0"; //$NON-NLS-1$
Filter builtInFilter = new Filter("Tim's Tasks", "Tim's Tasks", new QueryTemplate().join( //$NON-NLS-1$ //$NON-NLS-2$
Join.left(Metadata.TABLE, Task.ID.eq(Metadata.TASK))).where(Criterion.and(
MetadataCriteria.withKey("gtasks"), //$NON-NLS-1$
TaskCriteria.isVisible(),
TaskCriteria.notDeleted(),
Metadata.VALUE2.eq(listId))).orderBy(
Order.asc(Functions.cast(Metadata.VALUE5, "INTEGER"))), //$NON-NLS-1$
null);
// --- end
// --- task list
public static final IntegerProperty INDENT = new IntegerProperty(Metadata.TABLE,
Metadata.VALUE4.name);
public static final IntegerProperty ORDER = new IntegerProperty(Metadata.TABLE,
Metadata.VALUE5.name);
/**
* If database has an indent property for determining how rows are indented,
* return it here so we can read it from the cursor and use it
*/
protected IntegerProperty getIndentProperty() {
return null;
}
public IntegerProperty getIndentProperty() {
return INDENT;
public TouchListView getTouchListView() {
TouchListView tlv = (TouchListView) getListView();
return tlv;
}
@Override
public void onCreate(Bundle icicle) {
getIntent().putExtra(TOKEN_FILTER, builtInFilter);
super.onCreate(icicle);
TouchListView tlv = (TouchListView) getListView();
tlv.setDropListener(onDrop);
tlv.setRemoveListener(onRemove);
}
@Override
@ -139,6 +114,8 @@ public class DraggableTaskListActivity extends TaskListActivity {
ViewHolder viewHolder = (ViewHolder)container.getTag();
viewHolder.completeBox.setOnClickListener(completeBoxListener);
// TODO add listeners
// context menu listener
//container.findViewById(R.id.task_row).setOnCreateContextMenuListener(listener);
@ -147,25 +124,4 @@ public class DraggableTaskListActivity extends TaskListActivity {
}
}
// --- drag and swipe handlers
private final TouchListView.DropListener onDrop = new TouchListView.DropListener() {
@Override
public void drop(int from, int to) {
/*String item = adapter.getItem(from);
adapter.remove(item);
adapter.insert(item, to);*/
}
};
private final TouchListView.RemoveListener onRemove = new TouchListView.RemoveListener() {
@Override
public void remove(int which) {
// new GtasksIndentAction.GtasksIncreaseIndentAction().indent(adapter.getItemId(which));
// adapter.notifyDataSetChanged();
// adapter.remove(adapter.getItem(which));
}
};
}

Loading…
Cancel
Save