@Override
  protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    super.onLayout(changed, left, top, right, bottom);
    final float density = getContext().getResources().getDisplayMetrics().density;
    mDiameter = Math.min(getMeasuredWidth(), getMeasuredHeight());
    if (mDiameter <= 0) {
      mDiameter = (int) density * DEFAULT_CIRCLE_DIAMETER;
    }
    if (getBackground() == null && mCircleBackgroundEnabled) {
      final int shadowYOffset = (int) (density * Y_OFFSET);
      final int shadowXOffset = (int) (density * X_OFFSET);
      mShadowRadius = (int) (density * SHADOW_RADIUS);

      if (elevationSupported()) {
        mBgCircle = new ShapeDrawable(new OvalShape());
        ViewCompat.setElevation(this, SHADOW_ELEVATION * density);
      } else {
        OvalShape oval = new OvalShadow(mShadowRadius, mDiameter - mShadowRadius * 2);
        mBgCircle = new ShapeDrawable(oval);
        ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, mBgCircle.getPaint());
        mBgCircle
            .getPaint()
            .setShadowLayer(mShadowRadius, shadowXOffset, shadowYOffset, KEY_SHADOW_COLOR);
        final int padding = (int) mShadowRadius;
        // set padding so the inner image sits correctly within the shadow.
        setPadding(padding, padding, padding, padding);
      }
      mBgCircle.getPaint().setColor(mBackGroundColor);
      setBackgroundDrawable(mBgCircle);
    }
    mProgressDrawable.setBackgroundColor(mBackGroundColor);
    mProgressDrawable.setColorSchemeColors(mColors);
    mProgressDrawable.setSizeParameters(
        mDiameter,
        mDiameter,
        mInnerRadius <= 0 ? (mDiameter - mProgressStokeWidth * 2) / 4 : mInnerRadius,
        mProgressStokeWidth,
        mArrowWidth < 0 ? mProgressStokeWidth * 4 : mArrowWidth,
        mArrowHeight < 0 ? mProgressStokeWidth * 2 : mArrowHeight);
    if (isShowArrow()) {
      mProgressDrawable.showArrowOnFirstStart(true);
      mProgressDrawable.setArrowScale(1f);
      mProgressDrawable.showArrow(true);
    }
    super.setImageDrawable(null);
    super.setImageDrawable(mProgressDrawable);
    mProgressDrawable.setAlpha(255);
    mProgressDrawable.setStartEndTrim(0f, 0.75f);
  }
 public void setColorSchemeColors(int[] colors) {
   mDrawable.setColorSchemeColors(colors);
   invalidate();
 }
 /**
  * Set the colors used in the progress animation. The first color will also be the color of the
  * bar that grows in response to a user swipe gesture.
  *
  * @param colors
  */
 public void setColorSchemeColors(int... colors) {
   mColors = colors;
   if (mProgressDrawable != null) {
     mProgressDrawable.setColorSchemeColors(colors);
   }
 }
예제 #4
0
 /**
  * Set the colors used in the progress animation. The first color will also be the color of the
  * bar that grows in response to a user swipe gesture.
  *
  * @param colors
  */
 public void setColorSchemeColors(int... colors) {
   ensureTarget();
   mProgress.setColorSchemeColors(colors);
 }