diff options
| author | Jorge Ruesga <jorge@ruesga.com> | 2013-11-29 03:15:31 +0100 |
|---|---|---|
| committer | Jorge Ruesga <jorge@ruesga.com> | 2013-11-30 00:34:26 +0100 |
| commit | b7e30877660bf8ea7950c7b8dddbbe980d3e734d (patch) | |
| tree | cff52b1a69c6047f7e43961641bdc78e5300fada | |
| parent | e38d9f1fc3e1ffabd31092510262ff83051da023 (diff) | |
| download | android_packages_apps_CMFileManager-b7e30877660bf8ea7950c7b8dddbbe980d3e734d.tar.gz android_packages_apps_CMFileManager-b7e30877660bf8ea7950c7b8dddbbe980d3e734d.tar.bz2 android_packages_apps_CMFileManager-b7e30877660bf8ea7950c7b8dddbbe980d3e734d.zip | |
CMFM: Improve flingerview handling
Patchset 2: CleanUp
Change-Id: I933d11f2d97dcf4b66f18e734313258a0df200a7
Signed-off-by: Jorge Ruesga <jorge@ruesga.com>
| -rw-r--r-- | src/com/cyanogenmod/filemanager/ui/widgets/FlingerListView.java | 97 |
1 files changed, 60 insertions, 37 deletions
diff --git a/src/com/cyanogenmod/filemanager/ui/widgets/FlingerListView.java b/src/com/cyanogenmod/filemanager/ui/widgets/FlingerListView.java index 8079127e..018f72ed 100644 --- a/src/com/cyanogenmod/filemanager/ui/widgets/FlingerListView.java +++ b/src/com/cyanogenmod/filemanager/ui/widgets/FlingerListView.java @@ -23,6 +23,7 @@ import android.view.HapticFeedbackConstants; import android.view.MotionEvent; import android.view.View; import android.view.ViewConfiguration; +import android.widget.AbsListView; import android.widget.AdapterView; import android.widget.ListView; @@ -143,9 +144,9 @@ public class FlingerListView extends ListView { private int mFlingingViewPos; private View mFlingingView; private boolean mFlingingViewPressed; - private int mFlingingViewHeight; private int mFlingingViewWidth; private boolean mScrolling; + private boolean mScrollInAnimation; private boolean mFlinging; private boolean mFlingingStarted; private boolean mMoveStarted; @@ -199,6 +200,18 @@ public class FlingerListView extends ListView { //Initialize variables this.mFlingRemovePercentaje = DEFAULT_FLING_REMOVE_PERCENTAJE; this.mFlingThreshold = AndroidHelper.convertDpToPixel(getContext(), MIN_FLINGER_THRESHOLD); + setOnScrollListener(new OnScrollListener() { + @Override + public void onScrollStateChanged(AbsListView view, int scrollState) { + mScrollInAnimation = (scrollState == SCROLL_STATE_FLING); + } + + @Override + public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, + int totalItemCount) { + } + }); + mScrollInAnimation = false; } /** @@ -309,7 +322,6 @@ public class FlingerListView extends ListView { Rect r = new Rect(); this.mFlingingView.getDrawingRect(r); this.mFlingingViewWidth = r.width(); - this.mFlingingViewHeight = r.height(); // Set the pressed state this.mFlingingView.postDelayed(new Runnable() { @@ -324,15 +336,14 @@ public class FlingerListView extends ListView { } }, PRESSED_DELAY_TIME); - // Enable this, cause some strange effects. By the other side, the scrolling - // is not as much smooth as it should be - //super.onTouchEvent(ev); - return true; + // If not the view is not scrolling the capture event + if (!mScrollInAnimation) { + return true; + } } break; case MotionEvent.ACTION_MOVE: - this.mMoveStarted = true; if (this.mFlingingView != null) { this.mFlingingView.removeCallbacks(this.mLongPressDetection); this.mFlingingViewPressed = false; @@ -342,7 +353,7 @@ public class FlingerListView extends ListView { // Detect scrolling this.mCurrentY = (int)ev.getY(); this.mScrolling = - Math.abs(this.mCurrentY - this.mStartY) > this.mFlingingViewHeight; + Math.abs(this.mCurrentY - this.mStartY) > (this.mFlingThreshold / 3); if (this.mFlingingStarted) { // Don't allow scrolling this.mScrolling = false; @@ -359,16 +370,25 @@ public class FlingerListView extends ListView { this.mFlingingView.setPressed(false); // Started - if (!this.mFlingingStarted && this.mTranslationX > this.mFlingThreshold) { + if (!this.mFlingingStarted) { // Flinging starting - if (!this.mOnItemFlingerListener.onItemFlingerStart( - this, - this.mFlingingView, - this.mFlingingViewPos, - this.mFlingingView.getId())) { - break; + if (!mMoveStarted) { + if (!this.mOnItemFlingerListener.onItemFlingerStart( + this, + this.mFlingingView, + this.mFlingingViewPos, + this.mFlingingView.getId())) { + this.mCurrentX = 0; + this.mTranslationX = 0; + this.mFlingingView.setTranslationX(this.mTranslationX); + this.mFlingingView.setPressed(false); + break; + } + } + mMoveStarted = true; + if (this.mTranslationX > this.mFlingThreshold) { + this.mFlingingStarted = true; } - this.mFlingingStarted = true; } // Detect if flinging occurs @@ -398,6 +418,11 @@ public class FlingerListView extends ListView { }); } } + } else { + this.mCurrentX = 0; + this.mTranslationX = 0; + this.mFlingingView.setTranslationX(this.mTranslationX); + this.mFlingingView.setPressed(false); } } if (this.mFlingingStarted) { @@ -427,28 +452,26 @@ public class FlingerListView extends ListView { // What is the motion if (!this.mScrolling && this.mFlingingView != null) { - if (!this.mMoveStarted) { - if (!this.mLongPress) { - this.mFlingingViewPressed = false; - this.mFlingingView.removeCallbacks(this.mLongPressDetection); - this.mFlingingView.setPressed(true); - - this.mFlingingView.postDelayed(new Runnable() { - @Override - @SuppressWarnings("synthetic-access") - public void run() { - FlingerListView.this.mFlingingView.setPressed(false); - } - }, PRESSED_DELAY_TIME); - performItemClick( - this.mFlingingView, - this.mFlingingViewPos, - this.mFlingingView.getId()); - } - } + if(!this.mMoveStarted && !this.mLongPress) { + this.mFlingingViewPressed = false; + this.mFlingingView.removeCallbacks(this.mLongPressDetection); + this.mFlingingView.setPressed(true); - // Handled - this.mFlingingView.setPressed(false); + this.mFlingingView.postDelayed(new Runnable() { + @Override + @SuppressWarnings("synthetic-access") + public void run() { + FlingerListView.this.mFlingingView.setPressed(false); + } + }, PRESSED_DELAY_TIME); + performItemClick( + this.mFlingingView, + this.mFlingingViewPos, + this.mFlingingView.getId()); + + // Handled + this.mFlingingView.setPressed(false); + } return true; } |
