Java Code Examples for android.content.res.TypedArray#getFloat()

The following examples show how to use android.content.res.TypedArray#getFloat() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ShapeScrim.java    From deltachat-android with GNU General Public License v3.0 6 votes vote down vote up
public ShapeScrim(Context context, AttributeSet attrs, int defStyleAttr) {
  super(context, attrs, defStyleAttr);

  if (attrs != null) {
    TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.ShapeScrim, 0, 0);
    String     shapeName  = typedArray.getString(R.styleable.ShapeScrim_shape);

    if      ("square".equalsIgnoreCase(shapeName)) this.shape = ShapeType.SQUARE;
    else if ("circle".equalsIgnoreCase(shapeName)) this.shape = ShapeType.CIRCLE;
    else                                           this.shape = ShapeType.SQUARE;

    this.radius = typedArray.getFloat(R.styleable.ShapeScrim_radius, 0.4f);

    typedArray.recycle();
  } else {
    this.shape  = ShapeType.SQUARE;
    this.radius = 0.4f;
  }

  this.eraser = new Paint();
  this.eraser.setColor(0xFFFFFFFF);
  this.eraser.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
}
 
Example 2
Source File: ViewfinderView.java    From QrCodeDemo4 with MIT License 6 votes vote down vote up
public ViewfinderView(Context context, AttributeSet attrs) {
  super(context, attrs);

  //初始化自定义属性信息
  TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.ViewfinderView);
  laserColor = array.getColor(R.styleable.ViewfinderView_laser_color, 0x00FF00);
  cornerColor = array.getColor(R.styleable.ViewfinderView_corner_color, 0x00FF00);
  frameColor = array.getColor(R.styleable.ViewfinderView_frame_color, 0xFFFFFF);
  resultPointColor = array.getColor(R.styleable.ViewfinderView_result_point_color, 0xC0FFFF00);
  maskColor = array.getColor(R.styleable.ViewfinderView_mask_color, 0x60000000);
  resultColor = array.getColor(R.styleable.ViewfinderView_result_color, 0xB0000000);
  labelTextColor = array.getColor(R.styleable.ViewfinderView_label_text_color, 0x90FFFFFF);
  labelText = array.getString(R.styleable.ViewfinderView_label_text);
  labelTextSize = array.getFloat(R.styleable.ViewfinderView_label_text_size, 36f);

  // Initialize these once for performance rather than calling them every time in onDraw().
  paint = new Paint();
  paint.setAntiAlias(true);
  scannerAlpha = 0;
  possibleResultPoints = new HashSet<ResultPoint>(5);


}
 
Example 3
Source File: MaterialBadgeTextView.java    From Android with MIT License 6 votes vote down vote up
private void init(Context context, AttributeSet attrs) {
    setGravity(Gravity.CENTER);
    density = getContext().getResources().getDisplayMetrics().density;
    mShadowRadius = (int) (density * SHADOW_RADIUS);
    shadowYOffset = (int) (density * Y_OFFSET);
    shadowXOffset = (int) (density * X_OFFSET);
    basePadding = (mShadowRadius * 2);
    float textHeight = getTextSize();
    float textWidth = textHeight / 4;
    diffWH = (int) (Math.abs(textHeight - textWidth) / 2);
    int horizontalPadding = basePadding + diffWH;
    setPadding(horizontalPadding, basePadding, horizontalPadding, basePadding);
    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MaterialBadgeTextView);
    backgroundColor = typedArray.getColor(R.styleable.MaterialBadgeTextView_android_background, Color.WHITE);
    borderColor = typedArray.getColor(R.styleable.MaterialBadgeTextView_mbtv_border_color, Color.TRANSPARENT);
    borderWidth = typedArray.getDimension(R.styleable.MaterialBadgeTextView_mbtv_border_width, 0);
    borderAlpha = typedArray.getFloat(R.styleable.MaterialBadgeTextView_mbtv_border_alpha, 1);
    ctType = typedArray.getInt(R.styleable.MaterialBadgeTextView_mbtv_type, DEFAULT_FILL_TYPE);
    typedArray.recycle();
}
 
Example 4
Source File: PagerRecyclerView.java    From timecat with Apache License 2.0 5 votes vote down vote up
private void initAttrs(Context context, AttributeSet attrs, int defStyle) {
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RecyclerViewPager, defStyle, 0);
    mFlingFactor = a.getFloat(R.styleable.RecyclerViewPager_RecyclerViewPager_flingFactor, 0.15f);
    mTriggerOffset = a.getFloat(R.styleable.RecyclerViewPager_RecyclerViewPager_triggerOffset, 0.25f);
    mSinglePageFling = a.getBoolean(R.styleable.RecyclerViewPager_RecyclerViewPager_singlePageFling, mSinglePageFling);
    a.recycle();
}
 
