private void init() {
    COMMON_RADIUS = dip2px(getContext(), COMMON_RADIUS_VALUE);
    initCircleRadius();

    mInPaint.setColor(Color.parseColor(CIRCLE_COLOR_IN));
    mInPaint.setAntiAlias(true);
    mInPaint.setStyle(Paint.Style.FILL);

    mInStrokePaint.setColor(Color.parseColor(CIRCLE_COLOR_OUT));
    mInStrokePaint.setAntiAlias(true);
    mInStrokePaint.setStyle(Paint.Style.STROKE);
    mInStrokePaint.setStrokeWidth(dip2px(getContext(), STROKE_WIDTH));

    mOutPaint.setColor(Color.parseColor(CIRCLE_COLOR_IN));
    mOutPaint.setAntiAlias(true);
    mOutPaint.setStyle(Paint.Style.FILL);

    mOutStrokePaint.setColor(Color.parseColor(CIRCLE_COLOR_OUT));
    mOutStrokePaint.setAntiAlias(true);
    mOutStrokePaint.setStyle(Paint.Style.STROKE);
    mOutStrokePaint.setStrokeWidth(dip2px(getContext(), STROKE_WIDTH));

    mOutAlpha = mOutPaint.getAlpha();
    mOutStrokeAlpha = mOutStrokePaint.getAlpha();
  }
  /** <i>Overridden for internal use!</i> */
  @Override
  public int getOpacity() {
    int fill = mFillPaint.getAlpha();
    int stroke = mStrokePaint.getAlpha();

    if (fill == 0 && stroke == 0) {
      return PixelFormat.TRANSPARENT;
    } else if (fill == 255 && stroke == 255) {
      return PixelFormat.OPAQUE;
    } else {
      return PixelFormat.TRANSLUCENT;
    }
  }
Example #3
0
  /** Applies the rendering parameters defined for this {@link TextDrawable}. */
  protected void applyRenderingParameters() {
    if (mOpacity < 1.0f) {
      float alphaValue = mBackgroundPaint.getAlpha();
      int alpha = (int) (alphaValue * mOpacity);
      mBackgroundPaint.setAlpha(alpha);

      alphaValue = mFillPaint.getAlpha();
      alpha = (int) (alphaValue * mOpacity);
      mFillPaint.setAlpha(alpha);

      alphaValue = mStrokePaint.getAlpha();
      alpha = (int) (alphaValue * mOpacity);
      mStrokePaint.setAlpha(alpha);
    }
  }
 @Override
 public void setAlpha(int alpha) {
   if (mPaint.getAlpha() != alpha) {
     mPaint.setAlpha(alpha);
     invalidateSelf();
   }
 }
Example #5
0
  /** draws the hole in the center of the chart and the transparent circle / hole */
  protected void drawHole(Canvas c) {

    if (mChart.isDrawHoleEnabled()) {

      float transparentCircleRadius = mChart.getTransparentCircleRadius();
      float holeRadius = mChart.getHoleRadius();
      float radius = mChart.getRadius();

      PointF center = mChart.getCenterCircleBox();

      // only draw the circle if it can be seen (not covered by the hole)
      if (transparentCircleRadius > holeRadius) {

        // get original alpha
        int alpha = mTransparentCirclePaint.getAlpha();
        mTransparentCirclePaint.setAlpha(
            (int) ((float) alpha * mAnimator.getPhaseX() * mAnimator.getPhaseY()));

        // draw the transparent-circle
        mBitmapCanvas.drawCircle(
            center.x, center.y, radius / 100 * transparentCircleRadius, mTransparentCirclePaint);

        // reset alpha
        mTransparentCirclePaint.setAlpha(alpha);
      }

      // draw the hole-circle
      mBitmapCanvas.drawCircle(center.x, center.y, radius / 100 * holeRadius, mHolePaint);
    }
  }
Example #6
0
  /**
   * Sets the color the transparent-circle should have.
   *
   * @param color
   */
  public void setTransparentCircleColor(int color) {

    Paint p = ((PieChartRenderer) mRenderer).getPaintTransparentCircle();
    int alpha = p.getAlpha();
    p.setColor(color);
    p.setAlpha(alpha);
  }
 public void setAlpha(int paramInt)
 {
   if (paramInt != b.getAlpha())
   {
     b.setAlpha(paramInt);
     invalidateSelf();
   }
 }
