Skip to content

Commit

Permalink
add load big iamge progress
Browse files Browse the repository at this point in the history
  • Loading branch information
李松 committed May 17, 2017
1 parent 337c5e9 commit c34de70
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ subsampling-scale-image-view:https://github.com/davemorrissey/subsampling-scal
}
}
compile 'com.facebook.fresco.helper:fresco-helper:1.3.2'
compile 'com.facebook.fresco.helper:fresco-helper:1.4.0'
```

初始化
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// compile project(':fresco-helper')
compile 'com.facebook.fresco.helper:fresco-helper:1.3.2'
compile 'com.facebook.fresco.helper:fresco-helper:1.3.3'

compile 'com.android.support:appcompat-v7:25.3.0'
compile 'com.android.support:recyclerview-v7:25.3.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import com.anbetter.log.MLog;
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;
import com.facebook.fresco.helper.LargePhotoView;
import com.facebook.fresco.helper.Phoenix;


Expand All @@ -26,7 +27,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fresco_big_big);

final SubsamplingScaleImageView imageView = (SubsamplingScaleImageView) findViewById(R.id.image);
final LargePhotoView imageView = (LargePhotoView) findViewById(R.id.image);
imageView.setMinimumScaleType(SubsamplingScaleImageView.SCALE_TYPE_CUSTOM);
imageView.setMinScale(1.0f);
imageView.setMaxScale(2.0f);
Expand Down Expand Up @@ -79,7 +80,8 @@ public boolean onTouch(View view, MotionEvent motionEvent) {
// String fileCacheDir = getCacheDir().getAbsolutePath();
// MLog.i("fileCacheDir = " + fileCacheDir);

String url = "http://img5q.duitang.com/uploads/item/201402/24/20140224212510_eQRG5.thumb.700_0.jpeg";
// String url = "http://img5q.duitang.com/uploads/item/201402/24/20140224212510_eQRG5.thumb.700_0.jpeg";
String url = "http://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1490349606605&di=5510cf624bce949b977ba005f1dbaf84&imgtype=0&src=http%3A%2F%2Fattach.bbs.letv.com%2Fforum%2F201607%2F02%2F195153fz3mxtd50d0qjtz9.jpg";
// Phoenix.with(imageView)
// .setDiskCacheDir(fileCacheDir)
// .load(url);
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_fresco_big_big.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
<com.facebook.fresco.helper.LargePhotoView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/image"
android:layout_width="match_parent"
Expand Down
4 changes: 2 additions & 2 deletions fresco-helper/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ dependencies {
// Maven Group ID
group = "com.facebook.fresco.helper"
// library的版本号,后面每次更新都需要更改这个值
version = "1.3.2"
version = "1.4.0"

// 生成jar包的task
task sourcesJar(type: Jar) {
Expand Down Expand Up @@ -83,7 +83,7 @@ install {
packaging 'aar'
groupId 'com.facebook.fresco.helper'
artifactId 'fresco-helper'
version '1.3.2'
version '1.4.0'

licenses {
license {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,14 @@ public void onNewResultImpl(DataSource<CloseableReference<PooledByteBuffer>> dat
}
}

@Override
public void onProgressUpdate(DataSource<CloseableReference<PooledByteBuffer>> dataSource) {
int progress = (int) (dataSource.getProgress() * 100);
if (loadFileResult != null) {
loadFileResult.onProgress(progress);
}
}

@Override
public void onFailureImpl(DataSource dataSource) {
if (loadFileResult != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.facebook.fresco.helper;

import android.content.Context;
import android.util.AttributeSet;

import com.anbetter.log.MLog;
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;
import com.facebook.fresco.helper.listener.OnProgressListener;

/**
* Created by android_ls on 2017/5/17.
*/

public class LargePhotoView extends SubsamplingScaleImageView {

private OnProgressListener mOnProgressListener;
public LargePhotoView(Context context, AttributeSet attr) {
super(context, attr);
}

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

public void setOnProgressListener(OnProgressListener listener) {
this.mOnProgressListener = listener;
}

/**
* 加载进度
* @param progress 0~100
*/
public void onProgress(int progress) {
MLog.i("progress = " + progress);
if(mOnProgressListener != null) {
mOnProgressListener.onProgress(progress);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import android.net.Uri;
import android.text.TextUtils;
import android.view.ViewGroup;
import android.widget.Toast;

import com.anbetter.log.MLog;
import com.davemorrissey.labs.subscaleview.ImageSource;
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;
import com.facebook.common.util.UriUtil;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.controller.ControllerListener;
Expand Down Expand Up @@ -52,7 +52,7 @@ public static Builder with(SimpleDraweeView simpleDraweeView) {
return new Builder().build(simpleDraweeView);
}

public static Builder with(SubsamplingScaleImageView subsamplingScaleImageView) {
public static Builder with(LargePhotoView subsamplingScaleImageView) {
return new Builder().build(subsamplingScaleImageView);
}

Expand Down Expand Up @@ -240,7 +240,7 @@ public static class Builder {

private Context mContext;
private SimpleDraweeView mSimpleDraweeView;
private SubsamplingScaleImageView mSubsamplingScaleImageView;
private LargePhotoView mSubsamplingScaleImageView;

private String mUrl;
private String mDiskCachePath; // 超大图的本地缓存目录
Expand Down Expand Up @@ -275,7 +275,7 @@ public Builder build(SimpleDraweeView simpleDraweeView) {
return this;
}

public Builder build(SubsamplingScaleImageView subsamplingScaleImageView) {
public Builder build(LargePhotoView subsamplingScaleImageView) {
this.mSubsamplingScaleImageView = subsamplingScaleImageView;
return this;
}
Expand Down Expand Up @@ -430,26 +430,43 @@ private void loadNormal(String url) {
String fileName = FileUtils.getFileName(url);
mDiskCachePath = mDiskCachePath + File.separator + fileName;
}
// MLog.i("mDiskCachePath = " + mDiskCachePath);
MLog.i("mDiskCachePath = " + mDiskCachePath);

if (FileUtils.exists(mDiskCachePath)) {
// MLog.i("-->local file already exists");
MLog.i("-->local file already exists");
mSubsamplingScaleImageView.post(new Runnable() {
@Override
public void run() {
mSubsamplingScaleImageView.onProgress(100);
mSubsamplingScaleImageView.setImage(ImageSource.uri(mDiskCachePath));
}
});
} else {
ImageLoader.downloadImage(mSubsamplingScaleImageView.getContext(), url,
new IDownloadResult(mDiskCachePath) {

@Override
public void onProgress(final int progress) {
mSubsamplingScaleImageView.post(new Runnable() {
@Override
public void run() {
mSubsamplingScaleImageView.onProgress(progress);
}
});
}

@Override
public void onResult(final String filePath) {
// MLog.i("-->filePath = " + filePath);
MLog.i("-->filePath = " + filePath);
mSubsamplingScaleImageView.post(new Runnable() {
@Override
public void run() {
mSubsamplingScaleImageView.setImage(ImageSource.uri(filePath));
if(filePath != null) {
mSubsamplingScaleImageView.setImage(ImageSource.uri(filePath));
} else {
Toast.makeText(mSubsamplingScaleImageView.getContext(),
"加载图片失败,请检查网络", Toast.LENGTH_SHORT).show();
}
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public String getFilePath() {
return mFilePath;
}

public void onProgress(int progress) {

}

@Override
public abstract void onResult(String filePath);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.facebook.fresco.helper.listener;

/**
*
* Created by android_ls on 2017/5/17.
*/

public interface OnProgressListener {
void onProgress(int progress);
}

0 comments on commit c34de70

Please sign in to comment.