Skip to content

Commit

Permalink
[FIX] add some listener and update gradle
Browse files Browse the repository at this point in the history
  • Loading branch information
sunyichao committed Oct 25, 2017
1 parent 20d681b commit 023dd2c
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 100 deletions.
175 changes: 88 additions & 87 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,111 +24,112 @@ Step 2. Add the dependency
## Sample Code

```Java
final ViewpagerCommonAdapter viewpagerCommonAdapter = new ViewpagerCommonAdapter(MainActivity.this);
final ViewpagerCommonAdapter viewpagerCommonAdapter = new ViewpagerCommonAdapter(MainActivity.this);

viewpagerCommonAdapter.setOnImageSingleClickListener(new OnImageSingleClickListener() {
@Override
public void onImageSingleClick(int position, String path, PhotoView photoView) {
Toast.makeText(MainActivity.this, "onImageSingleClick" + position, Toast.LENGTH_SHORT).show();
}
});

viewpagerCommonAdapter.setOnImageLongClickListener(new OnImageLongClickListener() {
@Override
public boolean onImageLongClick(int position, String path, PhotoView photoView) {
Toast.makeText(MainActivity.this, "onImageLongClick" + position, Toast.LENGTH_SHORT).show();
return false;
}
});
viewpagerCommonAdapter.setOnImageSingleClickListener(new OnImageSingleClickListener() {
@Override
public void onImageSingleClick(int position, String path, PhotoView photoView) {
Toast.makeText(MainActivity.this, "onImageSingleClick" + position, Toast.LENGTH_SHORT).show();
}
});

final ImageViewer imageViewer = new ImageViewer.Builder(
new ImageLoader() {
viewpagerCommonAdapter.setOnImageLongClickListener(new OnImageLongClickListener() {
@Override
public void showImage(final int position, String path, ImageView imageView) {
final OnLoadListener loadListener = this.getOnLoadListener();
final View view = this.getView();
loadListener.onStart(position);
Glide.with(OCApplication.getContext())
.load(path)
.listener(new RequestListener<String, GlideDrawable>() {
@Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
loadListener.onError(position);
return false;
}

@Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
loadListener.onSuccess(position);
return false;
}
})
.into(imageView);
public boolean onImageLongClick(int position, String path, PhotoView photoView) {
Toast.makeText(MainActivity.this, "onImageLongClick" + position, Toast.LENGTH_SHORT).show();
return false;
}
},
viewpagerCommonAdapter)
.setIndex(2)
.setPaths(paths)
.setTransformerType(ImageViewer.TYPE_CUBEOUT_TRANSFORMER)
.build()
.show(getSupportFragmentManager(), "ImageViewer");
});

final ImageViewer imageViewer = new ImageViewer.Builder(
new ImageLoader() {
@Override
public void showImage(final int position, String path, ImageView imageView) {
final OnLoadListener loadListener = this.getOnLoadListener();
final View view = this.getView();
loadListener.onStart(position);
Glide.with(OCApplication.getContext())
.load(path)
.listener(new RequestListener<String, GlideDrawable>() {
@Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
loadListener.onError(position);
return false;
}

@Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
loadListener.onSuccess(position);
return false;
}
})
.into(imageView);
}
},
viewpagerCommonAdapter)
.setIndex(2)
.setPaths(paths)
.setTransformerType(ImageViewer.TYPE_CUBEOUT_TRANSFORMER)
.build()
.show(getSupportFragmentManager(), "ImageViewer");
```

## Customized Adapter

