Пример #1
0
 @Override
 public ConstantState getConstantState() {
   if (mScaleState.canConstantState()) {
     mScaleState.mChangingConfigurations = getChangingConfigurations();
     return mScaleState;
   }
   return null;
 }
Пример #2
0
  public ScaleDrawable(Drawable drawable, int gravity, float scaleWidth, float scaleHeight) {
    this(null, null);

    mScaleState.mDrawable = drawable;
    mScaleState.mGravity = gravity;
    mScaleState.mScaleWidth = scaleWidth;
    mScaleState.mScaleHeight = scaleHeight;

    if (drawable != null) {
      drawable.setCallback(this);
    }
  }
Пример #3
0
  @Override
  public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs)
      throws XmlPullParserException, IOException {
    super.inflate(r, parser, attrs);

    int type;

    TypedArray a = r.obtainAttributes(attrs, com.android.internal.R.styleable.ScaleDrawable);

    float sw = getPercent(a, com.android.internal.R.styleable.ScaleDrawable_scaleWidth);
    float sh = getPercent(a, com.android.internal.R.styleable.ScaleDrawable_scaleHeight);
    int g = a.getInt(com.android.internal.R.styleable.ScaleDrawable_scaleGravity, Gravity.LEFT);
    boolean min =
        a.getBoolean(
            com.android.internal.R.styleable.ScaleDrawable_useIntrinsicSizeAsMinimum, false);
    Drawable dr = a.getDrawable(com.android.internal.R.styleable.ScaleDrawable_drawable);

    a.recycle();

    final int outerDepth = parser.getDepth();
    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
        && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
      if (type != XmlPullParser.START_TAG) {
        continue;
      }
      dr = Drawable.createFromXmlInner(r, parser, attrs);
    }

    if (dr == null) {
      throw new IllegalArgumentException("No drawable specified for <scale>");
    }

    mScaleState.mDrawable = dr;
    mScaleState.mScaleWidth = sw;
    mScaleState.mScaleHeight = sh;
    mScaleState.mGravity = g;
    mScaleState.mUseIntrinsicSizeAsMin = min;
    if (dr != null) {
      dr.setCallback(this);
    }
  }