Example #8
0
  protected void renderCaption(Canvas canvas) {
    if (windowCaptionFrameCountdown > 0) {
      if (windowCaptionFrameCountdown < 0.2 * windowCaptionDelayFrames) {
        captionPaint.setAlpha(
            (int) (windowCaptionFrameCountdown / (0.2 * windowCaptionDelayFrames) * 255f));
      }

      captionPaint.setARGB(captionPaint.getAlpha(), 0, 0, 0);
      canvas.drawText(windowCaption, captionX - 2, captionY - 2, captionPaint);
      canvas.drawText(windowCaption, captionX + 2, captionY - 2, captionPaint);
      canvas.drawText(windowCaption, captionX + 2, captionY + 2, captionPaint);
      canvas.drawText(windowCaption, captionX - 2, captionY + 2, captionPaint);
      captionPaint.setARGB(captionPaint.getAlpha(), 255, 255, 255);
      canvas.drawText(windowCaption, captionX, captionY, captionPaint);
      windowCaptionFrameCountdown--;
    }
  }
 @Override
 public void setAlpha(int alpha) {
   final int oldAlpha = mPaint.getAlpha();
   if (alpha != oldAlpha) {
     mPaint.setAlpha(alpha);
     invalidateSelf();
   }
 }
Example #10
0
        @Override
        public void run() {
          if (!mFades) return;

          final int alpha = Math.max(mPaint.getAlpha() - mFadeBy, 0);
          mPaint.setAlpha(alpha);
          invalidate();
          if (alpha > 0) {
            postDelayed(this, FADE_FRAME_MS);
          }
        }
 public int getOpacity() {
   if (mGravity != 119) {}
   Bitmap localBitmap;
   do {
     return -3;
     localBitmap = mBitmap;
   } while ((localBitmap == null)
       || (localBitmap.hasAlpha())
       || (mPaint.getAlpha() < 255)
       || (isGreaterThanZero(mCornerRadius)));
   return -1;
 }
 @Override
 public int getOpacity() {
   if (mGravity != Gravity.FILL || mIsCircular) {
     return PixelFormat.TRANSLUCENT;
   }
   Bitmap bm = mBitmap;
   return (bm == null
           || bm.hasAlpha()
           || mPaint.getAlpha() < 255
           || isGreaterThanZero(mCornerRadius))
       ? PixelFormat.TRANSLUCENT
       : PixelFormat.OPAQUE;
 }
  @Override
  protected boolean drawSoftware(Canvas c, Paint p) {
    boolean hasContent = false;

    final int origAlpha = p.getAlpha();
    final int alpha = (int) (origAlpha * mOpacity + 0.5f);
    if (alpha > 0) {
      p.setAlpha(alpha);
      c.drawCircle(0, 0, mTargetRadius, p);
      p.setAlpha(origAlpha);
      hasContent = true;
    }

    return hasContent;
  }
Example #14
0
 @Override
 public int getOpacity() {
   if (mShapeState.mShape == null) {
     final Paint p = mShapeState.mPaint;
     if (p.getXfermode() == null) {
       final int alpha = p.getAlpha();
       if (alpha == 0) {
         return PixelFormat.TRANSPARENT;
       }
       if (alpha == 255) {
         return PixelFormat.OPAQUE;
       }
     }
   }
   // not sure, so be safe
   return PixelFormat.TRANSLUCENT;
 }
