@Override
 public void setImageBitmap(Bitmap bm) {
   mResource = 0;
   mDrawable = RoundedDrawable.fromBitmap(bm);
   updateDrawableAttrs();
   super.setImageDrawable(mDrawable);
 }
  /**
   * 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) {
    assert scaleType != null;

    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;
      }

      updateDrawableAttrs();
      updateBackgroundDrawableAttrs(false);
      invalidate();
    }
  }
 @Override
 public void setImageDrawable(Drawable drawable) {
   mResource = 0;
   mDrawable = RoundedDrawable.fromDrawable(drawable);
   updateDrawableAttrs();
   super.setImageDrawable(mDrawable);
 }
Пример #4
0
  public RoundedImageView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RoundedImageView, defStyle, 0);

    int index = a.getInt(R.styleable.RoundedImageView_android_scaleType, -1);
    if (index >= 0) {
      setScaleType(sScaleTypeArray[index]);
    }

    mCornerRadius = a.getDimensionPixelSize(R.styleable.RoundedImageView_corner_radius, -1);
    mBorderWidth = a.getDimensionPixelSize(R.styleable.RoundedImageView_border_width, -1);

    // don't allow negative values for radius and border
    if (mCornerRadius < 0) {
      mCornerRadius = DEFAULT_RADIUS;
    }
    if (mBorderWidth < 0) {
      mBorderWidth = DEFAULT_BORDER;
    }

    mBorderColor = a.getColorStateList(R.styleable.RoundedImageView_border_color);
    if (mBorderColor == null) {
      mBorderColor = ColorStateList.valueOf(RoundedDrawable.DEFAULT_BORDER_COLOR);
    }

    mRoundBackground = a.getBoolean(R.styleable.RoundedImageView_round_background, false);
    mOval = a.getBoolean(R.styleable.RoundedImageView_is_oval, false);

    if (mDrawable instanceof RoundedDrawable) {
      updateDrawableAttrs((RoundedDrawable) mDrawable);
    }

    if (mRoundBackground) {
      if (!(mBackgroundDrawable instanceof RoundedDrawable)) {
        // try setting background drawable now that we got the mRoundBackground param
        setBackgroundDrawable(mBackgroundDrawable);
      }
      if (mBackgroundDrawable instanceof RoundedDrawable) {
        updateDrawableAttrs((RoundedDrawable) mBackgroundDrawable);
      }
    }

    a.recycle();
  }
  public void setCornerRadius(float radius) {
    if (cornerRadius == radius) {
      return;
    }

    cornerRadius = radius;
    updateDrawableAttrs();
    updateBackgroundDrawableAttrs(false);
  }
 @Override
 public void setImageResource(int resId) {
   if (mResource != resId) {
     mResource = resId;
     mDrawable = resolveResource();
     updateDrawableAttrs();
     super.setImageDrawable(mDrawable);
   }
 }
Пример #7
0
 public void setImageBitmap(Bitmap bm) {
   if (bm != null) {
     mDrawable = new RoundedDrawable(bm, mCornerRadius, mBorderWidth, mBorderColor, mOval);
     updateDrawableAttrs((RoundedDrawable) mDrawable);
   } else {
     mDrawable = null;
   }
   super.setImageDrawable(mDrawable);
 }
  public void setBorderWidth(float width) {
    if (borderWidth == width) {
      return;
    }

    borderWidth = width;
    updateDrawableAttrs();
    updateBackgroundDrawableAttrs(false);
    invalidate();
  }
Пример #9
0
 @Override
 public void setImageDrawable(Drawable drawable) {
   if (drawable != null) {
     mDrawable =
         RoundedDrawable.fromDrawable(drawable, mCornerRadius, mBorderWidth, mBorderColor, mOval);
     updateDrawableAttrs((RoundedDrawable) mDrawable);
   } else {
     mDrawable = null;
   }
   super.setImageDrawable(mDrawable);
 }
  public void setBorderColor(ColorStateList colors) {
    if (borderColor.equals(colors)) {
      return;
    }

    borderColor =
        (colors != null) ? colors : ColorStateList.valueOf(RoundedDrawable.DEFAULT_BORDER_COLOR);
    updateDrawableAttrs();
    updateBackgroundDrawableAttrs(false);
    if (borderWidth > 0) {
      invalidate();
    }
  }
Пример #11
0
 @Override
 @Deprecated
 public void setBackgroundDrawable(Drawable background) {
   if (mRoundBackground && background != null) {
     mBackgroundDrawable =
         RoundedDrawable.fromDrawable(
             background, mCornerRadius, mBorderWidth, mBorderColor, mOval);
     updateDrawableAttrs((RoundedDrawable) mBackgroundDrawable);
   } else {
     mBackgroundDrawable = background;
   }
   super.setBackgroundDrawable(mBackgroundDrawable);
 }
Пример #12
0
  public void setRoundBackground(boolean roundBackground) {
    if (mRoundBackground == roundBackground) {
      return;
    }

    mRoundBackground = roundBackground;
    if (roundBackground) {
      if (mBackgroundDrawable instanceof RoundedDrawable) {
        updateDrawableAttrs((RoundedDrawable) mBackgroundDrawable);
      } else {
        setBackgroundDrawable(mBackgroundDrawable);
      }
    } else if (mBackgroundDrawable instanceof RoundedDrawable) {
      ((RoundedDrawable) mBackgroundDrawable).setBorderWidth(0);
      ((RoundedDrawable) mBackgroundDrawable).setCornerRadius(0);
    }

    invalidate();
  }
  public RoundedImageView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RoundedImageView, defStyle, 0);

    int index = a.getInt(R.styleable.RoundedImageView_android_scaleType, -1);
    if (index >= 0) {
      setScaleType(SCALE_TYPES[index]);
    } else {
      // default scaletype to FIT_CENTER
      setScaleType(ScaleType.FIT_CENTER);
    }

    cornerRadius = a.getDimensionPixelSize(R.styleable.RoundedImageView_corner_radius, -1);
    borderWidth = a.getDimensionPixelSize(R.styleable.RoundedImageView_border_width, -1);

    // don't allow negative values for radius and border
    if (cornerRadius < 0) {
      cornerRadius = DEFAULT_RADIUS;
    }
    if (borderWidth < 0) {
      borderWidth = DEFAULT_BORDER_WIDTH;
    }

    borderColor = a.getColorStateList(R.styleable.RoundedImageView_border_color);
    if (borderColor == null) {
      borderColor = ColorStateList.valueOf(RoundedDrawable.DEFAULT_BORDER_COLOR);
    }

    mutateBackground = a.getBoolean(R.styleable.RoundedImageView_mutate_background, false);
    isOval = a.getBoolean(R.styleable.RoundedImageView_oval, false);

    updateDrawableAttrs();
    updateBackgroundDrawableAttrs(true);

    a.recycle();
  }
 public void setOval(boolean oval) {
   isOval = oval;
   updateDrawableAttrs();
   updateBackgroundDrawableAttrs(false);
   invalidate();
 }