android.content.res.TypedArray#getValue()源码实例Demo

下面列出了android.content.res.TypedArray#getValue() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: sketch   文件: GifTextureView.java
private static InputSource findSource(final TypedArray textureViewAttributes) {
	final TypedValue value = new TypedValue();
	if (!textureViewAttributes.getValue(R.styleable.GifTextureView_gifSource, value)) {
		return null;
	}

	if (value.resourceId != 0) {
		final String resourceTypeName = textureViewAttributes.getResources().getResourceTypeName(value.resourceId);
		if (GifViewUtils.SUPPORTED_RESOURCE_TYPE_NAMES.contains(resourceTypeName)) {
			return new InputSource.ResourcesSource(textureViewAttributes.getResources(), value.resourceId);
		} else if (!"string".equals(resourceTypeName)) {
			throw new IllegalArgumentException(
					"Expected string, drawable, mipmap or raw resource type. '" + resourceTypeName
							+ "' is not supported");
		}
	}
	return new InputSource.AssetSource(textureViewAttributes.getResources().getAssets(), value.string.toString());
}
 
public FontStyleAdapter(Context context) {
  TypedArray stylesArray = getResources().obtainTypedArray(getFontStyles());
  TypedArray namesArray = getResources().obtainTypedArray(getFontStyleNames());

  TypedValue value = new TypedValue();
  for (int i = 0; i < stylesArray.length(); i++) {
    // 1. Get the attribute from the array: ?attr/textAppearanceHeadline1
    stylesArray.getValue(i, value);
    int attribute = value.data;

    // 2. Get the style from the attribute: @style/TextAppearance.MaterialComponents.Headline1
    TypedArray a = context.obtainStyledAttributes(new int[] {attribute});
    int style = a.getResourceId(0, 0);
    a.recycle();

    styles.add(style);
    names.add(namesArray.getString(i));
    attributeNames.add(context.getResources().getResourceEntryName(attribute));
  }
  stylesArray.recycle();
  namesArray.recycle();
}
 
private static InputSource findSource(final TypedArray textureViewAttributes) {
    final TypedValue value = new TypedValue();
    if (!textureViewAttributes.getValue(R.styleable.GifTextureView_gifSource, value)) {
        return null;
    }

    if (value.resourceId != 0) {
        final String type = textureViewAttributes.getResources().getResourceTypeName(value.resourceId);
        if ("drawable".equals(type) || "raw".equals(type)) {
            return new InputSource.ResourcesSource(textureViewAttributes.getResources(), value.resourceId);
        } else if (!"string".equals(type)) {
            throw new IllegalArgumentException("Expected string, drawable or raw resource, type " + type + " " +
                    "cannot be converted to GIF");
        }
    }
    return new InputSource.AssetSource(textureViewAttributes.getResources().getAssets(), value.string.toString());
}
 
源代码4 项目: litho   文件: TypedArrayUtils.java
static boolean isColorAttribute(TypedArray a, int idx) {
  synchronized (sTmpTypedValue) {
    a.getValue(idx, sTmpTypedValue);
    return sTmpTypedValue.type >= TypedValue.TYPE_FIRST_COLOR_INT
        && sTmpTypedValue.type <= TypedValue.TYPE_LAST_COLOR_INT;
  }
}
 
/**
 * get the raw value from a complex value ( Ex: complex = 14sp, returns 14)
 */
private float getRawSizeValue(TypedArray a, int index, float defValue) {
    TypedValue outValue = new TypedValue();
    boolean result = a.getValue(index, outValue);
    if (!result) {
        return defValue;
    }

    return TypedValue.complexToFloat(outValue.data);
}
 
源代码6 项目: revolution-irc   文件: LiveThemeUtils.java
public static int getAttribute(TypedArray attrs, int attr) {
    TypedValue typedValue = new TypedValue();
    if (!attrs.getValue(attr, typedValue))
        return 0;
    if (typedValue.type == TypedValue.TYPE_ATTRIBUTE)
        return typedValue.data;
    return 0;
}
 
