Java Code Examples for android.graphics.drawable.LayerDrawable#setLayerInset()
The following examples show how to use
android.graphics.drawable.LayerDrawable#setLayerInset() .
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: FlatUI.java From FamilyChat with Apache License 2.0 | 6 votes |
/** * Returns a suitable drawable for ActionBar with theme colors. * * @param theme selected theme * @param dark boolean for choosing dark colors or primary colors * @param borderBottom bottom border width * @return drawable to be used in ActionBar */ public static Drawable getActionBarDrawable(Activity activity, int theme, boolean dark, float borderBottom) { int[] colors = activity.getResources().getIntArray(theme); int color1 = colors[2]; int color2 = colors[1]; if (dark) { color1 = colors[1]; color2 = colors[0]; } borderBottom = dipToPx(activity, borderBottom); PaintDrawable front = new PaintDrawable(color1); PaintDrawable bottom = new PaintDrawable(color2); Drawable[] d = {bottom, front}; LayerDrawable drawable = new LayerDrawable(d); drawable.setLayerInset(1, 0, 0, 0, (int) borderBottom); return drawable; }
Example 2
Source File: ArrowButton.java From hkm-progress-button with MIT License | 6 votes |
protected LayerDrawable createCommonFace() { if (resIcon != -1) { LayerDrawable ly = afterProcessLayerDrawable(new LayerDrawable( new Drawable[]{ createFillDrawable(), getArrow(), getIcon() })); ly.setLayerInset(2, icon_size_text_padding, 0, 0, 0); return ly; } else { return afterProcessLayerDrawable(new LayerDrawable( new Drawable[]{ createFillDrawable(), getArrow() })); } }
Example 3
Source File: FloatingActionButton.java From GalleryFinal with Apache License 2.0 | 6 votes |
void updateBackground() { float circleLeft = mShadowRadius; float circleTop = mShadowRadius - mShadowOffset; final RectF circleRect = new RectF(circleLeft, circleTop, circleLeft + mCircleSize, circleTop + mCircleSize); LayerDrawable layerDrawable = new LayerDrawable( new Drawable[] { new BitmapDrawable(getResources()), createFillDrawable(circleRect), new BitmapDrawable(getResources()), getIconDrawable() }); float iconOffset = (mCircleSize - getDimension(R.dimen.fab_icon_size)) / 2f; int iconInsetHorizontal = (int) (mShadowRadius + iconOffset); int iconInsetTop = (int) (circleTop + iconOffset); int iconInsetBottom = (int) (mShadowRadius + mShadowOffset + iconOffset); layerDrawable.setLayerInset(3, iconInsetHorizontal, iconInsetTop, iconInsetHorizontal, iconInsetBottom); setBackgroundCompat(layerDrawable); }
Example 4
Source File: FloatingActionButton.java From UltimateAndroid with Apache License 2.0 | 6 votes |
void updateBackground() { float circleLeft = mShadowRadius; float circleTop = mShadowRadius - mShadowOffset; final RectF circleRect = new RectF(circleLeft, circleTop, circleLeft + mCircleSize, circleTop + mCircleSize); LayerDrawable layerDrawable = new LayerDrawable( new Drawable[] { getResources().getDrawable(mSize == SIZE_NORMAL ? R.drawable.floating_action_button_fab_bg_normal : R.drawable.floating_action_button_fab_bg_mini), createFillDrawable(circleRect), createStrokesDrawable(circleRect), getIconDrawable() }); float iconOffset = (mCircleSize - getDimension(R.dimen.fab_icon_size)) / 2f; int iconInsetHorizontal = (int) (mShadowRadius + iconOffset); int iconInsetTop = (int) (circleTop + iconOffset); int iconInsetBottom = (int) (mShadowRadius + mShadowOffset + iconOffset); layerDrawable.setLayerInset(3, iconInsetHorizontal, iconInsetTop, iconInsetHorizontal, iconInsetBottom); setBackgroundCompat(layerDrawable); }
Example 5
Source File: BubbleDrawableBuilder.java From mollyim-android with GNU General Public License v3.0 | 6 votes |
public Drawable create(Context context) { final GradientDrawable bubble = new GradientDrawable(); final int radius = context.getResources().getDimensionPixelSize(R.dimen.message_bubble_corner_radius); final float[] radii = cornerBooleansToRadii(corners, radius); bubble.setColor(color); bubble.setCornerRadii(radii); if (!hasShadow) { return bubble; } else { final GradientDrawable shadow = new GradientDrawable(); final int distance = context.getResources().getDimensionPixelSize(R.dimen.message_bubble_shadow_distance); shadow.setColor(shadowColor); shadow.setCornerRadii(radii); final LayerDrawable layers = new LayerDrawable(new Drawable[]{shadow, bubble}); layers.setLayerInset(1, 0, 0, 0, distance); return layers; } }
Example 6
Source File: FloatingActionButton.java From UltimateAndroid with Apache License 2.0 | 6 votes |
private Drawable createDrawable(int color) { OvalShape ovalShape = new OvalShape(); ShapeDrawable shapeDrawable = new ShapeDrawable(ovalShape); shapeDrawable.getPaint().setColor(color); if (mShadow) { LayerDrawable layerDrawable = new LayerDrawable( new Drawable[]{getResources().getDrawable(R.drawable.floating_acition_button_shadow), shapeDrawable}); int shadowSize = getDimension( mType == TYPE_NORMAL ? R.dimen.fab_shadow_size : R.dimen.fab_mini_shadow_size); layerDrawable.setLayerInset(1, shadowSize, shadowSize, shadowSize, shadowSize); return layerDrawable; } else { return shapeDrawable; } }
Example 7
Source File: FButton.java From Trivia-Knowledge with Apache License 2.0 | 5 votes |
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; }
Example 8
Source File: FileListAdapter.java From faceswap with Apache License 2.0 | 5 votes |
private Drawable getFileDrawable(int fileResource) { Drawable firstLayer = mContext.getResources().getDrawable(fileResource); LayerDrawable drawable = new LayerDrawable(new Drawable[]{ mContext.getResources().getDrawable(R.drawable.fplib_circle), firstLayer }); drawable.setLayerInset(1, (int) iconPadding, (int) iconPadding, (int) iconPadding, (int) iconPadding); return drawable; }
Example 9
Source File: ConditionsDrawables.java From PressureNet with GNU General Public License v3.0 | 5 votes |
public Drawable getSingleDrawable(LayerDrawable layerDrawable) { int resourceBitmapHeight = layerDrawable.getMinimumHeight(), resourceBitmapWidth = layerDrawable .getMinimumWidth(); float widthInInches = 0.2f; int widthInPixels = (int) (widthInInches * mContext.getResources() .getDisplayMetrics().densityDpi); int heightInPixels = (int) (widthInPixels * resourceBitmapHeight / resourceBitmapWidth); int insetLeft = 10, insetTop = 10, insetRight = 10, insetBottom = 10; layerDrawable.setLayerInset(1, insetLeft, insetTop, insetRight, insetBottom); Bitmap bitmap = Bitmap.createBitmap(widthInPixels, heightInPixels, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); layerDrawable.setBounds(0, 0, widthInPixels, heightInPixels); layerDrawable.draw(canvas); BitmapDrawable bitmapDrawable = new BitmapDrawable(mContext.getResources(), bitmap); bitmapDrawable.setBounds(0, 0, widthInPixels, heightInPixels); return bitmapDrawable; }
Example 10
Source File: LiveButton.java From LiveButton with Apache License 2.0 | 5 votes |
private LayerDrawable getLayerList(boolean isPressed) { float[] radii = new float[8]; for (int i = 0; i < radii.length; i++) { radii[i] = corners; } ShapeDrawable shapeShadow = new ShapeDrawable(new RectShape()); shapeShadow.getPaint().setColor(shadowColor); shapeShadow.setShape(new RoundRectShape(radii, null, null)); ShapeDrawable shapeBackground = new ShapeDrawable(new RectShape()); shapeBackground.getPaint().setColor(backgroundColor); shapeBackground.setShape(new RoundRectShape(radii, null, null)); LayerDrawable composite = new LayerDrawable(new Drawable[]{shapeShadow, shapeBackground}); if (isPressed) { composite.setLayerInset(0, 0, (int) (normalHeight - pressedHeight), 0, 0); composite.setLayerInset(1, 0, (int) (normalHeight - pressedHeight), 0, (int) pressedHeight); } else { composite.setLayerInset(0, 0, 0, 0, 0); composite.setLayerInset(1, 0, 0, 0, (int) normalHeight); } return composite; }
Example 11
Source File: FileRecyclerViewAdapter.java From FilePickerLibrary with Apache License 2.0 | 5 votes |
private Drawable getFileDrawable(int fileResource) { Drawable firstLayer = context.getResources().getDrawable(fileResource); LayerDrawable drawable = new LayerDrawable(new Drawable[]{ context.getResources().getDrawable(R.drawable.fplib_circle), firstLayer }); drawable.setLayerInset(1, (int) iconPadding, (int) iconPadding, (int) iconPadding, (int) iconPadding); return drawable; }
Example 12
Source File: Tab.java From BottomNavigationBar with Apache License 2.0 | 5 votes |
void showBadge(@NonNull Drawable badge) { LayerDrawable layerDrawable = new LayerDrawable(new Drawable[]{iconDrawable, badge}); layerDrawable.setLayerInset( 1, iconDrawable.getIntrinsicWidth(), 0, 0, iconDrawable.getIntrinsicHeight() ); icon.setImageDrawable(layerDrawable); }
Example 13
Source File: DefaultClusterRenderer.java From android-maps-utils with Apache License 2.0 | 5 votes |
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; }
Example 14
Source File: FloatingActionButton.java From android-floating-action-button with Apache License 2.0 | 5 votes |
void updateBackground() { final float strokeWidth = getDimension(R.dimen.fab_stroke_width); final float halfStrokeWidth = strokeWidth / 2f; LayerDrawable layerDrawable = new LayerDrawable( new Drawable[] { getResources().getDrawable(mSize == SIZE_NORMAL ? R.drawable.fab_bg_normal : R.drawable.fab_bg_mini), createFillDrawable(strokeWidth), createOuterStrokeDrawable(strokeWidth), getIconDrawable() }); int iconOffset = (int) (mCircleSize - getDimension(R.dimen.fab_icon_size)) / 2; int circleInsetHorizontal = (int) (mShadowRadius); int circleInsetTop = (int) (mShadowRadius - mShadowOffset); int circleInsetBottom = (int) (mShadowRadius + mShadowOffset); layerDrawable.setLayerInset(1, circleInsetHorizontal, circleInsetTop, circleInsetHorizontal, circleInsetBottom); layerDrawable.setLayerInset(2, (int) (circleInsetHorizontal - halfStrokeWidth), (int) (circleInsetTop - halfStrokeWidth), (int) (circleInsetHorizontal - halfStrokeWidth), (int) (circleInsetBottom - halfStrokeWidth)); layerDrawable.setLayerInset(3, circleInsetHorizontal + iconOffset, circleInsetTop + iconOffset, circleInsetHorizontal + iconOffset, circleInsetBottom + iconOffset); setBackgroundCompat(layerDrawable); }
Example 15
Source File: FileListAdapter.java From FilePickerLibrary with Apache License 2.0 | 5 votes |
private Drawable getFileDrawable(int fileResource) { Drawable firstLayer = mContext.getResources().getDrawable(fileResource); LayerDrawable drawable = new LayerDrawable(new Drawable[]{ mContext.getResources().getDrawable(R.drawable.fplib_circle), firstLayer }); drawable.setLayerInset(1, (int) iconPadding, (int) iconPadding, (int) iconPadding, (int) iconPadding); return drawable; }
Example 16
Source File: FloatingActionButton.java From FloatingActionButton with Apache License 2.0 | 5 votes |
void updateBackground() { final float strokeWidth = getDimension(R.dimen.fab_stroke_width); final float halfStrokeWidth = strokeWidth / 2f; LayerDrawable layerDrawable = new LayerDrawable( new Drawable[] { getResources().getDrawable(mSize == SIZE_NORMAL ? R.drawable.fab_bg_normal : R.drawable.fab_bg_mini), createFillDrawable(strokeWidth), createOuterStrokeDrawable(strokeWidth), getIconDrawable() }); int iconOffset = (int) (mCircleSize - getDimension(R.dimen.fab_icon_size)) / 2; int circleInsetHorizontal = (int) (mShadowRadius); int circleInsetTop = (int) (mShadowRadius - mShadowOffset); int circleInsetBottom = (int) (mShadowRadius + mShadowOffset); layerDrawable.setLayerInset(1, circleInsetHorizontal, circleInsetTop, circleInsetHorizontal, circleInsetBottom); layerDrawable.setLayerInset(2, (int) (circleInsetHorizontal - halfStrokeWidth), (int) (circleInsetTop - halfStrokeWidth), (int) (circleInsetHorizontal - halfStrokeWidth), (int) (circleInsetBottom - halfStrokeWidth)); layerDrawable.setLayerInset(3, circleInsetHorizontal + iconOffset, circleInsetTop + iconOffset, circleInsetHorizontal + iconOffset, circleInsetBottom + iconOffset); setBackgroundCompat(layerDrawable); }
Example 17
Source File: DiscView.java From Yuan-SxMusic with Apache License 2.0 | 5 votes |
/** * 得到唱盘图片 * 唱盘图片由空心圆盘及音乐专辑图片“合成”得到 */ public Drawable getDiscDrawable(Bitmap bitmap) { int discSize = (int) (mScreenWidth * DisplayUtil.SCALE_DISC_SIZE); int musicPicSize = (int) (mScreenWidth * DisplayUtil.SCALE_MUSIC_PIC_SIZE); Bitmap bitmapDisc = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getResources(), R .drawable.ic_disc), discSize, discSize, false); Bitmap bitmapMusicPic = Bitmap.createScaledBitmap(bitmap, musicPicSize, musicPicSize, true); BitmapDrawable discDrawable = new BitmapDrawable(bitmapDisc); RoundedBitmapDrawable roundMusicDrawable = RoundedBitmapDrawableFactory.create (getResources(), bitmapMusicPic); //抗锯齿 discDrawable.setAntiAlias(true); roundMusicDrawable.setAntiAlias(true); Drawable[] drawables = new Drawable[2]; drawables[0] = roundMusicDrawable; drawables[1] = discDrawable; LayerDrawable layerDrawable = new LayerDrawable(drawables); int musicPicMargin = (int) ((DisplayUtil.SCALE_DISC_SIZE - DisplayUtil .SCALE_MUSIC_PIC_SIZE) * mScreenWidth / 2); //调整专辑图片的四周边距,让其显示在正中 layerDrawable.setLayerInset(0, musicPicMargin, musicPicMargin, musicPicMargin, musicPicMargin); return layerDrawable; }
Example 18
Source File: FloatingActionButton.java From TvRemoteControl with Apache License 2.0 | 5 votes |
void updateBackground() { final float strokeWidth = getDimension(R.dimen.fab_stroke_width); final float halfStrokeWidth = strokeWidth / 2f; LayerDrawable layerDrawable = new LayerDrawable( new Drawable[] { getResources().getDrawable(mSize == SIZE_NORMAL ? R.drawable.fab_bg_normal : R.drawable.fab_bg_mini), createFillDrawable(strokeWidth), createOuterStrokeDrawable(strokeWidth), getIconDrawable() }); int iconOffset = (int) (mCircleSize - getDimension(R.dimen.fab_icon_size)) / 2; int circleInsetHorizontal = (int) (mShadowRadius); int circleInsetTop = (int) (mShadowRadius - mShadowOffset); int circleInsetBottom = (int) (mShadowRadius + mShadowOffset); layerDrawable.setLayerInset(1, circleInsetHorizontal, circleInsetTop, circleInsetHorizontal, circleInsetBottom); layerDrawable.setLayerInset(2, (int) (circleInsetHorizontal - halfStrokeWidth), (int) (circleInsetTop - halfStrokeWidth), (int) (circleInsetHorizontal - halfStrokeWidth), (int) (circleInsetBottom - halfStrokeWidth)); layerDrawable.setLayerInset(3, circleInsetHorizontal + iconOffset, circleInsetTop + iconOffset, circleInsetHorizontal + iconOffset, circleInsetBottom + iconOffset); setBackgroundCompat(layerDrawable); }
Example 19
Source File: DefaultClusterRenderer.java From react-native-baidu-map with MIT License | 5 votes |
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; }
Example 20
Source File: LoadingButton.java From LoadingButton with MIT License | 5 votes |
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; }