Example 5
Source File: HListView.java    From TV-HorizontalListView with Apache License 2.0 5 votes vote down vote up
public HListView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    TypedArray ta = context.getTheme().obtainStyledAttributes(attrs, R.styleable.HListView, defStyleAttr, 0);
    mItemWidth = ta.getDimensionPixelSize(R.styleable.HListView_item_width, 200);
    mItemHeight = ta.getDimensionPixelSize(R.styleable.HListView_item_height, 200);
    mItemScaleFactor = ta.getFloat(R.styleable.HListView_item_scale_factor, 1.1f);
    mItemScaleDuration = ta.getInteger(R.styleable.HListView_item_scale_duration, 300);
    mSpacing = ta.getDimensionPixelOffset(R.styleable.HListView_spacing, 20);
    mLeftOffSet = ta.getDimensionPixelOffset(R.styleable.HListView_left_offset, 20);
    mRightOffSet = ta.getDimensionPixelOffset(R.styleable.HListView_right_offset, 20);
    mGravity = ta.getInt(R.styleable.HListView_gravity, 1);
    int color = ta.getColor(R.styleable.HListView_bg_color, 0x80ffffff);
    ta.recycle();

    setBackgroundColor(color);
    setPadding(0, 0, 0, 0);

    mScroller = new OverScroller(getContext());
    mGestureDetector = new GestureDetector(getContext(), getOnGestureListener());

    setFocusable(true);
    requestFocus();

    if (isInEditMode()) {
        test();
    }
}
 
Example 6
Source File: SemicircleView.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
public SemicircleView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.SemicircleView, defStyle, 0);
    mCurvature = typedArray.getFloat(R.styleable.SemicircleView_curvature, 1);
    mDistanceTop = typedArray.getDimension(R.styleable.SemicircleView_distance_top, 0);
    maskOutColor = typedArray.getColor(R.styleable.SemicircleView_mask_out_color, maskOutColor);
    maskInColor = typedArray.getColor(R.styleable.SemicircleView_mask_in_color, maskInColor);
    typedArray.recycle();
}
 
Example 7
Source File: IndexBar.java    From ContactsList with Apache License 2.0 5 votes vote down vote up
/******************
 * common
 ******************/

private void initSetting(Context context, AttributeSet attrs) {
    mOnTouchingLetterChangeListener = getDummyListener();
    mNavigators = new ArrayList<>(0);
    mFocusIndex = -1;

    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.IndexBar);
    float textSize = typedArray.getDimension(R.styleable.IndexBar_letterSize, 8);
    int letterColor = typedArray.getColor(R.styleable.IndexBar_letterColor,
            ContextCompat.getColor(getContext(), android.R.color.white));
    mLetterSpacingExtra = typedArray.getFloat(R.styleable.IndexBar_letterSpacingExtra, 1.4f);
    int focusLetterColor = typedArray.getColor(R.styleable.IndexBar_focusLetterColor,
            ContextCompat.getColor(getContext(), android.R.color.white));
    typedArray.recycle();

    mPaint = new Paint();
    mPaint.setTypeface(Typeface.DEFAULT_BOLD);
    mPaint.setAntiAlias(true);
    mPaint.setColor(letterColor);
    mPaint.setTextSize(textSize);

    mFocusPaint = new Paint();
    mFocusPaint.setTypeface(Typeface.DEFAULT_BOLD);
    mFocusPaint.setAntiAlias(true);
    mFocusPaint.setFakeBoldText(true);
    mFocusPaint.setTextSize(textSize);
    mFocusPaint.setColor(focusLetterColor);

}
 