源代码7 项目: toktok-android   文件: LayoutManager.java
@Override
public RecyclerView.LayoutParams generateLayoutParams(@NonNull Context c, AttributeSet attrs) {
    // Just so we don't build layout params multiple times.

    boolean isString;
    TypedArray a = c.obtainStyledAttributes(attrs, R.styleable.superslim_LayoutManager);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        TypedValue value = new TypedValue();
        a.getValue(R.styleable.superslim_LayoutManager_slm_section_sectionManager, value);
        isString = value.type == TypedValue.TYPE_STRING;
    } else {
        isString =
                a.getType(R.styleable.superslim_LayoutManager_slm_section_sectionManager)
                        == TypedValue.TYPE_STRING;
    }
    String sectionManager = null;
    int sectionManagerKind;
    if (isString) {
        sectionManager = a
                .getString(R.styleable.superslim_LayoutManager_slm_section_sectionManager);
        if (TextUtils.isEmpty(sectionManager)) {
            sectionManagerKind = SECTION_MANAGER_LINEAR;
        } else {
            sectionManagerKind = SECTION_MANAGER_CUSTOM;
        }
    } else {
        sectionManagerKind = a
                .getInt(R.styleable.superslim_LayoutManager_slm_section_sectionManager,
                        SECTION_MANAGER_LINEAR);
    }
    a.recycle();

    return getSLM(sectionManagerKind, sectionManager).generateLayoutParams(c, attrs);
}
 
源代码8 项目: Contacts   文件: AttrUtil.java
public static TypedValue getValue(Context context, int attr)
{
	TypedArray ta = context.obtainStyledAttributes(new int[] { attr });
	TypedValue tv = new TypedValue();
	boolean bool = ta.getValue(0, tv);
	ta.recycle();
	if (bool == true)
		return tv;
	
	return null;
}
 
源代码9 项目: Klyph   文件: AttrUtil.java
public static TypedValue getValue(Context context, int attr)
{
	TypedArray ta = context.obtainStyledAttributes(new int[] { attr });
	TypedValue tv = new TypedValue();
	boolean bool = ta.getValue(0, tv);
	ta.recycle();
	if (bool == true)
		return tv;
	
	return null;
}
 
源代码10 项目: Klyph   文件: AttrUtil.java
public static TypedValue getValue(Context context, int attr)
{
	TypedArray ta = context.obtainStyledAttributes(new int[] { attr });
	TypedValue tv = new TypedValue();
	boolean bool = ta.getValue(0, tv);
	ta.recycle();
	if (bool == true)
		return tv;
	
	return null;
}
 
源代码11 项目: AndroidDemoProjects   文件: MyWatchFace.java
private int[] getIntArray(int resId) {
    TypedArray array = getResources().obtainTypedArray(resId);
    int[] rc = new int[array.length()];
    TypedValue value = new TypedValue();
    for (int i = 0; i < array.length(); i++) {
        array.getValue(i, value);
        rc[i] = value.resourceId;
    }
    return rc;
}
 
