From a646a4ef05c4f5f532d1aebbb561a3dd37246b99 Mon Sep 17 00:00:00 2001 From: xinfengkun Date: Thu, 6 Apr 2023 14:31:36 +0800 Subject: [PATCH] =?UTF-8?q?[sweeper310]=20cheery=20pick=20[hmi]=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B8=85=E6=89=AB=E8=BD=A6=E6=91=84=E5=83=8F?= =?UTF-8?q?=E5=A4=B4View=EF=BC=8C=E5=8D=87=E7=BA=A7glide=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.gradle | 8 +- .../hmi/ui/widget/SweeperVideoView.java | 87 +++++++++++++++++++ 2 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/widget/SweeperVideoView.java 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); + } + }); + } +}