Skip to content
This repository has been archived by the owner on Dec 12, 2020. It is now read-only.

Commit

Permalink
Swipe to complete tasks
Browse files Browse the repository at this point in the history
* Left to right swipe on an incomplete task to mark it as complete
* Right to left swipe on a complete task to mark it as incomplete
* Deprecate "Quick complete" setting
  • Loading branch information
ginatrapani committed Aug 12, 2012
1 parent 180e8bd commit 9682c4d
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 21 deletions.
3 changes: 0 additions & 3 deletions res/values-de/strings.xml
Expand Up @@ -82,9 +82,6 @@ You should have received a copy of the GNU General Public License along with Tod
<string name="show_task_age_pref_key">show_task_age_pref</string>
<string name="show_task_age_pref_title">Zeige Task Alter.</string>
<string name="show_task_age_pref_summary">Zeige Task Alter mit Erzeugungsdatum.</string>
<string name="short_touch_pref_title">Schnelles erledigen</string>
<string name="short_touch_pref_summary_on">Kurzer Klick auf einem Task markiert als erledigt.</string>
<!-- <string name="short_touch_pref_summary_off">Kurzer Klick auf einem Task zeihgt Kontext-Menü.</string> -->


<!-- sync dialog -->
Expand Down
4 changes: 0 additions & 4 deletions res/values-fr/strings.xml
Expand Up @@ -76,9 +76,6 @@ You should have received a copy of the GNU General Public License along with Tod
<string name="work_offline_pref_key">workofflinepref</string>
<string name="work_offline_pref_title">Travailler hors ligne</string>
<string name="work_offline_pref_summary">Ne pas envoyer automatiquement chaque changement à Dropbox.</string>
<string name="short_touch_pref_title">Terminer rapidement</string>
<string name="short_touch_pref_summary_on">Appyer rapidement sur une tâche pour la marquer comme terminée.</string>
<!-- <string name="short_touch_pref_summary_off">Short touch on a task launches full context menu.</string> -->

<!-- sync dialog -->
<string name="sync_dialog_title">Syncho manuelle</string>
Expand Down Expand Up @@ -124,7 +121,6 @@ You should have received a copy of the GNU General Public License along with Tod
<string name="toast_login_notconnected">Connexion impossible :\nAucune connexion internet.</string>
<string name="toast_notconnected">Aucune connexion internet;\nVous travaillez hors-ligne.</string>
<string name="toast_notconnected_switch_to_offline">Aucune connexion internet!\nPassage en mode hors-ligne.</string>
<string name="short_touch_pref_key">short_touch_pref</string>

<!-- Relative Dates -->
<string name="dates_days_ago">Il y a %d jours</string>
Expand Down
4 changes: 0 additions & 4 deletions res/values/strings.xml
Expand Up @@ -88,9 +88,6 @@ You should have received a copy of the GNU General Public License along with Tod
<string name="manual_sync_pref_key">workofflinepref</string>
<string name="manual_sync_pref_title">Manual sync</string>
<string name="manual_sync_pref_summary">Don\'t automatically upload every change to Dropbox.</string>
<string name="short_touch_pref_title">Quick complete</string>
<string name="short_touch_pref_summary_on">Short touch on a task to mark it complete.</string>
<!-- <string name="short_touch_pref_summary_off">Short touch on a task launches full context menu.</string> -->


<!-- sync dialog -->
Expand Down Expand Up @@ -139,7 +136,6 @@ You should have received a copy of the GNU General Public License along with Tod
<!-- online/offline toasts -->
<string name="toast_login_notconnected">Cannot log in:\nNo internet connection.</string>
<string name="toast_notconnected">No internet connection: Cannot sync with Dropbox right now.</string>
<string name="short_touch_pref_key">short_touch_pref</string>

