androidx.core.content.res.TypedArrayUtils Java Examples

The following examples show how to use androidx.core.content.res.TypedArrayUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpUriPreference.java    From FCM-for-Mojo with GNU General Public License v3.0 6 votes vote down vote up
public HttpUriPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);
    TypedArray a;

    a = context.obtainStyledAttributes(attrs, R.styleable.HttpUriPreference);
    mSummaryWhenAuthorizationSet = a.getString(R.styleable.HttpUriPreference_summaryWhenAuthorizationSet);
    keyUsername = a.getString(R.styleable.HttpUriPreference_keyHttpUsername);
    keyPassword = a.getString(R.styleable.HttpUriPreference_keyHttpPassword);
    a.recycle();

    a = context.obtainStyledAttributes(attrs,
            R.styleable.Preference, defStyleAttr, defStyleRes);
    mSummary = TypedArrayUtils.getString(a, R.styleable.Preference_summary,
            R.styleable.Preference_android_summary);
    a.recycle();

    setDialogLayoutResource(R.layout.dialog_http_uri_preference);

}
 
Example #2
Source File: NumberPickerPreference.java    From MaterialPreference with Apache License 2.0 6 votes vote down vote up
@SuppressLint("RestrictedApi")
public NumberPickerPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    mNumberPicker = new NumberPicker(context);

    TypedArray a;
    a = context.obtainStyledAttributes(attrs, R.styleable.NumberPickerPreference);
    mNumberPicker.setMinValue(a.getInt(R.styleable.NumberPickerPreference_min, 0));
    mNumberPicker.setMaxValue(a.getInt(R.styleable.NumberPickerPreference_max, 100));

    a = context.obtainStyledAttributes(attrs,
            R.styleable.Preference, defStyleAttr, defStyleRes);

    mSummary = TypedArrayUtils.getString(a, R.styleable.Preference_summary,
            R.styleable.Preference_android_summary);

    a.recycle();
}
 
Example #3
Source File: RingtonePreference.java    From MaterialPreference with Apache License 2.0 6 votes vote down vote up
public RingtonePreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    TypedArray a = context.obtainStyledAttributes(
            attrs, R.styleable.RingtonePreference, defStyleAttr, defStyleRes);

    mRingtoneType = TypedArrayUtils.getInt(a, R.styleable.RingtonePreference_ringtoneType,
            R.styleable.RingtonePreference_android_ringtoneType, RingtoneManager.TYPE_RINGTONE);
    mShowDefault = TypedArrayUtils.getBoolean(a, R.styleable.RingtonePreference_showDefault,
            R.styleable.RingtonePreference_android_showDefault, true);
    mShowSilent = TypedArrayUtils.getBoolean(a, R.styleable.RingtonePreference_showSilent,
            R.styleable.RingtonePreference_android_showSilent, true);
    mSummaryNone = a.getString(R.styleable.RingtonePreference_summaryNone);
    a.recycle();

    /* Retrieve the Preference summary attribute since it's private
     * in the Preference class.
     */
    a = context.obtainStyledAttributes(attrs,
            R.styleable.Preference, defStyleAttr, defStyleRes);

    mSummary = TypedArrayUtils.getString(a, R.styleable.Preference_summary,
            R.styleable.Preference_android_summary);

    a.recycle();
}
 
Example #4
Source File: MultiSelectListPreference.java    From MaterialPreference with Apache License 2.0 6 votes vote down vote up
@SuppressLint("RestrictedApi")
public MultiSelectListPreference(
        Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    final TypedArray a = context.obtainStyledAttributes(attrs,
            R.styleable.MultiSelectListPreference, defStyleAttr,
            defStyleRes);

    mEntries = TypedArrayUtils.getTextArray(a,
            R.styleable.MultiSelectListPreference_entries,
            R.styleable.MultiSelectListPreference_android_entries);

    mEntryValues = TypedArrayUtils.getTextArray(a,
            R.styleable.MultiSelectListPreference_entryValues,
            R.styleable.MultiSelectListPreference_android_entryValues);

    a.recycle();
}
 
