diff --git a/README-cn.md b/README-cn.md index 6d14ee9..0683982 100755 --- a/README-cn.md +++ b/README-cn.md @@ -65,7 +65,7 @@ Github: https://github.com/liaohuqiu 项目已经发布到了Maven中央库,包括`aar`和`apklib`两种格式。在Maven或者Gradle下可如下直接引入: -最新版版本号: `1.0.9.1-SNAPSHOT`, 发布到了: https://oss.sonatype.org/content/repositories/snapshots +最新版版本号: `1.0.9.2-SNAPSHOT`, 发布到了: https://oss.sonatype.org/content/repositories/snapshots 在gradle中: @@ -92,7 +92,7 @@ mavenCentral() aar - 1.0.9.1-SNAPSHOT + 1.0.9.2-SNAPSHOT 稳定版 @@ -111,7 +111,7 @@ mavenCentral() gradle / Android Studio, 最新版 ``` -compile 'in.srain.cube:ultra-ptr:1.0.9.1-SNAPSHOT' +compile 'in.srain.cube:ultra-ptr:1.0.9.2-SNAPSHOT' ``` gradle / Android Studio, 稳定版 diff --git a/README.md b/README.md index 11377b1..b54adf9 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,3 @@ -[![Android Gems](http://www.android-gems.com/badge/liaohuqiu/android-Ultra-Pull-To-Refresh.svg?a=b)](http://www.android-gems.com/lib/liaohuqiu/android-Ultra-Pull-To-Refresh) - ###### [Please follow me on GitHub, I need your support](http://www.liaohuqiu.net/posts/follow-me-on-github/) Github: https://github.com/liaohuqiu @@ -66,7 +64,7 @@ Support `API LEVEL >= 8`, all snapshots are taken from Genymotion, 2.3.7. This project has been pushed to Maven Central, both in `aar` and `apklib`. -The latest version: `1.0.9.1-SNAPSHOT`, has been published to: https://oss.sonatype.org/content/repositories/snapshots, in gradle: +The latest version: `1.0.9.2-SNAPSHOT`, has been published to: https://oss.sonatype.org/content/repositories/snapshots, in gradle: ``` maven { @@ -89,7 +87,7 @@ pom.xml, latest version: aar - 1.0.9.1-SNAPSHOT + 1.0.9.2-SNAPSHOT ``` @@ -109,7 +107,7 @@ pom.xml, stable version: gradle, latest version: ``` -compile 'in.srain.cube:ultra-ptr:1.0.9.1-SNAPSHOT' +compile 'in.srain.cube:ultra-ptr:1.0.9.2-SNAPSHOT' ``` gradle, stable version: diff --git a/ptr-demo/pom.xml b/ptr-demo/pom.xml index 1214227..3a90fc9 100755 --- a/ptr-demo/pom.xml +++ b/ptr-demo/pom.xml @@ -31,7 +31,7 @@ in.srain.cube ultra-ptr aar - 1.0.9.1-SNAPSHOT + 1.0.9.2-SNAPSHOT in.srain.cube diff --git a/ptr-demo/res/drawable/text_view_bg.xml b/ptr-demo/res/drawable/text_view_bg.xml index 65bb1f9..f661f85 100644 --- a/ptr-demo/res/drawable/text_view_bg.xml +++ b/ptr-demo/res/drawable/text_view_bg.xml @@ -1,5 +1,5 @@ - - + + \ No newline at end of file diff --git a/ptr-demo/res/layout/fragment_classic_header_with_scroll_view.xml b/ptr-demo/res/layout/fragment_classic_header_with_scroll_view.xml new file mode 100644 index 0000000..1d27d07 --- /dev/null +++ b/ptr-demo/res/layout/fragment_classic_header_with_scroll_view.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ptr-demo/res/values/strings.xml b/ptr-demo/res/values/strings.xml index 96f3efc..96f2c98 100755 --- a/ptr-demo/res/values/strings.xml +++ b/ptr-demo/res/values/strings.xml @@ -7,6 +7,7 @@ Contains A GridView Contains A ListView Contains A WebView + Contains ScrollView Contains A FrameLayout Contains Even A TextView EmptyView and ListView diff --git a/ptr-demo/src/in/srain/cube/views/ptr/demo/ui/PtrDemoHomeFragment.java b/ptr-demo/src/in/srain/cube/views/ptr/demo/ui/PtrDemoHomeFragment.java index a0de458..6a555df 100644 --- a/ptr-demo/src/in/srain/cube/views/ptr/demo/ui/PtrDemoHomeFragment.java +++ b/ptr-demo/src/in/srain/cube/views/ptr/demo/ui/PtrDemoHomeFragment.java @@ -62,6 +62,7 @@ public void onClick(View v) { getContext().pushFragmentToBackStack(WithWebView.class, null); } })); + itemInfos.add(newItemInfo(R.string.ptr_demo_block_with_list_view_and_empty_view, R.color.cube_mints_4d90fe, new OnClickListener() { @Override @@ -70,6 +71,16 @@ public void onClick(View v) { } })); + itemInfos.add(newItemInfo(R.string.ptr_demo_block_scroll_view, R.color.cube_mints_4d90fe, new OnClickListener() { + + @Override + public void onClick(View v) { + getContext().pushFragmentToBackStack(WithScrollView.class, null); + } + })); + itemInfos.add(null); + itemInfos.add(null); + itemInfos.add(newItemInfo(R.string.ptr_demo_block_keep_header, R.color.cube_mints_4d90fe, new OnClickListener() { @Override @@ -84,7 +95,6 @@ public void onClick(View v) { getContext().pushFragmentToBackStack(HideHeader.class, null); } })); - itemInfos.add(null); itemInfos.add(newItemInfo(R.string.ptr_demo_block_release_to_refresh, R.color.cube_mints_4d90fe, new OnClickListener() { @@ -108,6 +118,7 @@ public void onClick(View v) { getContext().pushFragmentToBackStack(AutoRefresh.class, null); } })); + itemInfos.add(null); itemInfos.add(newItemInfo(R.string.ptr_demo_block_storehouse_header_using_string_array, R.color.cube_mints_4d90fe, new OnClickListener() { diff --git a/ptr-demo/src/in/srain/cube/views/ptr/demo/ui/classic/WithScrollView.java b/ptr-demo/src/in/srain/cube/views/ptr/demo/ui/classic/WithScrollView.java new file mode 100644 index 0000000..39313e0 --- /dev/null +++ b/ptr-demo/src/in/srain/cube/views/ptr/demo/ui/classic/WithScrollView.java @@ -0,0 +1,63 @@ +package in.srain.cube.views.ptr.demo.ui.classic; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ScrollView; +import in.srain.cube.mints.base.TitleBaseFragment; +import in.srain.cube.views.ptr.PtrClassicFrameLayout; +import in.srain.cube.views.ptr.PtrDefaultHandler; +import in.srain.cube.views.ptr.PtrFrameLayout; +import in.srain.cube.views.ptr.PtrHandler; +import in.srain.cube.views.ptr.demo.R; + +public class WithScrollView extends TitleBaseFragment { + + private PtrClassicFrameLayout mPtrFrame; + private ScrollView mScrollView; + + @Override + public View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + + setHeaderTitle(R.string.ptr_demo_block_scroll_view); + + final View contentView = inflater.inflate(R.layout.fragment_classic_header_with_scroll_view, null); + mScrollView = (ScrollView) contentView.findViewById(R.id.rotate_header_scroll_view); + mPtrFrame = (PtrClassicFrameLayout) contentView.findViewById(R.id.rotate_header_web_view_frame); + mPtrFrame.setLastUpdateTimeRelateObject(this); + mPtrFrame.setPtrHandler(new PtrHandler() { + @Override + public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) { + return PtrDefaultHandler.checkContentCanBePulledDown(frame, mScrollView, header); + } + + @Override + public void onRefreshBegin(PtrFrameLayout frame) { + mPtrFrame.postDelayed(new Runnable() { + @Override + public void run() { + mPtrFrame.refreshComplete(); + } + }, 100); + } + }); + + // the following are default settings + mPtrFrame.setResistance(1.7f); + mPtrFrame.setRatioOfHeaderHeightToRefresh(1.2f); + mPtrFrame.setDurationToClose(200); + mPtrFrame.setDurationToCloseHeader(1000); + // default is false + mPtrFrame.setPullToRefresh(false); + // default is true + mPtrFrame.setKeepHeaderWhenRefresh(true); + mPtrFrame.postDelayed(new Runnable() { + @Override + public void run() { + mPtrFrame.autoRefresh(); + } + }, 100); + return contentView; + } +} \ No newline at end of file diff --git a/ptr-demo/src/in/srain/cube/views/ptr/demo/ui/classic/WithWebView.java b/ptr-demo/src/in/srain/cube/views/ptr/demo/ui/classic/WithWebView.java index 43b9268..8a4dc23 100755 --- a/ptr-demo/src/in/srain/cube/views/ptr/demo/ui/classic/WithWebView.java +++ b/ptr-demo/src/in/srain/cube/views/ptr/demo/ui/classic/WithWebView.java @@ -8,6 +8,7 @@ import android.webkit.WebViewClient; import in.srain.cube.mints.base.TitleBaseFragment; import in.srain.cube.views.ptr.PtrClassicFrameLayout; +import in.srain.cube.views.ptr.PtrDefaultHandler; import in.srain.cube.views.ptr.PtrFrameLayout; import in.srain.cube.views.ptr.PtrHandler; import in.srain.cube.views.ptr.demo.R; @@ -34,13 +35,13 @@ public void onPageFinished(WebView view, String url) { mPtrFrame.setLastUpdateTimeRelateObject(this); mPtrFrame.setPtrHandler(new PtrHandler() { @Override - public void onRefreshBegin(PtrFrameLayout frame) { - updateData(); + public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) { + return PtrDefaultHandler.checkContentCanBePulledDown(frame, mWebView, header); } @Override - public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) { - return mWebView.getScrollY() == 0; + public void onRefreshBegin(PtrFrameLayout frame) { + updateData(); } }); // the following are default settings diff --git a/ptr-lib/gradle.properties b/ptr-lib/gradle.properties index be1397c..1464131 100644 --- a/ptr-lib/gradle.properties +++ b/ptr-lib/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=1.0.9.1-SNAPSHOT +VERSION_NAME=1.0.9.2-SNAPSHOT POM_GROUP=in.srain.cube POM_ARTIFACT_ID=ultra-ptr diff --git a/ptr-lib/pom.xml b/ptr-lib/pom.xml index e2575bd..690b966 100755 --- a/ptr-lib/pom.xml +++ b/ptr-lib/pom.xml @@ -13,7 +13,7 @@ ultra-ptr aar Ultra Pull to Refresh - 1.0.9.1-SNAPSHOT + 1.0.9.2-SNAPSHOT Ultra Pull to Refresh in Android https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh diff --git a/ptr-lib/src/in/srain/cube/views/ptr/PtrFrameLayout.java b/ptr-lib/src/in/srain/cube/views/ptr/PtrFrameLayout.java index 0b5231f..ef8770b 100755 --- a/ptr-lib/src/in/srain/cube/views/ptr/PtrFrameLayout.java +++ b/ptr-lib/src/in/srain/cube/views/ptr/PtrFrameLayout.java @@ -59,7 +59,6 @@ public class PtrFrameLayout extends ViewGroup { // disable when detect moving horizontally private boolean mPreventForHorizontal = false; - private MotionEvent mDownEvent; private MotionEvent mLastMoveEvent; private PtrUIHandlerHook mRefreshCompleteHook; @@ -279,7 +278,6 @@ public boolean dispatchTouchEvent(MotionEvent e) { case MotionEvent.ACTION_DOWN: mHasSendCancelEvent = false; - mDownEvent = e; mPtrIndicator.onPressDown(e.getX(), e.getY()); mScrollChecker.abortIfWorking(); @@ -288,7 +286,8 @@ public boolean dispatchTouchEvent(MotionEvent e) { // The cancel event will be sent once the position is moved. // So let the event pass to children. // fix #93, #102 - return dispatchTouchEventSupper(e); + dispatchTouchEventSupper(e); + return true; case MotionEvent.ACTION_MOVE: mLastMoveEvent = e; @@ -905,8 +904,12 @@ private void sendCancelEvent() { if (DEBUG) { PtrCLog.d(LOG_TAG, "send cancel event"); } - MotionEvent last = mDownEvent; - last = mLastMoveEvent; + // The ScrollChecker will update position and lead to send cancel event when mLastMoveEvent is null. + // fix #104, #80, #92 + if (mLastMoveEvent == null) { + return; + } + MotionEvent last = mLastMoveEvent; MotionEvent e = MotionEvent.obtain(last.getDownTime(), last.getEventTime() + ViewConfiguration.getLongPressTimeout(), MotionEvent.ACTION_CANCEL, last.getX(), last.getY(), last.getMetaState()); dispatchTouchEventSupper(e); } diff --git a/update-project.py b/update-project.py index 10dfc33..d69213c 100644 --- a/update-project.py +++ b/update-project.py @@ -1,6 +1,6 @@ import os vars = { - 'ptr_lib_version': '1.0.9.1-SNAPSHOT', + 'ptr_lib_version': '1.0.9.2-SNAPSHOT', 'ptr_lib_stable_version': '1.0.9', 'cube_sdk_version': '1.0.44.39-SNAPSHOT' }