Esempio n. 1
0
 /**
  * Specify modifiers to the bounds for the drawable[index]. left += l top += t; right -= r; bottom
  * -= b;
  */
 public void setLayerInset(int index, int l, int t, int r, int b) {
   ChildDrawable childDrawable = mLayerState.mChildren[index];
   childDrawable.mInsetL = l;
   childDrawable.mInsetT = t;
   childDrawable.mInsetR = r;
   childDrawable.mInsetB = b;
 }
Esempio n. 2
0
  /**
   * 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);
  }
    LayerState(LayerState orig, LayerDrawable owner, Resources res) {
      if (orig != null) {
        final ChildDrawable[] origChildDrawable = orig.mChildren;
        final int N = orig.mNum;

        mNum = N;
        mChildren = new ChildDrawable[N];

        mChangingConfigurations = orig.mChangingConfigurations;
        mChildrenChangingConfigurations = orig.mChildrenChangingConfigurations;

        for (int i = 0; i < N; i++) {
          final ChildDrawable r = mChildren[i] = new ChildDrawable();
          final ChildDrawable or = origChildDrawable[i];
          if (res != null) {
            r.mDrawable = or.mDrawable.getConstantState().newDrawable(res);
          } else {
            r.mDrawable = or.mDrawable.getConstantState().newDrawable();
          }
          r.mDrawable.setCallback(owner);
          r.mDrawable.setLayoutDirection(or.mDrawable.getLayoutDirection());
          r.mInsetL = or.mInsetL;
          r.mInsetT = or.mInsetT;
          r.mInsetR = or.mInsetR;
          r.mInsetB = or.mInsetB;
          r.mId = or.mId;
        }

        mHaveOpacity = orig.mHaveOpacity;
        mOpacity = orig.mOpacity;
        mHaveStateful = orig.mHaveStateful;
        mStateful = orig.mStateful;
        mCheckedConstantState = mCanConstantState = true;
        mAutoMirrored = orig.mAutoMirrored;
      } else {
        mNum = 0;
        mChildren = null;
      }
    }