Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Hitomis committed May 9, 2017
1 parent 5b526f4 commit 593a4a0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ public void onFinish() {
public void onDelivered(int status) {
switch (status) {
case ImageLoader.STATUS_DISPLAY_SUCCESS:
if (TransferImage.STATE_TRANS_CLIP == targetImage.getState())
targetImage.transformIn(TransferImage.STAGE_SCALE);
// 启用 TransferImage 的手势缩放功能
targetImage.enable();
// 绑定点击关闭 Transferee
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,31 @@ private void init() {
paint.setStyle(Style.FILL);
}

/**
* 设置 TransferImage 初始位置信息
*
* @param locationX x坐标位置
* @param locationY y坐标位置
* @param width 宽度
* @param height 高度
*/
public void setOriginalInfo(int locationX, int locationY, int width, int height) {
originalLocationX = locationX;
originalLocationY = locationY;
originalWidth = width;
originalHeight = height;
}

public void setOriginalInfo(Drawable targetDrawable, int originWidth, int originHeight, int width, int height){
/**
* 设置 TransferImage 初始位置信息
*
* @param targetDrawable 初始显示的图片 Drawable
* @param originWidth TransferImage 初始宽度
* @param originHeight TransferImage 初始高度
* @param width 容器宽度
* @param height 容器高度
*/
public void setOriginalInfo(Drawable targetDrawable, int originWidth, int originHeight, int width, int height) {
Rect rect = getClipOriginalInfo(targetDrawable, originWidth, originHeight, width, height);
originalLocationX = rect.left;
originalLocationY = rect.top;
Expand Down Expand Up @@ -185,7 +202,7 @@ public void setDuration(long duration) {
/**
* 获取当前的状态
*
* @return {@link #STATE_TRANS_NORMAL}, {@link #STATE_TRANS_IN}, {@link #STATE_TRANS_OUT}
* @return {@link #STATE_TRANS_NORMAL}, {@link #STATE_TRANS_IN}, {@link #STATE_TRANS_OUT}, {@link #STATE_TRANS_CLIP}
*/
public int getState() {
return state;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
import com.zhy.adapter.abslistview.CommonAdapter;
import com.zhy.adapter.abslistview.ViewHolder;

Expand All @@ -28,21 +26,8 @@ public class UniversalNoThumActivity extends BaseActivity {

private GridView gvImages;
private DisplayImageOptions options;
private List<String> thumbnailImageList;
private List<String> sourceImageList;

{
thumbnailImageList = new ArrayList<>();
thumbnailImageList.add("http://oxgood.com/wp-content/uploads/2016/07/c3e4308aa6e2074c77d343d8824179c0-1024x628.jpg");
thumbnailImageList.add("http://oxgood.com/wp-content/uploads/2016/07/d86a1428bea533217c7e2b13b4e5963e-1024x736.jpg");
thumbnailImageList.add("http://oxgood.com/wp-content/uploads/2016/07/5cf47d87616dba975d1e85214025c349-1024x676.jpg");
thumbnailImageList.add("http://oxgood.com/wp-content/uploads/2016/07/53605f987ec71b74bb376b47a238430a-1024x734.jpg");
thumbnailImageList.add("http://oxgood.com/wp-content/uploads/2016/07/dad7c7f0e646780774de0374f406014b-1024x820.jpg");
thumbnailImageList.add("http://oxgood.com/wp-content/uploads/2016/07/cbdef59bd87caa712abb0f144c463101-1024x833.jpg");
thumbnailImageList.add("http://oxgood.com/wp-content/uploads/2016/07/e0f944e4c73ad5b6a018029bc7ebbb37-1024x734.jpg");
thumbnailImageList.add("http://oxgood.com/wp-content/uploads/2016/07/eadc61ec6a819fe8fb518f06b37b5ccf-1024x668.jpg");
thumbnailImageList.add("http://oxgood.com/wp-content/uploads/2016/07/e41b862ee191d342ec80cf39f97cc067-1024x724.jpg");

sourceImageList = new ArrayList<>();
sourceImageList.add("http://oxgood.com/wp-content/uploads/2016/07/c3e4308aa6e2074c77d343d8824179c0-1024x628.jpg");
sourceImageList.add("http://oxgood.com/wp-content/uploads/2016/07/d86a1428bea533217c7e2b13b4e5963e-1024x736.jpg");
Expand Down Expand Up @@ -103,69 +88,27 @@ public NineGridAdapter() {

@Override
protected void convert(ViewHolder viewHolder, String item, final int position) {
final ImageView imageView = viewHolder.getView(R.id.image_view);
ImageLoader.getInstance().displayImage(item, imageView, options, new ImageLoadingListener() {
@Override
public void onLoadingStarted(String imageUri, View view) {

}
ImageView imageView = viewHolder.getView(R.id.image_view);
ImageLoader.getInstance().displayImage(item, imageView, options);

imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {

}

@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
bindTransferee(imageView, position);
}

@Override
public void onLoadingCancelled(String imageUri, View view) {

public void onClick(View v) {
TransferConfig config = TransferConfig.build()
.setNowThumbnailIndex(position)
.setSourceImageList(sourceImageList)
.setMissPlaceHolder(R.mipmap.ic_empty_photo)
.setErrorPlaceHolder(R.mipmap.ic_empty_photo)
.setOriginImageList(wrapOriginImageViewList())
.setProgressIndicator(new ProgressPieIndicator())
.setIndexIndicator(new NumberIndexIndicator())
.setImageLoader(UniversalImageLoader.with(getApplicationContext()))
.setJustLoadHitImage(true)
.create();
transferee.apply(config).show();
}
});

// imageView.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// TransferConfig config = TransferConfig.build()
// .setNowThumbnailIndex(position)
// .setThumbnailImageList(sourceImageList)
// .setSourceImageList(sourceImageList)
// .setMissPlaceHolder(R.mipmap.ic_empty_photo)
// .setErrorPlaceHolder(R.mipmap.ic_empty_photo)
// .setOriginImageList(wrapOriginImageViewList())
// .setProgressIndicator(new ProgressPieIndicator())
// .setIndexIndicator(new NumberIndexIndicator())
// .setJustLoadHitImage(true)
// .setImageLoader(UniversalImageLoader.with(getApplicationContext()))
// .create();
// transferee.apply(config).show();
// }
// });
}
}

private void bindTransferee(ImageView imageView, final int position) {
// 如果指定了缩略图,那么缩略图一定要先加载完毕
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TransferConfig config = TransferConfig.build()
.setNowThumbnailIndex(position)
.setThumbnailImageList(sourceImageList)
.setSourceImageList(sourceImageList)
.setMissPlaceHolder(R.mipmap.ic_empty_photo)
.setErrorPlaceHolder(R.mipmap.ic_empty_photo)
.setOriginImageList(wrapOriginImageViewList())
.setProgressIndicator(new ProgressPieIndicator())
.setIndexIndicator(new NumberIndexIndicator())
.setImageLoader(UniversalImageLoader.with(getApplicationContext()))
.setJustLoadHitImage(true)
.create();
transferee.apply(config).show();
}
});
}
}

0 comments on commit 593a4a0

Please sign in to comment.