private Drawable createCircleDrawable(int color, float strokeWidth) { int alpha = Color.alpha(color); int opaqueColor = opaque(color); ShapeDrawable fillDrawable = new ShapeDrawable(new OvalShape()); final Paint paint = fillDrawable.getPaint(); paint.setAntiAlias(true); paint.setColor(opaqueColor); Drawable[] layers = { fillDrawable, createInnerStrokesDrawable(opaqueColor, strokeWidth) }; LayerDrawable drawable = alpha == 255 || !mStrokeVisible ? new LayerDrawable(layers) : new TranslucentLayerDrawable(alpha, layers); int halfStrokeWidth = (int) (strokeWidth / 2f); drawable.setLayerInset(1, halfStrokeWidth, halfStrokeWidth, halfStrokeWidth, halfStrokeWidth); return drawable; }
private Drawable createProductImageDrawable(Product product) { final ShapeDrawable background = new ShapeDrawable(); background.setShape(new OvalShape()); background.getPaint().setColor(ContextCompat.getColor(getContext(), product.color)); final BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), BitmapFactory.decodeResource(getResources(), product.image)); final LayerDrawable layerDrawable = new LayerDrawable (new Drawable[]{background, bitmapDrawable}); final int padding = (int) getResources().getDimension(R.dimen.spacing_huge); layerDrawable.setLayerInset(1, padding, padding, padding, padding); return layerDrawable; }
@Override public Drawable createShadowShapeDrawable(Context context, final CircleLoadingView circleLoadingView, int shadowColor) { final float density = context.getResources().getDisplayMetrics().density; ShapeDrawable circle = new ShapeDrawable(new OvalShape()); circle.getPaint().setColor(shadowColor); final float elevation = SHADOW_ELEVATION * density; circleLoadingView.setElevation(elevation); circleLoadingView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { ViewParent p = circleLoadingView.getParent(); if(p instanceof ViewGroup) { final int margin = (int) elevation; ViewGroup.LayoutParams params = circleLoadingView.getLayoutParams(); if(params instanceof ViewGroup.MarginLayoutParams){ ((ViewGroup.MarginLayoutParams) params).setMargins(margin, margin, margin, margin); } } circleLoadingView.getViewTreeObserver().removeOnGlobalLayoutListener(this); } }); return circle; }
@Override public Drawable createShadowShapeDrawable(Context context, CircleLoadingView circleLoadingView, int shadowColor) { final float density = context.getResources().getDisplayMetrics().density; mShadowRadius = (int) (density * SHADOW_RADIUS); final int diameter = (int) (RADIUS * density * 2); final int shadowYOffset = (int) (density * Y_OFFSET); final int shadowXOffset = (int) (density * X_OFFSET); OvalShape oval = new OvalShadow(mShadowRadius, diameter); ShapeDrawable circle = new ShapeDrawable(oval); ViewCompat.setLayerType(circleLoadingView, 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. circleLoadingView.setPadding(padding, padding, padding, padding); return circle; }
public MagnifierView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); bitmap = ((BitmapDrawable) getResources().getDrawable(R.drawable.pic)).getBitmap(); scaledBitmap = Bitmap.createScaledBitmap(bitmap, bitmap.getWidth() * FACTOR, bitmap.getHeight() * FACTOR, true); // bitmap.recycle(); mBitmapShader = new BitmapShader(scaledBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); mShapeDrawable = new ShapeDrawable(new OvalShape()); mShapeDrawable.setBounds(0, 0, WIDTH, WIDTH); mShapeDrawable.getPaint().setShader(mBitmapShader); mMatrix = new Matrix(); mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mPaint.setColor(Color.RED); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeWidth(3); }
private Bitmap getLargeNotificationIcon(Bitmap bitmap) { Resources resources = mContext.getResources(); int height = (int) resources.getDimension(android.R.dimen.notification_large_icon_height); int width = (int) resources.getDimension(android.R.dimen.notification_large_icon_width); final OvalShape circle = new OvalShape(); circle.resize(width, height); final Paint paint = new Paint(); paint.setColor(ApiCompatibilityUtils.getColor(resources, R.color.google_blue_grey_500)); final Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(result); circle.draw(canvas, paint); float leftOffset = (width - bitmap.getWidth()) / 2f; float topOffset = (height - bitmap.getHeight()) / 2f; if (leftOffset >= 0 && topOffset >= 0) { canvas.drawBitmap(bitmap, leftOffset, topOffset, null); } else { // Scale down the icon into the notification icon dimensions canvas.drawBitmap(bitmap, new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()), new Rect(0, 0, width, height), null); } return result; }
private static Bitmap getCircleIcon( Context context, @ColorInt int backgroundColor, int backgroundInset, @DrawableRes int iconResId, @ColorInt int iconColor, int iconInset) { Drawable[] layers = new Drawable[2]; ShapeDrawable background = new ShapeDrawable(new OvalShape()); background.getPaint().setColor(backgroundColor); Drawable icon = ContextCompat.getDrawable(context, iconResId); Drawable tintedIcon = DrawableCompat.wrap(icon.mutate()); DrawableCompat.setTint(tintedIcon, iconColor); layers[0] = background; layers[1] = tintedIcon; LayerDrawable layerDrawable = new LayerDrawable(layers); layerDrawable.setLayerInset(1, iconInset, iconInset, iconInset, iconInset); layerDrawable.setLayerInset(0, backgroundInset, backgroundInset, backgroundInset, backgroundInset); return drawableToBitmap(layerDrawable); }
private void buildColorPickerView(View view, int colorCode) { view.setVisibility(View.VISIBLE); ShapeDrawable biggerCircle = new ShapeDrawable(new OvalShape()); biggerCircle.setIntrinsicHeight(20); biggerCircle.setIntrinsicWidth(20); biggerCircle.setBounds(new Rect(0, 0, 20, 20)); biggerCircle.getPaint().setColor(colorCode); ShapeDrawable smallerCircle = new ShapeDrawable(new OvalShape()); smallerCircle.setIntrinsicHeight(5); smallerCircle.setIntrinsicWidth(5); smallerCircle.setBounds(new Rect(0, 0, 5, 5)); smallerCircle.getPaint().setColor(Color.WHITE); smallerCircle.setPadding(10, 10, 10, 10); Drawable[] drawables = {smallerCircle, biggerCircle}; LayerDrawable layerDrawable = new LayerDrawable(drawables); view.setBackgroundDrawable(layerDrawable); }
private ShapeHolder addBall(float x, float y) { OvalShape circle = new OvalShape(); circle.resize(50f, 50f); ShapeDrawable drawable = new ShapeDrawable(circle); ShapeHolder shapeHolder = new ShapeHolder(drawable); shapeHolder.setX(x - 25f); shapeHolder.setY(y - 25f); int red = (int)(Math.random() * 255); int green = (int)(Math.random() * 255); int blue = (int)(Math.random() * 255); int color = 0xff000000 | red << 16 | green << 8 | blue; Paint paint = drawable.getPaint(); //new Paint(Paint.ANTI_ALIAS_FLAG); int darkColor = 0xff000000 | red/4 << 16 | green/4 << 8 | blue/4; RadialGradient gradient = new RadialGradient(37.5f, 12.5f, 50f, color, darkColor, Shader.TileMode.CLAMP); paint.setShader(gradient); shapeHolder.setPaint(paint); balls.add(shapeHolder); return shapeHolder; }
public void select(int dayOfOrder) { this.selected = dayOfOrder; resetSelect(); if (this.mSelectListener != null) { this.mSelectListener.onSelect(dayOfOrder); } TextView tv = (TextView) this.tvList.get(dayOfOrder); tv.setTextColor(getResources().getColor(R.color.ju)); ShapeDrawable oval = new ShapeDrawable(new OvalShape()); if (dayOfOrder == this.orderOfToday) { oval.getPaint().setColor(getResources().getColor(R.color.he)); } else { oval.getPaint().setColor(getResources().getColor(R.color.hb)); } tv.setBackgroundDrawable(oval); }
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(); }
public CircleImageView(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 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); }
private void init(AttributeSet attrs, int defStyle) { // Load attributes final TypedArray a = getContext().obtainStyledAttributes( attrs, R.styleable.LevelView, defStyle, 0); mBackground = new ShapeDrawable(new OvalShape()); mBackground.getPaint().setColor(getResources().getColor(R.color.level_background_color)); mBubble = new ShapeDrawable(new OvalShape()); mBubble.getPaint().setColor(getResources().getColor(R.color.level_bubble_color)); mMarkPaint = new Paint(); mMarkPaint.setColor(getResources().getColor(R.color.level_mark_color)); mEdgePaint = new Paint(); mEdgePaint.setColor(getResources().getColor((R.color.level_edge_color))); mEdgePaint.setStyle(Paint.Style.STROKE); mEdgePaint.setStrokeWidth(a.getDimension(R.styleable.LevelView_edgeWidth, 10)); a.recycle(); }
void setupColorImageView(int[] padding, String type, int[] manualDimensions, boolean[] isManualDimensions, int[] autoDimensions) { colorImageView = new ImageView(gismoContext); fullContainerRelativeLayout.addView(colorImageView); colorImageView.setTag(Enums.ItemTag.Image); GradientDrawable outlineDrawable = new GradientDrawable(); ShapeDrawable shapeDrawable = new ShapeDrawable(); if (type.equals("oval")) { shapeDrawable.setShape(new OvalShape()); outlineDrawable.setShape(GradientDrawable.OVAL); } else { shapeDrawable.setShape(new RectShape()); outlineDrawable.setShape(GradientDrawable.RECTANGLE); } shapeDrawable.setIntrinsicWidth(isManualDimensions[0] ? manualDimensions[0] : autoDimensions[0]); shapeDrawable.setIntrinsicHeight(isManualDimensions[1] ? manualDimensions[1] : autoDimensions[1]); colorImageView.setImageDrawable(new LayerDrawable(new Drawable[]{shapeDrawable, outlineDrawable})); colorImageView.getLayoutParams().height = RelativeLayout.LayoutParams.WRAP_CONTENT; colorImageView.getLayoutParams().width = RelativeLayout.LayoutParams.WRAP_CONTENT; colorImageView.setPadding(padding[0], padding[1], padding[2], padding[3]); colorImageView.setAdjustViewBounds(true); }
public CircleImageView(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 = (int) mShadowRadius; // set padding so the inner image sits correctly within the shadow. setPadding(padding, padding, padding, padding); } circle.getPaint().setColor(color); setBackgroundDrawable(circle); }
public SwipyCircleImageView(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 = (int) mShadowRadius; // set padding so the inner image sits correctly within the shadow. setPadding(padding, padding, padding, padding); } circle.getPaint().setColor(color); setBackgroundDrawable(circle); }
private void createMovingItem() { OvalShape circle = new OvalShape(); ShapeDrawable drawable = new ShapeDrawable(circle); movingItem = new ShapeHolder(drawable); Paint paint = drawable.getPaint(); paint.setColor(mIndicatorSelectedBackground); paint.setAntiAlias(true); switch (mIndicatorMode){ case INSIDE: paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP)); break; case OUTSIDE: paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER)); break; case SOLO: paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC)); break; } movingItem.setPaint(paint); }
private void createMovingItem() { OvalShape circle = new OvalShape(); ShapeDrawable drawable = new ShapeDrawable(circle); movingItem = new ShapeHolder(drawable); Paint paint = drawable.getPaint(); paint.setColor(mIndicatorSelectedBackground); paint.setAntiAlias(true); switch (mIndicatorMode) { case INSIDE: paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP)); break; case OUTSIDE: paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER)); break; case SOLO: paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC)); break; } movingItem.setPaint(paint); }
private ArrayList<ImageButton> generateFollowCircles() { int diameter = mFAB.getType() == FloatingActionButton.TYPE_NORMAL ? Utils.getDimension(mContext, R.dimen.fab_size_normal) : Utils.getDimension(mContext, R.dimen.fab_size_mini); ArrayList<ImageButton> circles = new ArrayList<>(mMenuItems.size()); for (MenuItem item : mMenuItems) { ImageButton circle = new ImageButton(mContext); OvalShape ovalShape = new OvalShape(); ShapeDrawable shapeDrawable = new ShapeDrawable(ovalShape); shapeDrawable.getPaint().setColor(getResources().getColor(item.getBgColor())); circle.setBackgroundDrawable(shapeDrawable); circle.setImageResource(item.getIcon()); LayoutParams lp = new LayoutParams(diameter, diameter); circle.setLayoutParams(lp); circles.add(circle); } return circles; }
public RevealColorView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); //eclipse if (isInEditMode()) { return; } //new出View来 inkView = new View(context); //加到这个layout里面去 addView(inkView); //那个圆 circle = new ShapeDrawable(new OvalShape()); //设置background进去 AppCompat.setBackgroundDrawable(inkView, circle); //隐藏 inkView.setVisibility(View.INVISIBLE); }
private ShapeDrawable getDotBackground() { ShapeDrawable drawable = null; switch (mode) { case ROUND_RECT: int radius = dip2Pixels(dotRadius); float[] outerRect = new float[] { radius, radius, radius, radius, radius, radius, radius, radius }; RoundRectShape rr = new RoundRectShape(outerRect, null, null); drawable = new InnerShapeDrawableWithText(rr, dotText); drawable.getPaint().setColor(dotColor); break; case CIRCLE: OvalShape os = new OvalShape(); drawable = new InnerShapeDrawableWithText(os, dotText); drawable.getPaint().setColor(dotColor); // int paddingPixels = dip2Pixels(8); // drawable.setPadding(paddingPixels, paddingPixels, paddingPixels, // paddingPixels); break; } return drawable; }
private void initColorLayout() { float width = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 48, getContext().getResources().getDisplayMetrics()); mColorLayout.removeAllViews(); for(int i = 0, size = colors.length; i < size; i ++) { ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape()); shapeDrawable.setBounds(0, 0, (int) width, (int) width); shapeDrawable.getPaint().setColor(colors[i]); View view = new View(getContext()); view.setBackgroundDrawable(shapeDrawable); view.setTag(colors[i]); view.setOnClickListener(new ColorItemClickListener()); MarginLayoutParams layoutParams = new LayoutParams((int) width, (int) width); layoutParams.setMargins((int) (width / 8), 0, (int) (width / 8), 0); mColorLayout.addView(view, layoutParams); } }
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) private void Colorize() { for (int i = 0; i < buttons.size(); i++) { ShapeDrawable d = new ShapeDrawable(new OvalShape()); d.setBounds(58, 58, 58, 58); Log.e("Shape drown no", i + ""); buttons.get(i).setVisibility(View.INVISIBLE); d.getPaint().setStyle(Paint.Style.FILL); d.getPaint().setColor(colors.get(i)); buttons.get(i).setBackground(d); } animate(); }
public CircleImageView(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 = (int) mShadowRadius; // set padding so the inner image sits correctly within the shadow. setPadding(padding, padding, padding, padding); } circle.getPaint().setColor(color); setBackgroundDrawable(circle); }
/** * * @param isDisplayInToolbarMenu */ public void setHighLightMode(boolean isDisplayInToolbarMenu){ isHighLightMode = true; ViewGroup.LayoutParams params = getLayoutParams(); params.width = dp2px(getContext(), 8); params.height = params.width; if(isDisplayInToolbarMenu && params instanceof FrameLayout.LayoutParams){ ((FrameLayout.LayoutParams)params).topMargin=dp2px(getContext(), 8); ((FrameLayout.LayoutParams)params).rightMargin=dp2px(getContext(), 8); } setLayoutParams(params); ShapeDrawable drawable = new ShapeDrawable(new OvalShape()); ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, drawable.getPaint()); drawable.getPaint().setColor(backgroundColor); drawable.getPaint().setAntiAlias(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { setBackground(drawable); } else { setBackgroundDrawable(drawable); } setText(""); setVisibility(View.VISIBLE); }