Java Code Examples for androidx.core.content.res.TypedArrayUtils#getBoolean()

The following examples show how to use androidx.core.content.res.TypedArrayUtils#getBoolean() . 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: 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 2
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 3
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 4
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();
}