Example usage for android.graphics Canvas drawColor

List of usage examples for android.graphics Canvas drawColor

Introduction

In this page you can find the example usage for android.graphics Canvas drawColor.

Prototype

public void drawColor(@ColorInt int color) 

Source Link

Document

Fill the entire canvas' bitmap (restricted to the current clip) with the specified color, using srcover porterduff mode.

Usage

From source file:com.hippo.widget.slidingdrawerlayout.SlidingDrawerLayout.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (mFitPaddingTop != 0) {
        int saved = canvas.save();
        canvas.clipRect(0, 0, getWidth(), mFitPaddingTop);
        canvas.drawColor(mStatusBarColor);
        canvas.restoreToCount(saved);//  ww w . ja  va 2 s  . c o  m
    }

    if (mFitPaddingBottom != 0) {
        int saved = canvas.save();
        int height = getHeight();
        canvas.clipRect(0, height - mFitPaddingBottom, getWidth(), height);
        canvas.drawColor(mNavigationBarColor);
        canvas.restoreToCount(saved);
    }
}

From source file:com.android.launcher3.Utilities.java

/**
 * @param scale the scale to apply before drawing {@param icon} on the canvas
 *///w  w  w.  ja v a2 s . c  om
public static Bitmap createIconBitmap(Drawable icon, Context context, float scale) {
    synchronized (sCanvas) {
        final int iconBitmapSize = getIconBitmapSize();

        int width = iconBitmapSize;
        int height = iconBitmapSize;

        if (icon instanceof PaintDrawable) {
            PaintDrawable painter = (PaintDrawable) icon;
            painter.setIntrinsicWidth(width);
            painter.setIntrinsicHeight(height);
        } else if (icon instanceof BitmapDrawable) {
            // Ensure the bitmap has a density.
            BitmapDrawable bitmapDrawable = (BitmapDrawable) icon;
            Bitmap bitmap = bitmapDrawable.getBitmap();
            if (bitmap != null && bitmap.getDensity() == Bitmap.DENSITY_NONE) {
                bitmapDrawable.setTargetDensity(context.getResources().getDisplayMetrics());
            }
        }
        int sourceWidth = icon.getIntrinsicWidth();
        int sourceHeight = icon.getIntrinsicHeight();
        if (sourceWidth > 0 && sourceHeight > 0) {
            // Scale the icon proportionally to the icon dimensions
            final float ratio = (float) sourceWidth / sourceHeight;
            if (sourceWidth > sourceHeight) {
                height = (int) (width / ratio);
            } else if (sourceHeight > sourceWidth) {
                width = (int) (height * ratio);
            }
        }

        // no intrinsic size --> use default size
        int textureWidth = iconBitmapSize;
        int textureHeight = iconBitmapSize;

        final Bitmap bitmap = Bitmap.createBitmap(textureWidth, textureHeight, Bitmap.Config.ARGB_8888);
        final Canvas canvas = sCanvas;
        canvas.setBitmap(bitmap);

        final int left = (textureWidth - width) / 2;
        final int top = (textureHeight - height) / 2;

        @SuppressWarnings("all") // suppress dead code warning
        final boolean debug = false;
        if (debug) {
            // draw a big box for the icon for debugging
            canvas.drawColor(sColors[sColorIndex]);
            if (++sColorIndex >= sColors.length)
                sColorIndex = 0;
            Paint debugPaint = new Paint();
            debugPaint.setColor(0xffcccc00);
            canvas.drawRect(left, top, left + width, top + height, debugPaint);
        }

        sOldBounds.set(icon.getBounds());
        icon.setBounds(left, top, left + width, top + height);
        canvas.save(Canvas.MATRIX_SAVE_FLAG);
        canvas.scale(scale, scale, textureWidth / 2, textureHeight / 2);
        icon.draw(canvas);
        canvas.restore();
        icon.setBounds(sOldBounds);
        canvas.setBitmap(null);

        return bitmap;
    }
}

From source file:de.tlabs.ssr.g1.client.SourcesView.java

@Override
public void onDraw(Canvas canvas) {
    // zooming animation
    if (scalingInterpolator.isActive()) {
        setCurrentScaling(scalingInterpolator.getCurrentValue());
    }//from   ww w  .  j  a v  a 2  s  .co m

    // translation animation
    if (translationXInterpolator.isActive() || translationYInterpolator.isActive()) {
        float transX = currentTranslation[0];
        float transY = currentTranslation[1];
        if (translationXInterpolator.isActive()) {
            transX = translationXInterpolator.getCurrentValue();
        }
        if (translationYInterpolator.isActive()) {
            transY = translationYInterpolator.getCurrentValue();
        }
        setCurrentTranslation(transX, transY);
    }

    // center rotation animation
    if (centerRotationInterpolator.isActive()) {
        setCurrentCenterRotation(centerRotationInterpolator.getCurrentValue());
    }

    // calculate current viewport matrix if necessary
    if (getAndClearViewportFlag()) {
        recalculateViewportTransformation();
        recalculateSizeScale();
    }

    // clear background
    canvas.drawColor(0xFF000000);

    // draw audio scene
    canvas.setMatrix(viewportTransformation);
    synchronized (GlobalData.audioScene) {
        GlobalData.audioScene.draw(canvas, currentInverseScaling);
    }

    // reset matrix
    canvas.setMatrix(null);

    // draw size scale
    sizeScalePicture.draw(canvas);
}

From source file:com.gelakinetic.mtgfam.helpers.IndeterminateProgressBar.java