Example 8
Source File: MNHudCircularProgressBar.java    From MNProgressHUD with Apache License 2.0 5 votes vote down vote up
private void init(Context context, AttributeSet attrs) {
    rectF = new RectF();
    TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.MNHudCircularProgressBar, 0, 0);
    //Reading values from the XML layout
    try {
        // Value
        progress = typedArray.getFloat(R.styleable.MNHudCircularProgressBar_mn_progress, progress);
        // StrokeWidth
        strokeWidth = typedArray.getDimension(R.styleable.MNHudCircularProgressBar_mn_progressbar_width, strokeWidth);
        backgroundStrokeWidth = typedArray.getDimension(R.styleable.MNHudCircularProgressBar_mn_background_progressbar_width, backgroundStrokeWidth);
        // Color
        color = typedArray.getInt(R.styleable.MNHudCircularProgressBar_mn_progressbar_color, color);
        backgroundColor = typedArray.getInt(R.styleable.MNHudCircularProgressBar_mn_background_progressbar_color, backgroundColor);
    } finally {
        typedArray.recycle();
    }

    // Init Background
    backgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    backgroundPaint.setColor(backgroundColor);
    backgroundPaint.setStyle(Paint.Style.STROKE);
    backgroundPaint.setStrokeWidth(backgroundStrokeWidth);

    // Init Foreground
    foregroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    foregroundPaint.setColor(color);
    foregroundPaint.setStyle(Paint.Style.STROKE);
    foregroundPaint.setStrokeWidth(strokeWidth);
}
 
Example 9
Source File: ZoomHoverGridView.java    From CustomViewSets with Apache License 2.0 5 votes vote down vote up
public ZoomHoverGridView(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ZoomHoverView);
    mDivider = typedArray.getDimensionPixelOffset(R.styleable.ZoomHoverView_zhv_divider, DensityUtils.dip2px(context, 5));
    mMarginParent = typedArray.getDimensionPixelOffset(R.styleable.ZoomHoverView_zhv_margin_parent, DensityUtils.dip2px(context, 5));
    mColumnNum = typedArray.getInt(R.styleable.ZoomHoverView_zhv_column_num, 3);
    mAnimDuration = typedArray.getInt(R.styleable.ZoomHoverView_zhv_zoom_duration, getResources().getInteger(android.R.integer.config_shortAnimTime));
    mAnimZoomTo = typedArray.getFloat(R.styleable.ZoomHoverView_zhv_zoom_to, 1.2f);
    mUseBaseWH = typedArray.getBoolean(R.styleable.ZoomHoverView_zhv_use_baseWH, false);
    mBaseWidth = typedArray.getDimensionPixelSize(R.styleable.ZoomHoverView_zhv_base_width, DensityUtils.dip2px(context, 50));
    mBaseHeight = typedArray.getDimensionPixelSize(R.styleable.ZoomHoverView_zhv_base_height, DensityUtils.dip2px(context, 50));
    typedArray.recycle();
    mZoomOutInterpolator = mZoomInInterpolator = new AccelerateDecelerateInterpolator();
}
 
Example 10
Source File: CircularSeekBar.java    From circularseekbar with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize the CircularSeekBar with the attributes from the XML style.
 * Uses the defaults defined at the top of this file when an attribute is not specified by the user.
 * @param attrArray TypedArray containing the attributes.
 */
