android.util.TypedValue#TYPE_LAST_INT源码实例Demo

下面列出了android.util.TypedValue#TYPE_LAST_INT 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: android_9.0.0_r45   文件: TypedArray.java
/**
 * Retrieve the boolean value for the attribute at <var>index</var>.
 * <p>
 * If the attribute is an integer value, this method will return whether
 * it is equal to zero. If the attribute is not a boolean or integer value,
 * this method will attempt to coerce it to an integer using
 * {@link Integer#decode(String)} and return whether it is equal to zero.
 *
 * @param index Index of attribute to retrieve.
 * @param defValue Value to return if the attribute is not defined or
 *                 cannot be coerced to an integer.
 *
 * @return Boolean value of the attribute, or defValue if the attribute was
 *         not defined or could not be coerced to an integer.
 * @throws RuntimeException if the TypedArray has already been recycled.
 */
public boolean getBoolean(@StyleableRes int index, boolean defValue) {
    if (mRecycled) {
        throw new RuntimeException("Cannot make calls to a recycled instance!");
    }

    index *= STYLE_NUM_ENTRIES;
    final int[] data = mData;
    final int type = data[index + STYLE_TYPE];
    if (type == TypedValue.TYPE_NULL) {
        return defValue;
    } else if (type >= TypedValue.TYPE_FIRST_INT
            && type <= TypedValue.TYPE_LAST_INT) {
        return data[index + STYLE_DATA] != 0;
    }

    final TypedValue v = mValue;
    if (getValueAt(index, v)) {
        StrictMode.noteResourceMismatch(v);
        return XmlUtils.convertValueToBoolean(v.coerceToString(), defValue);
    }

    // We already checked for TYPE_NULL. This should never happen.
    throw new RuntimeException("getBoolean of bad type: 0x" + Integer.toHexString(type));
}
 
源代码2 项目: android_9.0.0_r45   文件: TypedArray.java
/**
 * Retrieve the integer value for the attribute at <var>index</var>.
 * <p>
 * Unlike {@link #getInt(int, int)}, this method will throw an exception if
 * the attribute is defined but is not an integer.
 *
 * @param index Index of attribute to retrieve.
 * @param defValue Value to return if the attribute is not defined or
 *                 not a resource.
 *
 * @return Attribute integer value, or defValue if not defined.
 * @throws RuntimeException if the TypedArray has already been recycled.
 * @throws UnsupportedOperationException if the attribute is defined but is
 *         not an integer.
 */
public int getInteger(@StyleableRes int index, int defValue) {
    if (mRecycled) {
        throw new RuntimeException("Cannot make calls to a recycled instance!");
    }

    final int attrIndex = index;
    index *= STYLE_NUM_ENTRIES;

    final int[] data = mData;
    final int type = data[index + STYLE_TYPE];
    if (type == TypedValue.TYPE_NULL) {
        return defValue;
    } else if (type >= TypedValue.TYPE_FIRST_INT
            && type <= TypedValue.TYPE_LAST_INT) {
        return data[index + STYLE_DATA];
    } else if (type == TypedValue.TYPE_ATTRIBUTE) {
        final TypedValue value = mValue;
        getValueAt(index, value);
        throw new UnsupportedOperationException(
                "Failed to resolve attribute at index " + attrIndex + ": " + value);
    }

    throw new UnsupportedOperationException("Can't convert value at index " + attrIndex
            + " to integer: type=0x" + Integer.toHexString(type));
}
 
源代码3 项目: android_9.0.0_r45   文件: TypedArray.java
/**
 * Special version of {@link #getDimensionPixelSize} for retrieving
 * {@link android.view.ViewGroup}'s layout_width and layout_height
 * attributes.  This is only here for performance reasons; applications
 * should use {@link #getDimensionPixelSize}.
 * <p>
 * This method will throw an exception if the attribute is defined but is
 * not a dimension or integer (enum).
 *
 * @param index Index of the attribute to retrieve.
 * @param name Textual name of attribute for error reporting.
 *
 * @return Attribute dimension value multiplied by the appropriate
 *         metric and truncated to integer pixels.
 * @throws RuntimeException if the TypedArray has already been recycled.
 * @throws UnsupportedOperationException if the attribute is defined but is
 *         not a dimension or integer (enum).
 */
