/** * Add a new layer to this drawable. The new layer is identified by an id. * * @param layer The drawable to add as a layer. * @param id The id of the new layer. * @param left The left padding of the new layer. * @param top The top padding of the new layer. * @param right The right padding of the new layer. * @param bottom The bottom padding of the new layer. */ private void addLayer(Drawable layer, int id, int left, int top, int right, int bottom) { final LayerState st = mLayerState; int N = st.mChildren != null ? st.mChildren.length : 0; int i = st.mNum; if (i >= N) { ChildDrawable[] nu = new ChildDrawable[N + 10]; if (i > 0) { System.arraycopy(st.mChildren, 0, nu, 0, i); } st.mChildren = nu; } mLayerState.mChildrenChangingConfigurations |= layer.getChangingConfigurations(); ChildDrawable childDrawable = new ChildDrawable(); st.mChildren[i] = childDrawable; childDrawable.mId = id; childDrawable.mDrawable = layer; childDrawable.mInsetL = left; childDrawable.mInsetT = top; childDrawable.mInsetR = right; childDrawable.mInsetB = bottom; st.mNum++; layer.setCallback(this); }
@Override public ConstantState getConstantState() { if (mLayerState.canConstantState()) { mLayerState.mChangingConfigurations = getChangingConfigurations(); return mLayerState; } return null; }
/** * Create a new layer drawable with the specified list of layers and the specified constant state. * * @param layers The list of layers to add to this drawable. * @param state The constant drawable state. */ LayerDrawable(Drawable[] layers, LayerState state) { this(state, null); int length = layers.length; ChildDrawable[] r = new ChildDrawable[length]; for (int i = 0; i < length; i++) { r[i] = new ChildDrawable(); r[i].mDrawable = layers[i]; layers[i].setCallback(this); mLayerState.mChildrenChangingConfigurations |= layers[i].getChangingConfigurations(); } mLayerState.mNum = length; mLayerState.mChildren = r; ensurePadding(); }
@Override public int getOpacity() { if (mOpacityOverride != PixelFormat.UNKNOWN) { return mOpacityOverride; } return mLayerState.getOpacity(); }
LayerDrawable(LayerState state, Drawable... layers) { this(state); int length = layers.length; Rec[] r = new Rec[length]; final LayerState layerState = mLayerState; for (int i = 0; i < length; i++) { r[i] = new Rec(); r[i].mDrawable = layers[i]; layers[i].setCallback(this); layerState.mChildrenChangingConfigurations |= layers[i].getChangingConfigurations(); } layerState.mNum = length; layerState.mArray = r; ensurePadding(); }
@Override public void setAutoMirrored(boolean mirrored) { mLayerState.mAutoMirrored = mirrored; final ChildDrawable[] array = mLayerState.mChildren; final int N = mLayerState.mNum; for (int i = 0; i < N; i++) { array[i].mDrawable.setAutoMirrored(mirrored); } }
@Override public boolean isStateful() { return mLayerState.isStateful(); }
@Override public int getOpacity() { return mLayerState.getOpacity(); }