protected void initAttributes(TypedArray attrArray) {
	mCircleXRadius = attrArray.getDimension(R.styleable.CircularSeekBar_circle_x_radius, DEFAULT_CIRCLE_X_RADIUS * DPTOPX_SCALE);
	mCircleYRadius = attrArray.getDimension(R.styleable.CircularSeekBar_circle_y_radius, DEFAULT_CIRCLE_Y_RADIUS * DPTOPX_SCALE);
	mPointerRadius = attrArray.getDimension(R.styleable.CircularSeekBar_pointer_radius, DEFAULT_POINTER_RADIUS * DPTOPX_SCALE);
	mPointerHaloWidth = attrArray.getDimension(R.styleable.CircularSeekBar_pointer_halo_width, DEFAULT_POINTER_HALO_WIDTH * DPTOPX_SCALE);
	mPointerHaloBorderWidth = attrArray.getDimension(R.styleable.CircularSeekBar_pointer_halo_border_width, DEFAULT_POINTER_HALO_BORDER_WIDTH * DPTOPX_SCALE);
	mCircleStrokeWidth = attrArray.getDimension(R.styleable.CircularSeekBar_circle_stroke_width, DEFAULT_CIRCLE_STROKE_WIDTH * DPTOPX_SCALE);

	mPointerColor = attrArray.getColor(R.styleable.CircularSeekBar_pointer_color, DEFAULT_POINTER_COLOR);
	mPointerHaloColor = attrArray.getColor(R.styleable.CircularSeekBar_pointer_halo_color, DEFAULT_POINTER_HALO_COLOR);
	mPointerHaloColorOnTouch = attrArray.getColor(R.styleable.CircularSeekBar_pointer_halo_color_ontouch, DEFAULT_POINTER_HALO_COLOR_ONTOUCH);
	mCircleColor = attrArray.getColor(R.styleable.CircularSeekBar_circle_color, DEFAULT_CIRCLE_COLOR);
	mCircleProgressColor = attrArray.getColor(R.styleable.CircularSeekBar_circle_progress_color, DEFAULT_CIRCLE_PROGRESS_COLOR);
	mCircleFillColor = attrArray.getColor(R.styleable.CircularSeekBar_circle_fill, DEFAULT_CIRCLE_FILL_COLOR);

	mPointerAlpha = Color.alpha(mPointerHaloColor);

	mPointerAlphaOnTouch = attrArray.getInt(R.styleable.CircularSeekBar_pointer_alpha_ontouch, DEFAULT_POINTER_ALPHA_ONTOUCH);
	if (mPointerAlphaOnTouch > 255 || mPointerAlphaOnTouch < 0) {
		mPointerAlphaOnTouch = DEFAULT_POINTER_ALPHA_ONTOUCH;
	}

	mMax = attrArray.getInt(R.styleable.CircularSeekBar_max, DEFAULT_MAX);
	mProgress = attrArray.getInt(R.styleable.CircularSeekBar_progress, DEFAULT_PROGRESS);
	mCustomRadii = attrArray.getBoolean(R.styleable.CircularSeekBar_use_custom_radii, DEFAULT_USE_CUSTOM_RADII);
	mMaintainEqualCircle = attrArray.getBoolean(R.styleable.CircularSeekBar_maintain_equal_circle, DEFAULT_MAINTAIN_EQUAL_CIRCLE);
	mMoveOutsideCircle = attrArray.getBoolean(R.styleable.CircularSeekBar_move_outside_circle, DEFAULT_MOVE_OUTSIDE_CIRCLE);
	lockEnabled = attrArray.getBoolean(R.styleable.CircularSeekBar_lock_enabled, DEFAULT_LOCK_ENABLED);

	// Modulo 360 right now to avoid constant conversion
	mStartAngle = ((360f + (attrArray.getFloat((R.styleable.CircularSeekBar_start_angle), DEFAULT_START_ANGLE) % 360f)) % 360f);
	mEndAngle = ((360f + (attrArray.getFloat((R.styleable.CircularSeekBar_end_angle), DEFAULT_END_ANGLE) % 360f)) % 360f);

	if (mStartAngle == mEndAngle) {
		//mStartAngle = mStartAngle + 1f;
		mEndAngle = mEndAngle - .1f;
	}
}
 
Example 11
Source File: DiscrollViewContent.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
public LayoutParams(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DiscrollView_LayoutParams);
    try {
        mDiscrollveAlpha = a.getBoolean(R.styleable.DiscrollView_LayoutParams_discrollve_alpha, false);
        mDiscrollveScaleX = a.getBoolean(R.styleable.DiscrollView_LayoutParams_discrollve_scaleX, false);
        mDiscrollveScaleY = a.getBoolean(R.styleable.DiscrollView_LayoutParams_discrollve_scaleY, false);
        mDiscrollveTranslation = a.getInt(R.styleable.DiscrollView_LayoutParams_discrollve_translation, -1);
        mDiscrollveThreshold = a.getFloat(R.styleable.DiscrollView_LayoutParams_discrollve_threshold, 0.0f);
        mDiscrollveFromBgColor = a.getColor(R.styleable.DiscrollView_LayoutParams_discrollve_fromBgColor, -1);
        mDiscrollveToBgColor = a.getColor(R.styleable.DiscrollView_LayoutParams_discrollve_toBgColor, -1);
    } finally {
        a.recycle();
    }
}
 