public int getLayoutDimension(@StyleableRes int index, String name) {
    if (mRecycled) {
        throw new RuntimeException("Cannot make calls to a recycled instance!");
    }

    final int attrIndex = index;
    index *= STYLE_NUM_ENTRIES;

    final int[] data = mData;
    final int type = data[index + STYLE_TYPE];
    if (type >= TypedValue.TYPE_FIRST_INT
            && type <= TypedValue.TYPE_LAST_INT) {
        return data[index + STYLE_DATA];
    } else if (type == TypedValue.TYPE_DIMENSION) {
        return TypedValue.complexToDimensionPixelSize(data[index + STYLE_DATA], mMetrics);
    } else if (type == TypedValue.TYPE_ATTRIBUTE) {
        final TypedValue value = mValue;
        getValueAt(index, value);
        throw new UnsupportedOperationException(
                "Failed to resolve attribute at index " + attrIndex + ": " + value);
    }

    throw new UnsupportedOperationException(getPositionDescription()
            + ": You must supply a " + name + " attribute.");
}
 
源代码4 项目: android_9.0.0_r45   文件: TypedArray.java
/**
 * Special version of {@link #getDimensionPixelSize} for retrieving
 * {@link android.view.ViewGroup}'s layout_width and layout_height
 * attributes.  This is only here for performance reasons; applications
 * should use {@link #getDimensionPixelSize}.
 *
 * @param index Index of the attribute to retrieve.
 * @param defValue The default value to return if this attribute is not
 *                 default or contains the wrong type of data.
 *
 * @return Attribute dimension value multiplied by the appropriate
 *         metric and truncated to integer pixels.
 * @throws RuntimeException if the TypedArray has already been recycled.
 */
public int getLayoutDimension(@StyleableRes int index, int defValue) {
    if (mRecycled) {
        throw new RuntimeException("Cannot make calls to a recycled instance!");
    }

    index *= STYLE_NUM_ENTRIES;
    final int[] data = mData;
    final int type = data[index + STYLE_TYPE];
    if (type >= TypedValue.TYPE_FIRST_INT
            && type <= TypedValue.TYPE_LAST_INT) {
        return data[index + STYLE_DATA];
    } else if (type == TypedValue.TYPE_DIMENSION) {
        return TypedValue.complexToDimensionPixelSize(data[index + STYLE_DATA], mMetrics);
    }

    return defValue;
}
 
源代码5 项目: android_9.0.0_r45   文件: Resources.java
/**
 * Returns a themed color integer associated with a particular resource ID.
 * If the resource holds a complex {@link ColorStateList}, then the default
 * color from the set is returned.
 *
 * @param id The desired resource identifier, as generated by the aapt
 *           tool. This integer encodes the package, type, and resource
 *           entry. The value 0 is an invalid identifier.
 * @param theme The theme used to style the color attributes, may be
 *              {@code null}.
 *
 * @throws NotFoundException Throws NotFoundException if the given ID does
 *         not exist.
 *
 * @return A single color value in the form 0xAARRGGBB.
 */
@ColorInt
public int getColor(@ColorRes int id, @Nullable Theme theme) throws NotFoundException {
    final TypedValue value = obtainTempTypedValue();
    try {
        final ResourcesImpl impl = mResourcesImpl;
        impl.getValue(id, value, true);
        if (value.type >= TypedValue.TYPE_FIRST_INT
                && value.type <= TypedValue.TYPE_LAST_INT) {
            return value.data;
        } else if (value.type != TypedValue.TYPE_STRING) {
            throw new NotFoundException("Resource ID #0x" + Integer.toHexString(id)
                    + " type #0x" + Integer.toHexString(value.type) + " is not valid");
        }

        final ColorStateList csl = impl.loadColorStateList(this, value, id, theme);
        return csl.getDefaultColor();
    } finally {
        releaseTempTypedValue(value);
    }
}
 
