Use VectorDrawable compat library

This commit is contained in:
ByteHamster 2021-04-15 21:21:31 +02:00
parent 5c81631843
commit d51e9c7625
12 changed files with 31 additions and 36 deletions

View File

@ -3,10 +3,9 @@ package de.danoeh.antennapod.adapter;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import android.util.TypedValue; import android.util.TypedValue;
@ -109,10 +108,10 @@ public class NavListAdapter extends RecyclerView.Adapter<NavListAdapter.Holder>
return titles[index]; return titles[index];
} }
private Drawable getDrawable(String tag) { private @DrawableRes int getDrawable(String tag) {
Activity context = activity.get(); Activity context = activity.get();
if (context == null) { if (context == null) {
return null; return 0;
} }
int icon; int icon;
switch (tag) { switch (tag) {
@ -135,12 +134,9 @@ public class NavListAdapter extends RecyclerView.Adapter<NavListAdapter.Holder>
icon = R.attr.content_new; icon = R.attr.content_new;
break; break;
default: default:
return null; return 0;
} }
TypedArray ta = context.obtainStyledAttributes(new int[] { icon }); return ThemeUtils.getDrawableFromAttr(context, icon);
Drawable result = ta.getDrawable(0);
ta.recycle();
return result;
} }
public List<String> getFragmentTags() { public List<String> getFragmentTags() {
@ -283,7 +279,7 @@ public class NavListAdapter extends RecyclerView.Adapter<NavListAdapter.Holder>
} }
} }
holder.image.setImageDrawable(getDrawable(fragmentTags.get(position))); holder.image.setImageResource(getDrawable(fragmentTags.get(position)));
} }
private void bindSectionDivider(DividerHolder holder) { private void bindSectionDivider(DividerHolder holder) {

View File

@ -1,7 +1,6 @@
package de.danoeh.antennapod.adapter.actionbutton; package de.danoeh.antennapod.adapter.actionbutton;
import android.content.Context; import android.content.Context;
import android.content.res.TypedArray;
import android.widget.ImageView; import android.widget.ImageView;
import androidx.annotation.AttrRes; import androidx.annotation.AttrRes;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -12,6 +11,7 @@ import de.danoeh.antennapod.core.feed.FeedItem;
import de.danoeh.antennapod.core.feed.FeedMedia; import de.danoeh.antennapod.core.feed.FeedMedia;
import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.storage.DownloadRequester; import de.danoeh.antennapod.core.storage.DownloadRequester;
import de.danoeh.antennapod.ui.common.ThemeUtils;
public abstract class ItemActionButton { public abstract class ItemActionButton {
FeedItem item; FeedItem item;
@ -62,9 +62,6 @@ public abstract class ItemActionButton {
button.setVisibility(getVisibility()); button.setVisibility(getVisibility());
button.setContentDescription(context.getString(getLabel())); button.setContentDescription(context.getString(getLabel()));
button.setOnClickListener((view) -> onClick(context)); button.setOnClickListener((view) -> onClick(context));
icon.setImageResource(ThemeUtils.getDrawableFromAttr(context, getDrawable()));
TypedArray drawables = context.obtainStyledAttributes(new int[]{getDrawable()});
icon.setImageDrawable(drawables.getDrawable(0));
drawables.recycle();
} }
} }

View File

@ -2,15 +2,12 @@ package de.danoeh.antennapod.view;
import android.content.Context; import android.content.Context;
import android.database.DataSetObserver; import android.database.DataSetObserver;
import android.graphics.drawable.Drawable;
import android.view.Gravity; import android.view.Gravity;
import android.widget.AbsListView; import android.widget.AbsListView;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.ListAdapter; import android.widget.ListAdapter;
import androidx.annotation.AttrRes; import androidx.annotation.AttrRes;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import android.util.TypedValue;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView; import android.widget.ImageView;
@ -18,6 +15,7 @@ import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
import de.danoeh.antennapod.R; import de.danoeh.antennapod.R;
import de.danoeh.antennapod.ui.common.ThemeUtils;
public class EmptyViewHandler { public class EmptyViewHandler {
private boolean layoutAdded = false; private boolean layoutAdded = false;
@ -52,10 +50,7 @@ public class EmptyViewHandler {
} }
public void setIcon(@AttrRes int iconAttr) { public void setIcon(@AttrRes int iconAttr) {
TypedValue typedValue = new TypedValue(); ivIcon.setImageResource(ThemeUtils.getDrawableFromAttr(context, iconAttr));
context.getTheme().resolveAttribute(iconAttr, typedValue, true);
Drawable d = ContextCompat.getDrawable(context, typedValue.resourceId);
ivIcon.setImageDrawable(d);
ivIcon.setVisibility(View.VISIBLE); ivIcon.setVisibility(View.VISIBLE);
} }

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical" android:orientation="vertical"
@ -15,7 +16,7 @@
android:id="@+id/widget_config_background" android:id="@+id/widget_config_background"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:src="@drawable/teaser" app:srcCompat="@drawable/teaser"
android:scaleType="centerCrop" /> android:scaleType="centerCrop" />
<include <include

View File

@ -47,7 +47,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="8dp" android:layout_height="8dp"
android:layout_alignBottom="@id/pager" android:layout_alignBottom="@id/pager"
android:src="@drawable/bg_gradient" app:srcCompat="@drawable/bg_gradient"
app:tint="?android:attr/windowBackground" app:tint="?android:attr/windowBackground"
android:importantForAccessibility="no"/> android:importantForAccessibility="no"/>

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical" android:orientation="vertical"
@ -32,7 +33,7 @@
<ImageButton <ImageButton
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:src="?attr/content_new" app:srcCompat="?attr/content_new"
android:contentDescription="@string/new_label" android:contentDescription="@string/new_label"
android:id="@+id/newTagButton"/> android:id="@+id/newTagButton"/>
</LinearLayout> </LinearLayout>

View File

@ -35,7 +35,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:importantForAccessibility="no" android:importantForAccessibility="no"
android:scaleType="fitCenter" android:scaleType="fitCenter"
android:src="?attr/dragview_background" app:srcCompat="?attr/dragview_background"
android:paddingStart="0dp" android:paddingStart="0dp"
android:paddingLeft="0dp" android:paddingLeft="0dp"
android:paddingEnd="4dp" android:paddingEnd="4dp"

View File

@ -2,6 +2,7 @@
<LinearLayout <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical">
@ -15,7 +16,7 @@
<ImageView <ImageView
android:layout_width="64dp" android:layout_width="64dp"
android:layout_height="64dp" android:layout_height="64dp"
android:src="@drawable/gpodder_icon"/> app:srcCompat="@drawable/gpodder_icon"/>
<TextView <TextView
android:id="@+id/createAccountButton" android:id="@+id/createAccountButton"

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical">
@ -9,7 +10,7 @@
android:id="@id/icon" android:id="@id/icon"
android:layout_width="64dp" android:layout_width="64dp"
android:layout_height="64dp" android:layout_height="64dp"
android:src="@drawable/gpodder_icon" /> app:srcCompat="@drawable/gpodder_icon" />
<TextView <TextView
android:id="@+id/txtvDescription" android:id="@+id/txtvDescription"

View File

@ -1,6 +1,7 @@
<?xml version='1.0' encoding='utf-8'?> <?xml version='1.0' encoding='utf-8'?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/nav_layout" android:id="@+id/nav_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
@ -18,7 +19,6 @@
android:focusable="true"> android:focusable="true">
<ImageView <ImageView
android:id="@+id/imgvCover"
android:layout_width="@dimen/thumbnail_length_navlist" android:layout_width="@dimen/thumbnail_length_navlist"
android:layout_height="@dimen/thumbnail_length_navlist" android:layout_height="@dimen/thumbnail_length_navlist"
android:layout_marginBottom="4dp" android:layout_marginBottom="4dp"
@ -30,7 +30,7 @@
android:cropToPadding="true" android:cropToPadding="true"
android:padding="8dp" android:padding="8dp"
android:scaleType="centerCrop" android:scaleType="centerCrop"
android:src="?attr/ic_settings" app:srcCompat="?attr/ic_settings"
tools:background="@android:color/holo_orange_dark" tools:background="@android:color/holo_orange_dark"
tools:src="@android:drawable/sym_def_app_icon" /> tools:src="@android:drawable/sym_def_app_icon" />

View File

@ -8,6 +8,8 @@ android {
targetSdkVersion rootProject.ext.targetSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion
multiDexEnabled false multiDexEnabled false
vectorDrawables.useSupportLibrary true
vectorDrawables.generatedDensities = []
testApplicationId "de.danoeh.antennapod.core.tests" testApplicationId "de.danoeh.antennapod.core.tests"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
@ -23,7 +24,7 @@
android:background="?android:attr/selectableItemBackground" android:background="?android:attr/selectableItemBackground"
android:scaleType="fitCenter" android:scaleType="fitCenter"
android:padding="8dp" android:padding="8dp"
android:src="@drawable/ic_av_play_white_24dp" /> app:srcCompat="@drawable/ic_av_play_white_24dp" />
<LinearLayout <LinearLayout
android:id="@+id/layout_left" android:id="@+id/layout_left"
@ -41,7 +42,7 @@
android:id="@+id/imgvCover" android:id="@+id/imgvCover"
android:layout_width="@android:dimen/app_icon_size" android:layout_width="@android:dimen/app_icon_size"
android:layout_height="match_parent" android:layout_height="match_parent"
android:src="@mipmap/ic_launcher_round" app:srcCompat="@mipmap/ic_launcher_round"
android:importantForAccessibility="no" android:importantForAccessibility="no"
android:layout_margin="12dp" /> android:layout_margin="12dp" />
@ -98,7 +99,7 @@
android:layout_marginRight="2dp" android:layout_marginRight="2dp"
android:layout_marginEnd="2dp" android:layout_marginEnd="2dp"
android:scaleType="fitXY" android:scaleType="fitXY"
android:src="@drawable/ic_av_fast_rewind_white_48dp"/> app:srcCompat="@drawable/ic_av_fast_rewind_white_48dp"/>
<ImageButton <ImageButton
android:id="@+id/butPlayExtended" android:id="@+id/butPlayExtended"
@ -109,7 +110,7 @@
android:layout_marginRight="2dp" android:layout_marginRight="2dp"
android:layout_marginEnd="2dp" android:layout_marginEnd="2dp"
android:scaleType="fitXY" android:scaleType="fitXY"
android:src="@drawable/ic_av_play_white_48dp"/> app:srcCompat="@drawable/ic_av_play_white_48dp"/>
<ImageButton <ImageButton
android:id="@+id/butFastForward" android:id="@+id/butFastForward"
@ -120,7 +121,7 @@
android:layout_marginRight="2dp" android:layout_marginRight="2dp"
android:layout_marginEnd="2dp" android:layout_marginEnd="2dp"
android:scaleType="fitXY" android:scaleType="fitXY"
android:src="@drawable/ic_av_fast_forward_white_48dp"/> app:srcCompat="@drawable/ic_av_fast_forward_white_48dp"/>
<ImageButton <ImageButton
android:id="@+id/butSkip" android:id="@+id/butSkip"
@ -131,7 +132,7 @@
android:layout_marginRight="2dp" android:layout_marginRight="2dp"
android:layout_marginEnd="2dp" android:layout_marginEnd="2dp"
android:scaleType="fitXY" android:scaleType="fitXY"
android:src="@drawable/ic_av_skip_white_24dp"/> app:srcCompat="@drawable/ic_av_skip_white_24dp"/>
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>