예제 #1
0
        protected override void Draw(Canvas canvas, Rect bounds)
        {
            int saveCount = canvas.Save();

            RectF arcBounds = mTempBounds;

            arcBounds.Set(bounds);

            mPaint.Alpha = MAX_ALPHA;
            mPaint.SetStyle(Paint.Style.Stroke);
            mPaint.Color = new Color(mCurrentColor);

            if (mSunCoordinateY < mInitSun_MoonCoordinateY)
            {
                canvas.DrawCircle(arcBounds.CenterX(), mSunCoordinateY, mSun_MoonRadius, mPaint);
            }

            if (mMoonCoordinateY < mInitSun_MoonCoordinateY)
            {
                int moonSaveCount = canvas.Save();
                canvas.Rotate(mMoonRotation, arcBounds.CenterX(), mMoonCoordinateY);
                canvas.DrawPath(CreateMoonPath(arcBounds.CenterX(), mMoonCoordinateY), mPaint);
                canvas.RestoreToCount(moonSaveCount);
            }

            for (int i = 0; i < mSunRayCount; i++)
            {
                int sunRaySaveCount = canvas.Save();
                //rotate 45 degrees can change the direction of 0 degrees to 1:30 clock
                //-mSunRayRotation means reverse rotation
                canvas.Rotate(45 - mSunRayRotation + (mIsExpandSunRay ? i : MAX_SUN_RAY_COUNT - i) * DEGREE_360 / MAX_SUN_RAY_COUNT, arcBounds.CenterX(), mSunCoordinateY);

                canvas.DrawLine(arcBounds.CenterX(), mSunRayStartCoordinateY, arcBounds.CenterX(), mSunRayEndCoordinateY, mPaint);
                canvas.RestoreToCount(sunRaySaveCount);
            }

            if (mShowStar)
            {
                if (mStarHolders.Count == 0)
                {
                    InitStarHolders(arcBounds);
                }

                for (int i = 0; i < mStarHolders.Count; i++)
                {
                    mPaint.SetStyle(Paint.Style.Fill);
                    mPaint.Alpha = mStarHolders[i].mAlpha;
                    canvas.DrawCircle(mStarHolders[i].mCurrentPoint.X, mStarHolders[i].mCurrentPoint.Y, mStarRadius, mPaint);
                }
            }

            canvas.RestoreToCount(saveCount);
        }
        protected override void Draw(Canvas canvas, Rect bounds)
        {
            int saveCount = canvas.Save();

            RectF arcBounds = mCurrentBounds;

            arcBounds.Set(bounds);
            //draw bottle
            mPaint.SetStyle(Paint.Style.Stroke);
            mPaint.Color = new Color(mBottleColor);
            canvas.DrawPath(CreateBottlePath(mBottleBounds), mPaint);

            //draw water
            mPaint.SetStyle(Paint.Style.FillAndStroke);
            mPaint.Color = new Color(mWaterColor);
            canvas.DrawPath(CreateWaterPath(mWaterBounds, mProgress), mPaint);

            //draw water drop
            mPaint.SetStyle(Paint.Style.Fill);
            mPaint.Color = new Color(mWaterColor);
            foreach (WaterDropHolder waterDropHolder in mWaterDropHolders)
            {
                if (waterDropHolder.mNeedDraw)
                {
                    canvas.DrawCircle(waterDropHolder.mInitX, waterDropHolder.mCurrentY, waterDropHolder.mRadius, mPaint);
                }
            }

            //draw loading text
            mPaint.Color = new Color(mBottleColor);
            canvas.DrawText(LOADING_TEXT, mBottleBounds.CenterX() - mLoadingBounds.Width() / 2.0f, mBottleBounds.Bottom + mBottleBounds.Height() * 0.2f, mPaint);
            canvas.RestoreToCount(saveCount);
        }
        protected override void Draw(Canvas canvas, Rect bounds)
        {
            int saveCount = canvas.Save();

            RectF arcBounds = mTempBounds;

            arcBounds.Set(bounds);
            arcBounds.Inset(mStrokeXInset, mStrokeYInset);

            mCurrentProgressBounds.Set(arcBounds.Left, arcBounds.Bottom - 2 * mCenterRadius, arcBounds.Right, arcBounds.Bottom);

            //Draw loading Drawable
            mLoadingDrawable.SetBounds((int)arcBounds.CenterX() - mLoadingDrawable.IntrinsicWidth / 2, 0, (int)arcBounds.CenterX() + mLoadingDrawable.IntrinsicWidth / 2, mLoadingDrawable.IntrinsicHeight);
            mLoadingDrawable.Draw(canvas);

            //Draw progress background
            float progressInset = mCenterRadius - mProgressCenterRadius;
            RectF progressRect  = new RectF(mCurrentProgressBounds);

            //sub DEFAULT_STROKE_INTERVAL, otherwise will have a interval between progress background and progress outline
            progressRect.Inset(progressInset - DEFAULT_STROKE_INTERVAL, progressInset - DEFAULT_STROKE_INTERVAL);
            mPaint.Color = new Color(mProgressBgColor);
            mPaint.SetStyle(Paint.Style.Fill);
            canvas.DrawRoundRect(progressRect, mProgressCenterRadius, mProgressCenterRadius, mPaint);

            //Draw progress
            mPaint.Color = new Color(mProgressColor);
            mPaint.SetStyle(Paint.Style.Fill);
            canvas.DrawPath(CreateProgressPath(mProgress, mProgressCenterRadius, progressRect), mPaint);

            //Draw leaves
            for (int i = 0; i < mLeafHolders.Count; i++)
            {
                int        leafSaveCount = canvas.Save();
                LeafHolder leafHolder    = mLeafHolders[i];
                Rect       leafBounds    = leafHolder.mLeafRect;

                canvas.Rotate(leafHolder.mLeafRotation, leafBounds.CenterX(), leafBounds.CenterY());
                mLeafDrawable.Bounds = leafBounds;
                mLeafDrawable.Draw(canvas);

                canvas.RestoreToCount(leafSaveCount);
            }

            //Draw progress background outline,
            //after Drawing the leaves and then Draw the outline of the progress background can
            //prevent the leaves from flying to the outside
            RectF progressOutlineRect        = new RectF(mCurrentProgressBounds);
            float progressOutlineStrokeInset = (mCenterRadius - mProgressCenterRadius) / 2.0f;

            progressOutlineRect.Inset(progressOutlineStrokeInset, progressOutlineStrokeInset);
            mPaint.SetStyle(Paint.Style.Stroke);
            mPaint.Color       = new Color(mProgressBgColor);
            mPaint.StrokeWidth = mCenterRadius - mProgressCenterRadius;
            canvas.DrawRoundRect(progressOutlineRect, mCenterRadius, mCenterRadius, mPaint);

            //Draw electric fan outline
            float electricFanCenterX = arcBounds.Right - mCenterRadius;
            float electricFanCenterY = arcBounds.Bottom - mCenterRadius;

            mPaint.Color = new Color(mElectricFanOutlineColor);
            mPaint.SetStyle(Paint.Style.Stroke);
            mPaint.StrokeWidth = mStrokeWidth;
            canvas.DrawCircle(arcBounds.Right - mCenterRadius, arcBounds.Bottom - mCenterRadius, mCenterRadius - mStrokeWidth / 2.0f, mPaint);

            //Draw electric background
            mPaint.Color = new Color(mElectricFanBgColor);
            mPaint.SetStyle(Paint.Style.Fill);
            canvas.DrawCircle(arcBounds.Right - mCenterRadius, arcBounds.Bottom - mCenterRadius, mCenterRadius - mStrokeWidth + DEFAULT_STROKE_INTERVAL, mPaint);

            //Draw electric fan
            int rotateSaveCount = canvas.Save();

            canvas.Rotate(mRotation, electricFanCenterX, electricFanCenterY);
            mElectricFanDrawable.SetBounds((int)(electricFanCenterX - mElectricFanDrawable.IntrinsicWidth / 2 * mScale), (int)(electricFanCenterY - mElectricFanDrawable.IntrinsicHeight / 2 * mScale), (int)(electricFanCenterX + mElectricFanDrawable.IntrinsicWidth / 2 * mScale), (int)(electricFanCenterY + mElectricFanDrawable.IntrinsicHeight / 2 * mScale));
            mElectricFanDrawable.Draw(canvas);
            canvas.RestoreToCount(rotateSaveCount);

            //Draw 100% text
            if (mScale < 1.0f)
            {
                mPaint.TextSize = mTextSize * (1 - mScale);
                mPaint.Color    = new Color(mElectricFanOutlineColor);
                Rect textRect = new Rect();
                mPaint.GetTextBounds(PERCENTAGE_100, 0, PERCENTAGE_100.Length, textRect);
                canvas.DrawText(PERCENTAGE_100, electricFanCenterX - textRect.Width() / 2.0f, electricFanCenterY + textRect.Height() / 2.0f, mPaint);
            }

            canvas.RestoreToCount(saveCount);
        }