-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
190 additions
and
174 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 51 additions & 51 deletions
102
...m/hjq/demo/ui/activity/ImageActivity.java → ...m/hjq/demo/ui/activity/PhotoActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,52 @@ | ||
package com.hjq.demo.ui.activity; | ||
|
||
import android.support.v4.view.ViewPager; | ||
|
||
import com.hjq.demo.R; | ||
import com.hjq.demo.common.MyActivity; | ||
import com.hjq.demo.ui.adapter.ImagePagerAdapter; | ||
|
||
import java.util.ArrayList; | ||
|
||
import butterknife.BindView; | ||
|
||
/** | ||
* author : Android 轮子哥 | ||
* github : https://github.com/getActivity/AndroidProject | ||
* time : 2019/03/05 | ||
* desc : 查看大图 | ||
*/ | ||
public final class ImageActivity extends MyActivity { | ||
|
||
@BindView(R.id.vp_image_pager) | ||
ViewPager mViewPager; | ||
|
||
@Override | ||
protected int getLayoutId() { | ||
return R.layout.activity_image; | ||
} | ||
|
||
@Override | ||
protected int getTitleId() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
protected void initView() { | ||
|
||
} | ||
|
||
@Override | ||
protected void initData() { | ||
ArrayList<String> data = new ArrayList<>(); | ||
data.add("https://www.baidu.com/img/bd_logo.png"); | ||
data.add("https://www.baidu.com/img/bd_logo.png"); | ||
data.add("https://www.baidu.com/img/bd_logo.png"); | ||
mViewPager.setAdapter(new ImagePagerAdapter(this, data)); | ||
} | ||
|
||
@Override | ||
public boolean statusBarDarkFont() { | ||
return !super.statusBarDarkFont(); | ||
} | ||
package com.hjq.demo.ui.activity; | ||
|
||
import android.support.v4.view.ViewPager; | ||
|
||
import com.hjq.demo.R; | ||
import com.hjq.demo.common.MyActivity; | ||
import com.hjq.demo.ui.adapter.PhotoPagerAdapter; | ||
|
||
import java.util.ArrayList; | ||
|
||
import butterknife.BindView; | ||
|
||
/** | ||
* author : Android 轮子哥 | ||
* github : https://github.com/getActivity/AndroidProject | ||
* time : 2019/03/05 | ||
* desc : 查看大图 | ||
*/ | ||
public final class PhotoActivity extends MyActivity { | ||
|
||
@BindView(R.id.vp_photo_pager) | ||
ViewPager mViewPager; | ||
|
||
@Override | ||
protected int getLayoutId() { | ||
return R.layout.activity_photo; | ||
} | ||
|
||
@Override | ||
protected int getTitleId() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
protected void initView() { | ||
|
||
} | ||
|
||
@Override | ||
protected void initData() { | ||
ArrayList<String> data = new ArrayList<>(); | ||
data.add("https://www.baidu.com/img/bd_logo.png"); | ||
data.add("https://www.baidu.com/img/bd_logo.png"); | ||
data.add("https://www.baidu.com/img/bd_logo.png"); | ||
mViewPager.setAdapter(new PhotoPagerAdapter(this, data)); | ||
} | ||
|
||
@Override | ||
public boolean statusBarDarkFont() { | ||
return !super.statusBarDarkFont(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 70 additions & 70 deletions
140
...jq/demo/ui/adapter/ImagePagerAdapter.java → ...jq/demo/ui/adapter/PhotoPagerAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,71 @@ | ||
package com.hjq.demo.ui.adapter; | ||
|
||
import android.app.Activity; | ||
import android.support.annotation.NonNull; | ||
import android.support.v4.view.PagerAdapter; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
import com.github.chrisbanes.photoview.PhotoView; | ||
import com.hjq.image.ImageLoader; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* author : Android 轮子哥 | ||
* github : https://github.com/getActivity/AndroidProject | ||
* time : 2019/03/05 | ||
* desc : 图片加载适配器 | ||
*/ | ||
public final class ImagePagerAdapter extends PagerAdapter implements View.OnClickListener { | ||
|
||
private Activity mActivity; | ||
private List<String> mData; | ||
|
||
public ImagePagerAdapter(Activity activity, List<String> data) { | ||
mActivity = activity; | ||
mData = data; | ||
} | ||
|
||
// 加载数量,自动回调 | ||
@Override | ||
public int getCount() { | ||
return mData.size(); | ||
} | ||
|
||
// 返回真表示不会重新创建,使用缓存加载。返回假则重新创建 | ||
@Override | ||
public boolean isViewFromObject(@NonNull View view, @NonNull Object object) { | ||
return view == object; | ||
} | ||
|
||
/** | ||
* 实例化条目 | ||
* ViewPager预加载机制:最多保存3个page,超过的将需要被销毁掉 | ||
* 由于最多3个page,所以不需要设置ViewHolder | ||
* 用于将数据设置给ViewItem | ||
*/ | ||
|
||
@NonNull | ||
@Override | ||
public Object instantiateItem(@NonNull ViewGroup container, int position) { | ||
PhotoView view = new PhotoView(mActivity); | ||
view.setOnClickListener(this); | ||
ImageLoader.loadImage(view, mData.get(position)); | ||
// 将View添加到ViewPager | ||
container.addView(view); | ||
return view; | ||
} | ||
|
||
// 销毁条目 | ||
@Override | ||
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) { | ||
container.removeView((View) object); | ||
} | ||
|
||
@Override | ||
public void onClick(View v) { | ||
// 点击退出当前的 Activity | ||
mActivity.finish(); | ||
} | ||
package com.hjq.demo.ui.adapter; | ||
|
||
import android.app.Activity; | ||
import android.support.annotation.NonNull; | ||
import android.support.v4.view.PagerAdapter; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
import com.github.chrisbanes.photoview.PhotoView; | ||
import com.hjq.image.ImageLoader; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* author : Android 轮子哥 | ||
* github : https://github.com/getActivity/AndroidProject | ||
* time : 2019/03/05 | ||
* desc : 图片加载适配器 | ||
*/ | ||
public final class PhotoPagerAdapter extends PagerAdapter implements View.OnClickListener { | ||
|
||
private Activity mActivity; | ||
private List<String> mData; | ||
|
||
public PhotoPagerAdapter(Activity activity, List<String> data) { | ||
mActivity = activity; | ||
mData = data; | ||
} | ||
|
||
// 加载数量,自动回调 | ||
@Override | ||
public int getCount() { | ||
return mData.size(); | ||
} | ||
|
||
// 返回真表示不会重新创建,使用缓存加载。返回假则重新创建 | ||
@Override | ||
public boolean isViewFromObject(@NonNull View view, @NonNull Object object) { | ||
return view == object; | ||
} | ||
|
||
/** | ||
* 实例化条目 | ||
* ViewPager预加载机制:最多保存3个page,超过的将需要被销毁掉 | ||
* 由于最多3个page,所以不需要设置ViewHolder | ||
* 用于将数据设置给ViewItem | ||
*/ | ||
|
||
@NonNull | ||
@Override | ||
public Object instantiateItem(@NonNull ViewGroup container, int position) { | ||
PhotoView view = new PhotoView(mActivity); | ||
view.setOnClickListener(this); | ||
ImageLoader.loadImage(view, mData.get(position)); | ||
// 将View添加到ViewPager | ||
container.addView(view); | ||
return view; | ||
} | ||
|
||
// 销毁条目 | ||
@Override | ||
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) { | ||
container.removeView((View) object); | ||
} | ||
|
||
@Override | ||
public void onClick(View v) { | ||
// 点击退出当前的 Activity | ||
mActivity.finish(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.hjq.demo.widget; | ||
|
||
import android.content.Context; | ||
import android.support.v4.view.ViewPager; | ||
import android.util.AttributeSet; | ||
import android.view.MotionEvent; | ||
|
||
/** | ||
* author : Android 轮子哥 | ||
* github : https://github.com/getActivity/AndroidProject | ||
* time : 2019/05/07 | ||
* desc : ViewPager 中使用 PhotoView 时出现 pointerIndex out of range 异常 | ||
*/ | ||
public final class PhotoViewPager extends ViewPager { | ||
|
||
public PhotoViewPager(Context context) { | ||
super(context); | ||
} | ||
|
||
public PhotoViewPager(Context context, AttributeSet attrs) { | ||
super(context, attrs); | ||
} | ||
|
||
@Override | ||
public boolean onInterceptTouchEvent(MotionEvent ev) { | ||
// 当PhotoView 和 ViewPager 组合时 ,用双指进行放大时 是没有问题的,但是用双指进行缩小的时候,程序就会崩掉 | ||
// 并且抛出java.lang.IllegalArgumentException: pointerIndex out of range | ||
try { | ||
return super.onInterceptTouchEvent(ev); | ||
} catch (IllegalArgumentException | ArrayIndexOutOfBoundsException ignored) { | ||
return false; | ||
} | ||
} | ||
} |
File renamed without changes
File renamed without changes
Oops, something went wrong.