diff --git a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/MoGoHmiFragment.kt b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/MoGoHmiFragment.kt index 2dac3b397b..242e1c9ed4 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/MoGoHmiFragment.kt +++ b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/MoGoHmiFragment.kt @@ -9,6 +9,7 @@ import android.view.animation.OvershootInterpolator import com.mogo.commons.mvp.MvpFragment import com.mogo.commons.voice.AIAssist import com.mogo.eagle.core.data.enums.WarningDirectionEnum +import com.mogo.eagle.core.data.notice.NoticeNormalData import com.mogo.eagle.core.data.notice.NoticeTrafficStylePushData import com.mogo.eagle.core.function.api.hmi.warning.IMoGoWarningStatusListener import com.mogo.eagle.core.function.hmi.R @@ -16,6 +17,7 @@ import com.mogo.eagle.core.function.hmi.notification.WarningFloat import com.mogo.eagle.core.function.hmi.notification.anim.DefaultAnimator import com.mogo.eagle.core.function.hmi.notification.enums.SidePattern import com.mogo.eagle.core.function.hmi.ui.notice.NoticeBannerView +import com.mogo.eagle.core.function.hmi.ui.notice.NoticeFloatView import com.mogo.eagle.core.function.hmi.ui.widget.V2XNotificationView import com.mogo.module.common.enums.EventTypeEnum import com.mogo.utils.logger.Logger @@ -215,8 +217,60 @@ class MoGoHmiFragment : MvpFragment override fun showNoticeForTrafficWithData(trafficStylePushData: NoticeTrafficStylePushData) { activity.let { val noticeBannerView = this.getContext()?.let { it1 -> NoticeBannerView(it1) } + mWarningFloat = it?.let { it1 -> + noticeBannerView?.let { it2 -> + WarningFloat.with(it1) + .setTag(tag) + .setLayout(it2) + .setSidePattern(SidePattern.TOP) + .setCountDownTime(5000) + .setGravity(Gravity.CENTER_HORIZONTAL, offsetY = 110) + .setImmersionStatusBar(true) + .addWarningStatusListener(null) + .addWarningStatusListener(object : IMoGoWarningStatusListener { + override fun onShow() { + // 创建弹窗成功才进行TTS播报 +// AIAssist.getInstance(activity) +// .speakTTSVoice("") + } + }) + .setAnimator(object : DefaultAnimator() { + override fun enterAnim( + view: View, + params: WindowManager.LayoutParams, + windowManager: WindowManager, + sidePattern: SidePattern + ): Animator? = + super.enterAnim(view, params, windowManager, sidePattern)?.apply { + interpolator = OvershootInterpolator() + } + override fun exitAnim( + view: View, + params: WindowManager.LayoutParams, + windowManager: WindowManager, + sidePattern: SidePattern + ): Animator? = + super.exitAnim(view, params, windowManager, sidePattern)?.setDuration(200) + }) + .show() + } + } } } + + var floatView: NoticeFloatView? = null + + /** + * 展示普通公告 liyz + * @param normalData + */ + override fun showNoticeNormal(normalData: NoticeNormalData) { + if (floatView == null) { + floatView = this.getContext()?.let { NoticeFloatView(it) } + } + floatView?.pushBeanChanged(normalData) + } + } \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/MoGoWarningContract.kt b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/MoGoWarningContract.kt index a22ee3ede8..ddfb1a48ca 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/MoGoWarningContract.kt +++ b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/MoGoWarningContract.kt @@ -3,6 +3,7 @@ package com.mogo.eagle.core.function.hmi.ui import com.mogo.commons.mvp.IView import com.mogo.eagle.core.data.enums.WarningDirectionEnum import com.mogo.eagle.core.data.notice.NoticeTrafficStylePushData +import com.mogo.eagle.core.data.notice.NoticeNormalData import com.mogo.eagle.core.function.api.hmi.warning.IMoGoWarningStatusListener @@ -102,5 +103,11 @@ interface MoGoWarningContract { * @param trafficStylePushData */ fun showNoticeForTrafficWithData(trafficStylePushData: NoticeTrafficStylePushData) + + /** + * 展示普通云公告 + * @param normalData + */ + fun showNoticeNormal(normalData: NoticeNormalData) } } \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/notice/NoticeCheckDialog.kt b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/notice/NoticeCheckDialog.kt new file mode 100644 index 0000000000..a5efe22924 --- /dev/null +++ b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/notice/NoticeCheckDialog.kt @@ -0,0 +1,40 @@ +package com.mogo.eagle.core.function.hmi.ui.notice + +import android.content.Context +import android.widget.ImageView +import android.widget.TextView +import com.mogo.eagle.core.function.hmi.R +import com.mogo.module.common.dialog.BaseFloatDialog + +/** + * 点击查看对话框,需要做接口的请求 TODO + */ +class NoticeCheckDialog(context: Context) : BaseFloatDialog(context) { + + private var pushCheckClose: ImageView? = null + private var pushCheckTitle: TextView? = null + private var pushCheckContent: TextView? = null + + init { + setContentView(R.layout.notice_push_dialog_check) + setCanceledOnTouchOutside(true) + pushCheckClose = findViewById(R.id.module_push_dialog_close) + pushCheckTitle = findViewById(R.id.module_push_dialog_title) + pushCheckContent = findViewById(R.id.module_push_dialog_content) + pushCheckClose?.setOnClickListener { + dismiss() + } + } + + fun showCheckDialog(title: String, content: String) { + if (isShowing) { + return + } + if (title.isBlank() || content.isBlank()) { + return + } + pushCheckTitle?.text = title + pushCheckContent?.text = content + show() + } +} \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/notice/NoticeFloatView.kt b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/notice/NoticeFloatView.kt new file mode 100644 index 0000000000..c101eee60b --- /dev/null +++ b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/notice/NoticeFloatView.kt @@ -0,0 +1,274 @@ +package com.mogo.eagle.core.function.hmi.ui.notice + +import android.content.Context +import android.os.Handler +import android.os.Looper +import android.util.Log +import android.view.LayoutInflater +import android.view.View +import android.widget.FrameLayout +import android.widget.TextView +import androidx.annotation.LayoutRes +import com.mogo.commons.context.ContextHolderUtil +import com.mogo.eagle.core.data.notice.NoticeNormalData +import com.mogo.eagle.core.function.hmi.R +import com.mogo.eagle.core.function.hmi.ui.notice.roundimage.RoundedImageView +import com.mogo.eagle.core.function.hmi.ui.utils.getApis +import com.mogo.eagle.core.function.hmi.ui.utils.gone +import com.mogo.eagle.core.function.hmi.ui.utils.visible +import com.mogo.service.windowview.IMogoTopViewManager +import com.mogo.service.windowview.IMogoTopViewStatusListener +import com.mogo.utils.glide.GlideApp + +/** + * 云公告弹框view + */ +class NoticeFloatView constructor( + private val context: Context +) { + + companion object { + const val TYPE_TOP_VIEW = 1 + const val TYPE_WINDOW_MANAGER = 2 + const val TAG: String = "FloatView.kt" + } + + interface PushViewController { + fun show(bean: NoticeNormalData?) + fun hide() + fun inflateView(@LayoutRes layoutId: Int) + } + + abstract inner class PushView(context: Context) : FrameLayout(context), + PushViewController { + private lateinit var titleIconContainer: View + private lateinit var pushTitle: TextView + private lateinit var pushImage: RoundedImageView + private lateinit var pushContent: TextView + private lateinit var pushCheck: TextView + private var pushData: NoticeNormalData? = null + + override fun inflateView(layoutId: Int) { + LayoutInflater.from(context).inflate(layoutId, this, true) + pushTitle = findViewById(R.id.module_push_title) + pushCheck = findViewById(R.id.module_push_check) + pushImage = findViewById(R.id.module_push_image) + pushContent = findViewById(R.id.module_push_content) + titleIconContainer = findViewById(R.id.module_push_app_icon_title) + + //查看结果 + pushCheck.setOnClickListener { + pushData?.let { + if (pushCheckDialog == null) { + pushCheckDialog = NoticeCheckDialog(ContextHolderUtil.getContext()) + } + pushCheckDialog!!.showCheckDialog(it.title, it.content) + } + } + } + + open fun setBean(bean: NoticeNormalData) { + pushData = bean + // title + pushTitle.text = bean.title + + // image + if (bean.imageUrl.isEmpty() && bean.QRCode.isEmpty()) { + pushImage.gone() + } else if (bean.imageUrl.isNotEmpty()) { + val params = pushImage.layoutParams + params.width = getImgWidth() + params.height = getImgHeight() + pushImage.layoutParams = params + pushImage.visible() + GlideApp.with(this).load(bean.imageUrl).into(pushImage) + } else if (bean.QRCode.isNotEmpty()) { + val params = pushImage.layoutParams + params.width = getQrImgWidth() + params.height = getQrImgHeight() + pushImage.layoutParams = params +// ThreadPoolService.execute { +// val bmp = stringConverterBitmap( +// bean.QRCode, +// getQrImgWidth(), +// getQrImgHeight() +// ) +// UiThreadHandler.post { +// pushImage.setImageBitmap(bmp) +// pushImage.visible() +// } +// } + } + + // content + if (bean.content.isEmpty()) { + pushContent.gone() + } else { + pushContent.text = bean.content + pushContent.visible() + } + + // 产品侧需要重新梳理,tts暂时不播报 +// if (bean.tts.isNotEmpty()) { +// AIAssist.getInstance(context).speakTTSVoice(bean.tts) +// } + } + + abstract fun getImgWidth(): Int + abstract fun getImgHeight(): Int + abstract fun getQrImgWidth(): Int + abstract fun getQrImgHeight(): Int + + override fun show(bean: NoticeNormalData?) { + isAddWindow = true + uiHandler.removeCallbacks(delayClosePush) + } + + override fun hide() { + isAddWindow = false + } + } + + + open inner class PushViewInTopView(context: Context) : PushView(context) { + + private val mTopViewManager: IMogoTopViewManager = getApis(context).topViewManager + + init { + inflateView(R.layout.notice_module_push_item) + } + + private var topViewStatusListener = object : IMogoTopViewStatusListener { + override fun onViewRemoved(view: View?) { + isAddWindow = false + } + + override fun onViewAdded(view: View?) { + + } + + override fun beforeViewRemoveAnim(view: View?) { + } + + override fun beforeViewAddAnim(view: View?) { + } + } + + override fun show(bean: NoticeNormalData?) { + super.show(bean) + mLastVisibleType = TYPE_TOP_VIEW + mTopViewManager.addView(this, topViewStatusListener) + setBean(bean!!) + } + + override fun hide() { + super.hide() + mTopViewManager.removeView(this) + } + + override fun getImgWidth(): Int = + context.resources.getDimensionPixelSize(R.dimen.module_push_ui_image_width) + + override fun getImgHeight(): Int = + context.resources.getDimensionPixelSize(R.dimen.module_push_ui_image_height) + + override fun getQrImgWidth(): Int = + context.resources.getDimensionPixelSize(R.dimen.module_push_ui_image_height) + + override fun getQrImgHeight(): Int = + context.resources.getDimensionPixelSize(R.dimen.module_push_ui_image_height) + } + + private var pushCheckDialog: NoticeCheckDialog? = null + private val delayClosePush: Runnable + private var isAddWindow = false + private val uiHandler = Handler(Looper.getMainLooper()) + + private var currentBean: NoticeNormalData? = null + private var mLastVisibleType = -1 + private var pushViewController: PushViewController? = null + + init { + delayClosePush = Runnable { + + } + } + + fun pushBeanChanged(bean: NoticeNormalData?) { + Log.d("liyz", "NoticeFloatVideo pushBeanChanged -----> bean = " + bean) + uiHandler.post { + uiHandler.removeCallbacks(delayClosePush) + if (bean == null) { + hide() + } else { + show(bean) + } + currentBean = bean + } + } + + private fun show(bean: NoticeNormalData) { + if (isAddWindow) { + if (getApis(context).statusManagerApi.isMainPageOnResume) { + if (mLastVisibleType != TYPE_TOP_VIEW) { + hide() + (pushViewController as View).postDelayed({ + show(bean) + }, 750L) + } else { + showByTopView(bean) + } + } else { + if (mLastVisibleType != TYPE_WINDOW_MANAGER) { + hide() + (pushViewController as View).postDelayed({ + show(bean) + }, 750L) + } else { + showByWindowManager(bean) + } + } + startClosePush() + } else { + if (getApis(context).statusManagerApi.isMainPageOnResume) { + showByTopView(bean) + } else { + showByWindowManager(bean) + } + } + } + + private fun showByTopView(bean: NoticeNormalData) { + if (pushViewController !is PushViewInTopView) { + pushViewController = PushViewInTopView(context) + } + pushViewController?.show(bean) + } + + private fun showByWindowManager(bean: NoticeNormalData?) { +// if (pushViewController !is PushViewInWindowView) { +// pushViewController = PushViewInWindowView(context) +// } +// pushViewController?.show(bean) + } + + private fun startClosePush() { + uiHandler.removeCallbacks(delayClosePush) + uiHandler.postDelayed( + delayClosePush, + 1000L + ) + } + + fun hide() { + if (!isAddWindow) { + return + } + try { + pushViewController?.hide() + } catch (e: Exception) { + e.printStackTrace() + } + } + +} \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/notice/roundimage/Corner.java b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/notice/roundimage/Corner.java new file mode 100644 index 0000000000..5239c2be29 --- /dev/null +++ b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/notice/roundimage/Corner.java @@ -0,0 +1,19 @@ +package com.mogo.eagle.core.function.hmi.ui.notice.roundimage; + + +import androidx.annotation.IntDef; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.SOURCE) +@IntDef({ + Corner.TOP_LEFT, Corner.TOP_RIGHT, + Corner.BOTTOM_LEFT, Corner.BOTTOM_RIGHT +}) +public @interface Corner { + int TOP_LEFT = 0; + int TOP_RIGHT = 1; + int BOTTOM_RIGHT = 2; + int BOTTOM_LEFT = 3; +} diff --git a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/notice/roundimage/RoundedDrawable.java b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/notice/roundimage/RoundedDrawable.java new file mode 100644 index 0000000000..33e75d1602 --- /dev/null +++ b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/notice/roundimage/RoundedDrawable.java @@ -0,0 +1,633 @@ +/* +* Copyright (C) 2015 Vincent Mi +* +* 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. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package com.mogo.eagle.core.function.hmi.ui.notice.roundimage; + +import android.content.res.ColorStateList; +import android.graphics.Bitmap; +import android.graphics.Bitmap.Config; +import android.graphics.BitmapShader; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.ColorFilter; +import android.graphics.Matrix; +import android.graphics.Paint; +import android.graphics.PixelFormat; +import android.graphics.Rect; +import android.graphics.RectF; +import android.graphics.Shader; +import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.Drawable; +import android.graphics.drawable.LayerDrawable; +import android.util.Log; +import android.widget.ImageView.ScaleType; + +import androidx.annotation.ColorInt; +import androidx.annotation.NonNull; + +import java.util.HashSet; +import java.util.Set; + +@SuppressWarnings("UnusedDeclaration") +public class RoundedDrawable extends Drawable { + + public static final String TAG = "RoundedDrawable"; + public static final int DEFAULT_BORDER_COLOR = Color.BLACK; + + private final RectF mBounds = new RectF(); + private final RectF mDrawableRect = new RectF(); + private final RectF mBitmapRect = new RectF(); + private final Bitmap mBitmap; + private final Paint mBitmapPaint; + private final int mBitmapWidth; + private final int mBitmapHeight; + private final RectF mBorderRect = new RectF(); + private final Paint mBorderPaint; + private final Matrix mShaderMatrix = new Matrix(); + private final RectF mSquareCornersRect = new RectF(); + + private Shader.TileMode mTileModeX = Shader.TileMode.CLAMP; + private Shader.TileMode mTileModeY = Shader.TileMode.CLAMP; + private boolean mRebuildShader = true; + + // [ topLeft, topRight, bottomLeft, bottomRight ] + private float mCornerRadius = 0f; + private final boolean[] mCornersRounded = new boolean[] { true, true, true, true }; + + private boolean mOval = false; + private float mBorderWidth = 0; + private ColorStateList mBorderColor = ColorStateList.valueOf(DEFAULT_BORDER_COLOR); + private ScaleType mScaleType = ScaleType.FIT_CENTER; + + public RoundedDrawable(Bitmap bitmap) { + mBitmap = bitmap; + + mBitmapWidth = bitmap.getWidth(); + mBitmapHeight = bitmap.getHeight(); + mBitmapRect.set(0, 0, mBitmapWidth, mBitmapHeight); + + mBitmapPaint = new Paint(); + mBitmapPaint.setStyle(Paint.Style.FILL); + mBitmapPaint.setAntiAlias(true); + + mBorderPaint = new Paint(); + mBorderPaint.setStyle(Paint.Style.STROKE); + mBorderPaint.setAntiAlias(true); + mBorderPaint.setColor(mBorderColor.getColorForState(getState(), DEFAULT_BORDER_COLOR)); + mBorderPaint.setStrokeWidth(mBorderWidth); + } + + public static RoundedDrawable fromBitmap(Bitmap bitmap) { + if (bitmap != null) { + return new RoundedDrawable(bitmap); + } else { + return null; + } + } + + public static Drawable fromDrawable(Drawable drawable) { + if (drawable != null) { + if (drawable instanceof RoundedDrawable) { + // just return if it's already a RoundedDrawable + return drawable; + } else if (drawable instanceof LayerDrawable) { + LayerDrawable ld = (LayerDrawable) drawable; + int num = ld.getNumberOfLayers(); + + // loop through layers to and change to RoundedDrawables if possible + for (int i = 0; i < num; i++) { + Drawable d = ld.getDrawable(i); + ld.setDrawableByLayerId(ld.getId(i), fromDrawable(d)); + } + return ld; + } + + // try to get a bitmap from the drawable and + Bitmap bm = drawableToBitmap(drawable); + if (bm != null) { + return new RoundedDrawable(bm); + } + } + return drawable; + } + + public static Bitmap drawableToBitmap(Drawable drawable) { + if (drawable instanceof BitmapDrawable) { + return ((BitmapDrawable) drawable).getBitmap(); + } + + Bitmap bitmap; + int width = Math.max(drawable.getIntrinsicWidth(), 2); + int height = Math.max(drawable.getIntrinsicHeight(), 2); + try { + bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888); + Canvas canvas = new Canvas(bitmap); + drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); + drawable.draw(canvas); + } catch (Exception e) { + e.printStackTrace(); + Log.w(TAG, "Failed to create bitmap from drawable!"); + bitmap = null; + } + + return bitmap; + } + + public Bitmap getSourceBitmap() { + return mBitmap; + } + + @Override + public boolean isStateful() { + return mBorderColor.isStateful(); + } + + @Override + protected boolean onStateChange(int[] state) { + int newColor = mBorderColor.getColorForState(state, 0); + if (mBorderPaint.getColor() != newColor) { + mBorderPaint.setColor(newColor); + return true; + } else { + return super.onStateChange(state); + } + } + + private void updateShaderMatrix() { + float scale; + float dx; + float dy; + + switch (mScaleType) { + case CENTER: + mBorderRect.set(mBounds); + mBorderRect.inset(mBorderWidth / 2, mBorderWidth / 2); + + mShaderMatrix.reset(); + mShaderMatrix.setTranslate((int) ((mBorderRect.width() - mBitmapWidth) * 0.5f + 0.5f), + (int) ((mBorderRect.height() - mBitmapHeight) * 0.5f + 0.5f)); + break; + + case CENTER_CROP: + mBorderRect.set(mBounds); + mBorderRect.inset(mBorderWidth / 2, mBorderWidth / 2); + + mShaderMatrix.reset(); + + dx = 0; + dy = 0; + + if (mBitmapWidth * mBorderRect.height() > mBorderRect.width() * mBitmapHeight) { + scale = mBorderRect.height() / (float) mBitmapHeight; + dx = (mBorderRect.width() - mBitmapWidth * scale) * 0.5f; + } else { + scale = mBorderRect.width() / (float) mBitmapWidth; + dy = (mBorderRect.height() - mBitmapHeight * scale) * 0.5f; + } + + mShaderMatrix.setScale(scale, scale); + mShaderMatrix.postTranslate((int) (dx + 0.5f) + mBorderWidth / 2, + (int) (dy + 0.5f) + mBorderWidth / 2); + break; + + case CENTER_INSIDE: + mShaderMatrix.reset(); + + if (mBitmapWidth <= mBounds.width() && mBitmapHeight <= mBounds.height()) { + scale = 1.0f; + } else { + scale = Math.min(mBounds.width() / (float) mBitmapWidth, + mBounds.height() / (float) mBitmapHeight); + } + + dx = (int) ((mBounds.width() - mBitmapWidth * scale) * 0.5f + 0.5f); + dy = (int) ((mBounds.height() - mBitmapHeight * scale) * 0.5f + 0.5f); + + mShaderMatrix.setScale(scale, scale); + mShaderMatrix.postTranslate(dx, dy); + + mBorderRect.set(mBitmapRect); + mShaderMatrix.mapRect(mBorderRect); + mBorderRect.inset(mBorderWidth / 2, mBorderWidth / 2); + mShaderMatrix.setRectToRect(mBitmapRect, mBorderRect, Matrix.ScaleToFit.FILL); + break; + + default: + case FIT_CENTER: + mBorderRect.set(mBitmapRect); + mShaderMatrix.setRectToRect(mBitmapRect, mBounds, Matrix.ScaleToFit.CENTER); + mShaderMatrix.mapRect(mBorderRect); + mBorderRect.inset(mBorderWidth / 2, mBorderWidth / 2); + mShaderMatrix.setRectToRect(mBitmapRect, mBorderRect, Matrix.ScaleToFit.FILL); + break; + + case FIT_END: + mBorderRect.set(mBitmapRect); + mShaderMatrix.setRectToRect(mBitmapRect, mBounds, Matrix.ScaleToFit.END); + mShaderMatrix.mapRect(mBorderRect); + mBorderRect.inset(mBorderWidth / 2, mBorderWidth / 2); + mShaderMatrix.setRectToRect(mBitmapRect, mBorderRect, Matrix.ScaleToFit.FILL); + break; + + case FIT_START: + mBorderRect.set(mBitmapRect); + mShaderMatrix.setRectToRect(mBitmapRect, mBounds, Matrix.ScaleToFit.START); + mShaderMatrix.mapRect(mBorderRect); + mBorderRect.inset(mBorderWidth / 2, mBorderWidth / 2); + mShaderMatrix.setRectToRect(mBitmapRect, mBorderRect, Matrix.ScaleToFit.FILL); + break; + + case FIT_XY: + mBorderRect.set(mBounds); + mBorderRect.inset(mBorderWidth / 2, mBorderWidth / 2); + mShaderMatrix.reset(); + mShaderMatrix.setRectToRect(mBitmapRect, mBorderRect, Matrix.ScaleToFit.FILL); + break; + } + + mDrawableRect.set(mBorderRect); + } + + @Override + protected void onBoundsChange(@NonNull Rect bounds) { + super.onBoundsChange(bounds); + + mBounds.set(bounds); + + updateShaderMatrix(); + } + + @Override + public void draw(@NonNull Canvas canvas) { + if (mRebuildShader) { + BitmapShader bitmapShader = new BitmapShader(mBitmap, mTileModeX, mTileModeY); + if (mTileModeX == Shader.TileMode.CLAMP && mTileModeY == Shader.TileMode.CLAMP) { + bitmapShader.setLocalMatrix(mShaderMatrix); + } + mBitmapPaint.setShader(bitmapShader); + mRebuildShader = false; + } + + if (mOval) { + if (mBorderWidth > 0) { + canvas.drawOval(mDrawableRect, mBitmapPaint); + canvas.drawOval(mBorderRect, mBorderPaint); + } else { + canvas.drawOval(mDrawableRect, mBitmapPaint); + } + } else { + if (any(mCornersRounded)) { + float radius = mCornerRadius; + if (mBorderWidth > 0) { + canvas.drawRoundRect(mDrawableRect, radius, radius, mBitmapPaint); + canvas.drawRoundRect(mBorderRect, radius, radius, mBorderPaint); + redrawBitmapForSquareCorners(canvas); + redrawBorderForSquareCorners(canvas); + } else { + canvas.drawRoundRect(mDrawableRect, radius, radius, mBitmapPaint); + redrawBitmapForSquareCorners(canvas); + } + } else { + canvas.drawRect(mDrawableRect, mBitmapPaint); + if (mBorderWidth > 0) { + canvas.drawRect(mBorderRect, mBorderPaint); + } + } + } + } + + private void redrawBitmapForSquareCorners(Canvas canvas) { + if (all(mCornersRounded)) { + // no square corners + return; + } + + if (mCornerRadius == 0) { + return; // no round corners + } + + float left = mDrawableRect.left; + float top = mDrawableRect.top; + float right = left + mDrawableRect.width(); + float bottom = top + mDrawableRect.height(); + float radius = mCornerRadius; + + if (!mCornersRounded[Corner.TOP_LEFT]) { + mSquareCornersRect.set(left, top, left + radius, top + radius); + canvas.drawRect(mSquareCornersRect, mBitmapPaint); + } + + if (!mCornersRounded[Corner.TOP_RIGHT]) { + mSquareCornersRect.set(right - radius, top, right, radius); + canvas.drawRect(mSquareCornersRect, mBitmapPaint); + } + + if (!mCornersRounded[Corner.BOTTOM_RIGHT]) { + mSquareCornersRect.set(right - radius, bottom - radius, right, bottom); + canvas.drawRect(mSquareCornersRect, mBitmapPaint); + } + + if (!mCornersRounded[Corner.BOTTOM_LEFT]) { + mSquareCornersRect.set(left, bottom - radius, left + radius, bottom); + canvas.drawRect(mSquareCornersRect, mBitmapPaint); + } + } + + private void redrawBorderForSquareCorners(Canvas canvas) { + if (all(mCornersRounded)) { + // no square corners + return; + } + + if (mCornerRadius == 0) { + return; // no round corners + } + + float left = mDrawableRect.left; + float top = mDrawableRect.top; + float right = left + mDrawableRect.width(); + float bottom = top + mDrawableRect.height(); + float radius = mCornerRadius; + float offset = mBorderWidth / 2; + + if (!mCornersRounded[Corner.TOP_LEFT]) { + canvas.drawLine(left - offset, top, left + radius, top, mBorderPaint); + canvas.drawLine(left, top - offset, left, top + radius, mBorderPaint); + } + + if (!mCornersRounded[Corner.TOP_RIGHT]) { + canvas.drawLine(right - radius - offset, top, right, top, mBorderPaint); + canvas.drawLine(right, top - offset, right, top + radius, mBorderPaint); + } + + if (!mCornersRounded[Corner.BOTTOM_RIGHT]) { + canvas.drawLine(right - radius - offset, bottom, right + offset, bottom, mBorderPaint); + canvas.drawLine(right, bottom - radius, right, bottom, mBorderPaint); + } + + if (!mCornersRounded[Corner.BOTTOM_LEFT]) { + canvas.drawLine(left - offset, bottom, left + radius, bottom, mBorderPaint); + canvas.drawLine(left, bottom - radius, left, bottom, mBorderPaint); + } + } + + @Override + public int getOpacity() { + return PixelFormat.TRANSLUCENT; + } + + @Override + public int getAlpha() { + return mBitmapPaint.getAlpha(); + } + + @Override + public void setAlpha(int alpha) { + mBitmapPaint.setAlpha(alpha); + invalidateSelf(); + } + + @Override + public ColorFilter getColorFilter() { + return mBitmapPaint.getColorFilter(); + } + + @Override + public void setColorFilter(ColorFilter cf) { + mBitmapPaint.setColorFilter(cf); + invalidateSelf(); + } + + @Override + public void setDither(boolean dither) { + mBitmapPaint.setDither(dither); + invalidateSelf(); + } + + @Override + public void setFilterBitmap(boolean filter) { + mBitmapPaint.setFilterBitmap(filter); + invalidateSelf(); + } + + @Override + public int getIntrinsicWidth() { + return mBitmapWidth; + } + + @Override + public int getIntrinsicHeight() { + return mBitmapHeight; + } + + /** + * @return the corner radius. + */ + public float getCornerRadius() { + return mCornerRadius; + } + + /** + * @param corner the specific corner to get radius of. + * @return the corner radius of the specified corner. + */ + public float getCornerRadius(@Corner int corner) { + return mCornersRounded[corner] ? mCornerRadius : 0f; + } + + /** + * Sets all corners to the specified radius. + * + * @param radius the radius. + * @return the {@link RoundedDrawable} for chaining. + */ + public RoundedDrawable setCornerRadius(float radius) { + setCornerRadius(radius, radius, radius, radius); + return this; + } + + /** + * Sets the corner radius of one specific corner. + * + * @param corner the corner. + * @param radius the radius. + * @return the {@link RoundedDrawable} for chaining. + */ + public RoundedDrawable setCornerRadius(@Corner int corner, float radius) { + if (radius != 0 && mCornerRadius != 0 && mCornerRadius != radius) { + throw new IllegalArgumentException("Multiple nonzero corner radii not yet supported."); + } + + if (radius == 0) { + if (only(corner, mCornersRounded)) { + mCornerRadius = 0; + } + mCornersRounded[corner] = false; + } else { + if (mCornerRadius == 0) { + mCornerRadius = radius; + } + mCornersRounded[corner] = true; + } + + return this; + } + + /** + * Sets the corner radii of all the corners. + * + * @param topLeft top left corner radius. + * @param topRight top right corner radius + * @param bottomRight bototm right corner radius. + * @param bottomLeft bottom left corner radius. + * @return the {@link RoundedDrawable} for chaining. + */ + public RoundedDrawable setCornerRadius(float topLeft, float topRight, float bottomRight, + float bottomLeft) { + Set radiusSet = new HashSet<>(4); + radiusSet.add(topLeft); + radiusSet.add(topRight); + radiusSet.add(bottomRight); + radiusSet.add(bottomLeft); + + radiusSet.remove(0f); + + if (radiusSet.size() > 1) { + throw new IllegalArgumentException("Multiple nonzero corner radii not yet supported."); + } + + if (!radiusSet.isEmpty()) { + float radius = radiusSet.iterator().next(); + if (Float.isInfinite(radius) || Float.isNaN(radius) || radius < 0) { + throw new IllegalArgumentException("Invalid radius value: " + radius); + } + mCornerRadius = radius; + } else { + mCornerRadius = 0f; + } + + mCornersRounded[Corner.TOP_LEFT] = topLeft > 0; + mCornersRounded[Corner.TOP_RIGHT] = topRight > 0; + mCornersRounded[Corner.BOTTOM_RIGHT] = bottomRight > 0; + mCornersRounded[Corner.BOTTOM_LEFT] = bottomLeft > 0; + return this; + } + + public float getBorderWidth() { + return mBorderWidth; + } + + public RoundedDrawable setBorderWidth(float width) { + mBorderWidth = width; + mBorderPaint.setStrokeWidth(mBorderWidth); + return this; + } + + public int getBorderColor() { + return mBorderColor.getDefaultColor(); + } + + public RoundedDrawable setBorderColor(@ColorInt int color) { + return setBorderColor(ColorStateList.valueOf(color)); + } + + public ColorStateList getBorderColors() { + return mBorderColor; + } + + public RoundedDrawable setBorderColor(ColorStateList colors) { + mBorderColor = colors != null ? colors : ColorStateList.valueOf(0); + mBorderPaint.setColor(mBorderColor.getColorForState(getState(), DEFAULT_BORDER_COLOR)); + return this; + } + + public boolean isOval() { + return mOval; + } + + public RoundedDrawable setOval(boolean oval) { + mOval = oval; + return this; + } + + public ScaleType getScaleType() { + return mScaleType; + } + + public RoundedDrawable setScaleType(ScaleType scaleType) { + if (scaleType == null) { + scaleType = ScaleType.FIT_CENTER; + } + if (mScaleType != scaleType) { + mScaleType = scaleType; + updateShaderMatrix(); + } + return this; + } + + public Shader.TileMode getTileModeX() { + return mTileModeX; + } + + public RoundedDrawable setTileModeX(Shader.TileMode tileModeX) { + if (mTileModeX != tileModeX) { + mTileModeX = tileModeX; + mRebuildShader = true; + invalidateSelf(); + } + return this; + } + + public Shader.TileMode getTileModeY() { + return mTileModeY; + } + + public RoundedDrawable setTileModeY(Shader.TileMode tileModeY) { + if (mTileModeY != tileModeY) { + mTileModeY = tileModeY; + mRebuildShader = true; + invalidateSelf(); + } + return this; + } + + private static boolean only(int index, boolean[] booleans) { + for (int i = 0, len = booleans.length; i < len; i++) { + if (booleans[i] != (i == index)) { + return false; + } + } + return true; + } + + private static boolean any(boolean[] booleans) { + for (boolean b : booleans) { + if (b) { return true; } + } + return false; + } + + private static boolean all(boolean[] booleans) { + for (boolean b : booleans) { + if (b) { return false; } + } + return true; + } + + public Bitmap toBitmap() { + return drawableToBitmap(this); + } +} diff --git a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/notice/roundimage/RoundedImageView.java b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/notice/roundimage/RoundedImageView.java new file mode 100644 index 0000000000..bfa6420fe7 --- /dev/null +++ b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/notice/roundimage/RoundedImageView.java @@ -0,0 +1,587 @@ +/* +* Copyright (C) 2015 Vincent Mi +* +* 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. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package com.mogo.eagle.core.function.hmi.ui.notice.roundimage; + +import android.content.Context; +import android.content.res.ColorStateList; +import android.content.res.Resources; +import android.content.res.TypedArray; +import android.graphics.Bitmap; +import android.graphics.ColorFilter; +import android.graphics.Shader; +import android.graphics.drawable.ColorDrawable; +import android.graphics.drawable.Drawable; +import android.graphics.drawable.LayerDrawable; +import android.net.Uri; +import android.util.AttributeSet; +import android.util.Log; + +import androidx.annotation.ColorInt; +import androidx.annotation.DimenRes; +import androidx.annotation.DrawableRes; +import androidx.appcompat.widget.AppCompatImageView; + +import com.mogo.eagle.core.function.hmi.R; + + +@SuppressWarnings("UnusedDeclaration") +public class RoundedImageView extends AppCompatImageView { + + // Constants for tile mode attributes + private static final int TILE_MODE_UNDEFINED = -2; + private static final int TILE_MODE_CLAMP = 0; + private static final int TILE_MODE_REPEAT = 1; + private static final int TILE_MODE_MIRROR = 2; + + public static final String TAG = "RoundedImageView"; + public static final float DEFAULT_RADIUS = 0f; + public static final float DEFAULT_BORDER_WIDTH = 0f; + public static final Shader.TileMode DEFAULT_TILE_MODE = Shader.TileMode.CLAMP; + private static final ScaleType[] SCALE_TYPES = { + ScaleType.MATRIX, + ScaleType.FIT_XY, + ScaleType.FIT_START, + ScaleType.FIT_CENTER, + ScaleType.FIT_END, + ScaleType.CENTER, + ScaleType.CENTER_CROP, + ScaleType.CENTER_INSIDE + }; + + private final float[] mCornerRadii = + new float[] { DEFAULT_RADIUS, DEFAULT_RADIUS, DEFAULT_RADIUS, DEFAULT_RADIUS }; + + private Drawable mBackgroundDrawable; + private ColorStateList mBorderColor = + ColorStateList.valueOf(RoundedDrawable.DEFAULT_BORDER_COLOR); + private float mBorderWidth = DEFAULT_BORDER_WIDTH; + private ColorFilter mColorFilter = null; + private boolean mColorMod = false; + private Drawable mDrawable; + private boolean mHasColorFilter = false; + private boolean mIsOval = false; + private boolean mMutateBackground = false; + private int mResource; + private int mBackgroundResource; + private ScaleType mScaleType; + private Shader.TileMode mTileModeX = DEFAULT_TILE_MODE; + private Shader.TileMode mTileModeY = DEFAULT_TILE_MODE; + + public RoundedImageView(Context context) { + super(context); + } + + public RoundedImageView(Context context, AttributeSet attrs) { + this(context, attrs, 0); + } + + public RoundedImageView(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + + TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RoundedImageView, defStyle, 0); + + int index = a.getInt(R.styleable.RoundedImageView_android_scaleType, -1); + if (index >= 0) { + setScaleType(SCALE_TYPES[index]); + } else { + // default scaletype to FIT_CENTER + setScaleType(ScaleType.FIT_CENTER); + } + + float cornerRadiusOverride = + a.getDimensionPixelSize(R.styleable.RoundedImageView_riv_corner_radius, -1); + + mCornerRadii[Corner.TOP_LEFT] = + a.getDimensionPixelSize(R.styleable.RoundedImageView_riv_corner_radius_top_left, -1); + mCornerRadii[Corner.TOP_RIGHT] = + a.getDimensionPixelSize(R.styleable.RoundedImageView_riv_corner_radius_top_right, -1); + mCornerRadii[Corner.BOTTOM_RIGHT] = + a.getDimensionPixelSize(R.styleable.RoundedImageView_riv_corner_radius_bottom_right, -1); + mCornerRadii[Corner.BOTTOM_LEFT] = + a.getDimensionPixelSize(R.styleable.RoundedImageView_riv_corner_radius_bottom_left, -1); + + boolean any = false; + for (int i = 0, len = mCornerRadii.length; i < len; i++) { + if (mCornerRadii[i] < 0) { + mCornerRadii[i] = 0f; + } else { + any = true; + } + } + + if (!any) { + if (cornerRadiusOverride < 0) { + cornerRadiusOverride = DEFAULT_RADIUS; + } + for (int i = 0, len = mCornerRadii.length; i < len; i++) { + mCornerRadii[i] = cornerRadiusOverride; + } + } + + mBorderWidth = a.getDimensionPixelSize(R.styleable.RoundedImageView_riv_border_width, -1); + if (mBorderWidth < 0) { + mBorderWidth = DEFAULT_BORDER_WIDTH; + } + + mBorderColor = a.getColorStateList(R.styleable.RoundedImageView_riv_border_color); + if (mBorderColor == null) { + mBorderColor = ColorStateList.valueOf(RoundedDrawable.DEFAULT_BORDER_COLOR); + } + + mMutateBackground = a.getBoolean(R.styleable.RoundedImageView_riv_mutate_background, false); + mIsOval = a.getBoolean(R.styleable.RoundedImageView_riv_oval, false); + + final int tileMode = a.getInt(R.styleable.RoundedImageView_riv_tile_Mode, TILE_MODE_UNDEFINED); + if (tileMode != TILE_MODE_UNDEFINED) { + setTileModeX(parseTileMode(tileMode)); + setTileModeY(parseTileMode(tileMode)); + } + + final int tileModeX = + a.getInt(R.styleable.RoundedImageView_riv_tile_Mode_x, TILE_MODE_UNDEFINED); + if (tileModeX != TILE_MODE_UNDEFINED) { + setTileModeX(parseTileMode(tileModeX)); + } + + final int tileModeY = + a.getInt(R.styleable.RoundedImageView_riv_tile_Mode_y, TILE_MODE_UNDEFINED); + if (tileModeY != TILE_MODE_UNDEFINED) { + setTileModeY(parseTileMode(tileModeY)); + } + + updateDrawableAttrs(); + updateBackgroundDrawableAttrs(true); + + if (mMutateBackground) { + // when setBackground() is called by View constructor, mMutateBackground is not loaded from the attribute, + // so it's false by default, what doesn't allow to create the RoundedDrawable. At this point, after load + // mMutateBackground and updated BackgroundDrawable to RoundedDrawable, the View's background drawable needs to + // be changed to this new drawable. + //noinspection deprecation + super.setBackgroundDrawable(mBackgroundDrawable); + } + + a.recycle(); + } + + private static Shader.TileMode parseTileMode(int tileMode) { + switch (tileMode) { + case TILE_MODE_CLAMP: + return Shader.TileMode.CLAMP; + case TILE_MODE_REPEAT: + return Shader.TileMode.REPEAT; + case TILE_MODE_MIRROR: + return Shader.TileMode.MIRROR; + default: + return null; + } + } + + @Override + protected void drawableStateChanged() { + super.drawableStateChanged(); + invalidate(); + } + + @Override + public ScaleType getScaleType() { + return mScaleType; + } + + @Override + public void setScaleType(ScaleType scaleType) { + assert scaleType != null; + + if (mScaleType != scaleType) { + mScaleType = scaleType; + + switch (scaleType) { + case CENTER: + case CENTER_CROP: + case CENTER_INSIDE: + case FIT_CENTER: + case FIT_START: + case FIT_END: + case FIT_XY: + super.setScaleType(ScaleType.FIT_XY); + break; + default: + super.setScaleType(scaleType); + break; + } + + updateDrawableAttrs(); + updateBackgroundDrawableAttrs(false); + invalidate(); + } + } + + @Override + public void setImageDrawable(Drawable drawable) { + mResource = 0; + mDrawable = RoundedDrawable.fromDrawable(drawable); + updateDrawableAttrs(); + super.setImageDrawable(mDrawable); + } + + @Override + public void setImageBitmap(Bitmap bm) { + mResource = 0; + mDrawable = RoundedDrawable.fromBitmap(bm); + updateDrawableAttrs(); + super.setImageDrawable(mDrawable); + } + + @Override + public void setImageResource(@DrawableRes int resId) { + if (mResource != resId) { + mResource = resId; + mDrawable = resolveResource(); + updateDrawableAttrs(); + super.setImageDrawable(mDrawable); + } + } + + @Override public void setImageURI(Uri uri) { + super.setImageURI(uri); + setImageDrawable(getDrawable()); + } + + private Drawable resolveResource() { + Resources rsrc = getResources(); + if (rsrc == null) { return null; } + + Drawable d = null; + + if (mResource != 0) { + try { + d = rsrc.getDrawable(mResource); + } catch (Exception e) { + Log.w(TAG, "Unable to find resource: " + mResource, e); + // Don't try again. + mResource = 0; + } + } + return RoundedDrawable.fromDrawable(d); + } + + @Override + public void setBackground(Drawable background) { + setBackgroundDrawable(background); + } + + @Override + public void setBackgroundResource(@DrawableRes int resId) { + if (mBackgroundResource != resId) { + mBackgroundResource = resId; + mBackgroundDrawable = resolveBackgroundResource(); + setBackgroundDrawable(mBackgroundDrawable); + } + } + + @Override + public void setBackgroundColor(int color) { + mBackgroundDrawable = new ColorDrawable(color); + setBackgroundDrawable(mBackgroundDrawable); + } + + private Drawable resolveBackgroundResource() { + Resources rsrc = getResources(); + if (rsrc == null) { return null; } + + Drawable d = null; + + if (mBackgroundResource != 0) { + try { + d = rsrc.getDrawable(mBackgroundResource); + } catch (Exception e) { + Log.w(TAG, "Unable to find resource: " + mBackgroundResource, e); + // Don't try again. + mBackgroundResource = 0; + } + } + return RoundedDrawable.fromDrawable(d); + } + + private void updateDrawableAttrs() { + updateAttrs(mDrawable, mScaleType); + } + + private void updateBackgroundDrawableAttrs(boolean convert) { + if (mMutateBackground) { + if (convert) { + mBackgroundDrawable = RoundedDrawable.fromDrawable(mBackgroundDrawable); + } + updateAttrs(mBackgroundDrawable, ScaleType.FIT_XY); + } + } + + @Override public void setColorFilter(ColorFilter cf) { + if (mColorFilter != cf) { + mColorFilter = cf; + mHasColorFilter = true; + mColorMod = true; + applyColorMod(); + invalidate(); + } + } + + private void applyColorMod() { + // Only mutate and apply when modifications have occurred. This should + // not reset the mColorMod flag, since these filters need to be + // re-applied if the Drawable is changed. + if (mDrawable != null && mColorMod) { + mDrawable = mDrawable.mutate(); + if (mHasColorFilter) { + mDrawable.setColorFilter(mColorFilter); + } + //mDrawable.setXfermode(mXfermode); + //mDrawable.setAlpha(mAlpha * mViewAlphaScale >> 8); + } + } + + private void updateAttrs(Drawable drawable, ScaleType scaleType) { + if (drawable == null) { return; } + + if (drawable instanceof RoundedDrawable) { + ((RoundedDrawable) drawable) + .setScaleType(scaleType) + .setBorderWidth(mBorderWidth) + .setBorderColor(mBorderColor) + .setOval(mIsOval) + .setTileModeX(mTileModeX) + .setTileModeY(mTileModeY); + + if (mCornerRadii != null) { + ((RoundedDrawable) drawable).setCornerRadius( + mCornerRadii[Corner.TOP_LEFT], + mCornerRadii[Corner.TOP_RIGHT], + mCornerRadii[Corner.BOTTOM_RIGHT], + mCornerRadii[Corner.BOTTOM_LEFT]); + } + + applyColorMod(); + } else if (drawable instanceof LayerDrawable) { + // loop through layers to and set drawable attrs + LayerDrawable ld = ((LayerDrawable) drawable); + for (int i = 0, layers = ld.getNumberOfLayers(); i < layers; i++) { + updateAttrs(ld.getDrawable(i), scaleType); + } + } + } + + @Override + @Deprecated + public void setBackgroundDrawable(Drawable background) { + mBackgroundDrawable = background; + updateBackgroundDrawableAttrs(true); + //noinspection deprecation + super.setBackgroundDrawable(mBackgroundDrawable); + } + + /** + * @return the largest corner radius. + */ + public float getCornerRadius() { + return getMaxCornerRadius(); + } + + /** + * @return the largest corner radius. + */ + public float getMaxCornerRadius() { + float maxRadius = 0; + for (float r : mCornerRadii) { + maxRadius = Math.max(r, maxRadius); + } + return maxRadius; + } + + /** + * Get the corner radius of a specified corner. + * + * @param corner the corner. + * @return the radius. + */ + public float getCornerRadius(@Corner int corner) { + return mCornerRadii[corner]; + } + + /** + * Set all the corner radii from a dimension resource id. + * + * @param resId dimension resource id of radii. + */ + public void setCornerRadiusDimen(@DimenRes int resId) { + float radius = getResources().getDimension(resId); + setCornerRadius(radius, radius, radius, radius); + } + + /** + * Set the corner radius of a specific corner from a dimension resource id. + * + * @param corner the corner to set. + * @param resId the dimension resource id of the corner radius. + */ + public void setCornerRadiusDimen(@Corner int corner, @DimenRes int resId) { + setCornerRadius(corner, getResources().getDimensionPixelSize(resId)); + } + + /** + * Set the corner radii of all corners in px. + * + * @param radius the radius to set. + */ + public void setCornerRadius(float radius) { + setCornerRadius(radius, radius, radius, radius); + } + + /** + * Set the corner radius of a specific corner in px. + * + * @param corner the corner to set. + * @param radius the corner radius to set in px. + */ + public void setCornerRadius(@Corner int corner, float radius) { + if (mCornerRadii[corner] == radius) { + return; + } + mCornerRadii[corner] = radius; + + updateDrawableAttrs(); + updateBackgroundDrawableAttrs(false); + invalidate(); + } + + /** + * Set the corner radii of each corner individually. Currently only one unique nonzero value is + * supported. + * + * @param topLeft radius of the top left corner in px. + * @param topRight radius of the top right corner in px. + * @param bottomRight radius of the bottom right corner in px. + * @param bottomLeft radius of the bottom left corner in px. + */ + public void setCornerRadius(float topLeft, float topRight, float bottomLeft, float bottomRight) { + if (mCornerRadii[Corner.TOP_LEFT] == topLeft + && mCornerRadii[Corner.TOP_RIGHT] == topRight + && mCornerRadii[Corner.BOTTOM_RIGHT] == bottomRight + && mCornerRadii[Corner.BOTTOM_LEFT] == bottomLeft) { + return; + } + + mCornerRadii[Corner.TOP_LEFT] = topLeft; + mCornerRadii[Corner.TOP_RIGHT] = topRight; + mCornerRadii[Corner.BOTTOM_LEFT] = bottomLeft; + mCornerRadii[Corner.BOTTOM_RIGHT] = bottomRight; + + updateDrawableAttrs(); + updateBackgroundDrawableAttrs(false); + invalidate(); + } + + public float getBorderWidth() { + return mBorderWidth; + } + + public void setBorderWidth(@DimenRes int resId) { + setBorderWidth(getResources().getDimension(resId)); + } + + public void setBorderWidth(float width) { + if (mBorderWidth == width) { return; } + + mBorderWidth = width; + updateDrawableAttrs(); + updateBackgroundDrawableAttrs(false); + invalidate(); + } + + @ColorInt + public int getBorderColor() { + return mBorderColor.getDefaultColor(); + } + + public void setBorderColor(@ColorInt int color) { + setBorderColor(ColorStateList.valueOf(color)); + } + + public ColorStateList getBorderColors() { + return mBorderColor; + } + + public void setBorderColor(ColorStateList colors) { + if (mBorderColor.equals(colors)) { return; } + + mBorderColor = + (colors != null) ? colors : ColorStateList.valueOf(RoundedDrawable.DEFAULT_BORDER_COLOR); + updateDrawableAttrs(); + updateBackgroundDrawableAttrs(false); + if (mBorderWidth > 0) { + invalidate(); + } + } + + public boolean isOval() { + return mIsOval; + } + + public void setOval(boolean oval) { + mIsOval = oval; + updateDrawableAttrs(); + updateBackgroundDrawableAttrs(false); + invalidate(); + } + + public Shader.TileMode getTileModeX() { + return mTileModeX; + } + + public void setTileModeX(Shader.TileMode tileModeX) { + if (this.mTileModeX == tileModeX) { return; } + + this.mTileModeX = tileModeX; + updateDrawableAttrs(); + updateBackgroundDrawableAttrs(false); + invalidate(); + } + + public Shader.TileMode getTileModeY() { + return mTileModeY; + } + + public void setTileModeY(Shader.TileMode tileModeY) { + if (this.mTileModeY == tileModeY) { return; } + + this.mTileModeY = tileModeY; + updateDrawableAttrs(); + updateBackgroundDrawableAttrs(false); + invalidate(); + } + + public boolean mutatesBackground() { + return mMutateBackground; + } + + public void mutateBackground(boolean mutate) { + if (mMutateBackground == mutate) { return; } + + mMutateBackground = mutate; + updateBackgroundDrawableAttrs(true); + invalidate(); + } +} diff --git a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/utils/NoticeGlobalTools.kt b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/utils/NoticeGlobalTools.kt new file mode 100644 index 0000000000..d1a736cdb4 --- /dev/null +++ b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/utils/NoticeGlobalTools.kt @@ -0,0 +1,40 @@ +package com.mogo.eagle.core.function.hmi.ui.utils + +import android.content.Context +import android.view.View +import com.alibaba.android.arouter.launcher.ARouter +import com.mogo.service.IMogoServiceApis +import com.mogo.eagle.core.data.constants.MogoServicePaths + +/** + * @author congtaowang + * @since 2020/6/28 + * + * 描述 + */ +private var apis: IMogoServiceApis? = null + +fun getApis(context: Context): IMogoServiceApis { + if (apis == null) { + apis = ARouter.getInstance().build(com.mogo.eagle.core.data.constants.MogoServicePaths.PATH_SERVICE_APIS).navigation(context) as IMogoServiceApis; + } + return apis!! +} + +fun View.gone() { + if (this.visibility != View.GONE) { + this.visibility = View.GONE + } +} + +fun View.visible() { + if (this.visibility != View.VISIBLE) { + this.visibility = View.VISIBLE + } +} + +fun View.invisible() { + if (this.visibility != View.INVISIBLE) { + this.visibility = View.INVISIBLE + } +} \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/warning/MoGoWarningProvider.kt b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/warning/MoGoWarningProvider.kt index b6263b04cd..a2bf43faec 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/warning/MoGoWarningProvider.kt +++ b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/warning/MoGoWarningProvider.kt @@ -92,11 +92,15 @@ class MoGoWarningProvider : IMoGoWaringProvider { } override fun showNoticeForTrafficWithData(pushData: NoticeTrafficStylePushData?) { - TODO("Not yet implemented") + if (pushData != null) { + mMoGoHmiFragment?.showNoticeForTrafficWithData(pushData) + }; } override fun showNoticeNormalData(normalData: NoticeNormalData?) { - TODO("Not yet implemented") + if (normalData != null) { + mMoGoHmiFragment?.showNoticeNormal(normalData) + } } override fun onDestroy() { diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-ldpi/module_push_close.png b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-ldpi/module_push_close.png new file mode 100755 index 0000000000..c1381dc44c Binary files /dev/null and b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-ldpi/module_push_close.png differ diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-ldpi/module_push_item_background_p.9.png b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-ldpi/module_push_item_background_p.9.png new file mode 100644 index 0000000000..a5dedc9ca3 Binary files /dev/null and b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-ldpi/module_push_item_background_p.9.png differ diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-ldpi/module_push_message_background.9.png b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-ldpi/module_push_message_background.9.png new file mode 100644 index 0000000000..bf455a0ea2 Binary files /dev/null and b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-ldpi/module_push_message_background.9.png differ diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-mdpi/module_push_close.png b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-mdpi/module_push_close.png new file mode 100755 index 0000000000..c1381dc44c Binary files /dev/null and b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-mdpi/module_push_close.png differ diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-mdpi/module_push_item_background_p.9.png b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-mdpi/module_push_item_background_p.9.png new file mode 100644 index 0000000000..5b43f7451d Binary files /dev/null and b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-mdpi/module_push_item_background_p.9.png differ diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-mdpi/module_push_message_background.9.png b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-mdpi/module_push_message_background.9.png new file mode 100644 index 0000000000..bf455a0ea2 Binary files /dev/null and b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-mdpi/module_push_message_background.9.png differ diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/module_push_close.png b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/module_push_close.png new file mode 100755 index 0000000000..bb3e2b1195 Binary files /dev/null and b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/module_push_close.png differ diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/module_push_dialog_close.png b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/module_push_dialog_close.png new file mode 100644 index 0000000000..ba03e033d8 Binary files /dev/null and b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/module_push_dialog_close.png differ diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/module_push_item_background_p.9.png b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/module_push_item_background_p.9.png new file mode 100644 index 0000000000..87a3f9179d Binary files /dev/null and b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/module_push_item_background_p.9.png differ diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/module_push_message_background.9.png b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/module_push_message_background.9.png new file mode 100644 index 0000000000..d4a8803684 Binary files /dev/null and b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/module_push_message_background.9.png differ diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/drawable/notice_item_background.xml b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable/notice_item_background.xml new file mode 100644 index 0000000000..2a98ae4301 --- /dev/null +++ b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable/notice_item_background.xml @@ -0,0 +1,11 @@ + + + + + + diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/layout/notice_module_push_item.xml b/core/function-impl/mogo-core-function-hmi/src/main/res/layout/notice_module_push_item.xml new file mode 100644 index 0000000000..93ba3700da --- /dev/null +++ b/core/function-impl/mogo-core-function-hmi/src/main/res/layout/notice_module_push_item.xml @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/layout/notice_push_dialog_check.xml b/core/function-impl/mogo-core-function-hmi/src/main/res/layout/notice_push_dialog_check.xml new file mode 100644 index 0000000000..7fdd8003f5 --- /dev/null +++ b/core/function-impl/mogo-core-function-hmi/src/main/res/layout/notice_push_dialog_check.xml @@ -0,0 +1,45 @@ + + + + + + + + + + \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/values/attr.xml b/core/function-impl/mogo-core-function-hmi/src/main/res/values/attr.xml new file mode 100644 index 0000000000..8972302147 --- /dev/null +++ b/core/function-impl/mogo-core-function-hmi/src/main/res/values/attr.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/values/dimens.xml b/core/function-impl/mogo-core-function-hmi/src/main/res/values/dimens.xml index 57be068902..f24f8060ae 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/res/values/dimens.xml +++ b/core/function-impl/mogo-core-function-hmi/src/main/res/values/dimens.xml @@ -30,4 +30,131 @@ 588px 1066px + + 16px + 352px + 32px + 32px + 16.5px + 12px + 20px + 18px + 210px + 13px + 15px + 18px + 320px + 180px + 16px + 320px + 160px + 9px + 20px + 0px + 48px + 10px + 14px + 50px + 20px + 20px + 90px + 5px + 84px + 38px + 36px + 100px + 64px + 24px + 16px + 44px + 2px + 20px + 27px + 16px + 64px + 8px + 16px + + 22px + 27px + 14px + 1.5px + 24px + 10px + 8px + 560px + 194px + 266px + 178px + 8px + 12px + 16px + 6px + 19px + 30px + 16px + 8px + 17px + 19px + 16px + 11px + 6px + 18px + 10px + 17px + 10px + 8px + 242px + 270px + 374px + 24px + 19px + 8px + 328px + 164px + 15px + 150px + 20px + 0px + 310px + 350px + 60px + 2px + 2px + 8px + 28px + 16px + 16px + 12px + 5px + 118px + 86px + 8px + + + 34px + 567px + 120px + + 2px + 120px + 30px + 55px + 42px + 208px + + 1200px + 763px + 32px + 107px + 107px + 40px + 54px + 56px + 1000px + 33px + 43px + 20px + + \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/values/strings.xml b/core/function-impl/mogo-core-function-hmi/src/main/res/values/strings.xml new file mode 100644 index 0000000000..ffd5d3fd45 --- /dev/null +++ b/core/function-impl/mogo-core-function-hmi/src/main/res/values/strings.xml @@ -0,0 +1,4 @@ + + mogo-module-push + 查看 + diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/values/styles.xml b/core/function-impl/mogo-core-function-hmi/src/main/res/values/styles.xml new file mode 100644 index 0000000000..bb44cc75bc --- /dev/null +++ b/core/function-impl/mogo-core-function-hmi/src/main/res/values/styles.xml @@ -0,0 +1,9 @@ + + + + diff --git a/core/function-impl/mogo-core-function-notice/src/main/AndroidManifest.xml b/core/function-impl/mogo-core-function-notice/src/main/AndroidManifest.xml index 9f65d6f79c..588f4336aa 100644 --- a/core/function-impl/mogo-core-function-notice/src/main/AndroidManifest.xml +++ b/core/function-impl/mogo-core-function-notice/src/main/AndroidManifest.xml @@ -2,5 +2,14 @@ - + + + + + + + + + + \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-notice/src/main/java/com/mogo/eagle/core/function/notice/NoticeProvider.java b/core/function-impl/mogo-core-function-notice/src/main/java/com/mogo/eagle/core/function/notice/NoticeProvider.java index ef40c6425c..243342adae 100644 --- a/core/function-impl/mogo-core-function-notice/src/main/java/com/mogo/eagle/core/function/notice/NoticeProvider.java +++ b/core/function-impl/mogo-core-function-notice/src/main/java/com/mogo/eagle/core/function/notice/NoticeProvider.java @@ -1,22 +1,18 @@ package com.mogo.eagle.core.function.notice; import android.content.Context; -import android.os.Bundle; import android.util.Log; -import androidx.fragment.app.Fragment; - import com.alibaba.android.arouter.facade.annotation.Route; import com.mogo.eagle.core.data.constants.MogoServicePaths; import com.mogo.eagle.core.function.api.notice.IMoGoNoticeProvider; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; /** * @author Jing - * @description 云公告 + * @description 云公告公告 * @since: 10/27/21 */ @Route(path = MogoServicePaths.PATH_AI_NOTICE) @@ -24,12 +20,6 @@ public class NoticeProvider implements IMoGoNoticeProvider { private String TAG = "AINotice"; private Context mContext; - @Nullable - @Override - public Fragment createCoverage(@Nullable Context context, @Nullable Bundle data) { - return null; - } - @NotNull @Override public String getFunctionName() { @@ -47,5 +37,4 @@ public class NoticeProvider implements IMoGoNoticeProvider { mContext = context; NoticeSocketManager.getInstance().registerSocketMessageListener(context); } - } diff --git a/core/function-impl/mogo-core-function-notice/src/main/java/com/mogo/eagle/core/function/notice/NoticeSocketManager.java b/core/function-impl/mogo-core-function-notice/src/main/java/com/mogo/eagle/core/function/notice/NoticeSocketManager.java index 97cb3363f0..417b6ffa1e 100644 --- a/core/function-impl/mogo-core-function-notice/src/main/java/com/mogo/eagle/core/function/notice/NoticeSocketManager.java +++ b/core/function-impl/mogo-core-function-notice/src/main/java/com/mogo/eagle/core/function/notice/NoticeSocketManager.java @@ -3,8 +3,13 @@ package com.mogo.eagle.core.function.notice; import android.content.Context; import android.util.Log; +import com.mogo.eagle.core.data.notice.NoticeNormalData; +import com.mogo.eagle.core.function.call.hmi.CallerHmiManager; import com.mogo.eagle.core.function.notice.receiver.NoticeMessageListener; import com.mogo.module.common.MogoApisHandler; +import com.mogo.service.cloud.socket.IMogoOnMessageListener; +import com.mogo.utils.logger.Logger; +import com.mogo.utils.network.utils.GsonUtil; /** * @author Jing @@ -32,13 +37,45 @@ class NoticeSocketManager { mNoticeMessageListener = new NoticeMessageListener(); MogoApisHandler.getInstance().getApis().getSocketManagerApi(context). registerOnMessageListener(301001, mNoticeMessageListener); + MogoApisHandler.getInstance().getApis().getSocketManagerApi(context). + registerOnMessageListener(100, mNormalNoticeListener); } public void unRegisterSocketMessageListener() { if (mNoticeMessageListener != null) { MogoApisHandler.getInstance().getApis().getSocketManagerApi(mContext). unregisterOnMessageListener(301001, mNoticeMessageListener); + MogoApisHandler.getInstance().getApis().getSocketManagerApi(mContext). + unregisterOnMessageListener(100, mNormalNoticeListener); } } + + /** + * 普通云公告 + */ + private IMogoOnMessageListener mNormalNoticeListener = new IMogoOnMessageListener< NoticeNormalData >() { + @Override + public Class target() { + return NoticeNormalData.class; + } + + @Override + public void onMsgReceived(NoticeNormalData obj) { + Logger.i("liyz", "100-- 普通公告数据:" + GsonUtil.jsonFromObject(obj)); + if (obj == null) { + return; + } + + //TODO 展示弹框 + CallerHmiManager.INSTANCE.showNormalBanner(obj); + +// NoticePushData data = new NoticePushData(); +// data.setImageUrl(obj.getImageUrl()); +// data.setContent(obj.getContent()); +// data.setInfoId(obj.getDbId()); +// CallerHmiManager.INSTANCE.showTrafficBanner(data); + } + + }; } diff --git a/core/function-impl/mogo-core-function-notice/src/main/java/com/mogo/eagle/core/function/notice/test/TestNoticeBroadcastReceiver.kt b/core/function-impl/mogo-core-function-notice/src/main/java/com/mogo/eagle/core/function/notice/test/TestNoticeBroadcastReceiver.kt index c73a67cf36..d6f4b07399 100644 --- a/core/function-impl/mogo-core-function-notice/src/main/java/com/mogo/eagle/core/function/notice/test/TestNoticeBroadcastReceiver.kt +++ b/core/function-impl/mogo-core-function-notice/src/main/java/com/mogo/eagle/core/function/notice/test/TestNoticeBroadcastReceiver.kt @@ -3,6 +3,7 @@ package com.mogo.eagle.core.function.notice.test import android.content.BroadcastReceiver import android.content.Context import android.content.Intent +import android.util.Log import com.mogo.eagle.core.data.notice.NoticeTrafficStylePushData import com.mogo.eagle.core.function.call.hmi.CallerHmiManager import com.mogo.utils.logger.Logger @@ -12,8 +13,8 @@ import com.mogo.utils.logger.Logger * @description 测试类 * @since: 10/29/21 */ -class TestNoticeBroadcastReceiver: BroadcastReceiver() { - private val TAG = "notice" +class TestNoticeBroadcastReceiver : BroadcastReceiver() { + private val TAG = "AINotice" private var mContext: Context? = null override fun onReceive(context: Context?, intent: Intent) { @@ -29,6 +30,7 @@ class TestNoticeBroadcastReceiver: BroadcastReceiver() { } private fun dispatchSceneTest(sceneType: Int) { + Log.d(TAG, "dispatchSceneTest::"+sceneType.toString()); if (sceneType == 301001) { val pushData = NoticeTrafficStylePushData() pushData.msg = "交警测试公告" diff --git a/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/notice/IMoGoNoticeProvider.java b/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/notice/IMoGoNoticeProvider.java index 43183ad6f7..c8ea129bcc 100644 --- a/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/notice/IMoGoNoticeProvider.java +++ b/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/notice/IMoGoNoticeProvider.java @@ -1,16 +1,13 @@ package com.mogo.eagle.core.function.api.notice; -import com.mogo.eagle.core.data.notice.NoticeNormalData; -import com.mogo.eagle.core.data.notice.NoticeTrafficStylePushData; -import com.mogo.eagle.core.function.api.base.IMoGoFunctionProvider; +import com.mogo.eagle.core.function.api.base.IMoGoFunctionServerProvider; /** * @author Jing * @description 云公告监听者 * @since: 10/27/21 */ -public interface IMoGoNoticeProvider extends IMoGoFunctionProvider { - +public interface IMoGoNoticeProvider extends IMoGoFunctionServerProvider { } diff --git a/modules/mogo-module-push/src/main/java/com/mogo/module/push/repository/PushRepository.kt b/modules/mogo-module-push/src/main/java/com/mogo/module/push/repository/PushRepository.kt index 366ca47a00..6562c109c5 100644 --- a/modules/mogo-module-push/src/main/java/com/mogo/module/push/repository/PushRepository.kt +++ b/modules/mogo-module-push/src/main/java/com/mogo/module/push/repository/PushRepository.kt @@ -62,37 +62,37 @@ class PushRepository(mContext: Context) { } init { - // 注册push通道监听 type 100时为push消息 - getApis(mContext).getSocketManagerApi(mContext) - .registerOnMessageListener(Config.PUSH_TYPE, object : IMogoOnMessageListener { - override fun target(): Class { - return PushBean::class.java - } - - override fun onMsgReceived(bean: PushBean?) { - Log.d("PushRepository", "pushBean = $bean") - if (bean != null) { - AnalyticsUtils.track(Config.NEWS_ARRIVE, "title", bean.title) - if (bean.mainSchema.isBlank()) { - bean.mainSchema = "" - } - if (bean.imageUrl.isBlank()) { - bean.imageUrl = "" - } - if (bean.appIcon.isBlank()) { - bean.appIcon = "" - } - pushBeanQueue.offer(bean) - } - if ( bean != null) { - HandlerUtils.mBgHandler.post { - pushBeanDao.insertAll(bean) - updateMsgNum() - } - } - startIterate() - } - }) + // 注册push通道监听 type 100时为push消息 lixp TODO +// getApis(mContext).getSocketManagerApi(mContext) +// .registerOnMessageListener(Config.PUSH_TYPE, object : IMogoOnMessageListener { +// override fun target(): Class { +// return PushBean::class.java +// } +// +// override fun onMsgReceived(bean: PushBean?) { +// Log.d("PushRepository", "pushBean = $bean") +// if (bean != null) { +// AnalyticsUtils.track(Config.NEWS_ARRIVE, "title", bean.title) +// if (bean.mainSchema.isBlank()) { +// bean.mainSchema = "" +// } +// if (bean.imageUrl.isBlank()) { +// bean.imageUrl = "" +// } +// if (bean.appIcon.isBlank()) { +// bean.appIcon = "" +// } +// pushBeanQueue.offer(bean) +// } +// if ( bean != null) { +// HandlerUtils.mBgHandler.post { +// pushBeanDao.insertAll(bean) +// updateMsgNum() +// } +// } +// startIterate() +// } +// }) HandlerUtils.mBgHandler.postDelayed({ updateMsgNum() }, 5000)