源代码12 项目: SegmentedButton   文件: SegmentedButtonGroup.java
private void getAttributes(Context context, @Nullable AttributeSet attrs)
{
    // According to docs for obtainStyledAttributes, attrs can be null and I assume that each value will be set
    // to the default
    final TypedArray ta = context.getTheme().obtainStyledAttributes(attrs, R.styleable.SegmentedButtonGroup, 0, 0);

    // Load background if available, this can be a drawable or a color
    // Note: Not well documented but getDrawable will return a ColorDrawable if a color is specified
    if (ta.hasValue(R.styleable.SegmentedButtonGroup_android_background))
        backgroundDrawable = ta.getDrawable(R.styleable.SegmentedButtonGroup_android_background);

    // Load background on selection if available, can be drawable or color
    if (ta.hasValue(R.styleable.SegmentedButtonGroup_selectedBackground))
        selectedBackgroundDrawable = ta.getDrawable(R.styleable.SegmentedButtonGroup_selectedBackground);

    // Note: Must read radius before setBorder call in order to round the border corners!
    radius = ta.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_radius, 0);
    selectedButtonRadius = ta.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_selectedButtonRadius, 0);

    // Setup border for button group
    // Width is the thickness of the border, color is the color of the border
    // Dash width and gap, if the dash width is not zero will make the border dashed with a ratio between dash
    // width and gap
    borderWidth = ta.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_borderWidth, 0);
    borderColor = ta.getColor(R.styleable.SegmentedButtonGroup_borderColor, Color.BLACK);
    borderDashWidth = ta.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_borderDashWidth, 0);
    borderDashGap = ta.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_borderDashGap, 0);

    // Set the border to the read values, this will set the border values to itself but will create a
    // GradientDrawable containing the border
    setBorder(borderWidth, borderColor, borderDashWidth, borderDashGap);

    // Get border information for the selected button
    // Same defaults as the border above, however this border information will be passed to each button so that
    // the correct border can be rendered around the selected button
    selectedBorderWidth = ta.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_selectedBorderWidth, 0);
    selectedBorderColor = ta.getColor(R.styleable.SegmentedButtonGroup_selectedBorderColor, Color.BLACK);
    selectedBorderDashWidth = ta.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_selectedBorderDashWidth, 0);
    selectedBorderDashGap = ta.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_selectedBorderDashGap, 0);

    position = ta.getInt(R.styleable.SegmentedButtonGroup_position, 0);
    draggable = ta.getBoolean(R.styleable.SegmentedButtonGroup_draggable, false);

    // Update clickable property
    // Not updating this property sets the clickable value to false by default but this sets the default to true
    // while keeping the clickable value if specified in the layouot XML
    setClickable(ta.getBoolean(R.styleable.SegmentedButtonGroup_android_clickable, true));

    ripple = ta.getBoolean(R.styleable.SegmentedButtonGroup_ripple, true);
    hasRippleColor = ta.hasValue(R.styleable.SegmentedButtonGroup_rippleColor);
    rippleColor = ta.getColor(R.styleable.SegmentedButtonGroup_rippleColor, Color.GRAY);

    final int dividerWidth = ta.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_dividerWidth, 1);
    final int dividerRadius = ta.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_dividerRadius, 0);
    final int dividerPadding = ta.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_dividerPadding, 0);

    // Load divider value if available, the divider can be either a drawable resource or a color
    // Load the TypedValue first and check the type to determine if color or drawable
    final TypedValue value = new TypedValue();
    if (ta.getValue(R.styleable.SegmentedButtonGroup_divider, value))
    {
        if (value.type == TypedValue.TYPE_REFERENCE || value.type == TypedValue.TYPE_STRING)
        {
            // Note: Odd case where Android Studio layout preview editor will fail to display a
            // SegmentedButtonGroup with a divider drawable because value.resourceId returns 0 and thus
            // ContextCompat.getDrawable will return NullPointerException
            // Loading drawable TypedArray.getDrawable or doing TypedArray.getResourceId fixes the problem
            if (isInEditMode())
            {
                setDivider(ta.getDrawable(R.styleable.SegmentedButtonGroup_divider), dividerWidth, dividerRadius,
                    dividerPadding);
            }
            else
            {
                setDivider(ContextCompat.getDrawable(context, value.resourceId), dividerWidth, dividerRadius,
                    dividerPadding);
            }
        }
        else if (value.type >= TypedValue.TYPE_FIRST_COLOR_INT && value.type <= TypedValue.TYPE_LAST_COLOR_INT)
        {
            // Divider is a color, value.data is the color value
            setDivider(value.data, dividerWidth, dividerRadius, dividerPadding);
        }
        else
        {
            // Invalid type for the divider, throw an exception
            throw new IllegalArgumentException("Invalid type for SegmentedButtonGroup divider in layout XML "
                + "resource. Must be a color or drawable");
        }
    }

    int selectionAnimationInterpolator = ta.getInt(R.styleable.SegmentedButtonGroup_selectionAnimationInterpolator,
        ANIM_INTERPOLATOR_FAST_OUT_SLOW_IN);
    setSelectionAnimationInterpolator(selectionAnimationInterpolator);
    selectionAnimationDuration = ta.getInt(R.styleable.SegmentedButtonGroup_selectionAnimationDuration, 500);

    // Recycle the typed array, required once done using it
    ta.recycle();
}
 
