Example usage for android.graphics.drawable LayerDrawable getNumberOfLayers

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

Introduction

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

Prototype

public int getNumberOfLayers() 

Source Link

Document

Returns the number of layers contained within this layer drawable.

Usage

From source file:android.support.v17.leanback.app.BackgroundManager.java

private TranslucentLayerDrawable createOptimizedTranslucentLayerDrawable(LayerDrawable layerDrawable) {
    int numChildren = layerDrawable.getNumberOfLayers();
    Drawable[] drawables = new Drawable[numChildren];
    for (int i = 0; i < numChildren; i++) {
        drawables[i] = layerDrawable.getDrawable(i);
    }//  ww  w.jav a  2s. com
    TranslucentLayerDrawable result = new OptimizedTranslucentLayerDrawable(drawables);
    for (int i = 0; i < numChildren; i++) {
        result.setId(i, layerDrawable.getId(i));
    }
    return result;
}

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.
 *//* w w w . j a  v  a 2s.  c o m*/
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;
}

From source file:org.kde.necessitas.ministro.ExtractStyle.java

private JSONObject getLayerDrawable(Object drawable, String filename) {
    JSONObject json = new JSONObject();
    LayerDrawable layers = (LayerDrawable) drawable;
    final int nr = layers.getNumberOfLayers();
    try {/*from   w  ww  .ja va  2  s .co m*/
        JSONArray array = new JSONArray();
        for (int i = 0; i < nr; i++) {
            JSONObject layerJsonObject = getDrawable(layers.getDrawable(i), filename + "__" + layers.getId(i));
            layerJsonObject.put("id", layers.getId(i));
            array.put(layerJsonObject);
        }
        json.put("type", "layer");
        Rect padding = new Rect();
        if (layers.getPadding(padding))
            json.put("padding", getJsonRect(padding));
        json.put("layers", array);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return json;
}

From source file:org.musicmod.android.app.MusicPlaybackActivity.java

private void setUIColor(int color) {

    LayerDrawable mProgressLayer = (LayerDrawable) mProgress.getProgressDrawable();
    mProgressLayer.getDrawable(mProgressLayer.getNumberOfLayers() - 1).setColorFilter(mUIColor, Mode.MULTIPLY);
    mProgress.invalidate();/*from w  w  w  .  ja  v  a2 s . c  om*/
    mVisualizerViewFftSpectrum.setColor(color);
    mVisualizerViewWaveForm.setColor(color);
    mTouchPaintView.setColor(color);
}