public CircleImageViewSupport(Context context, int color, final float radius) { super(context); final float density = getContext().getResources().getDisplayMetrics().density; final int diameter = (int) (radius * density * 2); final int shadowYOffset = (int) (density * Y_OFFSET); final int shadowXOffset = (int) (density * X_OFFSET); mShadowRadius = (int) (density * SHADOW_RADIUS); ShapeDrawable circle; if (elevationSupported()) { circle = new ShapeDrawable(new OvalShape()); ViewCompat.setElevation(this, SHADOW_ELEVATION * density); } else { OvalShape oval = new OvalShadow(mShadowRadius, diameter); circle = new ShapeDrawable(oval); ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, circle.getPaint()); circle .getPaint() .setShadowLayer(mShadowRadius, shadowXOffset, shadowYOffset, KEY_SHADOW_COLOR); final int padding = mShadowRadius; // set padding so the inner image sits correctly within the shadow. setPadding(padding, padding, padding, padding); } circle.getPaint().setColor(color); setBackgroundDrawable(circle); }
public static StateListDrawable createBlueButtonDrawable(Context context) { float corner = TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, 2, context.getResources().getDisplayMetrics()); float[] corners = new float[] {corner, corner, corner, corner, corner, corner, corner, corner}; ShapeDrawable shapeDrawable = new ShapeDrawable(); shapeDrawable.getPaint().setColor(TgR.color.blue_color); Shape rrs = new RoundRectShape(corners, null, null); shapeDrawable.setShape(rrs); ShapeDrawable shapeDrawablePressed = new ShapeDrawable(); // shapeDrawablePressed.getPaint().setColor((TgR.color.blue_color & 0x00FFFFFF) | (0xCC // << 24)); shapeDrawablePressed.getPaint().setColor(TgR.color.main_theme_color); Shape rrsPressed = new RoundRectShape(corners, null, null); shapeDrawablePressed.setShape(rrsPressed); ShapeDrawable shapeDrawableDisable = new ShapeDrawable(); shapeDrawableDisable.getPaint().setColor(0xFFD1D1D1); Shape rrsDisable = new RoundRectShape(corners, null, null); shapeDrawableDisable.setShape(rrsDisable); StateListDrawable sld = new StateListDrawable(); sld.addState(new int[] {-android.R.attr.state_enabled}, shapeDrawableDisable); sld.addState(new int[] {android.R.attr.state_pressed}, shapeDrawablePressed); sld.addState(new int[] {android.R.attr.state_enabled}, shapeDrawable); return sld; }
private LayerDrawable createDrawable(int radius, int topColor, int bottomColor) { float[] outerRadius = new float[] {radius, radius, radius, radius, radius, radius, radius, radius}; // Top RoundRectShape topRoundRect = new RoundRectShape(outerRadius, null, null); ShapeDrawable topShapeDrawable = new ShapeDrawable(topRoundRect); topShapeDrawable.getPaint().setColor(topColor); // Bottom RoundRectShape roundRectShape = new RoundRectShape(outerRadius, null, null); ShapeDrawable bottomShapeDrawable = new ShapeDrawable(roundRectShape); bottomShapeDrawable.getPaint().setColor(bottomColor); // Create array Drawable[] drawArray = {bottomShapeDrawable, topShapeDrawable}; LayerDrawable layerDrawable = new LayerDrawable(drawArray); // Set shadow height if (isShadowEnabled && topColor != Color.TRANSPARENT) { // unpressed drawable layerDrawable.setLayerInset(0, 0, 0, 0, 0); /*index, left, top, right, bottom*/ } else { // pressed drawable layerDrawable.setLayerInset(0, 0, mShadowHeight, 0, 0); /*index, left, top, right, bottom*/ } layerDrawable.setLayerInset(1, 0, 0, 0, mShadowHeight); /*index, left, top, right, bottom*/ return layerDrawable; }
public PagerHeader(Context context, AttributeSet attrs) { super(context, attrs); mContext = context; Resources resources = context.getResources(); mDisplayMetrics = resources.getDisplayMetrics(); // Get attributes from the layout xml TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PagerHeader, 0, 0); // mActiveTextColor = new ColorSet( // a.getColor(R.styleable.PagerHeader_activeTextColor, Color.GREEN)); mActiveTextColor = new ColorSet(resources.getColor(R.color.cputuner_green)); mInactiveTextColor = new ColorSet(a.getColor(R.styleable.PagerHeader_inactiveTextColor, Color.LTGRAY)); mTabColor = new ColorSet(a.getColor(R.styleable.PagerHeader_tabColor, mActiveTextColor.getColor())); mTabHeight = a.getDimensionPixelSize(R.styleable.PagerHeader_tabHeight, dipToPixels(4)); mTabPadding = a.getDimensionPixelSize(R.styleable.PagerHeader_tabPadding, dipToPixels(10)); mPaddingPush = a.getDimensionPixelSize(R.styleable.PagerHeader_paddingPush, dipToPixels(50)); mFadingEdgeLength = a.getDimensionPixelSize(R.styleable.PagerHeader_fadingEdgeLength, dipToPixels(30)); mShowTopShadow = a.getBoolean(R.styleable.PagerHeader_showTopShadow, true); mShowBottomBar = a.getBoolean(R.styleable.PagerHeader_showBottomBar, true); mShowTab = a.getBoolean(R.styleable.PagerHeader_showTab, true); ColorSet fadingEdgeColorHint = new ColorSet(0); int backgroundColor = a.getColor(R.styleable.PagerHeader_backgroundColor, Color.DKGRAY); setBackgroundColor(backgroundColor); fadingEdgeColorHint.setColor(backgroundColor); mTabDrawable = new ShapeDrawable(new RectShape()); mTabDrawable.getPaint().setColor(mTabColor.getColor()); mBottomBar = new ShapeDrawable(new RectShape()); mBottomBar.getPaint().setColor(mTabColor.getColor()); mBottomBarHeight = dipToPixels(2); mShadow = new GradientDrawable( GradientDrawable.Orientation.TOP_BOTTOM, new int[] {0x88000000, 0x00000000}); mShadowHeight = dipToPixels(3); int[] fadingEdgeGradient = new int[] {fadingEdgeColorHint.getColor(), fadingEdgeColorHint.getColor(0)}; mFadingEdgeLeft = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, fadingEdgeGradient); mFadingEdgeRight = new GradientDrawable(GradientDrawable.Orientation.RIGHT_LEFT, fadingEdgeGradient); final ViewConfiguration config = ViewConfiguration.get(context); int touchSlop = config.getScaledTouchSlop(); mTouchSlopSquare = touchSlop * touchSlop; }
@Override public void getActionsLayout(Context ctx, final LinearLayout cont) { WindowManager mWinMgr = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE); int displayWidth = mWinMgr.getDefaultDisplay().getWidth(); cont.removeAllViews(); final TextView cmd = new TextView(ctx); cmd.setText(Html.fromHtml("<b>Reading:</b> " + getOutputCelsius() + "°C")); if (prefs.isLightThemeSelected()) cmd.setTextColor(ctx.getResources().getColor(R.color.black)); RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.MATCH_PARENT); cmd.setLayoutParams(lp); lp.setMargins(2, 0, 0, 2); // cmd.setGravity(Gravity.TOP); cont.addView(cmd); ProgressBar par = new ProgressBar(ctx, null, android.R.attr.progressBarStyleHorizontal); // ProgressBar sfumata final ShapeDrawable pgDrawable = new ShapeDrawable(new RoundRectShape(Constants.roundedCorners, null, null)); final LinearGradient gradient = new LinearGradient( 0, 0, displayWidth / 2, 0, ctx.getResources().getColor(color.aa_blue), ctx.getResources().getColor(color.aa_red), android.graphics.Shader.TileMode.CLAMP); pgDrawable.getPaint().setStrokeWidth(3); pgDrawable.getPaint().setDither(true); pgDrawable.getPaint().setShader(gradient); ClipDrawable progress = new ClipDrawable(pgDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL); par.setProgressDrawable(progress); par.setBackgroundResource(android.R.drawable.progress_horizontal); RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT); lp2.setMargins(2, 2, 4, 2); par.setLayoutParams(lp2); par.setMax(50); par.setProgress(20); par.setProgress(0); par.setMax(40); par.setProgress((int) getOutputFloat()); cont.addView(par); }
@SuppressLint("NewApi") private void addBordersToView(LoopMeBannerView bannerView) { ShapeDrawable drawable = new ShapeDrawable(new RectShape()); drawable.getPaint().setColor(Color.BLACK); drawable.getPaint().setStyle(Style.FILL_AND_STROKE); drawable.getPaint().setAntiAlias(true); bannerView.setPadding(2, 2, 2, 2); if (Build.VERSION.SDK_INT < 16) { bannerView.setBackgroundDrawable(drawable); } else { bannerView.setBackground(drawable); } }
@Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); final float density = getContext().getResources().getDisplayMetrics().density; mDiameter = Math.min(getMeasuredWidth(), getMeasuredHeight()); if (mDiameter <= 0) { mDiameter = (int) density * DEFAULT_CIRCLE_DIAMETER; } if (getBackground() == null && mCircleBackgroundEnabled) { final int shadowYOffset = (int) (density * Y_OFFSET); final int shadowXOffset = (int) (density * X_OFFSET); mShadowRadius = (int) (density * SHADOW_RADIUS); if (elevationSupported()) { mBgCircle = new ShapeDrawable(new OvalShape()); ViewCompat.setElevation(this, SHADOW_ELEVATION * density); } else { OvalShape oval = new OvalShadow(mShadowRadius, mDiameter - mShadowRadius * 2); mBgCircle = new ShapeDrawable(oval); ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, mBgCircle.getPaint()); mBgCircle .getPaint() .setShadowLayer(mShadowRadius, shadowXOffset, shadowYOffset, KEY_SHADOW_COLOR); final int padding = (int) mShadowRadius; // set padding so the inner image sits correctly within the shadow. setPadding(padding, padding, padding, padding); } mBgCircle.getPaint().setColor(mBackGroundColor); setBackgroundDrawable(mBgCircle); } mProgressDrawable.setBackgroundColor(mBackGroundColor); mProgressDrawable.setColorSchemeColors(mColors); mProgressDrawable.setSizeParameters( mDiameter, mDiameter, mInnerRadius <= 0 ? (mDiameter - mProgressStokeWidth * 2) / 4 : mInnerRadius, mProgressStokeWidth, mArrowWidth < 0 ? mProgressStokeWidth * 4 : mArrowWidth, mArrowHeight < 0 ? mProgressStokeWidth * 2 : mArrowHeight); if (isShowArrow()) { mProgressDrawable.showArrowOnFirstStart(true); mProgressDrawable.setArrowScale(1f); mProgressDrawable.showArrow(true); } super.setImageDrawable(null); super.setImageDrawable(mProgressDrawable); mProgressDrawable.setAlpha(255); mProgressDrawable.setStartEndTrim(0f, 0.75f); }
@SuppressLint("NewApi") private void setUp(final double diameter) { PtrLocalDisplay.init(mParent.getContext()); final int shadowYOffset = PtrLocalDisplay.dp2px(Y_OFFSET); final int shadowXOffset = PtrLocalDisplay.dp2px(X_OFFSET); int mShadowRadius = PtrLocalDisplay.dp2px(SHADOW_RADIUS); OvalShape oval = new OvalShadow(mShadowRadius, (int) diameter); mShadow = new ShapeDrawable(oval); if (Build.VERSION.SDK_INT >= 11) { mParent.setLayerType(View.LAYER_TYPE_SOFTWARE, mShadow.getPaint()); } mShadow .getPaint() .setShadowLayer(mShadowRadius, shadowXOffset, shadowYOffset, KEY_SHADOW_COLOR); }
/** * Generates bitmap used for drawing button. * * @param radius Radius of button in pixels. */ @Override void generateBitmap() { super.generateBitmap(); // Size and shape buttonShape.setShape(new OvalShape()); buttonShape.setBounds( new Rect(PADDING, PADDING, (int) radius * 2 - PADDING, (int) radius * 2 - PADDING)); // Create button bitmap and render shape buttonBitmap = Bitmap.createBitmap((int) radius * 2, (int) radius * 2, Bitmap.Config.ARGB_4444); Canvas handleCanvas = new Canvas(buttonBitmap); buttonShape.getPaint().set(parent.fillPaint); buttonShape.draw(handleCanvas); // Set text style textPaint.setStyle(Paint.Style.FILL); textPaint.setTypeface(Typeface.DEFAULT_BOLD); textPaint.setTextAlign(Paint.Align.CENTER); textPaint.setColor(Color.BLACK); // Set size (one character has a standard design, more has dynamic size) if (label.length() == 1) textPaint.setTextSize(radius); else textPaint.setTextSize(radius / label.length() * 2.5f); // Set paint to clear text from button textPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); // Render the button handleCanvas.drawText(label, radius, radius + (textPaint.getTextSize() * .33333f), textPaint); }
// Throw IllegalArgumentException if shape has illegal value. private void setShape() { ShapeDrawable drawable = new ShapeDrawable(); // Set color of drawable. drawable .getPaint() .setColor( (backgroundColor == Component.COLOR_DEFAULT) ? SHAPED_DEFAULT_BACKGROUND_COLOR : backgroundColor); // Set shape of drawable. switch (shape) { case Component.BUTTON_SHAPE_ROUNDED: drawable.setShape(new RoundRectShape(ROUNDED_CORNERS_ARRAY, null, null)); break; case Component.BUTTON_SHAPE_RECT: drawable.setShape(new RectShape()); break; case Component.BUTTON_SHAPE_OVAL: drawable.setShape(new OvalShape()); break; default: throw new IllegalArgumentException(); } // Set drawable to the background of the button. view.setBackgroundDrawable(drawable); view.invalidate(); }
/* * (non-Javadoc) * * @see android.widget.Adapter#getView(int, android.view.View, android.view.ViewGroup) */ @SuppressLint("NewApi") @SuppressWarnings("deprecation") @Override public View getView(int position, View convertView, ViewGroup parent) { View view = convertView; if (view == null) { /* * TODO: build the layout programmatically */ view = mLayoutInflater.inflate(R.layout.org_dmfs_colorpickerdialog_palette_field, null); } // set the background to a colored circle // TODO: allow to customize the shape Shape shape = new ArcShape(0, 360); ShapeDrawable bg = new ShapeDrawable(shape); bg.getPaint().setColor(mPalette.getColor(position)); if (android.os.Build.VERSION.SDK_INT < 16) { view.setBackgroundDrawable(bg); } else { view.setBackground(bg); } return view; }
private Drawable createSelector(int color) { ShapeDrawable darkerCircle = new ShapeDrawable(new OvalShape()); darkerCircle.getPaint().setColor(translucentColor(shiftColorUp(color))); StateListDrawable stateListDrawable = new StateListDrawable(); stateListDrawable.addState(new int[] {android.R.attr.state_pressed}, darkerCircle); return stateListDrawable; }
private void drawKeyboardBackground(Canvas canvas, String colour) { ShapeDrawable background = new ShapeDrawable(new RectShape()); background.getPaint().setColor(Color.parseColor(colour)); background.setBounds( (int) getX(), (int) getY(), (int) getX() + getWidth(), (int) getY() + getHeight()); background.draw(canvas); }
public DrawableLayeredButton(Context context, int topLayer, boolean hasBorder) { Drawable topLayerDrawable = context.getResources().getDrawable(topLayer); Drawable greenButtonDrawable = context.getResources().getDrawable(mGreenButtonResource); InsetDrawable topLayerInset = new InsetDrawable(topLayerDrawable, Utilities.convertToPx(8)); InsetDrawable greenButtonInset = new InsetDrawable(greenButtonDrawable, Utilities.convertToPx(5)); int width = Utilities.convertToPx(40); int height = Utilities.convertToPx(40); ShapeDrawable border = new ShapeDrawable(new OvalShape()); border.getPaint().setColor(0xffabab25); border.setBounds(0, 0, width, height); Drawable[] nonActivatedlayers = new Drawable[2]; nonActivatedlayers[0] = greenButtonInset; nonActivatedlayers[1] = topLayerInset; LayerDrawable nonActivatedLayer = new LayerDrawable(nonActivatedlayers); Drawable[] activatedlayers = new Drawable[3]; activatedlayers[0] = border; activatedlayers[1] = greenButtonInset; activatedlayers[2] = topLayerInset; LayerDrawable activatedLayer = new LayerDrawable(activatedlayers); mDrawable = new StateListDrawable(); if (hasBorder) { mDrawable.addState(new int[] {android.R.attr.state_checked}, activatedLayer); } mDrawable.addState(new int[] {}, nonActivatedLayer); }
private void validateSavedColorCode(String code, String key) { try { ShapeDrawable shapeDrawable = new ShapeDrawable(); shapeDrawable.getPaint().setColor(Color.parseColor(code)); } catch (Exception e) { mPreferences.edit().putString(key, null).commit(); } }
public VistaAMedida(Context contexto) { super(contexto); int x = 10, y = 10; int ancho = 300, alto = 50; miDrawable = new ShapeDrawable(new OvalShape()); miDrawable.getPaint().setColor(0xff0000ff); miDrawable.setBounds(x, y, x + ancho, y + alto); }
private void init() { mControllerWidth = 50; mControllerHeight = 300; mController = new ShapeDrawable(new RectShape()); mController.getPaint().setColor(Color.WHITE); updateControllerPosition(); }
private void showLoading() { if (loadingDrawable == null) { loadingDrawable = new LoadingDrawable(loadingIv); } loadingIv.setImageDrawable(loadingDrawable); ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape()); shapeDrawable.getPaint().setColor(Color.parseColor("#ffffff")); loadingIv.setBackgroundDrawable(shapeDrawable); loadingDrawable.start(); }
private LayerDrawable makeClusterBackground() { mColoredCircleBackground = new ShapeDrawable(new OvalShape()); ShapeDrawable outline = new ShapeDrawable(new OvalShape()); outline.getPaint().setColor(0x80ffffff); // Transparent white. LayerDrawable background = new LayerDrawable(new Drawable[] {outline, mColoredCircleBackground}); int strokeWidth = (int) (mDensity * 3); background.setLayerInset(1, strokeWidth, strokeWidth, strokeWidth, strokeWidth); return background; }
@SuppressWarnings("deprecation") public void setBackground(int dipRadius, int badgeColor) { int radius = dip2Px(dipRadius); float[] radiusArray = new float[] {radius, radius, radius, radius, radius, radius, radius, radius}; RoundRectShape roundRect = new RoundRectShape(radiusArray, null, null); ShapeDrawable bgDrawable = new ShapeDrawable(roundRect); bgDrawable.getPaint().setColor(badgeColor); setBackgroundDrawable(bgDrawable); }
private ShapeDrawable getDefaultBackground() { int r = dipToPixels(DEFAULT_CORNER_RADIUS_DIP); float[] outerR = new float[] {r, r, r, r, r, r, r, r}; RoundRectShape rr = new RoundRectShape(outerR, null, null); ShapeDrawable drawable = new ShapeDrawable(rr); drawable.getPaint().setColor(badgeColor); return drawable; }
private void createCircleDrawable() { float radius = CIRCLE_DIAMETER / 2; final float density = getContext().getResources().getDisplayMetrics().density; final int diameter = (int) (radius * density * 2); final int shadowYOffset = (int) (density * Y_OFFSET); final int shadowXOffset = (int) (density * X_OFFSET); mShadowRadius = (int) (density * SHADOW_RADIUS); OvalShape oval = new OvalShadow(mShadowRadius, diameter); mCircle = new ShapeDrawable(oval); // ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, // circle.getPaint()); mCircle .getPaint() .setShadowLayer(mShadowRadius, shadowXOffset, shadowYOffset, KEY_SHADOW_COLOR); mPadding = (int) mShadowRadius; mCircle.getPaint().setColor(Color.WHITE); }
private Drawable generateBg() { StateListDrawable stateListDrawable = new StateListDrawable(); float width = mBorderWidth; float round = mBorderRound; int pressColor = mBorderColorPress; int color = mBorderColor; int pressColorBG = mBorderBgColorPress; int colorBG = mBorderBgColor; // 按下状态,边框 float[] outRadii = new float[] {round, round, round, round, round, round, round, round}; RoundRectShape pressRectShape = new RoundRectShape(outRadii, new RectF(width, width, width, width), outRadii); ShapeDrawable pressShape = new ShapeDrawable(pressRectShape); pressShape.getPaint().setColor(pressColor); // 按下背景 RoundRectShape pressRectShapeBg = new RoundRectShape(outRadii, null, null); ShapeDrawable pressShapeBg = new ShapeDrawable(pressRectShapeBg); pressShapeBg.getPaint().setColor(pressColorBG); LayerDrawable pressDrawable = new LayerDrawable(new Drawable[] {pressShapeBg, pressShape}); // 先绘制背景色,再绘制边框 stateListDrawable.addState(new int[] {android.R.attr.state_pressed}, pressDrawable); // 正常状态,边框 RoundRectShape rectShape = new RoundRectShape(outRadii, new RectF(width, width, width, width), outRadii); ShapeDrawable shape = new ShapeDrawable(rectShape); shape.getPaint().setColor(color); // 正常背景 RoundRectShape rectShapeBg = new RoundRectShape(outRadii, null, null); ShapeDrawable shapeBg = new ShapeDrawable(rectShapeBg); shapeBg.getPaint().setColor(colorBG); LayerDrawable drawable = new LayerDrawable(new Drawable[] {shapeBg, shape}); // 先绘制背景色,再绘制边框 stateListDrawable.addState(new int[] {}, drawable); return stateListDrawable; }
private Drawable createOuterStrokeDrawable(float strokeWidth) { ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape()); final Paint paint = shapeDrawable.getPaint(); paint.setAntiAlias(true); paint.setStrokeWidth(strokeWidth); paint.setStyle(Style.STROKE); paint.setColor(Color.BLACK); paint.setAlpha(opacityToAlpha(0.02f)); return shapeDrawable; }
/** * Called before the marker for a Cluster is added to the map. The default implementation draws a * circle with a rough count of the number of items. */ protected void onBeforeClusterRendered(Cluster<T> cluster, MarkerOptions markerOptions) { int bucket = getBucket(cluster); BitmapDescriptor descriptor = mIcons.get(bucket); if (descriptor == null) { mColoredCircleBackground.getPaint().setColor(getColor(bucket)); descriptor = BitmapDescriptorFactory.fromBitmap(mIconGenerator.makeIcon(getClusterText(bucket))); mIcons.put(bucket, descriptor); } // TODO: consider adding anchor(.5, .5) (Individual markers will overlap more often) markerOptions.icon(descriptor); }
public PuzzleView(Context context) { super(context); mDrawable = new ShapeDrawable(new OvalShape()); int x = 10; int y = 10; int width = 300; int height = 50; mDrawable.getPaint().setColor(0xff74AC23); mDrawable.setBounds(x, y, x + width, y + height); }
@Override public void setParameter(ZDepthParam param, int left, int top, int right, int bottom) { mRectTopShadow.left = left; mRectTopShadow.top = (int) (top + param.mOffsetYTopShadowPx); mRectTopShadow.right = right; mRectTopShadow.bottom = (int) (bottom + param.mOffsetYTopShadowPx); mRectBottomShadow.left = left; mRectBottomShadow.top = (int) (top + param.mOffsetYBottomShadowPx); mRectBottomShadow.right = right; mRectBottomShadow.bottom = (int) (bottom + param.mOffsetYBottomShadowPx); mTopShadow.getPaint().setColor(Color.argb(param.mAlphaTopShadow, 0, 0, 0)); if (0 < param.mBlurTopShadowPx) { mTopShadow .getPaint() .setMaskFilter(new BlurMaskFilter(param.mBlurTopShadowPx, BlurMaskFilter.Blur.NORMAL)); } else { mTopShadow.getPaint().setMaskFilter(null); } mBottomShadow.getPaint().setColor(Color.argb(param.mAlphaBottomShadow, 0, 0, 0)); if (0 < param.mBlurBottomShadowPx) { mBottomShadow .getPaint() .setMaskFilter(new BlurMaskFilter(param.mBlurBottomShadowPx, BlurMaskFilter.Blur.NORMAL)); } else { mBottomShadow.getPaint().setMaskFilter(null); } }
@Override public void draw(Canvas c) { if (mShadow != null) { mShadow.getPaint().setColor(mBackgroundColor); mShadow.draw(c); } final Rect bounds = getBounds(); final int saveCount = c.save(); c.rotate(mRotation, bounds.exactCenterX(), bounds.exactCenterY()); mRing.draw(c, bounds); c.restoreToCount(saveCount); }
@Override public void onBindSwipeViewHolder(RecyclerView.ViewHolder swipeViewHolder, int i) { SampleViewHolder sampleViewHolder = (SampleViewHolder) swipeViewHolder; ShapeDrawable drawable = new ShapeDrawable(new OvalShape()); drawable .getPaint() .setColor( mContext .getResources() .getColor(colors[((int) (Math.random() * (colors.length - 1)))])); sampleViewHolder.avatarView.setBackgroundDrawable(drawable); sampleViewHolder.textView.setText(mDataset.get(i)); }
/** * 通过绘制Path构建一个ShapeDrawable,用来绘制到画布Canvas上 * * @return */ private ShapeDrawable drawGooView() { Path path = new Path(); // 1. 根据当前两圆圆心的距离计算出固定圆的半径 float distance = (float) GeometryUtil.getDistanceBetween2Points(mDragCenter, mStickCenter); stickCircleTempRadius = getCurrentRadius(distance); // 2. 计算出经过两圆圆心连线的垂线的dragLineK(对边比临边)。求出四个交点坐标 float xDiff = mStickCenter.x - mDragCenter.x; Double dragLineK = null; if (xDiff != 0) { dragLineK = (double) ((mStickCenter.y - mDragCenter.y) / xDiff); } // 分别获得经过两圆圆心连线的垂线与圆的交点(两条垂线平行,所以dragLineK相等)。 PointF[] dragPoints = GeometryUtil.getIntersectionPoints(mDragCenter, dragCircleRadius, dragLineK); PointF[] stickPoints = GeometryUtil.getIntersectionPoints(mStickCenter, stickCircleTempRadius, dragLineK); // 3. 以两圆连线的0.618处作为 贝塞尔曲线 的控制点。(选一个中间点附近的控制点) PointF pointByPercent = GeometryUtil.getPointByPercent(mDragCenter, mStickCenter, 0.618f); // 绘制两圆连接 // 此处参见示意图{@link https://github.com/PoplarTang/DragGooView } path.moveTo((float) stickPoints[0].x, (float) stickPoints[0].y); path.quadTo( (float) pointByPercent.x, (float) pointByPercent.y, (float) dragPoints[0].x, (float) dragPoints[0].y); path.lineTo((float) dragPoints[1].x, (float) dragPoints[1].y); path.quadTo( (float) pointByPercent.x, (float) pointByPercent.y, (float) stickPoints[1].x, (float) stickPoints[1].y); path.close(); // 将四个交点画到屏幕上 // path.addCircle((float)dragPoints[0].x, (float)dragPoints[0].y, 5, Direction.CW); // path.addCircle((float)dragPoints[1].x, (float)dragPoints[1].y, 5, Direction.CW); // path.addCircle((float)stickPoints[0].x, (float)stickPoints[0].y, 5, Direction.CW); // path.addCircle((float)stickPoints[1].x, (float)stickPoints[1].y, 5, Direction.CW); // 构建ShapeDrawable ShapeDrawable shapeDrawable = new ShapeDrawable(new PathShape(path, 50f, 50f)); shapeDrawable.getPaint().setColor(Color.RED); return shapeDrawable; }