源代码6 项目: MDPreference   文件: ToolbarRippleDrawable.java
public Builder(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){
	TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RippleDrawable, defStyleAttr, defStyleRes);
	int resId;
	
	backgroundColor(a.getColor(R.styleable.RippleDrawable_rd_backgroundColor, 0));
	backgroundAnimDuration(a.getInteger(R.styleable.RippleDrawable_rd_backgroundAnimDuration, context.getResources().getInteger(android.R.integer.config_mediumAnimTime)));
	rippleType(a.getInteger(R.styleable.RippleDrawable_rd_rippleType, ToolbarRippleDrawable.TYPE_TOUCH));
          delayClickType(a.getInteger(R.styleable.RippleDrawable_rd_delayClick, RippleDrawable.DELAY_CLICK_NONE));
          int type = ThemeUtil.getType(a, R.styleable.RippleDrawable_rd_maxRippleRadius);
          if(type >= TypedValue.TYPE_FIRST_INT && type <= TypedValue.TYPE_LAST_INT)
              maxRippleRadius(a.getInteger(R.styleable.RippleDrawable_rd_maxRippleRadius, -1));
          else
	    maxRippleRadius(a.getDimensionPixelSize(R.styleable.RippleDrawable_rd_maxRippleRadius, ThemeUtil.dpToPx(context, 48)));
	rippleColor(a.getColor(R.styleable.RippleDrawable_rd_rippleColor, ThemeUtil.colorControlHighlight(context, 0)));
	rippleAnimDuration(a.getInteger(R.styleable.RippleDrawable_rd_rippleAnimDuration, context.getResources().getInteger(android.R.integer.config_mediumAnimTime)));
	if((resId = a.getResourceId(R.styleable.RippleDrawable_rd_inInterpolator, 0)) != 0)
		inInterpolator(AnimationUtils.loadInterpolator(context, resId));
	if((resId = a.getResourceId(R.styleable.RippleDrawable_rd_outInterpolator, 0)) != 0)
		outInterpolator(AnimationUtils.loadInterpolator(context, resId));
	
	a.recycle();			
}
 