Example #5
Source File: CheckBoxPreference.java    From MaterialPreference with Apache License 2.0 6 votes vote down vote up
@SuppressLint("RestrictedApi")
public CheckBoxPreference(
        Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    final TypedArray a = context.obtainStyledAttributes(attrs,
            R.styleable.CheckBoxPreference, defStyleAttr, defStyleRes);

    setSummaryOn(TypedArrayUtils.getString(a, R.styleable.CheckBoxPreference_summaryOn,
            R.styleable.CheckBoxPreference_android_summaryOn));

    setSummaryOff(TypedArrayUtils.getString(a, R.styleable.CheckBoxPreference_summaryOff,
            R.styleable.CheckBoxPreference_android_summaryOff));

    setDisableDependentsState(TypedArrayUtils.getBoolean(a,
            R.styleable.CheckBoxPreference_disableDependentsState,
            R.styleable.CheckBoxPreference_android_disableDependentsState, false));

    a.recycle();
}
 
Example #6
Source File: ListPreference.java    From MaterialPreference with Apache License 2.0 6 votes vote down vote up
@SuppressLint("RestrictedApi")
public ListPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    TypedArray a = context.obtainStyledAttributes(
            attrs, R.styleable.ListPreference, defStyleAttr, defStyleRes);

    mEntries = TypedArrayUtils.getTextArray(a, R.styleable.ListPreference_entries,
            R.styleable.ListPreference_android_entries);

    mEntryValues = TypedArrayUtils.getTextArray(a, R.styleable.ListPreference_entryValues,
            R.styleable.ListPreference_android_entryValues);

    a.recycle();

    /* Retrieve the Preference summary attribute since it's private
     * in the Preference class.
     */
    a = context.obtainStyledAttributes(attrs,
            R.styleable.Preference, defStyleAttr, defStyleRes);

    mSummary = TypedArrayUtils.getString(a, R.styleable.Preference_summary,
            R.styleable.Preference_android_summary);

    a.recycle();
}
 
Example #7
Source File: NumberPickerPreference.java    From MaterialPreference with Apache License 2.0 6 votes vote down vote up
@SuppressLint("RestrictedApi")
public NumberPickerPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    mNumberPicker = new NumberPicker(context);

    TypedArray a;
    a = context.obtainStyledAttributes(attrs, R.styleable.NumberPickerPreference);
    mNumberPicker.setMinValue(a.getInt(R.styleable.NumberPickerPreference_min, 0));
    mNumberPicker.setMaxValue(a.getInt(R.styleable.NumberPickerPreference_max, 100));

    a = context.obtainStyledAttributes(attrs,
            R.styleable.Preference, defStyleAttr, defStyleRes);

    mSummary = TypedArrayUtils.getString(a, R.styleable.Preference_summary,
            R.styleable.Preference_android_summary);

    a.recycle();
}
 
Example #8
Source File: PreferenceGroup.java    From MaterialPreference with Apache License 2.0 5 votes vote down vote up
@SuppressLint("RestrictedApi")
public PreferenceGroup(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    mPreferenceList = new ArrayList<>();

    final TypedArray a = context.obtainStyledAttributes(
            attrs, R.styleable.PreferenceGroup, defStyleAttr, defStyleRes);

    mOrderingAsAdded =
            TypedArrayUtils.getBoolean(a, R.styleable.PreferenceGroup_orderingFromXml,
                    R.styleable.PreferenceGroup_orderingFromXml, true);

    a.recycle();
}
 
Example #9
Source File: DialogPreference.java    From MaterialPreference with Apache License 2.0 5 votes vote down vote up
@SuppressLint("RestrictedApi")
public DialogPreference(
        Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    final TypedArray a = context.obtainStyledAttributes(attrs,
            R.styleable.DialogPreference, defStyleAttr, defStyleRes);

    mDialogTitle = TypedArrayUtils.getString(a, R.styleable.DialogPreference_dialogTitle,
            R.styleable.DialogPreference_android_dialogTitle);
    if (mDialogTitle == null) {
        // Fall back on the regular title of the preference
        // (the one that is seen in the list)
        mDialogTitle = getTitle();
    }

    mDialogMessage = TypedArrayUtils.getString(a, R.styleable.DialogPreference_dialogMessage,
            R.styleable.DialogPreference_android_dialogMessage);

    mDialogIcon = TypedArrayUtils.getDrawable(a, R.styleable.DialogPreference_dialogIcon,
            R.styleable.DialogPreference_android_dialogIcon);

    mPositiveButtonText = TypedArrayUtils.getString(a,
            R.styleable.DialogPreference_positiveButtonText,
            R.styleable.DialogPreference_android_positiveButtonText);

    mNegativeButtonText = TypedArrayUtils.getString(a,
            R.styleable.DialogPreference_negativeButtonText,
            R.styleable.DialogPreference_android_negativeButtonText);

    mDialogLayoutResId = TypedArrayUtils.getResourceId(a,
            R.styleable.DialogPreference_dialogLayout,
            R.styleable.DialogPreference_android_dialogLayout, 0);

    a.recycle();
}
 
