Add a Builder to to creat a dynamic FooterPreference easily
Fixes: 139163212 Test: compilation Change-Id: I09c455770d1de5b30cfba55fbd9f23c95fef39cd
This commit is contained in:
@@ -16,12 +16,14 @@
|
||||
|
||||
package com.android.settingslib.widget;
|
||||
|
||||
import android.annotation.StringRes;
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.content.res.TypedArrayUtils;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
@@ -80,4 +82,59 @@ public class FooterPreference extends Preference {
|
||||
setKey(KEY_FOOTER);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The builder is convenient to creat a dynamic FooterPreference.
|
||||
*/
|
||||
public static class Builder {
|
||||
private Context mContext;
|
||||
private String mKey;
|
||||
private CharSequence mTitle;
|
||||
|
||||
public Builder(@NonNull Context context) {
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
/**
|
||||
* To set the key value of the {@link FooterPreference}.
|
||||
* @param key The key value.
|
||||
*/
|
||||
public Builder setKey(String key) {
|
||||
mKey = key;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* To set the title of the {@link FooterPreference}.
|
||||
* @param title The title.
|
||||
*/
|
||||
public Builder setTitle(CharSequence title) {
|
||||
mTitle = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* To set the title of the {@link FooterPreference}.
|
||||
* @param titleResId The resource id of the title.
|
||||
*/
|
||||
public Builder setTitle(@StringRes int titleResId) {
|
||||
mTitle = mContext.getText(titleResId);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* To generate the {@link FooterPreference}.
|
||||
*/
|
||||
public FooterPreference build() {
|
||||
final FooterPreference footerPreference = new FooterPreference(mContext);
|
||||
footerPreference.setSelectable(false);
|
||||
if (!TextUtils.isEmpty(mKey)) {
|
||||
footerPreference.setKey(mKey);
|
||||
}
|
||||
if (!TextUtils.isEmpty(mTitle)) {
|
||||
footerPreference.setTitle(mTitle);
|
||||
}
|
||||
return footerPreference;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user