Example #15
0
  @Override
  public void draw(Canvas canvas) {
    Rect r = getBounds();
    Paint paint = mShapeState.mPaint;

    int prevAlpha = paint.getAlpha();
    paint.setAlpha(modulateAlpha(prevAlpha, mShapeState.mAlpha));

    if (mShapeState.mShape != null) {
      // need the save both for the translate, and for the (unknown) Shape
      int count = canvas.save();
      canvas.translate(r.left, r.top);
      onDraw(mShapeState.mShape, canvas, paint);
      canvas.restoreToCount(count);
    } else {
      canvas.drawRect(r, paint);
    }

    // restore
    paint.setAlpha(prevAlpha);
  }
  @Override
  public void draw(Canvas canvas) {
    final Rect r = new Rect(getBounds());
    if (canvas.getClipBounds(sTempRect) && !Rect.intersects(sTempRect, r)) {
      // The draw region has been clipped.
      return;
    }
    if (mIndicatorRectDirty) {
      initIndicatorRect();
    }
    final float iconScale;

    if ((mAnimationProgress >= ANIMATION_PROGRESS_STARTED)
        && (mAnimationProgress < ANIMATION_PROGRESS_COMPLETED)) {
      mPaint.setAlpha((int) ((1 - mAnimationProgress) * 255));
      mBgDrawable.setAlpha(mPaint.getAlpha());
      mBgDrawable.draw(canvas);
      canvas.drawOval(mIndicatorRect, mPaint);

      iconScale = ICON_SCALE_FACTOR + (1 - ICON_SCALE_FACTOR) * mAnimationProgress;
    } else if (mAnimationProgress == ANIMATION_PROGRESS_STOPPED) {
      mPaint.setAlpha(255);
      iconScale = ICON_SCALE_FACTOR;
      mBgDrawable.setAlpha(255);
      mBgDrawable.draw(canvas);

      if (mProgress >= 100) {
        canvas.drawOval(mIndicatorRect, mPaint);
      } else if (mProgress > 0) {
        canvas.drawArc(mIndicatorRect, -90, mProgress * 3.6f, false, mPaint);
      }
    } else {
      iconScale = 1;
    }

    canvas.save();
    canvas.scale(iconScale, iconScale, r.exactCenterX(), r.exactCenterY());
    mIcon.draw(canvas);
    canvas.restore();
  }
  @Override
  public void draw(Canvas canvas) {
    final Rect bounds = getBounds();

    final boolean clearColorFilter;
    if (mTintFilter != null && getPaint().getColorFilter() == null) {
      mPaint.setColorFilter(mTintFilter);
      clearColorFilter = true;
    } else {
      clearColorFilter = false;
    }

    final boolean needsMirroring = needsMirroring();
    if (needsMirroring) {
      // Mirror the 9patch
      canvas.translate(bounds.right - bounds.left, 0);
      canvas.scale(-1.0f, 1.0f);
    }

    final int restoreAlpha;
    if (mNinePatchState.mBaseAlpha != 1.0f) {
      restoreAlpha = mPaint.getAlpha();
      mPaint.setAlpha((int) (restoreAlpha * mNinePatchState.mBaseAlpha + 0.5f));
    } else {
      restoreAlpha = -1;
    }

    mNinePatch.draw(canvas, bounds, mPaint);

    if (clearColorFilter) {
      mPaint.setColorFilter(null);
    }

    if (restoreAlpha >= 0) {
      mPaint.setAlpha(restoreAlpha);
    }
  }
 public int getAlpha() {
   return mPaint.getAlpha();
 }