源代码7 项目: MDPreference   文件: RippleDrawable.java
public Builder(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){
	TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RippleDrawable, defStyleAttr, defStyleRes);
          int type, resId;

	backgroundColor(a.getColor(R.styleable.RippleDrawable_rd_backgroundColor, 0));
	backgroundAnimDuration(a.getInteger(R.styleable.RippleDrawable_rd_backgroundAnimDuration, context.getResources().getInteger(android.R.integer.config_mediumAnimTime)));
	rippleType(a.getInteger(R.styleable.RippleDrawable_rd_rippleType, RippleDrawable.TYPE_TOUCH));
          delayClickType(a.getInteger(R.styleable.RippleDrawable_rd_delayClick, RippleDrawable.DELAY_CLICK_NONE));
          type = ThemeUtil.getType(a, R.styleable.RippleDrawable_rd_maxRippleRadius);
          if(type >= TypedValue.TYPE_FIRST_INT && type <= TypedValue.TYPE_LAST_INT)
              maxRippleRadius(a.getInteger(R.styleable.RippleDrawable_rd_maxRippleRadius, -1));
          else
	    maxRippleRadius(a.getDimensionPixelSize(R.styleable.RippleDrawable_rd_maxRippleRadius, ThemeUtil.dpToPx(context, 48)));
	rippleColor(a.getColor(R.styleable.RippleDrawable_rd_rippleColor, ThemeUtil.colorControlHighlight(context, 0)));
	rippleAnimDuration(a.getInteger(R.styleable.RippleDrawable_rd_rippleAnimDuration, context.getResources().getInteger(android.R.integer.config_mediumAnimTime)));
	if((resId = a.getResourceId(R.styleable.RippleDrawable_rd_inInterpolator, 0)) != 0)
		inInterpolator(AnimationUtils.loadInterpolator(context, resId));
	if((resId = a.getResourceId(R.styleable.RippleDrawable_rd_outInterpolator, 0)) != 0)
		outInterpolator(AnimationUtils.loadInterpolator(context, resId));
	maskType(a.getInteger(R.styleable.RippleDrawable_rd_maskType, Mask.TYPE_RECTANGLE));
	cornerRadius(a.getDimensionPixelSize(R.styleable.RippleDrawable_rd_cornerRadius, 0));
	topLeftCornerRadius(a.getDimensionPixelSize(R.styleable.RippleDrawable_rd_topLeftCornerRadius, mMaskTopLeftCornerRadius));
	topRightCornerRadius(a.getDimensionPixelSize(R.styleable.RippleDrawable_rd_topRightCornerRadius, mMaskTopRightCornerRadius));
	bottomRightCornerRadius(a.getDimensionPixelSize(R.styleable.RippleDrawable_rd_bottomRightCornerRadius, mMaskBottomRightCornerRadius));
	bottomLeftCornerRadius(a.getDimensionPixelSize(R.styleable.RippleDrawable_rd_bottomLeftCornerRadius, mMaskBottomLeftCornerRadius));
	padding(a.getDimensionPixelSize(R.styleable.RippleDrawable_rd_padding, 0));
	left(a.getDimensionPixelSize(R.styleable.RippleDrawable_rd_leftPadding, mMaskLeft));
	right(a.getDimensionPixelSize(R.styleable.RippleDrawable_rd_rightPadding, mMaskRight));
	top(a.getDimensionPixelSize(R.styleable.RippleDrawable_rd_topPadding, mMaskTop));
	bottom(a.getDimensionPixelSize(R.styleable.RippleDrawable_rd_bottomPadding, mMaskBottom));
	
	a.recycle();			
}
 
源代码8 项目: android_9.0.0_r45   文件: Animation.java
/**
 * Size descriptions can appear inthree forms:
 * <ol>
 * <li>An absolute size. This is represented by a number.</li>
 * <li>A size relative to the size of the object being animated. This
 * is represented by a number followed by "%".</li> *
 * <li>A size relative to the size of the parent of object being
 * animated. This is represented by a number followed by "%p".</li>
 * </ol>
 * @param value The typed value to parse
 * @return The parsed version of the description
 */
static Description parseValue(TypedValue value) {
    Description d = new Description();
    if (value == null) {
        d.type = ABSOLUTE;
        d.value = 0;
    } else {
        if (value.type == TypedValue.TYPE_FRACTION) {
            d.type = (value.data & TypedValue.COMPLEX_UNIT_MASK) ==
                    TypedValue.COMPLEX_UNIT_FRACTION_PARENT ?
                            RELATIVE_TO_PARENT : RELATIVE_TO_SELF;
            d.value = TypedValue.complexToFloat(value.data);
            return d;
        } else if (value.type == TypedValue.TYPE_FLOAT) {
            d.type = ABSOLUTE;
            d.value = value.getFloat();
            return d;
        } else if (value.type >= TypedValue.TYPE_FIRST_INT &&
                value.type <= TypedValue.TYPE_LAST_INT) {
            d.type = ABSOLUTE;
            d.value = value.data;
            return d;
        }
    }

    d.type = ABSOLUTE;
    d.value = 0.0f;

    return d;
}
 
