Java Code Examples for android.graphics.Paint.setColor()

The following are Jave code examples for showing how to use setColor() of the android.graphics.Paint class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: LaunchEnr   File: PopupContainerWithArrow.java   View Source Code Vote up 6 votes
/**
 * Adds an arrow view pointing at the original icon.
 * @param horizontalOffset the horizontal offset of the arrow, so that it
 *                              points at the center of the original icon
 */
private View addArrowView(int horizontalOffset, int verticalOffset, int width, int height) {
    LayoutParams layoutParams = new LayoutParams(width, height);
    if (mIsLeftAligned) {
        layoutParams.gravity = Gravity.START;
        layoutParams.leftMargin = horizontalOffset;
    } else {
        layoutParams.gravity = Gravity.END;
        layoutParams.rightMargin = horizontalOffset;
    }
    if (mIsAboveIcon) {
        layoutParams.topMargin = verticalOffset;
    } else {
        layoutParams.bottomMargin = verticalOffset;
    }

    View arrowView = new View(getContext());
    if (Gravity.isVertical(((FrameLayout.LayoutParams) getLayoutParams()).gravity)) {
        // This is only true if there wasn't room for the container next to the icon,
        // so we centered it instead. In that case we don't want to show the arrow.
        arrowView.setVisibility(INVISIBLE);
    } else {
        ShapeDrawable arrowDrawable = new ShapeDrawable(TriangleShape.create(
                width, height, !mIsAboveIcon));
        Paint arrowPaint = arrowDrawable.getPaint();
        // Note that we have to use getChildAt() instead of getItemViewAt(),
        // since the latter expects the arrow which hasn't been added yet.
        PopupItemView itemAttachedToArrow = (PopupItemView)
                (getChildAt(mIsAboveIcon ? getChildCount() - 1 : 0));
        arrowPaint.setColor(itemAttachedToArrow.getArrowColor(mIsAboveIcon));
        // The corner path effect won't be reflected in the shadow, but shouldn't be noticeable.
        int radius = getResources().getDimensionPixelSize(R.dimen.popup_arrow_corner_radius);
        arrowPaint.setPathEffect(new CornerPathEffect(radius));
        arrowView.setBackground(arrowDrawable);
        arrowView.setElevation(getElevation());
    }
    addView(arrowView, mIsAboveIcon ? getChildCount() : 0, layoutParams);
    return arrowView;
}
 
Example 2
Project: Garbage_RippleView   File: RippleView.java   View Source Code Vote up 6 votes
private void init() {
    setLayerType(LAYER_TYPE_SOFTWARE,null);
    mPaint = new Paint();
    mPaint.setStyle(Paint.Style.FILL);
    mPaint.setStrokeWidth(1);
    mPaint.setAntiAlias(true);
    mPaint.setColor(Color.RED);

    mPath = new Path();


    anim = ValueAnimator.ofFloat(0f,1f);
    anim.setInterpolator(new AccelerateInterpolator());
    anim.setDuration(5000);
    anim.setRepeatCount(ValueAnimator.INFINITE);
    anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            progress = (float)animation.getAnimatedValue();
            invalidate();
        }
    });

    anim.start();

}
 
Example 3
Project: XERUNG   File: ButtonFloat.java   View Source Code Vote up 6 votes
public Bitmap cropCircle(Bitmap bitmap) {
	Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
	Canvas canvas = new Canvas(output);

	final int color = 0xff424242;
	final Paint paint = new Paint();
	final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());

	paint.setAntiAlias(true);
	canvas.drawARGB(0, 0, 0, 0);
	paint.setColor(color);
	canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2,
			bitmap.getWidth() / 2, paint);
	paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
	canvas.drawBitmap(bitmap, rect, rect, paint);
	return output;
}
 
