Example usage for android.graphics Canvas translate

List of usage examples for android.graphics Canvas translate

Introduction

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

Prototype

public void translate(float dx, float dy) 

Source Link

Document

Preconcat the current matrix with the specified translation

Usage

From source file:com.actionbarsherlock.internal.widget.IcsProgressBar.java

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

    Drawable d = mCurrentDrawable;/*from w  ww .  ja  va2 s  . com*/
    if (d != null) {
        // Translate canvas so a indeterminate circular progress bar with padding
        // rotates properly in its animation
        canvas.save();
        canvas.translate(getPaddingLeft() + mIndeterminateRealLeft, getPaddingTop() + mIndeterminateRealTop);
        long time = getDrawingTime();
        if (mAnimation != null) {
            mAnimation.getTransformation(time, mTransformation);
            float scale = mTransformation.getAlpha();
            try {
                mInDrawing = true;
                d.setLevel((int) (scale * MAX_LEVEL));
            } finally {
                mInDrawing = false;
            }
            if (SystemClock.uptimeMillis() - mLastDrawTime >= mAnimationResolution) {
                mLastDrawTime = SystemClock.uptimeMillis();
                postInvalidateDelayed(mAnimationResolution);
            }
        }
        d.draw(canvas);
        canvas.restore();
        if (mShouldStartAnimationDrawable && d instanceof Animatable) {
            ((Animatable) d).start();
            mShouldStartAnimationDrawable = false;
        }
    }
}

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

