Update the preview of the conversation message in the "Display size and text" page.

Bug: 227076211
Test: manual test
Change-Id: Ie83f95ba223a42f596c2a4ef68f33f4152a2cc07
This commit is contained in:
Peter_Liang
2022-03-27 20:26:21 +08:00
parent c4c923d1eb
commit 454f21cb21
6 changed files with 89 additions and 51 deletions

View File

@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2022 The Android Open Source Project
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.
-->
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
android:color="#639DF6"/>
<corners android:radius="28dp"/>
</shape>

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2022 The Android Open Source Project
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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?android:attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M12,12q-1.65,0 -2.825,-1.175Q8,9.65 8,8q0,-1.65 1.175,-2.825Q10.35,4 12,4q1.65,0 2.825,1.175Q16,6.35 16,8q0,1.65 -1.175,2.825Q13.65,12 12,12zM4,20v-2.8q0,-0.85 0.438,-1.562 0.437,-0.713 1.162,-1.088 1.55,-0.775 3.15,-1.163Q10.35,13 12,13t3.25,0.387q1.6,0.388 3.15,1.163 0.725,0.375 1.163,1.088Q20,16.35 20,17.2L20,20zM6,18h12v-0.8q0,-0.275 -0.137,-0.5 -0.138,-0.225 -0.363,-0.35 -1.35,-0.675 -2.725,-1.013Q13.4,15 12,15t-2.775,0.338Q7.85,15.675 6.5,16.35q-0.225,0.125 -0.362,0.35 -0.138,0.225 -0.138,0.5zM12,10q0.825,0 1.412,-0.588Q14,8.825 14,8t-0.588,-1.412Q12.825,6 12,6t-1.412,0.588Q10,7.175 10,8t0.588,1.412Q11.175,10 12,10zM12,8zM12,18z"/>
</vector>

View File

@@ -34,45 +34,19 @@
android:paddingEnd="@dimen/conversation_message_list_padding"
android:orientation="vertical">
<com.android.settings.display.ConversationMessageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:incoming="false"
app:messageText="@string/screen_zoom_conversation_message_1"
app:timestampText="@string/screen_zoom_conversation_timestamp_1"
app:iconText="@string/screen_zoom_conversation_icon_alex"
app:iconTextColor="@color/message_icon_text_outgoing"
app:iconBackgroundColor="@color/message_icon_background_outgoing" />
<com.android.settings.display.ConversationMessageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:incoming="true"
app:messageText="@string/screen_zoom_conversation_message_2"
app:timestampText="@string/screen_zoom_conversation_timestamp_2"
app:iconText="@string/screen_zoom_conversation_icon_pete"
app:iconTextColor="@color/message_icon_text_incoming"
app:messageText="@string/accessibility_text_reading_conversation_message_1"
app:iconBackgroundColor="@color/message_icon_background_incoming" />
<com.android.settings.display.ConversationMessageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:incoming="false"
app:messageText="@string/screen_zoom_conversation_message_3"
app:timestampText="@string/screen_zoom_conversation_timestamp_3"
app:iconText="@string/screen_zoom_conversation_icon_alex"
app:iconTextColor="@color/message_icon_text_outgoing"
app:messageText="@string/accessibility_text_reading_conversation_message_2"
app:iconBackgroundColor="@color/message_icon_background_outgoing" />
<com.android.settings.display.ConversationMessageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:incoming="true"
app:messageText="@string/screen_zoom_conversation_message_4"
app:timestampText="@string/screen_zoom_conversation_timestamp_4"
app:iconText="@string/screen_zoom_conversation_icon_pete"
app:iconTextColor="@color/message_icon_text_incoming"
app:iconBackgroundColor="@color/message_icon_background_incoming" />
</LinearLayout>
</view>
</androidx.core.widget.NestedScrollView>

View File

@@ -44,16 +44,17 @@
<color name="material_grey_100">#f5f5f5</color>
<color name="material_grey_200">#ffffff</color>
<color name="message_text_incoming">#ffffffff</color>
<color name="message_text_outgoing">#ff323232</color>
<color name="message_text_incoming">#E4E3DA</color>
<color name="message_text_outgoing">#1B1C17</color>
<color name="timestamp_text_outgoing">#99323232</color>
<color name="timestamp_text_incoming">#99ffffff</color>
<color name="message_bubble_incoming">#689f38</color>
<color name="message_bubble_outgoing">#ffffffff</color>
<color name="message_icon_background_incoming">#689f38</color>
<color name="message_bubble_incoming">#52534D</color>
<color name="message_bubble_outgoing">#C7C8B7</color>
<color name="message_icon_background_incoming">#E6F451</color>
<color name="message_icon_text_incoming">#ffffffff</color>
<color name="message_icon_background_outgoing">#4285f4</color>
<color name="message_icon_background_outgoing">#FBBC04</color>
<color name="message_icon_text_outgoing">#ffffffff</color>
<color name="message_icon_color">#DADADA</color>
<color name="usage_graph_dots">#B0BEC5</color>

View File