Example 4
Project: NeteaseCloudMusic   File: LineItemDecorator.java   View Source Code Vote up 6 votes
private void drawHrozontal(Canvas c, RecyclerView parent) {
        int childCount = parent.getChildCount();
        if (childCount<1)return;
//        int left = parent.getPaddingLeft()+leftView.getLeft()+leftView.getPaddingLeft();
        int top = parent.getPaddingTop();
        int bottom = parent.getHeight() - parent.getPaddingBottom();

        Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        paint.setColor(Color.LTGRAY);
        for (int i = 0; i < childCount-1; i++) {
            View child = parent.getChildAt(i);
            RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
                    .getLayoutParams();
            int left = child.getRight()+params.rightMargin;
            int right = left + 1;
            c.drawRect(left, top, right, bottom, paint);

        }
    }
 
Example 5
Project: android-agenda-view   File: AgendaView.java   View Source Code Vote up 6 votes
public void drawTimeLabels(Canvas canvas) {
    int px = rulerStartX;
    py = TIME_LABEL_FONT_SIZE + TIME_LABEL_VERTICAL_PADDING;

    Paint mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mTextPaint.setTextSize(TIME_LABEL_FONT_SIZE);
    mTextPaint.setColor(Color.LTGRAY);

    for (int i = 0; i < totalHours; i++) {
        String displayText = String.format("%02d:00", initialHour + i);
        float textWidth = mTextPaint.measureText(displayText);
        canvas.drawText(displayText, px, py, mTextPaint);
        labelXPosition[i] = px;
        px += textWidth + 10;
    }

    viewWidth = px;

    py += TIME_LABEL_VERTICAL_PADDING;

    canvas.drawLine(0, py, viewWidth, py, mTextPaint);
}
 
Example 6
Project: SimpleCustomizeView   File: RingChartView.java   View Source Code Vote up 6 votes
private void init(Context context, AttributeSet attrs) {
    mContext = context;
    TypedArray ta = mContext.getTheme().obtainStyledAttributes(attrs,R.styleable.RingChartView,0,0);
    mChartRadius = ta.getDimension(R.styleable.RingChartView_bigRingRadius,DEFAULT_RING_RADIUS);
    mCenterRadius = ta.getDimension(R.styleable.RingChartView_smallCircleRadius,DEFAULT_CENTER_RADIUS);
    mTextSize =ta.getDimension(R.styleable.RingChartView_ringTextSize,DEFAULT_TEXTSIZE);
    ta.recycle();
    paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setStyle(Paint.Style.FILL);

    textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    textPaint.setStyle(Paint.Style.FILL);
    textPaint.setTextSize(mTextSize);
    textPaint.setColor(mTextColor);

    wcPath = new Path();
}
 
Example 7
Project: TensorflowAndroidDemo   File: BorderedText.java   View Source Code Vote up 6 votes
/**
 * Create a bordered text object with the specified interior and exterior colors, text size and
 * alignment.
 *
 * @param interiorColor the interior text color
 * @param exteriorColor the exterior text color
 * @param textSize text size in pixels
 */
public BorderedText(final int interiorColor, final int exteriorColor, final float textSize) {
  interiorPaint = new Paint();
  interiorPaint.setTextSize(textSize);
  interiorPaint.setColor(interiorColor);
  interiorPaint.setStyle(Style.FILL);
  interiorPaint.setAntiAlias(false);
  interiorPaint.setAlpha(255);

  exteriorPaint = new Paint();
  exteriorPaint.setTextSize(textSize);
  exteriorPaint.setColor(exteriorColor);
  exteriorPaint.setStyle(Style.FILL_AND_STROKE);
  exteriorPaint.setStrokeWidth(textSize / 8);
  exteriorPaint.setAntiAlias(false);
  exteriorPaint.setAlpha(255);

  this.textSize = textSize;
}
 