Example 12
Source File: AllAngleExpandableButton.java    From AllAngleExpandableButton with Apache License 2.0 4 votes vote down vote up
private void init(Context context, AttributeSet attrs) {
    paint = new Paint();
    paint.setAntiAlias(true);
    paint.setStyle(Paint.Style.FILL);

    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.AllAngleExpandableButton);
    startAngle = ta.getInteger(R.styleable.AllAngleExpandableButton_aebStartAngleDegree, DEFAULT_START_ANGLE);
    endAngle = ta.getInteger(R.styleable.AllAngleExpandableButton_aebEndAngleDegree, DEFAULT_END_ANGLE);

    buttonGapPx = ta.getDimensionPixelSize(R.styleable.AllAngleExpandableButton_aebButtonGapDp, dp2px(context, DEFAULT_BUTTON_GAP_DP));
    mainButtonSizePx = ta.getDimensionPixelSize(R.styleable.AllAngleExpandableButton_aebMainButtonSizeDp, dp2px(context, DEFAULT_BUTTON_MAIN_SIZE_DP));
    subButtonSizePx = ta.getDimensionPixelSize(R.styleable.AllAngleExpandableButton_aebSubButtonSizeDp, dp2px(context, DEFAULT_BUTTON_SUB_SIZE_DP));
    buttonElevationPx = ta.getDimensionPixelSize(R.styleable.AllAngleExpandableButton_aebButtonElevation, dp2px(context, DEFAULT_BUTTON_ELEVATION_DP));
    buttonSideMarginPx = buttonElevationPx * 2;
    mainButtonTextSize = ta.getDimensionPixelSize(R.styleable.AllAngleExpandableButton_aebMainButtonTextSizeSp, sp2px(context, DEFAULT_BUTTON_TEXT_SIZE_SP));
    subButtonTextSize = ta.getDimensionPixelSize(R.styleable.AllAngleExpandableButton_aebSubButtonTextSizeSp, sp2px(context, DEFAULT_BUTTON_TEXT_SIZE_SP));
    mainButtonTextColor = ta.getColor(R.styleable.AllAngleExpandableButton_aebMainButtonTextColor, DEFAULT_BUTTON_TEXT_COLOR);
    subButtonTextColor = ta.getColor(R.styleable.AllAngleExpandableButton_aebSubButtonTextColor, DEFAULT_BUTTON_TEXT_COLOR);

    expandAnimDuration = ta.getInteger(R.styleable.AllAngleExpandableButton_aebAnimDurationMillis, DEFAULT_EXPAND_ANIMATE_DURATION);
    rotateAnimDuration = ta.getInteger(R.styleable.AllAngleExpandableButton_aebMainButtonRotateAnimDurationMillis, DEFAULT_ROTATE_ANIMATE_DURATION);
    maskBackgroundColor = ta.getInteger(R.styleable.AllAngleExpandableButton_aebMaskBackgroundColor, DEFAULT_MASK_BACKGROUND_COLOR);
    mainButtonRotateDegree = ta.getInteger(R.styleable.AllAngleExpandableButton_aebMainButtonRotateDegree, mainButtonRotateDegree);
    isSelectionMode = ta.getBoolean(R.styleable.AllAngleExpandableButton_aebIsSelectionMode, false);
    rippleEffect = ta.getBoolean(R.styleable.AllAngleExpandableButton_aebRippleEffect, true);
    rippleColor = ta.getColor(R.styleable.AllAngleExpandableButton_aebRippleColor, rippleColor);
    blurBackground = ta.getBoolean(R.styleable.AllAngleExpandableButton_aebBlurBackground, false);
    blurRadius = ta.getFloat(R.styleable.AllAngleExpandableButton_aebBlurRadius, DEFAULT_BLUR_RADIUS);
    ta.recycle();

    if (blurBackground) {
        blur = new Blur();
        blurImageView = new ImageView(getContext());
    }

    if (mainButtonRotateDegree != 0) {
        checkThreshold = expandAnimDuration > rotateAnimDuration ? expandAnimDuration : rotateAnimDuration;
    } else {
        checkThreshold = expandAnimDuration;
    }
    checker = new QuickClickChecker(checkThreshold);

    rippleInfo = new RippleInfo();
    pressPointF = new PointF();
    rawButtonRect = new Rect();
    rawButtonRectF = new RectF();
    shadowMatrix = new Matrix();

    initViewTreeObserver();
    initAnimators();
}
 
Example 13
Source File: HistogramChart.java    From walt with Apache License 2.0 4 votes vote down vote up
public HistogramChart(Context context, AttributeSet attrs) {
    super(context, attrs);
    inflate(getContext(), R.layout.histogram, this);

    barChart = (BarChart) findViewById(R.id.bar_chart);
    findViewById(R.id.button_close_bar_chart).setOnClickListener(this);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.HistogramChart);
    final String descString;
    final int numDataSets;
    final float binWidth;
    try {
        descString = a.getString(R.styleable.HistogramChart_description);
        numDataSets = a.getInteger(R.styleable.HistogramChart_numDataSets, 1);
        binWidth = a.getFloat(R.styleable.HistogramChart_binWidth, 5f);
    } finally {
        a.recycle();
    }

    ArrayList<IBarDataSet> dataSets = new ArrayList<>(numDataSets);
    for (int i = 0; i < numDataSets; i++) {
        final BarDataSet dataSet = new BarDataSet(new ArrayList<BarEntry>(), "");
        dataSet.setColor(ColorTemplate.MATERIAL_COLORS[i]);
        dataSets.add(dataSet);
    }

    BarData barData = new BarData(dataSets);
    barData.setBarWidth((1f - GROUP_SPACE)/numDataSets);
    barChart.setData(barData);
    histogramData = new HistogramData(numDataSets, binWidth);
    groupBars(barData);
    final Description desc = new Description();
    desc.setText(descString);
    desc.setTextSize(12f);
    barChart.setDescription(desc);

    XAxis xAxis = barChart.getXAxis();
    xAxis.setGranularityEnabled(true);
    xAxis.setGranularity(1);
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
    xAxis.setValueFormatter(new IAxisValueFormatter() {
        DecimalFormat df = new DecimalFormat("#.##");

        @Override
        public String getFormattedValue(float value, AxisBase axis) {
            return df.format(histogramData.getDisplayValue(value));
        }
    });

    barChart.setFitBars(true);
    barChart.invalidate();
}
 
