Example usage for android.graphics.drawable LayerDrawable LayerDrawable

List of usage examples for android.graphics.drawable LayerDrawable LayerDrawable

Introduction

In this page you can find the example usage for android.graphics.drawable LayerDrawable LayerDrawable.

Prototype

public LayerDrawable(@NonNull Drawable[] layers) 

Source Link

Document

Creates a new layer drawable with the list of specified layers.

Usage

From source file:com.richtodd.android.quiltdesign.block.PaperPiecedBlockPiece.java

private Drawable createDrawable(RenderOptions renderOptions) {

    PathShape pathShape = new PathShape(getPath(renderOptions.getWidth(), renderOptions.getHeight()),
            renderOptions.getWidth(), renderOptions.getHeight());

    if (renderOptions.getRenderStyle() == RenderStyles.BlackWhite) {

        ShapeDrawable strokeDrawable = new ShapeDrawable(pathShape);
        strokeDrawable.setBounds(0, 0, renderOptions.getWidth(), renderOptions.getHeight());
        strokeDrawable.getPaint().setColor(Color.BLACK);
        strokeDrawable.getPaint().setStyle(Paint.Style.STROKE);
        strokeDrawable.getPaint().setStrokeWidth(renderOptions.getStrokeWidth());

        ShapeDrawable fillDrawable = new ShapeDrawable(pathShape);
        fillDrawable.setBounds(0, 0, renderOptions.getWidth(), renderOptions.getHeight());
        fillDrawable.getPaint().setColor(Color.WHITE);
        fillDrawable.getPaint().setStyle(Paint.Style.FILL);

        Drawable[] layers = new Drawable[2];
        layers[0] = fillDrawable;/*from  ww  w . java2  s .  co m*/
        layers[1] = strokeDrawable;
        LayerDrawable drawable = new LayerDrawable(layers);

        return drawable;

    } else {

        ShapeDrawable drawable = new ShapeDrawable(pathShape);
        drawable.getPaint().setColor(getColor());
        drawable.getPaint().setStyle(Paint.Style.FILL);

        return drawable;
    }
}

From source file:io.imoji.sdk.editor.fragment.TagImojiFragment.java

public Drawable createTagDrawable() {

    GradientDrawable d = new GradientDrawable();
    TypedArray a = getActivity().getTheme().obtainStyledAttributes(new int[] { R.attr.colorAccent });
    final int accentColor = a.getColor(0, Color.WHITE);
    a.recycle();/*from w ww.  ja va  2  s. c  o  m*/
    d.setColor(0xB3FFFFFF & accentColor);
    d.setCornerRadius(getResources().getDimension(R.dimen.dim_8dp));
    d.setShape(GradientDrawable.RECTANGLE);

    GradientDrawable d1 = new GradientDrawable();
    d1.setCornerRadius(getResources().getDimension(R.dimen.dim_8dp));
    d1.setStroke((int) getResources().getDimension(R.dimen.dim_0_5dp), 0x66FFFFFF & Color.BLACK);

    GradientDrawable d2 = new GradientDrawable();
    d2.setStroke((int) getResources().getDimension(R.dimen.dim_1dp), accentColor);
    d2.setCornerRadius(getResources().getDimension(R.dimen.dim_8dp));

    LayerDrawable layer = new LayerDrawable(new Drawable[] { d, d2, d1 });

    int halfDp = (int) getResources().getDimension(R.dimen.dim_0_5dp);
    int oneDp = (int) getResources().getDimension(R.dimen.dim_1dp);
    int oneAndHalf = halfDp + oneDp;

    layer.setLayerInset(2, 0, 0, 0, 0);
    layer.setLayerInset(1, halfDp, halfDp, halfDp, halfDp);
    layer.setLayerInset(0, oneAndHalf, oneAndHalf, oneAndHalf, oneAndHalf);

    return layer;
}

From source file:com.appeaser.sublimenavigationviewlibrary.SublimeThemer.java

private void setDefaultItemBackground() {
    TypedValue value = new TypedValue();
    int colorControlHighlight = 0;
    if (mContext.getTheme().resolveAttribute(R.attr.colorControlHighlight, value, true)) {
        colorControlHighlight = value.data;
    } else {/*from  w ww. ja  v  a2  s  . c  o m*/
        colorControlHighlight = mDefaultTheme == DefaultTheme.LIGHT
                ? mContext.getResources().getColor(R.color.snv_ripple_material_light)
                : mContext.getResources().getColor(R.color.snv_ripple_material_dark);
    }

    StateListDrawable drawable = new StateListDrawable();
    LayerDrawable checked = new LayerDrawable(
            new Drawable[] { new ColorDrawable(colorControlHighlight), obtainSelectableItemBackground() });
    drawable.addState(CHECKED_STATE_SET, checked);
    drawable.addState(EMPTY_STATE_SET, obtainSelectableItemBackground());
    mItemBackground = drawable;
}