Example 8
Project: Android-PickerDialog   File: WheelView.java   View Source Code Vote up 6 votes
private void initPaints() {
    paintOuterText = new Paint();
    paintOuterText.setColor(textColorOut);
    paintOuterText.setAntiAlias(true);
    paintOuterText.setTypeface(Typeface.MONOSPACE);
    paintOuterText.setTextSize(textSize);

    paintCenterText = new Paint();
    paintCenterText.setColor(textColorCenter);
    paintCenterText.setAntiAlias(true);
    paintCenterText.setTextScaleX(1.1F);
    paintCenterText.setTypeface(Typeface.MONOSPACE);
    paintCenterText.setTextSize(textSize);

    paintIndicator = new Paint();
    paintIndicator.setColor(dividerColor);
    paintIndicator.setAntiAlias(true);

    if (android.os.Build.VERSION.SDK_INT >= 11) {
        setLayerType(LAYER_TYPE_SOFTWARE, null);
    }
}
 
Example 9
Project: odoo-work   File: BezelImageView.java   View Source Code Vote up 6 votes
private void otherInit() {
    // Other initialization
    mBlackPaint = new Paint();
    mBlackPaint.setColor(0xff000000);

    mMaskedPaint = new Paint();
    mMaskedPaint
            .setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));

    // Always want a cache allocated.
    mCacheBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);

    if (mDesaturateOnPress) {
        // Create a desaturate color filter for pressed state.
        ColorMatrix cm = new ColorMatrix();
        cm.setSaturation(0);
        mDesaturateColorFilter = new ColorMatrixColorFilter(cm);
    }
}
 
Example 10
Project: javaide   File: ErrorSpan.java   View Source Code Vote up 5 votes
@Override
public void draw(@NonNull Canvas canvas, CharSequence text, int start, int end, float x, int top,
                 int y, int bottom, @NonNull Paint paint) {
    RectF rect = new RectF(x, top, x + measureText(paint, text, start, end), bottom);

    Paint rectPaint = new Paint(paint);
    rectPaint.setAntiAlias(true);
    rectPaint.setStrokeWidth(2);
    rectPaint.setStyle(Paint.Style.STROKE);
    rectPaint.setColor(color);
    canvas.drawRect(rect, rectPaint);

    canvas.drawText(text, start, end, x, y, paint);
}
 
Example 11
Project: MySelfDemo   File: MyView2.java   View Source Code Vote up 5 votes
/**
 * 画线   一天线
 *
 * @param canvas
 */
private void drawPath2(Canvas canvas) {
    Paint paint = new Paint();
    paint.setColor(Color.BLUE);
    paint.setStyle(Paint.Style.STROKE);
    paint.setAntiAlias(true);
    Path path = new Path();
    path.lineTo(100, 100);
    path.rLineTo(100, 0); //r 是相对路径 意思是从上次的(100,100)为起点,相对来说画一条向右 100 的直线
    path.quadTo(100, 100, 500, 500);
    canvas.drawPath(path, paint);
}
 
Example 12
Project: BBSSDK-for-Android   File: ImageUtils.java   View Source Code Vote up 5 votes
/**
 * 转为圆角图片
 *
 * @param src         源图片
 * @param radius      圆角的度数
 * @param borderSize  边框尺寸
 * @param borderColor 边框颜色
 * @param recycle     是否回收
 * @return 圆角图片
 */