Example #19
0
  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (mViewPager == null) {
      return;
    }
    final int count = mViewPager.getAdapter().getCount();
    if (count == 0) {
      return;
    }

    if (mCurrentPage >= count) {
      setCurrentItem(count - 1);
      return;
    }

    int longSize;
    int longPaddingBefore;
    int longPaddingAfter;
    int shortPaddingBefore;
    if (mOrientation == HORIZONTAL) {
      longSize = getWidth();
      longPaddingBefore = getPaddingLeft();
      longPaddingAfter = getPaddingRight();
      shortPaddingBefore = getPaddingTop();
    } else {
      longSize = getHeight();
      longPaddingBefore = getPaddingTop();
      longPaddingAfter = getPaddingBottom();
      shortPaddingBefore = getPaddingLeft();
    }

    final float threeRadius = mRadius * 3;
    final float shortOffset = shortPaddingBefore + mRadius;
    float longOffset = longPaddingBefore + mRadius;
    if (mCentered) {
      longOffset +=
          ((longSize - longPaddingBefore - longPaddingAfter) / 2.0f)
              - ((count * threeRadius) / 2.0f);
    }

    float dX;
    float dY;

    float pageFillRadius = mRadius;
    if (mPaintStroke.getStrokeWidth() > 0) {
      pageFillRadius -= mPaintStroke.getStrokeWidth() / 2.0f;
    }

    // Draw stroked circles
    for (int iLoop = 0; iLoop < count; iLoop++) {
      float drawLong = longOffset + (iLoop * threeRadius);
      if (mOrientation == HORIZONTAL) {
        dX = drawLong;
        dY = shortOffset;
      } else {
        dX = shortOffset;
        dY = drawLong;
      }
      // Only paint fill if not completely transparent
      if (mPaintPageFill.getAlpha() > 0) {
        canvas.drawCircle(dX, dY, pageFillRadius, mPaintPageFill);
      }

      // Only paint stroke if a stroke width was non-zero
      if (pageFillRadius != mRadius) {
        canvas.drawCircle(dX, dY, mRadius, mPaintStroke);
      }
    }

    // Draw the filled circle according to the current scroll
    float cx = (mSnap ? mSnapPage : mCurrentPage) * threeRadius;
    if (!mSnap) {
      cx += mPageOffset * threeRadius;
    }
    if (mOrientation == HORIZONTAL) {
      dX = longOffset + cx;
      dY = shortOffset;
    } else {
      dX = shortOffset;
      dY = longOffset + cx;
    }
    canvas.drawCircle(dX, dY, mRadius, mPaintFill);
  }
 /**
  * Returns a {@link android.graphics.PixelFormat graphics.PixelFormat} value of OPAQUE or
  * TRANSLUCENT.
  */
 @Override
 public int getOpacity() {
   return mNinePatch.hasAlpha() || (mPaint != null && mPaint.getAlpha() < 255)
       ? PixelFormat.TRANSLUCENT
       : PixelFormat.OPAQUE;
 }
