mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-12-23 05:16:58 +00:00
Fix Animatable drawable class cast issue on sdk lower than 24. Fixes https://github.com/austinhuang0131/barinsta/issues/794
This commit is contained in:
parent
6d73528387
commit
cc8f14b562
@ -30,7 +30,6 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MediatorLiveData;
|
||||
@ -1204,7 +1203,7 @@ public class DirectMessageThreadFragment extends Fragment implements DirectReact
|
||||
private void setSendToMicIcon() {
|
||||
final Context context = getContext();
|
||||
if (context == null) return;
|
||||
final Drawable sendToMicDrawable = ContextCompat.getDrawable(context, R.drawable.avd_send_to_mic_anim);
|
||||
final Drawable sendToMicDrawable = Utils.getAnimatableDrawable(context, R.drawable.avd_send_to_mic_anim);
|
||||
if (sendToMicDrawable instanceof Animatable) {
|
||||
AnimatedVectorDrawableCompat.registerAnimationCallback(sendToMicDrawable, sendToMicAnimationCallback);
|
||||
}
|
||||
@ -1214,7 +1213,7 @@ public class DirectMessageThreadFragment extends Fragment implements DirectReact
|
||||
private void setMicToSendIcon() {
|
||||
final Context context = getContext();
|
||||
if (context == null) return;
|
||||
final Drawable micToSendDrawable = ContextCompat.getDrawable(context, R.drawable.avd_mic_to_send_anim);
|
||||
final Drawable micToSendDrawable = Utils.getAnimatableDrawable(context, R.drawable.avd_mic_to_send_anim);
|
||||
if (micToSendDrawable instanceof Animatable) {
|
||||
AnimatedVectorDrawableCompat.registerAnimationCallback(micToSendDrawable, micToSendAnimationCallback);
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.media.MediaScannerConnection;
|
||||
import android.media.MediaScannerConnection.OnScanCompletedListener;
|
||||
import android.net.Uri;
|
||||
@ -28,10 +29,13 @@ import android.view.inputmethod.InputMethodManager;
|
||||
import android.webkit.MimeTypeMap;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat;
|
||||
|
||||
import com.google.android.exoplayer2.database.ExoDatabaseProvider;
|
||||
import com.google.android.exoplayer2.upstream.cache.LeastRecentlyUsedCacheEvictor;
|
||||
@ -347,4 +351,15 @@ public final class Utils {
|
||||
Log.e(TAG, "hideKeyboard: ", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static Drawable getAnimatableDrawable(@NonNull final Context context,
|
||||
@DrawableRes final int drawableResId) {
|
||||
final Drawable drawable;
|
||||
if (Build.VERSION.SDK_INT >= 24) {
|
||||
drawable = ContextCompat.getDrawable(context, drawableResId);
|
||||
} else {
|
||||
drawable = AnimatedVectorDrawableCompat.create(context, drawableResId);
|
||||
}
|
||||
return drawable;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user