Example #10
Source File: SwitchPreference.java    From MaterialPreference with Apache License 2.0 5 votes vote down vote up
/**
 * Construct a new SwitchPreference with the given style options.
 *
 * @param context      The Context that will style this preference
 * @param attrs        Style attributes that differ from the default
 * @param defStyleAttr An attribute in the current theme that contains a
 *                     reference to a style resource that supplies default values for
 *                     the view. Can be 0 to not look for defaults.
 * @param defStyleRes  A resource identifier of a style resource that
 *                     supplies default values for the view, used only if
 *                     defStyleAttr is 0 or can not be found in the theme. Can be 0
 *                     to not look for defaults.
 */
@SuppressLint("RestrictedApi")
public SwitchPreference(Context context, AttributeSet attrs, int defStyleAttr,
                        int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    TypedArray a = context.obtainStyledAttributes(attrs,
            R.styleable.SwitchPreference, defStyleAttr, defStyleRes);

    setSummaryOn(TypedArrayUtils.getString(a, R.styleable.SwitchPreference_summaryOn,
            R.styleable.SwitchPreference_android_summaryOn));

    setSummaryOff(TypedArrayUtils.getString(a, R.styleable.SwitchPreference_summaryOff,
            R.styleable.SwitchPreference_android_summaryOff));

    setSwitchTextOn(TypedArrayUtils.getString(a,
            R.styleable.SwitchPreference_switchTextOn,
            R.styleable.SwitchPreference_android_switchTextOn));

    setSwitchTextOff(TypedArrayUtils.getString(a,
            R.styleable.SwitchPreference_switchTextOff,
            R.styleable.SwitchPreference_android_switchTextOff));

    setDisableDependentsState(TypedArrayUtils.getBoolean(a,
            R.styleable.SwitchPreference_disableDependentsState,
            R.styleable.SwitchPreference_android_disableDependentsState, false));

    a.recycle();
}
 
Example #11
Source File: EditTextPreference.java    From MaterialPreference with Apache License 2.0 5 votes vote down vote up
@SuppressLint("RestrictedApi")
public EditTextPreference(Context context, AttributeSet attrs, int defStyleAttr,
                          int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    TypedArray a;
    a = context.obtainStyledAttributes(attrs, R.styleable.EditTextPreference);

    mInputType = TypedArrayUtils.getInt(a, R.styleable.EditTextPreference_inputType,
            R.styleable.EditTextPreference_android_inputType, InputType.TYPE_CLASS_TEXT);

    mSingleLine = TypedArrayUtils.getBoolean(a, R.styleable.EditTextPreference_singleLine,
            R.styleable.EditTextPreference_android_singleLine, true);

    mSelectAllOnFocus = TypedArrayUtils.getBoolean(a, R.styleable.EditTextPreference_selectAllOnFocus,
            R.styleable.EditTextPreference_android_selectAllOnFocus, false);

    mHint = TypedArrayUtils.getString(a, R.styleable.EditTextPreference_hint,
            R.styleable.EditTextPreference_android_hint);

    mCommitOnEnter = a.getBoolean(R.styleable.EditTextPreference_commitOnEnter, false);
    a.recycle();

    /* Retrieve the Preference summary attribute since it's private
     * in the Preference class.
     */
    a = context.obtainStyledAttributes(attrs,
            R.styleable.Preference, defStyleAttr, defStyleRes);

    mSummary = TypedArrayUtils.getString(a, R.styleable.Preference_summary,
            R.styleable.Preference_android_summary);

    a.recycle();
}
 
Example #12
Source File: ColorPickerPreference.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
@SuppressLint("RestrictedApi")
public ColorPickerPreference(Context context, AttributeSet attrs) {
  this(context, attrs, TypedArrayUtils.getAttr(context, R.attr.dialogPreferenceStyle,
                                               android.R.attr.dialogPreferenceStyle));
}
 
