Android6.0 短信界面,添加多个收件人名字概率性不显示

5 篇文章 0 订阅
在短信编辑界面选择多个联系人时,联系人名字概率性显示不出来。这个联系人布局文件是 recipients_editor.xml, 里面有个自定义View

com.android.mms.ui.RecipientsEditor 这个 RecipientsEditor 继承自 /frameworks/opt/chips 下面的模块的 RecipientEditTextView

在 RecipientEditTextView.java 中做一些绘制工作。

出现这个问题的原因是由于在 RecipientEditTextView.java 文件中的函数 createChipBitmap在执行期间,background task 使TextView invalidate, onDraw 函数被调用,导致TextPaint 的 color 改变所致。

解决的办法1:
修改recipients_editor.xml
<com.android.mms.ui.RecipientsEditor
    android:id="@+id/recipients_editor"
    android:layout_width="254dp"
    android:layout_height="wrap_content"
    android:hint="@string/to_hint"
    android:fontFamily="sans-serif"
    android:textColorHint="#7fffffff"
    android:textSize="16sp"
    android:textColor="@color/recipient_editor_text_color"
    android:background="@drawable/underline_white"
    android:layout_gravity="bottom"
    android:textCursorDrawable="@null"
    app:unselectedChipTextColor="#ffffffff"
    app:unselectedChipBackgroundColor="#ff000000"
    android:nextFocusRight="@+id/recipients_selector"/>

指定 unselectedChipTextColor(不能为白色) 和 unselectedChipBackgroundColor

解决的办法2:
修改 /frameworks/opt/chips/src/com/android/ex/chips/RecipientEditTextView.java

函数:
private ChipBitmapContainer createChipBitmap(RecipientEntry contact, TextPaint paint,
            Drawable overrideBackgroundDrawable, int backgroundColor) {
...
paint.setColor(getDefaultChipTextColor(contact));(添加这句)
canvas.drawText(ellipsizedText, 0, ellipsizedText.length(),
                textX, getTextYOffset(height), paint);
...
            }

解决的办法3:
修改 /frameworks/opt/chips/src/com/android/ex/chips/RecipientEditTextView.java

Author: c_gniu <gniu@codeaurora.org>  2016-04-27 14:50:01
Committer: c_gniu <gniu@codeaurora.org>  2016-04-27 15:12:12
Parent: 7c3533a96b98712d4739ed689faf2c9ece784768 (Promotion of android-framework.lnx.1.0-00023.)
Branch: android-framework.lnx.1.0.c1-dev
Follows: many (22)
Precedes:

    Use new textpaint for drawing text
    
    when drawText by contact name, both Paint color and chips
    background are white, which makes the contact name invisible.
    use new TextPaint before draw text.
    
    Change-Id: I6ab23be016ac4b6316bf78cb2c520f6246aa0676
    CRs-Fixed: 1003981

------------- src/com/android/ex/chips/RecipientEditTextView.java -------------
index 4584e58..917bc53 100644
@@ -174,6 +174,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
     private static final int AVATAR_POSITION_START = 1;
 
     private Paint mWorkPaint = new Paint();
+    private TextPaint mFgTextPaint = new TextPaint();
 
     private Tokenizer mTokenizer;
     private Validator mValidator;
@@ -267,6 +268,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
         super(context, attrs);
         setChipDimensions(context, attrs);
         mTextHeight = calculateTextHeight();
+        setFgTextPaint();
         mAlternatesPopup = new ListPopupWindow(context);
         setupPopupWindow(mAlternatesPopup);
         mAddressPopup = new ListPopupWindow(context);
@@ -723,6 +725,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
             // Draw the default chip background
             mWorkPaint.reset();
             mWorkPaint.setColor(backgroundColor);
+            mWorkPaint.setAntiAlias(true);
             final float radius = height / 2;
             canvas.drawRoundRect(new RectF(0, 0, width, height), radius, radius,
                     mWorkPaint);
@@ -899,11 +902,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
     }
 
     private DrawableRecipientChip constructChipSpan(RecipientEntry contact) {
-        TextPaint paint = getPaint();
-        float defaultSize = paint.getTextSize();
-        int defaultColor = paint.getColor();
-
-        Bitmap tmpBitmap = createChipBitmap(contact, paint);
+        Bitmap tmpBitmap = createChipBitmap(contact, mFgTextPaint);
 
         // Pass the full text, un-ellipsized, to the chip.
         Drawable result = new BitmapDrawable(getResources(), tmpBitmap);
@@ -911,9 +910,6 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
         VisibleRecipientChip recipientChip =
                 new VisibleRecipientChip(result, contact);
         recipientChip.setExtraMargin(mLineSpacingExtra);
-        // Return text to the original size.
-        paint.setTextSize(defaultSize);
-        paint.setColor(defaultColor);
         return recipientChip;
     }
 
@@ -3148,6 +3144,13 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
         }
     }
 
+    /**
+     * set new PaintText for drawText.
+     */
+    private void setFgTextPaint(){
+        mFgTextPaint.set(getPaint());
+    }
+

     private static class ChipBitmapContainer {
         Bitmap bitmap;
         // information used for positioning the loaded icon




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值