源代码9 项目: Android-plugin-support   文件: DynamicApkParser.java
private boolean parseUsesPermission(DynamicApkInfo pkg, Resources res, XmlResourceParser parser,
                                    AttributeSet attrs) throws XmlPullParserException, IOException {
    TypedArray sa = res.obtainAttributes(attrs,
            Hooks.getStyleableArray("AndroidManifestUsesPermission"));

    // Note: don't allow this value to be a reference to a resource
    // that may change.
    String name = sa.getNonResourceString(
            Hooks.getStyleable("AndroidManifestUsesPermission_name"));

    int maxSdkVersion = 0;
    TypedValue val = sa.peekValue(
            Hooks.getStyleable("AndroidManifestUsesPermission_maxSdkVersion"));
    if (val != null) {
        if (val.type >= TypedValue.TYPE_FIRST_INT && val.type <= TypedValue.TYPE_LAST_INT) {
            maxSdkVersion = val.data;
        }
    }

    sa.recycle();

    if ((maxSdkVersion == 0) || (maxSdkVersion >= Build.VERSION.SDK_INT)) {
        if (name != null) {
            int index = pkg.requestedPermissions.indexOf(name);
            if (index == -1) {
                pkg.requestedPermissions.add(name.intern());
            } else {
                Log.w(TAG, "Ignoring duplicate uses-permissions/uses-permissions-sdk-m: "
                        + name + " in package: " + pkg.packageName + " at: "
                        + parser.getPositionDescription());
            }
        }
    }

    XmlUtils.skipCurrentTag(parser);
    return true;
}
 
源代码10 项目: PowerSwitch_Android   文件: ThemeHelper.java
/**
 * Get Color from Theme attribute
 *
 * @param context Activity context
 * @param attr    Attribute ressource ID
 * @return Color as Int
 */
@ColorInt
public static int getThemeAttrColor(Context context, @AttrRes int attr) {
    TypedValue typedValue = new TypedValue();
    if (context.getTheme().resolveAttribute(attr, typedValue, true)) {
        if (typedValue.type >= TypedValue.TYPE_FIRST_INT
                && typedValue.type <= TypedValue.TYPE_LAST_INT) {
            return typedValue.data;
        } else if (typedValue.type == TypedValue.TYPE_STRING) {
            return ContextCompat.getColor(context, typedValue.resourceId);
        }
    }

    return 0;
}
 
源代码11 项目: ArscEditor   文件: ResValueFactory.java
public ResScalarValue factory(int type, int value, String rawValue) throws IOException {
	switch (type) {
	case TypedValue.TYPE_NULL:
		return new ResReferenceValue(mPackage, 0, null);
	case TypedValue.TYPE_REFERENCE:
		return newReference(value, rawValue);
	case TypedValue.TYPE_ATTRIBUTE:
		return newReference(value, rawValue, true);
	case TypedValue.TYPE_STRING:
		return new ResStringValue(rawValue, value);
	case TypedValue.TYPE_FLOAT:
		return new ResFloatValue(Float.intBitsToFloat(value), value, rawValue);
	case TypedValue.TYPE_DIMENSION:
		return new ResDimenValue(value, rawValue);
	case TypedValue.TYPE_FRACTION:
		return new ResFractionValue(value, rawValue);
	case TypedValue.TYPE_INT_BOOLEAN:
		return new ResBoolValue(value != 0, value, rawValue);
	case 0x07:
		return newReference(value, rawValue);
	}

	if (type >= TypedValue.TYPE_FIRST_COLOR_INT && type <= TypedValue.TYPE_LAST_COLOR_INT) {
		return new ResColorValue(value, rawValue);
	}
	if (type >= TypedValue.TYPE_FIRST_INT && type <= TypedValue.TYPE_LAST_INT) {
		return new ResIntValue(value, rawValue, type);
	}

	throw new IOException("Invalid value type: " + type);
}
 
