176 lines
6.6 KiB
Java
176 lines
6.6 KiB
Java
package pl.droidsonroids.gif;
|
|
|
|
import android.content.Context;
|
|
import android.content.res.Resources;
|
|
import android.graphics.drawable.Drawable;
|
|
import android.os.Build;
|
|
import android.os.Parcelable;
|
|
import android.util.AttributeSet;
|
|
import android.widget.TextView;
|
|
import java.io.IOException;
|
|
import pl.droidsonroids.gif.GifViewUtils;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public class GifTextView extends TextView {
|
|
private GifViewUtils.GifViewAttributes a;
|
|
|
|
public GifTextView(Context context) {
|
|
super(context);
|
|
}
|
|
|
|
private static void a(Drawable[] drawableArr, boolean z) {
|
|
for (Drawable drawable : drawableArr) {
|
|
if (drawable != null) {
|
|
drawable.setVisible(z, false);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void setCompoundDrawablesVisible(boolean z) {
|
|
a(getCompoundDrawables(), z);
|
|
a(getCompoundDrawablesRelative(), z);
|
|
}
|
|
|
|
@Override // android.widget.TextView, android.view.View
|
|
protected void onAttachedToWindow() {
|
|
super.onAttachedToWindow();
|
|
setCompoundDrawablesVisible(true);
|
|
}
|
|
|
|
@Override // android.view.View
|
|
protected void onDetachedFromWindow() {
|
|
super.onDetachedFromWindow();
|
|
setCompoundDrawablesVisible(false);
|
|
}
|
|
|
|
@Override // android.widget.TextView, android.view.View
|
|
public void onRestoreInstanceState(Parcelable parcelable) {
|
|
if (!(parcelable instanceof GifViewSavedState)) {
|
|
super.onRestoreInstanceState(parcelable);
|
|
return;
|
|
}
|
|
GifViewSavedState gifViewSavedState = (GifViewSavedState) parcelable;
|
|
super.onRestoreInstanceState(gifViewSavedState.getSuperState());
|
|
Drawable[] compoundDrawables = getCompoundDrawables();
|
|
gifViewSavedState.restoreState(compoundDrawables[0], 0);
|
|
gifViewSavedState.restoreState(compoundDrawables[1], 1);
|
|
gifViewSavedState.restoreState(compoundDrawables[2], 2);
|
|
gifViewSavedState.restoreState(compoundDrawables[3], 3);
|
|
Drawable[] compoundDrawablesRelative = getCompoundDrawablesRelative();
|
|
gifViewSavedState.restoreState(compoundDrawablesRelative[0], 4);
|
|
gifViewSavedState.restoreState(compoundDrawablesRelative[2], 5);
|
|
gifViewSavedState.restoreState(getBackground(), 6);
|
|
}
|
|
|
|
@Override // android.widget.TextView, android.view.View
|
|
public Parcelable onSaveInstanceState() {
|
|
Drawable[] drawableArr = new Drawable[7];
|
|
if (this.a.a) {
|
|
Drawable[] compoundDrawables = getCompoundDrawables();
|
|
System.arraycopy(compoundDrawables, 0, drawableArr, 0, compoundDrawables.length);
|
|
Drawable[] compoundDrawablesRelative = getCompoundDrawablesRelative();
|
|
drawableArr[4] = compoundDrawablesRelative[0];
|
|
drawableArr[5] = compoundDrawablesRelative[2];
|
|
drawableArr[6] = getBackground();
|
|
}
|
|
return new GifViewSavedState(super.onSaveInstanceState(), drawableArr);
|
|
}
|
|
|
|
@Override // android.view.View
|
|
public void setBackgroundResource(int i) {
|
|
setBackground(a(i));
|
|
}
|
|
|
|
@Override // android.widget.TextView
|
|
public void setCompoundDrawablesRelativeWithIntrinsicBounds(int i, int i2, int i3, int i4) {
|
|
setCompoundDrawablesRelativeWithIntrinsicBounds(a(i), a(i2), a(i3), a(i4));
|
|
}
|
|
|
|
@Override // android.widget.TextView
|
|
public void setCompoundDrawablesWithIntrinsicBounds(int i, int i2, int i3, int i4) {
|
|
setCompoundDrawablesWithIntrinsicBounds(a(i), a(i2), a(i3), a(i4));
|
|
}
|
|
|
|
public void setFreezesAnimation(boolean z) {
|
|
this.a.a = z;
|
|
}
|
|
|
|
public GifTextView(Context context, AttributeSet attributeSet) {
|
|
super(context, attributeSet);
|
|
a(attributeSet, 0, 0);
|
|
}
|
|
|
|
private void a(AttributeSet attributeSet, int i, int i2) {
|
|
if (attributeSet != null) {
|
|
Drawable a = a(attributeSet.getAttributeResourceValue("http://schemas.android.com/apk/res/android", "drawableLeft", 0));
|
|
Drawable a2 = a(attributeSet.getAttributeResourceValue("http://schemas.android.com/apk/res/android", "drawableTop", 0));
|
|
Drawable a3 = a(attributeSet.getAttributeResourceValue("http://schemas.android.com/apk/res/android", "drawableRight", 0));
|
|
Drawable a4 = a(attributeSet.getAttributeResourceValue("http://schemas.android.com/apk/res/android", "drawableBottom", 0));
|
|
Drawable a5 = a(attributeSet.getAttributeResourceValue("http://schemas.android.com/apk/res/android", "drawableStart", 0));
|
|
Drawable a6 = a(attributeSet.getAttributeResourceValue("http://schemas.android.com/apk/res/android", "drawableEnd", 0));
|
|
if (getLayoutDirection() == 0) {
|
|
if (a5 != null) {
|
|
a = a5;
|
|
}
|
|
if (a6 == null) {
|
|
a6 = a3;
|
|
}
|
|
} else {
|
|
if (a5 != null) {
|
|
a3 = a5;
|
|
}
|
|
if (a6 == null) {
|
|
a6 = a;
|
|
}
|
|
a = a3;
|
|
}
|
|
setCompoundDrawablesRelativeWithIntrinsicBounds(a, a2, a6, a4);
|
|
setBackground(a(attributeSet.getAttributeResourceValue("http://schemas.android.com/apk/res/android", "background", 0)));
|
|
this.a = new GifViewUtils.GifViewAttributes(this, attributeSet, i, i2);
|
|
a();
|
|
}
|
|
this.a = new GifViewUtils.GifViewAttributes();
|
|
}
|
|
|
|
public GifTextView(Context context, AttributeSet attributeSet, int i) {
|
|
super(context, attributeSet, i);
|
|
a(attributeSet, i, 0);
|
|
}
|
|
|
|
public GifTextView(Context context, AttributeSet attributeSet, int i, int i2) {
|
|
super(context, attributeSet, i, i2);
|
|
a(attributeSet, i, i2);
|
|
}
|
|
|
|
private void a() {
|
|
if (this.a.b < 0) {
|
|
return;
|
|
}
|
|
for (Drawable drawable : getCompoundDrawables()) {
|
|
GifViewUtils.a(this.a.b, drawable);
|
|
}
|
|
for (Drawable drawable2 : getCompoundDrawablesRelative()) {
|
|
GifViewUtils.a(this.a.b, drawable2);
|
|
}
|
|
GifViewUtils.a(this.a.b, getBackground());
|
|
}
|
|
|
|
private Drawable a(int i) {
|
|
if (i == 0) {
|
|
return null;
|
|
}
|
|
Resources resources = getResources();
|
|
String resourceTypeName = resources.getResourceTypeName(i);
|
|
if (!isInEditMode() && GifViewUtils.a.contains(resourceTypeName)) {
|
|
try {
|
|
return new GifDrawable(resources, i);
|
|
} catch (Resources.NotFoundException | IOException unused) {
|
|
}
|
|
}
|
|
if (Build.VERSION.SDK_INT >= 21) {
|
|
return resources.getDrawable(i, getContext().getTheme());
|
|
}
|
|
return resources.getDrawable(i);
|
|
}
|
|
}
|