public void drawIndex(Canvas canvas) {
    //canvas.restore();
    Paint paint = this.mPaint;
    paint.setTypeface(Typeface.DEFAULT_BOLD);
    paint.setAntiAlias(true);// w w w . jav  a 2s.c  o m
    if (quoteData != null) {
        try {
            JSONArray jArr = quoteData.getJSONArray("data");
            JSONObject jo = jArr.getJSONObject(0);
            double zrsp = jo.getDouble("zrsp");

            double zjcj = jo.getDouble("zjcj");
            paint.setTextSize(mTextSize * 2);
            setColor(paint, zjcj, zrsp);
            paint.setTextAlign(Paint.Align.LEFT);
            canvas.translate(DX * 0.5f, DY * 2f);
            canvas.drawText(Utils.dataFormation(zjcj, stockdigit), x, y, paint);

            paint.setStyle(Paint.Style.STROKE);
            paint.setTextSize(mTextSize);

            double zhangd = jo.getDouble("zd");
            if (zhangd < 0) {
                paint.setColor(GlobalColor.colorPriceDown);
            } else if (zhangd > 0) {
                paint.setColor(GlobalColor.colorpriceUp);
            } else {
                paint.setColor(GlobalColor.colorPriceEqual);
            }
            canvas.translate(0, DY * 0.8f);
            String zhangdie = Utils.dataFormation(zhangd, stockdigit);
            if (zhangdie.equals("-"))
                canvas.drawText("", x, y, paint);
            else
                canvas.drawText(zhangdie, x, y, paint);

            double zhangf = jo.getDouble("zf");
            if (zhangf < 0) {
                paint.setColor(GlobalColor.colorPriceDown);
            } else if (zhangf > 0) {
                paint.setColor(GlobalColor.colorpriceUp);
            } else {
                paint.setColor(GlobalColor.colorPriceEqual);
            }
            canvas.translate(DX * 3.5f, 0);
            String zhangfu = Utils.dataFormation(zhangf * 100, stockdigit);
            if (zhangfu.equals("-"))
                canvas.drawText("", x, y, paint);
            else
                canvas.drawText(zhangfu + "%", x, y, paint);

            paint.setColor(GlobalColor.colorLabelName);
            canvas.translate(-DX * 3.5f, DY * 1.2f);
            //canvas.translate(-DX*0.5f, DY*2f);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("??", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("??", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);

            paint.setColor(GlobalColor.colorLabelName);
            paint.setTextAlign(Paint.Align.LEFT);
            canvas.translate(width / 2 - DX, -DY * 7);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);

            paint.setTextAlign(Paint.Align.RIGHT);
            paint.setColor(GlobalColor.colorLabelName);
            canvas.translate(0, 0);
            canvas.drawText(Utils.dataFormation(zrsp, stockdigit), x, y, paint);

            canvas.translate(width / 2, -DY * 3);
            paint.setTextAlign(Paint.Align.RIGHT);

            double jrkp = jo.getDouble("jrkp");
            setColor(paint, jrkp, zrsp);
            canvas.drawText(Utils.dataFormation(jrkp, stockdigit), x, y, paint);

            canvas.translate(0, DY);
            double zg = jo.getDouble("zgcj");
            setColor(paint, zg, zrsp);
            canvas.drawText(Utils.dataFormation(zg, stockdigit), x, y, paint);

            canvas.translate(0, DY);
            double zd = jo.getDouble("zdcj");
            setColor(paint, zd, zrsp);
            canvas.drawText(Utils.dataFormation(zd, stockdigit), x, y, paint);

            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            double amp = jo.getDouble("amp");
            if (amp == 0)
                canvas.drawText("", x, y, paint);
            else
                canvas.drawText(Utils.dataFormation(jo.getDouble("amp") * 100, 1) + "%", x, y, paint);

            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjsl"), true), x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjje"), true), x, y, paint);

            canvas.translate(0, DY);
            paint.setColor(GlobalColor.colorpriceUp);
            canvas.drawText(String.valueOf(jo.getInt("zj")), x, y, paint);
            canvas.translate(0, DY);
            paint.setColor(GlobalColor.colorPriceDown);
            canvas.drawText(String.valueOf(jo.getInt("dj")), x, y, paint);

        } catch (JSONException e) {
            Log.e(TAG, e.toString());
        }
    } else {//?????
        paint.setTextAlign(Paint.Align.LEFT);
        paint.setColor(GlobalColor.colorLabelName);

        canvas.translate(DX, DY * 2f);
        canvas.drawText("-", x, y, paint);

        paint.setStyle(Paint.Style.STROKE);
        paint.setTextSize(mTextSize);

        canvas.translate(-DX / 2, DY * 0.8f);
        canvas.drawText("-", x, y, paint);

        canvas.translate(DX * 2.5f, 0);
        canvas.drawText("-", x, y, paint);
        canvas.translate(-DX * 2.5f, DY * 1.2f);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("??", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("??", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);

        paint.setTextAlign(Paint.Align.LEFT);
        canvas.translate(width / 2 - DX, -DY * 7);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
    }
}

From source file:com.mylikes.likes.etchasketch.Slate.java

@Override
protected void onDraw(Canvas canvas) {
    if (mTiledCanvas != null) {
        canvas.save(Canvas.MATRIX_SAVE_FLAG);

        if (mPanX != 0 || mPanY != 0 || !mZoomMatrix.isIdentity()) {
            canvas.translate(mPanX, mPanY);
            canvas.concat(mZoomMatrix);/*from w ww.  jav a2s .  co  m*/

            canvas.drawRect(-20000, -20000, 20000, 0, mWorkspacePaint);
            canvas.drawRect(-20000, 0, 0, mTiledCanvas.getHeight(), mWorkspacePaint);
            canvas.drawRect(mTiledCanvas.getWidth(), 0, 20000, mTiledCanvas.getHeight(), mWorkspacePaint);
            canvas.drawRect(-20000, mTiledCanvas.getHeight(), 20000, 20000, mWorkspacePaint);
        }

        if (!mDirtyRegion.isEmpty()) {
            canvas.clipRegion(mDirtyRegion);
            mDirtyRegion.setEmpty();
        }
        // TODO: tune this threshold based on the device density
        mBlitPaint.setFilterBitmap(getScale(mZoomMatrix) < 3f);
        mTiledCanvas.drawTo(canvas, 0, 0, mBlitPaint, false); // @@ set to true for dirty tile updates
        if (0 != (mDebugFlags & FLAG_DEBUG_STROKES)) {
            drawStrokeDebugInfo(canvas);
        }
        for (MoveableDrawing drawing : overlays) {
            drawing.renderInto(canvas, moveMode && drawing == selectedDrawing);
        }

        canvas.restore();

        if (0 != (mDebugFlags & FLAG_DEBUG_PRESSURE)) {
            mPressureCooker.drawDebug(canvas);
        }
    }
}