源代码12 项目: android_9.0.0_r45   文件: XmlBlock.java
public boolean getAttributeBooleanValue(int idx,
        boolean defaultValue) {
    int t = nativeGetAttributeDataType(mParseState, idx);
    // Note: don't attempt to convert any other types, because
    // we want to count on aapt doing the conversion for us.
    if (t >= TypedValue.TYPE_FIRST_INT &&
        t <= TypedValue.TYPE_LAST_INT) {
        return nativeGetAttributeData(mParseState, idx) != 0;
    }
    return defaultValue;
}
 
源代码13 项目: apkReSign   文件: AXmlResourceParser.java
public int getAttributeIntValue(int index,int defaultValue) {
	int offset=getAttributeOffset(index);
	int valueType=m_attributes[offset+ATTRIBUTE_IX_VALUE_TYPE];
	if (valueType>=TypedValue.TYPE_FIRST_INT &&
		valueType<=TypedValue.TYPE_LAST_INT)
	{
		return m_attributes[offset+ATTRIBUTE_IX_VALUE_DATA];
	}
	return defaultValue;
}
 
源代码14 项目: android_9.0.0_r45   文件: XmlBlock.java
public int getAttributeUnsignedIntValue(int idx, int defaultValue) {
    int t = nativeGetAttributeDataType(mParseState, idx);
    // Note: don't attempt to convert any other types, because
    // we want to count on aapt doing the conversion for us.
    if (t >= TypedValue.TYPE_FIRST_INT &&
        t <= TypedValue.TYPE_LAST_INT) {
        return nativeGetAttributeData(mParseState, idx);
    }
    return defaultValue;
}
 
源代码15 项目: ratel   文件: AXmlResourceParser.java
@Override
public int getAttributeIntValue(int index, int defaultValue) {
    int offset = getAttributeOffset(index);
    int valueType = m_attributes[offset + ATTRIBUTE_IX_VALUE_TYPE];
    if (valueType >= TypedValue.TYPE_FIRST_INT && valueType <= TypedValue.TYPE_LAST_INT) {
        return m_attributes[offset + ATTRIBUTE_IX_VALUE_DATA];
    }
    return defaultValue;
}
 
源代码16 项目: Auto.js-ApkBuilder   文件: ResValueFactory.java
public ResScalarValue factory(int type, int value, String rawValue) throws IOException {
	switch (type) {
	case TypedValue.TYPE_NULL:
		return new ResReferenceValue(mPackage, 0, null);
	case TypedValue.TYPE_REFERENCE:
		return newReference(value, rawValue);
	case TypedValue.TYPE_ATTRIBUTE:
		return newReference(value, rawValue, true);
	case TypedValue.TYPE_STRING:
		return new ResStringValue(rawValue, value);
	case TypedValue.TYPE_FLOAT:
		return new ResFloatValue(Float.intBitsToFloat(value), value, rawValue);
	case TypedValue.TYPE_DIMENSION:
		return new ResDimenValue(value, rawValue);
	case TypedValue.TYPE_FRACTION:
		return new ResFractionValue(value, rawValue);
	case TypedValue.TYPE_INT_BOOLEAN:
		return new ResBoolValue(value != 0, value, rawValue);
	case 0x07:
		return newReference(value, rawValue);
	}

	if (type >= TypedValue.TYPE_FIRST_COLOR_INT && type <= TypedValue.TYPE_LAST_COLOR_INT) {
		return new ResColorValue(value, rawValue);
	}
	if (type >= TypedValue.TYPE_FIRST_INT && type <= TypedValue.TYPE_LAST_INT) {
		return new ResIntValue(value, rawValue, type);
	}

	throw new IOException("Invalid value type: " + type);
}
 
