Add RoundedImageView for avatars (#739)
* Add RoundedImageView for avatars * RoundedImageView: Remove unused things, fix touchable area
This commit is contained in:
parent
562beacfc1
commit
133808891d
26 changed files with 367 additions and 49 deletions
|
@ -81,7 +81,6 @@ dependencies {
|
|||
implementation 'com.squareup.okhttp3:okhttp:3.11.0'
|
||||
implementation 'com.squareup.okhttp3:logging-interceptor:3.11.0'
|
||||
implementation 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0'
|
||||
implementation 'com.pkmmte.view:circularimageview:1.1'
|
||||
implementation 'com.github.connyduck:sparkbutton:1.0.1'
|
||||
implementation 'com.github.chrisbanes:PhotoView:2.1.3'
|
||||
implementation 'com.mikepenz:google-material-typeface:3.0.1.2.original@aar'
|
||||
|
|
|
@ -314,7 +314,6 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasSupportF
|
|||
|
||||
Picasso.with(this)
|
||||
.load(account.avatar)
|
||||
.transform(RoundedTransformation(25f))
|
||||
.placeholder(R.drawable.avatar_default)
|
||||
.into(accountAvatarImageView)
|
||||
Picasso.with(this)
|
||||
|
@ -340,7 +339,6 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasSupportF
|
|||
|
||||
Picasso.with(this)
|
||||
.load(movedAccount.avatar)
|
||||
.transform(RoundedTransformation(25f))
|
||||
.placeholder(R.drawable.avatar_default)
|
||||
.into(accountMovedAvatar)
|
||||
|
||||
|
|
|
@ -111,12 +111,10 @@ import com.keylesspalace.tusky.view.ComposeOptionsListener;
|
|||
import com.keylesspalace.tusky.view.ComposeOptionsView;
|
||||
import com.keylesspalace.tusky.view.EditTextTyped;
|
||||
import com.keylesspalace.tusky.view.ProgressImageView;
|
||||
import com.keylesspalace.tusky.view.RoundedTransformation;
|
||||
import com.keylesspalace.tusky.view.TootButton;
|
||||
import com.mikepenz.google_material_typeface_library.GoogleMaterial;
|
||||
import com.mikepenz.iconics.IconicsDrawable;
|
||||
import com.squareup.picasso.Picasso;
|
||||
import at.connyduck.sparkbutton.helpers.Utils;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
@ -135,6 +133,7 @@ import java.util.Locale;
|
|||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import at.connyduck.sparkbutton.helpers.Utils;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.MultipartBody;
|
||||
import retrofit2.Call;
|
||||
|
@ -264,7 +263,6 @@ public final class ComposeActivity
|
|||
composeAvatar.setImageResource(R.drawable.avatar_default);
|
||||
} else {
|
||||
Picasso.with(this).load(activeAccount.getProfilePictureUrl())
|
||||
.transform(new RoundedTransformation(25))
|
||||
.error(R.drawable.avatar_default)
|
||||
.placeholder(R.drawable.avatar_default)
|
||||
.into(composeAvatar);
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.keylesspalace.tusky.adapter;
|
|||
import android.content.Context;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.keylesspalace.tusky.R;
|
||||
|
@ -10,14 +11,13 @@ import com.keylesspalace.tusky.entity.Account;
|
|||
import com.keylesspalace.tusky.interfaces.AccountActionListener;
|
||||
import com.keylesspalace.tusky.interfaces.LinkListener;
|
||||
import com.keylesspalace.tusky.util.CustomEmojiHelper;
|
||||
import com.pkmmte.view.CircularImageView;
|
||||
import com.squareup.picasso.Picasso;
|
||||
|
||||
class AccountViewHolder extends RecyclerView.ViewHolder {
|
||||
private View container;
|
||||
private TextView username;
|
||||
private TextView displayName;
|
||||
private CircularImageView avatar;
|
||||
private ImageView avatar;
|
||||
private String accountId;
|
||||
|
||||
AccountViewHolder(View itemView) {
|
||||
|
|
|
@ -21,13 +21,13 @@ import android.view.LayoutInflater;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.keylesspalace.tusky.R;
|
||||
import com.keylesspalace.tusky.entity.Account;
|
||||
import com.keylesspalace.tusky.interfaces.AccountActionListener;
|
||||
import com.keylesspalace.tusky.util.CustomEmojiHelper;
|
||||
import com.pkmmte.view.CircularImageView;
|
||||
import com.squareup.picasso.Picasso;
|
||||
|
||||
public class BlocksAdapter extends AccountAdapter {
|
||||
|
@ -78,7 +78,7 @@ public class BlocksAdapter extends AccountAdapter {
|
|||
}
|
||||
|
||||
static class BlockedUserViewHolder extends RecyclerView.ViewHolder {
|
||||
private CircularImageView avatar;
|
||||
private ImageView avatar;
|
||||
private TextView username;
|
||||
private TextView displayName;
|
||||
private ImageButton unblock;
|
||||
|
|
|
@ -21,13 +21,13 @@ import android.view.LayoutInflater;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.keylesspalace.tusky.interfaces.AccountActionListener;
|
||||
import com.keylesspalace.tusky.R;
|
||||
import com.keylesspalace.tusky.entity.Account;
|
||||
import com.keylesspalace.tusky.interfaces.AccountActionListener;
|
||||
import com.keylesspalace.tusky.util.CustomEmojiHelper;
|
||||
import com.pkmmte.view.CircularImageView;
|
||||
import com.squareup.picasso.Picasso;
|
||||
|
||||
public class FollowRequestsAdapter extends AccountAdapter {
|
||||
|
@ -78,7 +78,7 @@ public class FollowRequestsAdapter extends AccountAdapter {
|
|||
}
|
||||
|
||||
static class FollowRequestViewHolder extends RecyclerView.ViewHolder {
|
||||
private CircularImageView avatar;
|
||||
private ImageView avatar;
|
||||
private TextView username;
|
||||
private TextView displayName;
|
||||
private ImageButton accept;
|
||||
|
|
|
@ -31,7 +31,6 @@ import android.widget.TextView;
|
|||
import com.keylesspalace.tusky.R;
|
||||
import com.keylesspalace.tusky.entity.Account;
|
||||
import com.keylesspalace.tusky.util.CustomEmojiHelper;
|
||||
import com.keylesspalace.tusky.view.RoundedTransformation;
|
||||
import com.squareup.picasso.Picasso;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -131,7 +130,6 @@ public class MentionAutoCompleteAdapter extends ArrayAdapter<Account>
|
|||
Picasso.with(context)
|
||||
.load(account.getAvatar())
|
||||
.placeholder(R.drawable.avatar_default)
|
||||
.transform(new RoundedTransformation(25))
|
||||
.into(avatar);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,13 +6,13 @@ import android.view.LayoutInflater;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.keylesspalace.tusky.R;
|
||||
import com.keylesspalace.tusky.entity.Account;
|
||||
import com.keylesspalace.tusky.interfaces.AccountActionListener;
|
||||
import com.keylesspalace.tusky.util.CustomEmojiHelper;
|
||||
import com.pkmmte.view.CircularImageView;
|
||||
import com.squareup.picasso.Picasso;
|
||||
|
||||
public class MutesAdapter extends AccountAdapter {
|
||||
|
@ -63,7 +63,7 @@ public class MutesAdapter extends AccountAdapter {
|
|||
}
|
||||
|
||||
static class MutedUserViewHolder extends RecyclerView.ViewHolder {
|
||||
private CircularImageView avatar;
|
||||
private ImageView avatar;
|
||||
private TextView username;
|
||||
private TextView displayName;
|
||||
private ImageButton unmute;
|
||||
|
|
|
@ -23,8 +23,8 @@ import android.graphics.drawable.Drawable;
|
|||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v4.text.BidiFormatter;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.Spanned;
|
||||
import android.text.TextUtils;
|
||||
|
@ -46,7 +46,6 @@ import com.keylesspalace.tusky.interfaces.StatusActionListener;
|
|||
import com.keylesspalace.tusky.util.CustomEmojiHelper;
|
||||
import com.keylesspalace.tusky.util.DateUtils;
|
||||
import com.keylesspalace.tusky.util.LinkHelper;
|
||||
import com.keylesspalace.tusky.view.RoundedTransformation;
|
||||
import com.keylesspalace.tusky.viewdata.NotificationViewData;
|
||||
import com.keylesspalace.tusky.viewdata.StatusViewData;
|
||||
import com.squareup.picasso.Picasso;
|
||||
|
@ -291,7 +290,6 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
|
|||
Picasso.with(context)
|
||||
.load(account.getAvatar())
|
||||
.fit()
|
||||
.transform(new RoundedTransformation(25))
|
||||
.placeholder(R.drawable.avatar_default)
|
||||
.into(avatar);
|
||||
}
|
||||
|
@ -454,7 +452,6 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
|
|||
Picasso.with(context)
|
||||
.load(statusAvatarUrl)
|
||||
.placeholder(R.drawable.avatar_default)
|
||||
.transform(new RoundedTransformation(25))
|
||||
.into(statusAvatar);
|
||||
}
|
||||
|
||||
|
@ -465,7 +462,6 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
|
|||
.load(notificationAvatarUrl)
|
||||
.placeholder(R.drawable.avatar_default)
|
||||
.fit()
|
||||
.transform(new RoundedTransformation(25))
|
||||
.into(notificationAvatar);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,17 +26,16 @@ import com.keylesspalace.tusky.util.DateUtils;
|
|||
import com.keylesspalace.tusky.util.HtmlUtils;
|
||||
import com.keylesspalace.tusky.util.LinkHelper;
|
||||
import com.keylesspalace.tusky.util.ThemeUtils;
|
||||
import com.keylesspalace.tusky.view.RoundedTransformation;
|
||||
import com.keylesspalace.tusky.viewdata.StatusViewData;
|
||||
import com.mikepenz.iconics.utils.Utils;
|
||||
import com.squareup.picasso.Picasso;
|
||||
|
||||
import at.connyduck.sparkbutton.SparkButton;
|
||||
import at.connyduck.sparkbutton.SparkEventListener;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import at.connyduck.sparkbutton.SparkButton;
|
||||
import at.connyduck.sparkbutton.SparkEventListener;
|
||||
|
||||
abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
||||
private View container;
|
||||
private TextView displayName;
|
||||
|
@ -122,7 +121,6 @@ abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
|||
Picasso.with(avatar.getContext())
|
||||
.load(url)
|
||||
.placeholder(R.drawable.avatar_default)
|
||||
.transform(new RoundedTransformation(25))
|
||||
.into(avatar);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,9 +25,9 @@ import android.widget.TextView;
|
|||
import com.keylesspalace.tusky.R;
|
||||
import com.keylesspalace.tusky.interfaces.StatusActionListener;
|
||||
import com.keylesspalace.tusky.util.ThemeUtils;
|
||||
import com.keylesspalace.tusky.view.RoundedTransformation;
|
||||
import com.keylesspalace.tusky.viewdata.StatusViewData;
|
||||
import com.squareup.picasso.Picasso;
|
||||
|
||||
import at.connyduck.sparkbutton.helpers.Utils;
|
||||
|
||||
public class StatusViewHolder extends StatusBaseViewHolder {
|
||||
|
@ -59,7 +59,6 @@ public class StatusViewHolder extends StatusBaseViewHolder {
|
|||
Picasso.with(context)
|
||||
.load(rebloggedUrl)
|
||||
.placeholder(R.drawable.avatar_default)
|
||||
.transform(new RoundedTransformation(25))
|
||||
.into(avatarReblog);
|
||||
} else {
|
||||
avatarReblog.setVisibility(View.GONE);
|
||||
|
|
|
@ -0,0 +1,332 @@
|
|||
package com.keylesspalace.tusky.view;
|
||||
|
||||
/*
|
||||
* Original CircleImageView Copyright 2014 - 2018 Henning Dodenhof
|
||||
* Adapted to RoundedImageView by charlag in 2018
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapShader;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.ColorFilter;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Outline;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.Shader;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.annotation.RequiresApi;
|
||||
import android.support.v7.widget.AppCompatImageView;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.view.ViewOutlineProvider;
|
||||
|
||||
public class RoundedImageView extends AppCompatImageView {
|
||||
|
||||
private static final ScaleType SCALE_TYPE = ScaleType.CENTER_CROP;
|
||||
|
||||
private static final Bitmap.Config BITMAP_CONFIG = Bitmap.Config.ARGB_8888;
|
||||
private static final int COLORDRAWABLE_DIMENSION = 2;
|
||||
|
||||
private static final int DEFAULT_BORDER_WIDTH = 0;
|
||||
private static final int DEFAULT_BORDER_COLOR = Color.BLACK;
|
||||
private static final int DEFAULT_CIRCLE_BACKGROUND_COLOR = Color.TRANSPARENT;
|
||||
private static float ROUNDED_PERCENT = 25;
|
||||
|
||||
private final RectF mDrawableRect = new RectF();
|
||||
private final RectF mBorderRect = new RectF();
|
||||
|
||||
private final Matrix mShaderMatrix = new Matrix();
|
||||
private final Paint mBitmapPaint = new Paint();
|
||||
private final Paint mBorderPaint = new Paint();
|
||||
private final Paint mCircleBackgroundPaint = new Paint();
|
||||
|
||||
private int mCircleBackgroundColor = DEFAULT_CIRCLE_BACKGROUND_COLOR;
|
||||
|
||||
private Bitmap mBitmap;
|
||||
private BitmapShader mBitmapShader;
|
||||
private int mBitmapWidth;
|
||||
private int mBitmapHeight;
|
||||
|
||||
private float mDrawableRadius;
|
||||
private float mBorderRadius;
|
||||
|
||||
private ColorFilter mColorFilter;
|
||||
|
||||
private boolean mReady;
|
||||
private boolean mSetupPending;
|
||||
|
||||
public RoundedImageView(Context context) {
|
||||
super(context);
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
public RoundedImageView(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public RoundedImageView(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
super.setScaleType(SCALE_TYPE);
|
||||
mReady = true;
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
setOutlineProvider(new OutlineProvider());
|
||||
}
|
||||
|
||||
if (mSetupPending) {
|
||||
setup();
|
||||
mSetupPending = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScaleType getScaleType() {
|
||||
return SCALE_TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setScaleType(ScaleType scaleType) {
|
||||
if (scaleType != SCALE_TYPE) {
|
||||
throw new IllegalArgumentException(String.format("ScaleType %s not supported.", scaleType));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAdjustViewBounds(boolean adjustViewBounds) {
|
||||
if (adjustViewBounds) {
|
||||
throw new IllegalArgumentException("adjustViewBounds not supported.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
|
||||
if (mBitmap == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mCircleBackgroundColor != Color.TRANSPARENT) {
|
||||
canvas.drawRoundRect(mDrawableRect, mDrawableRadius, mDrawableRadius,
|
||||
mCircleBackgroundPaint);
|
||||
}
|
||||
canvas.drawRoundRect(mDrawableRect, mDrawableRadius, mDrawableRadius, mBitmapPaint);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||
super.onSizeChanged(w, h, oldw, oldh);
|
||||
setup();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPadding(int left, int top, int right, int bottom) {
|
||||
super.setPadding(left, top, right, bottom);
|
||||
setup();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPaddingRelative(int start, int top, int end, int bottom) {
|
||||
super.setPaddingRelative(start, top, end, bottom);
|
||||
setup();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setImageBitmap(Bitmap bm) {
|
||||
super.setImageBitmap(bm);
|
||||
initializeBitmap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setImageDrawable(Drawable drawable) {
|
||||
super.setImageDrawable(drawable);
|
||||
initializeBitmap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setImageResource(@DrawableRes int resId) {
|
||||
super.setImageResource(resId);
|
||||
initializeBitmap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setImageURI(Uri uri) {
|
||||
super.setImageURI(uri);
|
||||
initializeBitmap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColorFilter(ColorFilter cf) {
|
||||
if (cf == mColorFilter) {
|
||||
return;
|
||||
}
|
||||
|
||||
mColorFilter = cf;
|
||||
applyColorFilter();
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ColorFilter getColorFilter() {
|
||||
return mColorFilter;
|
||||
}
|
||||
|
||||
private void applyColorFilter() {
|
||||
if (mBitmapPaint != null) {
|
||||
mBitmapPaint.setColorFilter(mColorFilter);
|
||||
}
|
||||
}
|
||||
|
||||
private Bitmap getBitmapFromDrawable(Drawable drawable) {
|
||||
if (drawable == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (drawable instanceof BitmapDrawable) {
|
||||
return ((BitmapDrawable) drawable).getBitmap();
|
||||
}
|
||||
|
||||
try {
|
||||
Bitmap bitmap;
|
||||
|
||||
if (drawable instanceof ColorDrawable) {
|
||||
bitmap = Bitmap.createBitmap(COLORDRAWABLE_DIMENSION, COLORDRAWABLE_DIMENSION, BITMAP_CONFIG);
|
||||
} else {
|
||||
bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), BITMAP_CONFIG);
|
||||
}
|
||||
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
|
||||
drawable.draw(canvas);
|
||||
return bitmap;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeBitmap() {
|
||||
mBitmap = getBitmapFromDrawable(getDrawable());
|
||||
setup();
|
||||
}
|
||||
|
||||
private void setup() {
|
||||
if (!mReady) {
|
||||
mSetupPending = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (getWidth() == 0 && getHeight() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mBitmap == null) {
|
||||
invalidate();
|
||||
return;
|
||||
}
|
||||
|
||||
mBitmapShader = new BitmapShader(mBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
|
||||
|
||||
mBitmapPaint.setAntiAlias(true);
|
||||
mBitmapPaint.setShader(mBitmapShader);
|
||||
|
||||
mBorderPaint.setStyle(Paint.Style.STROKE);
|
||||
mBorderPaint.setAntiAlias(true);
|
||||
mBorderPaint.setColor(DEFAULT_BORDER_COLOR);
|
||||
mBorderPaint.setStrokeWidth(DEFAULT_BORDER_WIDTH);
|
||||
|
||||
mCircleBackgroundPaint.setStyle(Paint.Style.FILL);
|
||||
mCircleBackgroundPaint.setAntiAlias(true);
|
||||
mCircleBackgroundPaint.setColor(mCircleBackgroundColor);
|
||||
|
||||
mBitmapHeight = mBitmap.getHeight();
|
||||
mBitmapWidth = mBitmap.getWidth();
|
||||
|
||||
mBorderRect.set(calculateBounds());
|
||||
|
||||
float shorterSideBorder = Math.min(mBorderRect.width(), mBorderRect.height());
|
||||
mBorderRadius = shorterSideBorder / 2 * ROUNDED_PERCENT / 100;
|
||||
|
||||
mDrawableRect.set(mBorderRect);
|
||||
|
||||
float shorterSide = Math.min(mDrawableRect.width(), mDrawableRect.height());
|
||||
mDrawableRadius = shorterSide / 2 * ROUNDED_PERCENT / 100;
|
||||
|
||||
|
||||
applyColorFilter();
|
||||
updateShaderMatrix();
|
||||
invalidate();
|
||||
}
|
||||
|
||||
private RectF calculateBounds() {
|
||||
int availableWidth = getWidth() - getPaddingLeft() - getPaddingRight();
|
||||
int availableHeight = getHeight() - getPaddingTop() - getPaddingBottom();
|
||||
|
||||
int sideLength = Math.min(availableWidth, availableHeight);
|
||||
|
||||
float left = getPaddingLeft() + (availableWidth - sideLength) / 2f;
|
||||
float top = getPaddingTop() + (availableHeight - sideLength) / 2f;
|
||||
|
||||
return new RectF(left, top, left + sideLength, top + sideLength);
|
||||
}
|
||||
|
||||
private void updateShaderMatrix() {
|
||||
float scale;
|
||||
float dx = 0;
|
||||
float dy = 0;
|
||||
|
||||
mShaderMatrix.set(null);
|
||||
|
||||
if (mBitmapWidth * mDrawableRect.height() > mDrawableRect.width() * mBitmapHeight) {
|
||||
scale = mDrawableRect.height() / (float) mBitmapHeight;
|
||||
dx = (mDrawableRect.width() - mBitmapWidth * scale) * 0.5f;
|
||||
} else {
|
||||
scale = mDrawableRect.width() / (float) mBitmapWidth;
|
||||
dy = (mDrawableRect.height() - mBitmapHeight * scale) * 0.5f;
|
||||
}
|
||||
|
||||
mShaderMatrix.setScale(scale, scale);
|
||||
mShaderMatrix.postTranslate((int) (dx + 0.5f) + mDrawableRect.left, (int) (dy + 0.5f) + mDrawableRect.top);
|
||||
|
||||
mBitmapShader.setLocalMatrix(mShaderMatrix);
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
private class OutlineProvider extends ViewOutlineProvider {
|
||||
|
||||
@Override
|
||||
public void getOutline(View view, Outline outline) {
|
||||
Rect bounds = new Rect();
|
||||
mBorderRect.roundOut(bounds);
|
||||
outline.setRoundRect(bounds, mBorderRadius);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="oval">
|
||||
android:shape="rectangle">
|
||||
<corners android:radius="10dp" />
|
||||
<solid android:color="#66000000" />
|
||||
<size
|
||||
android:width="80dp"
|
||||
|
|
|
@ -301,7 +301,7 @@
|
|||
|
||||
<include layout="@layout/item_status_bottom_sheet" />
|
||||
|
||||
<ImageView
|
||||
<com.keylesspalace.tusky.view.RoundedImageView
|
||||
android:id="@+id/accountAvatarImageView"
|
||||
android:layout_width="@dimen/account_activity_avatar_size"
|
||||
android:layout_height="@dimen/account_activity_avatar_size"
|
||||
|
@ -312,5 +312,4 @@
|
|||
app:layout_anchorGravity="top"
|
||||
app:layout_scrollFlags="scroll"
|
||||
app:srcCompat="@drawable/avatar_default" />
|
||||
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
android:layout_marginBottom="8dp"
|
||||
android:background="@android:color/transparent">
|
||||
|
||||
<ImageView
|
||||
<com.keylesspalace.tusky.view.RoundedImageView
|
||||
android:id="@+id/composeAvatar"
|
||||
android:layout_width="?attr/actionBarSize"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
|
|
|
@ -53,7 +53,7 @@
|
|||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="-40dp">
|
||||
|
||||
<com.pkmmte.view.CircularImageView
|
||||
<com.keylesspalace.tusky.view.RoundedImageView
|
||||
android:id="@+id/avatarPreview"
|
||||
android:layout_width="80dp"
|
||||
android:layout_height="80dp"
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
android:paddingLeft="16dp"
|
||||
android:paddingRight="16dp">
|
||||
|
||||
<com.pkmmte.view.CircularImageView
|
||||
<com.keylesspalace.tusky.view.RoundedImageView
|
||||
android:id="@+id/account_avatar"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
android:gravity="center_vertical"
|
||||
android:padding="8dp">
|
||||
|
||||
<ImageView
|
||||
<com.keylesspalace.tusky.view.RoundedImageView
|
||||
android:id="@+id/avatar"
|
||||
android:layout_width="42dp"
|
||||
android:layout_height="42dp"
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
android:paddingLeft="16dp"
|
||||
android:paddingRight="16dp">
|
||||
|
||||
<com.pkmmte.view.CircularImageView
|
||||
<com.keylesspalace.tusky.view.RoundedImageView
|
||||
android:id="@+id/blocked_user_avatar"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
android:textSize="?attr/status_text_medium"
|
||||
tools:text="Someone followed you" />
|
||||
|
||||
<ImageView
|
||||
<com.keylesspalace.tusky.view.RoundedImageView
|
||||
android:id="@+id/notification_avatar"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
|
@ -35,7 +35,7 @@
|
|||
android:layout_marginEnd="14dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:contentDescription="@string/action_view_profile"
|
||||
android:scaleType="fitCenter"
|
||||
android:scaleType="centerCrop"
|
||||
android:textSize="?attr/status_text_medium" />
|
||||
|
||||
<android.support.text.emoji.widget.EmojiTextView
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
android:paddingLeft="16dp"
|
||||
android:paddingRight="16dp">
|
||||
|
||||
<com.pkmmte.view.CircularImageView
|
||||
<com.keylesspalace.tusky.view.RoundedImageView
|
||||
android:id="@+id/follow_request_avatar"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
android:paddingLeft="16dp"
|
||||
android:paddingRight="16dp">
|
||||
|
||||
<com.pkmmte.view.CircularImageView
|
||||
<com.keylesspalace.tusky.view.RoundedImageView
|
||||
android:id="@+id/muted_user_avatar"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
android:textSize="?attr/status_text_medium"
|
||||
tools:text="ConnyDuck boosted" />
|
||||
|
||||
<ImageView
|
||||
<com.keylesspalace.tusky.view.RoundedImageView
|
||||
android:id="@+id/status_avatar"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
|
@ -31,10 +31,10 @@
|
|||
android:layout_marginEnd="14dp"
|
||||
android:layout_marginTop="14dp"
|
||||
android:contentDescription="@string/action_view_profile"
|
||||
android:scaleType="fitCenter"
|
||||
android:scaleType="centerCrop"
|
||||
tools:src="@drawable/avatar_default" />
|
||||
|
||||
<ImageView
|
||||
<com.keylesspalace.tusky.view.RoundedImageView
|
||||
android:id="@+id/status_avatar_reblog"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
|
|
|
@ -11,14 +11,14 @@
|
|||
android:paddingLeft="14dp"
|
||||
android:paddingRight="14dp">
|
||||
|
||||
<ImageView
|
||||
<com.keylesspalace.tusky.view.RoundedImageView
|
||||
android:id="@+id/status_avatar"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginEnd="14dp"
|
||||
android:layout_marginTop="14dp"
|
||||
android:contentDescription="@string/action_view_profile"
|
||||
android:scaleType="fitCenter"
|
||||
android:scaleType="centerCrop"
|
||||
tools:src="@drawable/avatar_default" />
|
||||
|
||||
<LinearLayout
|
||||
|
|
|
@ -115,7 +115,7 @@
|
|||
android:textSize="?attr/status_text_medium"
|
||||
tools:text="Example status here" />
|
||||
|
||||
<ImageView
|
||||
<com.keylesspalace.tusky.view.RoundedImageView
|
||||
android:id="@+id/notification_status_avatar"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
|
@ -127,7 +127,7 @@
|
|||
android:contentDescription="@string/action_view_profile"
|
||||
android:paddingBottom="12dp"
|
||||
android:paddingRight="12dp"
|
||||
android:scaleType="fitCenter"
|
||||
android:scaleType="centerCrop"
|
||||
tools:ignore="RtlHardcoded,RtlSymmetry"
|
||||
tools:src="@drawable/avatar_default" />
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
android:textSize="?attr/status_text_medium"
|
||||
tools:text="Account has moved" />
|
||||
|
||||
<ImageView
|
||||
<com.keylesspalace.tusky.view.RoundedImageView
|
||||
android:id="@+id/accountMovedAvatar"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
|
|
Loading…
Reference in a new issue