public void draw(Canvas canvas) {
    final int width = mBounds.width();
    final int height = mBounds.height();
    final int cx = width / 2;
    final int cy = height / 2;
    int restoreCount = canvas.save();
    canvas.clipRect(mBounds);/*  w w  w .  ja v  a  2s  .co  m*/

    if (mRunning || (mFinishTime > 0)) {
        long now = AnimationUtils.currentAnimationTimeMillis();
        long elapsed = (now - mStartTime) % ANIMATION_DURATION_MS;
        float rawProgress = (elapsed / (ANIMATION_DURATION_MS / 100f));

        // If we're not running anymore, that means we're running through the finish animation.
        if (!mRunning) {
            // If the finish animation is done, don't draw anything, and don't re-post.
            if ((now - mFinishTime) >= FINISH_ANIMATION_DURATION_MS) {
                mFinishTime = 0;
                return;
            }

            // Otherwise, use a 0 opacity alpha layer to clear the animation
            // from the inside out. This layer will prevent the circles from
            // drawing within its bounds.
            long finishElapsed = (now - mFinishTime) % FINISH_ANIMATION_DURATION_MS;
            float finishProgress = (finishElapsed / (FINISH_ANIMATION_DURATION_MS / 100f));
            float pct = (finishProgress / 100f);
            // Radius of the circle is half of the screen.
            float clearRadius = width / 2 * INTERPOLATOR.getInterpolation(pct);
            mClipRect.set(cx - clearRadius, 0, cx + clearRadius, height);
            canvas.saveLayerAlpha(mClipRect, 0, 0);
        }

        if (rawProgress >= 0 && rawProgress < 25) {
            canvas.drawColor(mColor4);
        } else if (rawProgress >= 25 && rawProgress < 50) {
            canvas.drawColor(mColor1);
        } else if (rawProgress >= 50 && rawProgress < 75) {
            canvas.drawColor(mColor2);
        } else {
            canvas.drawColor(mColor3);
        }

        // Then draw up to 4 overlapping concentric circles of varying radii, based on how far
        // along we are in the cycle.
        // progress 0-50 draw mColor2
        // progress 25-75 draw mColor3
        // progress 50-100 draw mColor4
        // progress 75 (wrap to 25) draw mColor1
        if ((rawProgress >= 0 && rawProgress <= 25)) {
            float pct = (((rawProgress + 25) * 2) / 100f);
            drawCircle(canvas, cx, cy, mColor1, pct);
        }
        if (rawProgress >= 0 && rawProgress <= 50) {
            float pct = ((rawProgress * 2) / 100f);
            drawCircle(canvas, cx, cy, mColor2, pct);
        }
        if (rawProgress >= 25 && rawProgress <= 75) {
            float pct = (((rawProgress - 25) * 2) / 100f);
            drawCircle(canvas, cx, cy, mColor3, pct);
        }
        if (rawProgress >= 50 && rawProgress <= 100) {
            float pct = (((rawProgress - 50) * 2) / 100f);
            drawCircle(canvas, cx, cy, mColor4, pct);
        }
        if ((rawProgress >= 75 && rawProgress <= 100)) {
            float pct = (((rawProgress - 75) * 2) / 100f);
            drawCircle(canvas, cx, cy, mColor1, pct);
        }
        // Keep running until we finish out the last cycle.
        ViewCompat.postInvalidateOnAnimation(mParent);
    }
    canvas.restoreToCount(restoreCount);
}

From source file:com.cssweb.android.view.TrendView.java