Example #13
Source File: ItemPickerPreferenceV7.java    From libcommon with Apache License 2.0 4 votes vote down vote up
public ItemPickerPreferenceV7(final Context context, final AttributeSet attrs) {
	this(context, attrs, TypedArrayUtils.getAttr(context, R.attr.dialogPreferenceStyle,
		android.R.attr.dialogPreferenceStyle));
}
 
Example #14
Source File: CheckOnPrefClickListPreference.java    From vinyl-cast with MIT License 4 votes vote down vote up
@SuppressLint("RestrictedApi")
public CheckOnPrefClickListPreference(Context context, AttributeSet attrs) {
    this(context, attrs, TypedArrayUtils.getAttr(context, R.attr.dialogPreferenceStyle,
            android.R.attr.dialogPreferenceStyle));
}
 
Example #15
Source File: InfoButtonListPreferencePref.java    From vinyl-cast with MIT License 4 votes vote down vote up
@SuppressLint("RestrictedApi")
public InfoButtonListPreferencePref(Context context, AttributeSet attrs) {
    this(context, attrs, TypedArrayUtils.getAttr(context, R.attr.dialogPreferenceStyle,
            android.R.attr.dialogPreferenceStyle));
}
 
Example #16
Source File: Preference.java    From MaterialPreference with Apache License 2.0 4 votes vote down vote up
/**
 * Perform inflation from XML and apply a class-specific base style. This
 * constructor of Preference allows subclasses to use their own base style
 * when they are inflating. For example, a {@link CheckBoxPreference}
 * constructor calls this version of the super class constructor and
 * supplies {@code android.R.attr.checkBoxPreferenceStyle} for
 * <var>defStyleAttr</var>. This allows the theme's checkbox preference
 * style to modify all of the base preference attributes as well as the
 * {@link CheckBoxPreference} class's attributes.
 *
 * @param context      The Context this is associated with, through which it can
 *                     access the current theme, resources,
 *                     {@link android.content.SharedPreferences}, etc.
 * @param attrs        The attributes of the XML tag that is inflating the
 *                     preference.
 * @param defStyleAttr An attribute in the current theme that contains a
 *                     reference to a style resource that supplies default values for
 *                     the view. Can be 0 to not look for defaults.
 * @param defStyleRes  A resource identifier of a style resource that
 *                     supplies default values for the view, used only if
 *                     defStyleAttr is 0 or can not be found in the theme. Can be 0
 *                     to not look for defaults.
 * @see #Preference(Context, android.util.AttributeSet)
 */
@SuppressLint("RestrictedApi")
public Preference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    mContext = context;

    final TypedArray a = context.obtainStyledAttributes(
            attrs, R.styleable.Preference, defStyleAttr, defStyleRes);

    mIconResId = TypedArrayUtils.getResourceId(a, R.styleable.Preference_icon,
            R.styleable.Preference_android_icon, 0);

    mKey = TypedArrayUtils.getString(a, R.styleable.Preference_key,
            R.styleable.Preference_android_key);

    mTitle = TypedArrayUtils.getText(a, R.styleable.Preference_title,
            R.styleable.Preference_android_title);

    mSummary = TypedArrayUtils.getText(a, R.styleable.Preference_summary,
            R.styleable.Preference_android_summary);

    mOrder = TypedArrayUtils.getInt(a, R.styleable.Preference_order,
            R.styleable.Preference_android_order, DEFAULT_ORDER);

    mFragment = TypedArrayUtils.getString(a, R.styleable.Preference_fragment,
            R.styleable.Preference_android_fragment);

    mLayoutResId = TypedArrayUtils.getResourceId(a, R.styleable.Preference_layout,
            R.styleable.Preference_android_layout, R.layout.preference_material);

    mWidgetLayoutResId = TypedArrayUtils.getResourceId(a, R.styleable.Preference_widgetLayout,
            R.styleable.Preference_android_widgetLayout, 0);

    mEnabled = TypedArrayUtils.getBoolean(a, R.styleable.Preference_enabled,
            R.styleable.Preference_android_enabled, true);

    mSelectable = TypedArrayUtils.getBoolean(a, R.styleable.Preference_selectable,
            R.styleable.Preference_android_selectable, true);

    mPersistent = TypedArrayUtils.getBoolean(a, R.styleable.Preference_persistent,
            R.styleable.Preference_android_persistent, true);

    mDependencyKey = TypedArrayUtils.getString(a, R.styleable.Preference_dependency,
            R.styleable.Preference_android_dependency);

    mDividerBelowVisibility = TypedArrayUtils.getInt(a, R.styleable.Preference_dividerBelowVisibility,
            R.styleable.Preference_dividerBelowVisibility, DividerVisibility.UNSPECIFIED);

    if (a.hasValue(R.styleable.Preference_defaultValue)) {
        mDefaultValue = onGetDefaultValue(a, R.styleable.Preference_defaultValue);
    } else if (a.hasValue(R.styleable.Preference_android_defaultValue)) {
        mDefaultValue = onGetDefaultValue(a, R.styleable.Preference_android_defaultValue);
    }

    mShouldDisableView =
            TypedArrayUtils.getBoolean(a, R.styleable.Preference_shouldDisableView,
                    R.styleable.Preference_android_shouldDisableView, true);

    mHasSingleLineTitleAttr = a.hasValue(R.styleable.Preference_singleLineTitle);
    if (mHasSingleLineTitleAttr) {
        mSingleLineTitle = TypedArrayUtils.getBoolean(a, R.styleable.Preference_singleLineTitle,
                R.styleable.Preference_android_singleLineTitle, true);
    }

    mIconSpaceReserved = TypedArrayUtils.getBoolean(a, R.styleable.Preference_iconSpaceReserved,
            R.styleable.Preference_android_iconSpaceReserved, false);

    a.recycle();
}
 
