diff --git a/README-cn.md b/README-cn.md
index 967e828..7cd377a 100755
--- a/README-cn.md
+++ b/README-cn.md
@@ -58,7 +58,7 @@
in.srain.cube
ultra-ptr
apklib
- 1.0.6
+ 1.0.7
```
或者
@@ -68,13 +68,13 @@
in.srain.cube
ultra-ptr
aar
- 1.0.6
+ 1.0.7
```
gradle / Android Studio
```
-compile 'in.srain.cube:ultra-ptr:1.0.6@aar'
+compile 'in.srain.cube:ultra-ptr:1.0.7@aar'
```
#### 配置
@@ -244,6 +244,12 @@ ptrFrame.setPtrHandler(new PtrHandler() {
});
```
+# 常见问题
+
+* ViewPager滑动冲突: `disableWhenHorizontalMove()`
+
+* 长按LongPressed, `setInterceptEventWhileWorking()`
+
# License
diff --git a/README.md b/README.md
index bdc64c7..0a1b291 100755
--- a/README.md
+++ b/README.md
@@ -61,7 +61,7 @@ pom.xml
in.srain.cube
ultra-ptr
apklib
- 1.0.6
+ 1.0.7
```
or
@@ -71,13 +71,13 @@ or
in.srain.cube
ultra-ptr
aar
- 1.0.6
+ 1.0.7
```
gradle
```
-compile 'in.srain.cube:ultra-ptr:1.0.6@aar'
+compile 'in.srain.cube:ultra-ptr:1.0.7@aar'
```
#### Config
@@ -280,6 +280,11 @@ public interface PtrUIHandler {
}
```
+# Q & A
+
+* work with ViewPager: `disableWhenHorizontalMove()`
+
+* work with LongPressed, `setInterceptEventWhileWorking()`
# License
diff --git a/build-template.py b/build-template.py
index 4228025..48159e2 100644
--- a/build-template.py
+++ b/build-template.py
@@ -1,6 +1,6 @@
import os
vars = {
- 'ptr_lib_version': '1.0.6',
+ 'ptr_lib_version': '1.0.7',
'cube_sdk_version': '1.0.43-SNAPSHOT'
}
diff --git a/ptr-demo/AndroidManifest.xml b/ptr-demo/AndroidManifest.xml
index c720bf3..23b8346 100755
--- a/ptr-demo/AndroidManifest.xml
+++ b/ptr-demo/AndroidManifest.xml
@@ -27,6 +27,10 @@
+
+
\ No newline at end of file
diff --git a/ptr-demo/pom.xml b/ptr-demo/pom.xml
index 51d04c2..53f1a75 100755
--- a/ptr-demo/pom.xml
+++ b/ptr-demo/pom.xml
@@ -37,7 +37,7 @@
in.srain.cube
ultra-ptr
aar
- 1.0.6
+ 1.0.7
in.srain.cube
diff --git a/ptr-demo/res/drawable/text_view_bg.xml b/ptr-demo/res/drawable/text_view_bg.xml
new file mode 100644
index 0000000..65bb1f9
--- /dev/null
+++ b/ptr-demo/res/drawable/text_view_bg.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/ptr-demo/res/layout/activity_main.xml b/ptr-demo/res/layout/activity_main.xml
index e2d80d2..8687897 100755
--- a/ptr-demo/res/layout/activity_main.xml
+++ b/ptr-demo/res/layout/activity_main.xml
@@ -1,7 +1,7 @@
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/ptr-demo/res/layout/fragment_classic_header_with_list_view.xml b/ptr-demo/res/layout/fragment_classic_header_with_list_view.xml
index d1fc249..1ea893e 100755
--- a/ptr-demo/res/layout/fragment_classic_header_with_list_view.xml
+++ b/ptr-demo/res/layout/fragment_classic_header_with_list_view.xml
@@ -25,7 +25,8 @@
android:listSelector="@android:color/transparent"
android:paddingLeft="12dp"
android:paddingRight="12dp"
- android:scrollbarStyle="outsideOverlay" />
+ android:scrollbarStyle="outsideOverlay"
+ android:choiceMode="singleChoice" />
\ No newline at end of file
diff --git a/ptr-demo/res/layout/fragment_classic_header_with_textview.xml b/ptr-demo/res/layout/fragment_classic_header_with_textview.xml
index 088bf14..9af9985 100755
--- a/ptr-demo/res/layout/fragment_classic_header_with_textview.xml
+++ b/ptr-demo/res/layout/fragment_classic_header_with_textview.xml
@@ -22,7 +22,8 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="@dimen/cube_mints_content_view_padding"
- android:background="@color/cube_mints_4d90fe"
+ android:clickable="true"
+ android:background="@drawable/text_view_bg"
android:gravity="center"
android:text="I am a TextView"
android:textColor="@color/cube_mints_white"
diff --git a/ptr-demo/res/layout/fragment_view_pager.xml b/ptr-demo/res/layout/fragment_view_pager.xml
new file mode 100644
index 0000000..e34b3d2
--- /dev/null
+++ b/ptr-demo/res/layout/fragment_view_pager.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/ptr-demo/res/layout/view_pager_fragment_list_view_header.xml b/ptr-demo/res/layout/view_pager_fragment_list_view_header.xml
new file mode 100644
index 0000000..3323d70
--- /dev/null
+++ b/ptr-demo/res/layout/view_pager_fragment_list_view_header.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
diff --git a/ptr-demo/res/layout/view_pager_indicator_item.xml b/ptr-demo/res/layout/view_pager_indicator_item.xml
new file mode 100644
index 0000000..69a7a1e
--- /dev/null
+++ b/ptr-demo/res/layout/view_pager_indicator_item.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/ptr-demo/res/values/strings.xml b/ptr-demo/res/values/strings.xml
index 69ecde0..e16f81c 100755
--- a/ptr-demo/res/values/strings.xml
+++ b/ptr-demo/res/values/strings.xml
@@ -17,7 +17,7 @@
Keep Header while Refreshing
Hide Header while Refreshing
Long Press
- ViewPager
+ View Pager
StoreHouse Style \nusing string array from xml
using xml:
StoreHouse Style \n\nusing string
diff --git a/ptr-demo/src/in/srain/cube/views/ptr/demo/ui/HomeFragment.java b/ptr-demo/src/in/srain/cube/views/ptr/demo/ui/HomeFragment.java
index d323246..4a99276 100755
--- a/ptr-demo/src/in/srain/cube/views/ptr/demo/ui/HomeFragment.java
+++ b/ptr-demo/src/in/srain/cube/views/ptr/demo/ui/HomeFragment.java
@@ -1,5 +1,6 @@
package in.srain.cube.views.ptr.demo.ui;
+import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
@@ -15,6 +16,7 @@
import in.srain.cube.views.ptr.demo.ui.storehouse.StoreHouseUsingPointList;
import in.srain.cube.views.ptr.demo.ui.storehouse.StoreHouseUsingString;
import in.srain.cube.views.ptr.demo.ui.storehouse.StoreHouseUsingStringArray;
+import in.srain.cube.views.ptr.demo.ui.viewpager.ViewPagerActivity;
import in.srain.cube.views.ptr.header.StoreHouseHeader;
import java.util.ArrayList;
@@ -136,10 +138,13 @@ public void onClick(View v) {
getContext().pushFragmentToBackStack(WithLongPressFragment.class, null);
}
}));
- itemInfos.add(newItemInfo(R.string.ptr_demo_placeholder, R.color.cube_mints_4d90fe, new OnClickListener() {
+ itemInfos.add(newItemInfo(R.string.ptr_demo_block_with_view_pager, R.color.cube_mints_4d90fe, new OnClickListener() {
@Override
public void onClick(View v) {
+ Intent intent = new Intent();
+ intent.setClass(getContext(), ViewPagerActivity.class);
+ startActivity(intent);
}
}));
itemInfos.add(newItemInfo(R.string.ptr_demo_placeholder, R.color.cube_mints_4d90fe, new OnClickListener() {
diff --git a/ptr-demo/src/in/srain/cube/views/ptr/demo/ui/classic/WithListView.java b/ptr-demo/src/in/srain/cube/views/ptr/demo/ui/classic/WithListView.java
index 201d0f6..bbef6de 100755
--- a/ptr-demo/src/in/srain/cube/views/ptr/demo/ui/classic/WithListView.java
+++ b/ptr-demo/src/in/srain/cube/views/ptr/demo/ui/classic/WithListView.java
@@ -118,7 +118,6 @@ public View createView(LayoutInflater inflater) {
@Override
public void showData(int position, JsonData itemData) {
- CLog.d("test", "%s", itemData);
mImageView.loadImage(mImageLoader, itemData.optString("pic"));
}
}
diff --git a/ptr-demo/src/in/srain/cube/views/ptr/demo/ui/viewpager/ImageListViewHolder.java b/ptr-demo/src/in/srain/cube/views/ptr/demo/ui/viewpager/ImageListViewHolder.java
new file mode 100644
index 0000000..1ba1e47
--- /dev/null
+++ b/ptr-demo/src/in/srain/cube/views/ptr/demo/ui/viewpager/ImageListViewHolder.java
@@ -0,0 +1,33 @@
+package in.srain.cube.views.ptr.demo.ui.viewpager;
+
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.ImageView;
+import in.srain.cube.image.CubeImageView;
+import in.srain.cube.image.ImageLoader;
+import in.srain.cube.request.JsonData;
+import in.srain.cube.views.list.ViewHolderBase;
+import in.srain.cube.views.ptr.demo.R;
+
+public class ImageListViewHolder extends ViewHolderBase {
+
+ private ImageLoader mImageLoader;
+ private CubeImageView mImageView;
+
+ private ImageListViewHolder(ImageLoader imageLoader) {
+ mImageLoader = imageLoader;
+ }
+
+ @Override
+ public View createView(LayoutInflater inflater) {
+ View v = inflater.inflate(R.layout.list_view_item, null);
+ mImageView = (CubeImageView) v.findViewById(R.id.list_view_item_image_view);
+ mImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
+ return v;
+ }
+
+ @Override
+ public void showData(int position, JsonData itemData) {
+ mImageView.loadImage(mImageLoader, itemData.optString("pic"));
+ }
+}
diff --git a/ptr-demo/src/in/srain/cube/views/ptr/demo/ui/viewpager/ViewPagerActivity.java b/ptr-demo/src/in/srain/cube/views/ptr/demo/ui/viewpager/ViewPagerActivity.java
new file mode 100644
index 0000000..d5387c5
--- /dev/null
+++ b/ptr-demo/src/in/srain/cube/views/ptr/demo/ui/viewpager/ViewPagerActivity.java
@@ -0,0 +1,178 @@
+package in.srain.cube.views.ptr.demo.ui.viewpager;
+
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentManager;
+import android.support.v4.app.FragmentStatePagerAdapter;
+import android.support.v4.view.ViewPager;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.AbsListView;
+import android.widget.TextView;
+import in.srain.cube.mints.base.TitleBaseActivity;
+import in.srain.cube.request.JsonData;
+import in.srain.cube.request.RequestFinishHandler;
+import in.srain.cube.util.LocalDisplay;
+import in.srain.cube.views.pager.TabPageIndicator;
+import in.srain.cube.views.ptr.PtrClassicFrameLayout;
+import in.srain.cube.views.ptr.PtrFrameLayout;
+import in.srain.cube.views.ptr.PtrHandler;
+import in.srain.cube.views.ptr.demo.R;
+import in.srain.cube.views.ptr.demo.data.DemoRequestData;
+
+import java.util.ArrayList;
+
+public class ViewPagerActivity extends TitleBaseActivity {
+
+ private TabPageIndicator mCatTabPageIndicator;
+ private ViewPager mFragmentViewPager;
+ private FragmentViewPagerAdapter mPagerAdapter;
+ private PtrFrameLayout mPtrFrame;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setHeaderTitle(R.string.ptr_demo_block_with_view_pager);
+ setContentView(R.layout.activity_view_pager);
+ initCateViews();
+ }
+
+ private void initCateViews() {
+
+ int startIndex = 0;
+
+ mCatTabPageIndicator = (TabPageIndicator) findViewById(R.id.view_pager_tab_indicator);
+ mFragmentViewPager = (ViewPager) this.findViewById(R.id.view_pager_view_pager);
+ ArrayList list = new ArrayList();
+
+ for (int i = 1; i <= 8; i++) {
+ list.add(ViewPagerFragment.create(i));
+ }
+ mPagerAdapter = new FragmentViewPagerAdapter(getSupportFragmentManager(), list);
+ mFragmentViewPager.setAdapter(mPagerAdapter);
+
+ mCatTabPageIndicator.setViewHolderCreator(new TabPageIndicator.ViewHolderCreator() {
+ @Override
+ public TabPageIndicator.ViewHolderBase createViewHolder() {
+ return new HomeCatItemViewHolder();
+ }
+ });
+ mCatTabPageIndicator.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
+
+ @Override
+ public void onPageSelected(int i) {
+ switchTo(i);
+ }
+ });
+ mCatTabPageIndicator.setViewPager(mFragmentViewPager);
+
+ mPtrFrame = (PtrClassicFrameLayout) findViewById(R.id.view_pager_ptr_frame);
+ mPtrFrame.disableWhenHorizontalMove(true);
+ mPtrFrame.setPtrHandler(new PtrHandler() {
+ @Override
+ public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {
+ return mPagerAdapter.checkCanDoRefresh();
+ }
+
+ @Override
+ public void onRefreshBegin(PtrFrameLayout frame) {
+ mPagerAdapter.updateData();
+ }
+ });
+ mFragmentViewPager.setCurrentItem(startIndex);
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ mCatTabPageIndicator.moveToItem(mFragmentViewPager.getCurrentItem());
+ }
+
+ private void switchTo(int position) {
+ mPagerAdapter.switchTO(position);
+ }
+
+ private class FragmentViewPagerAdapter extends FragmentStatePagerAdapter {
+
+ private final ArrayList mViewPagerFragments;
+ private ViewPagerFragment mCurrentFragment;
+
+ public FragmentViewPagerAdapter(FragmentManager fm, ArrayList list) {
+ super(fm);
+ mViewPagerFragments = list;
+ }
+
+ @Override
+ public void destroyItem(ViewGroup container, int position, Object object) {
+ }
+
+ @Override
+ public Fragment getItem(int position) {
+ return mViewPagerFragments.get(position);
+ }
+
+ protected void updateData() {
+ final ViewPagerFragment fragment = mCurrentFragment;
+ DemoRequestData.getImageList(new RequestFinishHandler() {
+ @Override
+ public void onRequestFinish(final JsonData data) {
+ if (fragment == mCurrentFragment) {
+ fragment.update(data);
+ mPtrFrame.refreshComplete();
+ }
+ }
+ });
+ }
+
+ @Override
+ public int getCount() {
+ return mViewPagerFragments.size();
+ }
+
+ public void switchTO(final int position) {
+ int len = mViewPagerFragments.size();
+ for (int i = 0; i < len; i++) {
+ ViewPagerFragment fragment = mViewPagerFragments.get(i);
+ if (i == position) {
+ mCurrentFragment = fragment;
+ fragment.show();
+ } else {
+ fragment.hide();
+ }
+ }
+ }
+
+ public boolean checkCanDoRefresh() {
+ if (mCurrentFragment == null) {
+ return true;
+ }
+ return mCurrentFragment.checkCanDoRefresh();
+ }
+ }
+
+ private class HomeCatItemViewHolder extends TabPageIndicator.ViewHolderBase {
+
+ private TextView mNameView;
+ private View mTagView;
+
+ @Override
+ public View createView(LayoutInflater layoutInflater, int position) {
+ View view = layoutInflater.inflate(R.layout.view_pager_indicator_item, null);
+ view.setLayoutParams(new AbsListView.LayoutParams(LocalDisplay.dp2px(40), -1));
+ mNameView = (TextView) view.findViewById(R.id.view_pager_indicator_name);
+ mTagView = view.findViewById(R.id.view_pager_indicator_tab_current);
+ return view;
+ }
+
+ @Override
+ public void updateView(int position, boolean isCurrent) {
+ mNameView.setText(position + "");
+ if (isCurrent) {
+ mTagView.setVisibility(View.VISIBLE);
+ } else {
+ mTagView.setVisibility(View.INVISIBLE);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/ptr-demo/src/in/srain/cube/views/ptr/demo/ui/viewpager/ViewPagerFragment.java b/ptr-demo/src/in/srain/cube/views/ptr/demo/ui/viewpager/ViewPagerFragment.java
new file mode 100644
index 0000000..5a65571
--- /dev/null
+++ b/ptr-demo/src/in/srain/cube/views/ptr/demo/ui/viewpager/ViewPagerFragment.java
@@ -0,0 +1,88 @@
+package in.srain.cube.views.ptr.demo.ui.viewpager;
+
+import android.os.Bundle;
+import android.text.TextUtils;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.ListView;
+import android.widget.TextView;
+import in.srain.cube.app.CubeFragment;
+import in.srain.cube.image.ImageLoader;
+import in.srain.cube.image.ImageLoaderFactory;
+import in.srain.cube.request.JsonData;
+import in.srain.cube.views.list.ListViewDataAdapter;
+import in.srain.cube.views.ptr.demo.R;
+import in.srain.cube.views.ptr.demo.ui.MaterialStyleFragment;
+
+public class ViewPagerFragment extends CubeFragment {
+
+ private int mPage;
+ private ListView mListView;
+ private ImageLoader mImageLoader;
+ private ListViewDataAdapter mAdapter;
+
+ public static ViewPagerFragment create(int page) {
+ ViewPagerFragment fragment = new ViewPagerFragment();
+ fragment.mPage = page;
+ return fragment;
+ }
+
+ @Override
+ protected View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ return null;
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ mImageLoader = ImageLoaderFactory.create(getContext()).tryToAttachToContainer(getContext());
+ View view = inflater.inflate(R.layout.fragment_view_pager, null);
+ mListView = (ListView) view.findViewById(R.id.view_pager_list_view);
+
+ View headerView = inflater.inflate(R.layout.view_pager_fragment_list_view_header, null);
+ TextView mHeaderTextView = (TextView) headerView.findViewById(R.id.view_pager_fragment_list_view_header_title);
+ mHeaderTextView.setBackgroundColor(0xff4d90fe * mPage / 30);
+ mHeaderTextView.setText("Page: " + mPage);
+
+ mListView.addHeaderView(headerView);
+ mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+ @Override
+ public void onItemClick(AdapterView> parent, View view, int position, long id) {
+ if (position >= 0) {
+ final String url = mAdapter.getItem(position).optString("pic");
+ if (!TextUtils.isEmpty(url)) {
+ getContext().pushFragmentToBackStack(MaterialStyleFragment.class, url);
+ }
+ }
+ }
+ });
+
+ mAdapter = new ListViewDataAdapter();
+ mAdapter.setViewHolderClass(this, ImageListViewHolder.class, mImageLoader);
+ mListView.setAdapter(mAdapter);
+ return view;
+ }
+
+ public void update(JsonData data) {
+ mAdapter.getDataList().clear();
+ mAdapter.getDataList().addAll(data.optJson("data").optJson("list").toArrayList());
+ mAdapter.notifyDataSetChanged();
+ }
+
+ public void show() {
+
+ }
+
+ public void hide() {
+
+ }
+
+ public boolean checkCanDoRefresh() {
+ if (mAdapter.getCount() == 0 || mListView == null) {
+ return true;
+ }
+ return mListView.getFirstVisiblePosition() == 0 && mListView.getChildAt(0).getTop() == 0;
+ }
+
+}
diff --git a/ptr-lib/gradle.properties b/ptr-lib/gradle.properties
index f88e822..0f60076 100644
--- a/ptr-lib/gradle.properties
+++ b/ptr-lib/gradle.properties
@@ -1,4 +1,4 @@
-VERSION_NAME=1.0.6
+VERSION_NAME=1.0.7
ANDROID_BUILD_MIN_SDK_VERSION=8
ANDROID_BUILD_TARGET_SDK_VERSION=16
diff --git a/ptr-lib/pom.xml b/ptr-lib/pom.xml
index c58034c..2e56352 100755
--- a/ptr-lib/pom.xml
+++ b/ptr-lib/pom.xml
@@ -13,7 +13,7 @@
ultra-ptr
aar
Ultra Pull to Refresh
- 1.0.6
+ 1.0.7
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 880f79b..b4cd871 100755
--- a/ptr-lib/src/in/srain/cube/views/ptr/PtrFrameLayout.java
+++ b/ptr-lib/src/in/srain/cube/views/ptr/PtrFrameLayout.java
@@ -266,6 +266,7 @@ public boolean dispatchTouchEvent(MotionEvent e) {
}
onRelease(false);
if (mCurrentPos != mPressedPos) {
+ sendCancelEvent();
return true;
}
return dispatchTouchEventSupper(e);
diff --git a/template/README-cn.md b/template/README-cn.md
index 5fc713a..2f44f58 100644
--- a/template/README-cn.md
+++ b/template/README-cn.md
@@ -244,6 +244,12 @@ ptrFrame.setPtrHandler(new PtrHandler() {
});
```
+# 常见问题
+
+* ViewPager滑动冲突: `disableWhenHorizontalMove()`
+
+* 长按LongPressed, `setInterceptEventWhileWorking()`
+
# License
diff --git a/template/README.md b/template/README.md
index 94557a5..2ccfd37 100644
--- a/template/README.md
+++ b/template/README.md
@@ -280,6 +280,11 @@ public interface PtrUIHandler {
}
```
+# Q & A
+
+* work with ViewPager: `disableWhenHorizontalMove()`
+
+* work with LongPressed, `setInterceptEventWhileWorking()`
# License