From fe632a4f9f5dd5aa9ed8e54f42aa1496ce08f480 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Wed, 12 Feb 2020 13:38:18 +0100 Subject: [PATCH] Fixed other square images --- .../danoeh/antennapod/view/SquareImageView.java | 17 ++++++++++++++++- app/src/main/res/layout/cover_fragment.xml | 4 +++- .../res/layout/mediaplayerinfo_activity.xml | 12 ++++++------ core/src/main/res/values/attrs.xml | 4 ++++ 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/de/danoeh/antennapod/view/SquareImageView.java b/app/src/main/java/de/danoeh/antennapod/view/SquareImageView.java index 439f80b97..6c9a12f43 100644 --- a/app/src/main/java/de/danoeh/antennapod/view/SquareImageView.java +++ b/app/src/main/java/de/danoeh/antennapod/view/SquareImageView.java @@ -1,13 +1,16 @@ package de.danoeh.antennapod.view; import android.content.Context; +import android.content.res.TypedArray; import androidx.appcompat.widget.AppCompatImageView; import android.util.AttributeSet; +import de.danoeh.antennapod.core.R; /** * From http://stackoverflow.com/a/19449488/6839 */ public class SquareImageView extends AppCompatImageView { + private boolean useMinimum = false; public SquareImageView(Context context) { super(context); @@ -15,17 +18,29 @@ public class SquareImageView extends AppCompatImageView { public SquareImageView(Context context, AttributeSet attrs) { super(context, attrs); + loadAttrs(context, attrs); } public SquareImageView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); + loadAttrs(context, attrs); + } + + private void loadAttrs(Context context, AttributeSet attrs) { + TypedArray a = context.getTheme().obtainStyledAttributes(attrs, + new int[]{R.styleable.SquareImageView_useMinimum}, 0, 0); + useMinimum = a.getBoolean(0, false); + a.recycle(); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); - int size = Math.min(getMeasuredWidth(), getMeasuredHeight()); + int size = getMeasuredWidth(); + if (useMinimum) { + size = Math.min(getMeasuredWidth(), getMeasuredHeight()); + } setMeasuredDimension(size, size); } diff --git a/app/src/main/res/layout/cover_fragment.xml b/app/src/main/res/layout/cover_fragment.xml index f73562245..c5fedd07a 100644 --- a/app/src/main/res/layout/cover_fragment.xml +++ b/app/src/main/res/layout/cover_fragment.xml @@ -3,6 +3,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" + xmlns:squareImageView="http://schemas.android.com/apk/res-auto" android:orientation="vertical" android:padding="8dp" android:gravity="center"> @@ -18,7 +19,8 @@ android:layout_marginRight="32dp" android:transitionName="coverTransition" tools:src="@android:drawable/sym_def_app_icon" - android:foreground="?attr/selectableItemBackgroundBorderless"/> + android:foreground="?attr/selectableItemBackgroundBorderless" + squareImageView:useMinimum="true" /> + + + +