From 4ba2088fe078320a3e76fe79dc851660ba5f6c1c Mon Sep 17 00:00:00 2001 From: xuxinchao Date: Mon, 13 Mar 2023 12:20:54 +0800 Subject: [PATCH] =?UTF-8?q?[dev=5Farch=5Fopt=5F3.0]=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E7=9B=92=E5=AD=90M1=E3=80=81M2=E4=B9=98=E5=AE=A2=E7=AB=AF?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=BF=90=E8=90=A5=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../function/hmi/ui/msgbox/MBoxBubbleView.kt | 2 +- .../hmi/ui/msgbox/MMsgBoxBubbleView.kt | 7 +- .../function/hmi/ui/msgbox/MMsgBoxListView.kt | 11 +- .../function/hmi/ui/msgbox/SharpView.java | 59 ++++ .../ui/msgbox/adapter/MBoxBubbleAdapter.kt | 26 +- .../ui/msgbox/adapter/MMsgBoxBubbleAdapter.kt | 2 +- .../ui/msgbox/adapter/MMsgBoxListAdapter.kt | 8 +- .../hmi/ui/widget/ExpandableTextView.java | 303 ++++++++++++++++++ .../drawable-xhdpi/ic_expand_less_black.png | Bin 0 -> 697 bytes .../drawable-xhdpi/ic_expand_more_black.png | Bin 0 -> 716 bytes .../main/res/layout/item_m_box_operation.xml | 51 +++ .../src/main/res/layout/item_m_box_v2x.xml | 2 +- .../res/layout/item_m_msg_box_operation.xml | 5 +- .../res/layout/item_m_msg_list_operation.xml | 10 +- 14 files changed, 459 insertions(+), 27 deletions(-) create mode 100644 core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/msgbox/SharpView.java create mode 100644 core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/widget/ExpandableTextView.java create mode 100644 core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/ic_expand_less_black.png create mode 100644 core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/ic_expand_more_black.png create mode 100644 core/function-impl/mogo-core-function-hmi/src/main/res/layout/item_m_box_operation.xml diff --git a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/msgbox/MBoxBubbleView.kt b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/msgbox/MBoxBubbleView.kt index 17151d727e..42ff1b43d0 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/msgbox/MBoxBubbleView.kt +++ b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/msgbox/MBoxBubbleView.kt @@ -55,7 +55,7 @@ class MBoxBubbleView @JvmOverloads constructor( UiThreadHandler.post { if(category == MsgCategory.NOTICE){ if(msgBoxList.type == MsgBoxType.NOTICE || msgBoxList.type == MsgBoxType.V2X - || msgBoxList.type == MsgBoxType.OBU){ + || msgBoxList.type == MsgBoxType.OBU || msgBoxList.type == MsgBoxType.OPERATION){ MsgBoxConfig.noticeList.add(msgBoxList) if(isShowData){ CallerMsgBoxEventListenerManager.invokeUpdateTipListener(true) diff --git a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/msgbox/MMsgBoxBubbleView.kt b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/msgbox/MMsgBoxBubbleView.kt index e382698b28..e6daa2e3ed 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/msgbox/MMsgBoxBubbleView.kt +++ b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/msgbox/MMsgBoxBubbleView.kt @@ -52,14 +52,9 @@ class MMsgBoxBubbleView @JvmOverloads constructor( UiThreadHandler.post { if(category == MsgCategory.NOTICE){ if(msgBoxList.type == MsgBoxType.NOTICE || msgBoxList.type == MsgBoxType.V2X - || msgBoxList.type == MsgBoxType.OBU){ + || msgBoxList.type == MsgBoxType.OBU || msgBoxList.type == MsgBoxType.OPERATION){ update(msgBoxList) } - if(msgBoxList.type == MsgBoxType.OPERATION){ - if((msgBoxList.bean as OperationMsg).type == 2){ - update(msgBoxList) - } - } } } } diff --git a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/msgbox/MMsgBoxListView.kt b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/msgbox/MMsgBoxListView.kt index e881c94369..726a6dae6d 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/msgbox/MMsgBoxListView.kt +++ b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/msgbox/MMsgBoxListView.kt @@ -59,21 +59,12 @@ class MMsgBoxListView @JvmOverloads constructor( UiThreadHandler.post{ if(category == MsgCategory.NOTICE){ if(msgBoxList.type == MsgBoxType.NOTICE || msgBoxList.type == MsgBoxType.V2X - || msgBoxList.type == MsgBoxType.OBU){ + || msgBoxList.type == MsgBoxType.OBU || msgBoxList.type == MsgBoxType.OPERATION){ noticeList?.add(0,msgBoxList) noticeList?.let { mMsgBoxListAdapter?.setData(it) } } - if(msgBoxList.type == MsgBoxType.OPERATION){ - if((msgBoxList.bean as OperationMsg).type == 2){ - noticeList?.add(0,msgBoxList) - noticeList?.let { - mMsgBoxListAdapter?.setData(it) - } - } - } - } } } diff --git a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/msgbox/SharpView.java b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/msgbox/SharpView.java new file mode 100644 index 0000000000..af4567c9dd --- /dev/null +++ b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/msgbox/SharpView.java @@ -0,0 +1,59 @@ +package com.mogo.eagle.core.function.hmi.ui.msgbox; + +import android.content.Context; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.graphics.Path; +import android.util.AttributeSet; +import android.view.View; + +import androidx.annotation.Nullable; + +public class SharpView extends View { + + private int mWidth =0; //三角形的宽度 + private int mHeight =0; //三角形的高度 + private Context mContext; + + public SharpView(Context context) { + super(context); + this.mContext=context; + initView(); + } + + public SharpView(Context context, @Nullable AttributeSet attrs) { + super(context, attrs); + this.mContext=context; + initView(); + } + + private void initView() { + mWidth = 25; + mHeight = 25; + } + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + setMeasuredDimension(mWidth,mHeight); + } + + @Override + protected void onDraw(Canvas canvas) { + super.onDraw(canvas); + //创建画笔 + Paint paint = new Paint(); + paint.setColor(Color.parseColor("#FFFFFFFF")); + paint.setAntiAlias(true); //抗锯齿 + paint.setStyle(Paint.Style.FILL);//实线 + //创建路径 + Path path = new Path(); + path.moveTo(0,mHeight); + path.lineTo(mWidth,mHeight); + path.lineTo(mWidth/2,0); + path.close();//闭合路径 + //画在画布上 + canvas.drawPath(path,paint); + } + +} diff --git a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/msgbox/adapter/MBoxBubbleAdapter.kt b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/msgbox/adapter/MBoxBubbleAdapter.kt index c95913d7e7..83842d19e9 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/msgbox/adapter/MBoxBubbleAdapter.kt +++ b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/msgbox/adapter/MBoxBubbleAdapter.kt @@ -21,6 +21,7 @@ class MBoxBubbleAdapter(private val activity: Activity): RecyclerView.Adapter){ @@ -37,6 +38,10 @@ class MBoxBubbleAdapter(private val activity: Activity): RecyclerView.Adapter { + val view = LayoutInflater.from(parent.context).inflate(R.layout.item_m_box_operation,parent,false) + BubbleOperationHolder(view) + } else -> { val view = LayoutInflater.from(parent.context).inflate(R.layout.item_m_box_v2x,parent,false) BubbleV2XHolder(view) @@ -61,6 +66,14 @@ class MBoxBubbleAdapter(private val activity: Activity): RecyclerView.Adapter { + //运营消息 + data?.let { + val operationMsg = it[position].msgBoxBean.bean as OperationMsg + holder.tvMOperationTime.text = TimeUtils.millis2String(it[position].msgBoxBean.timestamp,getHourMinFormat()) + holder.tvMOperationContent.text = operationMsg.content + } + } is BubbleV2XHolder -> { data?.let { val msgBoxBean = it[position] @@ -74,7 +87,7 @@ class MBoxBubbleAdapter(private val activity: Activity): RecyclerView.Adapter { + mWidth = getWidth(); + if (toExpand) { + setExpandText(); + } else { + setCloseText(); + } + }); + } + + public void toggle() { + toggle(!mIsExpanding); + } + + /** + * 设置TextView可显示的最大行数 + * + * @param maxLines 最大行数 + */ + @Override + public void setMaxLines(int maxLines) { + if (mMaxLines == 0) { + // 这里对mMaxLines记录一次就可以 + this.mMaxLines = maxLines; + } + super.setMaxLines(maxLines); + } + + public void setToDBC(boolean toDBC) { + ToDBC = toDBC; + } + + public int getToExpandImageWidth() { + return mToExpandImageWidth; + } + + public int getToCloseImageWidth() { + return mToCloseImageWidth; + } + + public void setToExpandImageWidth(int mToExpandImageWidth) { + this.mToExpandImageWidth = mToExpandImageWidth; + } + + public void setToCloseImageWidth(int mToCloseImageWidth) { + this.mToCloseImageWidth = mToCloseImageWidth; + } + + public SpannableString getDefaultToExpandSpannableString() { + SpannableString spannableString = new SpannableString("... "); + // 测量文字的高度,用于设置图片大小 + Paint paint = getPaint(); + Paint.FontMetrics fontMetrics = paint.getFontMetrics(); + setToExpandImageWidth((int) (fontMetrics.descent - fontMetrics.ascent)); + // 对图片的宽高设置 + @SuppressLint("UseCompatLoadingForDrawables") + Drawable drawable = getResources().getDrawable(R.drawable.ic_expand_more_black); + drawable.setBounds(0, 0 , getToExpandImageWidth(), getToExpandImageWidth()); + ImageSpan span = new ImageSpan(drawable); + spannableString.setSpan(span, spannableString.length() - 1, spannableString.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); + // 对imageSpan设置点击事件,也可以这里不设置,在Activity对expandTextView整个事件设置点击事件 + return spannableString; + } + + + public SpannableString getDefaultToCloseSpannableString() { + // 因为末尾要插入图片,这里空格是占位符 + SpannableString spannableString = new SpannableString(" "); + // 测量文字的高度,用于设置图片大小 + Paint paint = getPaint(); + Paint.FontMetrics fontMetrics = paint.getFontMetrics(); + setToCloseImageWidth((int) (fontMetrics.descent - fontMetrics.ascent)); + // 对图片的宽高设置 + @SuppressLint("UseCompatLoadingForDrawables") + Drawable drawable = getResources().getDrawable(R.drawable.ic_expand_less_black); + drawable.setBounds(0, 0 , getToCloseImageWidth(), getToCloseImageWidth()); + ImageSpan span = new ImageSpan(drawable); + spannableString.setSpan(span, spannableString.length() - 1, spannableString.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); + return spannableString; + } + + /** + * 设置文本收起 + */ + public void setCloseText() { + mIsExpanding = false; + setMaxLines(mMaxLines); + + boolean needAppend = false; + String workingText = originText; + + if (mMaxLines != 0) { + Layout originLayout = createWorkingLayout(originText); + mOriginTextLines = originLayout.getLineCount(); + // 原始文本的行数 大于 最大能显示行数 + if (mOriginTextLines > mMaxLines) { + // 获取mMaxLines行的文本 + workingText = originText.substring(0, originLayout.getLineEnd(mMaxLines - 1)).trim(); + // 计算mMaxLines行的文本的宽度 + float allWidth = getPaint().measureText(workingText); + // 当前显示需要的宽度 + float realWidth = getPaint().measureText(workingText + SPAN_TO_EXPAND) + mToExpandImageWidth; + + while (realWidth > allWidth) { + int lastSpace = workingText.length() - 1; + if (lastSpace == -1) { + break; + } + workingText = workingText.substring(0, lastSpace); + realWidth = getPaint().measureText(workingText + SPAN_TO_EXPAND) + mToExpandImageWidth; + } + + needAppend = true; + } + } + setText(workingText); + if (needAppend) { + // 必须使用append,不能在上面使用+连接,否则spannable会无效 + append(SPAN_TO_EXPAND); + } + setMovementMethod(LinkMovementMethod.getInstance()); + } + + /** + * 设置文本展开 + */ + public void setExpandText() { + if (mOriginTextLines <= mMaxLines) { + return; + } + mIsExpanding = true; + setMaxLines(Integer.MAX_VALUE); + + Layout originLayout = createWorkingLayout(originText); + Layout compareLayout = createWorkingLayout(originText + SPAN_TO_CLOSE); + if (compareLayout.getLineCount() > originLayout.getLineCount()) { + setText(originText + "\n"); + } else { + setText(originText); + } + append(SPAN_TO_CLOSE); + setMovementMethod(LinkMovementMethod.getInstance()); + } + + /** + * 返回textview的显示区域的layout + */ + private Layout createWorkingLayout(String workingText) { + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) { + return StaticLayout.Builder.obtain(workingText, 0, workingText.length(), getPaint(), mWidth).build(); + } else { + return new StaticLayout(workingText, getPaint(), mWidth - getPaddingLeft() - getPaddingRight(), + Layout.Alignment.ALIGN_NORMAL, getLineSpacingMultiplier(), getLineSpacingExtra(), false); + } + } + + /** + * 屏蔽长按事件,防止崩溃 + */ + @Override + public void setLongClickable(boolean longClickable) { + super.setLongClickable(false); + } + + /** + * 转全角 + */ + private static String toDBC(String input) { + char[] c = input.toCharArray(); + for (int i = 0; i < c.length; i++) { + if (c[i] == '\n') { + + } else if (c[i] == ' ') { + c[i] = '\u3000'; + } else if (c[i] < '\177') { + c[i] = (char) (c[i] + 65248); + } + } + return new String(c); + } + + /** + * 转半角 + */ + public static String ToDBC(String input) { + char[] c = input.toCharArray(); + for (int i = 0; i < c.length; i++) { + if (c[i] == '\u3000') { + c[i] = ' '; + } else if (c[i] > '\uFF00' && c[i] < '\uFF5F') { + c[i] = (char) (c[i] - 65248); + + } + } + return new String(c); + } + + /** + * 用于生成 文本末尾要追加的SpannableString + */ + public interface CreateAppenderListener { + SpannableString getDefaultToCloseSpannableString(); + SpannableString getDefaultToExpandSpannableString(); + } + +} diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/ic_expand_less_black.png b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/ic_expand_less_black.png new file mode 100644 index 0000000000000000000000000000000000000000..233b1c27ffc17893d6b86d5023dd8fa1633ca9af GIT binary patch literal 697 zcmeAS@N?(olHy`uVBq!ia0vp^Vj#@H1|*Mc$*~4fjKx9jP7LeL$-D$|Tv8)E(|mmy zw18|52FCVG1{RPKAeI7R1_tH@j10^`nh_+nfC(-uwtyMI1}T(LG>&3mU{dyUaSX8# z+&a}ZTO?4V?Y{BM2U;E*x_6tIX)#g^K*V1rt=6|7FpVVus!U< zcg7%PmVc?hu45Z>9g1ySKc8JxD|f@2`ETk<{U=lXV`E-2U!Rb?=nb#Q;VLE*wd@^# za}HMR+sG}GemZeG`|d!VWA?ji25$l`Mo-JHwcOZZt? zgfnIQTvc*Cz%gQiM3U!Swrqd**nN|n1)X(n`Y!*kd-!)Edum(iv5=WHS}fB_!roH@5XQ5fB!h?!%3kt;T4mQ_(&|NmJ&bQwsc1J-L3kozrTGfVQ~J{ z=8C3mvlG}}d~$DHP(0W5^^S&blWfzUg)VnLmf3h${A)CicJ>;(4ekpUZ%!%SVaxBl zdwKZw{MK}hWi58LRcz*5&IT)e9xy#zdmv^7)9c&(PY>_oI;VI3cG!!8U$3LLoqS?> z$b8OO>FYsSxpu+xCT^_Qe)I6zmEAUN`#FAhCfzrBwL{)*@6<~dpQM--T&Z*@y)QQV z|I4c}CnvkC?Oz|;uiBTR?tRAP@09$E9-a=B4%38B#!2>1r>${GD$fyf)=@3^7yQrr zwn$WM$lnt4soKZiAAMBlUDx@5o&RA;(vE$LnXj(z+<2;x_uj>>wFPYE|6ZT}!oFE? V^TrUFzvn>7#?#f$Wt~$(69CIcAf*5R literal 0 HcmV?d00001 diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/ic_expand_more_black.png b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/ic_expand_more_black.png new file mode 100644 index 0000000000000000000000000000000000000000..6e2b5e9fddea9196a0de23d945e5ea80a030ae48 GIT binary patch literal 716 zcmeAS@N?(olHy`uVBq!ia0vp^Vj#@H1|*Mc$*~4fjKx9jP7LeL$-D$|Tv8)E(|mmy zw18|52FCVG1{RPKAeI7R1_tH@j10^`nh_+nfC(-uwtyMI1}T(LG>&3mU^4S`aSX8# z+&Xn*wuqz1vHd&WJoF6M*j=8<^6^Vklm^R`h9B$_x=LkQDhXDsiV0JXDMds?WGJdF zjp*38)l<7;k>d5JyNVGfOsgiHw%h;yOitOgyE5V>4{lVxul{`7{PVMWRw6yYpUWyX zw`Vdhlf3j`{Vv&C%kmeq?9p_Oh^>FL@3~^kwaUVaTJh04q?x%5WKO+me0$*`_q1bK z6|1?P~FUbZ6@FDTHSMehDRpdU-@f))eoZ$0g+x4&o;g5F4(d} z`|J4yRg(FWW(Z!sZp+K2y(^9Hb>rp(1#O>G=J=l8vue7sRmsn0#}^wfa;>Yad9#nz z>6nFK`tjs;=`%(WJ~>WDKmT7Ld(q(E;%;$c{oIt}lIQ&HZw^fR)^(wI;ic`X{zgw! zKEN~GZvW9{8{d6-?B_Y=YFuK?6Yp%%pEGCk>d3uz+2tI2=Y3uNX4`?YQy#B>DYhYK z{`OtsQk%_K+uQG*tNwJtT!y>A*i7d+tBPHF+RmPnJKC8Gd-!84re#=8o^*Jv$J+k- z34Ghb?wsW5y{9(Mc$pQ)sk!-*jyaZX5x0Hbb^i@ntFNA? zFx3(#Mj!lN5hUEcDs9>U(I5i^i-MmyblO{m6T- rUCsTW?7yA2k54i5)r-0NHu;yd&HW>y8(J^Bf>M&FtDnm{r-UW|bOSK1 literal 0 HcmV?d00001 diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/layout/item_m_box_operation.xml b/core/function-impl/mogo-core-function-hmi/src/main/res/layout/item_m_box_operation.xml new file mode 100644 index 0000000000..7e563fa97f --- /dev/null +++ b/core/function-impl/mogo-core-function-hmi/src/main/res/layout/item_m_box_operation.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/layout/item_m_box_v2x.xml b/core/function-impl/mogo-core-function-hmi/src/main/res/layout/item_m_box_v2x.xml index 60eab23068..80d40787cb 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/res/layout/item_m_box_v2x.xml +++ b/core/function-impl/mogo-core-function-hmi/src/main/res/layout/item_m_box_v2x.xml @@ -44,7 +44,7 @@ android:ellipsize="end" android:textColor="#FF203555" android:textSize="@dimen/dp_18" - android:layout_marginStart="@dimen/dp_20" + android:layout_marginStart="@dimen/dp_18" android:layout_marginEnd="@dimen/dp_18" /> diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/layout/item_m_msg_box_operation.xml b/core/function-impl/mogo-core-function-hmi/src/main/res/layout/item_m_msg_box_operation.xml index de8d8eae24..716146b2a1 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/res/layout/item_m_msg_box_operation.xml +++ b/core/function-impl/mogo-core-function-hmi/src/main/res/layout/item_m_msg_box_operation.xml @@ -41,10 +41,11 @@ android:gravity="start" android:textColor="#FF203555" android:textSize="20dp" + android:textStyle="bold" android:layout_marginStart="@dimen/dp_13" android:layout_marginEnd="@dimen/dp_13" + android:maxLines="2" + android:ellipsize="end" /> - - \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/layout/item_m_msg_list_operation.xml b/core/function-impl/mogo-core-function-hmi/src/main/res/layout/item_m_msg_list_operation.xml index a064113ef4..075ede3c2a 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/res/layout/item_m_msg_list_operation.xml +++ b/core/function-impl/mogo-core-function-hmi/src/main/res/layout/item_m_msg_list_operation.xml @@ -1,7 +1,7 @@ -