@@ -257,12 +257,13 @@
<dimen name="conversation_message_text_size">16sp</dimen>
<dimen name="conversation_status_text_size">12sp</dimen>
<dimen name="conversation_bubble_width_snap">20dp</dimen>
<dimen name="message_bubble_arrow_width">9dp</dimen>
<dimen name="message_bubble_left_right_padding">9dp</dimen>
<dimen name="message_padding_default">18dp</dimen>
<dimen name="message_text_left_right_padding">14dp</dimen>
<dimen name="message_text_top_padding">10dp</dimen>
<dimen name="message_text_bottom_padding">12dp</dimen>
<dimen name="message_metadata_top_padding">4dp</dimen>
<dimen name="message_icon_inset">11dp</dimen>
<!-- Accessibility Settings -->
<dimen name="accessibility_layout_margin_start_end">16dp</dimen>

View File

@@ -21,6 +21,8 @@ import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
@@ -106,14 +108,14 @@ public class ConversationMessageView extends FrameLayout {
MeasureSpec.EXACTLY);
mContactIconView.measure(iconMeasureSpec, iconMeasureSpec);
final int arrowWidth =
getResources().getDimensionPixelSize(R.dimen.message_bubble_arrow_width);
final int messageBubblePadding =
getResources().getDimensionPixelOffset(R.dimen.message_bubble_left_right_padding);
// We need to subtract contact icon width twice from the horizontal space to get
// the max leftover space because we want the message bubble to extend no further than the
// starting position of the message bubble in the opposite direction.
final int maxLeftoverSpace = horizontalSpace - mContactIconView.getMeasuredWidth() * 2
- arrowWidth - getPaddingLeft() - getPaddingRight();
- messageBubblePadding - getPaddingLeft() - getPaddingRight();
final int messageContentWidthMeasureSpec = MeasureSpec.makeMeasureSpec(maxLeftoverSpace,
MeasureSpec.AT_MOST);
@@ -170,19 +172,28 @@ public class ConversationMessageView extends FrameLayout {
private void updateViewContent() {
mMessageTextView.setText(mMessageText);
mStatusTextView.setText(mTimestampText);
mStatusTextView.setVisibility(TextUtils.isEmpty(mTimestampText) ? GONE : VISIBLE);
mContactIconView.setText(mIconText);
mContactIconView.setTextColor(mIconTextColor);
final Drawable iconBase = getContext().getDrawable(R.drawable.conversation_message_icon);
mContactIconView
.setBackground(getTintedDrawable(getContext(), iconBase, mIconBackgroundColor));
final Drawable iconBackground = getContext().getDrawable(
R.drawable.conversation_message_icon);
final Drawable icon = getContext().getDrawable(R.drawable.ic_person);
final LayerDrawable layerDrawable = new LayerDrawable(
new Drawable[]{
getTintedDrawable(getContext(), iconBackground, mIconBackgroundColor),
getTintedDrawable(getContext(), icon,
getContext().getColor(R.color.message_icon_color))});
final int iconInset = getResources().getDimensionPixelOffset(R.dimen.message_icon_inset);
layerDrawable.setLayerInset(/* index= */ 1, iconInset, iconInset, iconInset, iconInset);
mContactIconView.setBackground(layerDrawable);
}
private void updateViewAppearance() {
final Resources res = getResources();
final int arrowWidth = res.getDimensionPixelOffset(
R.dimen.message_bubble_arrow_width);
final int messageBubbleLeftRightPadding = res.getDimensionPixelOffset(
R.dimen.message_bubble_left_right_padding);
final int messageTextLeftRightPadding = res.getDimensionPixelOffset(
R.dimen.message_text_left_right_padding);
final int textTopPadding = res.getDimensionPixelOffset(
@@ -191,14 +202,11 @@ public class ConversationMessageView extends FrameLayout {
R.dimen.message_text_bottom_padding);
final int textLeftPadding, textRightPadding;
textLeftPadding = messageTextLeftRightPadding;
textRightPadding = messageTextLeftRightPadding;
if (mIncoming) {
textLeftPadding = messageTextLeftRightPadding + arrowWidth;
textRightPadding = messageTextLeftRightPadding;
} else {
textLeftPadding = messageTextLeftRightPadding;
textRightPadding = messageTextLeftRightPadding + arrowWidth;
}
final int messageBubbleLeftPadding = mIncoming ? messageBubbleLeftRightPadding : 0;
final int messageBubbleRightPadding = mIncoming ? 0 : messageBubbleLeftRightPadding;
// These values do not depend on whether the message includes attachments
final int gravity = mIncoming ? (Gravity.START | Gravity.CENTER_VERTICAL) :
@@ -216,7 +224,7 @@ public class ConversationMessageView extends FrameLayout {
final Context context = getContext();
final Drawable textBackgroundDrawable = getTintedDrawable(context,
context.getDrawable(bubbleDrawableResId),
context.getDrawable(R.drawable.conversation_message_text_info_view_background),
context.getColor(bubbleColorResId));
mMessageTextAndInfoView.setBackground(textBackgroundDrawable);
@@ -234,6 +242,8 @@ public class ConversationMessageView extends FrameLayout {
// Update the message row and message bubble views
setPadding(getPaddingLeft(), messageTopPadding, getPaddingRight(), 0);
mMessageBubble.setGravity(gravity);
mMessageBubble.setPaddingRelative(messageBubbleLeftPadding, /* top= */ 0,
messageBubbleRightPadding, /* bottom= */ 0);
updateTextAppearance();
}