源代码13 项目: android_9.0.0_r45   文件: Keyboard.java
/** Create a key with the given top-left coordinate and extract its attributes from
 * the XML parser.
 * @param res resources associated with the caller's context
 * @param parent the row that this key belongs to. The row must already be attached to
 * a {@link Keyboard}.
 * @param x the x coordinate of the top-left
 * @param y the y coordinate of the top-left
 * @param parser the XML parser containing the attributes for this key
 */
public Key(Resources res, Row parent, int x, int y, XmlResourceParser parser) {
    this(parent);

    this.x = x;
    this.y = y;
    
    TypedArray a = res.obtainAttributes(Xml.asAttributeSet(parser), 
            com.android.internal.R.styleable.Keyboard);

    width = getDimensionOrFraction(a, 
            com.android.internal.R.styleable.Keyboard_keyWidth,
            keyboard.mDisplayWidth, parent.defaultWidth);
    height = getDimensionOrFraction(a, 
            com.android.internal.R.styleable.Keyboard_keyHeight,
            keyboard.mDisplayHeight, parent.defaultHeight);
    gap = getDimensionOrFraction(a, 
            com.android.internal.R.styleable.Keyboard_horizontalGap,
            keyboard.mDisplayWidth, parent.defaultHorizontalGap);
    a.recycle();
    a = res.obtainAttributes(Xml.asAttributeSet(parser),
            com.android.internal.R.styleable.Keyboard_Key);
    this.x += gap;
    TypedValue codesValue = new TypedValue();
    a.getValue(com.android.internal.R.styleable.Keyboard_Key_codes, 
            codesValue);
    if (codesValue.type == TypedValue.TYPE_INT_DEC 
            || codesValue.type == TypedValue.TYPE_INT_HEX) {
        codes = new int[] { codesValue.data };
    } else if (codesValue.type == TypedValue.TYPE_STRING) {
        codes = parseCSV(codesValue.string.toString());
    }
    
    iconPreview = a.getDrawable(com.android.internal.R.styleable.Keyboard_Key_iconPreview);
    if (iconPreview != null) {
        iconPreview.setBounds(0, 0, iconPreview.getIntrinsicWidth(), 
                iconPreview.getIntrinsicHeight());
    }
    popupCharacters = a.getText(
            com.android.internal.R.styleable.Keyboard_Key_popupCharacters);
    popupResId = a.getResourceId(
            com.android.internal.R.styleable.Keyboard_Key_popupKeyboard, 0);
    repeatable = a.getBoolean(
            com.android.internal.R.styleable.Keyboard_Key_isRepeatable, false);
    modifier = a.getBoolean(
            com.android.internal.R.styleable.Keyboard_Key_isModifier, false);
    sticky = a.getBoolean(
            com.android.internal.R.styleable.Keyboard_Key_isSticky, false);
    edgeFlags = a.getInt(com.android.internal.R.styleable.Keyboard_Key_keyEdgeFlags, 0);
    edgeFlags |= parent.rowEdgeFlags;

    icon = a.getDrawable(
            com.android.internal.R.styleable.Keyboard_Key_keyIcon);
    if (icon != null) {
        icon.setBounds(0, 0, icon.getIntrinsicWidth(), icon.getIntrinsicHeight());
    }
    label = a.getText(com.android.internal.R.styleable.Keyboard_Key_keyLabel);
    text = a.getText(com.android.internal.R.styleable.Keyboard_Key_keyOutputText);
    
    if (codes == null && !TextUtils.isEmpty(label)) {
        codes = new int[] { label.charAt(0) };
    }
    a.recycle();
}
 