From source file:com.androguide.apkreator.MainActivity.java

/**
 * Method to set the color scheme according to the color defined in
 * config.xml/*from   ww  w. j a v  a  2 s.c  o  m*/
 *
 * @param newColor : the color retrieved from config.xml
 */
public void changeColor(int newColor) {
    tabs.setIndicatorColor(newColor);
    Drawable colorDrawable = new ColorDrawable(newColor);
    Drawable bottomDrawable = getResources().getDrawable(R.drawable.actionbar_bottom);
    LayerDrawable ld = new LayerDrawable(new Drawable[] { colorDrawable, bottomDrawable });

    if (oldBackground == null) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1)
            ld.setCallback(drawableCallback);
        else
            getSupportActionBar().setBackgroundDrawable(ld);

    } else {
        TransitionDrawable td = new TransitionDrawable(new Drawable[] { oldBackground, ld });
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1)
            td.setCallback(drawableCallback);
        else
            getSupportActionBar().setBackgroundDrawable(td);
        td.startTransition(200);
    }
    oldBackground = ld;
    currentColor = newColor;

    /**
     * The following is a work-around to avoid NPE, see the following
     * thread:
     *
     * @see http://stackoverflow.com/questions/11002691/actionbar-
     *      setbackgrounddrawable-nulling-background-from-thread-handler
     */
    try {
        getSupportActionBar().setDisplayShowTitleEnabled(false);
        getSupportActionBar().setDisplayShowTitleEnabled(true);
    } catch (NullPointerException e) {
        Log.e("NPE", e.getMessage());
    }

}

From source file:de.mrapp.android.view.FloatingActionButton.java

/**
 * Creates and returns a drawable, which can be used as the floating action button's background,
 * when it is activated.//ww  w .  ja  v  a 2  s . c  om
 *
 * @return The drawable, which has been created, as an instance of the class {@link Drawable}
 */
private Drawable createActivatedBackgroundDrawable() {
    Drawable drawable = createBackgroundDrawable(getColor());
    Drawable hoverDrawable = createBackgroundDrawable(getActivatedColor());
    return new LayerDrawable(new Drawable[] { drawable, hoverDrawable });
}

From source file:de.mrapp.android.view.FloatingActionButton.java

/**
 * Creates and returns a drawable, which can be used as the floating action button's background,
 * when it is pressed.// www .j  av  a  2s  .  co  m
 *
 * @return The drawable, which has been created, as an instance of the class {@link Drawable}
 */
private Drawable createPressedBackgroundDrawable() {
    Drawable drawable = createBackgroundDrawable(getColor());
    Drawable hoverDrawable = createBackgroundDrawable(getPressedColor());
    return new LayerDrawable(new Drawable[] { drawable, hoverDrawable });
}

From source file:com.winneredge.stockly.wcommons.floatingactionwidget.FloatingActionButton.java

void updateBackground() {
    LayerDrawable layerDrawable;//w w  w .  j a  va2s .  c o  m
    if (hasShadow()) {
        layerDrawable = new LayerDrawable(
                new Drawable[] { new Shadow(), createFillDrawable(), getIconDrawable() });
    } else {
        layerDrawable = new LayerDrawable(new Drawable[] { createFillDrawable(), getIconDrawable() });
    }

    int iconSize = -1;
    if (getIconDrawable() != null) {
        iconSize = Math.max(getIconDrawable().getIntrinsicWidth(), getIconDrawable().getIntrinsicHeight());
    }
    int iconOffset = (getCircleSize() - (iconSize > 0 ? iconSize : mIconSize)) / 2;
    int circleInsetHorizontal = hasShadow() ? mShadowRadius + Math.abs(mShadowXOffset) : 0;
    int circleInsetVertical = hasShadow() ? mShadowRadius + Math.abs(mShadowYOffset) : 0;

    if (mProgressBarEnabled) {
        circleInsetHorizontal += mProgressWidth;
        circleInsetVertical += mProgressWidth;
    }

    /*layerDrawable.setLayerInset(
        mShowShadow ? 1 : 0,
        circleInsetHorizontal,
        circleInsetVertical,
        circleInsetHorizontal,
        circleInsetVertical
    );*/
    layerDrawable.setLayerInset(hasShadow() ? 2 : 1, circleInsetHorizontal + iconOffset,
            circleInsetVertical + iconOffset, circleInsetHorizontal + iconOffset,
            circleInsetVertical + iconOffset);

    setBackgroundCompat(layerDrawable);
}