Example 14
Source File: ParallaxFrameLayout.java    From Prodigal with Apache License 2.0 4 votes vote down vote up
public LayoutParams(Context c, AttributeSet attrs) {
    super(c, attrs);
    TypedArray a = c.obtainStyledAttributes(attrs, R.styleable.ParallaxLayout_Layout);
    parallaxFactor = a.getFloat(R.styleable.ParallaxLayout_Layout_layout_parallaxFactor, parallaxFactor);
    a.recycle();
}
 
Example 15
Source File: SeekBarPreference.java    From AndroidMaterialPreferences with Apache License 2.0 4 votes vote down vote up
@Override
protected final Object onGetDefaultValue(final TypedArray a, final int index) {
    return a.getFloat(index, 0);
}
 
Example 16
Source File: ViewUtil.java    From MDPreference with Apache License 2.0 4 votes vote down vote up
public static void applyTextAppearance(TextView v, int resId){
    if(resId == 0)
        return;

    String fontFamily = null;
    int typefaceIndex = -1;
    int styleIndex = -1;
    int shadowColor = 0;
    float dx = 0, dy = 0, r = 0;

    TypedArray appearance = v.getContext().obtainStyledAttributes(resId, R.styleable.TextAppearance);
    if (appearance != null) {
        int n = appearance.getIndexCount();
        for (int i = 0; i < n; i++) {
            int attr = appearance.getIndex(i);

            if (attr == R.styleable.TextAppearance_android_textColorHighlight) {
                v.setHighlightColor(appearance.getColor(attr, 0));

            } else if (attr == R.styleable.TextAppearance_android_textColor) {
                v.setTextColor(appearance.getColorStateList(attr));

            } else if (attr == R.styleable.TextAppearance_android_textColorHint) {
                v.setHintTextColor(appearance.getColorStateList(attr));

            } else if (attr == R.styleable.TextAppearance_android_textColorLink) {
                v.setLinkTextColor(appearance.getColorStateList(attr));

            } else if (attr == R.styleable.TextAppearance_android_textSize) {
                v.setTextSize(TypedValue.COMPLEX_UNIT_PX, appearance.getDimensionPixelSize(attr, 0));

            } else if (attr == R.styleable.TextAppearance_android_typeface) {
                typefaceIndex = appearance.getInt(attr, -1);

            } else if (attr == R.styleable.TextAppearance_android_fontFamily) {
                fontFamily = appearance.getString(attr);

            } else if (attr == R.styleable.TextAppearance_tv_fontFamily) {
                fontFamily = appearance.getString(attr);

            } else if (attr == R.styleable.TextAppearance_android_textStyle) {
                styleIndex = appearance.getInt(attr, -1);

            } else if (attr == R.styleable.TextAppearance_android_textAllCaps) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
                    v.setAllCaps(appearance.getBoolean(attr, false));

            } else if (attr == R.styleable.TextAppearance_android_shadowColor) {
                shadowColor = appearance.getInt(attr, 0);

            } else if (attr == R.styleable.TextAppearance_android_shadowDx) {
                dx = appearance.getFloat(attr, 0);

            } else if (attr == R.styleable.TextAppearance_android_shadowDy) {
                dy = appearance.getFloat(attr, 0);

            } else if (attr == R.styleable.TextAppearance_android_shadowRadius) {
                r = appearance.getFloat(attr, 0);

            } else if (attr == R.styleable.TextAppearance_android_elegantTextHeight) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
                    v.setElegantTextHeight(appearance.getBoolean(attr, false));

            } else if (attr == R.styleable.TextAppearance_android_letterSpacing) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
                    v.setLetterSpacing(appearance.getFloat(attr, 0));

            } else if (attr == R.styleable.TextAppearance_android_fontFeatureSettings) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
                    v.setFontFeatureSettings(appearance.getString(attr));

            }
        }

        appearance.recycle();
    }

    if (shadowColor != 0)
        v.setShadowLayer(r, dx, dy, shadowColor);

    Typeface tf = null;
    if (fontFamily != null) {
        tf = TypefaceUtil.load(v.getContext(), fontFamily, styleIndex);
        if (tf != null)
            v.setTypeface(tf);
    }
    if(tf != null) {
        switch (typefaceIndex) {
            case 1:
                tf = Typeface.SANS_SERIF;
                break;
            case 2:
                tf = Typeface.SERIF;
                break;
            case 3:
                tf = Typeface.MONOSPACE;
                break;
        }
        v.setTypeface(tf, styleIndex);
    }
}
 
