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