private void drawChart(Canvas canvas) throws JSONException {
    Log.i("@@@@@@@@@draw tick@@@@@@@@@@", quoteArray + ">>>>>>>>>");
    //Log.i("@@@@@@@@@@@@@@@@@@@", quoteArray.length()+">>>>>>>>>");
    if (quoteArray == null || quoteArray.isNull(0))
        return;// ww  w  . jav  a 2  s .  c  o  m

    canvas.drawColor(GlobalColor.clearSCREEN);

    paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(1);

    mpaint = new Paint();
    mpaint.setTypeface(Typeface.DEFAULT_BOLD);
    mpaint.setAntiAlias(true);
    mpaint.setTextAlign(Paint.Align.LEFT);
    mpaint.setStyle(Paint.Style.STROKE);
    mpaint.setTextSize(dTextSize);

    /**
     * ?
     */
    closeLeft = Utils.dataFormation(high, stockdigit);
    closeRight = "00.00%";
    LSpace = (int) (Math.max(mpaint.measureText(closeLeft),
            mpaint.measureText(String.valueOf(Math.round(highvolume)))));
    //???
    //RSpace = (int)(paint.measureText(closeRight) + 10);
    RSpace = 0;

    axisLabelHeight = Font.getFontHeight(dTextSize);

    graphicsQuoteWidth = width - LSpace - RSpace;
    SPACE = graphicsQuoteWidth / MINUTES;
    topTitleHeight = axisLabelHeight;
    graphicsQuoteHeight = height - axisLabelHeight - topTitleHeight;
    price_row_num = 2;//(int)graphicsQuoteHeight/3/25;
    volume_row_num = price_row_num;
    price_row_height = graphicsQuoteHeight / price_row_num / 3;
    volume_row_height = price_row_height;

    calc_zf();

    title1 = ":";
    title7 = ":";
    title8 = quoteArray.getJSONArray(isTrackNumber).getString(3);
    title2 = Utils.dataFormation(quoteArray.getJSONArray(isTrackNumber).getDouble(0), stockdigit);

    mpaint.setColor(GlobalColor.colorLabelName);

    canvas.drawText(title7 + title8.substring(11, 16), LSpace, axisLabelHeight - 5, mpaint);
    canvas.drawText(title1, LSpace + mpaint.measureText(":00:0000"), axisLabelHeight - 5, mpaint);
    if (quoteArray.getJSONArray(isTrackNumber).getDouble(0) == 0) {
        mpaint.setColor(GlobalColor.colorPriceEqual);
    } else if (quoteArray.getJSONArray(isTrackNumber).getDouble(0) > close) {
        mpaint.setColor(GlobalColor.colorpriceUp);
    } else if (quoteArray.getJSONArray(isTrackNumber).getDouble(0) < close) {
        mpaint.setColor(GlobalColor.colorPriceDown);
    } else {
        mpaint.setColor(GlobalColor.colorPriceEqual);
    }
    canvas.drawText(title2, LSpace + mpaint.measureText(":00:0000:"), axisLabelHeight - 5, mpaint);

    if (!this.isZs()) {
        if ("cf".equals(exchange) || "dc".equals(exchange) || "sf".equals(exchange) || "cz".equals(exchange)
                || "hk".equals(exchange)) {
        } else {
            mpaint.setColor(GlobalColor.colorLabelName);
            title9 = "?:";
            canvas.drawText(title9, LSpace + mpaint.measureText(":00:000000:" + title2),
                    axisLabelHeight - 5, mpaint);
            double avePrice = 0;
            double cjje = quoteArray.getJSONArray(isTrackNumber).getDouble(2);
            int scaleCount = 1;
            scaleCount = Utils.getCoefficient(exchange, stockcode);
            double cjsl = quoteArray.getJSONArray(isTrackNumber).getDouble(1) * scaleCount;
            if (cjsl > 0) {
                avePrice = cjje / cjsl;
            } else {
                avePrice = jrkp;
            }
            if (avePrice == 0) {
                mpaint.setColor(GlobalColor.colorPriceEqual);
            } else if (avePrice > close) {
                mpaint.setColor(GlobalColor.colorpriceUp);
            } else if (avePrice < close) {
                mpaint.setColor(GlobalColor.colorPriceDown);
            } else {
                mpaint.setColor(GlobalColor.colorPriceEqual);
            }
            canvas.drawText(Utils.dataFormation(avePrice, stockdigit),
                    LSpace + mpaint.measureText(":00:000000:" + title2 + "?:"),
                    axisLabelHeight - 5, mpaint);
        }
    }

    if (isZs()) {
        if (close == 0)
            close = 1000;
    } else {
        if (close == 0)
            close = 1;
    }

    low = Math.min(low, close);
    //upPrice = close * (1+max_zf);
    //downPrice = close * (1-max_zf);

    paint.setColor(GlobalColor.clrLine);
    canvas.drawLine(LSpace + graphicsQuoteWidth, topTitleHeight, LSpace + graphicsQuoteWidth,
            graphicsQuoteHeight + topTitleHeight, paint);

    // 
    upQuoteX = LSpace;
    upQuoteY = topTitleHeight;
    upQuoteWidth = (int) graphicsQuoteWidth;
    upQuoteHeight = price_row_num * price_row_height;
    for (int i = 0; i < price_row_num; i++) {
        if (i == 0) {
            canvas.drawLine(upQuoteX, upQuoteY + price_row_height * i, upQuoteX + upQuoteWidth,
                    upQuoteY + price_row_height * i, paint);
        } else
            Graphics.drawDashline(canvas, upQuoteX, upQuoteY + price_row_height * i, upQuoteX + upQuoteWidth,
                    upQuoteY + price_row_height * i, paint);
    }

    for (int i = 0; i < DIVIDE_COUNT; i++) {
        if (i == 0) {
            canvas.drawLine(upQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, upQuoteY,
                    upQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, upQuoteY + upQuoteHeight, paint);
        } else
            Graphics.drawDashline(canvas, upQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, upQuoteY,
                    upQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, upQuoteY + upQuoteHeight, paint);
    }
    //scale = close * max_zf / price_row_num;
    scale = Arith.div(close * max_zf, price_row_num, stockdigit + 1);

    mpaint.setTextAlign(Paint.Align.RIGHT);
    mpaint.setColor(GlobalColor.colorPriceEqual);
    canvas.drawText(Utils.dataFormation(close, stockdigit), upQuoteX,
            upQuoteY + upQuoteHeight + axisLabelHeight / 2, mpaint);

    mpaint.setColor(GlobalColor.colorpriceUp);
    for (int i = 1; i <= price_row_num; i++) {
        AxisLabelPrice = close + scale * i;
        canvas.drawText(Utils.dataFormation(AxisLabelPrice, stockdigit), upQuoteX,
                upQuoteY + upQuoteHeight - price_row_height * i + axisLabelHeight / 2, mpaint);
    }

    // 
    downQuoteX = LSpace;
    downQuoteY = topTitleHeight + upQuoteHeight;
    downQuoteWidth = (int) graphicsQuoteWidth;

    downQuoteHeight = upQuoteHeight;

    paint.setColor(GlobalColor.clrLine);
    for (int i = 0; i < price_row_num; i++) {
        if (i == 0) {
            canvas.drawLine(downQuoteX, downQuoteY + price_row_height * i, downQuoteX + downQuoteWidth,
                    downQuoteY + price_row_height * i, paint);
        } else
            Graphics.drawDashline(canvas, downQuoteX, downQuoteY + price_row_height * i,
                    downQuoteX + downQuoteWidth, downQuoteY + price_row_height * i, paint);
    }

    for (int i = 0; i < DIVIDE_COUNT; i++) {
        if (i == 0) {
            canvas.drawLine(downQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, downQuoteY,
                    downQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, downQuoteY + downQuoteHeight + 1, paint);
        } else
            Graphics.drawDashline(canvas, downQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, downQuoteY,
                    downQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, downQuoteY + downQuoteHeight, paint);
    }

    mpaint.setColor(GlobalColor.colorPriceDown);
    for (int i = 1; i < price_row_num; i++) {
        AxisLabelPrice = close - scale * i;
        canvas.drawText(Utils.dataFormation(AxisLabelPrice, stockdigit), upQuoteX,
                upQuoteY + upQuoteHeight + price_row_height * i + axisLabelHeight / 2, mpaint);
    }

    //  
    // added by hujun for 20110511???
    if (actualDataLen > 0 && !this.isOpenFund()) {
        if ("cf".equals(exchange) || "dc".equals(exchange) || "sf".equals(exchange) || "cz".equals(exchange)) {
            scale = upQuoteHeight / (close * max_zf);
            paint.setColor(GlobalColor.colorFZLine);
            int quotelen = quoteArray.length();
            double x1 = 0;
            double y1 = 0;
            double x2 = 0;
            double y2 = 0;
            double temp = 0;

            x1 = upQuoteX;
            double lastnewp = 0;
            double nownewp = 0;
            nownewp = quoteArray.getJSONArray(0).getDouble(0);
            if (nownewp == 0)
                nownewp = close;
            if (nownewp >= close) {
                temp = (nownewp - close) * scale;
                y1 = topTitleHeight + upQuoteHeight - temp;
            } else {
                temp = (close - nownewp) * scale;
                y1 = topTitleHeight + upQuoteHeight + temp;
            }
            lastnewp = nownewp;
            for (int i = 1; i < quotelen; i++) {
                x2 = upQuoteX + SPACE * i;
                nownewp = quoteArray.getJSONArray(i).getDouble(0);
                if (nownewp == 0)
                    nownewp = lastnewp;
                if (nownewp >= close) {
                    temp = (nownewp - close) * scale;
                    y2 = topTitleHeight + upQuoteHeight - temp;
                } else {
                    temp = (close - nownewp) * scale;
                    y2 = topTitleHeight + upQuoteHeight + temp;
                }
                lastnewp = nownewp;

                canvas.drawLine((int) x1, (int) y1, (int) x2, (int) y2, paint);

                x1 = x2;
                y1 = y2;
            } // end for

            paint.setColor(GlobalColor.colorFZAvePriceLine);
            x1 = upQuoteX;
            double cjje = quoteArray.getJSONArray(0).getDouble(0);
            double avePrice = cjje;
            double lastavg = 0;
            if (avePrice > high) {
                avePrice = high;
            }
            if (avePrice < low) {
                avePrice = low;
            }
            if (avePrice >= close) {
                temp = (avePrice - close) * scale;
                y1 = topTitleHeight + upQuoteHeight - temp;
            } else {
                temp = (close - avePrice) * scale;
                y1 = topTitleHeight + upQuoteHeight + temp;
            }
            lastavg = avePrice;
            double xl = quoteArray.getJSONArray(0).getDouble(1);
            double mathpjj = quoteArray.getJSONArray(0).getDouble(0) * xl;
            for (int i = 1; i < quotelen; i++) {
                x2 = upQuoteX + SPACE * i;
                mathpjj += quoteArray.getJSONArray(i).getDouble(0) * (quoteArray.getJSONArray(i).getDouble(1)
                        - quoteArray.getJSONArray(i - 1).getDouble(1));
                if (mathpjj == 0) {
                    if (lastavg == 0) {
                        avePrice = close;
                    } else {
                        avePrice = lastavg;
                    }
                } else {
                    avePrice = mathpjj / quoteArray.getJSONArray(i).getDouble(1);
                }
                lastavg = avePrice;
                if (avePrice > high) {
                    avePrice = high;
                }
                if (avePrice < low) {
                    avePrice = low;
                }
                if (avePrice >= close) {
                    temp = (avePrice - close) * scale;
                    y2 = topTitleHeight + upQuoteHeight - temp;
                } else {
                    temp = (close - avePrice) * scale;
                    y2 = topTitleHeight + upQuoteHeight + temp;
                }
                canvas.drawLine((int) x1, (int) y1, (int) x2, (int) y2, paint);

                x1 = x2;
                y1 = y2;
            } // end for
        } else {
            scale = upQuoteHeight / (close * max_zf);
            paint.setColor(GlobalColor.colorFZLine);
            int quotelen = quoteArray.length();
            double x1 = 0;
            double y1 = 0;
            double x2 = 0;
            double y2 = 0;
            double temp = 0;

            x1 = upQuoteX;
            double lastnewp = 0;
            double nownewp = 0;
            nownewp = quoteArray.getJSONArray(0).getDouble(0);
            if (nownewp == 0)
                nownewp = close;
            if (nownewp >= close) {
                temp = (nownewp - close) * scale;
                y1 = topTitleHeight + upQuoteHeight - temp;
            } else {
                temp = (close - nownewp) * scale;
                y1 = topTitleHeight + upQuoteHeight + temp;
            }
            lastnewp = nownewp;
            for (int i = 1; i < quotelen; i++) {
                x2 = upQuoteX + SPACE * i;
                nownewp = quoteArray.getJSONArray(i).getDouble(0);
                if (nownewp == 0)
                    nownewp = lastnewp;
                if (nownewp >= close) {
                    temp = (nownewp - close) * scale;
                    y2 = topTitleHeight + upQuoteHeight - temp;
                } else {
                    temp = (close - nownewp) * scale;
                    y2 = topTitleHeight + upQuoteHeight + temp;
                }
                lastnewp = nownewp;

                canvas.drawLine((int) x1, (int) y1, (int) x2, (int) y2, paint);

                x1 = x2;
                y1 = y2;
            } // end for

            if (this.isZs()) {
                // ?   ??
                if ("sz".equals(exchange) || "sh".equals(exchange)) {
                    if (("000001".equals(stockcode) || "399001".equals(stockcode))
                            && !quoteData.isNull("data2")) {
                        paint.setColor(GlobalColor.colorFZAvePriceLine);
                        x1 = upQuoteX;
                        double avePrice = quoteData.getJSONArray("data2").getJSONArray(0).getDouble(0);
                        if (avePrice > high) {
                            avePrice = high;
                        }
                        if (avePrice < low) {
                            avePrice = low;
                        }
                        if (avePrice >= close) {
                            temp = (avePrice - close) * scale;
                            y1 = topTitleHeight + upQuoteHeight - temp;
                        } else {
                            temp = (close - avePrice) * scale;
                            y1 = topTitleHeight + upQuoteHeight + temp;
                        }
                        int len = quoteData.getJSONArray("data2").length();
                        for (int i = 1; i < len; i++) {
                            if ("15:00".equals(quoteData.getJSONArray("data2").getJSONArray(i).getString(1)
                                    .substring(11, 16))) {

                            } else {
                                x2 = upQuoteX + SPACE * i;
                                avePrice = quoteData.getJSONArray("data2").getJSONArray(i).getDouble(0);
                                if (avePrice > high) {
                                    avePrice = high;
                                }
                                if (avePrice < low) {
                                    avePrice = low;
                                }
                                if (avePrice >= close) {
                                    temp = (avePrice - close) * scale;
                                    y2 = topTitleHeight + upQuoteHeight - temp;
                                } else {
                                    temp = (close - avePrice) * scale;
                                    y2 = topTitleHeight + upQuoteHeight + temp;
                                }
                                canvas.drawLine((int) x1, (int) y1, (int) x2, (int) y2, paint);

                                x1 = x2;
                                y1 = y2;
                            }
                        } // end for
                    } else {
                        paint.setColor(GlobalColor.colorFZAvePriceLine);
                        x1 = upQuoteX;
                        double cjje = quoteArray.getJSONArray(0).getDouble(0);
                        double avePrice = cjje;
                        double lastavg = 0;
                        if (avePrice > high) {
                            avePrice = high;
                        }
                        if (avePrice < low) {
                            avePrice = low;
                        }
                        if (avePrice >= close) {
                            temp = (avePrice - close) * scale;
                            y1 = topTitleHeight + upQuoteHeight - temp;
                        } else {
                            temp = (close - avePrice) * scale;
                            y1 = topTitleHeight + upQuoteHeight + temp;
                        }
                        lastavg = avePrice;
                        double xl = quoteArray.getJSONArray(0).getDouble(1);
                        double mathpjj = quoteArray.getJSONArray(0).getDouble(0) * xl;
                        for (int i = 1; i < quotelen; i++) {
                            x2 = upQuoteX + SPACE * i;
                            mathpjj += quoteArray.getJSONArray(i).getDouble(0)
                                    * (quoteArray.getJSONArray(i).getDouble(1)
                                            - quoteArray.getJSONArray(i - 1).getDouble(1));
                            if (mathpjj == 0) {
                                if (lastavg == 0) {
                                    avePrice = close;
                                } else {
                                    avePrice = lastavg;
                                }
                            } else {
                                avePrice = mathpjj / quoteArray.getJSONArray(i).getDouble(1);
                            }
                            lastavg = avePrice;
                            if (avePrice > high) {
                                avePrice = high;
                            }
                            if (avePrice < low) {
                                avePrice = low;
                            }
                            if (avePrice >= close) {
                                temp = (avePrice - close) * scale;
                                y2 = topTitleHeight + upQuoteHeight - temp;
                            } else {
                                temp = (close - avePrice) * scale;
                                y2 = topTitleHeight + upQuoteHeight + temp;
                            }
                            canvas.drawLine((int) x1, (int) y1, (int) x2, (int) y2, paint);

                            x1 = x2;
                            y1 = y2;
                        } // end for
                    }
                }
            } else {
                paint.setColor(GlobalColor.colorFZAvePriceLine);
                x1 = upQuoteX;
                double cjje = quoteArray.getJSONArray(0).getDouble(2);
                int scaleCount = 1;
                scaleCount = Utils.getCoefficient(exchange, stockcode);
                double cjsl = quoteArray.getJSONArray(0).getDouble(1) * scaleCount;
                double avePrice = cjje / cjsl;
                double lastavg = 0;
                if (cjsl == 0)
                    avePrice = close;
                if (avePrice > high) {
                    avePrice = high;
                }
                if (avePrice < low) {
                    avePrice = low;
                }
                if (avePrice >= close) {
                    temp = (avePrice - close) * scale;
                    y1 = topTitleHeight + upQuoteHeight - temp;
                } else {
                    temp = (close - avePrice) * scale;
                    y1 = topTitleHeight + upQuoteHeight + temp;
                }
                lastavg = avePrice;
                for (int i = 1; i < quotelen; i++) {
                    x2 = upQuoteX + SPACE * i;
                    cjje = quoteArray.getJSONArray(i).getDouble(2);
                    cjsl = quoteArray.getJSONArray(i).getDouble(1) * scaleCount; // ?
                    if (cjsl == 0) {
                        if (lastavg == 0) {
                            avePrice = close;
                        } else {
                            avePrice = lastavg;
                        }
                    } else {
                        avePrice = cjje / cjsl;
                    }
                    lastavg = avePrice;
                    if (avePrice > high) {
                        avePrice = high;
                    }
                    if (avePrice < low) {
                        avePrice = low;
                    }
                    if (avePrice >= close) {
                        temp = (avePrice - close) * scale;
                        y2 = topTitleHeight + upQuoteHeight - temp;
                    } else {
                        temp = (close - avePrice) * scale;
                        y2 = topTitleHeight + upQuoteHeight + temp;
                    }
                    canvas.drawLine((int) x1, (int) y1, (int) x2, (int) y2, paint);

                    x1 = x2;
                    y1 = y2;
                } // end for
            }
        }
    }

    // ??
    volumeX = LSpace;
    volumeY = topTitleHeight + upQuoteHeight + downQuoteHeight;
    volumeWidth = (int) graphicsQuoteWidth;
    volumeHeight = graphicsQuoteHeight - upQuoteHeight - downQuoteHeight;

    volume_row_height = volumeHeight / volume_row_num;

    paint.setColor(GlobalColor.clrLine);
    for (int i = 0; i <= volume_row_num; i++) {
        if (i == 0) {
            canvas.drawLine(volumeX, volumeY + volume_row_height * i, volumeX + volumeWidth,
                    volumeY + volume_row_height * i, paint);
        } else {
            if (i != volume_row_num)
                Graphics.drawDashline(canvas, volumeX, volumeY + volume_row_height * i, volumeX + volumeWidth,
                        volumeY + volume_row_height * i, paint);
        }
    }

    for (int i = 0; i < DIVIDE_COUNT; i++) {
        if (i == 0) {
            canvas.drawLine(volumeX + MINUTES / DIVIDE_COUNT * SPACE * i, volumeY,
                    volumeX + MINUTES / DIVIDE_COUNT * SPACE * i, volumeY + volumeHeight, paint);
        } else
            Graphics.drawDashline(canvas, volumeX + MINUTES / DIVIDE_COUNT * SPACE * i, volumeY,
                    volumeX + MINUTES / DIVIDE_COUNT * SPACE * i, volumeY + volumeHeight, paint);
    }

    if (this.isZs()) {
        //highVolume =  TickUtil.gethighAmount(quoteData.getJSONArray("data"));
        highVolume = highamount;
    } else {
        //highVolume =  TickUtil.gethighVolume(quoteData.getJSONArray("data"));
        highVolume = highvolume;
    }

    if (highVolume == 0) {
        if (this.isZs()) {
            // ?
            highVolume = volume_row_num * 4 * 100; // ???48highVolume=32
        } else {
            highVolume = volume_row_num * 4 * 100; // ???48highVolume=32
        }
    }
    if (highVolume < volume_row_num + 1)
        highVolume = volume_row_num + 1;
    scale = highVolume / volume_row_num;
    int volumeLabelY = volumeY + Font.getFontHeight(dTextSize) / 2;

    mpaint.setColor(GlobalColor.clr_tick_volume);
    for (int i = 0; i <= volume_row_num; i++) {
        if (i != volume_row_num) {
            AxisLabelVolume = highVolume - scale * i;
            if (this.isZs())
                AxisLabelVolume = Math.round(AxisLabelVolume / 10000);
            else
                AxisLabelVolume = Math.round(AxisLabelVolume);

            canvas.drawText(String.valueOf((int) AxisLabelVolume), upQuoteX,
                    volumeLabelY + volume_row_height * i, mpaint);
        }
    }

    // ??
    if (actualDataLen > 0) {
        scale = volumeHeight / highVolume;
        paint.setColor(GlobalColor.colorVolumeLine);
        double prevVol = 0;
        double temp = 0;
        for (int i = 0; i < actualDataLen; i++) {
            if (this.isZs())
                temp = (quoteArray.getJSONArray(i).getDouble(2) - prevVol) * scale;
            else
                temp = (quoteArray.getJSONArray(i).getDouble(1) - prevVol) * scale;
            float x1 = volumeX + SPACE * i;
            float y1 = (float) (volumeY + volumeHeight - temp);

            float x2 = x1;
            float y2 = volumeY + volumeHeight;
            canvas.drawLine((int) x1, (int) y1, (int) x2, (int) y2, paint);
            if (this.isZs())
                prevVol = quoteArray.getJSONArray(i).getDouble(2);
            else
                prevVol = quoteArray.getJSONArray(i).getDouble(1);
        }
    }

    drawTimeX(canvas);

    // 
    paint.setColor(GlobalColor.clrLine);
    canvas.drawLine(LSpace, graphicsQuoteHeight + topTitleHeight, LSpace + graphicsQuoteWidth,
            graphicsQuoteHeight + topTitleHeight, paint);

    if (isTrackStatus) {
        canvas.save();
        //??
        paint.setColor(GlobalColor.colorLine);
        canvas.drawLine(trackLineV, topTitleHeight, trackLineV, graphicsQuoteHeight + topTitleHeight, paint);
        canvas.restore();
    }
}

