PercentLayoutInfo info = null; TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.Carbon); float value = array.getFraction(R.styleable.Carbon_carbon_widthPercent, 1, 1, -1f); if (value != -1f) { value = array.getFraction(R.styleable.Carbon_carbon_heightPercent, 1, 1, -1f); if (value != -1f) { if (Log.isLoggable(TAG, Log.VERBOSE)) { value = array.getFraction(R.styleable.Carbon_carbon_marginPercent, 1, 1, -1f); if (value != -1f) { if (Log.isLoggable(TAG, Log.VERBOSE)) { value = array.getFraction(R.styleable.Carbon_carbon_marginLeftPercent, 1, 1, -1f); if (value != -1f) { value = array.getFraction(R.styleable.Carbon_carbon_marginTopPercent, 1, 1, -1f); if (value != -1f) { value = array.getFraction(R.styleable.Carbon_carbon_marginRightPercent, 1, 1, -1f); if (value != -1f) { value = array.getFraction(R.styleable.Carbon_carbon_marginBottomPercent, 1, 1, -1f); if (value != -1f) {
TypedValue value = a.peekValue(attr); if(value.type == TypedValue.TYPE_FRACTION) { mMaxLineWidthPercent = a.getFraction(attr, 1, 1, 0.75f); mMaxLineWidth = 0; TypedValue value = a.peekValue(attr); if(value.type == TypedValue.TYPE_FRACTION) { mMinLineWidthPercent = a.getFraction(attr, 1, 1, 0.25f); mMinLineWidth = 0;
maxLineWidth(0.75f); else if(value.type == TypedValue.TYPE_FRACTION) maxLineWidth(a.getFraction(R.styleable.LinearProgressDrawable_lpd_maxLineWidth, 1, 1, 0.75f)); else maxLineWidth(a.getDimensionPixelSize(R.styleable.LinearProgressDrawable_lpd_maxLineWidth, 0)); minLineWidth(0.25f); else if(value.type == TypedValue.TYPE_FRACTION) minLineWidth(a.getFraction(R.styleable.LinearProgressDrawable_lpd_minLineWidth, 1, 1, 0.25f)); else minLineWidth(a.getDimensionPixelSize(R.styleable.LinearProgressDrawable_lpd_minLineWidth, 0));
@Test public void getFraction_shouldReturnGivenValue() throws Exception { TypedArray typedArray = context.obtainStyledAttributes( Robolectric.buildAttributeSet() .addAttribute(android.R.attr.width, "50%") .build(), new int[]{android.R.attr.width}); assertThat(typedArray.getFraction(0, 100, 1, -1)) .isEqualTo(50f); }
/** * Parse and create key attributes. This constructor is used to parse Row tag. * * @param keyAttr an attributes array of Row tag. * @param defaultKeyWidth a default key width. * @param keyboardWidth the keyboard width that is required to calculate keyWidth attribute. */ public RowAttributes(final TypedArray keyAttr, final float defaultKeyWidth, final int keyboardWidth) { mDefaultKeyWidth = keyAttr.getFraction(R.styleable.Keyboard_Key_keyWidth, keyboardWidth, keyboardWidth, defaultKeyWidth); mDefaultKeyLabelFlags = keyAttr.getInt(R.styleable.Keyboard_Key_keyLabelFlags, 0); mDefaultBackgroundType = keyAttr.getInt(R.styleable.Keyboard_Key_backgroundType, Key.BACKGROUND_TYPE_NORMAL); }
/** * Parse and create key attributes. This constructor is used to parse Row tag. * * @param keyAttr an attributes array of Row tag. * @param defaultKeyWidth a default key width. * @param keyboardWidth the keyboard width that is required to calculate keyWidth attribute. */ public RowAttributes(final TypedArray keyAttr, final float defaultKeyWidth, final int keyboardWidth) { mDefaultKeyWidth = keyAttr.getFraction(R.styleable.Keyboard_Key_keyWidth, keyboardWidth, keyboardWidth, defaultKeyWidth); mDefaultKeyLabelFlags = keyAttr.getInt(R.styleable.Keyboard_Key_keyLabelFlags, 0); mDefaultBackgroundType = keyAttr.getInt(R.styleable.Keyboard_Key_backgroundType, Key.BACKGROUND_TYPE_NORMAL); }
public float getKeyX(final TypedArray keyAttr) { if (keyAttr == null || !keyAttr.hasValue(R.styleable.Keyboard_Key_keyXPos)) { return mCurrentX; } final float keyXPos = keyAttr.getFraction(R.styleable.Keyboard_Key_keyXPos, mParams.mBaseWidth, mParams.mBaseWidth, 0); if (keyXPos >= 0) { return keyXPos + mParams.mLeftPadding; } // If keyXPos is negative, the actual x-coordinate will be // keyboardWidth + keyXPos. // keyXPos shouldn't be less than mCurrentX because drawable area for this // key starts at mCurrentX. Or, this key will overlaps the adjacent key on // its left hand side. final int keyboardRightEdge = mParams.mOccupiedWidth - mParams.mRightPadding; return Math.max(keyXPos + keyboardRightEdge, mCurrentX); }
public float getKeyX(final TypedArray keyAttr) { if (keyAttr == null || !keyAttr.hasValue(R.styleable.Keyboard_Key_keyXPos)) { return mCurrentX; } final float keyXPos = keyAttr.getFraction(R.styleable.Keyboard_Key_keyXPos, mParams.mBaseWidth, mParams.mBaseWidth, 0); if (keyXPos >= 0) { return keyXPos + mParams.mLeftPadding; } // If keyXPos is negative, the actual x-coordinate will be // keyboardWidth + keyXPos. // keyXPos shouldn't be less than mCurrentX because drawable area for this // key starts at mCurrentX. Or, this key will overlaps the adjacent key on // its left hand side. final int keyboardRightEdge = mParams.mOccupiedWidth - mParams.mRightPadding; return Math.max(keyXPos + keyboardRightEdge, mCurrentX); }
/** * Parse and update key attributes using default attributes. This constructor is used * to parse include tag. * * @param keyAttr an attributes array of include tag. * @param defaultRowAttr default Row attributes. * @param keyboardWidth the keyboard width that is required to calculate keyWidth attribute. */ public RowAttributes(final TypedArray keyAttr, final RowAttributes defaultRowAttr, final int keyboardWidth) { mDefaultKeyWidth = keyAttr.getFraction(R.styleable.Keyboard_Key_keyWidth, keyboardWidth, keyboardWidth, defaultRowAttr.mDefaultKeyWidth); mDefaultKeyLabelFlags = keyAttr.getInt(R.styleable.Keyboard_Key_keyLabelFlags, 0) | defaultRowAttr.mDefaultKeyLabelFlags; mDefaultBackgroundType = keyAttr.getInt(R.styleable.Keyboard_Key_backgroundType, defaultRowAttr.mDefaultBackgroundType); } }
/** * Parse and update key attributes using default attributes. This constructor is used * to parse include tag. * * @param keyAttr an attributes array of include tag. * @param defaultRowAttr default Row attributes. * @param keyboardWidth the keyboard width that is required to calculate keyWidth attribute. */ public RowAttributes(final TypedArray keyAttr, final RowAttributes defaultRowAttr, final int keyboardWidth) { mDefaultKeyWidth = keyAttr.getFraction(R.styleable.Keyboard_Key_keyWidth, keyboardWidth, keyboardWidth, defaultRowAttr.mDefaultKeyWidth); mDefaultKeyLabelFlags = keyAttr.getInt(R.styleable.Keyboard_Key_keyLabelFlags, 0) | defaultRowAttr.mDefaultKeyLabelFlags; mDefaultBackgroundType = keyAttr.getInt(R.styleable.Keyboard_Key_backgroundType, defaultRowAttr.mDefaultBackgroundType); } }
public LayoutParams(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = context .obtainStyledAttributes(attrs, R.styleable.FlexboxLayout_Layout); order = a.getInt(R.styleable.FlexboxLayout_Layout_layout_order, ORDER_DEFAULT); flexGrow = a .getFloat(R.styleable.FlexboxLayout_Layout_layout_flexGrow, FLEX_GROW_DEFAULT); flexShrink = a.getFloat(R.styleable.FlexboxLayout_Layout_layout_flexShrink, FLEX_SHRINK_DEFAULT); alignSelf = a .getInt(R.styleable.FlexboxLayout_Layout_layout_alignSelf, ALIGN_SELF_AUTO); flexBasisPercent = a .getFraction(R.styleable.FlexboxLayout_Layout_layout_flexBasisPercent, 1, 1, FLEX_BASIS_PERCENT_DEFAULT); a.recycle(); }
public static float getFraction(final TypedArray a, final int index, final float defValue) { final TypedValue value = a.peekValue(index); if (value == null || !isFractionValue(value)) { return defValue; } return a.getFraction(index, 1, 1, defValue); }
public static float getFraction(final TypedArray a, final int index, final float defValue) { final TypedValue value = a.peekValue(index); if (value == null || !isFractionValue(value)) { return defValue; } return a.getFraction(index, 1, 1, defValue); }
static int getDimensionOrFraction(TypedArray a, int index, int base, int defValue, float scale) { TypedValue value = a.peekValue(index); if (value == null) return defValue; if (value.type == TypedValue.TYPE_DIMENSION) { //Log.i(TAG, "getDimensionOrFraction() got dimension value, defvalue = " + defValue + ". scale = " +scale); return (int) (a.getDimensionPixelOffset(index, defValue) * scale); //Jeremy '11,9,4 } else if (value.type == TypedValue.TYPE_FRACTION) { // Round it to avoid values like 47.9999 from getting truncated //Log.i(TAG, "getDimensionOrFraction() got fraction value, base = " + base + ". defvalue = " + defValue + ". scale = " +scale); return (int) (a.getFraction(index, base, base, defValue) * scale); //Jeremy '12,5,26 add scale. '12,5,27 use (int) instead of round to avoid rouding error } return defValue; } }
/** * Obtains the drag sensitivity from the current theme. * * @param themeResourceId * The resource id of the theme, the drag sensitivity should be obtained from, as an * {@link Integer} value */ private void obtainDragSensitivity(@StyleRes final int themeResourceId) { TypedArray typedArray = getContext().getTheme().obtainStyledAttributes(themeResourceId, new int[]{R.attr.bottomSheetDragSensitivity}); float dragSensitivity = typedArray.getFraction(0, 1, 1, -1); if (dragSensitivity != -1) { setDragSensitivity(dragSensitivity); } }
/** * Obtains the dim amount from the current theme. * * @param themeResourceId * The resource id of the theme, the dim amount should be obtained from, as an * {@link Integer} value */ private void obtainDimAmount(@StyleRes final int themeResourceId) { TypedArray typedArray = getContext().getTheme().obtainStyledAttributes(themeResourceId, new int[]{R.attr.bottomSheetDimAmount}); float dimAmount = typedArray.getFraction(0, 1, 1, -1); if (dimAmount != -1) { setDimAmount(dimAmount); } }
public static float getDimensionOrFraction(final TypedArray a, final int index, final int base, final float defValue) { final TypedValue value = a.peekValue(index); if (value == null) { return defValue; } if (isFractionValue(value)) { return a.getFraction(index, base, base, defValue); } else if (isDimensionValue(value)) { return a.getDimension(index, defValue); } return defValue; }
public static float getDimensionOrFraction(final TypedArray a, final int index, final int base, final float defValue) { final TypedValue value = a.peekValue(index); if (value == null) { return defValue; } if (isFractionValue(value)) { return a.getFraction(index, base, base, defValue); } else if (isDimensionValue(value)) { return a.getDimension(index, defValue); } return defValue; }
public float getKeyWidth(final TypedArray keyAttr, final float keyXPos) { if (keyAttr == null) { return getDefaultKeyWidth(); } final int widthType = ResourceUtils.getEnumValue(keyAttr, R.styleable.Keyboard_Key_keyWidth, KEYWIDTH_NOT_ENUM); switch (widthType) { case KEYWIDTH_FILL_RIGHT: // If keyWidth is fillRight, the actual key width will be determined to fill // out the area up to the right edge of the keyboard. final int keyboardRightEdge = mParams.mOccupiedWidth - mParams.mRightPadding; return keyboardRightEdge - keyXPos; default: // KEYWIDTH_NOT_ENUM return keyAttr.getFraction(R.styleable.Keyboard_Key_keyWidth, mParams.mBaseWidth, mParams.mBaseWidth, getDefaultKeyWidth()); } } }
public float getKeyWidth(final TypedArray keyAttr, final float keyXPos) { if (keyAttr == null) { return getDefaultKeyWidth(); } final int widthType = ResourceUtils.getEnumValue(keyAttr, R.styleable.Keyboard_Key_keyWidth, KEYWIDTH_NOT_ENUM); switch (widthType) { case KEYWIDTH_FILL_RIGHT: // If keyWidth is fillRight, the actual key width will be determined to fill // out the area up to the right edge of the keyboard. final int keyboardRightEdge = mParams.mOccupiedWidth - mParams.mRightPadding; return keyboardRightEdge - keyXPos; default: // KEYWIDTH_NOT_ENUM return keyAttr.getFraction(R.styleable.Keyboard_Key_keyWidth, mParams.mBaseWidth, mParams.mBaseWidth, getDefaultKeyWidth()); } } }