void updateBackground() { LayerDrawable layerDrawable; if (mShowShadow) { layerDrawable = new LayerDrawable(new Drawable[]{ new Shadow(), createFillDrawable() }); int leftInset = mShadowRadius + Math.abs(mShadowXOffset); int topInset = mShadowRadius + Math.abs(mShadowYOffset); int rightInset = (mShadowRadius + Math.abs(mShadowXOffset)); int bottomInset = (mShadowRadius + Math.abs(mShadowYOffset)); layerDrawable.setLayerInset( 1, leftInset, topInset, rightInset, bottomInset ); } else { layerDrawable = new LayerDrawable(new Drawable[]{ createFillDrawable() }); } setBackgroundCompat(layerDrawable); }
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; }
@Test public void setDrawableByLayerId_shouldReturnFalseIfIdNotFound() throws Exception { LayerDrawable layerDrawable = new LayerDrawable(drawables); boolean ret = layerDrawable.setDrawableByLayerId(123, drawable4000); assertFalse(ret); }
int maskColor = Color.argb(50, Color.red(mTintColor), Color.green(mTintColor), Color.blue(mTintColor)); maskDrawable.setColor(maskColor); LayerDrawable pressedDrawable = new LayerDrawable(new Drawable[] {uncheckedDrawable, maskDrawable});
private static StateListDrawable setupStateDrawable(ViewGroupPosition position, int strokeWidth, GradientDrawable defaultGd, GradientDrawable activeGd, GradientDrawable disabledGd) { StateListDrawable stateListDrawable = new StateListDrawable(); LayerDrawable defaultLayer = new LayerDrawable(new Drawable[]{defaultGd}); LayerDrawable activeLayer = new LayerDrawable(new Drawable[]{activeGd}); LayerDrawable disabledLayer = new LayerDrawable(new Drawable[]{disabledGd});
public DropDownMenu(Context context) { super(View.inflate(context, R.layout.carbon_popupmenu, null)); getContentView().setLayoutParams(new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); recycler = getContentView().findViewById(R.id.recycler); recycler.setLayoutManager(new LinearLayoutManager(context)); recycler.setOnKeyListener((v, keyCode, event) -> { if (event.getAction() == KeyEvent.ACTION_UP && (keyCode == KeyEvent.KEYCODE_MENU || keyCode == KeyEvent.KEYCODE_BACK)) { dismiss(); return true; } return false; }); LayerDrawable dividerDrawable = new LayerDrawable(new Drawable[]{ new ColorDrawable(Carbon.getThemeColor(context, R.attr.carbon_colorForeground)), new ColorDrawable(Carbon.getThemeColor(context, R.attr.carbon_dividerColor)) }); DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(dividerDrawable, context.getResources().getDimensionPixelSize(R.dimen.carbon_dividerHeight)); dividerItemDecoration.setDrawAfter(position -> getAdapter().getItem(position) == customItem); recycler.addItemDecoration(dividerItemDecoration); defaultAdapter = new DropDown.Adapter<>(); recycler.setAdapter(defaultAdapter); setBackgroundDrawable(new ColorDrawable(context.getResources().getColor(android.R.color.transparent))); setTouchable(true); setFocusable(true); setOutsideTouchable(true); setAnimationStyle(0); }
@Test public void testGetNumberOfLayers() { LayerDrawable layerDrawable = new LayerDrawable(drawables); assertEquals("count", 3, layerDrawable.getNumberOfLayers()); }
void updateBackground() { LayerDrawable layerDrawable; if (hasShadow()) { layerDrawable = new LayerDrawable(new Drawable[]{ new Shadow(), createFillDrawable(), }); } else { layerDrawable = new LayerDrawable(new Drawable[]{ createFillDrawable(), getIconDrawable()
return null; } else { LayerDrawable layerDrawable = new LayerDrawable(drawables); for (int i = 0; i < drawables.length; i++) { int[] childLayersAttr = childLayersAttrs[i];
@Test public void setDrawableByLayerId_shouldReturnTrueIfIdWasFound() throws Exception { LayerDrawable layerDrawable = new LayerDrawable(drawables); int index = 0; int layerId = 345; layerDrawable.setId(index, layerId); boolean ret = layerDrawable.setDrawableByLayerId(layerId, drawable4000); assertTrue(ret); } }
@Test public void testSetDrawableByLayerId1() throws Exception { LayerDrawable layerDrawable = new LayerDrawable(drawables); int index = 1; int layerId = 345; layerDrawable.setId(index, layerId); layerDrawable.setDrawableByLayerId(layerId, drawable4000); assertEquals(shadowOf(drawable4000).getCreatedFromResId(), shadowOf(layerDrawable.getDrawable(index)).getCreatedFromResId()); }
@Test public void testSetDrawableByLayerId2() throws Exception { LayerDrawable layerDrawable = new LayerDrawable(drawables); int index = 0; int layerId = 345; layerDrawable.setId(index, layerId); layerDrawable.setDrawableByLayerId(layerId, drawable4000); assertEquals(shadowOf(drawable4000).getCreatedFromResId(), shadowOf(layerDrawable.getDrawable(index)).getCreatedFromResId()); }
protected BorderDrawable getOrCreateBorder() { if (mBackgroundDrawable == null) { Drawable backgroundDrawable = mHost.getBackground(); WXViewUtils.setBackGround(mHost,null); mBackgroundDrawable = new BorderDrawable(); if (backgroundDrawable == null) { WXViewUtils.setBackGround(mHost,mBackgroundDrawable); } else { //TODO Not strictly clip according to background-clip:border-box WXViewUtils.setBackGround(mHost,new LayerDrawable(new Drawable[]{ mBackgroundDrawable,backgroundDrawable})); } } return mBackgroundDrawable; }
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); }
/** * Create a drawable to be used as for a bubble. This is not necessarily the best way to create * drawables for your bubbles, and you should probably use a layer-list or combine the icon and * background in your favorite image editing program. * * @param icon drawable for the icon * @param background drawable for the background * @return a drawable where the icon appears over the background */ public static Drawable makeBubbleDrawable(Drawable icon, Drawable background) { return new LayerDrawable(new Drawable[]{icon, background}); }
public void updateIcon() { if (mSelectIcon == null) { mIconView.setImageDrawable(mNormalIcon); } else { mCompundIcon = new LayerDrawable(new Drawable[]{mNormalIcon, mSelectIcon}); mNormalIcon.setAlpha(255); mSelectIcon.setAlpha(0); mIconView.setImageDrawable(mCompundIcon); } }
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; }
private Drawable getRotateDrawable(final Drawable d, final float angle) { final Drawable[] arD = { d }; return new LayerDrawable(arD) { @Override public void draw(final Canvas canvas) { canvas.save(); canvas.rotate(angle, d.getBounds().width() / 2, d.getBounds().height() / 2); super.draw(canvas); canvas.restore(); } }; }
@Override public Drawable getDrawable(int position) { Drawable[] drawable = new Drawable[] { createOvalDrawable(getItem(position).getValue()), new TextDrawable(String.valueOf(position)) }; return new LayerDrawable(drawable); }
Drawable getLayerDrawable(int progress, int background) { ShapeDrawable shape = new ShapeDrawable(); shape.getPaint().setStyle(Paint.Style.FILL); shape.getPaint().setColor(background); ShapeDrawable shapeD = new ShapeDrawable(); shapeD.getPaint().setStyle(Paint.Style.FILL); shapeD.getPaint().setColor(progress); ClipDrawable clipDrawable = new ClipDrawable(shapeD, Gravity.LEFT, ClipDrawable.HORIZONTAL); return new LayerDrawable(new Drawable[]{shape, clipDrawable}); } }