Example #17
Source File: NumberPickerPreferenceV7.java    From libcommon with Apache License 2.0 4 votes vote down vote up
public NumberPickerPreferenceV7(@NonNull final Context context,
	@Nullable final AttributeSet attrs) {

	this(context, attrs, TypedArrayUtils.getAttr(context, R.attr.dialogPreferenceStyle,
		android.R.attr.dialogPreferenceStyle));
}
 
Example #18
Source File: DialogPreferenceV7.java    From libcommon with Apache License 2.0 4 votes vote down vote up
public DialogPreferenceV7(@NonNull final Context context,
	@Nullable final AttributeSet attrs) {

	this(context, attrs, TypedArrayUtils.getAttr(context, R.attr.dialogPreferenceStyle,
		android.R.attr.dialogPreferenceStyle));
}
 
Example #19
Source File: MultilineLabelPreferenceV7.java    From libcommon with Apache License 2.0 4 votes vote down vote up
public MultilineLabelPreferenceV7(final Context context, final AttributeSet attrs) {
	this(context, attrs, TypedArrayUtils.getAttr(context, R.attr.preferenceStyle,
		android.R.attr.preferenceStyle));
}
 
Example #20
Source File: SeekBarPreferenceV7.java    From libcommon with Apache License 2.0 4 votes vote down vote up
public SeekBarPreferenceV7(final Context context, final AttributeSet attrs) {
	this(context, attrs, TypedArrayUtils.getAttr(context, R.attr.seekBarPreferenceStyle,
		android.R.attr.preferenceStyle));
}
 
Example #21
Source File: TimePickerPreferenceV7.java    From libcommon with Apache License 2.0 4 votes vote down vote up
public TimePickerPreferenceV7(@NonNull final Context context,
	@Nullable final AttributeSet attrs) {

	this(context, attrs, TypedArrayUtils.getAttr(context, R.attr.dialogPreferenceStyle,
		android.R.attr.dialogPreferenceStyle));
}
 
Example #22
Source File: SubTitlePreferenceV7.java    From libcommon with Apache License 2.0 4 votes vote down vote up
public SubTitlePreferenceV7(final Context context, final AttributeSet attrs) {
	this(context, attrs, TypedArrayUtils.getAttr(context, R.attr.preferenceStyle,
		android.R.attr.preferenceStyle));
}
 
Example #23
Source File: ColorPickerDialogPreferenceV7.java    From libcommon with Apache License 2.0 4 votes vote down vote up
public ColorPickerDialogPreferenceV7(@NonNull final Context context,
	@Nullable final AttributeSet attrs) {

	this(context, attrs, TypedArrayUtils.getAttr(context, R.attr.dialogPreferenceStyle,
		android.R.attr.dialogPreferenceStyle));
}
 
Example #24
Source File: SubTitleListPreferenceV7.java    From libcommon with Apache License 2.0 4 votes vote down vote up
public SubTitleListPreferenceV7(final Context context, final AttributeSet attrs) {
	this(context, attrs, TypedArrayUtils.getAttr(context, R.attr.preferenceStyle,
		android.R.attr.preferenceStyle));
}