Example 17
Source File: ParallaxRelativeLayout.java    From material-intro-screen with MIT License 4 votes vote down vote up
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();
}
 
Example 18
Source File: RippleBackground.java    From Conquer with Apache License 2.0 4 votes vote down vote up
private void init(final Context context, final AttributeSet attrs) {
    if (isInEditMode()) return;

    if (null == attrs) {
        throw new IllegalArgumentException("Attributes should be provided to this view,");
    }

    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RippleBackground);
    rippleColor = typedArray.getColor(R.styleable.RippleBackground_rb_color, getResources().getColor(R.color.rippelColor));
    rippleStrokeWidth = typedArray.getDimension(R.styleable.RippleBackground_rb_strokeWidth,
            getResources().getDimension(R.dimen.rippleStrokeWidth));
    rippleRadius = typedArray.getDimension(R.styleable.RippleBackground_rb_radius, getResources().getDimension(R.dimen.rippleRadius));
    rippleDurationTime = typedArray.getInt(R.styleable.RippleBackground_rb_duration, DEFAULT_DURATION_TIME);
    rippleAmount = typedArray.getInt(R.styleable.RippleBackground_rb_rippleAmount, DEFAULT_RIPPLE_COUNT);
    rippleScale = typedArray.getFloat(R.styleable.RippleBackground_rb_scale, DEFAULT_SCALE);
    rippleType = typedArray.getInt(R.styleable.RippleBackground_rb_type, DEFAULT_FILL_TYPE);
    typedArray.recycle();

    rippleDelay = rippleDurationTime / rippleAmount;

    paint = new Paint();
    paint.setAntiAlias(true);
    if (rippleType == DEFAULT_FILL_TYPE) {
        rippleStrokeWidth = 0;
        paint.setStyle(Paint.Style.FILL);
    } else paint.setStyle(Paint.Style.STROKE);
    paint.setColor(rippleColor);

    rippleParams = new LayoutParams((int) (2 * (rippleRadius + rippleStrokeWidth)), (int) (2 * (rippleRadius + rippleStrokeWidth)));
    rippleParams.addRule(CENTER_IN_PARENT, TRUE);

    animatorSet = new AnimatorSet();
    animatorSet.setDuration(rippleDurationTime);
    animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
    animatorList = new ArrayList<Animator>();

    for (int i = 0; i < rippleAmount; i++) {
        RippleView rippleView = new RippleView(getContext());
        addView(rippleView, rippleParams);
        rippleViewList.add(rippleView);
        final ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(rippleView, "ScaleX", 1.0f, rippleScale);
        scaleXAnimator.setRepeatCount(ObjectAnimator.INFINITE);
        scaleXAnimator.setRepeatMode(ObjectAnimator.RESTART);
        scaleXAnimator.setStartDelay(i * rippleDelay);
        animatorList.add(scaleXAnimator);
        final ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(rippleView, "ScaleY", 1.0f, rippleScale);
        scaleYAnimator.setRepeatCount(ObjectAnimator.INFINITE);
        scaleYAnimator.setRepeatMode(ObjectAnimator.RESTART);
        scaleYAnimator.setStartDelay(i * rippleDelay);
        animatorList.add(scaleYAnimator);
        final ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(rippleView, "Alpha", 1.0f, 0f);
        alphaAnimator.setRepeatCount(ObjectAnimator.INFINITE);
        alphaAnimator.setRepeatMode(ObjectAnimator.RESTART);
        alphaAnimator.setStartDelay(i * rippleDelay);
        animatorList.add(alphaAnimator);
    }

    animatorSet.playTogether(animatorList);
}
 
