Skip to content

Commit

Permalink
代码优化
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaojieonly committed Nov 7, 2024
1 parent 770fbeb commit 1ae996e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 33 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ dependencies {
// implementation 'com.alibaba.fastjson2:fastjson2:2.0.47'

implementation 'com.android.support:multidex:1.0.3'

// implementation 'com.github.bumptech.glide:glide:4.16.0'
/**
* 原始依赖
*/
Expand Down
13 changes: 2 additions & 11 deletions app/src/main/java/com/hippo/lib/image/Image.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class Image private constructor(
) {
internal var mObtainedDrawable: Drawable?
private var mBitmap: Bitmap? = null
// public val MAX_BITMAP_SIZE = 100 * 1024 * 1024

init {
mObtainedDrawable = null
Expand Down Expand Up @@ -82,11 +81,11 @@ class Image private constructor(
}
// Should we lazy decode it?
} else {
mObtainedDrawable = Drawable.createFromStream(source, "image")
mObtainedDrawable=Drawable.createFromStream(source,null)
}
}
if (mObtainedDrawable == null) {
mObtainedDrawable = drawable!!
mObtainedDrawable = drawable
// throw IllegalArgumentException("数据解码出错")
}
}
Expand All @@ -109,12 +108,7 @@ class Image private constructor(
if (mObtainedDrawable is AnimatedImageDrawable) {
(mObtainedDrawable as AnimatedImageDrawable?)?.stop()
}
} else {
if (mObtainedDrawable is AnimationDrawable) {
(mObtainedDrawable as AnimationDrawable?)?.stop()
}
}

if (mObtainedDrawable is BitmapDrawable) {
(mObtainedDrawable as BitmapDrawable?)?.bitmap?.recycle()
}
Expand Down Expand Up @@ -180,10 +174,7 @@ class Image private constructor(
if (!started) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
(mObtainedDrawable as AnimatedImageDrawable?)?.start()
} else {
(mObtainedDrawable as AnimationDrawable?)?.start()
}

}
}

Expand Down
24 changes: 15 additions & 9 deletions app/src/main/java/com/hippo/widget/LoadImageView.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ private void clearDrawable() {

// Set drawable null
setImageDrawable(null);
if (imageBitmap!=null){
if (imageBitmap != null) {
imageBitmap.release();
imageBitmap = null;
}
Expand Down Expand Up @@ -305,6 +305,7 @@ public boolean onGetValue(@NonNull ImageBitmap value, int source) {
} else {
setImageDrawable(drawable);
}

imageBitmap = value;
return true;
}
Expand Down Expand Up @@ -341,27 +342,32 @@ public void onCancel() {
@Override
public void start() {
Drawable drawable = getImageDrawable();
if (drawable instanceof AnimatedImageDrawable animatedImageDrawable) {
animatedImageDrawable.start();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
if (drawable instanceof AnimatedImageDrawable animatedImageDrawable) {
animatedImageDrawable.start();
}
}
}

@Override
public void stop() {
Drawable drawable = getImageDrawable();
if (drawable instanceof AnimatedImageDrawable animatedImageDrawable) {
animatedImageDrawable.stop();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
if (drawable instanceof AnimatedImageDrawable animatedImageDrawable) {
animatedImageDrawable.stop();
}
}
}

@Override
public boolean isRunning() {
Drawable drawable = getImageDrawable();
if (drawable instanceof AnimatedImageDrawable animatedImageDrawable) {
return animatedImageDrawable.isRunning();
} else {
return false;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
if (drawable instanceof AnimatedImageDrawable animatedImageDrawable) {
return animatedImageDrawable.isRunning();
}
}
return false;
}

@Override
Expand Down
32 changes: 20 additions & 12 deletions app/src/main/java/com/hippo/widget/LoadImageViewNew.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.TransitionDrawable;
import android.os.Build;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
Expand All @@ -49,7 +50,7 @@
import java.lang.annotation.RetentionPolicy;

public class LoadImageViewNew extends FixedAspectImageView implements Unikery<ImageBitmap>,
View.OnClickListener, View.OnLongClickListener,Animatable {
View.OnClickListener, View.OnLongClickListener, Animatable {

public static final int RETRY_TYPE_NONE = 0;
public static final int RETRY_TYPE_CLICK = 1;
Expand Down Expand Up @@ -211,7 +212,7 @@ public void resetClip() {
mClipHeight = Integer.MIN_VALUE;
}

public void load(){
public void load() {
load(mKey, mUrl, true);
}

Expand All @@ -221,7 +222,7 @@ public void load(String key, String url) {


public void load(String key, String url, boolean useNetwork) {
if (url == null || key == null ) {
if (url == null || key == null) {
return;
}

Expand All @@ -238,7 +239,7 @@ public void load(String key, String url, boolean useNetwork) {
.setKey(key)
.setUrl(url)
.setUseNetwork(useNetwork);
if (url.contains(DOMAIN_EX)||url.contains(DOMAIN_E)){
if (url.contains(DOMAIN_EX) || url.contains(DOMAIN_E)) {
builder.setOkHttpClient(EhApplication.getOkHttpClient(getContext()));
}
mConaco.load(builder);
Expand Down Expand Up @@ -345,27 +346,34 @@ public void onCancel() {
@Override
public void start() {
Drawable drawable = getImageDrawable();
if (drawable instanceof AnimatedImageDrawable animatedImageDrawable) {
animatedImageDrawable.start();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
if (drawable instanceof AnimatedImageDrawable animatedImageDrawable) {
animatedImageDrawable.start();
}
}
}

@Override
public void stop() {
Drawable drawable = getImageDrawable();
if (drawable instanceof AnimatedImageDrawable animatedImageDrawable) {
animatedImageDrawable.stop();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
if (drawable instanceof AnimatedImageDrawable animatedImageDrawable) {
animatedImageDrawable.stop();
}
}

}

@Override
public boolean isRunning() {
Drawable drawable = getImageDrawable();
if (drawable instanceof AnimatedImageDrawable animatedImageDrawable) {
return animatedImageDrawable.isRunning();
} else {
return false;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
if (drawable instanceof AnimatedImageDrawable animatedImageDrawable) {
return animatedImageDrawable.isRunning();
}
}
return false;

}

@Override
Expand Down

0 comments on commit 1ae996e

Please sign in to comment.