Skip to content

Commit

Permalink
重构方法,优化,以及增加新方法
Browse files Browse the repository at this point in the history
  • Loading branch information
HomHomLin committed Mar 3, 2016
1 parent a022279 commit 5056161
Show file tree
Hide file tree
Showing 9 changed files with 358 additions and 218 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ protected void onCreate(Bundle savedInstanceState) {
public void onClick(View v) {
Toast.makeText(FrescoZoomImageViewActivity.this,"OnClick",Toast.LENGTH_SHORT).show();
frescoImageView.asCircle();
frescoImageView.loadView("https://avatars0.githubusercontent.com/u/66577?v=3&s=460",R.mipmap.ic_launcher);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
PROJ_GROUP=homhomlin.lib
PROJ_VERSION=1.2.1
PROJ_VERSION=1.3.0
PROJ_NAME=FrescoImageView
PROJ_WEBSITEURL=https://github.com/HomHomLin/FrescoImageView
PROJ_ISSUETRACKERURL=
Expand Down
6 changes: 2 additions & 4 deletions lib.lhh.fiv.library/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="lib.lhh.fiv.library"
android:versionCode="1210"
android:versionName="1.2.1" >
<application>
</application>
android:versionCode="1300"
android:versionName="1.3.0" >
</manifest>
3 changes: 0 additions & 3 deletions lib.lhh.fiv.library/res/values/strings.xml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package lib.lhh.fiv.library;

import com.facebook.drawee.controller.ControllerListener;
import com.facebook.drawee.generic.RoundingParams;
import com.facebook.drawee.interfaces.DraweeController;
import com.facebook.imagepipeline.request.ImageRequest;
import com.facebook.imagepipeline.request.Postprocessor;

/**
* Created by Linhh on 16/3/2.
*/
public interface BaseFrescoImageView {

/**
* 获得当前监听
* @return
*/
public ControllerListener getControllerListener();

/**
* 获得当前使用的DraweeController
* @return
*/
public DraweeController getDraweeController();

/**
* 获得低级别ImageRequest
* @return
*/
public ImageRequest getLowImageRequest();

/**
* 获得当前使用的ImageRequest
* @return
*/
public ImageRequest getImageRequest();

/**
* 获得当前使用的RoundingParams
*/
public RoundingParams getRoundingParams();

/**
* 是否开启动画
* @return
*/
public boolean isAnim();

/**
* 获得当前后处理
* @return
*/
public Postprocessor getPostProcessor();

/**
* 获得当前使用的默认图
* @return
*/
public int getDefaultResID();

/**
* 获得当前加载的图片
* @return
*/
public String getThumbnailUrl();

/**
* 获得当前低分辨率图片
* @return
*/
public String getLowThumbnailUrl();

/**
* 获得加载的本地图片
* @return
*/
public String getThumbnailPath();

/**
* 是否可以点击重试,默认false
* @return
*/
public boolean getTapToRetryEnabled();
}
68 changes: 27 additions & 41 deletions lib.lhh.fiv.library/src/lib.lhh.fiv/library/FrescoController.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package lib.lhh.fiv.library;

import com.facebook.drawee.controller.ControllerListener;
import com.facebook.drawee.generic.RoundingParams;
import com.facebook.imagepipeline.request.Postprocessor;

Expand Down Expand Up @@ -34,47 +35,11 @@ public interface FrescoController {
*/
public void loadLocalImage(String path, int defaultRes);

/**
* 获得当前后处理
* @return
*/
public Postprocessor getPostProcessor();

/**
* 设置后处理
* @param postProcessor
*/
public void setPostProcessor(Postprocessor postProcessor);

/**
* 获得当前使用的默认图
* @return
*/
public int getDefaultResID();

/**
* 获得当前加载的图片
* @return
*/
public String getThumbnailUrl();

/**
* 将该Fresco处理为圆形
*/
public void asCircle();

/**
* 是否开启动画
* @return
*/
public boolean isAnim();

/**
* 是否开启动画
* @param anim
*/
public void setAnim(boolean anim);

/**
* 用一种颜色来遮挡View以实现圆形,在一些内存较低的机器上推荐使用
* @param overlay_color
Expand Down Expand Up @@ -106,15 +71,36 @@ public interface FrescoController {
*/
public void clearRoundingParams();

/**
* 获得当前使用的RoundingParams
*/
public RoundingParams getRoundingParams();

/**
* 设置RoundingParams
* @param roundingParmas
*/
public void setRoundingParmas(RoundingParams roundingParmas);

/**
* 设置下载监听器
* @param controllerListener
*/
public void setControllerListener(ControllerListener controllerListener);


/**
* 设置后处理
* @param postProcessor
*/
public void setPostProcessor(Postprocessor postProcessor);


/**
* 是否开启动画
* @param anim
*/
public void setAnim(boolean anim);

/**
* 是否可以点击重试
* @param tapToRetryEnabled
*/
public void setTapToRetryEnabled(boolean tapToRetryEnabled);

}
57 changes: 57 additions & 0 deletions lib.lhh.fiv.library/src/lib.lhh.fiv/library/FrescoFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package lib.lhh.fiv.library;

import android.net.Uri;
import android.text.TextUtils;

import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.interfaces.DraweeController;
import com.facebook.imagepipeline.request.ImageRequest;
import com.facebook.imagepipeline.request.ImageRequestBuilder;

/**
* Created by Linhh on 16/3/2.
*/
public class FrescoFactory {

public static DraweeController buildDraweeController(BaseFrescoImageView fresco){
return Fresco.newDraweeControllerBuilder()
.setImageRequest(fresco.getImageRequest())
.setAutoPlayAnimations(fresco.isAnim())
.setTapToRetryEnabled(fresco.getTapToRetryEnabled())
.setLowResImageRequest(fresco.getLowImageRequest())
.setControllerListener(fresco.getControllerListener())
.setOldController(fresco.getDraweeController())
.build();
}

public static ImageRequest buildImageRequestWithResource(BaseFrescoImageView fresco){
return ImageRequestBuilder.newBuilderWithResourceId(fresco.getDefaultResID())
.setPostprocessor(fresco.getPostProcessor())
.setLocalThumbnailPreviewsEnabled(true)
.build();
}

public static ImageRequest buildImageRequestWithSource(BaseFrescoImageView fresco){
String thumbnail = null;
if(TextUtils.isEmpty(fresco.getThumbnailUrl())){
thumbnail = fresco.getThumbnailPath();
}else{
thumbnail = fresco.getThumbnailUrl();
}
Uri uri = Uri.parse(thumbnail);
return ImageRequestBuilder.newBuilderWithSource(uri)
.setPostprocessor(fresco.getPostProcessor())
.setLocalThumbnailPreviewsEnabled(true)
.build();
}

public static ImageRequest buildLowImageRequest(BaseFrescoImageView fresco){
String lowThumbnail = null;
if(TextUtils.isEmpty(fresco.getLowThumbnailUrl())){
return null;
}
lowThumbnail = fresco.getLowThumbnailUrl();
Uri uri = Uri.parse(lowThumbnail);
return ImageRequest.fromUri(uri);
}
}
Loading

0 comments on commit 5056161

Please sign in to comment.