From source file:com.lab47billion.appchooser.HorizontalPicker.java

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

    int saveCount = canvas.getSaveCount();
    canvas.save();/*from ww w  .  ja  v  a2s . c o m*/

    int selectedItem = mSelectedItem;

    float itemWithPadding = mItemWidth + mDividerSize;

    // translate horizontal to center
    canvas.translate(itemWithPadding * mSideItems, 0);

    if (mValues != null) {
        for (int i = 0; i < mValues.length; i++) {

            mTextPaint.setColor(getTextColor(i));

            // get text layout
            View layout = mLayouts[i][0];
            //                layout.draw(canvas);
            //NEW
            View layoutSub = mLayouts[i][1];
            int saveCountHeight = canvas.getSaveCount();
            canvas.save();

            float x = 0;
            float lineWidth = 40f;
            if (lineWidth > mItemWidth) {
                if (isRtl(mValues[i])) {
                    x += (lineWidth - mItemWidth) / 2;
                } else {
                    x -= (lineWidth - mItemWidth) / 2;
                }
            }

            /*set select item top padding */
            int yTranslate;
            if (!isScrollingStart && i == selectedItem) {
                mTextPaint.setTextSize(mSelectedTextSize);
            } else {
                mTextPaint.setTextSize(mNormalTextSize);
            }

            // translate vertically to center
            if (layoutSub != null) {
                yTranslate = (canvas.getHeight() - (layout.getHeight() + layoutSub.getHeight())) / 2;
            } else {
                yTranslate = (canvas.getHeight() - layout.getHeight()) / 2;
            }

            if (i == selectedItem && topPadding != -1) {
                yTranslate = topPadding;
            }

            canvas.translate(-x, yTranslate);

            RectF clipBounds;
            if (x == 0) {
                clipBounds = mItemClipBounds;
            } else {
                clipBounds = mItemClipBoundsOffser;
                clipBounds.set(mItemClipBounds);
                clipBounds.offset(x, 0);
            }
            canvas.clipRect(clipBounds);
            layout.draw(canvas);

            if (layoutSub != null) {
                Paint.FontMetrics fontMetrics = mTextPaint.getFontMetrics();
                int heightText = (int) (Math.abs(fontMetrics.ascent) + Math.abs(fontMetrics.descent));
                canvas.translate(-x, (layout.getHeight() + heightText - getTopPadding()) / 2);
                canvas.clipRect(clipBounds);
                layoutSub.draw(canvas);
            }

            // restore vertical translation
            canvas.restoreToCount(saveCountHeight);

            // translate horizontal for 1 item
            canvas.translate(itemWithPadding, 0);
        }
    }

    // restore horizontal translation
    canvas.restoreToCount(saveCount);

    drawEdgeEffect(canvas, mLeftEdgeEffect, 270);
    drawEdgeEffect(canvas, mRightEdgeEffect, 90);
}

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

