Java Code Examples for android.graphics.Paint#setAntiAlias()

The following examples show how to use android.graphics.Paint#setAntiAlias() . 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: MyButton.java    From quickmark with MIT License 6 votes vote down vote up
@Override
public void draw(Canvas canvas) {
	// TODO Auto-generated method stub

	super.draw(canvas);
	float Radius = getRadius();
	bitmap = createBitmap(bitmap, Radius, Radius);

	Paint paint = new Paint();
	paint.setColor(Color.WHITE);
	paint.setAntiAlias(true);
	canvas.drawCircle(Radius, Radius, Radius, paint);

	canvas.drawCircle(Radius, Radius, Radius * 4 / 5, backgroundPaint);
	paint.setTextAlign(Paint.Align.CENTER);
	paint.setTextSize(Radius * 5 / 3);
 
	canvas.drawText(text, (Radius+Radius * 1 / 10),(Radius+Radius * 1 / 2), paint);
	canvas.drawBitmap(bitmap, 0, 0, null);

}
 
Example 2
Source File: ColorPickerView.java    From ColorPicker with Apache License 2.0 6 votes vote down vote up
private void initPaintTools() {

    satValPaint = new Paint();
    satValTrackerPaint = new Paint();
    hueAlphaTrackerPaint = new Paint();
    alphaPaint = new Paint();
    alphaTextPaint = new Paint();
    borderPaint = new Paint();

    satValTrackerPaint.setStyle(Style.STROKE);
    satValTrackerPaint.setStrokeWidth(DrawingUtils.dpToPx(getContext(), 2));
    satValTrackerPaint.setAntiAlias(true);

    hueAlphaTrackerPaint.setColor(sliderTrackerColor);
    hueAlphaTrackerPaint.setStyle(Style.STROKE);
    hueAlphaTrackerPaint.setStrokeWidth(DrawingUtils.dpToPx(getContext(), 2));
    hueAlphaTrackerPaint.setAntiAlias(true);

    alphaTextPaint.setColor(0xff1c1c1c);
    alphaTextPaint.setTextSize(DrawingUtils.dpToPx(getContext(), 14));
    alphaTextPaint.setAntiAlias(true);
    alphaTextPaint.setTextAlign(Align.CENTER);
    alphaTextPaint.setFakeBoldText(true);
  }
 
Example 3
Source File: CropCircleWithBorderTransformation.java    From ImageLoader with Apache License 2.0 6 votes vote down vote up
private Bitmap circleCrop(BitmapPool pool, Bitmap source) {
    if (source == null) return null;

    int size = (int) (Math.min(source.getWidth(), source.getHeight()) - (mBorderWidth / 2));
    int x = (source.getWidth() - size) / 2;
    int y = (source.getHeight() - size) / 2;
    // TODO this could be acquired from the pool too
    Bitmap squared = Bitmap.createBitmap(source, x, y, size, size);
    Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888);
    if (result == null) {
        result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
    }
    Canvas canvas = new Canvas(result);
    Paint paint = new Paint();
    paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
    paint.setAntiAlias(true);
    float r = size / 2f;
    canvas.drawCircle(r, r, r, paint);
    if (mBorderPaint != null) {
        float borderRadius = r - mBorderWidth / 2;
        canvas.drawCircle(r, r, borderRadius, mBorderPaint);
    }
    return result;

}
 
Example 4
Source File: ProgressView.java    From ProgressFloatingActionButton with Apache License 2.0 6 votes vote down vote up
public ProgressView(Context context, AttributeSet attrs) {
    super(context, attrs);

    // Every attribute is initialized with a default value
    mColor = getThemePrimaryColor(context);

    mStartingProgress = 0;
    mCurrentProgress = 0;
    mTargetProgress = 0;
    mTotalProgress = 100;
    mStepSize = 10;
    mAnimationDuration = 640;

    if (isInEditMode()) {
        mCurrentProgress = 40;
        mTargetProgress = 40;
    }

    paint = new Paint();
    paint.setAntiAlias(true);
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(mColor);
}
 