Example #21
0
 /**
  * Set the draw paint alpha by modulateAlpha
  *
  * @param paint Paint
  * @param alpha Alpha
  * @return PrevAlpha
  */
 protected int setPaintAlpha(Paint paint, int alpha) {
   final int prevAlpha = paint.getAlpha();
   paint.setAlpha(GeniusUi.modulateAlpha(prevAlpha, alpha));
   return prevAlpha;
 }
 public int getRippleAlpha() {
   return paint.getAlpha();
 }
 @Override
 public int getOpacity() {
   return paint.getAlpha();
 }
 protected void onDraw(Canvas paramCanvas) {
   super.onDraw(paramCanvas);
   if (f == null) {}
   int i5;
   do {
     return;
     i5 = f.getAdapter().getCount();
   } while (i5 == 0);
   if (h >= i5) {
     setCurrentItem(i5 - 1);
     return;
   }
   int i4;
   int i3;
   int i2;
   int i1;
   float f6;
   float f1;
   float f2;
   float f3;
   float f4;
   float f5;
   if (l == 0) {
     i4 = getWidth();
     i3 = getPaddingLeft();
     i2 = getPaddingRight();
     i1 = getPaddingTop();
     f6 = e * 3.0F + r;
     f1 = i1;
     f1 = e + f1;
     f2 = i3 + e;
     if (!m) {
       break label456;
     }
     f3 = e;
     f4 = i5;
     f5 = e;
     float f7 = i5 - 1;
     f2 += (i4 - i3 - i2) / 2.0F - (f3 * 2.0F * f4 + f5 * f7) / 2.0F;
     f1 = (getHeight() - getPaddingTop() - getPaddingBottom()) / 2.0F - e + f1;
   }
   label239:
   label448:
   label456:
   for (; ; ) {
     f4 = e;
     f3 = f4;
     if (c.getStrokeWidth() > 0.0F) {
       f3 = f4 - c.getStrokeWidth() / 2.0F;
     }
     i1 = 0;
     if (i1 < i5) {
       f4 = i1 * f6 + f2;
       if (l == 0) {
         f5 = f4;
         f4 = f1;
       }
       for (; ; ) {
         if (b.getAlpha() > 0) {
           paramCanvas.drawCircle(f5, f4, f3, b);
         }
         if (f3 != e) {
           paramCanvas.drawCircle(f5, f4, e, c);
         }
         i1 += 1;
         break label239;
         i4 = getHeight();
         i3 = getPaddingTop();
         i2 = getPaddingBottom();
         i1 = getPaddingLeft();
         break;
         f5 = f1;
       }
     }
     if (n) {
       i1 = i;
       f4 = i1 * f6;
       f3 = f4;
       if (!n) {
         f3 = f4 + j * f6;
       }
       if (l != 0) {
         break label448;
       }
       f3 = f2 + f3;
       f2 = f1;
       f1 = f3;
     }
     for (; ; ) {
       paramCanvas.drawCircle(f1, f2, e, d);
       return;
       i1 = h;
       break;
       f2 += f3;
     }
   }
 }
 public final void setAccuracyTint(@ColorInt int color) {
   int alpha = accuracyPaint.getAlpha();
   accuracyPaint.setColor(color);
   accuracyPaint.setAlpha(alpha);
   invalidate();
 }
  /*
   * (non-Javadoc)
   *
   * @see android.view.View#onDraw(android.graphics.Canvas)
   */
  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (mViewPager == null) {
      return;
    }
    final int count = mViewPager.getAdapter().getCount();
    if (count == 0) {
      return;
    }

    // mCurrentPage is -1 on first start and after orientation changed. If so, retrieve the correct
    // index from viewpager.
    if (mCurrentPage == -1 && mViewPager != null) mCurrentPage = mViewPager.getCurrentItem();

    // Calculate views bounds
    ArrayList<Rect> bounds = calculateAllBounds(mPaintText);
    final int boundsSize = bounds.size();

    // Make sure we're on a page that still exists
    if (mCurrentPage >= boundsSize) {
      setCurrentItem(boundsSize - 1);
      return;
    }

    final int countMinusOne = count - 1;
    final float halfWidth = getWidth() / 2f;
    final int left = getLeft();
    final float leftClip = left + mClipPadding;
    final int width = getWidth();
    final int height = getHeight();
    final int right = left + width;
    final float rightClip = right - mClipPadding;

    int page = mCurrentPage;
    float offsetPercent;
    if (mPageOffset <= 0.5) {
      offsetPercent = mPageOffset;
    } else {
      page += 1;
      offsetPercent = 1 - mPageOffset;
    }
    final boolean currentSelected = (offsetPercent <= SELECTION_FADE_PERCENTAGE);
    final boolean currentBold = (offsetPercent <= BOLD_FADE_PERCENTAGE);
    final float selectedPercent =
        (SELECTION_FADE_PERCENTAGE - offsetPercent) / SELECTION_FADE_PERCENTAGE;

    // Verify if the current view must be clipped to the screen
    Rect curPageBound = bounds.get(mCurrentPage);
    float curPageWidth = curPageBound.right - curPageBound.left;
    if (curPageBound.left < leftClip) {
      // Try to clip to the screen (left side)
      clipViewOnTheLeft(curPageBound, curPageWidth, left);
    }
    if (curPageBound.right > rightClip) {
      // Try to clip to the screen (right side)
      clipViewOnTheRight(curPageBound, curPageWidth, right);
    }

    // Left views starting from the current position
    if (mCurrentPage > 0) {
      for (int i = mCurrentPage - 1; i >= 0; i--) {
        Rect bound = bounds.get(i);
        // Is left side is outside the screen
        if (bound.left < leftClip) {
          int w = bound.right - bound.left;
          // Try to clip to the screen (left side)
          clipViewOnTheLeft(bound, w, left);
          // Except if there's an intersection with the right view
          Rect rightBound = bounds.get(i + 1);
          // Intersection
          if (bound.right + mTitlePadding > rightBound.left) {
            bound.left = (int) (rightBound.left - w - mTitlePadding);
            bound.right = bound.left + w;
          }
        }
      }
    }
    // Right views starting from the current position
    if (mCurrentPage < countMinusOne) {
      for (int i = mCurrentPage + 1; i < count; i++) {
        Rect bound = bounds.get(i);
        // If right side is outside the screen
        if (bound.right > rightClip) {
          int w = bound.right - bound.left;
          // Try to clip to the screen (right side)
          clipViewOnTheRight(bound, w, right);
          // Except if there's an intersection with the left view
          Rect leftBound = bounds.get(i - 1);
          // Intersection
          if (bound.left - mTitlePadding < leftBound.right) {
            bound.left = (int) (leftBound.right + mTitlePadding);
            bound.right = bound.left + w;
          }
        }
      }
    }

    // Now draw views
    int colorTextAlpha = mColorText >>> 24;
    for (int i = 0; i < count; i++) {
      // Get the title
      Rect bound = bounds.get(i);
      // Only if one side is visible
      if ((bound.left > left && bound.left < right)
          || (bound.right > left && bound.right < right)) {
        final boolean currentPage = (i == page);
        final CharSequence pageTitle = getTitle(i);
        final Drawable pageIcon = getIcon(i);

        // Only set bold if we are within bounds
        mPaintText.setFakeBoldText(currentPage && currentBold && mBoldText);

        // Draw text as unselected
        mPaintText.setColor(mColorText);
        if (currentPage && currentSelected) {
          // Fade out/in unselected text as the selected text fades in/out
          mPaintText.setAlpha(colorTextAlpha - (int) (colorTextAlpha * selectedPercent));
        }

        float iconOffset = 0;
        if (pageIcon != null) {
          Rect iconBounds = pageIcon.getBounds();
          pageIcon.setAlpha(mPaintText.getAlpha());
          getResources();
          iconBounds.offset(
              bound.left, (int) (4 * Resources.getSystem().getDisplayMetrics().density));
          pageIcon.draw(canvas);
          iconOffset = iconBounds.width() + mIconPadding;
        }
        canvas.drawText(
            pageTitle,
            0,
            pageTitle.length(),
            bound.left + iconOffset,
            bound.bottom + mTopPadding,
            mPaintText);

        // If we are within the selected bounds draw the selected text
        if (currentPage && currentSelected) {
          mPaintText.setColor(mColorSelected);
          mPaintText.setAlpha((int) ((mColorSelected >>> 24) * selectedPercent));
          if (pageIcon != null) {
            pageIcon.setAlpha(mPaintText.getAlpha());
            pageIcon.draw(canvas);
          }
          canvas.drawText(
              pageTitle,
              0,
              pageTitle.length(),
              bound.left + iconOffset,
              bound.bottom + mTopPadding,
              mPaintText);
        }
      }
    }

    // Draw the footer line
    mPath.reset();
    mPath.moveTo(0, height - mFooterLineHeight / 2f);
    mPath.lineTo(width, height - mFooterLineHeight / 2f);
    mPath.close();
    canvas.drawPath(mPath, mPaintFooterLine);

    switch (mFooterIndicatorStyle) {
      case Triangle:
        mPath.reset();
        mPath.moveTo(halfWidth, height - mFooterLineHeight - mFooterIndicatorHeight);
        mPath.lineTo(halfWidth + mFooterIndicatorHeight, height - mFooterLineHeight);
        mPath.lineTo(halfWidth - mFooterIndicatorHeight, height - mFooterLineHeight);
        mPath.close();
        canvas.drawPath(mPath, mPaintFooterIndicator);
        break;

      case Underline:
        if (!currentSelected || page >= boundsSize) {
          break;
        }

        Rect underlineBounds = bounds.get(page);
        mPath.reset();
        mPath.moveTo(
            underlineBounds.left - mFooterIndicatorUnderlinePadding, height - mFooterLineHeight);
        mPath.lineTo(
            underlineBounds.right + mFooterIndicatorUnderlinePadding, height - mFooterLineHeight);
        mPath.lineTo(
            underlineBounds.right + mFooterIndicatorUnderlinePadding,
            height - mFooterLineHeight - mFooterIndicatorHeight);
        mPath.lineTo(
            underlineBounds.left - mFooterIndicatorUnderlinePadding,
            height - mFooterLineHeight - mFooterIndicatorHeight);
        mPath.close();

        mPaintFooterIndicator.setAlpha((int) (0xFF * selectedPercent));
        canvas.drawPath(mPath, mPaintFooterIndicator);
        mPaintFooterIndicator.setAlpha(0xFF);
        break;
    }
  }