From 7a7297338b7665778dcf3044351692076332ab0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B6=82=E5=86=B0=E5=86=B0?= Date: Wed, 15 Nov 2017 17:21:56 +0800 Subject: [PATCH] fixed multi menu can open bug --- .gitignore | 3 +- .idea/.name | 1 - .idea/compiler.xml | 22 ------- .idea/copyright/profiles_settings.xml | 3 - .idea/encodings.xml | 6 -- .idea/gradle.xml | 19 ------ .idea/misc.xml | 62 ------------------- .idea/modules.xml | 10 --- .idea/runConfigurations.xml | 12 ---- .idea/vcs.xml | 6 -- app/app.iml | 53 +++++++++------- app/build.gradle | 12 ++-- .../tubb/smrv/demo/normal/SimpleActivity.java | 14 ++--- build.gradle | 12 ++-- gradle/wrapper/gradle-wrapper.properties | 2 +- library/build.gradle | 12 ++-- library/library.iml | 44 ++++++------- .../tubb/smrv/SwipeHorizontalMenuLayout.java | 4 +- .../java/com/tubb/smrv/SwipeMenuGridView.java | 9 ++- .../java/com/tubb/smrv/SwipeMenuHelper.java | 15 ++++- .../java/com/tubb/smrv/SwipeMenuLayout.java | 8 +-- .../java/com/tubb/smrv/SwipeMenuListView.java | 9 ++- .../com/tubb/smrv/SwipeMenuRecyclerView.java | 15 +++-- .../com/tubb/smrv/SwipeMenuScrollView.java | 14 +++-- .../tubb/smrv/SwipeVerticalMenuLayout.java | 5 +- 25 files changed, 129 insertions(+), 243 deletions(-) delete mode 100644 .idea/.name delete mode 100644 .idea/compiler.xml delete mode 100644 .idea/copyright/profiles_settings.xml delete mode 100644 .idea/encodings.xml delete mode 100644 .idea/gradle.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/runConfigurations.xml delete mode 100644 .idea/vcs.xml diff --git a/.gitignore b/.gitignore index 9c4de58..1a7fcaa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ .gradle +.idea /local.properties -/.idea/workspace.xml -/.idea/libraries .DS_Store /build /captures diff --git a/.idea/.name b/.idea/.name deleted file mode 100644 index cd861bc..0000000 --- a/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -SwipeMenu \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index 96cc43e..0000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml deleted file mode 100644 index e7bedf3..0000000 --- a/.idea/copyright/profiles_settings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml deleted file mode 100644 index 97626ba..0000000 --- a/.idea/encodings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml deleted file mode 100644 index 66e2f6f..0000000 --- a/.idea/gradle.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 7e40dfc..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1.7 - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index bf377ed..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml deleted file mode 100644 index 7f68460..0000000 --- a/.idea/runConfigurations.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/app/app.iml b/app/app.iml index 4e044d5..ff301a0 100644 --- a/app/app.iml +++ b/app/app.iml @@ -9,7 +9,6 @@ - + + + + @@ -45,7 +47,6 @@ - @@ -53,7 +54,6 @@ - @@ -61,7 +61,6 @@ - @@ -69,7 +68,6 @@ - @@ -77,43 +75,52 @@ - + + + - - - - - - + + + + + - - + + + + + - - - + - - - - - + + + + + + + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index cbc5423..4f5fa59 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,13 +1,13 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 23 - buildToolsVersion '23.0.2' + compileSdkVersion 25 + buildToolsVersion '25.0.3' defaultConfig { applicationId "com.tubb.smrv.demo" minSdkVersion 9 - targetSdkVersion 23 + targetSdkVersion 25 versionCode 1 versionName "1.0" } @@ -25,9 +25,9 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.android.support:appcompat-v7:23.1.1' + compile 'com.android.support:appcompat-v7:25.1.1' compile 'com.squareup.picasso:picasso:2.5.2' - compile 'com.android.support:cardview-v7:23.1.1' - compile 'com.android.support:recyclerview-v7:23.1.1' + compile 'com.android.support:cardview-v7:25.1.1' + compile 'com.android.support:recyclerview-v7:25.1.1' compile project(':library') } diff --git a/app/src/main/java/com/tubb/smrv/demo/normal/SimpleActivity.java b/app/src/main/java/com/tubb/smrv/demo/normal/SimpleActivity.java index 60d15e1..636804c 100644 --- a/app/src/main/java/com/tubb/smrv/demo/normal/SimpleActivity.java +++ b/app/src/main/java/com/tubb/smrv/demo/normal/SimpleActivity.java @@ -59,13 +59,13 @@ public void onClick(View v) { } }); -// findViewById(R.id.smContentView).setOnLongClickListener(new View.OnLongClickListener() { -// @Override -// public boolean onLongClick(View v) { -// Toast.makeText(SimpleActivity.this, "content view long click", Toast.LENGTH_SHORT).show(); -// return false; -// } -// }); + findViewById(R.id.smContentView).setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + Toast.makeText(SimpleActivity.this, "content view long click", Toast.LENGTH_SHORT).show(); + return true; + } + }); findViewById(R.id.smMenuViewLeft).setOnClickListener(new View.OnClickListener() { @Override diff --git a/build.gradle b/build.gradle index 9851875..82743a4 100644 --- a/build.gradle +++ b/build.gradle @@ -2,12 +2,11 @@ buildscript { repositories { - jcenter { - url "http://jcenter.bintray.com/" - } + google() + jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.1.0' + classpath 'com.android.tools.build:gradle:3.0.0-beta6' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } @@ -15,8 +14,7 @@ buildscript { allprojects { repositories { - jcenter { - url "http://jcenter.bintray.com/" - } + google() + jcenter() } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 39a496a..156649d 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-all.zip \ No newline at end of file +distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip \ No newline at end of file diff --git a/library/build.gradle b/library/build.gradle index 5f6c934..1757ff7 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -8,17 +8,17 @@ buildscript { } } dependencies { - classpath 'com.novoda:bintray-release:0.3.4' + classpath 'com.novoda:bintray-release:0.5.0' } } android { - compileSdkVersion 23 - buildToolsVersion '23.0.2' + compileSdkVersion 25 + buildToolsVersion '25.0.3' defaultConfig { minSdkVersion 9 - targetSdkVersion 23 + targetSdkVersion 25 versionCode 28 versionName "5.4.0" } @@ -37,8 +37,8 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) - provided 'com.android.support:appcompat-v7:23.1.1' - provided 'com.android.support:recyclerview-v7:23.1.1' + provided 'com.android.support:appcompat-v7:25.1.1' + provided 'com.android.support:recyclerview-v7:25.1.1' } publish { diff --git a/library/library.iml b/library/library.iml index c05cab9..197221c 100644 --- a/library/library.iml +++ b/library/library.iml @@ -9,7 +9,6 @@ - + + + + @@ -46,7 +48,6 @@ - @@ -54,7 +55,6 @@ - @@ -62,7 +62,6 @@ - @@ -70,7 +69,6 @@ - @@ -78,40 +76,44 @@ - - + + - - - + + + + - - - - - + - - - - + + + + + + + + + + + \ No newline at end of file diff --git a/library/src/main/java/com/tubb/smrv/SwipeHorizontalMenuLayout.java b/library/src/main/java/com/tubb/smrv/SwipeHorizontalMenuLayout.java index 8cfdc97..c1f3654 100644 --- a/library/src/main/java/com/tubb/smrv/SwipeHorizontalMenuLayout.java +++ b/library/src/main/java/com/tubb/smrv/SwipeHorizontalMenuLayout.java @@ -34,7 +34,7 @@ public SwipeHorizontalMenuLayout(Context context, AttributeSet attrs, int defSty @Override public boolean onInterceptTouchEvent(MotionEvent ev) { boolean isIntercepted = super.onInterceptTouchEvent(ev); - int action = ev.getAction(); + int action = ev.getActionMasked(); switch (action) { case MotionEvent.ACTION_DOWN: mDownX = mLastX = (int) ev.getX(); @@ -71,7 +71,7 @@ public boolean onTouchEvent(MotionEvent ev) { mVelocityTracker.addMovement(ev); int dx; int dy; - int action = ev.getAction(); + int action = ev.getActionMasked(); switch (action) { case MotionEvent.ACTION_DOWN: mLastX = (int) ev.getX(); diff --git a/library/src/main/java/com/tubb/smrv/SwipeMenuGridView.java b/library/src/main/java/com/tubb/smrv/SwipeMenuGridView.java index 9f04d61..16d40d0 100644 --- a/library/src/main/java/com/tubb/smrv/SwipeMenuGridView.java +++ b/library/src/main/java/com/tubb/smrv/SwipeMenuGridView.java @@ -29,12 +29,15 @@ protected void init() { mHelper = new SwipeMenuHelper(getContext(), this); } + @Override + public boolean dispatchTouchEvent(MotionEvent ev) { + return mHelper.handleDispatchTouchEvent(ev) || super.dispatchTouchEvent(ev); + } + @Override public boolean onInterceptTouchEvent(MotionEvent ev) { boolean isIntercepted = super.onInterceptTouchEvent(ev); - // ignore Multi-Touch - if (ev.getActionIndex() != 0) return true; - int action = ev.getAction(); + int action = ev.getActionMasked(); switch (action) { case MotionEvent.ACTION_DOWN: isIntercepted = mHelper.handleListDownTouchEvent(ev, isIntercepted); diff --git a/library/src/main/java/com/tubb/smrv/SwipeMenuHelper.java b/library/src/main/java/com/tubb/smrv/SwipeMenuHelper.java index 2c40e71..742fe6a 100644 --- a/library/src/main/java/com/tubb/smrv/SwipeMenuHelper.java +++ b/library/src/main/java/com/tubb/smrv/SwipeMenuHelper.java @@ -1,6 +1,7 @@ package com.tubb.smrv; import android.content.Context; +import android.support.annotation.Nullable; import android.support.v4.view.ViewCompat; import android.view.MotionEvent; import android.view.View; @@ -28,6 +29,15 @@ public SwipeMenuHelper(Context context, Callback callback) { mViewConfig = ViewConfiguration.get(context); } + public boolean handleDispatchTouchEvent(MotionEvent ev) { + int action = ev.getActionMasked(); + switch (action) { + case MotionEvent.ACTION_POINTER_DOWN: + return true; + } + return false; + } + /** * Handle touch down event, decide whether intercept or not. * @param ev Touch event @@ -52,7 +62,7 @@ public boolean handleListDownTouchEvent(MotionEvent ev, boolean defaultIntercept } touchingView = mCallback.transformTouchingView(touchingPosition, touchingView); if (touchingView != null) { - View itemView = getSwipeMenuView((ViewGroup) touchingView); + View itemView = getSwipeMenuView(touchingView); if (itemView != null && itemView instanceof SwipeHorizontalMenuLayout) { mOldSwipedView = (SwipeHorizontalMenuLayout) itemView; mOldTouchedPosition = touchingPosition; @@ -66,7 +76,7 @@ public boolean handleListDownTouchEvent(MotionEvent ev, boolean defaultIntercept return isIntercepted; } - public View getSwipeMenuView(ViewGroup itemView) { + public View getSwipeMenuView(View itemView) { if (itemView instanceof SwipeHorizontalMenuLayout) { return itemView; } @@ -96,6 +106,7 @@ public View getSwipeMenuView(ViewGroup itemView) { * @param y Vertical position in pixels to search * @return The child view under (x, y) or null if no matching child is found */ + @Nullable public View findChildViewUnder(float x, float y) { final int count = mCallback.getRealChildCount(); for (int i = count - 1; i >= 0; i--) { diff --git a/library/src/main/java/com/tubb/smrv/SwipeMenuLayout.java b/library/src/main/java/com/tubb/smrv/SwipeMenuLayout.java index 4cd0704..d34ac1c 100644 --- a/library/src/main/java/com/tubb/smrv/SwipeMenuLayout.java +++ b/library/src/main/java/com/tubb/smrv/SwipeMenuLayout.java @@ -73,25 +73,25 @@ public SwipeMenuLayout(Context context, AttributeSet attrs, int defStyle) { } public void smoothOpenBeginMenu() { - if (mBeginSwiper == null) throw new IllegalArgumentException("Not have begin menu!"); + if (mBeginSwiper == null) throw new IllegalArgumentException("No begin menu!"); mCurrentSwiper = mBeginSwiper; smoothOpenMenu(); } public void smoothOpenEndMenu() { - if (mEndSwiper == null) throw new IllegalArgumentException("Not have end menu!"); + if (mEndSwiper == null) throw new IllegalArgumentException("No end menu!"); mCurrentSwiper = mEndSwiper; smoothOpenMenu(); } public void smoothCloseBeginMenu() { - if (mBeginSwiper == null) throw new IllegalArgumentException("Not have begin menu!"); + if (mBeginSwiper == null) throw new IllegalArgumentException("No begin menu!"); mCurrentSwiper = mBeginSwiper; smoothCloseMenu(); } public void smoothCloseEndMenu() { - if (mEndSwiper == null) throw new IllegalArgumentException("Not have end menu!"); + if (mEndSwiper == null) throw new IllegalArgumentException("No end menu!"); mCurrentSwiper = mEndSwiper; smoothCloseMenu(); } diff --git a/library/src/main/java/com/tubb/smrv/SwipeMenuListView.java b/library/src/main/java/com/tubb/smrv/SwipeMenuListView.java index 6f40d04..65dee00 100644 --- a/library/src/main/java/com/tubb/smrv/SwipeMenuListView.java +++ b/library/src/main/java/com/tubb/smrv/SwipeMenuListView.java @@ -29,12 +29,15 @@ protected void init() { mHelper = new SwipeMenuHelper(getContext(), this); } + @Override + public boolean dispatchTouchEvent(MotionEvent ev) { + return mHelper.handleDispatchTouchEvent(ev) || super.dispatchTouchEvent(ev); + } + @Override public boolean onInterceptTouchEvent(MotionEvent ev) { boolean isIntercepted = super.onInterceptTouchEvent(ev); - // ignore Multi-Touch - if (ev.getActionIndex() != 0) return true; - int action = ev.getAction(); + int action = ev.getActionMasked(); switch (action) { case MotionEvent.ACTION_DOWN: isIntercepted = mHelper.handleListDownTouchEvent(ev, isIntercepted); diff --git a/library/src/main/java/com/tubb/smrv/SwipeMenuRecyclerView.java b/library/src/main/java/com/tubb/smrv/SwipeMenuRecyclerView.java index e653a07..ea5aaf2 100644 --- a/library/src/main/java/com/tubb/smrv/SwipeMenuRecyclerView.java +++ b/library/src/main/java/com/tubb/smrv/SwipeMenuRecyclerView.java @@ -30,14 +30,17 @@ protected void init() { } @Override - public boolean onInterceptTouchEvent(MotionEvent ev) { - boolean isIntercepted = super.onInterceptTouchEvent(ev); - // ignore Multi-Touch - if (ev.getActionIndex() != 0) return true; - int action = ev.getAction(); + public boolean dispatchTouchEvent(MotionEvent ev) { + return mHelper.handleDispatchTouchEvent(ev) || super.dispatchTouchEvent(ev); + } + + @Override + public boolean onInterceptTouchEvent(MotionEvent event) { + boolean isIntercepted = super.onInterceptTouchEvent(event); + int action = event.getActionMasked(); switch (action) { case MotionEvent.ACTION_DOWN: - isIntercepted = mHelper.handleListDownTouchEvent(ev, isIntercepted); + isIntercepted = mHelper.handleListDownTouchEvent(event, isIntercepted); break; } return isIntercepted; diff --git a/library/src/main/java/com/tubb/smrv/SwipeMenuScrollView.java b/library/src/main/java/com/tubb/smrv/SwipeMenuScrollView.java index cc927b4..52db5ab 100644 --- a/library/src/main/java/com/tubb/smrv/SwipeMenuScrollView.java +++ b/library/src/main/java/com/tubb/smrv/SwipeMenuScrollView.java @@ -1,10 +1,8 @@ package com.tubb.smrv; import android.content.Context; -import android.support.v4.view.ViewCompat; -import android.support.v7.widget.RecyclerView; +import android.support.annotation.Nullable; import android.util.AttributeSet; -import android.util.Log; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; @@ -56,12 +54,15 @@ protected void onFinishInflate() { } } + @Override + public boolean dispatchTouchEvent(MotionEvent ev) { + return mHelper.handleDispatchTouchEvent(ev) || super.dispatchTouchEvent(ev); + } + @Override public boolean onInterceptTouchEvent(MotionEvent ev) { boolean isIntercepted = super.onInterceptTouchEvent(ev); - // ignore Multi-Touch - if (ev.getActionIndex() != 0) return true; - int action = ev.getAction(); + int action = ev.getActionMasked(); switch (action) { case MotionEvent.ACTION_DOWN: isIntercepted = mHelper.handleListDownTouchEvent(ev, isIntercepted); @@ -110,6 +111,7 @@ protected Helper(Context context, Callback callback) { super(context, callback); } + @Nullable @Override public View findChildViewUnder(float x, float y) { if (menuLayoutList != null) { diff --git a/library/src/main/java/com/tubb/smrv/SwipeVerticalMenuLayout.java b/library/src/main/java/com/tubb/smrv/SwipeVerticalMenuLayout.java index 60a01cd..8147c59 100644 --- a/library/src/main/java/com/tubb/smrv/SwipeVerticalMenuLayout.java +++ b/library/src/main/java/com/tubb/smrv/SwipeVerticalMenuLayout.java @@ -3,7 +3,6 @@ import android.content.Context; import android.support.v4.view.ViewCompat; import android.util.AttributeSet; -import android.util.Log; import android.view.MotionEvent; import android.view.VelocityTracker; import android.view.View; @@ -34,7 +33,7 @@ public SwipeVerticalMenuLayout(Context context, AttributeSet attrs, int defStyle @Override public boolean onInterceptTouchEvent(MotionEvent ev) { boolean isIntercepted = super.onInterceptTouchEvent(ev); - int action = ev.getAction(); + int action = ev.getActionMasked(); switch (action) { case MotionEvent.ACTION_DOWN: mDownX = mLastX = (int) ev.getX(); @@ -71,7 +70,7 @@ public boolean onTouchEvent(MotionEvent ev) { mVelocityTracker.addMovement(ev); int dx; int dy; - int action = ev.getAction(); + int action = ev.getActionMasked(); switch (action) { case MotionEvent.ACTION_DOWN: mLastX = (int) ev.getX();