| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.internal.widget; |
| 18 |
|
| 19 |
import android.annotation.AttrRes; |
| 20 |
import android.annotation.NonNull; |
| 21 |
import android.annotation.Nullable; |
| 22 |
import android.annotation.StyleRes; |
| 23 |
import android.app.Notification; |
| 24 |
import android.content.Context; |
| 25 |
import android.text.Layout; |
| 26 |
import android.util.AttributeSet; |
| 27 |
import android.view.LayoutInflater; |
| 28 |
import android.widget.RemoteViews; |
| 29 |
|
| 30 |
import com.android.internal.R; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
@RemoteViews.RemoteView |
| 36 |
public class MessagingTextMessage extends ImageFloatingTextView implements MessagingMessage { |
| 37 |
|
| 38 |
private static final MessagingPool<MessagingTextMessage> sInstancePool = |
| 39 |
new MessagingPool<>(20); |
| 40 |
private final MessagingMessageState mState = new MessagingMessageState(this); |
| 41 |
|
| 42 |
public MessagingTextMessage(@NonNull Context context) { |
| 43 |
super(context); |
| 44 |
} |
| 45 |
|
| 46 |
public MessagingTextMessage(@NonNull Context context, @Nullable AttributeSet attrs) { |
| 47 |
super(context, attrs); |
| 48 |
} |
| 49 |
|
| 50 |
public MessagingTextMessage(@NonNull Context context, @Nullable AttributeSet attrs, |
| 51 |
@AttrRes int defStyleAttr) { |
| 52 |
super(context, attrs, defStyleAttr); |
| 53 |
} |
| 54 |
|
| 55 |
public MessagingTextMessage(@NonNull Context context, @Nullable AttributeSet attrs, |
| 56 |
@AttrRes int defStyleAttr, @StyleRes int defStyleRes) { |
| 57 |
super(context, attrs, defStyleAttr, defStyleRes); |
| 58 |
} |
| 59 |
|
| 60 |
@Override |
| 61 |
public MessagingMessageState getState() { |
| 62 |
return mState; |
| 63 |
} |
| 64 |
|
| 65 |
@Override |
| 66 |
public boolean setMessage(Notification.MessagingStyle.Message message) { |
| 67 |
MessagingMessage.super.setMessage(message); |
| 68 |
setText(message.getText()); |
| 69 |
return true; |
| 70 |
} |
| 71 |
|
| 72 |
static MessagingMessage createMessage(IMessagingLayout layout, |
| 73 |
Notification.MessagingStyle.Message m) { |
| 74 |
MessagingLinearLayout messagingLinearLayout = layout.getMessagingLinearLayout(); |
| 75 |
MessagingTextMessage createdMessage = sInstancePool.acquire(); |
| 76 |
if (createdMessage == null) { |
| 77 |
createdMessage = (MessagingTextMessage) LayoutInflater.from( |
| 78 |
layout.getContext()).inflate( |
| 79 |
R.layout.notification_template_messaging_text_message, |
| 80 |
messagingLinearLayout, |
| 81 |
false); |
| 82 |
createdMessage.addOnLayoutChangeListener(MessagingLayout.MESSAGING_PROPERTY_ANIMATOR); |
| 83 |
} |
| 84 |
createdMessage.setMessage(m); |
| 85 |
return createdMessage; |
| 86 |
} |
| 87 |
|
| 88 |
public void recycle() { |
| 89 |
MessagingMessage.super.recycle(); |
| 90 |
sInstancePool.release(this); |
| 91 |
} |
| 92 |
|
| 93 |
public static void dropCache() { |
| 94 |
sInstancePool.clear(); |
| 95 |
} |
| 96 |
|
| 97 |
@Override |
| 98 |
public int getMeasuredType() { |
| 99 |
boolean measuredTooSmall = getMeasuredHeight() |
| 100 |
< getLayoutHeight() + getPaddingTop() + getPaddingBottom(); |
| 101 |
if (measuredTooSmall && getLineCount() <= 1) { |
| 102 |
return MEASURED_TOO_SMALL; |
| 103 |
} else { |
| 104 |
Layout layout = getLayout(); |
| 105 |
if (layout == null) { |
| 106 |
return MEASURED_TOO_SMALL; |
| 107 |
} |
| 108 |
if (layout.getEllipsisCount(layout.getLineCount() - 1) > 0) { |
| 109 |
return MEASURED_SHORTENED; |
| 110 |
} else { |
| 111 |
return MEASURED_NORMAL; |
| 112 |
} |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
@Override |
| 117 |
public void setMaxDisplayedLines(int lines) { |
| 118 |
setMaxLines(lines); |
| 119 |
} |
| 120 |
|
| 121 |
@Override |
| 122 |
public int getConsumedLines() { |
| 123 |
return getLineCount(); |
| 124 |
} |
| 125 |
|
| 126 |
public int getLayoutHeight() { |
| 127 |
Layout layout = getLayout(); |
| 128 |
if (layout == null) { |
| 129 |
return 0; |
| 130 |
} |
| 131 |
return layout.getHeight(); |
| 132 |
} |
| 133 |
|
| 134 |
@Override |
| 135 |
public void setColor(int color) { |
| 136 |
setTextColor(color); |
| 137 |
} |
| 138 |
} |