1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-08-13 17:03:48 -04:00

Merge pull request #183 from dzan/fix_swipe_select

Revert to swipe to enter multi select mode.
This commit is contained in:
dzan 2012-09-21 10:26:05 -07:00
commit 950940ca3a

View File

@ -25,8 +25,10 @@ import android.text.style.ForegroundColorSpan;
import android.text.style.StyleSpan; import android.text.style.StyleSpan;
import android.util.Log; import android.util.Log;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.GestureDetector;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -58,6 +60,8 @@ import com.fsck.k9.K9;
import com.fsck.k9.Preferences; import com.fsck.k9.Preferences;
import com.fsck.k9.R; import com.fsck.k9.R;
import com.fsck.k9.SearchSpecification; import com.fsck.k9.SearchSpecification;
import com.fsck.k9.activity.misc.SwipeGestureDetector;
import com.fsck.k9.activity.misc.SwipeGestureDetector.OnSwipeGestureListener;
import com.fsck.k9.activity.setup.AccountSettings; import com.fsck.k9.activity.setup.AccountSettings;
import com.fsck.k9.activity.setup.FolderSettings; import com.fsck.k9.activity.setup.FolderSettings;
import com.fsck.k9.activity.setup.Prefs; import com.fsck.k9.activity.setup.Prefs;
@ -82,7 +86,8 @@ import com.handmark.pulltorefresh.library.PullToRefreshListView;
* shows a list of messages. * shows a list of messages.
* From this Activity the user can perform all standard message operations. * From this Activity the user can perform all standard message operations.
*/ */
public class MessageList extends K9ListActivity implements OnItemClickListener { public class MessageList extends K9ListActivity implements OnItemClickListener,
OnSwipeGestureListener {
/** /**
* Reverses the result of a {@link Comparator}. * Reverses the result of a {@link Comparator}.
@ -675,6 +680,9 @@ public class MessageList extends K9ListActivity implements OnItemClickListener {
initializeMessageList(getIntent(), true); initializeMessageList(getIntent(), true);
mListView.setVerticalFadingEdgeEnabled(false); mListView.setVerticalFadingEdgeEnabled(false);
// Enable gesture detection for MessageLists
mGestureDetector = new GestureDetector(new SwipeGestureDetector(this, this));
// Enable context action bar behaviour // Enable context action bar behaviour
mListView.setOnItemLongClickListener(new OnItemLongClickListener() { mListView.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override @Override
@ -1517,6 +1525,33 @@ public class MessageList extends K9ListActivity implements OnItemClickListener {
return true; return true;
} }
@Override
public void onSwipeRightToLeft(final MotionEvent e1, final MotionEvent e2) {
// Handle right-to-left as an un-select
handleSwipe(e1, false);
}
@Override
public void onSwipeLeftToRight(final MotionEvent e1, final MotionEvent e2) {
// Handle left-to-right as a select.
handleSwipe(e1, true);
}
/**
* Handle a select or unselect swipe event
* @param downMotion Event that started the swipe
* @param selected true if this was an attempt to select (i.e. left to right).
*/
private void handleSwipe(final MotionEvent downMotion, final boolean selected) {
int[] listPosition = new int[2];
mListView.getLocationOnScreen(listPosition);
int position = mListView.pointToPosition((int) downMotion.getRawX() - listPosition[0], (int) downMotion.getRawY() - listPosition[1]);
if (position != AdapterView.INVALID_POSITION) {
final MessageInfoHolder message = (MessageInfoHolder) mListView.getItemAtPosition(position);
toggleMessageSelect(message);
}
}
class MessageListAdapter extends BaseAdapter { class MessageListAdapter extends BaseAdapter {
private final List<MessageInfoHolder> mMessages = private final List<MessageInfoHolder> mMessages =
Collections.synchronizedList(new ArrayList<MessageInfoHolder>()); Collections.synchronizedList(new ArrayList<MessageInfoHolder>());