summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHongwei Wang <hwwang@google.com>2013-09-11 22:00:13 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-09-11 22:00:13 +0000
commite44b3c6a990f41d3e58406310183b16db0dab3ea (patch)
tree40c21d636fe624de7dfe7b9d7474a1d2697e1518
parent704acc087ce359295475a46695c2821c55778344 (diff)
parentbf5b298b1a5752a56315131a22434185198370a8 (diff)
Merge "Support drag & drop across "pages" of the favorites list" into klp-dev
-rw-r--r--res/layout/phone_favorites_fragment.xml2
-rw-r--r--src/com/android/dialer/list/PhoneFavoriteFragment.java4
-rw-r--r--src/com/android/dialer/list/PhoneFavoriteListView.java (renamed from src/com/android/dialer/list/SwipeableListView.java)104
3 files changed, 91 insertions, 19 deletions
diff --git a/res/layout/phone_favorites_fragment.xml b/res/layout/phone_favorites_fragment.xml
index 3b9e589eb..6023fc84e 100644
--- a/res/layout/phone_favorites_fragment.xml
+++ b/res/layout/phone_favorites_fragment.xml
@@ -28,7 +28,7 @@
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
- <com.android.dialer.list.SwipeableListView
+ <com.android.dialer.list.PhoneFavoriteListView
android:id="@+id/contact_tile_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
diff --git a/src/com/android/dialer/list/PhoneFavoriteFragment.java b/src/com/android/dialer/list/PhoneFavoriteFragment.java
index 0aae8aada..d7c387e57 100644
--- a/src/com/android/dialer/list/PhoneFavoriteFragment.java
+++ b/src/com/android/dialer/list/PhoneFavoriteFragment.java
@@ -145,7 +145,7 @@ public class PhoneFavoriteFragment extends Fragment implements OnItemClickListen
private CallLogQueryHandler mCallLogQueryHandler;
private TextView mEmptyView;
- private SwipeableListView mListView;
+ private PhoneFavoriteListView mListView;
private View mShowAllContactsButton;
private final HashMap<Long, Integer> mItemIdTopMap = new HashMap<Long, Integer>();
@@ -206,7 +206,7 @@ public class PhoneFavoriteFragment extends Fragment implements OnItemClickListen
final View listLayout = inflater.inflate(
R.layout.phone_favorites_fragment, container, false);
- mListView = (SwipeableListView) listLayout.findViewById(R.id.contact_tile_list);
+ mListView = (PhoneFavoriteListView) listLayout.findViewById(R.id.contact_tile_list);
mListView.setItemsCanFocus(true);
mListView.setOnItemClickListener(this);
mListView.setVerticalScrollBarEnabled(false);
diff --git a/src/com/android/dialer/list/SwipeableListView.java b/src/com/android/dialer/list/PhoneFavoriteListView.java
index 449628da7..b5da054f9 100644
--- a/src/com/android/dialer/list/SwipeableListView.java
+++ b/src/com/android/dialer/list/PhoneFavoriteListView.java
@@ -19,10 +19,13 @@ package com.android.dialer.list;
import android.content.Context;
import android.content.res.Configuration;
+import android.os.Handler;
import android.util.AttributeSet;
import android.util.Log;
+import android.view.DragEvent;
import android.view.MotionEvent;
import android.view.View;
+import android.view.View.OnDragListener;
import android.view.ViewConfiguration;
import android.widget.ListView;
@@ -32,40 +35,75 @@ import com.android.dialer.list.SwipeHelper.OnItemGestureListener;
import com.android.dialer.list.SwipeHelper.SwipeHelperCallback;
/**
- * Copy of packages/apps/UnifiedEmail - com.android.mail.ui.Swipeable with changes.
+ * The ListView composed of {@link ContactTileRow}.
+ * This ListView handles both
+ * - Swiping, which is borrowed from packages/apps/UnifiedEmail (com.android.mail.ui.Swipeable)
+ * - Drag and drop
*/
-public class SwipeableListView extends ListView implements SwipeHelperCallback {
+public class PhoneFavoriteListView extends ListView implements
+ SwipeHelperCallback, OnDragListener {
+
+ public static final String LOG_TAG = PhoneFavoriteListView.class.getSimpleName();
+
private SwipeHelper mSwipeHelper;
private boolean mEnableSwipe = true;
- public static final String LOG_TAG = SwipeableListView.class.getSimpleName();
-
private OnItemGestureListener mOnItemGestureListener;
- public SwipeableListView(Context context) {
+ private float mDensityScale;
+ private float mTouchSlop;
+
+ private int mTopScrollBound;
+ private int mBottomScrollBound;
+ private int mLastDragY;
+
+ private Handler mScrollHandler;
+ private final long SCROLL_HANDLER_DELAY_MILLIS = 5;
+ private final int DRAG_SCROLL_PX_UNIT = 10;
+
+ /**
+ * {@link #mTopScrollBound} and {@link mBottomScrollBound} will be
+ * offseted to the top / bottom by {@link #getHeight} * {@link #BOUND_GAP_RATIO} pixels.
+ */
+ private final float BOUND_GAP_RATIO = 0.2f;
+
+ private final Runnable mDragScroller = new Runnable() {
+ @Override
+ public void run() {
+ if (mLastDragY <= mTopScrollBound) {
+ smoothScrollBy(-DRAG_SCROLL_PX_UNIT, (int) SCROLL_HANDLER_DELAY_MILLIS);
+ } else if (mLastDragY >= mBottomScrollBound) {
+ smoothScrollBy(DRAG_SCROLL_PX_UNIT, (int) SCROLL_HANDLER_DELAY_MILLIS);
+ }
+ mScrollHandler.postDelayed(this, SCROLL_HANDLER_DELAY_MILLIS);
+ }
+ };
+
+ public PhoneFavoriteListView(Context context) {
this(context, null);
}
- public SwipeableListView(Context context, AttributeSet attrs) {
+ public PhoneFavoriteListView(Context context, AttributeSet attrs) {
this(context, attrs, -1);
}
- public SwipeableListView(Context context, AttributeSet attrs, int defStyle) {
+ public PhoneFavoriteListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
- float densityScale = getResources().getDisplayMetrics().density;
- float pagingTouchSlop = ViewConfiguration.get(context).getScaledPagingTouchSlop();
- mSwipeHelper = new SwipeHelper(context, SwipeHelper.X, this, densityScale,
- pagingTouchSlop);
+ mDensityScale = getResources().getDisplayMetrics().density;
+ mTouchSlop = ViewConfiguration.get(context).getScaledPagingTouchSlop();
+ mSwipeHelper = new SwipeHelper(context, SwipeHelper.X, this,
+ mDensityScale, mTouchSlop);
setItemsCanFocus(true);
+ setOnDragListener(this);
}
@Override
protected void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
- float densityScale = getResources().getDisplayMetrics().density;
- mSwipeHelper.setDensityScale(densityScale);
- float pagingTouchSlop = ViewConfiguration.get(getContext()).getScaledPagingTouchSlop();
- mSwipeHelper.setPagingTouchSlop(pagingTouchSlop);
+ mDensityScale= getResources().getDisplayMetrics().density;
+ mTouchSlop = ViewConfiguration.get(getContext()).getScaledPagingTouchSlop();
+ mSwipeHelper.setDensityScale(mDensityScale);
+ mSwipeHelper.setPagingTouchSlop(mTouchSlop);
}
/**
@@ -162,4 +200,38 @@ public class SwipeableListView extends ListView implements SwipeHelperCallback {
// the chance to intercept events anymore
requestDisallowInterceptTouchEvent(true);
}
-} \ No newline at end of file
+
+ @Override
+ public boolean dispatchDragEvent(DragEvent event) {
+ switch (event.getAction()) {
+ case DragEvent.ACTION_DRAG_LOCATION:
+ if (mScrollHandler == null) {
+ mScrollHandler = getHandler();
+ }
+ mLastDragY = (int) event.getY();
+ mScrollHandler.postDelayed(mDragScroller, SCROLL_HANDLER_DELAY_MILLIS);
+ break;
+ case DragEvent.ACTION_DRAG_ENTERED:
+ final int boundGap = (int) (getHeight() * BOUND_GAP_RATIO);
+ mTopScrollBound = (getTop() + boundGap);
+ mBottomScrollBound = (getBottom() - boundGap);
+ break;
+ case DragEvent.ACTION_DRAG_EXITED:
+ case DragEvent.ACTION_DRAG_ENDED:
+ mScrollHandler.removeCallbacks(mDragScroller);
+ break;
+ case DragEvent.ACTION_DRAG_STARTED:
+ // Not a receiver
+ case DragEvent.ACTION_DROP:
+ // Not a receiver
+ default:
+ break;
+ }
+ return super.dispatchDragEvent(event);
+ }
+
+ @Override
+ public boolean onDrag(View v, DragEvent event) {
+ return true;
+ }
+}