From source file:com.bluepixel.android.sgpool.ui.widget.SwipeProgressBar.java

void draw(Canvas canvas) {
    final int width = mBounds.width();
    final int cx = width / 2;
    final int cy = mBounds.top + mBounds.height() / 2;
    boolean drawTriggerWhileFinishing = false;
    int restoreCount = canvas.save();
    canvas.clipRect(mBounds);/*from   ww  w.j  av  a  2  s .co  m*/
    if (mRunning || (mFinishTime > 0)) {
        long now = AnimationUtils.currentAnimationTimeMillis();
        long elapsed = (now - mStartTime) % ANIMATION_DURATION_MS;
        long iterations = (now - mStartTime) / ANIMATION_DURATION_MS;
        float rawProgress = (elapsed / (ANIMATION_DURATION_MS / 100f));
        // If we're not running anymore, that means we're running through
        // the finish animation.
        if (!mRunning) {
            // If the finish animation is done, don't draw anything, and
            // don't repost.
            if ((now - mFinishTime) >= FINISH_ANIMATION_DURATION_MS) {
                mFinishTime = 0;
                return;
            }
            // Otherwise, use a 0 opacity alpha layer to clear the animation
            // from the inside out. This layer will prevent the circles from
            // drawing within its bounds.
            long finishElapsed = (now - mFinishTime) % FINISH_ANIMATION_DURATION_MS;
            float finishProgress = (finishElapsed / (FINISH_ANIMATION_DURATION_MS / 100f));
            float pct = (finishProgress / 100f);
            // Radius of the circle is half of the screen.
            float clearRadius = width / 2 * INTERPOLATOR.getInterpolation(pct);
            mClipRect.set(cx - clearRadius, mBounds.top, cx + clearRadius, mBounds.bottom);
            canvas.saveLayerAlpha(mClipRect, 0, 0);
            // Only draw the trigger if there is a space in the center of
            // this refreshing view that needs to be filled in by the
            // trigger. If the progress view is just still animating, let it
            // continue animating.
            drawTriggerWhileFinishing = true;
        }
        // First fill in with the last color that would have finished drawing.
        if (iterations == 0) {
            canvas.drawColor(mColor1);
        } else {
            if (rawProgress >= 0 && rawProgress < 25) {
                canvas.drawColor(mColor4);
            } else if (rawProgress >= 25 && rawProgress < 50) {
                canvas.drawColor(mColor1);
            } else if (rawProgress >= 50 && rawProgress < 75) {
                canvas.drawColor(mColor2);
            } else {
                canvas.drawColor(mColor3);
            }
        }
        // Then draw up to 4 overlapping concentric circles of varying radii, based on how far
        // along we are in the cycle.
        // progress 0-50 draw mColor2
        // progress 25-75 draw mColor3
        // progress 50-100 draw mColor4
        // progress 75 (wrap to 25) draw mColor1
        if ((rawProgress >= 0 && rawProgress <= 25)) {
            float pct = (((rawProgress + 25) * 2) / 100f);
            drawCircle(canvas, cx, cy, mColor1, pct);
        }
        if (rawProgress >= 0 && rawProgress <= 50) {
            float pct = ((rawProgress * 2) / 100f);
            drawCircle(canvas, cx, cy, mColor2, pct);
        }
        if (rawProgress >= 25 && rawProgress <= 75) {
            float pct = (((rawProgress - 25) * 2) / 100f);
            drawCircle(canvas, cx, cy, mColor3, pct);
        }
        if (rawProgress >= 50 && rawProgress <= 100) {
            float pct = (((rawProgress - 50) * 2) / 100f);
            drawCircle(canvas, cx, cy, mColor4, pct);
        }
        if ((rawProgress >= 75 && rawProgress <= 100)) {
            float pct = (((rawProgress - 75) * 2) / 100f);
            drawCircle(canvas, cx, cy, mColor1, pct);
        }
        if (mTriggerPercentage > 0 && drawTriggerWhileFinishing) {
            // There is some portion of trigger to draw. Restore the canvas,
            // then draw the trigger. Otherwise, the trigger does not appear
            // until after the bar has finished animating and appears to
            // just jump in at a larger width than expected.
            canvas.restoreToCount(restoreCount);
            restoreCount = canvas.save();
            canvas.clipRect(mBounds);
            drawTrigger(canvas, cx, cy);
        }
        // Keep running until we finish out the last cycle.
        ViewCompat.postInvalidateOnAnimation(mParent);
    } else {
        // Otherwise if we're in the middle of a trigger, draw that.
        if (mTriggerPercentage > 0 && mTriggerPercentage <= 1.0) {
            drawTrigger(canvas, cx, cy);
        }
    }
    canvas.restoreToCount(restoreCount);
}