Example 5
Source File: StrokeView.java    From sinovoice-pathfinder with MIT License 6 votes vote down vote up
private void initView() {
	mPath = new Path();
	mPaint = new Paint();
	mPaint.setAntiAlias(true);
	mPaint.setDither(true);
	mPaint.setStyle(Paint.Style.STROKE);
	mPaint.setStrokeCap(Paint.Cap.ROUND);
	mPaint.setStrokeJoin(Paint.Join.ROUND);
	mPaint.setStrokeWidth(mScriptWidth);
	mPaint.setColor(mScriptColor);

	mBorderPaint = new Paint();
	mBorderPaint.setAntiAlias(true);
	mBorderPaint.setStyle(Paint.Style.STROKE);
	mBorderPaint.setStrokeCap(Paint.Cap.ROUND);
	mBorderPaint.setStrokeJoin(Paint.Join.ROUND);
	mBorderPaint.setStrokeWidth(5);
	mBorderPaint.setColor(0xFF000000);

	mBrushPaint = new Paint();
	mBrushPaint.setStyle(Paint.Style.FILL);
	mBrushPaint.setStrokeCap(Paint.Cap.ROUND);
	mBrushPaint.setStrokeJoin(Paint.Join.ROUND);

}
 
Example 6
Source File: CircleView.java    From AcDisplay with GNU General Public License v2.0 6 votes vote down vote up
private void init() {
    Resources res = getResources();
    mCornerMargin = res.getDimension(R.dimen.circle_corner_margin);
    mRadiusTarget = res.getDimension(R.dimen.circle_radius_target);
    mRadiusDecreaseThreshold = res.getDimension(R.dimen.circle_radius_decrease_threshold);
    mShortAnimTime = res.getInteger(android.R.integer.config_shortAnimTime);
    mMediumAnimTime = res.getInteger(android.R.integer.config_mediumAnimTime);

    mDrawableLeftTopCorner = new CornerIconDrawable(Config.KEY_CORNER_ACTION_LEFT_TOP);
    mDrawableRightTopCorner = new CornerIconDrawable(Config.KEY_CORNER_ACTION_RIGHT_TOP);
    mDrawableLeftBottomCorner = new CornerIconDrawable(Config.KEY_CORNER_ACTION_LEFT_BOTTOM);
    mDrawableRightBottomCorner = new CornerIconDrawable(Config.KEY_CORNER_ACTION_RIGHT_BOTTOM);

    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    initInverseColorFilter();

    setRadius(0);
}
 
