Files
lineage-sdk/packages/LineagePreferenceLib/java/lineageos/preference/SelfRemovingPreference.java
rmp22 6b4867d982 [BUGFIX] SelfRemovingPreference: set visibility at early stage
Change-Id: Ic23c4a78fa424b045d8f38b6b799339570a6fda0
Signed-off-by: rmp22 <195054967+rmp22@users.noreply.github.com>
2025-11-26 17:48:34 +09:00

62 lines
1.7 KiB
Java

/*
* SPDX-FileCopyrightText: 2016 The CyanogenMod project
* SPDX-License-Identifier: Apache-2.0
*/
package lineageos.preference;
import android.content.Context;
import android.util.AttributeSet;
import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;
/**
* A Preference which can automatically remove itself from the hierarchy
* based on constraints set in XML.
*/
public class SelfRemovingPreference extends Preference {
private final ConstraintsHelper mConstraints;
public SelfRemovingPreference(Context context, AttributeSet attrs,
int defStyle, int defStyleRes) {
super(context, attrs, defStyle, defStyleRes);
mConstraints = new ConstraintsHelper(context, attrs, this);
setVisible(mConstraints.isAvailable());
}
public SelfRemovingPreference(Context context, AttributeSet attrs, int defStyle) {
this(context, attrs, defStyle, 0);
}
public SelfRemovingPreference(Context context, AttributeSet attrs) {
this(context, attrs, ConstraintsHelper.getAttr(context,
androidx.preference.R.attr.preferenceStyle,
android.R.attr.preferenceStyle));
}
public SelfRemovingPreference(Context context) {
this(context, null);
}
@Override
public void onAttached() {
super.onAttached();
mConstraints.onAttached();
}
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
mConstraints.onBindViewHolder(holder);
}
public void setAvailable(boolean available) {
mConstraints.setAvailable(available);
}
public boolean isAvailable() {
return mConstraints.isAvailable();
}
}