From source file:de.mrapp.android.view.FloatingActionButton.java

/**
 * Creates and returns a drawable, which can be used as the floating action button's background,
 * when it is disabled./*from w  ww  . j a  v a2 s  . c o m*/
 *
 * @return The drawable, which has been created, as an instance of the class {@link Drawable}
 */
private Drawable createDisabledBackgroundDrawable() {
    Drawable drawable = createBackgroundDrawable(getColor());
    Drawable hoverDrawable = createBackgroundDrawable(getDisabledColor());
    return new LayerDrawable(new Drawable[] { drawable, hoverDrawable });
}

From source file:com.ksharkapps.musicnow.ui.activities.BaseActivity.java

public void changeActionBarColor(int newColor) {

    int color = newColor != 0 ? newColor : SettingsActivity.getActionBarColor(this);
    Drawable colorDrawable = new ColorDrawable(color);
    Drawable bottomDrawable = getResources().getDrawable(R.drawable.transparent_overlay);
    LayerDrawable ld = new LayerDrawable(new Drawable[] { colorDrawable, bottomDrawable });

    if (oldBackground == null) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
            ld.setCallback(drawableCallback);
        } else {/*from ww  w .  j  a va  2  s .co m*/
            actBar.setBackgroundDrawable(colorDrawable);
        }

    } else {
        TransitionDrawable td = new TransitionDrawable(new Drawable[] { oldBackground, ld });
        // workaround for broken ActionBarContainer drawable handling on
        // pre-API 17 builds
        // https://github.com/android/platform_frameworks_base/commit/a7cc06d82e45918c37429a59b14545c6a57db4e4
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
            td.setCallback(drawableCallback);
        } else {
            actBar.setBackgroundDrawable(td);
        }
        td.startTransition(200);
    }

    oldBackground = ld;

    // http://stackoverflow.com/questions/11002691/actionbar-setbackgrounddrawable-nulling-background-from-thread-handler
    actBar.setDisplayShowTitleEnabled(false);
    actBar.setDisplayShowTitleEnabled(true);

    if (Utils.hasKitKat()) {
        if (SettingsActivity.getTranslucentMode(this)) {
            SystemBarTintManager tintManager = new SystemBarTintManager(this);
            tintManager.setStatusBarTintEnabled(true);
            tintManager.setStatusBarTintColor(getResources().getColor(R.color.contextual_actionbar_color));

        }

    }

}

From source file:com.actionbarsherlock.internal.widget.IcsProgressBar.java

/**
 * Converts a drawable to a tiled version of itself. It will recursively
 * traverse layer and state list drawables.
 *//*from w  w  w. j a  v  a  2  s . c  om*/
private Drawable tileify(Drawable drawable, boolean clip) {

    if (drawable instanceof LayerDrawable) {
        LayerDrawable background = (LayerDrawable) drawable;
        final int N = background.getNumberOfLayers();
        Drawable[] outDrawables = new Drawable[N];

        for (int i = 0; i < N; i++) {
            int id = background.getId(i);
            outDrawables[i] = tileify(background.getDrawable(i),
                    (id == android.R.id.progress || id == android.R.id.secondaryProgress));
        }

        LayerDrawable newBg = new LayerDrawable(outDrawables);

        for (int i = 0; i < N; i++) {
            newBg.setId(i, background.getId(i));
        }

        return newBg;

    } /* else if (drawable instanceof StateListDrawable) {
      StateListDrawable in = (StateListDrawable) drawable;
      StateListDrawable out = new StateListDrawable();
      int numStates = in.getStateCount();
      for (int i = 0; i < numStates; i++) {
          out.addState(in.getStateSet(i), tileify(in.getStateDrawable(i), clip));
      }
      return out;
              
      }*/ else if (drawable instanceof BitmapDrawable) {
        final Bitmap tileBitmap = ((BitmapDrawable) drawable).getBitmap();
        if (mSampleTile == null) {
            mSampleTile = tileBitmap;
        }

        final ShapeDrawable shapeDrawable = new ShapeDrawable(getDrawableShape());

        final BitmapShader bitmapShader = new BitmapShader(tileBitmap, Shader.TileMode.REPEAT,
                Shader.TileMode.CLAMP);
        shapeDrawable.getPaint().setShader(bitmapShader);

        return (clip) ? new ClipDrawable(shapeDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL) : shapeDrawable;
    }

    return drawable;
}