summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRohit Yengisetty <rohit@cyngn.com>2015-01-15 13:16:16 -0800
committerRohit Yengisetty <rohit@cyngn.com>2015-01-15 15:01:52 -0800
commit62623b7b9afec91f12e15146d03aafac74998f08 (patch)
tree837a679a6acc73a86c4085ae6c486fff16f200fc
parentb5ad7c99c3e990868042b13cd31c532b6102e0cd (diff)
downloadandroid_packages_apps_ContactsCommon-62623b7b9afec91f12e15146d03aafac74998f08.tar.gz
android_packages_apps_ContactsCommon-62623b7b9afec91f12e15146d03aafac74998f08.tar.bz2
android_packages_apps_ContactsCommon-62623b7b9afec91f12e15146d03aafac74998f08.zip
ContactsCommon : Add scroll gesture support on Contacts List
Adds the ability to listen for vertical scroll up and scroll down gestures on the contacts list view. Change-Id: I27ecc110a623eb5394f7b80d192a317294da0660
-rwxr-xr-xsrc/com/android/contacts/common/list/ContactEntryListFragment.java57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/com/android/contacts/common/list/ContactEntryListFragment.java b/src/com/android/contacts/common/list/ContactEntryListFragment.java
index 4af18305..86c36502 100755
--- a/src/com/android/contacts/common/list/ContactEntryListFragment.java
+++ b/src/com/android/contacts/common/list/ContactEntryListFragment.java
@@ -38,6 +38,7 @@ import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnFocusChangeListener;
import android.view.View.OnTouchListener;
+import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.AbsListView;
@@ -118,6 +119,9 @@ public abstract class ContactEntryListFragment<T extends ContactEntryListAdapter
private T mAdapter;
private View mView;
private ListView mListView;
+ private float mClickY;
+ private float mTouchSlop;
+ private ContactListGestureListener mContactListGestureListener;
/**
* Used for keeping track of the scroll state of the list.
@@ -185,6 +189,7 @@ public abstract class ContactEntryListFragment<T extends ContactEntryListAdapter
super.onAttach(activity);
setContext(activity);
setLoaderManager(super.getLoaderManager());
+ mTouchSlop = ViewConfiguration.get(activity).getScaledTouchSlop();
}
/**
@@ -195,6 +200,13 @@ public abstract class ContactEntryListFragment<T extends ContactEntryListAdapter
configurePhotoLoader();
}
+ /**
+ * Register a listener for scroll events on contacts list view
+ */
+ public void setContactListGestureListener(ContactListGestureListener listener) {
+ mContactListGestureListener = listener;
+ }
+
public Context getContext() {
return mContext;
}
@@ -879,6 +891,35 @@ public abstract class ContactEntryListFragment<T extends ContactEntryListAdapter
@Override
public boolean onTouch(View view, MotionEvent event) {
if (view == mListView) {
+ // proceed w/ gesture calculation only if a listener is registered
+ if (mContactListGestureListener != null) {
+ int action = event.getAction();
+ switch (action) {
+
+ case MotionEvent.ACTION_DOWN:
+ mClickY = event.getY();
+ break;
+
+ case MotionEvent.ACTION_MOVE:
+ // only interested in vertical scroll movements
+ float distanceMoved = mClickY - event.getY();
+ if (Math.abs(distanceMoved) > mTouchSlop) {
+ if (distanceMoved < 0) {
+ // scrolled down
+ mContactListGestureListener.onScroll(
+ ContactListGestureListener.SCROLL_DOWN);
+
+ } else {
+ // scrolled up
+ mContactListGestureListener.onScroll(
+ ContactListGestureListener.SCROLL_UP);
+ }
+ // set Y to the current place in the gesture
+ mClickY = event.getY();
+ }
+
+ }
+ }
hideSoftKeyboard();
}
return false;
@@ -932,4 +973,20 @@ public abstract class ContactEntryListFragment<T extends ContactEntryListAdapter
return View.SCROLLBAR_POSITION_RIGHT;
}
}
+
+ /**
+ * Callback interface to listen for scroll gestures on the Contacts List
+ */
+ public interface ContactListGestureListener {
+
+ public int SCROLL_UP = 0;
+ public int SCROLL_DOWN = 1;
+
+ /**
+ * Called when the user tries scrolling the contacts list
+ * @param scrollDirection direction of the scroll
+ */
+ public void onScroll(int scrollDirection);
+ }
+
}