List of usage examples for android.util TypedValue TYPE_DIMENSION
int TYPE_DIMENSION
To view the source code for android.util TypedValue TYPE_DIMENSION.
Click Source Link
From source file:com.flashgugu.library.widgets.paginationseekbar.PaginationSeekBar.java
public PaginationSeekBar(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setFocusable(true);/*w w w.ja v a 2 s . c o m*/ setWillNotDraw(false); mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); float density = context.getResources().getDisplayMetrics().density; mTrackHeight = (int) (1 * density); mScrubberHeight = (int) (4 * density); int thumbSize = (int) (density * ThumbDrawable.DEFAULT_SIZE_DP); //Extra pixels for a touch area of 48dp int touchBounds = (int) (density * 32); mAddedTouchBounds = (touchBounds - thumbSize) / 2; TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PaginationSeekBar, R.attr.paginationSeekBarStyle, defStyle); int max = 100; int min = 0; int value = 1; mMirrorForRtl = a.getBoolean(R.styleable.PaginationSeekBar_psb_mirrorForRtl, mMirrorForRtl); mAllowTrackClick = a.getBoolean(R.styleable.PaginationSeekBar_psb_allowTrackClickToDrag, mAllowTrackClick); int indexMax = R.styleable.PaginationSeekBar_psb_max; int indexMin = R.styleable.PaginationSeekBar_psb_min; int indexValue = R.styleable.PaginationSeekBar_psb_value; pageCountPerOneBoard = R.styleable.PaginationSeekBar_psb_pageCountPerOneBoard; final TypedValue out = new TypedValue(); //Not sure why, but we wanted to be able to use dimensions here... if (a.getValue(indexMax, out)) { if (out.type == TypedValue.TYPE_DIMENSION) { max = a.getDimensionPixelSize(indexMax, max); } else { max = a.getInteger(indexMax, max); } } if (a.getValue(indexMin, out)) { if (out.type == TypedValue.TYPE_DIMENSION) { min = a.getDimensionPixelSize(indexMin, min); } else { min = a.getInteger(indexMin, min); } } if (a.getValue(indexValue, out)) { if (out.type == TypedValue.TYPE_DIMENSION) { value = a.getDimensionPixelSize(indexValue, value); } else { value = a.getInteger(indexValue, value); } } if (a.getValue(pageCountPerOneBoard, out)) { pageCountPerOneBoard = a.getInteger(pageCountPerOneBoard, pageCountPerOneBoard); } mMin = min; mMax = Math.max(min + 1, max); mValue = Math.max(min, Math.min(max, value)); updateKeyboardRange(); mIndicatorFormatter = a.getString(R.styleable.PaginationSeekBar_psb_indicatorFormatter); ColorStateList trackColor = a.getColorStateList(R.styleable.PaginationSeekBar_psb_trackColor); ColorStateList progressColor = a.getColorStateList(R.styleable.PaginationSeekBar_psb_progressColor); ColorStateList rippleColor = a.getColorStateList(R.styleable.PaginationSeekBar_psb_rippleColor); int thumbTextColor = a.getColor(R.styleable.PaginationSeekBar_psb_thumbTextColor, Color.WHITE); boolean editMode = isInEditMode(); if (editMode && rippleColor == null) { rippleColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { Color.DKGRAY }); } if (editMode && trackColor == null) { trackColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { Color.GRAY }); } if (editMode && progressColor == null) { progressColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { 0xff009688 }); } if (editMode && thumbTextColor == 0) { thumbTextColor = Color.WHITE; } mRipple = SeekBarCompat.getRipple(rippleColor); if (isLollipopOrGreater) { SeekBarCompat.setBackground(this, mRipple); } else { mRipple.setCallback(this); } TrackRectDrawable shapeDrawable = new TrackRectDrawable(trackColor); mTrack = shapeDrawable; mTrack.setCallback(this); shapeDrawable = new TrackRectDrawable(progressColor); mScrubber = shapeDrawable; mScrubber.setCallback(this); ThumbDrawable thumbDrawable = new ThumbDrawable(progressColor, thumbTextColor, thumbSize, mValue); mThumb = thumbDrawable; mThumb.setCallback(this); mThumb.setBounds(0, 0, mThumb.getIntrinsicWidth(), mThumb.getIntrinsicHeight()); if (!editMode) { mIndicator = new PopupIndicator(context, attrs, defStyle, convertValueToMessage(mMax)); mIndicator.setListener(mFloaterListener); } a.recycle(); setNumericTransformer(new DefaultNumericTransformer()); initPagecountPerOneboard(pageCountPerOneBoard); }
From source file:com.mightyworkouts.seekbar.DiscreteSeekBar.java
public DiscreteSeekBar(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); MightyWorkoutHelper.printLog(CommonUtils.WARN, this.getClass().getName(), "CONSTRUCTOR DiscreteSeekBar"); setFocusable(true);// ww w . j a v a 2s .c om setWillNotDraw(false); /*bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.green_slider_thumb) .copy(Bitmap.Config.ARGB_8888, true);*/ mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); float density = context.getResources().getDisplayMetrics().density; mTrackHeight = (int) (4 * density); mScrubberHeight = (int) (4 * density); int thumbSize = (int) (density * ThumbDrawable.DEFAULT_SIZE_DP); //Extra pixels for a touch area of 48dp int touchBounds = (int) (density * 32); mAddedTouchBounds = (touchBounds - thumbSize) / 2; TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DiscreteSeekBar, defStyleAttr, R.style.Widget_DiscreteSeekBar); int max = 100; int min = 0; int value = 0; mMirrorForRtl = a.getBoolean(R.styleable.DiscreteSeekBar_dsb_mirrorForRtl, mMirrorForRtl); mAllowTrackClick = a.getBoolean(R.styleable.DiscreteSeekBar_dsb_allowTrackClickToDrag, mAllowTrackClick); mIndicatorPopupEnabled = a.getBoolean(R.styleable.DiscreteSeekBar_dsb_indicatorPopupEnabled, mIndicatorPopupEnabled); int indexMax = R.styleable.DiscreteSeekBar_dsb_max; int indexMin = R.styleable.DiscreteSeekBar_dsb_min; int indexValue = R.styleable.DiscreteSeekBar_dsb_value; final TypedValue out = new TypedValue(); //Not sure why, but we wanted to be able to use dimensions here... if (a.getValue(indexMax, out)) { if (out.type == TypedValue.TYPE_DIMENSION) { max = a.getDimensionPixelSize(indexMax, max); } else { max = a.getInteger(indexMax, max); } } if (a.getValue(indexMin, out)) { if (out.type == TypedValue.TYPE_DIMENSION) { min = a.getDimensionPixelSize(indexMin, min); } else { min = a.getInteger(indexMin, min); } } if (a.getValue(indexValue, out)) { if (out.type == TypedValue.TYPE_DIMENSION) { value = a.getDimensionPixelSize(indexValue, value); } else { value = a.getInteger(indexValue, value); } } mMin = min; mMax = Math.max(min + 1, max); mValue = Math.max(min, Math.min(max, value)); updateKeyboardRange(); mIndicatorFormatter = a.getString(R.styleable.DiscreteSeekBar_dsb_indicatorFormatter); ColorStateList trackColor = a.getColorStateList(R.styleable.DiscreteSeekBar_dsb_trackColor); ColorStateList progressColor = a.getColorStateList(R.styleable.DiscreteSeekBar_dsb_progressColor); ColorStateList rippleColor = a.getColorStateList(R.styleable.DiscreteSeekBar_dsb_rippleColor); boolean editMode = isInEditMode(); if (editMode || rippleColor == null) { rippleColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { Color.DKGRAY }); } if (editMode || trackColor == null) { trackColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { Color.GRAY }); } if (editMode || progressColor == null) { progressColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { DEFAULT_THUMB_COLOR }); } mRipple = SeekBarCompat.getRipple(context, rippleColor); if (isLollipopOrGreater) { SeekBarCompat.setBackground(this, mRipple); } else { mRipple.setCallback(this); } TrackRectDrawable shapeDrawable = new TrackRectDrawable(context, trackColor); mTrack = shapeDrawable; mTrack.setCallback(this); shapeDrawable = new TrackRectDrawable(context, progressColor); mScrubber = shapeDrawable; mScrubber.setCallback(this); mThumb = new ThumbDrawable(bitmap, context, progressColor, thumbSize); mThumb.setCallback(this); mThumb.setBounds(0, 0, mThumb.getIntrinsicWidth(), mThumb.getIntrinsicHeight()); if (!editMode) { mIndicator = new PopupIndicator(context, attrs, defStyleAttr, convertValueToMessage(mMax)); mIndicator.setListener(mFloaterListener); } a.recycle(); setNumericTransformer(new DefaultNumericTransformer()); }
From source file:com.example.michaelg.myapplication.Item.discreteseekbar.DiscreteSeekBar.java
public DiscreteSeekBar(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); setFocusable(true);/*from w w w . j a va 2 s . co m*/ setWillNotDraw(false); mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); float density = context.getResources().getDisplayMetrics().density; TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DiscreteSeekBar, defStyleAttr, R.style.Widget_DiscreteSeekBar); int max = 100; int min = 0; int value = 0; mMirrorForRtl = a.getBoolean(R.styleable.DiscreteSeekBar_dsb_mirrorForRtl, mMirrorForRtl); mAllowTrackClick = a.getBoolean(R.styleable.DiscreteSeekBar_dsb_allowTrackClickToDrag, mAllowTrackClick); mIndicatorPopupEnabled = a.getBoolean(R.styleable.DiscreteSeekBar_dsb_indicatorPopupEnabled, mIndicatorPopupEnabled); mTrackHeight = a.getDimensionPixelSize(R.styleable.DiscreteSeekBar_dsb_trackHeight, (int) (1 * density)); mScrubberHeight = a.getDimensionPixelSize(R.styleable.DiscreteSeekBar_dsb_scrubberHeight, (int) (4 * density)); int thumbSize = a.getDimensionPixelSize(R.styleable.DiscreteSeekBar_dsb_thumbSize, (int) (density * ThumbDrawable.DEFAULT_SIZE_DP)); int separation = a.getDimensionPixelSize(R.styleable.DiscreteSeekBar_dsb_indicatorSeparation, (int) (SEPARATION_DP * density)); //Extra pixels for a minimum touch area of 32dp int touchBounds = (int) (density * 32); mAddedTouchBounds = Math.max(0, (touchBounds - thumbSize) / 2); int indexMax = R.styleable.DiscreteSeekBar_dsb_max; int indexMin = R.styleable.DiscreteSeekBar_dsb_min; int indexValue = R.styleable.DiscreteSeekBar_dsb_value; final TypedValue out = new TypedValue(); //Not sure why, but we wanted to be able to use dimensions here... if (a.getValue(indexMax, out)) { if (out.type == TypedValue.TYPE_DIMENSION) { max = a.getDimensionPixelSize(indexMax, max); } else { max = a.getInteger(indexMax, max); } } if (a.getValue(indexMin, out)) { if (out.type == TypedValue.TYPE_DIMENSION) { min = a.getDimensionPixelSize(indexMin, min); } else { min = a.getInteger(indexMin, min); } } if (a.getValue(indexValue, out)) { if (out.type == TypedValue.TYPE_DIMENSION) { value = a.getDimensionPixelSize(indexValue, value); } else { value = a.getInteger(indexValue, value); } } mMin = min; mMax = Math.max(min + 1, max); mValue = Math.max(min, Math.min(max, value)); updateKeyboardRange(); mIndicatorFormatter = a.getString(R.styleable.DiscreteSeekBar_dsb_indicatorFormatter); ColorStateList trackColor = a.getColorStateList(R.styleable.DiscreteSeekBar_dsb_trackColor); ColorStateList progressColor = a.getColorStateList(R.styleable.DiscreteSeekBar_dsb_progressColor); ColorStateList rippleColor = a.getColorStateList(R.styleable.DiscreteSeekBar_dsb_rippleColor); boolean editMode = isInEditMode(); if (editMode || rippleColor == null) { rippleColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { Color.DKGRAY }); } if (editMode || trackColor == null) { trackColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { Color.GRAY }); } if (editMode || progressColor == null) { progressColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { DEFAULT_THUMB_COLOR }); } mRipple = SeekBarCompat.getRipple(rippleColor); if (isLollipopOrGreater) { SeekBarCompat.setBackground(this, mRipple); } else { mRipple.setCallback(this); } TrackRectDrawable shapeDrawable = new TrackRectDrawable(trackColor); mTrack = shapeDrawable; mTrack.setCallback(this); shapeDrawable = new TrackRectDrawable(progressColor); mScrubber = shapeDrawable; mScrubber.setCallback(this); mThumb = new ThumbDrawable(progressColor, thumbSize); mThumb.setCallback(this); mThumb.setBounds(0, 0, mThumb.getIntrinsicWidth(), mThumb.getIntrinsicHeight()); if (!editMode) { mIndicator = new PopupIndicator(context, attrs, defStyleAttr, convertValueToMessage(mMax), thumbSize, thumbSize + mAddedTouchBounds + separation); mIndicator.setListener(mFloaterListener); } a.recycle(); setNumericTransformer(new DefaultNumericTransformer()); }
From source file:android.support.graphics.drawable.AnimatorInflaterCompat.java
private static PropertyValuesHolder getPVH(TypedArray styledAttributes, int valueType, int valueFromId, int valueToId, String propertyName) { TypedValue tvFrom = styledAttributes.peekValue(valueFromId); boolean hasFrom = (tvFrom != null); int fromType = hasFrom ? tvFrom.type : 0; TypedValue tvTo = styledAttributes.peekValue(valueToId); boolean hasTo = (tvTo != null); int toType = hasTo ? tvTo.type : 0; if (valueType == VALUE_TYPE_UNDEFINED) { // Check whether it's color type. If not, fall back to default type (i.e. float type) if ((hasFrom && isColorType(fromType)) || (hasTo && isColorType(toType))) { valueType = VALUE_TYPE_COLOR; } else {//from ww w . j av a 2 s .com valueType = VALUE_TYPE_FLOAT; } } boolean getFloats = (valueType == VALUE_TYPE_FLOAT); PropertyValuesHolder returnValue = null; if (valueType == VALUE_TYPE_PATH) { String fromString = styledAttributes.getString(valueFromId); String toString = styledAttributes.getString(valueToId); PathParser.PathDataNode[] nodesFrom = PathParser.createNodesFromPathData(fromString); PathParser.PathDataNode[] nodesTo = PathParser.createNodesFromPathData(toString); if (nodesFrom != null || nodesTo != null) { if (nodesFrom != null) { TypeEvaluator evaluator = new PathDataEvaluator(); if (nodesTo != null) { if (!PathParser.canMorph(nodesFrom, nodesTo)) { throw new InflateException(" Can't morph from " + fromString + " to " + toString); } returnValue = PropertyValuesHolder.ofObject(propertyName, evaluator, nodesFrom, nodesTo); } else { returnValue = PropertyValuesHolder.ofObject(propertyName, evaluator, (Object) nodesFrom); } } else if (nodesTo != null) { TypeEvaluator evaluator = new PathDataEvaluator(); returnValue = PropertyValuesHolder.ofObject(propertyName, evaluator, (Object) nodesTo); } } } else { TypeEvaluator evaluator = null; // Integer and float value types are handled here. if (valueType == VALUE_TYPE_COLOR) { // special case for colors: ignore valueType and get ints evaluator = ArgbEvaluator.getInstance(); } if (getFloats) { float valueFrom; float valueTo; if (hasFrom) { if (fromType == TypedValue.TYPE_DIMENSION) { valueFrom = styledAttributes.getDimension(valueFromId, 0f); } else { valueFrom = styledAttributes.getFloat(valueFromId, 0f); } if (hasTo) { if (toType == TypedValue.TYPE_DIMENSION) { valueTo = styledAttributes.getDimension(valueToId, 0f); } else { valueTo = styledAttributes.getFloat(valueToId, 0f); } returnValue = PropertyValuesHolder.ofFloat(propertyName, valueFrom, valueTo); } else { returnValue = PropertyValuesHolder.ofFloat(propertyName, valueFrom); } } else { if (toType == TypedValue.TYPE_DIMENSION) { valueTo = styledAttributes.getDimension(valueToId, 0f); } else { valueTo = styledAttributes.getFloat(valueToId, 0f); } returnValue = PropertyValuesHolder.ofFloat(propertyName, valueTo); } } else { int valueFrom; int valueTo; if (hasFrom) { if (fromType == TypedValue.TYPE_DIMENSION) { valueFrom = (int) styledAttributes.getDimension(valueFromId, 0f); } else if (isColorType(fromType)) { valueFrom = styledAttributes.getColor(valueFromId, 0); } else { valueFrom = styledAttributes.getInt(valueFromId, 0); } if (hasTo) { if (toType == TypedValue.TYPE_DIMENSION) { valueTo = (int) styledAttributes.getDimension(valueToId, 0f); } else if (isColorType(toType)) { valueTo = styledAttributes.getColor(valueToId, 0); } else { valueTo = styledAttributes.getInt(valueToId, 0); } returnValue = PropertyValuesHolder.ofInt(propertyName, valueFrom, valueTo); } else { returnValue = PropertyValuesHolder.ofInt(propertyName, valueFrom); } } else { if (hasTo) { if (toType == TypedValue.TYPE_DIMENSION) { valueTo = (int) styledAttributes.getDimension(valueToId, 0f); } else if (isColorType(toType)) { valueTo = styledAttributes.getColor(valueToId, 0); } else { valueTo = styledAttributes.getInt(valueToId, 0); } returnValue = PropertyValuesHolder.ofInt(propertyName, valueTo); } } } if (returnValue != null && evaluator != null) { returnValue.setEvaluator(evaluator); } } return returnValue; }
From source file:in.sc9.discreteslider.DiscreteSlider.java
public DiscreteSlider(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); setFocusable(true);//from w ww . j ava 2 s . c o m setWillNotDraw(false); mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); float density = context.getResources().getDisplayMetrics().density; mTrackHeight = (int) (1 * density); mScrubberHeight = (int) (4 * density); int thumbSize = (int) (density * ThumbDrawable.DEFAULT_SIZE_DP); //Extra pixels for a touch area of 48dp int touchBounds = (int) (density * 32); mAddedTouchBounds = (touchBounds - thumbSize) / 2; TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DiscreteSlider, defStyleAttr, R.style.Widget_DiscreteSeekBar); int max = 100; int min = 0; int value = 0; mMirrorForRtl = a.getBoolean(R.styleable.DiscreteSlider_dsb_mirrorForRtl, mMirrorForRtl); mAllowTrackClick = a.getBoolean(R.styleable.DiscreteSlider_dsb_allowTrackClickToDrag, mAllowTrackClick); mIndicatorPopupEnabled = a.getBoolean(R.styleable.DiscreteSlider_dsb_indicatorPopupEnabled, mIndicatorPopupEnabled); mIndicatorTextFromArray = a.getBoolean(R.styleable.DiscreteSlider_dsb_indicatorTextFromArray, mIndicatorTextFromArray); int indexMax = R.styleable.DiscreteSlider_dsb_max; int indexMin = R.styleable.DiscreteSlider_dsb_min; int indexValue = R.styleable.DiscreteSlider_dsb_value; final TypedValue out = new TypedValue(); //Not sure why, but we wanted to be able to use dimensions here... if (a.getValue(indexMax, out)) { if (out.type == TypedValue.TYPE_DIMENSION) { max = a.getDimensionPixelSize(indexMax, max); } else { max = a.getInteger(indexMax, max); } } if (a.getValue(indexMin, out)) { if (out.type == TypedValue.TYPE_DIMENSION) { min = a.getDimensionPixelSize(indexMin, min); } else { min = a.getInteger(indexMin, min); } } if (a.getValue(indexValue, out)) { if (out.type == TypedValue.TYPE_DIMENSION) { value = a.getDimensionPixelSize(indexValue, value); } else { value = a.getInteger(indexValue, value); } } mMin = min; mMax = Math.max(min + 1, max); mValue = Math.max(min, Math.min(max, value)); updateKeyboardRange(); mIndicatorFormatter = a.getString(R.styleable.DiscreteSlider_dsb_indicatorFormatter); mDiscretePointsEnabled = a.getBoolean(R.styleable.DiscreteSlider_dsb_discretePointsEnabled, false); mDiscretePointsShowAlways = a.getBoolean(R.styleable.DiscreteSlider_dsb_discretePointsShowAlways, false); ColorStateList trackColor = a.getColorStateList(R.styleable.DiscreteSlider_dsb_trackColor); ColorStateList progressColor = a.getColorStateList(R.styleable.DiscreteSlider_dsb_progressColor); ColorStateList rippleColor = a.getColorStateList(R.styleable.DiscreteSlider_dsb_rippleColor); int discretePointColor = a.getColor(R.styleable.DiscreteSlider_dsb_discretePointsColor, Color.RED); mtextColor = a.getColor(R.styleable.DiscreteSlider_dsb_textColor, Color.BLACK); mTextSize = a.getDimensionPixelSize(R.styleable.DiscreteSlider_dsb_TextSize, mTextSize); mTextPaddingTop = a.getDimensionPixelSize(R.styleable.DiscreteSlider_dsb_TextSize, mTextPaddingTop); textStyle = a.getInt(R.styleable.DiscreteSlider_dsb_TextStyle, textStyle); boolean editMode = isInEditMode(); if (editMode || rippleColor == null) { rippleColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { Color.DKGRAY }); } if (editMode || trackColor == null) { trackColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { Color.GRAY }); } if (editMode || progressColor == null) { progressColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { DEFAULT_THUMB_COLOR }); } if (editMode) { discretePointColor = Color.RED; mtextColor = Color.BLACK; } mRipple = SeekBarCompat.getRipple(rippleColor); if (isLollipopOrGreater) { SeekBarCompat.setBackground(this, mRipple); } else { mRipple.setCallback(this); } TrackRectDrawable shapeDrawable = new TrackRectDrawable(trackColor); mTrack = shapeDrawable; mTrack.setCallback(this); shapeDrawable = new TrackRectDrawable(progressColor); mScrubber = shapeDrawable; mScrubber.setCallback(this); mThumb = new ThumbDrawable(progressColor, thumbSize); mThumb.setCallback(this); mThumb.setBounds(0, 0, mThumb.getIntrinsicWidth(), mThumb.getIntrinsicHeight()); textArray = new String[((mMax - mMin) + 1)]; int j = mMin; for (int i = 0; i < ((mMax - mMin) + 1); i++) { if (j <= mMax) { textArray[i] = j + ""; j++; } else break; } if (!editMode) { mIndicator = new PopupIndicator(context, attrs, defStyleAttr, convertValueToMessage(mMax)); mIndicator.setListener(mFloaterListener); } a.recycle(); setNumericTransformer(new DefaultNumericTransformer()); mDiscretePoints = new Paint(Paint.ANTI_ALIAS_FLAG); mDiscretePoints.setColor(discretePointColor); mDiscretePoints.setStyle(Paint.Style.FILL); mDiscretePointsTran = new Paint(Paint.ANTI_ALIAS_FLAG); mDiscretePointsTran.setColor(Color.TRANSPARENT); mDiscretePointsTran.setStyle(Paint.Style.FILL_AND_STROKE); position = new RectF(); }
From source file:devlight.io.library.ArcProgressStackView.java
public ArcProgressStackView(final Context context, final AttributeSet attrs, final int defStyleAttr) { super(context, attrs, defStyleAttr); // Init CPSV//from w w w .ja v a 2 s.c o m // Always draw setWillNotDraw(false); setLayerType(LAYER_TYPE_SOFTWARE, null); ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, null); // Detect if features available mIsFeaturesAvailable = Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB; // Retrieve attributes from xml final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ArcProgressStackView); try { setIsAnimated(typedArray.getBoolean(R.styleable.ArcProgressStackView_apsv_animated, true)); setIsShadowed(typedArray.getBoolean(R.styleable.ArcProgressStackView_apsv_shadowed, true)); setIsRounded(typedArray.getBoolean(R.styleable.ArcProgressStackView_apsv_rounded, false)); setIsDragged(typedArray.getBoolean(R.styleable.ArcProgressStackView_apsv_dragged, false)); setIsLeveled(typedArray.getBoolean(R.styleable.ArcProgressStackView_apsv_leveled, false)); setTypeface(typedArray.getString(R.styleable.ArcProgressStackView_apsv_typeface)); setTextColor(typedArray.getColor(R.styleable.ArcProgressStackView_apsv_text_color, Color.WHITE)); setShadowRadius(typedArray.getDimension(R.styleable.ArcProgressStackView_apsv_shadow_radius, DEFAULT_SHADOW_RADIUS)); setShadowDistance(typedArray.getDimension(R.styleable.ArcProgressStackView_apsv_shadow_distance, DEFAULT_SHADOW_DISTANCE)); setShadowAngle(typedArray.getInteger(R.styleable.ArcProgressStackView_apsv_shadow_angle, (int) DEFAULT_SHADOW_ANGLE)); setShadowColor( typedArray.getColor(R.styleable.ArcProgressStackView_apsv_shadow_color, DEFAULT_SHADOW_COLOR)); setAnimationDuration(typedArray.getInteger(R.styleable.ArcProgressStackView_apsv_animation_duration, DEFAULT_ANIMATION_DURATION)); setStartAngle(typedArray.getInteger(R.styleable.ArcProgressStackView_apsv_start_angle, (int) DEFAULT_START_ANGLE)); setSweepAngle(typedArray.getInteger(R.styleable.ArcProgressStackView_apsv_sweep_angle, (int) DEFAULT_SWEEP_ANGLE)); setProgressModelOffset(typedArray.getDimension(R.styleable.ArcProgressStackView_apsv_model_offset, DEFAULT_MODEL_OFFSET)); setModelBgEnabled(typedArray.getBoolean(R.styleable.ArcProgressStackView_apsv_model_bg_enabled, false)); // Set orientation final int orientationOrdinal = typedArray .getInt(R.styleable.ArcProgressStackView_apsv_indicator_orientation, 0); setIndicatorOrientation( orientationOrdinal == 0 ? IndicatorOrientation.VERTICAL : IndicatorOrientation.HORIZONTAL); // Retrieve interpolator Interpolator interpolator = null; try { final int interpolatorId = typedArray .getResourceId(R.styleable.ArcProgressStackView_apsv_interpolator, 0); interpolator = interpolatorId == 0 ? null : AnimationUtils.loadInterpolator(context, interpolatorId); } catch (Resources.NotFoundException exception) { interpolator = null; exception.printStackTrace(); } finally { setInterpolator(interpolator); } // Set animation info if is available if (mIsFeaturesAvailable) { mProgressAnimator.setFloatValues(MIN_FRACTION, MAX_FRACTION); mProgressAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(final ValueAnimator animation) { mAnimatedFraction = (float) animation.getAnimatedValue(); if (mAnimatorUpdateListener != null) mAnimatorUpdateListener.onAnimationUpdate(animation); postInvalidate(); } }); } // Check whether draw width dimension or fraction if (typedArray.hasValue(R.styleable.ArcProgressStackView_apsv_draw_width)) { final TypedValue drawWidth = new TypedValue(); typedArray.getValue(R.styleable.ArcProgressStackView_apsv_draw_width, drawWidth); if (drawWidth.type == TypedValue.TYPE_DIMENSION) setDrawWidthDimension(drawWidth.getDimension(context.getResources().getDisplayMetrics())); else setDrawWidthFraction(drawWidth.getFraction(MAX_FRACTION, MAX_FRACTION)); } else setDrawWidthFraction(DEFAULT_DRAW_WIDTH_FRACTION); // Set preview models if (isInEditMode()) { String[] preview = null; try { final int previewId = typedArray .getResourceId(R.styleable.ArcProgressStackView_apsv_preview_colors, 0); preview = previewId == 0 ? null : typedArray.getResources().getStringArray(previewId); } catch (Exception exception) { preview = null; exception.printStackTrace(); } finally { if (preview == null) preview = typedArray.getResources().getStringArray(R.array.default_preview); final Random random = new Random(); for (String previewColor : preview) mModels.add( new Model("", random.nextInt((int) MAX_PROGRESS), Color.parseColor(previewColor))); measure(mSize, mSize); } // Set preview model bg color mPreviewModelBgColor = typedArray.getColor(R.styleable.ArcProgressStackView_apsv_preview_bg, Color.LTGRAY); } } finally { typedArray.recycle(); } }
From source file:android.support.v7.app.AppCompatDelegateImplV7.java
private void applyFixedSizeWindow() { TypedArray a = mContext.obtainStyledAttributes(R.styleable.Theme); TypedValue mFixedWidthMajor = null;//from ww w . j av a 2s . c om TypedValue mFixedWidthMinor = null; TypedValue mFixedHeightMajor = null; TypedValue mFixedHeightMinor = null; if (a.hasValue(R.styleable.Theme_windowFixedWidthMajor)) { if (mFixedWidthMajor == null) mFixedWidthMajor = new TypedValue(); a.getValue(R.styleable.Theme_windowFixedWidthMajor, mFixedWidthMajor); } if (a.hasValue(R.styleable.Theme_windowFixedWidthMinor)) { if (mFixedWidthMinor == null) mFixedWidthMinor = new TypedValue(); a.getValue(R.styleable.Theme_windowFixedWidthMinor, mFixedWidthMinor); } if (a.hasValue(R.styleable.Theme_windowFixedHeightMajor)) { if (mFixedHeightMajor == null) mFixedHeightMajor = new TypedValue(); a.getValue(R.styleable.Theme_windowFixedHeightMajor, mFixedHeightMajor); } if (a.hasValue(R.styleable.Theme_windowFixedHeightMinor)) { if (mFixedHeightMinor == null) mFixedHeightMinor = new TypedValue(); a.getValue(R.styleable.Theme_windowFixedHeightMinor, mFixedHeightMinor); } final DisplayMetrics metrics = mContext.getResources().getDisplayMetrics(); final boolean isPortrait = metrics.widthPixels < metrics.heightPixels; int w = ViewGroup.LayoutParams.MATCH_PARENT; int h = ViewGroup.LayoutParams.MATCH_PARENT; final TypedValue tvw = isPortrait ? mFixedWidthMinor : mFixedWidthMajor; if (tvw != null && tvw.type != TypedValue.TYPE_NULL) { if (tvw.type == TypedValue.TYPE_DIMENSION) { w = (int) tvw.getDimension(metrics); } else if (tvw.type == TypedValue.TYPE_FRACTION) { w = (int) tvw.getFraction(metrics.widthPixels, metrics.widthPixels); } } final TypedValue tvh = isPortrait ? mFixedHeightMajor : mFixedHeightMinor; if (tvh != null && tvh.type != TypedValue.TYPE_NULL) { if (tvh.type == TypedValue.TYPE_DIMENSION) { h = (int) tvh.getDimension(metrics); } else if (tvh.type == TypedValue.TYPE_FRACTION) { h = (int) tvh.getFraction(metrics.heightPixels, metrics.heightPixels); } } if (w != ViewGroup.LayoutParams.MATCH_PARENT || h != ViewGroup.LayoutParams.MATCH_PARENT) { mWindow.setLayout(w, h); } a.recycle(); }