@Override protected Object onGetDefaultValue(TypedArray a, int index) { return a.getFloat(index, 0); }
public TwoLevelHeader(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); mSpinnerStyle = SpinnerStyle.FixedBehind; TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.TwoLevelHeader); mMaxRage = ta.getFloat(R.styleable.TwoLevelHeader_srlMaxRage, mMaxRage); mFloorRage = ta.getFloat(R.styleable.TwoLevelHeader_srlFloorRage, mFloorRage); mRefreshRage = ta.getFloat(R.styleable.TwoLevelHeader_srlRefreshRage, mRefreshRage); mFloorDuration = ta.getInt(R.styleable.TwoLevelHeader_srlFloorDuration, mFloorDuration); mEnableTwoLevel = ta.getBoolean(R.styleable.TwoLevelHeader_srlEnableTwoLevel, mEnableTwoLevel); mEnablePullToCloseTwoLevel = ta.getBoolean(R.styleable.TwoLevelHeader_srlEnablePullToCloseTwoLevel, mEnablePullToCloseTwoLevel); ta.recycle(); }
public LayoutParams(Context c, AttributeSet attrs) { super(c, attrs); final TypedArray ta = c.obtainStyledAttributes(attrs, ATTRS); if (ta != null) { this.weight = ta.getFloat(0, 0); ta.recycle(); } } }
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FixedThumb, defStyleAttr, defStyleRes); minAspect = a.getFloat(R.styleable.FixedThumb_minAspect, 0.0f); maxAspect = a.getFloat(R.styleable.FixedThumb_maxAspect, 0.0f); a.recycle(); }
/** * This method extracts all needed values from the styled attributes. * Those are used to configure the view. */ @SuppressWarnings("deprecation") protected void processStyledAttributes(@NonNull TypedArray a) { float targetAspectRatioX = Math.abs(a.getFloat(R.styleable.ucrop_UCropView_ucrop_aspect_ratio_x, DEFAULT_ASPECT_RATIO)); float targetAspectRatioY = Math.abs(a.getFloat(R.styleable.ucrop_UCropView_ucrop_aspect_ratio_y, DEFAULT_ASPECT_RATIO)); if (targetAspectRatioX == SOURCE_IMAGE_ASPECT_RATIO || targetAspectRatioY == SOURCE_IMAGE_ASPECT_RATIO) { mTargetAspectRatio = SOURCE_IMAGE_ASPECT_RATIO; } else { mTargetAspectRatio = targetAspectRatioX / targetAspectRatioY; } }
private void parseTextAttrs(TypedArray a) { if (a.hasValue(R.styleable.BaselineGridTextView_lineHeightMultiplierHint)) { lineHeightMultiplierHint = a.getFloat(R.styleable.BaselineGridTextView_lineHeightMultiplierHint, 1f); } if (a.hasValue(R.styleable.BaselineGridTextView_lineHeightHint)) { lineHeightHint = a.getDimensionPixelSize( R.styleable.BaselineGridTextView_lineHeightHint, 0); } if (a.hasValue(R.styleable.BaselineGridTextView_android_fontFamily)) { fontResId = a.getResourceId(R.styleable.BaselineGridTextView_android_fontFamily, 0); } }
LayoutParams(Context context, AttributeSet attributeSet) { super(context, attributeSet); TypedArray typedArray = context.obtainStyledAttributes(attributeSet, R.styleable.ParallaxLayout_Layout); parallaxFactor = typedArray.getFloat(R.styleable.ParallaxLayout_Layout_layout_parallaxFactor, parallaxFactor); typedArray.recycle(); }
LayoutParams(Context context, AttributeSet attributeSet) { super(context, attributeSet); TypedArray typedArray = context.obtainStyledAttributes(attributeSet, R.styleable.ParallaxLayout_Layout); parallaxFactor = typedArray.getFloat(R.styleable.ParallaxLayout_Layout_layout_parallaxFactor, parallaxFactor); typedArray.recycle(); }
LayoutParams(Context context, AttributeSet attributeSet) { super(context, attributeSet); TypedArray typedArray = context.obtainStyledAttributes(attributeSet, R.styleable.ParallaxLayout_Layout); parallaxFactor = typedArray.getFloat(R.styleable.ParallaxLayout_Layout_layout_parallaxFactor, parallaxFactor); typedArray.recycle(); }
public AspectImageView(Context context, AttributeSet attrs) { super(context, attrs); TypedArray arr = context.obtainStyledAttributes(attrs, new int[] { R.attr.aspect }); aspect = arr.getFloat(0, aspect); arr.recycle(); }
public ElasticDragDismissFrameLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); final TypedArray a = getContext().obtainStyledAttributes( attrs, R.styleable.ElasticDragDismissFrameLayout, 0, 0); if (a.hasValue(R.styleable.ElasticDragDismissFrameLayout_dragDismissDistance)) { dragDismissDistance = a.getDimensionPixelSize(R.styleable .ElasticDragDismissFrameLayout_dragDismissDistance, 0); } else if (a.hasValue(R.styleable.ElasticDragDismissFrameLayout_dragDismissFraction)) { dragDismissFraction = a.getFloat(R.styleable .ElasticDragDismissFrameLayout_dragDismissFraction, dragDismissFraction); } if (a.hasValue(R.styleable.ElasticDragDismissFrameLayout_dragDismissScale)) { dragDismissScale = a.getFloat(R.styleable .ElasticDragDismissFrameLayout_dragDismissScale, dragDismissScale); shouldScale = dragDismissScale != 1f; } if (a.hasValue(R.styleable.ElasticDragDismissFrameLayout_dragElasticity)) { dragElacticity = a.getFloat(R.styleable.ElasticDragDismissFrameLayout_dragElasticity, dragElacticity); } a.recycle(); }
static float getAttrFloat(Context context, AttributeSet attrs, int attr, float defaultValue) { TypedArray a = obtainAttributes(context.getResources(), context.getTheme(), attrs, new int[]{attr}); final float alphaMod = a.getFloat(0, defaultValue); a.recycle(); return alphaMod; }
public Scale(@NonNull Context context, @NonNull AttributeSet attrs) { super(context, attrs); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Scale); setDisappearedScale(a.getFloat(R.styleable.Scale_disappearedScale, mDisappearedScale)); a.recycle(); }
public Scale(@NonNull Context context, @NonNull AttributeSet attrs) { super(context, attrs); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Scale); setDisappearedScale(a.getFloat(R.styleable.Scale_disappearedScale, mDisappearedScale)); a.recycle(); }
public ParallaxScrimageView(Context context, AttributeSet attrs) { super(context, attrs); final TypedArray a = getContext().obtainStyledAttributes( attrs, R.styleable.ParallaxScrimageView); if (a.hasValue(R.styleable.ParallaxScrimageView_scrimColor)) { scrimColor = a.getColor(R.styleable.ParallaxScrimageView_scrimColor, scrimColor); } if (a.hasValue(R.styleable.ParallaxScrimageView_scrimAlpha)) { scrimAlpha = a.getFloat(R.styleable.ParallaxScrimageView_scrimAlpha, scrimAlpha); } if (a.hasValue(R.styleable.ParallaxScrimageView_maxScrimAlpha)) { maxScrimAlpha = a.getFloat(R.styleable.ParallaxScrimageView_maxScrimAlpha, maxScrimAlpha); } if (a.hasValue(R.styleable.ParallaxScrimageView_parallaxFactor)) { parallaxFactor = a.getFloat(R.styleable.ParallaxScrimageView_parallaxFactor, parallaxFactor); } a.recycle(); scrimPaint = new Paint(); scrimPaint.setColor(ColorUtils.modifyAlpha(scrimColor, scrimAlpha)); }
public ArcMotion(@NonNull Context context, @NonNull AttributeSet attrs) { super(context, attrs); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ArcMotion); float minimumVerticalAngle = a.getFloat(R.styleable.ArcMotion_minimumVerticalAngle, DEFAULT_MIN_ANGLE_DEGREES); setMinimumVerticalAngle(minimumVerticalAngle); float minimumHorizontalAngle = a.getFloat(R.styleable.ArcMotion_minimumHorizontalAngle, DEFAULT_MIN_ANGLE_DEGREES); setMinimumHorizontalAngle(minimumHorizontalAngle); float maximumAngle = a.getFloat(R.styleable.ArcMotion_maximumAngle, DEFAULT_MAX_ANGLE_DEGREES); setMaximumAngle(maximumAngle); a.recycle(); }
@SuppressWarnings("ResourceType") public SubtitlePainter(Context context) { int[] viewAttr = {android.R.attr.lineSpacingExtra, android.R.attr.lineSpacingMultiplier}; TypedArray styledAttributes = context.obtainStyledAttributes(null, viewAttr, 0, 0); spacingAdd = styledAttributes.getDimensionPixelSize(0, 0); spacingMult = styledAttributes.getFloat(1, 1); styledAttributes.recycle(); Resources resources = context.getResources(); DisplayMetrics displayMetrics = resources.getDisplayMetrics(); int twoDpInPx = Math.round((2f * displayMetrics.densityDpi) / DisplayMetrics.DENSITY_DEFAULT); outlineWidth = twoDpInPx; shadowRadius = twoDpInPx; shadowOffset = twoDpInPx; textPaint = new TextPaint(); textPaint.setAntiAlias(true); textPaint.setSubpixelText(true); paint = new Paint(); paint.setAntiAlias(true); paint.setStyle(Style.FILL); }
private void init(Context context, AttributeSet attrs) { TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProgressView); int color = a.getColor(R.styleable.ProgressView_color, Color.BLACK); mPaint.setColor(color); mPaint.setStrokeCap(Paint.Cap.SQUARE); mPaint.setStrokeJoin(Paint.Join.MITER); mPaint.setStyle(Paint.Style.STROKE); mIndeterminate = a.getBoolean(R.styleable.ProgressView_indeterminate, true); setProgress(a.getFloat(R.styleable.ProgressView_progress, 0f)); a.recycle(); setupAnimators(); }
@Test public void shouldApplyStylesFromResourceReference() throws Exception { Theme theme = resources.newTheme(); theme.applyStyle(R.style.Theme_AnotherTheme, true); TypedArray a = theme.obtainStyledAttributes(null, R.styleable.CustomView, R.attr.animalStyle, 0); int animalStyleId = a.getResourceId(R.styleable.CustomView_animalStyle, 0); assertThat(animalStyleId).isEqualTo(R.style.Gastropod); assertThat(a.getFloat(R.styleable.CustomView_aspectRatio, 0.2f)).isEqualTo(1.69f); }
@Test public void shouldApplyStylesFromAttributeReference() throws Exception { Theme theme = resources.newTheme(); theme.applyStyle(R.style.Theme_ThirdTheme, true); TypedArray a = theme.obtainStyledAttributes(null, R.styleable.CustomView, R.attr.animalStyle, 0); int animalStyleId = a.getResourceId(R.styleable.CustomView_animalStyle, 0); assertThat(animalStyleId).isEqualTo(R.style.Gastropod); assertThat(a.getFloat(R.styleable.CustomView_aspectRatio, 0.2f)).isEqualTo(1.69f); }