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; } } }
public Drawable getDrawable(TypedArray array, int index, Resources.Theme theme) { TypedValue value = new TypedValue(); array.getValue(index, value); return loadDrawable(value, theme); }
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); }
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 static void initAnimations(AnimatedView view, TypedArray a, int[] ids) { if (((View) view).isInEditMode()) return; int carbon_inAnimation = ids[0]; if (a.hasValue(carbon_inAnimation)) { TypedValue typedValue = new TypedValue(); a.getValue(carbon_inAnimation, typedValue); if (typedValue.resourceId != 0) { view.setInAnimator(AnimatorInflater.loadAnimator(((View) view).getContext(), typedValue.resourceId)); } else { view.setInAnimator(AnimUtils.Style.values()[typedValue.data].getInAnimator()); } } int carbon_outAnimation = ids[1]; if (a.hasValue(carbon_outAnimation)) { TypedValue typedValue = new TypedValue(); a.getValue(carbon_outAnimation, typedValue); if (typedValue.resourceId != 0) { view.setOutAnimator(AnimatorInflater.loadAnimator(((View) view).getContext(), typedValue.resourceId)); } else { view.setOutAnimator(AnimUtils.Style.values()[typedValue.data].getOutAnimator()); } } }
a.getValue(/*com.android.internal.R.styleable.*/AnimatorSet_ordering, orderingValue); int ordering = orderingValue.type == TypedValue.TYPE_INT_DEC ? orderingValue.data : TOGETHER;
@Test public void applyStyleForced() { final Resources.Theme theme = resources.newTheme(); theme.applyStyle(R.style.MyBlackTheme, true); TypedArray arr = theme.obtainStyledAttributes(new int[]{android.R.attr.windowBackground, android.R.attr.textColorHint}); final TypedValue blackBackgroundColor = new TypedValue(); arr.getValue(0, blackBackgroundColor); assertThat(blackBackgroundColor.resourceId).isEqualTo(android.R.color.black); arr.recycle(); theme.applyStyle(R.style.MyBlueTheme, true); arr = theme.obtainStyledAttributes(new int[]{android.R.attr.windowBackground, android.R.attr.textColor, android.R.attr.textColorHint}); final TypedValue blueBackgroundColor = new TypedValue(); arr.getValue(0, blueBackgroundColor); assertThat(blueBackgroundColor.resourceId).isEqualTo(R.color.blue); final TypedValue blueTextColor = new TypedValue(); arr.getValue(1, blueTextColor); assertThat(blueTextColor.resourceId).isEqualTo(R.color.white); final TypedValue blueTextColorHint = new TypedValue(); arr.getValue(2, blueTextColorHint); assertThat(blueTextColorHint.resourceId).isEqualTo(android.R.color.darker_gray); arr.recycle(); }
@Test public void obtainStyledAttributesShouldDereferenceValues() { Resources.Theme theme = resources.newTheme(); theme.applyStyle(R.style.MyBlackTheme, false); TypedArray arr = theme.obtainStyledAttributes(new int[]{android.R.attr.windowBackground}); TypedValue value = new TypedValue(); arr.getValue(0, value); arr.recycle(); assertThat(value.type).isAtLeast(TYPE_FIRST_COLOR_INT); assertThat(value.type).isAtMost(TYPE_LAST_INT); }
@Test public void applyStyleNotForced() { final Resources.Theme theme = resources.newTheme(); // Apply black theme theme.applyStyle(R.style.MyBlackTheme, true); TypedArray arr = theme.obtainStyledAttributes(new int[]{android.R.attr.windowBackground, android.R.attr.textColorHint}); final TypedValue blackBackgroundColor = new TypedValue(); arr.getValue(0, blackBackgroundColor); assertThat(blackBackgroundColor.resourceId).isEqualTo(android.R.color.black); final TypedValue blackTextColorHint = new TypedValue(); arr.getValue(1, blackTextColorHint); assertThat(blackTextColorHint.resourceId).isEqualTo(android.R.color.darker_gray); arr.recycle(); // Apply blue theme theme.applyStyle(R.style.MyBlueTheme, false); arr = theme.obtainStyledAttributes(new int[]{android.R.attr.windowBackground, android.R.attr.textColor, android.R.attr.textColorHint}); final TypedValue blueBackgroundColor = new TypedValue(); arr.getValue(0, blueBackgroundColor); assertThat(blueBackgroundColor.resourceId).isEqualTo(android.R.color.black); final TypedValue blueTextColor = new TypedValue(); arr.getValue(1, blueTextColor); assertThat(blueTextColor.resourceId).isEqualTo(R.color.white); final TypedValue blueTextColorHint = new TypedValue(); arr.getValue(2, blueTextColorHint); assertThat(blueTextColorHint.resourceId).isEqualTo(android.R.color.darker_gray); arr.recycle(); }
@Test public void multiFormatAttributes_integerDecimalValue() { AttributeSet attributeSet = Robolectric.buildAttributeSet().addAttribute(R.attr.multiformat, "16").build(); TypedArray typedArray = resources.obtainAttributes(attributeSet, new int[] {R.attr.multiformat}); TypedValue outValue = new TypedValue(); typedArray.getValue(0, outValue); assertThat(outValue.type).isEqualTo(TypedValue.TYPE_INT_DEC); }
@Test public void multiFormatAttributes_stringValue() { AttributeSet attributeSet = Robolectric.buildAttributeSet().addAttribute(R.attr.multiformat, "Hello World").build(); TypedArray typedArray = resources.obtainAttributes(attributeSet, new int[] {R.attr.multiformat}); TypedValue outValue = new TypedValue(); typedArray.getValue(0, outValue); assertThat(outValue.type).isEqualTo(TypedValue.TYPE_STRING); }
@Test public void multiFormatAttributes_integerHexValue() { AttributeSet attributeSet = Robolectric.buildAttributeSet().addAttribute(R.attr.multiformat, "0x10").build(); TypedArray typedArray = resources.obtainAttributes(attributeSet, new int[] {R.attr.multiformat}); TypedValue outValue = new TypedValue(); typedArray.getValue(0, outValue); assertThat(outValue.type).isEqualTo(TypedValue.TYPE_INT_HEX); }
@Test public void multiFormatAttributes_booleanValue() { AttributeSet attributeSet = Robolectric.buildAttributeSet().addAttribute(R.attr.multiformat, "true").build(); TypedArray typedArray = resources.obtainAttributes(attributeSet, new int[] {R.attr.multiformat}); TypedValue outValue = new TypedValue(); typedArray.getValue(0, outValue); assertThat(outValue.type).isEqualTo(TypedValue.TYPE_INT_BOOLEAN); }
/** * Loading an int array from resource file * * @param resId ResourceId of the integer array * @return int array */ private int[] getIntArray(int resId) { TypedArray array = mResources.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; } array.recycle(); return rc; }
/** * Loading an int array from resource file * * @param resId ResourceId of the integer array * @return int array */ private int[] getIntArray(int resId) { TypedArray array = mResources.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; } array.recycle(); return rc; }
a.getValue(/*com.android.internal.R.styleable.*/AnimatorSet_ordering, orderingValue); int ordering = orderingValue.type == TypedValue.TYPE_INT_DEC ? orderingValue.data : TOGETHER;
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(); }
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; }
TypedValue a = new TypedValue(); getTheme().resolveAttribute(android.R.attr.windowTitleBackgroundStyle, a, true); if(a.type == TypedValue.TYPE_REFERENCE){ TypedArray b = this.obtainStyledAttributes(a.resourceId, new int[]{ android.R.attr.background }); b.getValue(0, a); titleBar.setBackgroundResource(a.resourceid); b.recycle(); }