public static Bitmap toRoundCorner(final Bitmap src, final float radius, int borderSize, int borderColor, final boolean recycle) {
	if (isEmptyBitmap(src)) {
		return null;
	}
	int width = src.getWidth();
	int height = src.getHeight();
	Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
	Bitmap ret = Bitmap.createBitmap(width, height, src.getConfig());
	BitmapShader shader = new BitmapShader(src, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
	paint.setShader(shader);
	Canvas canvas = new Canvas(ret);
	RectF rectF = new RectF(0, 0, width, height);
	float halfBorderSize = borderSize / 2f;
	rectF.inset(halfBorderSize, halfBorderSize);
	canvas.drawRoundRect(rectF, radius, radius, paint);
	if (borderSize > 0) {
		paint.setShader(null);
		paint.setColor(borderColor);
		paint.setStyle(Paint.Style.STROKE);
		paint.setStrokeWidth(borderSize);
		paint.setStrokeCap(Paint.Cap.ROUND);
		canvas.drawRoundRect(rectF, radius, radius, paint);
	}
	if (recycle && !src.isRecycled()) {
		src.recycle();
	}
	return ret;
}
 
Example 13
Project: PicShow-zhaipin   File: SpringBar.java   View Source Code Vote up 5 votes
public SpringBar(Context context, int springColor, float maxRadiusPercent, float minRadiusPercent) {
    super(context);
    this.maxRadiusPercent = maxRadiusPercent;
    this.minRadiusPercent = minRadiusPercent;
    foot = new Point();
    head = new Point();
    path = new Path();
    paint = new Paint();
    paint.setAntiAlias(true);
    paint.setStyle(Paint.Style.FILL_AND_STROKE);
    paint.setStrokeWidth(1);
    paint.setColor(springColor);
}
 
Example 14
Project: Ghost-Android   File: BorderedCircleTransformation.java   View Source Code Vote up 5 votes
@Override
public Bitmap transform(Bitmap source) {
    int size = Math.min(source.getWidth(), source.getHeight());

    int x = (source.getWidth() - size) / 2;
    int y = (source.getHeight() - size) / 2;

    Bitmap squaredBitmap = Bitmap.createBitmap(source, x, y, size, size);
    if (squaredBitmap != source) {
        source.recycle();
    }

    Bitmap bitmap = Bitmap.createBitmap(size, size, source.getConfig());

    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint();
    BitmapShader shader = new BitmapShader(squaredBitmap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
    paint.setShader(shader);
    paint.setAntiAlias(true);

    float r = size / 2f;

    // Prepare the background
    Paint paintBg = new Paint();
    paintBg.setColor(BORDER_COLOR);
    paintBg.setAntiAlias(true);

    // Draw the background circle
    canvas.drawCircle(r, r, r, paintBg);

    // Draw the image smaller than the background so a little border will be seen
    canvas.drawCircle(r, r, r - BORDER_RADIUS, paint);

    squaredBitmap.recycle();
    return bitmap;
}
 
Example 15
Project: Cable-Android   File: MotionView.java   View Source Code Vote up 5 votes
private void initEntityBorder(@NonNull MotionEntity entity ) {
  // init stroke
  int strokeSize = getResources().getDimensionPixelSize(R.dimen.scribble_stroke_size);
  Paint borderPaint = new Paint();
  borderPaint.setStrokeWidth(strokeSize);
  borderPaint.setAntiAlias(true);
  borderPaint.setColor(getContext().getResources().getColor(R.color.sticker_selected_color));

  entity.setBorderPaint(borderPaint);
}
 
Example 16
Project: kotlin-android   File: RectLayer.java   View Source Code Vote up 5 votes
@Override
public void draw(Canvas canvas) {
    super.draw(canvas);
    int width = getWidth();
    int height = getHeight();
    rect = new Rect(width/12, height/5, width * 11 / 12, height *7 /10);
    Paint p = new Paint();
    p.setColor(Color.BLACK);
    p.setStyle(Paint.Style.FILL);
    p.setAlpha(76);
    canvas.drawRect(0, 0, width, rect.top, p);
    canvas.drawRect(0, rect.bottom, width, height, p);
    canvas.drawRect(0, rect.top, rect.left, rect.bottom, p);
    canvas.drawRect(rect.right, rect.top, width, rect.bottom, p);

    p.setColor(Color.RED);
    p.setAlpha(255);
    p.setStrokeWidth(3);
    int lineVerticalPos = rect.top + (rect.height() >> 1);
    canvas.drawLine(rect.left + 10, lineVerticalPos, rect.right - 10, lineVerticalPos, p);

    p.setColor(Color.WHITE);
    p.setStrokeWidth(3);
    float[] vertice = {rect.left, rect.top, rect.right, rect.top,
            rect.right, rect.top, rect.right, rect.bottom,
            rect.right, rect.bottom, rect.left, rect.bottom,
            rect.left, rect.top, rect.left, rect.bottom};
    canvas.drawLines(vertice, p);

    p.setARGB(255, 255, 141, 22);
    p.setStrokeWidth(5);
    canvas.drawLine(rect.left, rect.top, rect.left + 40, rect.top, p);
    canvas.drawLine(rect.right - 40, rect.top, rect.right, rect.top, p);
    canvas.drawLine(rect.right, rect.top, rect.right, rect.top + 40, p);
    canvas.drawLine(rect.right, rect.bottom - 40, rect.right, rect.bottom, p);
    canvas.drawLine(rect.right - 40, rect.bottom, rect.right, rect.bottom, p);
    canvas.drawLine(rect.left, rect.bottom, rect.left + 40, rect.bottom, p);
    canvas.drawLine(rect.left, rect.bottom - 40, rect.left, rect.bottom, p);
    canvas.drawLine(rect.left, rect.top, rect.left, rect.top + 40, p);
}
 
Example 17
Project: BLE-Indoor-Positioning   File: BeaconView.java   View Source Code Vote up 5 votes
@CallSuper
public void initialize() {
    textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    textPaint.setColor(Color.BLACK);
    textPaint.setTextSize(pixelsPerDip * 8);

    primaryFillPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    primaryFillPaint.setStyle(Paint.Style.FILL);
    primaryFillPaint.setColor(ContextCompat.getColor(getContext(), R.color.primary));

    primaryStrokePaint = new Paint(primaryFillPaint);
    primaryStrokePaint.setStyle(Paint.Style.STROKE);
    primaryStrokePaint.setStrokeWidth(pixelsPerDip);

    secondaryFillPaint = new Paint(primaryFillPaint);
    secondaryFillPaint.setColor(ContextCompat.getColor(getContext(), R.color.accent));

    secondaryStrokePaint = new Paint(primaryStrokePaint);
    secondaryStrokePaint.setColor(ContextCompat.getColor(getContext(), R.color.accent));

    whiteFillPaint = new Paint(primaryFillPaint);
    whiteFillPaint.setColor(Color.WHITE);

    whiteStrokePaint = new Paint(primaryStrokePaint);
    whiteStrokePaint.setColor(Color.WHITE);

    beaconRangePaint = new Paint(primaryFillPaint);
    beaconRangePaint.setAlpha(25);

    deviceRangePaint = new Paint(secondaryFillPaint);
    deviceRangePaint.setAlpha(25);

    backgroundPaint = new Paint();
    backgroundPaint.setColor(Color.WHITE);
    backgroundPaint.setStyle(Paint.Style.FILL);
}
 
Example 18
Project: buildAPKsApps   File: BarChart.java   View Source Code Vote up 4 votes
/**
 * Draws a bar.
 * 
 * @param canvas the canvas
 * @param xMin the X axis minimum
 * @param yMin the Y axis minimum
 * @param xMax the X axis maximum
 * @param yMax the Y axis maximum
 * @param scale the scale index
 * @param seriesIndex the current series index
 * @param paint the paint
 */
private void drawBar(Canvas canvas, float xMin, float yMin, float xMax, float yMax, int scale,
    int seriesIndex, Paint paint) {
  // Fix negative bars issue in Android 4.2
  float temp;
  if (xMin > xMax) {
    temp = xMin;
    xMin = xMax;
    xMax = temp;
  }
  if (yMin > yMax) {
    temp = yMin;
    yMin = yMax;
    yMax = temp;
  }

  SimpleSeriesRenderer renderer = mRenderer.getSeriesRendererAt(seriesIndex);
  if (renderer.isGradientEnabled()) {
    float minY = (float) toScreenPoint(new double[] { 0, renderer.getGradientStopValue() }, scale)[1];
    float maxY = (float) toScreenPoint(new double[] { 0, renderer.getGradientStartValue() },
        scale)[1];
    float gradientMinY = Math.max(minY, Math.min(yMin, yMax));
    float gradientMaxY = Math.min(maxY, Math.max(yMin, yMax));
    int gradientMinColor = renderer.getGradientStopColor();
    int gradientMaxColor = renderer.getGradientStartColor();
    int gradientStartColor = gradientMaxColor;
    int gradientStopColor = gradientMinColor;

    if (yMin < minY) {
      paint.setColor(gradientMinColor);
      canvas.drawRect(Math.round(xMin), Math.round(yMin), Math.round(xMax),
          Math.round(gradientMinY), paint);
    } else {
      gradientStopColor = getGradientPartialColor(gradientMinColor, gradientMaxColor,
          (maxY - gradientMinY) / (maxY - minY));
    }
    if (yMax > maxY) {
      paint.setColor(gradientMaxColor);
      canvas.drawRect(Math.round(xMin), Math.round(gradientMaxY), Math.round(xMax),
          Math.round(yMax), paint);
    } else {
      gradientStartColor = getGradientPartialColor(gradientMaxColor, gradientMinColor,
          (gradientMaxY - minY) / (maxY - minY));
    }
    GradientDrawable gradient = new GradientDrawable(Orientation.BOTTOM_TOP, new int[] {
        gradientStartColor, gradientStopColor });
    gradient.setBounds(Math.round(xMin), Math.round(gradientMinY), Math.round(xMax),
        Math.round(gradientMaxY));
    gradient.draw(canvas);
  } else {
    if (Math.abs(yMin - yMax) < 1) {
      if (yMin < yMax) {
        yMax = yMin + 1;
      } else {
        yMax = yMin - 1;
      }
    }
    canvas
        .drawRect(Math.round(xMin), Math.round(yMin), Math.round(xMax), Math.round(yMax), paint);
  }
}
 
Example 19
Project: GitHub   File: TriangleShapeRenderer.java   View Source Code Vote up 4 votes
@Override
public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler,
                        float posX, float posY, Paint renderPaint) {

    final float shapeSize = dataSet.getScatterShapeSize();
    final float shapeHalf = shapeSize / 2f;
    final float shapeHoleSizeHalf = Utils.convertDpToPixel(dataSet.getScatterShapeHoleRadius());
    final float shapeHoleSize = shapeHoleSizeHalf * 2.f;
    final float shapeStrokeSize = (shapeSize - shapeHoleSize) / 2.f;

    final int shapeHoleColor = dataSet.getScatterShapeHoleColor();

    renderPaint.setStyle(Paint.Style.FILL);

    // create a triangle path
    Path tri = mTrianglePathBuffer;
    tri.reset();

    tri.moveTo(posX, posY - shapeHalf);
    tri.lineTo(posX + shapeHalf, posY + shapeHalf);
    tri.lineTo(posX - shapeHalf, posY + shapeHalf);

    if (shapeSize > 0.0) {
        tri.lineTo(posX, posY - shapeHalf);

        tri.moveTo(posX - shapeHalf + shapeStrokeSize,
                posY + shapeHalf - shapeStrokeSize);
        tri.lineTo(posX + shapeHalf - shapeStrokeSize,
                posY + shapeHalf - shapeStrokeSize);
        tri.lineTo(posX,
                posY - shapeHalf + shapeStrokeSize);
        tri.lineTo(posX - shapeHalf + shapeStrokeSize,
                posY + shapeHalf - shapeStrokeSize);
    }

    tri.close();

    c.drawPath(tri, renderPaint);
    tri.reset();

    if (shapeSize > 0.0 &&
            shapeHoleColor != ColorTemplate.COLOR_NONE) {

        renderPaint.setColor(shapeHoleColor);

        tri.moveTo(posX,
                posY - shapeHalf + shapeStrokeSize);
        tri.lineTo(posX + shapeHalf - shapeStrokeSize,
                posY + shapeHalf - shapeStrokeSize);
        tri.lineTo(posX - shapeHalf + shapeStrokeSize,
                posY + shapeHalf - shapeStrokeSize);
        tri.close();

        c.drawPath(tri, renderPaint);
        tri.reset();
    }

}
 
Example 20
Project: FastAndroid   File: SwitchButton.java   View Source Code Vote up 2 votes
/**
 * 初始化参数
 */
private void initView(Context context, AttributeSet attrs) {
    TypedArray typedArray = null;
    if (attrs != null) {
        typedArray = context.obtainStyledAttributes(attrs, R.styleable.SwitchButton);
    }

    shadowEffect = optBoolean(typedArray, R.styleable.SwitchButton_sb_shadow_effect, true);

    uncheckCircleColor = optColor(typedArray, R.styleable.SwitchButton_sb_uncheckcircle_color, 0XffAAAAAA);

    uncheckCircleWidth = optPixelSize(typedArray, R.styleable.SwitchButton_sb_uncheckcircle_width, dp2pxInt(1.5f));//dp2pxInt(1.5f);

    uncheckCircleOffsetX = dp2px(10);

    uncheckCircleRadius = optPixelSize(typedArray, R.styleable.SwitchButton_sb_uncheckcircle_radius, dp2px(4));//dp2px(4);

    checkedLineOffsetX = dp2px(4);
    checkedLineOffsetY = dp2px(4);

    shadowRadius = optPixelSize(typedArray, R.styleable.SwitchButton_sb_shadow_radius, dp2pxInt(2.5f));//dp2pxInt(2.5f);

    shadowOffset = optPixelSize(typedArray, R.styleable.SwitchButton_sb_shadow_offset, dp2pxInt(1.5f));//dp2pxInt(1.5f);

    shadowColor = optColor(typedArray, R.styleable.SwitchButton_sb_shadow_color, 0X33000000);//0X33000000;

    uncheckColor = optColor(typedArray, R.styleable.SwitchButton_sb_uncheck_color, 0XffDDDDDD);//0XffDDDDDD;

    checkedColor = optColor(typedArray, R.styleable.SwitchButton_sb_checked_color, 0Xff51d367);//0Xff51d367;

    borderWidth = optPixelSize(typedArray, R.styleable.SwitchButton_sb_border_width, dp2pxInt(1));//dp2pxInt(1);

    checkLineColor = optColor(typedArray, R.styleable.SwitchButton_sb_checkline_color, Color.WHITE);//Color.WHITE;

    checkLineWidth = optPixelSize(typedArray, R.styleable.SwitchButton_sb_checkline_width, dp2pxInt(1f));//dp2pxInt(1.0f);

    checkLineLength = dp2px(6);

    int buttonColor = optColor(typedArray, R.styleable.SwitchButton_sb_button_color, Color.WHITE);//Color.WHITE;

    int effectDuration = optInt(typedArray, R.styleable.SwitchButton_sb_effect_duration, 300);//300;

    isChecked = optBoolean(typedArray, R.styleable.SwitchButton_sb_checked, false);

    showIndicator = optBoolean(typedArray, R.styleable.SwitchButton_sb_show_indicator, true);

    background = optColor(typedArray, R.styleable.SwitchButton_sb_background, Color.WHITE);//Color.WHITE;

    enableEffect = optBoolean(typedArray, R.styleable.SwitchButton_sb_enable_effect, true);

    if (typedArray != null) {
        typedArray.recycle();
    }
    paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    buttonPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    buttonPaint.setColor(buttonColor);

    if (shadowEffect) {
        buttonPaint.setShadowLayer(shadowRadius, 0, shadowOffset, shadowColor);
    }

    viewState = new ViewState();
    beforeState = new ViewState();
    afterState = new ViewState();

    valueAnimator = ValueAnimator.ofFloat(0f, 1f);
    valueAnimator.setDuration(effectDuration);
    valueAnimator.setRepeatCount(0);

    valueAnimator.addUpdateListener(animatorUpdateListener);
    valueAnimator.addListener(animatorListener);

    super.setClickable(true);

    this.setPadding(0, 0, 0, 0);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        setLayerType(LAYER_TYPE_SOFTWARE, null);
    }
}