Improve the look of message bubbles.

This commit is contained in:
Greyson Parrelli
2018-06-26 10:27:44 -07:00
parent 7cfcb62c25
commit 24b062d8dd
202 changed files with 2671 additions and 1451 deletions

View File

@@ -2,13 +2,12 @@ package org.thoughtcrime.securesms.components;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.net.Uri;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.annotation.UiThread;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Pair;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
@@ -39,7 +38,7 @@ import static com.bumptech.glide.load.resource.drawable.DrawableTransitionOption
public class ThumbnailView extends FrameLayout {
private static final String TAG = ThumbnailView.class.getSimpleName();
private static final String TAG = ThumbnailView.class.getSimpleName();
private static final int WIDTH = 0;
private static final int HEIGHT = 1;
private static final int MIN_WIDTH = 0;
@@ -48,9 +47,7 @@ public class ThumbnailView extends FrameLayout {
private static final int MAX_HEIGHT = 3;
private ImageView image;
private ImageView playOverlay;
private int backgroundColorHint;
private int radius;
private View playOverlay;
private OnClickListener parentClickListener;
private final int[] dimens = new int[2];
@@ -62,6 +59,8 @@ public class ThumbnailView extends FrameLayout {
private SlideClickListener downloadClickListener = null;
private Slide slide = null;
private int radius;
public ThumbnailView(Context context) {
this(context, null);
}
@@ -75,20 +74,20 @@ public class ThumbnailView extends FrameLayout {
inflate(context, R.layout.thumbnail_view, this);
this.radius = getResources().getDimensionPixelSize(R.dimen.message_bubble_corner_radius);
this.image = findViewById(R.id.thumbnail_image);
this.playOverlay = findViewById(R.id.play_overlay);
super.setOnClickListener(new ThumbnailClickDispatcher());
if (attrs != null) {
TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.ThumbnailView, 0, 0);
backgroundColorHint = typedArray.getColor(R.styleable.ThumbnailView_backgroundColorHint, Color.BLACK);
bounds[MIN_WIDTH] = typedArray.getDimensionPixelSize(R.styleable.ThumbnailView_minWidth, 0);
bounds[MAX_WIDTH] = typedArray.getDimensionPixelSize(R.styleable.ThumbnailView_maxWidth, 0);
bounds[MIN_HEIGHT] = typedArray.getDimensionPixelSize(R.styleable.ThumbnailView_minHeight, 0);
bounds[MAX_HEIGHT] = typedArray.getDimensionPixelSize(R.styleable.ThumbnailView_maxHeight, 0);
bounds[MIN_WIDTH] = typedArray.getDimensionPixelSize(R.styleable.ThumbnailView_minWidth, 0);
bounds[MAX_WIDTH] = typedArray.getDimensionPixelSize(R.styleable.ThumbnailView_maxWidth, 0);
bounds[MIN_HEIGHT] = typedArray.getDimensionPixelSize(R.styleable.ThumbnailView_minHeight, 0);
bounds[MAX_HEIGHT] = typedArray.getDimensionPixelSize(R.styleable.ThumbnailView_maxHeight, 0);
typedArray.recycle();
}
radius = getResources().getDimensionPixelOffset(R.dimen.message_corner_collapse_radius);
}
@Override
@@ -210,8 +209,17 @@ public class ThumbnailView extends FrameLayout {
return transferControls.get();
}
public void setBackgroundColorHint(int color) {
this.backgroundColorHint = color;
public void setBounds(int minWidth, int maxWidth, int minHeight, int maxHeight) {
bounds[MIN_WIDTH] = minWidth;
bounds[MAX_WIDTH] = maxWidth;
bounds[MIN_HEIGHT] = minHeight;
bounds[MAX_HEIGHT] = maxHeight;
forceLayout();
}
public void setImageBackground(@DrawableRes int resId) {
image.setBackgroundResource(resId);
}
@UiThread
@@ -273,10 +281,9 @@ public class ThumbnailView extends FrameLayout {
public void setImageResource(@NonNull GlideRequests glideRequests, @NonNull Uri uri) {
if (transferControls.isPresent()) getTransferControls().setVisibility(View.GONE);
glideRequests.load(new DecryptableUri(uri))
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.transform(new RoundedCorners(radius))
.diskCacheStrategy(DiskCacheStrategy.NONE)
.transforms(new CenterCrop(), new RoundedCorners(radius))
.transition(withCrossFade())
.centerCrop()
.into(image);
}