Ejemplo n.º 1
0
 private void updateDrawableAttrs(RoundedDrawable drawable) {
   drawable.setScaleType(mScaleType);
   drawable.setCornerRadius(mCornerRadius);
   drawable.setBorderWidth(mBorderWidth);
   drawable.setBorderColors(mBorderColor);
   drawable.setOval(mOval);
 }
Ejemplo n.º 2
0
  /**
   * Controls how the image should be resized or moved to match the size of this ImageView.
   *
   * @param scaleType The desired scaling mode.
   * @attr ref android.R.styleable#ImageView_scaleType
   */
  @Override
  public void setScaleType(ScaleType scaleType) {
    if (scaleType == null) {
      throw new NullPointerException();
    }

    if (mScaleType != scaleType) {
      mScaleType = scaleType;

      switch (scaleType) {
        case CENTER:
        case CENTER_CROP:
        case CENTER_INSIDE:
        case FIT_CENTER:
        case FIT_START:
        case FIT_END:
        case FIT_XY:
          super.setScaleType(ScaleType.FIT_XY);
          break;
        default:
          super.setScaleType(scaleType);
          break;
      }

      if (mDrawable instanceof RoundedDrawable
          && ((RoundedDrawable) mDrawable).getScaleType() != scaleType) {
        ((RoundedDrawable) mDrawable).setScaleType(scaleType);
      }

      if (mBackgroundDrawable instanceof RoundedDrawable
          && ((RoundedDrawable) mBackgroundDrawable).getScaleType() != scaleType) {
        ((RoundedDrawable) mBackgroundDrawable).setScaleType(scaleType);
      }
      setWillNotCacheDrawing(true);
      requestLayout();
      invalidate();
    }
  }
Ejemplo n.º 3
0
  private void updateAttrs(Drawable drawable) {
    if (drawable == null) {
      return;
    }

    if (drawable instanceof RoundedDrawable) {
      ((RoundedDrawable) drawable).setScaleType(mScaleType);
      ((RoundedDrawable) drawable).setCornerRadius(mCornerRadius);

      mDrawable.setColorFilter(mColorFilter);
    } else if (drawable instanceof LayerDrawable) {
      // loop through layers to and set drawable attrs
      LayerDrawable ld = ((LayerDrawable) drawable);
      for (int i = 0, layers = ld.getNumberOfLayers(); i < layers; i++) {
        updateAttrs(ld.getDrawable(i));
      }
    }
  }