本文整理汇总了Java中android.graphics.drawable.shapes.OvalShape类的典型用法代码示例。如果您正苦于以下问题:Java OvalShape类的具体用法?Java OvalShape怎么用?Java OvalShape使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OvalShape类属于android.graphics.drawable.shapes包,在下文中一共展示了OvalShape类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createCircleDrawable
import android.graphics.drawable.shapes.OvalShape; //导入依赖的package包/类
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;
}
示例2: createCircleDrawable
import android.graphics.drawable.shapes.OvalShape; //导入依赖的package包/类
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;
}
示例3: createProductImageDrawable
import android.graphics.drawable.shapes.OvalShape; //导入依赖的package包/类
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;
}
示例4: createShadowShapeDrawable
import android.graphics.drawable.shapes.OvalShape; //导入依赖的package包/类
@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;
}
示例5: MagnifierView
import android.graphics.drawable.shapes.OvalShape; //导入依赖的package包/类
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);
}
示例6: getLargeNotificationIcon
import android.graphics.drawable.shapes.OvalShape; //导入依赖的package包/类
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;
}
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:26,代码来源:DownloadNotificationService.java
示例7: getCircleIcon
import android.graphics.drawable.shapes.OvalShape; //导入依赖的package包/类
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);
}
示例8: buildColorPickerView
import android.graphics.drawable.shapes.OvalShape; //导入依赖的package包/类
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);
}
示例9: addBall
import android.graphics.drawable.shapes.OvalShape; //导入依赖的package包/类
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;
}
示例10: createProductImageDrawable
import android.graphics.drawable.shapes.OvalShape; //导入依赖的package包/类
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;
}
示例11: select
import android.graphics.drawable.shapes.OvalShape; //导入依赖的package包/类
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);
}
示例12: setShape
import android.graphics.drawable.shapes.OvalShape; //导入依赖的package包/类
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();
}
示例13: CircleImageView
import android.graphics.drawable.shapes.OvalShape; //导入依赖的package包/类
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);
}
示例14: CircleImageViewSupport
import android.graphics.drawable.shapes.OvalShape; //导入依赖的package包/类
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);
}
示例15: init
import android.graphics.drawable.shapes.OvalShape; //导入依赖的package包/类
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();
}