<!-- Relative Dates -->
<string name="dates_days_ago">%d days ago</string>
Expand Down
2 changes: 0 additions & 2 deletions res/xml/preferences.xml
Expand Up @@ -33,8 +33,6 @@
android:title="@string/todotxt_settings_header">
<CheckBoxPreference android:key="@string/prepend_date_pref_key"
android:title="@string/prepend_date_pref_title" android:summary="@string/prepend_date_pref_summary" />
<CheckBoxPreference android:key="@string/short_touch_pref_key"
android:title="@string/short_touch_pref_title" android:summary="@string/short_touch_pref_summary_on" />
<CheckBoxPreference android:key="@string/line_breaks_pref_key"
android:title="@string/line_breaks_pref_title" android:summary="@string/line_breaks_pref_summary" />
</PreferenceCategory>
Expand Down
71 changes: 63 additions & 8 deletions src/com/todotxt/todotxttouch/TodoTxtTouch.java
Expand Up @@ -55,10 +55,13 @@
import android.util.Log;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
Expand Down Expand Up @@ -113,6 +116,9 @@ public class TodoTxtTouch extends ListActivity implements
private static final int SYNC_CHOICE_DIALOG = 100;
private static final int SYNC_CONFLICT_DIALOG = 101;

private GestureDetector gestureDetector;
private View.OnTouchListener gestureListener;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -180,6 +186,22 @@ public void onReceive(Context context, Intent intent) {
Log.v(TAG, "Searched for " + m_search);
setFilteredTasks(false);
}

gestureDetector = new GestureDetector(new TodoTxtGestureDetector());
gestureListener = new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (gestureDetector.onTouchEvent(event)) {
MotionEvent cancelEvent = MotionEvent.obtain(event);
cancelEvent.setAction(MotionEvent.ACTION_CANCEL);
v.onTouchEvent(cancelEvent);
return true;
}
return false;
}
};

getListView().setOnTouchListener(gestureListener);
}

private void initializeTasks() {
Expand Down Expand Up @@ -465,7 +487,8 @@ protected void onPostExecute(Boolean result) {
}.execute(task);
}
};
Util.showConfirmationDialog(this, R.string.areyousure, listener);
Util.showConfirmationDialog(this, R.string.areyousure, listener,
R.string.unComplete);
}

private void completeTaskAt(final int pos) {
Expand Down Expand Up @@ -962,13 +985,7 @@ void setFilteredTasks(boolean reload) {
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
m_pos = position;
boolean completeOnShort = m_app.m_prefs.getBoolean(
getString(R.string.short_touch_pref_key), false);
if (completeOnShort) {
completeTaskAt(position);
} else {
openContextMenu(getListView());
}
openContextMenu(getListView());
}

private void updateSyncUI() {
Expand Down Expand Up @@ -1128,4 +1145,42 @@ public void startFilterActivity() {
startActivityIfNeeded(i, REQUEST_FILTER);
}

class TodoTxtGestureDetector extends SimpleOnGestureListener {
private static final int SWIPE_MIN_DISTANCE = 120;
private static final int SWIPE_MAX_OFF_PATH = 250;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
return false;

ListView lv = getListView();
int pos = lv.pointToPosition((int) e1.getX(), (int) e1.getY());

// right to left swipe - mark task complete
if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
Log.v(TAG, "Fling left");
// if task is complete, undo complete
final Task task = m_adapter.getItem(pos);
if (task.isCompleted()) {
undoCompleteTaskAt(pos);
}
return true;
} else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
// left to right swipe - uncomplete task
Log.v(TAG, "Fling right");
// if task is incomplete, mark as complete
final Task task = m_adapter.getItem(pos);
if (!task.isCompleted()) {
completeTaskAt(pos);
}
return true;
}
return false;
}
}
}
12 changes: 12 additions & 0 deletions src/com/todotxt/todotxttouch/util/Util.java
Expand Up @@ -233,6 +233,18 @@ public static void showConfirmationDialog(Context cxt, int msgid,
builder.show();
}

public static void showConfirmationDialog(Context cxt, int msgid,
OnClickListener oklistener, int titleid) {
AlertDialog.Builder builder = new AlertDialog.Builder(cxt);
// builder.setTitle(cxt.getPackageName());
builder.setTitle(titleid);
builder.setMessage(msgid);
builder.setPositiveButton(android.R.string.ok, oklistener);
builder.setNegativeButton(android.R.string.cancel, null);
builder.setCancelable(true);
builder.show();
}

public static void showDeleteConfirmationDialog(Context cxt,
OnClickListener oklistener) {
AlertDialog.Builder builder = new AlertDialog.Builder(cxt);
Expand Down

0 comments on commit 9682c4d

Please sign in to comment.