类android.support.v4.content.res.TypedArrayUtils源码实例Demo

下面列出了怎么用android.support.v4.content.res.TypedArrayUtils的API类实例代码及写法,或者点击链接到github查看源代码。

@SuppressLint("RestrictedApi")
public IntegerSimpleMenuPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

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

    a.recycle();

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

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

    mEntryValues = getIntArray(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();

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

    int popupStyle = a.getResourceId(R.styleable.SimpleMenuPreference_popupStyle, R.style.Preference_SimpleMenuPreference_Popup);

    mPopupWindow = new SimpleMenuPopupWindow(context, attrs, R.styleable.SimpleMenuPreference_popupStyle, popupStyle);
    mPopupWindow.setOnItemClickListener(new SimpleMenuPopupWindow.OnItemClickListener() {
        @Override
        public void onClick(int i) {
            int value = getEntryValues()[i];
            if (callChangeListener(value)) {
                setValue(value);
            }
        }
    });
}
 
@SuppressLint("RestrictedApi")
private static int[] getIntArray(TypedArray a, @StyleableRes int index,
                                 @StyleableRes int fallbackIndex) {
    int resourceId = TypedArrayUtils.getResourceId(a, index, fallbackIndex, 0);
    return a.getResources().getIntArray(resourceId);
}
 
@SuppressLint("RestrictedApi")
public RadioButtonPreference(Context context, AttributeSet attrs) {
    this(context, attrs, TypedArrayUtils.getAttr(context, R.attr.checkBoxPreferenceStyle,
            android.R.attr.checkBoxPreferenceStyle));
}
 
源代码4 项目: Silence   文件: ColorPickerPreference.java
@SuppressLint("RestrictedApi")
public ColorPickerPreference(Context context, AttributeSet attrs) {
  this(context, attrs, TypedArrayUtils.getAttr(context, R.attr.dialogPreferenceStyle,
                                               android.R.attr.dialogPreferenceStyle));
}
 
源代码5 项目: Silence   文件: RingtonePreference.java
@SuppressLint("RestrictedApi")
public RingtonePreference(Context context, AttributeSet attrs) {
  this(context, attrs, TypedArrayUtils.getAttr(context, R.attr.dialogPreferenceStyle,
                                               android.R.attr.dialogPreferenceStyle));
}