From source file:br.com.leoleal.swipetorefresh.SwipeProgressBar.java

void draw(Canvas canvas) {
    final int width = mBounds.width();
    final int height = mBounds.height();
    final int cx = width / 2;
    final int cy = height / 2;
    boolean drawTriggerWhileFinishing = false;
    int restoreCount = canvas.save();
    canvas.clipRect(mBounds);/*from  w  w w.j av  a  2s.com*/

    if (mRunning || (mFinishTime > 0)) {
        long now = AnimationUtils.currentAnimationTimeMillis();
        long elapsed = (now - mStartTime) % ANIMATION_DURATION_MS;
        long iterations = (now - mStartTime) / ANIMATION_DURATION_MS;
        float rawProgress = (elapsed / (ANIMATION_DURATION_MS / 100f));

        // If we're not running anymore, that means we're running through
        // the finish animation.
        if (!mRunning) {
            // If the finish animation is done, don't draw anything, and
            // don't repost.
            if ((now - mFinishTime) >= FINISH_ANIMATION_DURATION_MS) {
                mFinishTime = 0;
                return;
            }

            // Otherwise, use a 0 opacity alpha layer to clear the animation
            // from the inside out. This layer will prevent the circles from
            // drawing within its bounds.
            long finishElapsed = (now - mFinishTime) % FINISH_ANIMATION_DURATION_MS;
            float finishProgress = (finishElapsed / (FINISH_ANIMATION_DURATION_MS / 100f));
            float pct = (finishProgress / 100f);
            // Radius of the circle is half of the screen.
            float clearRadius = width / 2 * INTERPOLATOR.getInterpolation(pct);
            mClipRect.set(cx - clearRadius, 0, cx + clearRadius, height);
            canvas.saveLayerAlpha(mClipRect, 0, 0);
            // Only draw the trigger if there is a space in the center of
            // this refreshing view that needs to be filled in by the
            // trigger. If the progress view is just still animating, let it
            // continue animating.
            drawTriggerWhileFinishing = true;
        }

        // First fill in with the last color that would have finished drawing.
        if (iterations == 0) {
            canvas.drawColor(mColor1);
        } else {
            if (rawProgress >= 0 && rawProgress < 25) {
                canvas.drawColor(mColor4);
            } else if (rawProgress >= 25 && rawProgress < 50) {
                canvas.drawColor(mColor1);
            } else if (rawProgress >= 50 && rawProgress < 75) {
                canvas.drawColor(mColor2);
            } else {
                canvas.drawColor(mColor3);
            }
        }

        // Then draw up to 4 overlapping concentric circles of varying radii, based on how far
        // along we are in the cycle.
        // progress 0-50 draw mColor2
        // progress 25-75 draw mColor3
        // progress 50-100 draw mColor4
        // progress 75 (wrap to 25) draw mColor1
        if ((rawProgress >= 0 && rawProgress <= 25)) {
            float pct = (((rawProgress + 25) * 2) / 100f);
            drawCircle(canvas, cx, cy, mColor1, pct);
        }
        if (rawProgress >= 0 && rawProgress <= 50) {
            float pct = ((rawProgress * 2) / 100f);
            drawCircle(canvas, cx, cy, mColor2, pct);
        }
        if (rawProgress >= 25 && rawProgress <= 75) {
            float pct = (((rawProgress - 25) * 2) / 100f);
            drawCircle(canvas, cx, cy, mColor3, pct);
        }
        if (rawProgress >= 50 && rawProgress <= 100) {
            float pct = (((rawProgress - 50) * 2) / 100f);
            drawCircle(canvas, cx, cy, mColor4, pct);
        }
        if ((rawProgress >= 75 && rawProgress <= 100)) {
            float pct = (((rawProgress - 75) * 2) / 100f);
            drawCircle(canvas, cx, cy, mColor1, pct);
        }
        if (mTriggerPercentage > 0 && drawTriggerWhileFinishing) {
            // There is some portion of trigger to draw. Restore the canvas,
            // then draw the trigger. Otherwise, the trigger does not appear
            // until after the bar has finished animating and appears to
            // just jump in at a larger width than expected.
            canvas.restoreToCount(restoreCount);
            restoreCount = canvas.save();
            canvas.clipRect(mBounds);
            drawTrigger(canvas, cx, cy);
        }
        // Keep running until we finish out the last cycle.
        ViewCompat.postInvalidateOnAnimation(mParent, mBounds.left, mBounds.top, mBounds.right, mBounds.bottom);
    } else {
        // Otherwise if we're in the middle of a trigger, draw that.
        if (mTriggerPercentage > 0 && mTriggerPercentage <= 1.0) {
            drawTrigger(canvas, cx, cy);
        }
    }
    canvas.restoreToCount(restoreCount);
}

