From a44ce6d93690d471808d237a3fc7573d927031ce Mon Sep 17 00:00:00 2001 From: kymjs Date: Mon, 7 Sep 2015 16:48:32 +0800 Subject: [PATCH] =?UTF-8?q?KJBitmap=E6=B7=BB=E5=8A=A0=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E5=8A=A0=E5=AF=86=E4=BC=A0=E8=BE=93=E7=9A=84=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KJFrame/kjframe/build.gradle | 2 +- .../main/java/org/kymjs/kjframe/KJBitmap.java | 6 +++++- .../kymjs/kjframe/bitmap/ImageDisplayer.java | 17 ++++++++--------- .../org/kymjs/kjframe/bitmap/ImageRequest.java | 16 +++++++++++++--- 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/KJFrame/kjframe/build.gradle b/KJFrame/kjframe/build.gradle index 1017c0a9..cb46cdee 100644 --- a/KJFrame/kjframe/build.gradle +++ b/KJFrame/kjframe/build.gradle @@ -2,7 +2,7 @@ apply plugin: 'com.android.library' apply plugin: 'com.jfrog.bintray' apply plugin: 'com.github.dcendents.android-maven' -version = "2.4.3" +version = "2.4.3.2" android { compileSdkVersion 22 diff --git a/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/KJBitmap.java b/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/KJBitmap.java index c9e4d5a9..0271665b 100644 --- a/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/KJBitmap.java +++ b/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/KJBitmap.java @@ -69,8 +69,12 @@ public KJBitmap() { } public KJBitmap(BitmapConfig bitmapConfig) { + this(new HttpConfig(), bitmapConfig); + } + + public KJBitmap(HttpConfig httpConfig, BitmapConfig bitmapConfig) { this.mConfig = bitmapConfig; - displayer = new ImageDisplayer(mConfig); + displayer = new ImageDisplayer(httpConfig, mConfig); doLoadingViews = new Vector(30); } diff --git a/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/bitmap/ImageDisplayer.java b/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/bitmap/ImageDisplayer.java index e5089fb9..03aed96c 100755 --- a/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/bitmap/ImageDisplayer.java +++ b/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/bitmap/ImageDisplayer.java @@ -15,8 +15,9 @@ */ package org.kymjs.kjframe.bitmap; -import java.util.HashMap; -import java.util.LinkedList; +import android.graphics.Bitmap; +import android.os.Handler; +import android.os.Looper; import org.kymjs.kjframe.KJHttp; import org.kymjs.kjframe.http.HttpCallBack; @@ -24,9 +25,8 @@ import org.kymjs.kjframe.http.KJHttpException; import org.kymjs.kjframe.http.Request; -import android.graphics.Bitmap; -import android.os.Handler; -import android.os.Looper; +import java.util.HashMap; +import java.util.LinkedList; /** * 图片显示器 @@ -49,18 +49,17 @@ public class ImageDisplayer { /** * 创建一个图片显示器 - * + * * @param bitmapConfig */ - public ImageDisplayer(BitmapConfig bitmapConfig) { - HttpConfig config = new HttpConfig(); + public ImageDisplayer(HttpConfig httpConfig, BitmapConfig bitmapConfig) { // 靠,在这里踩了个坑。 最初写的是Integer.MAX_VALUE, // 结果把这个值*60000转成毫秒long以后溢出了 这次我给个死的值行不行。1000天,能不能算永久了 // 其实还有一种解决办法是直接在缓存读取的时候,看到是bitmap缓存不管是否失效都返回, // 但是这种不利于自定义扩展,就不用了,有兴趣的可以看CacheDispatcher的105行 // @kymjs记录于2015.4.30 // config.cacheTime = bitmapConfig.cacheTime; - mKJHttp = new KJHttp(config); + mKJHttp = new KJHttp(httpConfig); mMemoryCache = BitmapConfig.mMemoryCache; mResponseDelayMs = bitmapConfig.delayTime; } diff --git a/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/bitmap/ImageRequest.java b/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/bitmap/ImageRequest.java index 4969fa99..4e8c35f7 100755 --- a/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/bitmap/ImageRequest.java +++ b/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/bitmap/ImageRequest.java @@ -16,9 +16,11 @@ package org.kymjs.kjframe.bitmap; -import java.util.Map; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; import org.kymjs.kjframe.http.HttpCallBack; +import org.kymjs.kjframe.http.HttpConfig; import org.kymjs.kjframe.http.HttpHeaderParser; import org.kymjs.kjframe.http.KJHttpException; import org.kymjs.kjframe.http.NetworkResponse; @@ -26,8 +28,8 @@ import org.kymjs.kjframe.http.Response; import org.kymjs.kjframe.utils.KJLoger; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; +import java.util.HashMap; +import java.util.Map; /** * 从网络下载一张bitmap @@ -41,9 +43,12 @@ public class ImageRequest extends Request { // 用来保证当前对象只有一个线程在访问 private static final Object sDecodeLock = new Object(); + private final Map mHeaders = new HashMap(); + public ImageRequest(String url, int maxWidth, int maxHeight, HttpCallBack callback) { super(HttpMethod.GET, url, callback); + mHeaders.put("cookie", HttpConfig.sCookie); mMaxWidth = maxWidth; mMaxHeight = maxHeight; } @@ -58,6 +63,11 @@ public String getCacheKey() { return getUrl(); } + @Override + public Map getHeaders() { + return mHeaders; + } + /** * 框架会自动将大于设定值的bitmap转换成设定值,所以需要这个方法来判断应该显示默认大小或者是设定值大小。
* 本方法会根据maxPrimary与actualPrimary比较来判断,如果无法判断则会根据辅助值判断,辅助值一般是主要值对应的。