Messaging: Use xml drawables

Replace the pngs with xml drawables

Change-Id: I71be32c36194d3b34b54287a09789f73087600ef
This commit is contained in:
Michael W
2024-12-26 14:55:12 +01:00
parent 4ecf5bc70a
commit d869533f6f
357 changed files with 604 additions and 101 deletions
@@ -20,16 +20,16 @@ import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Typeface;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.VectorDrawable;
import android.media.ExifInterface;
import android.net.Uri;
import android.text.TextUtils;
import androidx.core.content.res.ResourcesCompat;
import com.android.messaging.R;
import com.android.messaging.util.Assert;
import com.android.messaging.util.AvatarUriUtil;
@@ -42,8 +42,8 @@ import java.io.InputStream;
import java.util.List;
public class AvatarRequest extends UriImageRequest<AvatarRequestDescriptor> {
private static Bitmap sDefaultPersonBitmap;
private static Bitmap sDefaultPersonBitmapLarge;
private static final float SCALING_FACTOR = 1.33f;
private TypedArray mColors;
public AvatarRequest(final Context context,
@@ -122,37 +122,14 @@ public class AvatarRequest extends UriImageRequest<AvatarRequestDescriptor> {
final Bitmap bitmap = getBitmapPool().createOrReuseBitmap(width, height,
getBackgroundColor(AvatarUriUtil.getIdentifier(mDescriptor.uri)));
final Canvas canvas = new Canvas(bitmap);
final VectorDrawable defaultPerson = (VectorDrawable) ResourcesCompat.getDrawable(
mContext.getResources(), R.drawable.ic_person_light, mContext.getTheme());
float dstWidth = Math.min(defaultPerson.getIntrinsicWidth() * SCALING_FACTOR, width);
float dstHeight = Math.min(defaultPerson.getIntrinsicHeight() * SCALING_FACTOR, height);
if (sDefaultPersonBitmap == null) {
final BitmapDrawable defaultPerson = (BitmapDrawable) mContext.getResources()
.getDrawable(R.drawable.ic_person_light);
sDefaultPersonBitmap = defaultPerson.getBitmap();
}
if (sDefaultPersonBitmapLarge == null) {
final BitmapDrawable largeDefaultPerson = (BitmapDrawable) mContext.getResources()
.getDrawable(R.drawable.ic_person_light_large);
sDefaultPersonBitmapLarge = largeDefaultPerson.getBitmap();
}
Bitmap defaultPerson = null;
if (mDescriptor.isWearBackground) {
final BitmapDrawable wearDefaultPerson = (BitmapDrawable) mContext.getResources()
.getDrawable(R.drawable.ic_person_wear);
defaultPerson = wearDefaultPerson.getBitmap();
} else {
final boolean isLargeDefault = (width > sDefaultPersonBitmap.getWidth()) ||
(height > sDefaultPersonBitmap.getHeight());
defaultPerson =
isLargeDefault ? sDefaultPersonBitmapLarge : sDefaultPersonBitmap;
}
final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
final Matrix matrix = new Matrix();
final RectF source = new RectF(0, 0, defaultPerson.getWidth(), defaultPerson.getHeight());
final RectF dest = new RectF(0, 0, width, height);
matrix.setRectToRect(source, dest, Matrix.ScaleToFit.FILL);
canvas.drawBitmap(defaultPerson, matrix, paint);
canvas.translate((width - dstWidth) / 2, (height - dstHeight) / 2);
defaultPerson.setBounds(0, 0, (int)dstWidth, (int)dstHeight);
defaultPerson.draw(canvas);
return bitmap;
}
@@ -33,9 +33,6 @@ public class ConversationDrawables {
// Cache the color filtered bubble drawables so that we don't need to create a
// new one for each ConversationMessageView.
private Drawable mIncomingBubbleDrawable;
private Drawable mOutgoingBubbleDrawable;
private Drawable mIncomingErrorBubbleDrawable;
private Drawable mIncomingBubbleNoArrowDrawable;
private Drawable mOutgoingBubbleNoArrowDrawable;
private Drawable mAudioPlayButtonDrawable;
@@ -75,15 +72,12 @@ public class ConversationDrawables {
public void updateDrawables() {
final Resources resources = mContext.getResources();
mIncomingBubbleDrawable = resources.getDrawable(R.drawable.msg_bubble_incoming);
mIncomingBubbleNoArrowDrawable =
resources.getDrawable(R.drawable.message_bubble_incoming_no_arrow);
mIncomingErrorBubbleDrawable = resources.getDrawable(R.drawable.msg_bubble_error);
mOutgoingBubbleDrawable = resources.getDrawable(R.drawable.msg_bubble_outgoing);
mOutgoingBubbleNoArrowDrawable =
resources.getDrawable(R.drawable.message_bubble_outgoing_no_arrow);
mAudioPlayButtonDrawable = resources.getDrawable(R.drawable.ic_audio_play);
mAudioPauseButtonDrawable = resources.getDrawable(R.drawable.ic_audio_pause);
mAudioPlayButtonDrawable = resources.getDrawable(R.drawable.ic_play_light);
mAudioPauseButtonDrawable = resources.getDrawable(R.drawable.ic_pause_light);
mIncomingAudioProgressBackgroundDrawable =
resources.getDrawable(R.drawable.audio_progress_bar_background_incoming);
mOutgoingAudioProgressBackgroundDrawable =
@@ -108,16 +102,9 @@ public class ConversationDrawables {
}
public Drawable getBubbleDrawable(final boolean selected, final boolean incoming,
final boolean needArrow, final boolean isError, final String identifier) {
final boolean isError, final String identifier) {
final Drawable protoDrawable;
if (needArrow) {
if (incoming) {
protoDrawable = isError && !selected ?
mIncomingErrorBubbleDrawable : mIncomingBubbleDrawable;
} else {
protoDrawable = mOutgoingBubbleDrawable;
}
} else if (incoming) {
if (incoming) {
protoDrawable = mIncomingBubbleNoArrowDrawable;
} else {
protoDrawable = mOutgoingBubbleNoArrowDrawable;
@@ -282,14 +282,6 @@ public class ConversationMessageView extends FrameLayout implements View.OnClick
return mData.getCanClusterWithPreviousMessage();
}
/**
* Returns whether we need to show message bubble arrow. We don't show arrow if the message
* contains media attachments or if shouldShowSimplifiedVisualStyle() is true.
*/
private boolean shouldShowMessageBubbleArrow() {
return false;
}
/**
* Returns whether we need to show a message bubble for text content.
*/
@@ -665,7 +657,6 @@ public class ConversationMessageView extends FrameLayout implements View.OnClick
final ConversationDrawables drawableProvider = ConversationDrawables.get();
final boolean incoming = mData.getIsIncoming();
final boolean outgoing = !incoming;
final boolean showArrow = shouldShowMessageBubbleArrow();
final int messageTopPaddingClustered =
res.getDimensionPixelSize(R.dimen.message_padding_same_author);
@@ -699,7 +690,6 @@ public class ConversationMessageView extends FrameLayout implements View.OnClick
textBackground = drawableProvider.getBubbleDrawable(
isSelected(),
incoming,
false /* needArrow */,
mData.hasIncomingErrorStatus(),
mData.getSenderContactLookupKey());
textMinHeight = messageTextMinHeightDefault;
@@ -723,12 +713,11 @@ public class ConversationMessageView extends FrameLayout implements View.OnClick
}
} else {
// Text only
contentLeftPadding = (!showArrow && incoming) ? arrowWidth : 0;
contentRightPadding = (!showArrow && outgoing) ? arrowWidth : 0;
contentLeftPadding = incoming ? arrowWidth : 0;
contentRightPadding = outgoing ? arrowWidth : 0;
textBackground = drawableProvider.getBubbleDrawable(
isSelected(),
incoming,
shouldShowMessageBubbleArrow(),
mData.hasIncomingErrorStatus(),
mData.getSenderContactLookupKey());
textMinHeight = messageTextMinHeightDefault;
@@ -736,16 +725,8 @@ public class ConversationMessageView extends FrameLayout implements View.OnClick
textTopPadding = textTopPaddingDefault;
textBottomPadding = textBottomPaddingDefault;
mMessageTextView.setTextIsSelectable(isSelected());
if (showArrow && incoming) {
textLeftPadding = messageTextLeftRightPadding + arrowWidth;
} else {
textLeftPadding = messageTextLeftRightPadding;
}
if (showArrow && outgoing) {
textRightPadding = messageTextLeftRightPadding + arrowWidth;
} else {
textRightPadding = messageTextLeftRightPadding;
}
textLeftPadding = messageTextLeftRightPadding;
textRightPadding = messageTextLeftRightPadding;
}
// These values do not depend on whether the message includes attachments
@@ -1121,8 +1102,8 @@ public class ConversationMessageView extends FrameLayout implements View.OnClick
final AudioAttachmentView audioView = (AudioAttachmentView) view;
audioView.bindMessagePartData(attachment, mData.getIsIncoming(), isSelected());
audioView.setBackground(ConversationDrawables.get().getBubbleDrawable(
isSelected(), mData.getIsIncoming(), false /* needArrow */,
mData.hasIncomingErrorStatus(), mData.getSenderContactLookupKey()));
isSelected(), mData.getIsIncoming(), mData.hasIncomingErrorStatus(),
mData.getSenderContactLookupKey()));
}
@Override
@@ -1138,8 +1119,8 @@ public class ConversationMessageView extends FrameLayout implements View.OnClick
personView.bind(DataModel.get().createVCardContactItemData(getContext(),
attachment));
personView.setBackground(ConversationDrawables.get().getBubbleDrawable(
isSelected(), mData.getIsIncoming(), false /* needArrow */,
mData.hasIncomingErrorStatus(), mData.getSenderContactLookupKey()));
isSelected(), mData.getIsIncoming(), mData.hasIncomingErrorStatus(),
mData.getSenderContactLookupKey()));
final int nameTextColorRes;
final int detailsTextColorRes;
if (isSelected()) {
@@ -443,7 +443,7 @@ class CameraMediaChooser extends MediaChooser implements
mVideoCounter.setVisibility(isRecording ? View.VISIBLE : View.GONE);
mSwapModeButton.setImageResource(videoMode ?
R.drawable.ic_mp_camera_small_light :
R.drawable.ic_camera_light :
R.drawable.ic_mp_video_small_light);
mSwapModeButton.setContentDescription(context.getString(videoMode ?
R.string.camera_switch_to_still_mode : R.string.camera_switch_to_video_mode));
@@ -451,15 +451,15 @@ class CameraMediaChooser extends MediaChooser implements
mSwapModeButton.setEnabled(isCameraAvailable);
if (isRecording) {
mCaptureButton.setImageResource(R.drawable.ic_mp_capture_stop_large_light);
mCaptureButton.setImageResource(R.drawable.ic_mp_capture_stop_light);
mCaptureButton.setContentDescription(context.getString(
R.string.camera_stop_recording));
} else if (videoMode) {
mCaptureButton.setImageResource(R.drawable.ic_mp_video_large_light);
mCaptureButton.setImageResource(R.drawable.ic_mp_video_small_light);
mCaptureButton.setContentDescription(context.getString(
R.string.camera_start_recording));
} else {
mCaptureButton.setImageResource(R.drawable.ic_checkmark_large_light);
mCaptureButton.setImageResource(R.drawable.ic_checkmark_light);
mCaptureButton.setContentDescription(context.getString(
R.string.camera_take_picture));
}
@@ -181,7 +181,7 @@ public class GalleryGridItemView extends FrameLayout {
mImageView.setImageResourceId(mData.getImageRequestDescriptor());
mImageView.setVisibility(VISIBLE);
if (ContentType.isVideoType(mData.getContentType())) {
mIcon.setImageResource(R.drawable.ic_video_play_light);
mIcon.setImageResource(R.drawable.ic_play_light);
mIcon.clearColorFilter();
mIcon.setVisibility(VISIBLE);
} else {
@@ -143,7 +143,7 @@ abstract class MediaChooser extends BasePagerViewHolder
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.show();
// Use X instead of <- in the action bar
actionBar.setHomeAsUpIndicator(R.drawable.ic_remove_small_light);
actionBar.setHomeAsUpIndicator(R.drawable.ic_cancel_small_light);
actionBar.setTitle(actionBarTitleResId);
}
}