From source file:cn.sdgundam.comicatsdgo.extension.SwipeProgressBar.java

void draw(Canvas canvas) {
    final int width = mBounds.width();
    final int height = mBounds.height();
    final int cx = width / 2;
    final int cy = height / 2;
    boolean drawTriggerWhileFinishing = false;
    int restoreCount = canvas.save();
    canvas.clipRect(mBounds);//from   ww w  . j  ava 2s . co m

    if (mRunning || (mFinishTime > 0)) {
        long now = AnimationUtils.currentAnimationTimeMillis();
        long elapsed = (now - mStartTime) % ANIMATION_DURATION_MS;
        long iterations = (now - mStartTime) / ANIMATION_DURATION_MS;
        float rawProgress = (elapsed / (ANIMATION_DURATION_MS / 100f));

        // If we're not running anymore, that means we're running through
        // the finish animation.
        if (!mRunning) {
            // If the finish animation is done, don't draw anything, and
            // don't repost.
            if ((now - mFinishTime) >= FINISH_ANIMATION_DURATION_MS) {
                mFinishTime = 0;
                return;
            }

            // Otherwise, use a 0 opacity alpha layer to clear the animation
            // from the inside out. This layer will prevent the circles from
            // drawing within its bounds.
            long finishElapsed = (now - mFinishTime) % FINISH_ANIMATION_DURATION_MS;
            float finishProgress = (finishElapsed / (FINISH_ANIMATION_DURATION_MS / 100f));
            float pct = (finishProgress / 100f);
            // Radius of the circle is half of the screen.
            float clearRadius = width / 2 * INTERPOLATOR.getInterpolation(pct);
            mClipRect.set(cx - clearRadius, 0, cx + clearRadius, height);
            canvas.saveLayerAlpha(mClipRect, 0, 0);
            // Only draw the trigger if there is a space in the center of
            // this refreshing view that needs to be filled in by the
            // trigger. If the progress view is just still animating, let it
            // continue animating.
            drawTriggerWhileFinishing = true;
        }

        // First fill in with the last color that would have finished drawing.
        if (iterations == 0) {
            canvas.drawColor(mColor1);
        } else {
            if (rawProgress >= 0 && rawProgress < 25) {
                canvas.drawColor(mColor4);
            } else if (rawProgress >= 25 && rawProgress < 50) {
                canvas.drawColor(mColor1);
            } else if (rawProgress >= 50 && rawProgress < 75) {
                canvas.drawColor(mColor2);
            } else {
                canvas.drawColor(mColor3);
            }
        }

        // Then draw up to 4 overlapping concentric circles of varying radii, based on how far
        // along we are in the cycle.
        // progress 0-50 draw mColor2
        // progress 25-75 draw mColor3
        // progress 50-100 draw mColor4
        // progress 75 (wrap to 25) draw mColor1
        if ((rawProgress >= 0 && rawProgress <= 25)) {
            float pct = (((rawProgress + 25) * 2) / 100f);
            drawCircle(canvas, cx, cy, mColor1, pct);
        }
        if (rawProgress >= 0 && rawProgress <= 50) {
            float pct = ((rawProgress * 2) / 100f);
            drawCircle(canvas, cx, cy, mColor2, pct);
        }
        if (rawProgress >= 25 && rawProgress <= 75) {
            float pct = (((rawProgress - 25) * 2) / 100f);
            drawCircle(canvas, cx, cy, mColor3, pct);
        }
        if (rawProgress >= 50 && rawProgress <= 100) {
            float pct = (((rawProgress - 50) * 2) / 100f);
            drawCircle(canvas, cx, cy, mColor4, pct);
        }
        if ((rawProgress >= 75 && rawProgress <= 100)) {
            float pct = (((rawProgress - 75) * 2) / 100f);
            drawCircle(canvas, cx, cy, mColor1, pct);
        }
        if (mTriggerPercentage > 0 && drawTriggerWhileFinishing) {
            // There is some portion of trigger to draw. Restore the canvas,
            // then draw the trigger. Otherwise, the trigger does not appear
            // until after the bar has finished animating and appears to
            // just jump in at a larger width than expected.
            canvas.restoreToCount(restoreCount);
            restoreCount = canvas.save();
            canvas.clipRect(mBounds);
            drawTrigger(canvas, cx, cy);
        }
        // Keep running until we finish out the last cycle.
        ViewCompat.postInvalidateOnAnimation(mParent);
    } else {
        // Otherwise if we're in the middle of a trigger, draw that.
        if (mTriggerPercentage > 0 && mTriggerPercentage <= 1.0) {
            drawTrigger(canvas, cx, cy);
        }
    }
    canvas.restoreToCount(restoreCount);
}

