discord-jadx/app/src/main/java/com/jaredrummler/android/colorpicker/ColorPreferenceCompat.java

152 lines
5.6 KiB
Java

package com.jaredrummler.android.colorpicker;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import androidx.annotation.ColorInt;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;
import c.d.b.a.a;
import c.k.a.a.e;
import c.k.a.a.g;
public class ColorPreferenceCompat extends Preference implements g {
public int i = -16777216;
public boolean j;
public int k;
public int l;
public boolean m;
public boolean n;
public boolean o;
public boolean p;
public int q;
public int[] r;
/* renamed from: s reason: collision with root package name */
public int f2381s;
public ColorPreferenceCompat(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
setPersistent(true);
TypedArray obtainStyledAttributes = getContext().obtainStyledAttributes(attributeSet, R.f.ColorPreference);
this.j = obtainStyledAttributes.getBoolean(R.f.ColorPreference_cpv_showDialog, true);
this.k = obtainStyledAttributes.getInt(R.f.ColorPreference_cpv_dialogType, 1);
this.l = obtainStyledAttributes.getInt(R.f.ColorPreference_cpv_colorShape, 1);
this.m = obtainStyledAttributes.getBoolean(R.f.ColorPreference_cpv_allowPresets, true);
this.n = obtainStyledAttributes.getBoolean(R.f.ColorPreference_cpv_allowCustom, true);
this.o = obtainStyledAttributes.getBoolean(R.f.ColorPreference_cpv_showAlphaSlider, false);
this.p = obtainStyledAttributes.getBoolean(R.f.ColorPreference_cpv_showColorShades, true);
this.q = obtainStyledAttributes.getInt(R.f.ColorPreference_cpv_previewSize, 0);
int resourceId = obtainStyledAttributes.getResourceId(R.f.ColorPreference_cpv_colorPresets, 0);
this.f2381s = obtainStyledAttributes.getResourceId(R.f.ColorPreference_cpv_dialogTitle, R.e.cpv_default_title);
if (resourceId != 0) {
this.r = getContext().getResources().getIntArray(resourceId);
} else {
this.r = e.i;
}
if (this.l == 1) {
setWidgetLayoutResource(this.q == 1 ? R.d.cpv_preference_circle_large : R.d.cpv_preference_circle);
} else {
setWidgetLayoutResource(this.q == 1 ? R.d.cpv_preference_square_large : R.d.cpv_preference_square);
}
obtainStyledAttributes.recycle();
}
public FragmentActivity f() {
Context context = getContext();
if (context instanceof FragmentActivity) {
return (FragmentActivity) context;
}
if (context instanceof ContextWrapper) {
Context baseContext = ((ContextWrapper) context).getBaseContext();
if (baseContext instanceof FragmentActivity) {
return (FragmentActivity) baseContext;
}
}
throw new IllegalStateException("Error getting activity from context");
}
@Override // androidx.preference.Preference
public void onAttached() {
super.onAttached();
if (this.j) {
FragmentManager supportFragmentManager = f().getSupportFragmentManager();
StringBuilder L = a.L("color_");
L.append(getKey());
e eVar = (e) supportFragmentManager.findFragmentByTag(L.toString());
if (eVar != null) {
eVar.j = this;
}
}
}
@Override // androidx.preference.Preference
public void onBindViewHolder(PreferenceViewHolder preferenceViewHolder) {
super.onBindViewHolder(preferenceViewHolder);
ColorPanelView colorPanelView = (ColorPanelView) preferenceViewHolder.itemView.findViewById(R.c.cpv_preference_preview_color_panel);
if (colorPanelView != null) {
colorPanelView.setColor(this.i);
}
}
@Override // androidx.preference.Preference
public void onClick() {
super.onClick();
if (this.j) {
int[] iArr = e.i;
e.k kVar = new e.k();
kVar.f = this.k;
kVar.a = this.f2381s;
kVar.n = this.l;
kVar.g = this.r;
kVar.j = this.m;
kVar.k = this.n;
kVar.i = this.o;
kVar.m = this.p;
kVar.h = this.i;
e a = kVar.a();
a.j = this;
FragmentTransaction beginTransaction = f().getSupportFragmentManager().beginTransaction();
StringBuilder L = a.L("color_");
L.append(getKey());
beginTransaction.add(a, L.toString()).commitAllowingStateLoss();
}
}
@Override // c.k.a.a.g
public void onColorReset(int i) {
}
@Override // c.k.a.a.g
public void onColorSelected(int i, @ColorInt int i2) {
this.i = i2;
persistInt(i2);
notifyChanged();
callChangeListener(Integer.valueOf(i2));
}
@Override // c.k.a.a.g
public void onDialogDismissed(int i) {
}
@Override // androidx.preference.Preference
public Object onGetDefaultValue(TypedArray typedArray, int i) {
return Integer.valueOf(typedArray.getInteger(i, -16777216));
}
@Override // androidx.preference.Preference
public void onSetInitialValue(Object obj) {
super.onSetInitialValue(obj);
if (obj instanceof Integer) {
int intValue = ((Integer) obj).intValue();
this.i = intValue;
persistInt(intValue);
return;
}
this.i = getPersistedInt(-16777216);
}
}