diff --git a/.gitignore b/.gitignore index c6cbe56..c07e41d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ /local.properties /.idea/workspace.xml /.idea/libraries +.idea .DS_Store /build /captures diff --git a/README.md b/README.md index 64e6a6f..22e3490 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,9 @@ ## I. 结果 -![][demo_1_jpg] -![][demo_2_jpg] +|||| +|:---:|:---:|:---:| +|![][demo_1_jpg]|![][demo_2_jpg]|![][demo_3_png]| #### 1. 基本库(`library`): @@ -63,6 +64,17 @@ PicassoLoader.display7Niu(imageview2, MOCK_DATA_URL) ``` +#### 3. 基于[Glide](https://github.com/bumptech/glide)的封装工具库(`utils-glide`) + +[![Download][qiniu_img_picasso_svg]][qiniu_img_picasso_url] + +```java +GlideLoader.createLoader(image8, MOCK_DATA_URL) + .size(dp2px(250)) + .addOpBlur(40, 20) + .attach(); +``` + ## II. 使用 ``` @@ -71,6 +83,8 @@ dependencies { implementation 'com.liulishuo.qiniuimageloader:library:1.0.4' // 可不引: 基于基本库与picasso做上层封装,可作为案例,也可直接使用 implementation 'com.liulishuo.qiniuimageloader:utils-picasso:1.0.4' + // 可不引: 基于 glide 封装 + implementation 'com.liulishuo.qiniuimageloader:utils-glide:1.0.4' } ``` @@ -172,6 +186,7 @@ dependencies { > `utils-picasso`依赖与`library`,`libarry`拥有的所有参数,`utils-picasso`都有,下面是`utils-picasso`做上层封装的时候增加的 +> `utils-glide` 与此类似 ##### 特有全局配置 ``` @@ -230,5 +245,6 @@ limitations under the License. [qiniu_img_picasso_url]: https://bintray.com/jacksgong/maven/QiniuImageLoader-picassoUtils/_latestVersion [demo_1_jpg]: https://github.com/lingochamp/QiniuImageLoader/raw/master/art/demo_1.jpg [demo_2_jpg]: https://github.com/lingochamp/QiniuImageLoader/raw/master/art/demo_2.jpg +[demo_3_png]: ./art/demo_3.png [build_status_svg]: https://travis-ci.org/lingochamp/QiniuImageLoader.svg?branch=master [build_status_link]: https://travis-ci.org/lingochamp/QiniuImageLoader diff --git a/art/demo_3.png b/art/demo_3.png new file mode 100644 index 0000000..9b483bc Binary files /dev/null and b/art/demo_3.png differ diff --git a/build.gradle b/build.gradle index b8a625a..46a3256 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,7 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { + ext.kotlin_version = '1.3.31' repositories { google() jcenter() @@ -8,6 +9,7 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:3.1.3' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } diff --git a/demo/build.gradle b/demo/build.gradle index 9b4e498..aafabd3 100644 --- a/demo/build.gradle +++ b/demo/build.gradle @@ -23,5 +23,6 @@ dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') implementation 'com.android.support:appcompat-v7:27.1.1' implementation project(':utils-picasso') + implementation project(':utils-glide') implementation project(':library') } diff --git a/demo/src/main/java/com/liulishuo/qiniuimageloader/demo/MainActivity.java b/demo/src/main/java/com/liulishuo/qiniuimageloader/demo/MainActivity.java index 5cbe77c..d14554b 100644 --- a/demo/src/main/java/com/liulishuo/qiniuimageloader/demo/MainActivity.java +++ b/demo/src/main/java/com/liulishuo/qiniuimageloader/demo/MainActivity.java @@ -8,13 +8,14 @@ import android.view.MenuItem; import android.widget.ImageView; +import com.liulishuo.qiniuimageloader.glide.GlideLoader; import com.liulishuo.qiniuimageloader.utils.PicassoLoader; /** * Created by Jacksgong on 12/13/15. */ public class MainActivity extends AppCompatActivity { - private static String MOCK_DATA_URL = "http://7xjww9.com1.z0.glb.clouddn.com/20130221114001385.jpg"; + private static String MOCK_DATA_URL = "http://image.youcute.cn/17-7-7/50670860.jpg"; @Override protected void onCreate(Bundle savedInstanceState) { @@ -44,7 +45,27 @@ protected void onCreate(Bundle savedInstanceState) { .halfScreenW() .attach(); + GlideLoader.createLoader(image6, MOCK_DATA_URL) + .attach(); + + GlideLoader.createLoader(image7, MOCK_DATA_URL) + .centerCrop() + .wR(R.dimen.image_2_width) + .attach(); + + GlideLoader.createLoader(image8, MOCK_DATA_URL) + .size(dp2px(250)) + .addOpBlur(40, 20) + .attach(); + + GlideLoader.createLoader(image9, MOCK_DATA_URL) + .w(dp2px(270)) + .addOpRotate(30) + .attach(); + GlideLoader.createLoader(image10, MOCK_DATA_URL) + .halfScreenW() + .attach(); } public int dp2px(float dpValue) { @@ -59,12 +80,23 @@ public int dp2px(float dpValue) { private ImageView image4; private ImageView image5; + private ImageView image6; + private ImageView image7; + private ImageView image8; + private ImageView image9; + private ImageView image10; + private void assignViews() { - image1 = (ImageView) findViewById(R.id.image_1); - image2 = (ImageView) findViewById(R.id.image_2); - image3 = (ImageView) findViewById(R.id.image_3); - image4 = (ImageView) findViewById(R.id.image_4); - image5 = (ImageView) findViewById(R.id.image_5); + image1 = findViewById(R.id.image_1); + image2 = findViewById(R.id.image_2); + image3 = findViewById(R.id.image_3); + image4 = findViewById(R.id.image_4); + image5 = findViewById(R.id.image_5); + image6 = findViewById(R.id.image_6); + image7 = findViewById(R.id.image_7); + image8 = findViewById(R.id.image_8); + image9 = findViewById(R.id.image_9); + image10 = findViewById(R.id.image_10); } @Override diff --git a/demo/src/main/res/layout/activity_main.xml b/demo/src/main/res/layout/activity_main.xml index e9716e3..c017390 100644 --- a/demo/src/main/res/layout/activity_main.xml +++ b/demo/src/main/res/layout/activity_main.xml @@ -1,49 +1,115 @@ - - - - - - - - - - - - + android:stretchColumns="*"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/library/build.gradle b/library/build.gradle index 1cd2fa7..31993a2 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -14,6 +14,10 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } + + dependencies{ + implementation "com.android.support:support-annotations:28.0.0" + } } apply from: rootProject.file('gradle/mvn-push.gradle') diff --git a/library/src/main/java/com/liulishuo/qiniuimageloader/QiniuImageLoader.java b/library/src/main/java/com/liulishuo/qiniuimageloader/QiniuImageLoader.java index 88d2f20..1b8b699 100644 --- a/library/src/main/java/com/liulishuo/qiniuimageloader/QiniuImageLoader.java +++ b/library/src/main/java/com/liulishuo/qiniuimageloader/QiniuImageLoader.java @@ -1,12 +1,12 @@ /** * Copyright (c) 2015 LingoChamp Inc. - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + *

* http://www.apache.org/licenses/LICENSE-2.0 - * + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -16,10 +16,16 @@ package com.liulishuo.qiniuimageloader; import android.content.Context; +import android.graphics.drawable.Drawable; +import android.os.Build; +import android.support.annotation.DimenRes; +import android.support.annotation.DrawableRes; +import android.support.annotation.Nullable; import android.text.TextUtils; import android.util.Log; import android.widget.ImageView; +import java.security.InvalidParameterException; import java.util.ArrayList; import java.util.List; @@ -39,6 +45,13 @@ public class QiniuImageLoader { private int h = 0; private String oriUrl; private ImageView imageView; + protected boolean isAvatar = false; + + public static int DEFAULT_PLACE_HOLDER = 0; + public static int DEFAULT_AVATAR_PLACE_HOLDER = 0; + @Nullable + protected Drawable defaultDrawable; + /** * 限定缩略图的宽最少为,高最少为,进行等比缩放,居中裁剪。 @@ -93,7 +106,7 @@ public T w(final int w) { * @param wResource DimenRes * @return */ - public T wR(final int wResource) { + public T wR(@DimenRes final int wResource) { if (getContext() == null) { return (T) this; } @@ -520,16 +533,30 @@ public void attach() { * for download & attach image 2 imageView */ public void attachWithNoClear() { - throw new UnsupportedOperationException( - "Required method instantiateItem was not overridden"); + if (getImageView() == null) { + throw new InvalidParameterException(String.format("imageView must not be null! %s", getOriUrl())); + } + + if (this.defaultDrawable == null) { + if (isAvatar) { + this.defaultDrawable = getDrawable(DEFAULT_AVATAR_PLACE_HOLDER); + } else { + this.defaultDrawable = getDrawable(DEFAULT_PLACE_HOLDER); + } + } + + attachWithNoClear(createQiniuUrl()); + } + + protected void attachWithNoClear(String url) { + throw new UnsupportedOperationException("Required method instantiateItem was not overridden"); } /** * for just download image */ public void fetch() { - throw new UnsupportedOperationException( - "Required method instantiateItem was not overridden"); + throw new UnsupportedOperationException("Required method instantiateItem was not overridden"); } protected ImageView getImageView() { @@ -559,4 +586,51 @@ protected Format getFormat() { protected List getOpList() { return opList; } -} + + @Nullable + private Drawable getDrawable(final int resourceId) { + if (resourceId == 0 || imageView == null) { + return null; + } + Drawable drawable = null; + try { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { + drawable = imageView.getResources().getDrawable(resourceId); + } else { + drawable = imageView.getContext().getDrawable(resourceId); + } + + } catch (Exception e) { + e.printStackTrace(); + } + + return drawable; + } + + /** + * 指定占位图 + * + * @param defaultDrawable placeholder for image + * @return T + */ + public T defaultD(final Drawable defaultDrawable) { + this.defaultDrawable = defaultDrawable; + return (T) this; + } + + public T defaultD(@DrawableRes final int defaultDrawableRes) { + this.defaultDrawable = getDrawable(defaultDrawableRes); + return (T) this; + } + + /** + * 占位图采用默认头像的占位图 + * + * @return T + * @see #DEFAULT_AVATAR_PLACE_HOLDER + */ + public T avatar() { + this.isAvatar = true; + return (T) this; + } +} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index b1d251b..a5d3a11 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include ':demo', ':library', ':utils-picasso' +include ':demo', ':library', ':utils-picasso', ':utils-glide' diff --git a/utils-glide/.gitignore b/utils-glide/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/utils-glide/.gitignore @@ -0,0 +1 @@ +/build diff --git a/utils-glide/build.gradle b/utils-glide/build.gradle new file mode 100644 index 0000000..ea79933 --- /dev/null +++ b/utils-glide/build.gradle @@ -0,0 +1,36 @@ +apply plugin: 'com.android.library' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-kapt' + +android { + compileSdkVersion COMPILE_SDK_VERSION as int + buildToolsVersion BUILD_TOOLS_VERSION as String + + defaultConfig { + minSdkVersion 14 + versionName VERSION_NAME as String + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + +} + +dependencies { + implementation project(':library') + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation "com.github.bumptech.glide:glide:4.9.0" + kapt "com.github.bumptech.glide:compiler:4.9.0" +} + + +apply from: rootProject.file('gradle/mvn-push.gradle') + +// Avoid Kotlin docs error +tasks.withType(Javadoc) { + enabled = false +} \ No newline at end of file diff --git a/utils-glide/gradle.properties b/utils-glide/gradle.properties new file mode 100644 index 0000000..717df6d --- /dev/null +++ b/utils-glide/gradle.properties @@ -0,0 +1,4 @@ +POM_ARTIFACT_ID=utils-glide +POM_NAME=QiniuImageLoader-glideUtils +POM_DESCRIPTION=在Android上结合七牛提供的API,让加载图片更有效、更节流、更简单、更可控、更酷 +POM_PACKAGING=aar diff --git a/utils-glide/proguard-rules.pro b/utils-glide/proguard-rules.pro new file mode 100644 index 0000000..40d798d --- /dev/null +++ b/utils-glide/proguard-rules.pro @@ -0,0 +1,31 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile + +-keep public class * implements com.bumptech.glide.module.GlideModule +-keep public class * extends com.bumptech.glide.module.AppGlideModule +-keep public enum com.bumptech.glide.load.ImageHeaderParser$** { + **[] $VALUES; + public *; +} + +# for DexGuard only +-keepresourcexmlelements manifest/application/meta-data@value=GlideModule \ No newline at end of file diff --git a/utils-glide/src/main/AndroidManifest.xml b/utils-glide/src/main/AndroidManifest.xml new file mode 100644 index 0000000..7140d4b --- /dev/null +++ b/utils-glide/src/main/AndroidManifest.xml @@ -0,0 +1 @@ + diff --git a/utils-glide/src/main/java/com/liulishuo/qiniuimageloader/glide/GlideLoader.kt b/utils-glide/src/main/java/com/liulishuo/qiniuimageloader/glide/GlideLoader.kt new file mode 100644 index 0000000..bd493ad --- /dev/null +++ b/utils-glide/src/main/java/com/liulishuo/qiniuimageloader/glide/GlideLoader.kt @@ -0,0 +1,73 @@ +package com.liulishuo.qiniuimageloader.glide + +import android.content.Context +import android.graphics.Bitmap +import android.graphics.drawable.Drawable +import android.support.annotation.DrawableRes +import android.widget.ImageView +import com.bumptech.glide.Glide +import com.bumptech.glide.load.Transformation +import com.bumptech.glide.request.RequestListener +import com.bumptech.glide.request.target.Target +import com.liulishuo.qiniuimageloader.QiniuImageLoader + +/** + * Create by StefanJi on 2019-05-10 + */ + +class GlideLoader { + + companion object { + + @JvmStatic + fun setGlobalPlaceHolder(@DrawableRes defaultPlaceHolder: Int, @DrawableRes defaultAvatarPlaceHolder: Int) { + QiniuImageLoader.DEFAULT_PLACE_HOLDER = defaultPlaceHolder + QiniuImageLoader.DEFAULT_AVATAR_PLACE_HOLDER = defaultAvatarPlaceHolder + } + + @JvmStatic + fun setGlobalTargetProvider(target: Target) { + GlideQiniuImageLoader.DEFAULT_TARGET = target + } + + @JvmStatic + fun createLoader(context: Context, oriUrl: String) = + GlideQiniuImageLoader(context, oriUrl) + + @JvmStatic + fun createLoader(imageView: ImageView, oriUrl: String) = + GlideQiniuImageLoader(imageView, oriUrl) + + @JvmStatic + internal fun display( + imageView: ImageView, + url: String, + defaultDrawable: Drawable?, + transformation: Transformation?, + requestListener: RequestListener? + ) { + Glide.with(imageView) + .load(url) + .apply { + transformation?.let { transform(it) } + } + .placeholder(defaultDrawable) + .listener(requestListener) + .into(imageView) + } + + @JvmStatic + internal fun fetch(context: Context, url: String, target: Target?) { + Glide.with(context) + .load(url) + .apply { + if (target != null) { + into(target) + } else { + preload() + } + } + } + + } +} \ No newline at end of file diff --git a/utils-glide/src/main/java/com/liulishuo/qiniuimageloader/glide/GlideQiniuImageLoader.kt b/utils-glide/src/main/java/com/liulishuo/qiniuimageloader/glide/GlideQiniuImageLoader.kt new file mode 100644 index 0000000..6be61c8 --- /dev/null +++ b/utils-glide/src/main/java/com/liulishuo/qiniuimageloader/glide/GlideQiniuImageLoader.kt @@ -0,0 +1,54 @@ +package com.liulishuo.qiniuimageloader.glide + +import android.content.Context +import android.graphics.drawable.Drawable +import android.widget.ImageView +import com.bumptech.glide.load.resource.bitmap.BitmapTransformation +import com.bumptech.glide.request.RequestListener +import com.bumptech.glide.request.target.Target +import com.liulishuo.qiniuimageloader.QiniuImageLoader + +/** + * Create by StefanJi on 2019-05-10 + */ + +class GlideQiniuImageLoader : QiniuImageLoader { + + private var transformation: BitmapTransformation? = null + private var requestListener: RequestListener? = null + private var target: Target? = null + + internal constructor(context: Context, oriUrl: String) : super(context, oriUrl) + + internal constructor(imageView: ImageView, oriUrl: String) : super(imageView, oriUrl) + + companion object { + var DEFAULT_TARGET: Target? = null + } + + override fun attachWithNoClear(url: String) { + GlideLoader.display(imageView, url, defaultDrawable, transformation, requestListener) + } + + override fun fetch() { + if (target == null) { + target = DEFAULT_TARGET + } + GlideLoader.fetch(context, createQiniuUrl(), target) + } + + fun transformation(transformation: BitmapTransformation): GlideQiniuImageLoader { + this.transformation = transformation + return this + } + + fun attachCallback(listener: RequestListener): GlideQiniuImageLoader { + this.requestListener = listener + return this + } + + fun target(target: Target): GlideQiniuImageLoader { + this.target = target + return this + } +} \ No newline at end of file diff --git a/utils-glide/src/main/res/values/strings.xml b/utils-glide/src/main/res/values/strings.xml new file mode 100644 index 0000000..c399342 --- /dev/null +++ b/utils-glide/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + utils-glide + diff --git a/utils-picasso/src/main/java/com/liulishuo/qiniuimageloader/utils/PicassoLoader.java b/utils-picasso/src/main/java/com/liulishuo/qiniuimageloader/utils/PicassoLoader.java index 6018738..aae47de 100644 --- a/utils-picasso/src/main/java/com/liulishuo/qiniuimageloader/utils/PicassoLoader.java +++ b/utils-picasso/src/main/java/com/liulishuo/qiniuimageloader/utils/PicassoLoader.java @@ -20,6 +20,7 @@ import android.util.Log; import android.widget.ImageView; +import com.liulishuo.qiniuimageloader.QiniuImageLoader; import com.squareup.picasso.Callback; import com.squareup.picasso.Picasso; import com.squareup.picasso.RequestCreator; @@ -40,8 +41,8 @@ public class PicassoLoader { * @param defaultAvatarPlaceHolder */ public static void setGlobalPlaceHolder(final int defaultPlaceHolder, final int defaultAvatarPlaceHolder) { - PicassoQiniuImageLoader.DEFAULT_PLACE_HOLDER = defaultPlaceHolder; - PicassoQiniuImageLoader.DEFAULT_AVATAR_PLACE_HOLDER = defaultAvatarPlaceHolder; + QiniuImageLoader.DEFAULT_PLACE_HOLDER = defaultPlaceHolder; + QiniuImageLoader.DEFAULT_AVATAR_PLACE_HOLDER = defaultAvatarPlaceHolder; } /** diff --git a/utils-picasso/src/main/java/com/liulishuo/qiniuimageloader/utils/PicassoQiniuImageLoader.java b/utils-picasso/src/main/java/com/liulishuo/qiniuimageloader/utils/PicassoQiniuImageLoader.java index 4def186..2783db3 100644 --- a/utils-picasso/src/main/java/com/liulishuo/qiniuimageloader/utils/PicassoQiniuImageLoader.java +++ b/utils-picasso/src/main/java/com/liulishuo/qiniuimageloader/utils/PicassoQiniuImageLoader.java @@ -1,12 +1,12 @@ /** * Copyright (c) 2015 LingoChamp Inc. - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + *

* http://www.apache.org/licenses/LICENSE-2.0 - * + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -16,8 +16,6 @@ package com.liulishuo.qiniuimageloader.utils; import android.content.Context; -import android.graphics.drawable.Drawable; -import android.os.Build; import android.widget.ImageView; import com.liulishuo.qiniuimageloader.QiniuImageLoader; @@ -32,17 +30,12 @@ */ public class PicassoQiniuImageLoader extends QiniuImageLoader { - static int DEFAULT_PLACE_HOLDER = 0; - static int DEFAULT_AVATAR_PLACE_HOLDER = 0; - /** * 建议用于绑定Activity生命周期,回收网络资源所用 * (如Activity#onResume时,根据target区分出其他Activity,并将他们全部暂停) */ static PicassoLoader.TargetProvider DEFAULT_TARGET_PROVIDER = null; - private boolean isAvatar = false; - public PicassoQiniuImageLoader(Context context, String oriUrl) { super(context, oriUrl); } @@ -51,41 +44,15 @@ public PicassoQiniuImageLoader(ImageView imageView, String oriUrl) { super(imageView, oriUrl); } - - /** - * 占位图采用默认头像的占位图 - * - * @return - * @see #DEFAULT_AVATAR_PLACE_HOLDER - */ - public PicassoQiniuImageLoader avatar() { - this.isAvatar = true; - return this; - } - - - /** - * 使用Picasso加载图片到目标ImageView上,并且不清理存储的各类属性参数 - */ @Override - public void attachWithNoClear() { - if (getImageView() == null) { - throw new InvalidParameterException(String.format("imageView must not be null! %s", getOriUrl())); - } - - String u = createQiniuUrl(); - - Drawable d = this.defaultDrawable; - - if (d == null) { - if (isAvatar) { - d = getDrawable(getImageView(), DEFAULT_AVATAR_PLACE_HOLDER); - } else { - d = getDrawable(getImageView(), DEFAULT_PLACE_HOLDER); - } - } - - PicassoLoader.display(getImageView(), u, d, transformation, findTarget(), attachCallback); + protected void attachWithNoClear(String url) { + PicassoLoader.display( + getImageView(), + url, + this.defaultDrawable, + transformation, + findTarget(), + attachCallback); } private Target findTarget() { @@ -100,62 +67,13 @@ private Target findTarget() { return null; } - private Drawable defaultDrawable; - - /** - * 指定占位图 - * - * @param defaultDrawable DrawableRes - * @return - */ - public PicassoQiniuImageLoader defaultD(final int defaultDrawable) { - this.defaultDrawable = getDrawable(getImageView(), defaultDrawable); - return this; - } - - /** - * 指定占位图 - * - * @param defaultDrawable - * @return - */ - public PicassoQiniuImageLoader defaultD(final Drawable defaultDrawable) { - this.defaultDrawable = defaultDrawable; - return this; - } - - /** - * @param imageView - * @param resourceId DrawableRes - * @return - */ - protected Drawable getDrawable(final ImageView imageView, final int resourceId) { - if (resourceId == 0) { - return null; - } - - Drawable drawable = null; - try { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { - drawable = imageView.getResources().getDrawable(resourceId); - } else { - drawable = imageView.getContext().getDrawable(resourceId); - } - - } catch (Exception e) { - e.printStackTrace(); - } - - return drawable; - } - private Target target; /** * 指定picasso的Target * - * @param target - * @return + * @param target com.squareup.picasso.Target + * @return PicassoQiniuImageLoader */ public PicassoQiniuImageLoader target(final Target target) { this.target = target; @@ -167,8 +85,8 @@ public PicassoQiniuImageLoader target(final Target target) { /** * 指定Transformation * - * @param transformation - * @return + * @param transformation Image transformation + * @return PicassoQiniuImageLoader */ public PicassoQiniuImageLoader transformation(final Transformation transformation) { this.transformation = transformation; @@ -180,8 +98,8 @@ public PicassoQiniuImageLoader transformation(final Transformation transformatio /** * 指定picasso的Callback * - * @param attachCallback - * @return + * @param attachCallback Image load callback + * @return PicassoQiniuImageLoader */ public PicassoQiniuImageLoader attachCallback(final Callback attachCallback) { this.attachCallback = attachCallback;