diff --git a/config.gradle b/config.gradle index c2c71ebf9c..8c86d0bd4f 100644 --- a/config.gradle +++ b/config.gradle @@ -40,10 +40,10 @@ ext { arouter : "com.alibaba:arouter-api:1.0.12-mogo", aroutercompiler : "com.alibaba:arouter-compiler:1.0.12-mogo", // glide - glide : 'com.github.bumptech.glide:glide:4.8.0', - glideokhttp3 : 'com.github.bumptech.glide:okhttp3-integration:4.8.0', - glideanno : 'com.github.bumptech.glide:annotations:4.8.0', - glidecompiler : 'com.github.bumptech.glide:compiler:4.8.0', + glide : 'com.github.bumptech.glide:glide:4.11.0', + glideokhttp3 : 'com.github.bumptech.glide:okhttp3-integration:4.11.0', + glideanno : 'com.github.bumptech.glide:annotations:4.11.0', + glidecompiler : 'com.github.bumptech.glide:compiler:4.11.0', androidxannotation : "androidx.annotation:annotation:1.2.0", okhttpinterceptor : "com.squareup.okhttp3:logging-interceptor:3.12.0", // fresco diff --git a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/widget/SweeperVideoView.java b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/widget/SweeperVideoView.java new file mode 100644 index 0000000000..ce038d1457 --- /dev/null +++ b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/widget/SweeperVideoView.java @@ -0,0 +1,87 @@ +package com.mogo.eagle.core.function.hmi.ui.widget; + + +import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.drawable.Drawable; +import android.util.AttributeSet; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.widget.AppCompatImageView; + +import com.bumptech.glide.Priority; +import com.bumptech.glide.load.engine.DiskCacheStrategy; +import com.bumptech.glide.request.RequestOptions; +import com.bumptech.glide.request.target.CustomTarget; +import com.bumptech.glide.request.transition.Transition; +import com.mogo.eagle.core.function.api.autopilot.IMoGoSweeperFutianBackCameraVideoListener; +import com.mogo.eagle.core.function.call.autopilot.CallerSweeperFutianBackCameraVideoListenerManager; +import com.mogo.eagle.core.utilcode.mogo.glide.GlideApp; +import com.mogo.eagle.core.utilcode.util.ThreadUtils; + +/** + * 清扫车摄像头展示View + */ +public class SweeperVideoView extends AppCompatImageView implements IMoGoSweeperFutianBackCameraVideoListener { + private static final String TAG = SweeperVideoView.class.getSimpleName(); + private final RequestOptions requestOptions = new RequestOptions() + .priority(Priority.HIGH) + .skipMemoryCache(true) + .diskCacheStrategy(DiskCacheStrategy.NONE) + .dontAnimate(); + + public SweeperVideoView(@NonNull Context context) { + super(context); + } + + public SweeperVideoView(@NonNull Context context, @Nullable AttributeSet attrs) { + super(context, attrs); + } + + public SweeperVideoView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + @Override + protected void onAttachedToWindow() { + super.onAttachedToWindow(); + CallerSweeperFutianBackCameraVideoListenerManager.INSTANCE.addListener(TAG, this); + } + + @Override + protected void onDetachedFromWindow() { + super.onDetachedFromWindow(); + CallerSweeperFutianBackCameraVideoListenerManager.INSTANCE.removeListener(this); + } + + private final CustomTarget target = new CustomTarget() { + @Override + public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition transition) { + //回调内容 + if (!resource.isRecycled()) { + SweeperVideoView.this.setImageBitmap(resource); + } + } + + @Override + public void onLoadCleared(@Nullable Drawable placeholder) { + //这个方法在target被回收时调用,如果在除了imageView以外的地方引用了imageView中的bitmap,在这里清除引用以避免崩溃 + } + }; + + @Override + public void onSweeperFutianBackCameraVideo(@NonNull byte[] data) { + ThreadUtils.runOnUiThread(new Runnable() { + @Override + public void run() { + GlideApp.with(SweeperVideoView.this) + .asBitmap() + .load(data) + .placeholder(SweeperVideoView.this.getDrawable()) + .apply(requestOptions) + .into(target); + } + }); + } +}