Example 19
Source File: RxRulerWheelView.java    From RxTools-master with Apache License 2.0 4 votes vote down vote up
protected void init(AttributeSet attrs) {
    float density = getResources().getDisplayMetrics().density;
    mCenterMarkWidth = (int) (density * 1.5f + 0.5f);
    mMarkWidth = density;

    mHighlightColor = 0xFFF74C39;
    mMarkTextColor = 0xFF666666;
    mMarkColor = 0xFFEEEEEE;
    mCursorSize = density * 18;
    mCenterTextSize = density * 22;
    mNormalTextSize = density * 18;
    mBottomSpace = density * 6;

    TypedArray ta = attrs == null ? null : getContext().obtainStyledAttributes(attrs, R.styleable.lwvWheelView);
    if (ta != null) {
        mHighlightColor = ta.getColor(R.styleable.lwvWheelView_lwvHighlightColor, mHighlightColor);
        mMarkTextColor = ta.getColor(R.styleable.lwvWheelView_lwvMarkTextColor, mMarkTextColor);
        mMarkColor = ta.getColor(R.styleable.lwvWheelView_lwvMarkColor, mMarkColor);
        mIntervalFactor = ta.getFloat(R.styleable.lwvWheelView_lwvIntervalFactor, mIntervalFactor);
        mMarkRatio = ta.getFloat(R.styleable.lwvWheelView_lwvMarkRatio, mMarkRatio);
        mAdditionCenterMark = ta.getString(R.styleable.lwvWheelView_lwvAdditionalCenterMark);
        mCenterTextSize = ta.getDimension(R.styleable.lwvWheelView_lwvCenterMarkTextSize, mCenterTextSize);
        mNormalTextSize = ta.getDimension(R.styleable.lwvWheelView_lwvMarkTextSize, mNormalTextSize);
        mCursorSize = ta.getDimension(R.styleable.lwvWheelView_lwvCursorSize, mCursorSize);
    }
    mFadeMarkColor = mHighlightColor & 0xAAFFFFFF;
    mIntervalFactor = Math.max(1, mIntervalFactor);
    mMarkRatio = Math.min(1, mMarkRatio);
    mTopSpace = mCursorSize + density * 2;

    mMarkPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mMarkTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mMarkTextPaint.setTextAlign(Paint.Align.CENTER);
    mMarkTextPaint.setColor(mHighlightColor);

    mMarkPaint.setColor(mMarkColor);
    mMarkPaint.setStrokeWidth(mCenterMarkWidth);

    mMarkTextPaint.setTextSize(mCenterTextSize);
    calcIntervalDis();

    mScroller = new OverScroller(getContext());
    mContentRectF = new RectF();

    mGestureDetectorCompat = new GestureDetectorCompat(getContext(), this);

    selectIndex(0);
}
 
Example 20
Source File: CircleProgressView.java    From MoeQuest with Apache License 2.0 3 votes vote down vote up
/**
 * Parse the attributes passed to the view from the XML
 *
 * @param a the attributes to parse
 */
private void parseAttributes(TypedArray a) {

  DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
  barWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, barWidth, metrics);
  rimWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, rimWidth, metrics);
  circleRadius = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, circleRadius,
      metrics);

  circleRadius = (int) a.getDimension(R.styleable.CircleProgressView_matProg_circleRadius,
      circleRadius);

  fillRadius = a.getBoolean(R.styleable.CircleProgressView_matProg_fillRadius, false);

  barWidth = (int) a.getDimension(R.styleable.CircleProgressView_matProg_barWidth, barWidth);

  rimWidth = (int) a.getDimension(R.styleable.CircleProgressView_matProg_rimWidth, rimWidth);

  float baseSpinSpeed = a.getFloat(R.styleable.CircleProgressView_matProg_spinSpeed,
      spinSpeed / 360.0f);
  spinSpeed = baseSpinSpeed * 360;

  barSpinCycleTime = a.getInt(R.styleable.CircleProgressView_matProg_barSpinCycleTime,
      (int) barSpinCycleTime);

  barColor = a.getColor(R.styleable.CircleProgressView_matProg_barColor, barColor);

  rimColor = a.getColor(R.styleable.CircleProgressView_matProg_rimColor, rimColor);

  linearProgress = a.getBoolean(R.styleable.CircleProgressView_matProg_linearProgress, false);

  if (a.getBoolean(R.styleable.CircleProgressView_matProg_progressIndeterminate, false)) {
    spin();
  }

  a.recycle();
}