```Java
public class CustomViewpagerAdapter extends ViewpagerAdapter {
public class CustomViewpagerAdapter extends ViewpagerAdapter {

public CustomViewpagerAdapter(Context context) {
super(context);
}
public CustomViewpagerAdapter(Context context) {
super(context);
}

@Override
protected View initView(ViewGroup container, int position) {
return LayoutInflater.from(mContext).inflate(R.layout.demo_photoview, container, false);
}
@Override
protected View initView(ViewGroup container, int position) {
return LayoutInflater.from(mContext).inflate(R.layout.demo_photoview, container, false);
}

@Override
protected void loadImage(final int position, String path, View view) {
final ImageView imageView = (ImageView) view.findViewById(R.id.image_demo);
//自定义adapter可以在内部直接设置点击事件
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(mContext, "demoOnPhotoTap" + position, Toast.LENGTH_SHORT).show();
}
});
@Override
protected void loadImage(final int position, String path, View view) {
final ImageView imageView = (ImageView) view.findViewById(R.id.image_demo);
//自定义adapter可以在内部直接设置点击事件
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(mContext, "demoOnPhotoTap" + position, Toast.LENGTH_SHORT).show();
}
});

imageView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
Toast.makeText(mContext, "demoOnLongClick" + position, Toast.LENGTH_SHORT).show();
return false;
}
});
imageView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
Toast.makeText(mContext, "demoOnLongClick" + position, Toast.LENGTH_SHORT).show();
return false;
}
});

imageLoader.showImage(position, path, imageView);
}
imageLoader.showImage(position, path, imageView);
}

}
}
```

## Customized ImageViewer init

```Java
new ImageViewer.Builder(
new ImageLoader() {
@Override
public void showImage(int position, String path, ImageView imageView) {
Glide.with(OCApplication.getContext())
.load(path)
.into(imageView);
}
},
new CustomViewpagerAdapter(MainActivity.this))
.setIndex(3)
.setPaths(paths)
.setTransformerType(ImageViewer.TYPE_ZOOMOUT_TRANSFORMER)
.build()
.show(getSupportFragmentManager(), "ImageViewer");
new ImageViewer.Builder(
new ImageLoader() {
@Override
public void showImage(int position, String path, ImageView imageView) {
Glide.with(OCApplication.getContext())
.load(path)
.into(imageView);
}
},
new CustomViewpagerAdapter(MainActivity.this))
.setIndex(3)
.setPaths(paths)
.setTransformerType(ImageViewer.TYPE_ZOOMOUT_TRANSFORMER)
.build()
.show(getSupportFragmentManager(), "ImageViewer");

```
5 changes: 1 addition & 4 deletions app/src/main/java/cn/demo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ protected void onCreate(Bundle savedInstanceState) {
paths.add("http://tupian.enterdesk.com/2013/mxy/12/07/3/4.jpg");
paths.add("http://pic.58pic.com/58pic/13/40/15/62958PICTq7_1024.jpg");
paths.add("http://pic.qiantucdn.com/58pic/11/69/82/58PIC2Q58PICsY9.jpg");
paths.add("http://img05.tooopen.com/images/20150630/tooopen_sy_132344141259.jpg");
paths.add("http://img3.3lian.com/2013/v11/41/d/81.jpg");

button1.setOnClickListener(new View.OnClickListener() {
Expand All @@ -60,10 +59,8 @@ public void showImage(int position, String path, ImageView imageView) {
}
},
new CustomViewpagerAdapter(MainActivity.this))
.setIndex(3)
.setIndex(0)
.setPaths(paths)
.setExtraDismissType(ImageViewer.TYPE_ELASTIC_DIMISS)
.setTransformerType(ImageViewer.TYPE_ZOOMOUT_TRANSFORMER)
.build()
.show(getSupportFragmentManager(), "ImageViewer");
}
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.1'
classpath 'com.android.tools.build:gradle:3.0.0-beta6'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'

// NOTE: Do not place your application dependencies here; they belong
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sun Jun 18 02:55:09 CST 2017
#Wed Oct 25 10:45:11 CST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
13 changes: 7 additions & 6 deletions imageviewer/src/main/java/cn/imageviewer/view/ImageViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,15 @@ public void onResume() {
//如果在onViewCreated 设置会出现设置无效的状况
viewpager.setCurrentItem(index);

if (onPageChangeListener != null) {
viewpager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
viewpager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
index = position;
if (onPageChangeListener != null) {
onPageChangeListener.onChange(position);
}
});
}
}
});
}

public void setCurrentPage(int page) {
Expand Down

0 comments on commit 023dd2c

Please sign in to comment.