From source file:com.linsq.androiddemo.refresh2.SwipeProgressBar.java

void draw(Canvas canvas) {
    final int width = mBounds.width();
    final int height = mBounds.height();
    final int cx = width / 2;
    final int cy = height / 2;
    boolean drawTriggerWhileFinishing = false;
    int restoreCount = canvas.save();
    canvas.clipRect(mBounds);/*www .j a va  2 s .  co m*/
    if (mRunning || (mFinishTime > 0)) {
        long now = AnimationUtils.currentAnimationTimeMillis();
        long elapsed = (now - mStartTime) % ANIMATION_DURATION_MS;
        long iterations = (now - mStartTime) / ANIMATION_DURATION_MS;
        float rawProgress = (elapsed / (ANIMATION_DURATION_MS / 100f));
        // If we're not running anymore, that means we're running through
        // the finish animation.
        if (!mRunning) {
            // If the finish animation is done, don't draw anything, and
            // don't repost.
            if ((now - mFinishTime) >= FINISH_ANIMATION_DURATION_MS) {
                mFinishTime = 0;
                return;
            }
            // Otherwise, use a 0 opacity alpha layer to clear the animation
            // from the inside out. This layer will prevent the circles from
            // drawing within its bounds.
            long finishElapsed = (now - mFinishTime) % FINISH_ANIMATION_DURATION_MS;
            float finishProgress = (finishElapsed / (FINISH_ANIMATION_DURATION_MS / 100f));
            float pct = (finishProgress / 100f);
            // Radius of the circle is half of the screen.
            float clearRadius = width / 2 * INTERPOLATOR.getInterpolation(pct);
            mClipRect.set(cx - clearRadius, 0, cx + clearRadius, height);
            canvas.saveLayerAlpha(mClipRect, 0, 0);
            // Only draw the trigger if there is a space in the center of
            // this refreshing view that needs to be filled in by the
            // trigger. If the progress view is just still animating, let it
            // continue animating.
            drawTriggerWhileFinishing = true;
        }
        // First fill in with the last color that would have finished
        // drawing.
        if (iterations == 0) {
            canvas.drawColor(mColor1);
        } else {
            if (rawProgress >= 0 && rawProgress < 25) {
                canvas.drawColor(mColor4);
            } else if (rawProgress >= 25 && rawProgress < 50) {
                canvas.drawColor(mColor1);
            } else if (rawProgress >= 50 && rawProgress < 75) {
                canvas.drawColor(mColor2);
            } else {
                canvas.drawColor(mColor3);
            }
        }
        // Then draw up to 4 overlapping concentric circles of varying
        // radii, based on how far
        // along we are in the cycle.
        // progress 0-50 draw mColor2
        // progress 25-75 draw mColor3
        // progress 50-100 draw mColor4
        // progress 75 (wrap to 25) draw mColor1
        if ((rawProgress >= 0 && rawProgress <= 25)) {
            float pct = (((rawProgress + 25) * 2) / 100f);
            drawCircle(canvas, cx, cy, mColor1, pct);
        }
        if (rawProgress >= 0 && rawProgress <= 50) {
            float pct = ((rawProgress * 2) / 100f);
            drawCircle(canvas, cx, cy, mColor2, pct);
        }
        if (rawProgress >= 25 && rawProgress <= 75) {
            float pct = (((rawProgress - 25) * 2) / 100f);
            drawCircle(canvas, cx, cy, mColor3, pct);
        }
        if (rawProgress >= 50 && rawProgress <= 100) {
            float pct = (((rawProgress - 50) * 2) / 100f);
            drawCircle(canvas, cx, cy, mColor4, pct);
        }
        if ((rawProgress >= 75 && rawProgress <= 100)) {
            float pct = (((rawProgress - 75) * 2) / 100f);
            drawCircle(canvas, cx, cy, mColor1, pct);
        }
        if (mTriggerPercentage > 0 && drawTriggerWhileFinishing) {
            // There is some portion of trigger to draw. Restore the canvas,
            // then draw the trigger. Otherwise, the trigger does not appear
            // until after the bar has finished animating and appears to
            // just jump in at a larger width than expected.
            canvas.restoreToCount(restoreCount);
            restoreCount = canvas.save();
            canvas.clipRect(mBounds);
            drawTrigger(canvas, cx, cy);
        }
        // Keep running until we finish out the last cycle.
        ViewCompat.postInvalidateOnAnimation(mParent);
    } else {
        // Otherwise if we're in the middle of a trigger, draw that.
        if (mTriggerPercentage > 0 && mTriggerPercentage <= 1.0) {
            drawTrigger(canvas, cx, cy);
        }
    }
    canvas.restoreToCount(restoreCount);
}