源代码14 项目: libcommon   文件: Keyboard.java
/**
 * Create a key with the given top-left coordinate and extract its attributes from
 * the XML parser.
 *
 * @param res    resources associated with the caller's context
 * @param parent the row that this key belongs to. The row must already be attached to
 *               a {@link Keyboard}.
 * @param x      the x coordinate of the top-left
 * @param y      the y coordinate of the top-left
 * @param parser the XML parser containing the attributes for this key
 */
public Key(@NonNull final  Resources res,
	@NonNull final  Keyboard.Row parent,
	final int x, final int y,
	final XmlResourceParser parser) {

	this(parent);

	this.x = x;
	this.y = y;

	TypedArray a = res.obtainAttributes(Xml.asAttributeSet(parser),
		R.styleable.Keyboard);

	width = getDimensionOrFraction(a,
		R.styleable.Keyboard_keyWidth,
		keyboard.mDisplayWidth, parent.defaultWidth);
	height = getDimensionOrFraction(a,
		R.styleable.Keyboard_keyHeight,
		keyboard.mDisplayHeight, parent.defaultHeight);
	gap = getDimensionOrFraction(a,
		R.styleable.Keyboard_horizontalGap,
		keyboard.mDisplayWidth, parent.defaultHorizontalGap);
	a.recycle();
	a = res.obtainAttributes(Xml.asAttributeSet(parser),
		R.styleable.Keyboard_Key);
	this.x += gap;
	TypedValue codesValue = new TypedValue();
	a.getValue(R.styleable.Keyboard_Key_codes, codesValue);
	if (DEBUG) Log.i(TAG, "Key:" + codesValue);
	if (codesValue.type == TypedValue.TYPE_INT_DEC
		|| codesValue.type == TypedValue.TYPE_INT_HEX) {
		codes = new int[]{codesValue.data};
	} else if (codesValue.type == TypedValue.TYPE_STRING) {
		codes = parseCSV(codesValue.string.toString());
	}

	iconPreview = a.getDrawable(R.styleable.Keyboard_Key_iconPreview);
	if (iconPreview != null) {
		iconPreview.setBounds(0, 0, iconPreview.getIntrinsicWidth(),
			iconPreview.getIntrinsicHeight());
	}
	popupCharacters = a.getText(
		R.styleable.Keyboard_Key_popupCharacters);
	popupResId = a.getResourceId(
		R.styleable.Keyboard_Key_popupKeyboard, 0);
	repeatable = a.getBoolean(
		R.styleable.Keyboard_Key_isRepeatable, false);
	modifier = a.getBoolean(
		R.styleable.Keyboard_Key_isModifier, false);
	sticky = a.getBoolean(
		R.styleable.Keyboard_Key_isSticky, false);
	edgeFlags = a.getInt(R.styleable.Keyboard_Key_keyEdgeFlags, 0);
	edgeFlags |= parent.rowEdgeFlags;

	icon = a.getDrawable(
		R.styleable.Keyboard_Key_keyIcon);
	if (icon != null) {
		icon.setBounds(0, 0, icon.getIntrinsicWidth(), icon.getIntrinsicHeight());
	}
	label = a.getText(R.styleable.Keyboard_Key_keyLabel);
	text = a.getText(R.styleable.Keyboard_Key_keyOutputText);

	if (codes == null && !TextUtils.isEmpty(label)) {
		codes = new int[]{label.charAt(0)};
	}
	a.recycle();
}
 