Example 7
Source File: DrawUtils.java    From OpenCircle with GNU General Public License v3.0 6 votes vote down vote up
public static Bitmap getCroppedBitmap(Bitmap bitmap)
{
    int fudgeFactor = 0;
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Bitmap output = Bitmap
            .createBitmap(width - fudgeFactor, height - fudgeFactor, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, width - fudgeFactor, height - fudgeFactor);

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawCircle(width / 2 - fudgeFactor, height / 2 - fudgeFactor,
                      width / 2 - fudgeFactor, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    return output;
}
 
Example 8
Source File: Malevich.java    From malevich with MIT License 6 votes vote down vote up
/**
 * Creates a circle bitmap
 *
 * @param bitmap original bitmap source
 */
public static Bitmap getCircleBitmap(Bitmap bitmap) {
    final Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
            bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(output);

    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    final int color = Color.RED;

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawOval(rectF, paint);

    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    bitmap.recycle();
    return output;
}
 
Example 9
Source File: ClockProgressBar.java    From ToDoList with Apache License 2.0 5 votes vote down vote up
private Paint getPaint() {
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setStrokeWidth(6.0f);
    paint.setStyle(Paint.Style.STROKE);
    return paint;
}
 
Example 10
Source File: DrawingImageView.java    From applivery-android-sdk with Apache License 2.0 5 votes vote down vote up
Holder(int color, float width) {
  path = new Path();
  paint = new Paint();
  paint.setAntiAlias(true);
  paint.setStrokeWidth(width);
  paint.setColor(color);
  paint.setStyle(Paint.Style.STROKE);
  paint.setStrokeJoin(Paint.Join.ROUND);
  paint.setStrokeCap(Paint.Cap.ROUND);
}
 
Example 11
Source File: PointCanvasHandler.java    From za-Farmer with MIT License 5 votes vote down vote up
@Override
public void handle(Canvas canvas) {
    Paint paint = new Paint();
    paint.setColor(Color.RED);
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(8);

    //中间画布操作
    paint.setAntiAlias(true);
    paint.setStrokeWidth(3);
    canvas.drawCircle(point.x, point.y, 10, paint);
    canvas.drawLine(point.x - 40, point.y, point.x + 40, point.y, paint);
    canvas.drawLine(point.x, point.y - 40, point.x, point.y + 40, paint);
    paint.setStrokeWidth(8);
}
 
Example 12
Source File: CircleProgress.java    From android with MIT License 5 votes vote down vote up
/**
 * 画中间大的圆环,先画背景,后画绿色进度
 * 半径:view_radius - CIRCLE_GAP * mDividerWidth
 *
 * @param canvas 画布
 */
private void drawCircle(Canvas canvas) {
    int radius = (int) (getViewRadius() - CIRCLE_GAP * mDividerWidth);

    RectF oval = new RectF(
            getCenterX() - radius,
            getCenterY() - radius,
            getCenterX() + radius,
            getCenterY() + radius);

    Paint circlePaint = new Paint();
    circlePaint.setAntiAlias(true);
    circlePaint.setStrokeWidth(CIRCLE_STROKE_WIDTH);
    circlePaint.setStyle(Paint.Style.STROKE);
    circlePaint.setStrokeCap(Paint.Cap.ROUND);

    circlePaint.setColor(mCircleGray);
    canvas.drawArc(oval, CIRCLE_START_ANGLE, CIRCLE_SWEEP_ANGLE, false, circlePaint);

    if (mEndIndicator > mStartIndicator && mProgress >= mStartIndicator) {
        circlePaint.setColor(mCircleGreen);
        float angle = CIRCLE_SWEEP_ANGLE * (mProgress - mStartIndicator) / (mEndIndicator - mStartIndicator);
        canvas.drawArc(oval, CIRCLE_START_ANGLE, angle, false, circlePaint);

        if (!TextUtils.isEmpty(mProgressAlert)) {
            drawAlert(canvas, radius, angle);
        }
    }
}
 
Example 13
Source File: PointFadeIndicator.java    From Dachshund-Tab-Layout with MIT License 5 votes vote down vote up
public PointFadeIndicator(DachshundTabLayout dachshundTabLayout) {
    this.dachshundTabLayout = dachshundTabLayout;

    valueAnimator = new ValueAnimator();
    valueAnimator.setInterpolator(new LinearInterpolator());
    valueAnimator.setDuration(DEFAULT_DURATION);
    valueAnimator.addUpdateListener(this);
    valueAnimator.setIntValues(0,255);

    paint = new Paint();
    paint.setAntiAlias(true);
    paint.setStyle(Paint.Style.FILL);

    startX = (int) dachshundTabLayout.getChildXCenter(dachshundTabLayout.getCurrentPosition());
}
 
Example 14
Source File: RoundedImageView.java    From android-tutorials-glide with MIT License 5 votes vote down vote up
public static Bitmap getCroppedBitmap(Bitmap bmp, int radius) {
    Bitmap sbmp;
    if (bmp.getWidth() != radius || bmp.getHeight() != radius) {
        float smallest = Math.min(bmp.getWidth(), bmp.getHeight());
        float factor = smallest / radius;
        sbmp = Bitmap.createScaledBitmap(bmp, (int) (bmp.getWidth() / factor), (int) (bmp.getHeight() / factor), false);
    }
    else {
        sbmp = bmp;
    }
    Bitmap output = Bitmap.createBitmap(radius, radius,
            Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xffa19774;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, radius, radius);

    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(Color.parseColor("#BAB399"));
    canvas.drawCircle(radius / 2 + 0.7f,
            radius / 2 + 0.7f, radius / 2 + 0.1f, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(sbmp, rect, rect, paint);

    return output;
}
 
Example 15
Source File: PaintRenderer.java    From Ansole with GNU General Public License v2.0 5 votes vote down vote up
public PaintRenderer(int fontSize, ColorScheme scheme) {
    super(scheme);
    mTextPaint = new Paint();
    mTextPaint.setTypeface(Typeface.MONOSPACE);
    mTextPaint.setAntiAlias(true);
    mTextPaint.setTextSize(fontSize);

    mCharHeight = (int) Math.ceil(mTextPaint.getFontSpacing());
    mCharAscent = (int) Math.ceil(mTextPaint.ascent());
    mCharDescent = mCharHeight + mCharAscent;
    mCharWidth = mTextPaint.measureText(EXAMPLE_CHAR, 0, 1);
}
 
Example 16
Source File: ViewfinderView.java    From DoraemonKit with Apache License 2.0 5 votes vote down vote up
public ViewfinderView(Context context, AttributeSet attrs) {
    super(context, attrs);

    //初始化自定义属性信息
    TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.ViewfinderView);

    try {
        laserColor = array.getColor(R.styleable.ViewfinderView_dkLaserColor, 0x00FF00);
        cornerColor = array.getColor(R.styleable.ViewfinderView_dkCornerColor, 0x00FF00);
        frameColor = array.getColor(R.styleable.ViewfinderView_dkFrameColor, 0xFFFFFF);
        resultPointColor = array.getColor(R.styleable.ViewfinderView_dkResultPointColor, 0xC0FFFF00);
        maskColor = array.getColor(R.styleable.ViewfinderView_dkMaskColor, 0x60000000);
        resultColor = array.getColor(R.styleable.ViewfinderView_dkResultColor, 0xB0000000);
        labelTextColor = array.getColor(R.styleable.ViewfinderView_dkLabelTextColor, 0x90FFFFFF);
        labelText = array.getString(R.styleable.ViewfinderView_dkLabelText);
        labelTextSize = array.getFloat(R.styleable.ViewfinderView_dkLabelTextSize, 36f);
    } finally {
        array.recycle();
    }

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


}
 
Example 17
Source File: WaveView.java    From Android-BluetoothKit with Apache License 2.0 4 votes vote down vote up
private void init() {
    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mList = new LinkedList<>();
}
 
Example 18
Source File: ChartView.java    From mytracks with Apache License 2.0 4 votes vote down vote up
/**
 * Constructor.
 * 
 * @param context the context
 */
public ChartView(Context context) {
  super(context);

  series[ELEVATION_SERIES] = new ChartValueSeries(context,
      Integer.MIN_VALUE,
      Integer.MAX_VALUE,
      new int[] { 5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000 },
      R.string.description_elevation_metric,
      R.string.description_elevation_imperial,
      R.color.chart_elevation_fill,
      R.color.chart_elevation_border);
  series[SPEED_SERIES] = new ChartValueSeries(context,
      0,
      Integer.MAX_VALUE,
      new int[] {1, 5, 10, 20, 50, 100 },
      R.string.description_speed_metric,
      R.string.description_speed_imperial,
      R.color.chart_speed_fill,
      R.color.chart_speed_border);
  series[PACE_SERIES] = new ChartValueSeries(context,
      0,
      Integer.MAX_VALUE,
      new int[] {1, 2, 5, 10, 15, 20, 30, 60, 120 },
      R.string.description_pace_metric,
      R.string.description_pace_imperial,
      R.color.chart_pace_fill,
      R.color.chart_pace_border);
  series[HEART_RATE_SERIES] = new ChartValueSeries(context,
      0,
      Integer.MAX_VALUE,
      new int[] {25, 50 },
      R.string.description_sensor_heart_rate,
      R.string.description_sensor_heart_rate,
      R.color.chart_heart_rate_fill,
      R.color.chart_heart_rate_border);
  series[CADENCE_SERIES] = new ChartValueSeries(context,
      0,
      Integer.MAX_VALUE,
      new int[] {5, 10, 25, 50 },
      R.string.description_sensor_cadence,
      R.string.description_sensor_cadence,
      R.color.chart_cadence_fill,
      R.color.chart_cadence_border);
  series[POWER_SERIES] = new ChartValueSeries(context,
      0,
      1000,
      new int[] { 5, 50, 100, 200 },
      R.string.description_sensor_power,
      R.string.description_sensor_power,
      R.color.chart_power_fill,
      R.color.chart_power_border);

  float scale = context.getResources().getDisplayMetrics().density;

  axisPaint = new Paint();
  axisPaint.setStyle(Style.STROKE);
  axisPaint.setColor(context.getResources().getColor(android.R.color.black));
  axisPaint.setAntiAlias(true);
  axisPaint.setTextSize(SMALL_TEXT_SIZE * scale);

  xAxisMarkerPaint = new Paint(axisPaint);
  xAxisMarkerPaint.setTextAlign(Align.CENTER);

  gridPaint = new Paint();
  gridPaint.setStyle(Style.STROKE);
  gridPaint.setColor(context.getResources().getColor(android.R.color.darker_gray));
  gridPaint.setAntiAlias(false);
  gridPaint.setPathEffect(new DashPathEffect(new float[] { 3, 2 }, 0));

  markerPaint = new Paint();
  markerPaint.setStyle(Style.STROKE);
  markerPaint.setColor(context.getResources().getColor(android.R.color.darker_gray));
  markerPaint.setAntiAlias(false);

  pointer = context.getResources().getDrawable(R.drawable.ic_arrow_180);
  pointer.setBounds(0, 0, pointer.getIntrinsicWidth(), pointer.getIntrinsicHeight());

  statisticsMarker = getResources().getDrawable(R.drawable.ic_marker_yellow_pushpin);
  markerWidth = statisticsMarker.getIntrinsicWidth();
  markerHeight = statisticsMarker.getIntrinsicHeight();
  statisticsMarker.setBounds(0, 0, markerWidth, markerHeight);

  waypointMarker = getResources().getDrawable(R.drawable.ic_marker_blue_pushpin);
  waypointMarker.setBounds(0, 0, markerWidth, markerHeight);

  scroller = new Scroller(context);
  setFocusable(true);
  setClickable(true);
  updateDimensions();
}
 
Example 19
Source File: MyWatchFaceService.java    From watchface with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(SurfaceHolder holder) {
    super.onCreate(holder);

    setWatchFaceStyle(new WatchFaceStyle.Builder(MyWatchFaceService.this).build());

    mBackgroundPaint = new Paint();
    mBackgroundPaint.setColor(Color.BLACK);

    /*
     * Toggle the backgroundResIds to see
     * the change of colors due to palette doing its magic.
     */
    final int backgroundResId = R.drawable.custom_background;
    //final int backgroundResId = R.drawable.custom_background2;

    mBackgroundBitmap = BitmapFactory.decodeResource(getResources(), backgroundResId);
    mHandPaint = new Paint();
    mHandPaint.setColor(Color.WHITE);
    mHandPaint.setStrokeWidth(STROKE_WIDTH);
    mHandPaint.setAntiAlias(true);
    mHandPaint.setStrokeCap(Paint.Cap.ROUND);
    mHandPaint.setShadowLayer(SHADOW_RADIUS, 0, 0, Color.BLACK);
    mHandPaint.setStyle(Paint.Style.STROKE);

    // Asynchronous call to generate Palette
    Palette.from(mBackgroundBitmap).generate(
            new Palette.PaletteAsyncListener() {
                public void onGenerated(Palette palette) {
                    /*
                     * Sometimes, palette is unable to generate a color palette
                     * so we need to check that we have one.
                     */
                    if (palette != null) {
                        Log.d("onGenerated", palette.toString());
                        mWatchHandColor = palette.getVibrantColor(Color.WHITE);
                        mWatchHandShadowColor = palette.getDarkMutedColor(Color.BLACK);
                        setWatchHandColor();
                    }
            }
    });



    mCalendar = Calendar.getInstance();
}
 
Example 20
Source File: CustomSlidingTabIndicator.java    From StickyHeaderViewPager with Apache License 2.0 4 votes vote down vote up
public CustomSlidingTabIndicator(Context ctx, AttributeSet attrs, int defStyle) {
    super(ctx, attrs, defStyle);

    //Request HorizontalScrollView to stretch its content to fill the viewport
    setFillViewport(true);

    //This view will not do any drawing on its own, clear this flag if you override onDraw()
    setWillNotDraw(false);

    //Layout to hold all the tabs
    mTabsContainer = new LinearLayout(ctx);
    mTabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    mTabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.MATCH_PARENT));

    //Add the container to HorizontalScrollView as its only child view
    addView(mTabsContainer);

    //Convert the dimensions to DP
    DisplayMetrics dm = getResources().getDisplayMetrics();
    mScrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mScrollOffset, dm);
    mIndicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mIndicatorHeight, dm);
    mUnderlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mUnderlineHeight, dm);
    mDividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mDividerPadding, dm);
    mTabSidePadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mTabSidePadding, dm);
    mTabTopBtmPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mTabTopBtmPadding, dm);
    mDividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mDividerWidth, dm);
    mTabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, mTabTextSize, dm);

    //Get system attrs (android:textSize & android:textColor)
    TypedArray typedArray = ctx.obtainStyledAttributes(attrs, ATTRS);

    mTabTextSize = typedArray.getDimensionPixelSize(0, mTabTextSize);
    mTabTextColor = typedArray.getColor(1, mTabTextColor);

    typedArray.recycle();

    //Get custom attrs
    typedArray = ctx.obtainStyledAttributes(attrs, R.styleable.CustomSlidingTabIndicator);

    mIndicatorColor = typedArray.getColor(R.styleable.CustomSlidingTabIndicator_STIindicatorColor, mIndicatorColor);
    mUnderlineColor = typedArray.getColor(R.styleable.CustomSlidingTabIndicator_STIunderlineColor, mUnderlineColor);
    mDividerColor = typedArray.getColor(R.styleable.CustomSlidingTabIndicator_STIdividerColor, mDividerColor);
    mTabTextColor = typedArray.getColor(R.styleable.CustomSlidingTabIndicator_STItextColor, mTabTextColor);
    mIndicatorHeight = typedArray.getDimensionPixelSize(R.styleable.CustomSlidingTabIndicator_STIindicatorHeight, mIndicatorHeight);
    mUnderlineHeight = typedArray.getDimensionPixelSize(R.styleable.CustomSlidingTabIndicator_STIunderlineHeight, mUnderlineHeight);
    mDividerPadding = typedArray.getDimensionPixelSize(R.styleable.CustomSlidingTabIndicator_STIdividersPadding, mDividerPadding);
    mTabSidePadding = typedArray.getDimensionPixelSize(R.styleable.CustomSlidingTabIndicator_STItabLeftRightPadding, mTabSidePadding);
    mScrollOffset = typedArray.getDimensionPixelSize(R.styleable.CustomSlidingTabIndicator_STIscrollOffSet, mScrollOffset);
    mTabTextSize = typedArray.getDimensionPixelSize(R.styleable.CustomSlidingTabIndicator_STItabTextSize, mTabTextSize);
    mTabBackgroundResId = typedArray.getResourceId(R.styleable.CustomSlidingTabIndicator_STItabBackground, mTabBackgroundResId);
    mShouldExpand = typedArray.getBoolean(R.styleable.CustomSlidingTabIndicator_STIshouldExpand, mShouldExpand);
    mTextAllCap = typedArray.getBoolean(R.styleable.CustomSlidingTabIndicator_STItextCaps, mTextAllCap);
    mTabTopBtmPadding = typedArray.getDimensionPixelSize(R.styleable.CustomSlidingTabIndicator_STItabTopBtmPadding, mTabTopBtmPadding);

    typedArray.recycle();

    //Paint to draw the rectangle box
    mRectPaint = new Paint();
    mRectPaint.setAntiAlias(true);
    mRectPaint.setStyle(Paint.Style.FILL);

    //Paint to draw the divider
    mDividerPaint = new Paint();
    mDividerPaint.setAntiAlias(true);
    mDividerPaint.setStrokeWidth(mDividerWidth);

    //Default: width = wrap_content, height = match_parent
    mDefaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);

    //Expanded: width = 0, height = match_parent, weight = 1.0f
    mExpandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f);
}