From source file:com.miku.framelite.widget.SwipeProgressBar.java

void draw(Canvas canvas) {
    final int width = mBounds.width();
    final int height = mBounds.height();
    final int cx = width / 2;
    final int cy = mBounds.top + height / 2;
    boolean drawTriggerWhileFinishing = false;
    int restoreCount = canvas.save();
    canvas.clipRect(mBounds);/*from w w  w.j  a va 2  s.c o m*/

    if (mRunning || (mFinishTime > 0)) {
        long now = AnimationUtils.currentAnimationTimeMillis();
        long elapsed = (now - mStartTime) % ANIMATION_DURATION_MS;
        long iterations = (now - mStartTime) / ANIMATION_DURATION_MS;
        float rawProgress = (elapsed / (ANIMATION_DURATION_MS / 100f));

        // If we're not running anymore, that means we're running through
        // the finish animation.
        if (!mRunning) {
            // If the finish animation is done, don't draw anything, and
            // don't repost.
            if ((now - mFinishTime) >= FINISH_ANIMATION_DURATION_MS) {
                mFinishTime = 0;
                return;
            }

            // Otherwise, use a 0 opacity alpha layer to clear the animation
            // from the inside out. This layer will prevent the circles from
            // drawing within its bounds.
            long finishElapsed = (now - mFinishTime) % FINISH_ANIMATION_DURATION_MS;
            float finishProgress = (finishElapsed / (FINISH_ANIMATION_DURATION_MS / 100f));
            float pct = (finishProgress / 100f);
            // Radius of the circle is half of the screen.
            float clearRadius = width / 2 * INTERPOLATOR.getInterpolation(pct);
            mClipRect.set(cx - clearRadius, 0, cx + clearRadius, height);
            canvas.saveLayerAlpha(mClipRect, 0, 0);
            // Only draw the trigger if there is a space in the center of
            // this refreshing view that needs to be filled in by the
            // trigger. If the progress view is just still animating, let it
            // continue animating.
            drawTriggerWhileFinishing = true;
        }

        // First fill in with the last color that would have finished drawing.
        if (iterations == 0) {
            canvas.drawColor(mColor1);
        } else {
            if (rawProgress >= 0 && rawProgress < 25) {
                canvas.drawColor(mColor4);
            } else if (rawProgress >= 25 && rawProgress < 50) {
                canvas.drawColor(mColor1);
            } else if (rawProgress >= 50 && rawProgress < 75) {
                canvas.drawColor(mColor2);
            } else {
                canvas.drawColor(mColor3);
            }
        }

        // Then draw up to 4 overlapping concentric circles of varying radii, based on how far
        // along we are in the cycle.
        // progress 0-50 draw mColor2
        // progress 25-75 draw mColor3
        // progress 50-100 draw mColor4
        // progress 75 (wrap to 25) draw mColor1
        if ((rawProgress >= 0 && rawProgress <= 25)) {
            float pct = (((rawProgress + 25) * 2) / 100f);
            drawCircle(canvas, cx, cy, mColor1, pct);
        }
        if (rawProgress >= 0 && rawProgress <= 50) {
            float pct = ((rawProgress * 2) / 100f);
            drawCircle(canvas, cx, cy, mColor2, pct);
        }
        if (rawProgress >= 25 && rawProgress <= 75) {
            float pct = (((rawProgress - 25) * 2) / 100f);
            drawCircle(canvas, cx, cy, mColor3, pct);
        }
        if (rawProgress >= 50 && rawProgress <= 100) {
            float pct = (((rawProgress - 50) * 2) / 100f);
            drawCircle(canvas, cx, cy, mColor4, pct);
        }
        if ((rawProgress >= 75 && rawProgress <= 100)) {
            float pct = (((rawProgress - 75) * 2) / 100f);
            drawCircle(canvas, cx, cy, mColor1, pct);
        }
        if (mTriggerPercentage > 0 && drawTriggerWhileFinishing) {
            // There is some portion of trigger to draw. Restore the canvas,
            // then draw the trigger. Otherwise, the trigger does not appear
            // until after the bar has finished animating and appears to
            // just jump in at a larger width than expected.
            canvas.restoreToCount(restoreCount);
            restoreCount = canvas.save();
            canvas.clipRect(mBounds);
            drawTrigger(canvas, cx, cy);
        }
        // Keep running until we finish out the last cycle.
        ViewCompat.postInvalidateOnAnimation(mParent);
    } else {
        // Otherwise if we're in the middle of a trigger, draw that.
        if (mTriggerPercentage > 0 && mTriggerPercentage <= 1.0) {
            drawTrigger(canvas, cx, cy);
        }
    }
    canvas.restoreToCount(restoreCount);
}