源代码17 项目: Android-Applications-Info   文件: AXMLPrinter.java
private static String getAttributeValue(AXmlResourceParser parser, int index) {
    int type = parser.getAttributeValueType(index);
    int data = parser.getAttributeValueData(index);
    if (type == TypedValue.TYPE_STRING) {
        return parser.getAttributeValue(index);
    }
    if (type == TypedValue.TYPE_ATTRIBUTE) {
        return String.format("?%s%08X", getPackage(data), data);
    }
    if (type == TypedValue.TYPE_REFERENCE) {
        return String.format("@%s%08X", getPackage(data), data);
    }
    if (type == TypedValue.TYPE_FLOAT) {
        return String.valueOf(Float.intBitsToFloat(data));
    }
    if (type == TypedValue.TYPE_INT_HEX) {
        return String.format("0x%08X", data);
    }
    if (type == TypedValue.TYPE_INT_BOOLEAN) {
        return data != 0 ? "true" : "false";
    }
    if (type == TypedValue.TYPE_DIMENSION) {
        return Float.toString(complexToFloat(data)) +
                DIMENSION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK];
    }
    if (type == TypedValue.TYPE_FRACTION) {
        return Float.toString(complexToFloat(data)) +
                FRACTION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK];
    }
    if (type >= TypedValue.TYPE_FIRST_COLOR_INT && type <= TypedValue.TYPE_LAST_COLOR_INT) {
        return String.format("#%08X", data);
    }
    if (type >= TypedValue.TYPE_FIRST_INT && type <= TypedValue.TYPE_LAST_INT) {
        return String.valueOf(data);
    }
    return String.format("<0x%X, type 0x%02X>", data, type);
}
 
public int getAttributeIntValue(int index, int defaultValue) {
    int offset = getAttributeOffset(index);
    int valueType = m_attributes[offset + ATTRIBUTE_IX_VALUE_TYPE];
    if (valueType >= TypedValue.TYPE_FIRST_INT &&
            valueType <= TypedValue.TYPE_LAST_INT) {
        return m_attributes[offset + ATTRIBUTE_IX_VALUE_DATA];
    }
    return defaultValue;
}
 
源代码19 项目: AndroidComponentPlugin   文件: PackageParser.java
private boolean parseUsesPermission(Package pkg, Resources res, XmlResourceParser parser,
                                        AttributeSet attrs, String[] outError)
            throws XmlPullParserException, IOException {
        TypedArray sa = res.obtainAttributes(attrs,
                com.android.internal.R.styleable.AndroidManifestUsesPermission);

        // Note: don't allow this value to be a reference to a resource
        // that may change.
        String name = sa.getNonResourceString(
                com.android.internal.R.styleable.AndroidManifestUsesPermission_name);
/*
        boolean required = sa.getBoolean(
                com.android.internal.R.styleable.AndroidManifestUsesPermission_required, true);
*/
        boolean required = true; // Optional <uses-permission> not supported

        int maxSdkVersion = 0;
        TypedValue val = sa.peekValue(
                com.android.internal.R.styleable.AndroidManifestUsesPermission_maxSdkVersion);
        if (val != null) {
            if (val.type >= TypedValue.TYPE_FIRST_INT && val.type <= TypedValue.TYPE_LAST_INT) {
                maxSdkVersion = val.data;
            }
        }

        sa.recycle();

        if ((maxSdkVersion == 0) || (maxSdkVersion >= Build.VERSION.RESOURCES_SDK_INT)) {
            if (name != null) {
                int index = pkg.requestedPermissions.indexOf(name);
                if (index == -1) {
                    pkg.requestedPermissions.add(name.intern());
                    pkg.requestedPermissionsRequired.add(required ? Boolean.TRUE : Boolean.FALSE);
                } else {
                    if (pkg.requestedPermissionsRequired.get(index) != required) {
                        outError[0] = "conflicting <uses-permission> entries";
                        mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
                        return false;
                    }
                }
            }
        }

        XmlUtils.skipCurrentTag(parser);
        return true;
    }
 
源代码20 项目: Indic-Keyboard   文件: ResourceUtils.java
public static boolean isIntegerValue(final TypedValue v) {
    return v.type >= TypedValue.TYPE_FIRST_INT && v.type <= TypedValue.TYPE_LAST_INT;
}