public void drawQihuo(Canvas canvas) {
    //canvas.restore();
    Paint paint = this.mPaint;
    paint.setTypeface(Typeface.DEFAULT_BOLD);
    paint.setAntiAlias(true);/*from  w  ww . j  a v a  2  s .  c  o  m*/
    if (quoteData != null) {
        try {
            JSONArray jArr = quoteData.getJSONArray("data");
            JSONObject jo = jArr.getJSONObject(0);
            String str = "";
            double zrsp = jo.getDouble("zrsp");

            double zjcj = jo.getDouble("zjcj");
            paint.setTextSize(mTextSize * 2);
            setColor(paint, zjcj, zrsp);
            paint.setTextAlign(Paint.Align.LEFT);
            canvas.translate(DX, DY * 2f);
            canvas.drawText(Utils.dataFormation(zjcj, stockdigit), x, y, paint);

            paint.setStyle(Paint.Style.STROKE);
            paint.setTextSize(mTextSize);

            double zhangd = jo.getDouble("zd");
            if (zhangd < 0) {
                paint.setColor(GlobalColor.colorPriceDown);
            } else if (zhangd > 0) {
                paint.setColor(GlobalColor.colorpriceUp);
            } else {
                paint.setColor(GlobalColor.colorPriceEqual);
            }
            canvas.translate(-DX / 2, DY * 0.8f);
            String zhangdie = Utils.dataFormation(zhangd, stockdigit, jo.getInt("tp"));
            if (zhangdie.equals("-"))
                canvas.drawText("", x, y, paint);
            else
                canvas.drawText(zhangdie, x, y, paint);

            double zhangf = jo.getDouble("zf");
            if (zhangf < 0) {
                paint.setColor(GlobalColor.colorPriceDown);
            } else if (zhangf > 0) {
                paint.setColor(GlobalColor.colorpriceUp);
            } else {
                paint.setColor(GlobalColor.colorPriceEqual);
            }
            canvas.translate(DX * 2.5f, 0);
            String zhangfu = Utils.dataFormation(zhangf * 100, 1);
            if (zhangfu.equals("-") || zhangfu.equals(""))
                canvas.drawText("", x, y, paint);
            else
                canvas.drawText(zhangfu + "%", x, y, paint);

            paint.setColor(GlobalColor.colorLabelName);

            canvas.translate(-DX * 3, DY * 1.2f);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText(" ", x, y, paint);

            canvas.translate(width / 2, -DY * 2);
            paint.setTextAlign(Paint.Align.RIGHT);
            double temp2 = jo.getDouble("sjw1");
            setColor(paint, temp2, zrsp);
            str = Utils.dataFormation(temp2, stockdigit, jo.getInt("tp"));
            canvas.drawText(str, x - tips, y, paint);

            canvas.translate(0, DY);
            temp2 = jo.getDouble("bjw1");
            setColor(paint, temp2, zrsp);
            str = Utils.dataFormation(temp2, stockdigit, jo.getInt("tp"));
            canvas.drawText(str, x - tips, y, paint);

            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(jo.getDouble("jrkc"), 0, jo.getInt("tp")), x - tips, y, paint);

            paint.setColor(GlobalColor.colorLabelName);
            paint.setTextAlign(Paint.Align.LEFT);
            canvas.translate(0, -DY * 5);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("??", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText(" ", x, y, paint);

            paint.setTextAlign(Paint.Align.RIGHT);
            canvas.translate(width / 2, -DY * 5);
            double jrkp = jo.getDouble("jrkp");
            setColor(paint, jrkp, zrsp);
            canvas.drawText(Utils.dataFormation(jrkp, stockdigit, jo.getInt("tp")), x - tips, y, paint);

            canvas.translate(0, DY);
            double zg = jo.getDouble("zgcj");
            setColor(paint, zg, zrsp);
            canvas.drawText(Utils.dataFormation(zg, stockdigit, jo.getInt("tp")), x - tips, y, paint);

            canvas.translate(0, DY);
            double zd = jo.getDouble("zdcj");
            setColor(paint, zd, zrsp);
            canvas.drawText(Utils.dataFormation(zd, stockdigit, jo.getInt("tp")), x - tips, y, paint);

            canvas.translate(0, DY);
            paint.setColor(GlobalColor.colorStockName);
            canvas.drawText(Utils.getAmountFormat(jo.getInt("ssl1"), false), x - tips, y, paint);

            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getInt("bsl1"), false), x - tips, y, paint);

            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(jo.getDouble("jrpc"), 0, jo.getInt("tp")), x - tips, y, paint);
        } catch (JSONException e) {
            Log.e(TAG, e.toString());
        }
    } else {//?????
        paint.setTextAlign(Paint.Align.LEFT);
        paint.setColor(GlobalColor.colorLabelName);

        canvas.translate(DX, DY * 2f);
        canvas.drawText("-", x, y, paint);

        paint.setStyle(Paint.Style.STROKE);
        paint.setTextSize(mTextSize);

        canvas.translate(-DX / 2, DY * 0.8f);
        canvas.drawText("-", x, y, paint);

        canvas.translate(DX * 2.5f, 0);
        canvas.drawText("-", x, y, paint);
        canvas.translate(-DX * 3, DY * 1.2f);
        canvas.drawText("?", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText(" ", x, y, paint);

        paint.setTextAlign(Paint.Align.LEFT);
        canvas.translate(width / 2, -DY * 5);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("??", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("?", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText(" ", x, y, paint);
    }
}

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

public void drawPrice(Canvas canvas) {
    //canvas.restore();
    Paint paint = this.mPaint;
    paint.setTypeface(Typeface.DEFAULT_BOLD);
    paint.setAntiAlias(true);/*ww w.  ja  v a2 s. c om*/
    if (quoteData != null) {
        try {
            JSONArray jArr = quoteData.getJSONArray("data");
            JSONObject jo = jArr.getJSONObject(0);
            String str = "";
            double zrsp = jo.getDouble("zrsp");

            double zjcj = jo.getDouble("zjcj");
            paint.setTextSize(mTextSize * 2);
            setColor(paint, zjcj, zrsp);
            paint.setTextAlign(Paint.Align.LEFT);
            canvas.translate(DX, DY * 2f);
            canvas.drawText(Utils.dataFormation(zjcj, stockdigit), x, y, paint);

            paint.setStyle(Paint.Style.STROKE);
            paint.setTextSize(mTextSize);

            double zhangd = jo.getDouble("zd");
            if (zhangd < 0) {
                paint.setColor(GlobalColor.colorPriceDown);
            } else if (zhangd > 0) {
                paint.setColor(GlobalColor.colorpriceUp);
            } else {
                paint.setColor(GlobalColor.colorPriceEqual);
            }
            canvas.translate(-DX / 2, DY * 0.8f);
            String zhangdie = Utils.dataFormation(zhangd, stockdigit, jo.getInt("tp"));
            if (zhangdie.equals("-"))
                canvas.drawText("", x, y, paint);
            else
                canvas.drawText(zhangdie, x, y, paint);

            double zhangf = jo.getDouble("zf");
            if (zhangf < 0) {
                paint.setColor(GlobalColor.colorPriceDown);
            } else if (zhangf > 0) {
                paint.setColor(GlobalColor.colorpriceUp);
            } else {
                paint.setColor(GlobalColor.colorPriceEqual);
            }
            canvas.translate(DX * 2.5f, 0);
            //String zhangfu = Utils.dataFormation(zhangf*100, stockdigit);
            //?????2?
            String zhangfu = Utils.dataFormation(zhangf * 100, 1, jo.getInt("tp"));
            if (zhangfu.equals("-") || zhangfu.equals(""))
                canvas.drawText("", x, y, paint);
            else
                canvas.drawText(zhangfu + "%", x, y, paint);

            paint.setColor(GlobalColor.colorLabelName);
            canvas.translate(-DX * 3, DY * 1.2f);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);

            canvas.translate(DX * 2, -DY * 4);
            for (int i = 1; i <= 5; i++) {
                double temp2 = jo.getDouble("sjw" + i);
                setColor(paint, temp2, zrsp);
                str = Utils.dataFormation(temp2, stockdigit, jo.getInt("tp"));
                canvas.drawText(str, x, y, paint);
                if (i != 5)
                    canvas.translate(0, DY);
            }

            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(width / 2 - DX * 2, -DY * 4);
            for (int i = 1; i <= 5; i++) {
                paint.setTextAlign(Paint.Align.RIGHT);
                canvas.drawText(Utils.getAmountFormat(jo.getInt("ssl" + i), false), x - tips, y, paint);
                if (i != 5)
                    canvas.translate(0, DY);
            }

            paint.setColor(GlobalColor.colorLabelName);
            paint.setTextAlign(Paint.Align.LEFT);
            canvas.translate(0, -DY * 7);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);

            //paint.setTextAlign(Paint.Align.CENTER);
            canvas.translate(DX * 2, -DY * 7);
            double jrkp = jo.getDouble("jrkp");
            setColor(paint, jrkp, zrsp);
            canvas.drawText(Utils.dataFormation(jrkp, stockdigit, jo.getInt("tp")), x, y, paint);

            canvas.translate(0, DY);
            double zg = jo.getDouble("zgcj");
            setColor(paint, zg, zrsp);
            canvas.drawText(Utils.dataFormation(zg, stockdigit, jo.getInt("tp")), x, y, paint);

            canvas.translate(0, DY);
            double zd = jo.getDouble("zdcj");
            setColor(paint, zd, zrsp);
            canvas.drawText(Utils.dataFormation(zd, stockdigit, jo.getInt("tp")), x, y, paint);

            canvas.translate(0, DY);
            for (int i = 1; i <= 5; i++) {
                double temp2 = jo.getDouble("bjw" + i);
                setColor(paint, temp2, zrsp);
                str = Utils.dataFormation(temp2, stockdigit, jo.getInt("tp"));
                canvas.drawText(str, x, y, paint);
                if (i != 5)
                    canvas.translate(0, DY);
            }

            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(width / 2 - DX * 2, -DY * 4);
            for (int i = 1; i <= 5; i++) {
                paint.setTextAlign(Paint.Align.RIGHT);
                canvas.drawText(Utils.getAmountFormat(jo.getInt("bsl" + i), false), x - tips, y, paint);
                if (i != 5)
                    canvas.translate(0, DY);
            }
        } catch (JSONException e) {
            Log.e(TAG, e.toString());
        }
    } else {//?????
        paint.setTextAlign(Paint.Align.LEFT);
        paint.setColor(GlobalColor.colorLabelName);

        canvas.translate(DX, DY * 2f);
        canvas.drawText("-", x, y, paint);

        paint.setStyle(Paint.Style.STROKE);
        paint.setTextSize(mTextSize);

        canvas.translate(-DX / 2, DY * 0.8f);
        canvas.drawText("-", x, y, paint);

        canvas.translate(DX * 2.5f, 0);
        canvas.drawText("-", x, y, paint);
        canvas.translate(-DX * 3, DY * 1.2f);
        canvas.drawText("?", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("?", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("?", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("?", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("?", x, y, paint);

        paint.setTextAlign(Paint.Align.LEFT);
        canvas.translate(width / 2, -DY * 7);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
    }
}

From source file:com.bitflake.counter.HorizontalPicker.java

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

    int saveCount = canvas.getSaveCount();
    canvas.save();/*from www .jav  a2  s.  c o  m*/

    int selectedItem = this.selectedItem;

    float itemWithPadding = itemWidth + dividerSize;

    // translate horizontal to center
    canvas.translate(itemWithPadding * sideItems, 0);

    if (values != null) {
        for (int i = 0; i < values.length; i++) {

            // set text color for item
            textPaint.setColor(getTextColor(i));

            // get text layout
            BoringLayout layout = layouts[i];

            int saveCountHeight = canvas.getSaveCount();
            canvas.save();

            float x = 0;

            float lineWidth = layout.getLineWidth(0);
            if (lineWidth > itemWidth) {
                if (isRtl(values[i])) {
                    x += (lineWidth - itemWidth) / 2;
                } else {
                    x -= (lineWidth - itemWidth) / 2;
                }
            }

            if (marquee != null && i == selectedItem) {
                x += marquee.getScroll();
            }

            // translate vertically to center
            canvas.translate(-x, (canvas.getHeight() - layout.getHeight()) / 2);

            RectF clipBounds;
            if (x == 0) {
                clipBounds = itemClipBounds;
            } else {
                clipBounds = itemClipBoundsOffset;
                clipBounds.set(itemClipBounds);
                clipBounds.offset(x, 0);
            }

            canvas.clipRect(clipBounds);
            layout.draw(canvas);

            if (marquee != null && i == selectedItem && marquee.shouldDrawGhost()) {
                canvas.translate(marquee.getGhostOffset(), 0);
                layout.draw(canvas);
            }

            // restore vertical translation
            canvas.restoreToCount(saveCountHeight);

            // translate horizontal for 1 item
            canvas.translate(itemWithPadding, 0);
        }
    }

    // restore horizontal translation
    canvas.restoreToCount(saveCount);

    drawEdgeEffect(canvas, leftEdgeEffect, 270);
    drawEdgeEffect(canvas, rightEdgeEffect, 90);
}

From source file:kr.selfcontrol.selflocklauncher.picker.HorizontalPicker.java

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

    int saveCount = canvas.getSaveCount();
    canvas.save();/*w  ww . j  a  v  a  2  s.  c o  m*/

    int selectedItem = mSelectedItem;

    float itemWithPadding = mItemWidth + mDividerSize;

    // translate horizontal to center
    canvas.translate(itemWithPadding * mSideItems, 0);

    if (mValues != null) {
        for (int i = 0; i < mValues.length; i++) {

            // set text color for item
            mTextPaint.setColor(getTextColor(i));

            // get text layout
            BoringLayout layout = mLayouts[i];

            int saveCountHeight = canvas.getSaveCount();
            canvas.save();

            float x = 0;

            float lineWidth = layout.getLineWidth(0);
            if (lineWidth > mItemWidth) {
                if (isRtl(mValues[i])) {
                    x += (lineWidth - mItemWidth) / 2;
                } else {
                    x -= (lineWidth - mItemWidth) / 2;
                }
            }

            if (mMarquee != null && i == selectedItem) {
                x += mMarquee.getScroll();
            }

            // translate vertically to center
            canvas.translate(-x, (canvas.getHeight() - layout.getHeight()) / 2);

            RectF clipBounds;
            if (x == 0) {
                clipBounds = mItemClipBounds;
            } else {
                clipBounds = mItemClipBoundsOffser;
                clipBounds.set(mItemClipBounds);
                clipBounds.offset(x, 0);
            }

            canvas.clipRect(clipBounds);
            layout.draw(canvas);

            if (mMarquee != null && i == selectedItem && mMarquee.shouldDrawGhost()) {
                canvas.translate(mMarquee.getGhostOffset(), 0);
                layout.draw(canvas);
            }

            // restore vertical translation
            canvas.restoreToCount(saveCountHeight);

            // translate horizontal for 1 item
            canvas.translate(itemWithPadding, 0);
        }
    }

    // restore horizontal translation
    canvas.restoreToCount(saveCount);

    drawEdgeEffect(canvas, mLeftEdgeEffect, 270);
    drawEdgeEffect(canvas, mRightEdgeEffect, 90);
}

From source file:com.jjoe64.graphview.Viewport.java

/**
 * Draws the overscroll "glow" at the four edges of the chart region, if necessary.
 *
 * @see EdgeEffectCompat/*from   www  . j  a v a2  s  .c  o m*/
 */
private void drawEdgeEffectsUnclipped(Canvas canvas) {
    // The methods below rotate and translate the canvas as needed before drawing the glow,
    // since EdgeEffectCompat always draws a top-glow at 0,0.

    boolean needsInvalidate = false;

    if (!mEdgeEffectTop.isFinished()) {
        final int restoreCount = canvas.save();
        canvas.translate(mGraphView.getGraphContentLeft(), mGraphView.getGraphContentTop());
        mEdgeEffectTop.setSize(mGraphView.getGraphContentWidth(), mGraphView.getGraphContentHeight());
        if (mEdgeEffectTop.draw(canvas)) {
            needsInvalidate = true;
        }
        canvas.restoreToCount(restoreCount);
    }

    if (!mEdgeEffectBottom.isFinished()) {
        final int restoreCount = canvas.save();
        canvas.translate(mGraphView.getGraphContentLeft(),
                mGraphView.getGraphContentTop() + mGraphView.getGraphContentHeight());
        canvas.rotate(180, mGraphView.getGraphContentWidth() / 2, 0);
        mEdgeEffectBottom.setSize(mGraphView.getGraphContentWidth(), mGraphView.getGraphContentHeight());
        if (mEdgeEffectBottom.draw(canvas)) {
            needsInvalidate = true;
        }
        canvas.restoreToCount(restoreCount);
    }

    if (!mEdgeEffectLeft.isFinished()) {
        final int restoreCount = canvas.save();
        canvas.translate(mGraphView.getGraphContentLeft(),
                mGraphView.getGraphContentTop() + mGraphView.getGraphContentHeight());
        canvas.rotate(-90, 0, 0);
        mEdgeEffectLeft.setSize(mGraphView.getGraphContentHeight(), mGraphView.getGraphContentWidth());
        if (mEdgeEffectLeft.draw(canvas)) {
            needsInvalidate = true;
        }
        canvas.restoreToCount(restoreCount);
    }

    if (!mEdgeEffectRight.isFinished()) {
        final int restoreCount = canvas.save();
        canvas.translate(mGraphView.getGraphContentLeft() + mGraphView.getGraphContentWidth(),
                mGraphView.getGraphContentTop());
        canvas.rotate(90, 0, 0);
        mEdgeEffectRight.setSize(mGraphView.getGraphContentHeight(), mGraphView.getGraphContentWidth());
        if (mEdgeEffectRight.draw(canvas)) {
            needsInvalidate = true;
        }
        canvas.restoreToCount(restoreCount);
    }

    if (needsInvalidate) {
        ViewCompat.postInvalidateOnAnimation(mGraphView);
    }
}

From source file:com.achep.acdisplay.ui.widgets.CircleView.java

@Override
protected void onDraw(Canvas canvas) {
    final float ratio = calculateRatio();

    // Draw all corners
    drawCornerIcon(canvas, mDrawableLeftTopCorner, 0, 0 /* left top */);
    drawCornerIcon(canvas, mDrawableRightTopCorner, 1, 0 /* right top */);
    drawCornerIcon(canvas, mDrawableLeftBottomCorner, 0, 1 /* left bottom */);
    drawCornerIcon(canvas, mDrawableRightBottomCorner, 1, 1 /* right bottom */);

    // Darkening background
    int alpha = (int) (mDarkening * 255);
    alpha += (int) ((255 - alpha) * ratio * 0.7f); // Change alpha dynamically
    canvas.drawColor(/*from ww w  .  j  av  a2s  . co m*/
            Color.argb(alpha, Color.red(mOuterColor), Color.green(mOuterColor), Color.blue(mOuterColor)));

    // Draw unlock circle
    mPaint.setColor(mInnerColor);
    mPaint.setAlpha((int) (255 * Math.pow(ratio, 1f / 3f)));
    canvas.drawCircle(mPoint[0], mPoint[1], mRadiusDrawn, mPaint);

    if (ratio >= 0.5f) {
        // Draw unlock icon at the center of circle
        float scale = 0.5f + 0.5f * ratio;
        canvas.save();
        canvas.translate(mPoint[0] - mDrawable.getMinimumWidth() / 2 * scale,
                mPoint[1] - mDrawable.getMinimumHeight() / 2 * scale);
        canvas.scale(scale, scale);
        mDrawable.draw(canvas);
        canvas.restore();
    }
}