/**
 * Retrieve a dimensional unit attribute at <var>index</var> for use as a size in raw pixels. A
 * size conversion involves rounding the base value, and ensuring that a non-zero base value is at
 * least one pixel in size.
 *
 * <p>This method will throw an exception if the attribute is defined but is not a dimension.
 *
 * @param context The Context the view is running in, through which the current theme, resources,
 *     etc can be accessed.
 * @param attributes array of typed attributes from which the dimension unit must be read.
 * @param index Index of attribute to retrieve.
 * @param defaultValue Value to return if the attribute is not defined or not a resource.
 * @return Attribute dimension value multiplied by the appropriate metric and truncated to integer
 *     pixels, or defaultValue if not defined.
 * @throws UnsupportedOperationException if the attribute is defined but is not a dimension.
 * @see TypedArray#getDimensionPixelSize(int, int)
 */
public static int getDimensionPixelSize(
    @NonNull Context context,
    @NonNull TypedArray attributes,
    @StyleableRes int index,
    final int defaultValue) {
  TypedValue value = new TypedValue();
  if (!attributes.getValue(index, value) || value.type != TypedValue.TYPE_ATTRIBUTE) {
    return attributes.getDimensionPixelSize(index, defaultValue);
  }

  TypedArray styledAttrs = context.getTheme().obtainStyledAttributes(new int[] {value.data});
  int dimension = styledAttrs.getDimensionPixelSize(0, defaultValue);
  styledAttrs.recycle();
  return dimension;
}
 
源代码16 项目: Carbon   文件: LollipopDrawablesCompat.java
public static Drawable getDrawable(TypedArray array, int index, Resources.Theme theme) {
    TypedValue value = new TypedValue();
    array.getValue(index, value);
    return loadDrawable(array.getResources(), value, theme);
}
 
源代码17 项目: toktok-android   文件: LayoutManager.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public LayoutParams(@NonNull Context c, AttributeSet attrs) {
    super(c, attrs);

    TypedArray a = c.obtainStyledAttributes(attrs, R.styleable.superslim_LayoutManager);
    isHeader = a.getBoolean(
            R.styleable.superslim_LayoutManager_slm_isHeader,
            false);
    //noinspection ResourceType
    headerDisplay = a.getInt(
            R.styleable.superslim_LayoutManager_slm_headerDisplay,
            DEFAULT_HEADER_DISPLAY);
    mFirstPosition = a.getInt(
            R.styleable.superslim_LayoutManager_slm_section_firstPosition,
            NO_FIRST_POSITION);

    // Header margin types can be dimension or integer (enum).
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        TypedValue value = new TypedValue();
        a.getValue(R.styleable.superslim_LayoutManager_slm_section_headerMarginStart,
                value);
        loadHeaderStartMargin(a, value.type == TypedValue.TYPE_DIMENSION);

        a.getValue(R.styleable.superslim_LayoutManager_slm_section_headerMarginEnd, value);
        loadHeaderEndMargin(a, value.type == TypedValue.TYPE_DIMENSION);

        a.getValue(R.styleable.superslim_LayoutManager_slm_section_sectionManager, value);
        loadSlm(a, value.type == TypedValue.TYPE_STRING);
    } else {
        boolean isDimension;
        isDimension =
                a.getType(R.styleable.superslim_LayoutManager_slm_section_headerMarginStart)
                        == TypedValue.TYPE_DIMENSION;
        loadHeaderStartMargin(a, isDimension);

        isDimension =
                a.getType(R.styleable.superslim_LayoutManager_slm_section_headerMarginEnd)
                        == TypedValue.TYPE_DIMENSION;
        loadHeaderEndMargin(a, isDimension);

        boolean isString =
                a.getType(R.styleable.superslim_LayoutManager_slm_section_sectionManager)
                        == TypedValue.TYPE_STRING;
        loadSlm(a, isString);
    }

    a.recycle();
}
 
源代码18 项目: android-apps   文件: MenuInflater.java
/**
 * Called when the parser is pointing to an item tag.
 */
