Fixed other square images

This commit is contained in:
ByteHamster 2020-02-12 13:38:18 +01:00
parent 0485102797
commit fe632a4f9f
4 changed files with 29 additions and 8 deletions

View File

@ -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);
}

View File

@ -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" />
<TextView
android:id="@+id/txtvPodcastTitle"

View File

@ -117,7 +117,7 @@
android:layout_marginRight="16dp"
android:layout_marginEnd="16dp"
android:layout_centerHorizontal="true"
android:background="?attr/selectableItemBackground"
android:background="?attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/pause_label"
android:src="?attr/av_play"
android:scaleType="fitCenter"
@ -132,7 +132,7 @@
android:layout_toStartOf="@id/butPlay"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:background="?attr/selectableItemBackground"
android:background="?attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/rewind_label"
android:src="?attr/av_rew_big"
android:scaleType="fitCenter"
@ -161,7 +161,7 @@
android:layout_height="@dimen/audioplayer_playercontrols_length"
android:layout_toLeftOf="@id/butRev"
android:layout_toStartOf="@id/butRev"
android:background="?attr/selectableItemBackground"
android:background="?attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/set_playback_speed_label"
android:src="?attr/av_speed"
android:scaleType="fitCenter"
@ -191,7 +191,7 @@
android:layout_height="@dimen/audioplayer_playercontrols_length"
android:layout_toLeftOf="@id/butRev"
android:layout_toStartOf="@id/butRev"
android:background="?attr/selectableItemBackground"
android:background="?attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/cast_disconnect_label"
android:src="?attr/ic_cast_disconnect"
android:scaleType="fitCenter"
@ -208,7 +208,7 @@
android:layout_toEndOf="@id/butPlay"
android:layout_marginRight="16dp"
android:layout_marginEnd="16dp"
android:background="?attr/selectableItemBackground"
android:background="?attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/fast_forward_label"
android:src="?attr/av_ff_big"
android:scaleType="fitCenter"
@ -237,7 +237,7 @@
android:layout_height="@dimen/audioplayer_playercontrols_length"
android:layout_toRightOf="@id/butFF"
android:layout_toEndOf="@id/butFF"
android:background="?attr/selectableItemBackground"
android:background="?attr/selectableItemBackgroundBorderless"
android:scaleType="fitCenter"
android:src="?attr/av_skip_big"
android:contentDescription="@string/skip_episode_label"

View File

@ -77,4 +77,8 @@
<attr name="about_screen_card_border" format="color"/>
<attr name="about_screen_font_color" format="color"/>
<attr name="batch_edit_fab_icon" format="reference"/>
<declare-styleable name="SquareImageView">
<attr name="useMinimum" format="boolean" />
</declare-styleable>
</resources>