Example usage for android.support.v4.content.res TypedArrayUtils getString

List of usage examples for android.support.v4.content.res TypedArrayUtils getString

Introduction

In this page you can find the example usage for android.support.v4.content.res TypedArrayUtils getString.

Prototype

public static String getString(TypedArray a, @StyleableRes int index, @StyleableRes int fallbackIndex) 

Source Link

Usage

From source file:android.support.v7.preference.DialogPreference.java

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);/*  w w  w .ja va 2  s  . c om*/

    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();
}

From source file:android.support.v7.preference.CheckBoxPreference.java

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);//from   w w w  .  jav a2  s.com

    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();
}

From source file:android.support.v7.preference.ListPreference.java

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();/* w  w w.j  av a  2s  .c  o  m*/

    /* 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();
}

From source file:rikka.materialpreference.SwitchPreference.java

/**
 * 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./* w w w . j  a v a  2 s .c om*/
 */
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();

    //setWidgetLayoutResource(R.layout.preference_switch_material);
}

From source file:rikka.materialpreference.EditTextPreference.java

public EditTextPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    TypedArray a;/* w w w.  j  a  v  a 2 s .co m*/
    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);

    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();
}

From source file:android.support.v7.preference.SwitchPreferenceCompat.java

/**
 * 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.//from   w  w w  . j  a  va 2  s  . c  o  m
 */
public SwitchPreferenceCompat(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

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

    setSummaryOn(TypedArrayUtils.getString(a, R.styleable.SwitchPreferenceCompat_summaryOn,
            R.styleable.SwitchPreferenceCompat_android_summaryOn));

    setSummaryOff(TypedArrayUtils.getString(a, R.styleable.SwitchPreferenceCompat_summaryOff,
            R.styleable.SwitchPreferenceCompat_android_summaryOff));

    setSwitchTextOn(TypedArrayUtils.getString(a, R.styleable.SwitchPreferenceCompat_switchTextOn,
            R.styleable.SwitchPreferenceCompat_android_switchTextOn));

    setSwitchTextOff(TypedArrayUtils.getString(a, R.styleable.SwitchPreferenceCompat_switchTextOff,
            R.styleable.SwitchPreferenceCompat_android_switchTextOff));

    setDisableDependentsState(
            TypedArrayUtils.getBoolean(a, R.styleable.SwitchPreferenceCompat_disableDependentsState,
                    R.styleable.SwitchPreferenceCompat_android_disableDependentsState, false));

    a.recycle();
}

From source file:android.support.v14.preference.SwitchPreference.java

/**
 * 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./*  w  w  w  .  java2 s . c om*/
 */
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();
}

From source file:rikka.materialpreference.RingtonePreference.java

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);/*  w w w .ja  v  a 2 s.c  om*/

    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();
}

From source file:rikka.materialpreference.Preference.java

/**
 * 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./*from www . ja v a 2  s .c  om*/
 * @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)
 */
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.getString(a, R.styleable.Preference_title, R.styleable.Preference_android_title);

    mSummary = TypedArrayUtils.getString(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);

    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_shouldDisableView, true);

    a.recycle();
}

From source file:android.support.v7.preference.Preference.java

/**
 * 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.//w w  w.j  a v  a 2 s .  co  m
 * @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)
 */
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.getString(a, R.styleable.Preference_title, R.styleable.Preference_android_title);

    mSummary = TypedArrayUtils.getString(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);

    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);

    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);

    a.recycle();
}