public void readItem(AttributeSet attrs) {
    TypedArray a = mContext.obtainStyledAttributes(attrs,
            R.styleable.SherlockMenuItem);

    // Inherit attributes from the group as default value
    itemId = a.getResourceId(R.styleable.SherlockMenuItem_android_id, defaultItemId);
    final int category = a.getInt(R.styleable.SherlockMenuItem_android_menuCategory, groupCategory);
    final int order = a.getInt(R.styleable.SherlockMenuItem_android_orderInCategory, groupOrder);
    itemCategoryOrder = (category & Menu.CATEGORY_MASK) | (order & Menu.USER_MASK);
    itemTitle = a.getText(R.styleable.SherlockMenuItem_android_title);
    itemTitleCondensed = a.getText(R.styleable.SherlockMenuItem_android_titleCondensed);
    itemIconResId = a.getResourceId(R.styleable.SherlockMenuItem_android_icon, 0);
    itemAlphabeticShortcut =
            getShortcut(a.getString(R.styleable.SherlockMenuItem_android_alphabeticShortcut));
    itemNumericShortcut =
            getShortcut(a.getString(R.styleable.SherlockMenuItem_android_numericShortcut));
    if (a.hasValue(R.styleable.SherlockMenuItem_android_checkable)) {
        // Item has attribute checkable, use it
        itemCheckable = a.getBoolean(R.styleable.SherlockMenuItem_android_checkable, false) ? 1 : 0;
    } else {
        // Item does not have attribute, use the group's (group can have one more state
        // for checkable that represents the exclusive checkable)
        itemCheckable = groupCheckable;
    }

    itemChecked = a.getBoolean(R.styleable.SherlockMenuItem_android_checked, defaultItemChecked);
    itemVisible = a.getBoolean(R.styleable.SherlockMenuItem_android_visible, groupVisible);
    itemEnabled = a.getBoolean(R.styleable.SherlockMenuItem_android_enabled, groupEnabled);

    TypedValue value = new TypedValue();
    a.getValue(R.styleable.SherlockMenuItem_android_showAsAction, value);
    itemShowAsAction = value.type == TypedValue.TYPE_INT_HEX ? value.data : -1;

    itemListenerMethodName = a.getString(R.styleable.SherlockMenuItem_android_onClick);
    itemActionViewLayout = a.getResourceId(R.styleable.SherlockMenuItem_android_actionLayout, 0);
    itemActionViewClassName = a.getString(R.styleable.SherlockMenuItem_android_actionViewClass);
    itemActionProviderClassName = a.getString(R.styleable.SherlockMenuItem_android_actionProviderClass);

    final boolean hasActionProvider = itemActionProviderClassName != null;
    if (hasActionProvider && itemActionViewLayout == 0 && itemActionViewClassName == null) {
        itemActionProvider = newInstance(itemActionProviderClassName,
                    ACTION_PROVIDER_CONSTRUCTOR_SIGNATURE,
                    mActionProviderConstructorArguments);
    } else {
        if (hasActionProvider) {
            Log.w(LOG_TAG, "Ignoring attribute 'actionProviderClass'."
                    + " Action view already specified.");
        }
        itemActionProvider = null;
    }

    a.recycle();

    itemAdded = false;
}
 
源代码19 项目: RippleDrawable   文件: LollipopDrawablesCompat.java
public static Drawable getDrawable(TypedArray array, int index, Resources.Theme theme) {
    TypedValue value = new TypedValue();
    array.getValue(index, value);
    return loadDrawable(array.getResources(), value, theme);
}
 
源代码20 项目: android-apps   文件: FakeDialogPhoneWindow.java
public FakeDialogPhoneWindow(Context context, AttributeSet attrs) {
    super(context, attrs);

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

    a.getValue(R.styleable.SherlockTheme_windowMinWidthMajor, mMinWidthMajor);
    a.getValue(R.styleable.SherlockTheme_windowMinWidthMinor, mMinWidthMinor);

    a.recycle();
}