Files
lineage-sdk/packages/LineagePreferenceLib/java/lineageos/preference/LineagePartsPreference.java
Michael Bestas 38be42ce0a sdk: Cleanup imports
find . -name "*.java" | xargs java -jar \
~/bin/google-java-format-1.25.2-all-deps.jar \
--aosp --fix-imports-only --replace

Change-Id: If39579285c13cecdb3592d8ccf0605b8030b340e
2025-03-23 12:06:59 +02:00

71 lines
2.0 KiB
Java

/*
* SPDX-FileCopyrightText: 2016 The CyanogenMod Project
* SPDX-License-Identifier: Apache-2.0
*/
package lineageos.preference;
import android.content.Context;
import android.os.Bundle;
import android.util.AttributeSet;
/**
* A link to a remote preference screen which can be used with a minimum amount
* of information. Supports summary updates asynchronously.
*/
public class LineagePartsPreference extends RemotePreference {
private static final String TAG = "LineagePartsPreference";
private final PartInfo mPart;
private final Context mContext;
public LineagePartsPreference(Context context, AttributeSet attrs,
int defStyle, int defStyleRes) {
super(context, attrs, defStyle, defStyleRes);
mContext = context;
mPart = PartsList.get(context).getPartInfo(getKey());
if (mPart == null) {
throw new RuntimeException("Part not found: " + getKey());
}
updatePreference();
setIntent(mPart.getIntentForActivity());
}
public LineagePartsPreference(Context context, AttributeSet attrs, int defStyle) {
this(context, attrs, defStyle, 0);
}
public LineagePartsPreference(Context context, AttributeSet attrs) {
this(context, attrs, androidx.preference.R.attr.preferenceStyle);
}
@Override
public void onRemoteUpdated(Bundle bundle) {
if (bundle.containsKey(PartsList.EXTRA_PART)) {
PartInfo update = bundle.getParcelable(PartsList.EXTRA_PART);
if (update != null) {
mPart.updateFrom(update);
updatePreference();
}
}
}
@Override
protected String getRemoteKey(Bundle metaData) {
// remote key is the same as ours
return getKey();
}
private void updatePreference() {
if (isAvailable() != mPart.isAvailable()) {
setAvailable(mPart.isAvailable());
}
if (isAvailable()) {
setTitle(mPart.getTitle());
setSummary(mPart.getSummary());
}
}
}