69 lines
2.2 KiB
Java
69 lines
2.2 KiB
Java
package com.twitter.sdk.android.tweetui;
|
|
|
|
import android.content.Context;
|
|
import android.content.res.TypedArray;
|
|
import android.util.AttributeSet;
|
|
import android.widget.ImageButton;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class ToggleImageButton extends ImageButton {
|
|
private static final int[] e = {R$attr.state_toggled_on};
|
|
boolean a;
|
|
String b;
|
|
String c;
|
|
final boolean d;
|
|
|
|
public ToggleImageButton(Context context) {
|
|
this(context, null);
|
|
}
|
|
|
|
public void a() {
|
|
setToggledOn(!this.a);
|
|
}
|
|
|
|
@Override // android.widget.ImageView, android.view.View
|
|
public int[] onCreateDrawableState(int i) {
|
|
int[] onCreateDrawableState = super.onCreateDrawableState(i + 2);
|
|
if (this.a) {
|
|
ImageButton.mergeDrawableStates(onCreateDrawableState, e);
|
|
}
|
|
return onCreateDrawableState;
|
|
}
|
|
|
|
@Override // android.view.View
|
|
public boolean performClick() {
|
|
if (this.d) {
|
|
a();
|
|
}
|
|
return super.performClick();
|
|
}
|
|
|
|
public void setToggledOn(boolean z) {
|
|
this.a = z;
|
|
setContentDescription(z ? this.b : this.c);
|
|
refreshDrawableState();
|
|
}
|
|
|
|
public ToggleImageButton(Context context, AttributeSet attributeSet) {
|
|
this(context, attributeSet, 0);
|
|
}
|
|
|
|
public ToggleImageButton(Context context, AttributeSet attributeSet, int i) {
|
|
super(context, attributeSet, i);
|
|
TypedArray typedArray = null;
|
|
try {
|
|
typedArray = context.getTheme().obtainStyledAttributes(attributeSet, R$styleable.ToggleImageButton, i, 0);
|
|
String string = typedArray.getString(R$styleable.ToggleImageButton_contentDescriptionOn);
|
|
String string2 = typedArray.getString(R$styleable.ToggleImageButton_contentDescriptionOff);
|
|
this.b = string == null ? (String) getContentDescription() : string;
|
|
this.c = string2 == null ? (String) getContentDescription() : string2;
|
|
this.d = typedArray.getBoolean(R$styleable.ToggleImageButton_toggleOnClick, true);
|
|
setToggledOn(false);
|
|
} finally {
|
|
if (typedArray != null) {
|
|
typedArray.recycle();
|
|
}
|
|
}
|
|
}
|
|
}
|