Example usage for android.graphics Canvas drawText

List of usage examples for android.graphics Canvas drawText

Introduction

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

Prototype

public void drawText(@NonNull String text, float x, float y, @NonNull Paint paint) 

Source Link

Document

Draw the text, with origin at (x,y), using the specified paint.

Usage

From source file:com.fanfou.app.opensource.ui.viewpager.TitlePageIndicator.java

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

    // Calculate views bounds
    final ArrayList<RectF> bounds = calculateAllBounds(this.mPaintText);

    final int count = getPageCount();
    final int countMinusOne = count - 1;
    final float halfWidth = getWidth() / 2f;
    final int left = getLeft();
    final float leftClip = left + this.mClipPadding;
    final int width = getWidth();
    final int height = getHeight();
    final int right = left + width;
    final float rightClip = right - this.mClipPadding;
    final float offsetPercent = (1.0f * this.mCurrentOffset) / width;

    int page = this.mCurrentPage;
    if (this.mCurrentOffset > halfWidth) {
        page++;//  w  ww .  j  a v a  2  s.co m
    }
    final boolean currentSelected = (offsetPercent <= TitlePageIndicator.SELECTION_FADE_PERCENTAGE);
    final boolean currentBold = (offsetPercent <= TitlePageIndicator.BOLD_FADE_PERCENTAGE);
    final float selectedPercent = (TitlePageIndicator.SELECTION_FADE_PERCENTAGE - offsetPercent)
            / TitlePageIndicator.SELECTION_FADE_PERCENTAGE;

    // Verify if the current view must be clipped to the screen
    final RectF curPageBound = bounds.get(this.mCurrentPage);

    // fix null pointer exception
    if (curPageBound != null) {
        final float curPageWidth = curPageBound.right - curPageBound.left;
        if (curPageBound.left < leftClip) {
            // Try to clip to the screen (left side)
            clipViewOnTheLeft(curPageBound, curPageWidth, left);
        }
        if (curPageBound.right > rightClip) {
            // Try to clip to the screen (right side)
            clipViewOnTheRight(curPageBound, curPageWidth, right);
        }
    }

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

    // if(App.DEBUG){
    // Log.e(TAG,
    // "===============================================================");
    // Log.e(TAG, "onDraw() mCurrentPage="+mCurrentPage);
    // Log.e(TAG, "onDraw() ");
    // Log.e(TAG, "onDraw() ");
    // Log.e(TAG, "onDraw() ");
    // Log.e(TAG, "onDraw() ");
    // Log.e(TAG, "onDraw() ");
    // Log.e(TAG,
    // "===============================================================");
    // }

    // Now draw views
    for (int i = 0; i < count; i++) {
        // Get the title
        final RectF bound = bounds.get(i);
        // Only if one side is visible
        if (((bound.left > left) && (bound.left < right)) || ((bound.right > left) && (bound.right < right))) {
            final boolean currentPage = (i == page);
            // Only set bold if we are within bounds
            this.mPaintText.setFakeBoldText(currentPage && currentBold && this.mBoldText);

            // Draw text as unselected
            this.mPaintText.setColor(this.mColorText);
            canvas.drawText(this.mTitleProvider.getTitle(i), bound.left, bound.bottom, this.mPaintText);

            // If we are within the selected bounds draw the selected text
            if (currentPage && currentSelected) {
                this.mPaintText.setColor(this.mColorSelected);
                this.mPaintText.setAlpha((int) ((this.mColorSelected >>> 24) * selectedPercent));
                canvas.drawText(this.mTitleProvider.getTitle(i), bound.left, bound.bottom, this.mPaintText);
            }
        }
    }

    // Draw the footer line
    // mPath = new Path();
    this.mPath.reset();
    this.mPath.moveTo(0, height - this.mFooterLineHeight);
    this.mPath.lineTo(width, height - this.mFooterLineHeight);
    this.mPath.close();
    canvas.drawPath(this.mPath, this.mPaintFooterLine);

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

    case Underline:
        if (!currentSelected) {
            break;
        }

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

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

From source file:com.alibaba.akita.widget.TitlePageIndicator.java

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

    if (mViewPager == null) {
        return;/*  w ww .j a v a2s .co  m*/
    }
    final int count = mViewPager.getAdapter().getCount();
    if (count == 0) {
        return;
    }

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

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

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

    int page = mCurrentPage;
    float offsetPercent;
    if (mCurrentOffset <= halfWidth) {
        offsetPercent = 1.0f * mCurrentOffset / width;
    } else {
        page += 1;
        offsetPercent = 1.0f * (width - mCurrentOffset) / width;
    }
    final boolean currentSelected = (offsetPercent <= SELECTION_FADE_PERCENTAGE);
    final boolean currentBold = (offsetPercent <= BOLD_FADE_PERCENTAGE);
    final float selectedPercent = (SELECTION_FADE_PERCENTAGE - offsetPercent) / SELECTION_FADE_PERCENTAGE;

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

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

    //Now draw views
    int colorTextAlpha = mColorText >>> 24;
    for (int i = 0; i < count; i++) {
        //Get the title
        RectF bound = bounds.get(i);
        //Only if one side is visible
        if ((bound.left > left && bound.left < right) || (bound.right > left && bound.right < right)) {
            final boolean currentPage = (i == page);
            //Only set bold if we are within bounds
            mPaintText.setFakeBoldText(currentPage && currentBold && mBoldText);

            //Draw text as unselected
            mPaintText.setColor(mColorText);
            if (currentPage && currentSelected) {
                //Fade out/in unselected text as the selected text fades in/out
                mPaintText.setAlpha(colorTextAlpha - (int) (colorTextAlpha * selectedPercent));
            }
            canvas.drawText(mTitleProvider.getTitle(i), bound.left, bound.bottom + mTopPadding, mPaintText);

            //If we are within the selected bounds draw the selected text
            if (currentPage && currentSelected) {
                mPaintText.setColor(mColorSelected);
                mPaintText.setAlpha((int) ((mColorSelected >>> 24) * selectedPercent));
                canvas.drawText(mTitleProvider.getTitle(i), bound.left, bound.bottom + mTopPadding, mPaintText);
            }
        }
    }

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

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

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

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

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

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

public void drawBIAS(Canvas canvas, JSONObject quoteData, int begin, int count, double shapeWidth,
        double spaceWidth, double highPrice, double lowPrice, double highVolume, int actualDataLen)
        throws JSONException {
    if (quoteData.isNull("BIAS") || quoteData.getJSONArray("BIAS").length() < 1) {
        isNetworkErrorDisplay();//from   ww w  .j  a v a 2 s.  c  o m
        return;
    }
    double max = 0.001;
    double min = -0.001;

    int len = quoteData.getJSONArray("BIAS").length();
    for (int i = begin; i < (begin + count) && i < len; i++) {
        double bias1 = quoteData.getJSONArray("BIAS").getJSONArray(i).getDouble(1);
        double bias2 = quoteData.getJSONArray("BIAS").getJSONArray(i).getDouble(2);
        double bias3 = quoteData.getJSONArray("BIAS").getJSONArray(i).getDouble(3);

        if (bias1 > max)
            max = bias1;
        if (bias2 > max)
            max = bias2;
        if (bias3 > max)
            max = bias3;

        if (bias1 < 0) {
            if (bias1 < min)
                min = bias1;
        }
        if (bias2 < 0) {
            if (bias2 < min)
                min = bias2;
        }
        if (bias3 < 0) {
            if (bias3 < min)
                min = bias3;
        }
    }

    max = max + (max - min) * 0.1;
    min = min - (max - min) * 0.1;

    //double scale = this.volumeHeight / (max + Math.abs(min)) / 1.2;
    double scale = this.volumeHeight / (max - min);
    double lbl1value = max - (max - min) / 3;
    double lbl2value = max - (max - min) * 2 / 3;

    int startX = klineX;
    int startY = klineY;

    int axisY10 = (int) (startY + volumeHeight - (max - min) * scale);

    paint.setColor(GlobalColor.clrLine);
    Graphics.drawDashline(canvas, startX, axisY10, width, axisY10, paint);

    int axisY0 = (int) (startY + volumeHeight - (lbl1value - min) * scale);
    Graphics.drawDashline(canvas, startX, axisY0, width, axisY0, paint);

    int axisYM10 = (int) (startY + volumeHeight - (lbl2value - min) * scale);
    Graphics.drawDashline(canvas, startX, axisYM10, width, axisYM10, paint);

    if (isTrackStatus == false) {
        tPaint.setColor(GlobalColor.colorKlabel);
        canvas.drawText(Utils.dataFormation(max, stockdigit), startX - tips / 4, axisY10 + axisLabelHeight / 2,
                tPaint);
        canvas.drawText(Utils.dataFormation(lbl1value, stockdigit), startX - tips / 4,
                axisY0 + axisLabelHeight / 2, tPaint);
        canvas.drawText(Utils.dataFormation(lbl2value, stockdigit), startX - tips / 4,
                axisYM10 + axisLabelHeight / 2, tPaint);
    }
    canvas.drawLine(startX, height - axisLabelHeight, width, height - axisLabelHeight, paint);

    if (quoteData != null) {
        double axisX = 0;

        double bias1x = 0;
        double bias1y = 0;

        double bias2x = 0;
        double bias2y = 0;

        double bias3x = 0;
        double bias3y = 0;

        for (int i = begin; i < (begin + count); i++) {
            double bias1 = quoteData.getJSONArray("BIAS").getJSONArray(i).getDouble(1);
            double bias2 = quoteData.getJSONArray("BIAS").getJSONArray(i).getDouble(2);
            double bias3 = quoteData.getJSONArray("BIAS").getJSONArray(i).getDouble(3);

            double bias1Height = 0;
            double bias2Height = 0;
            double bias3Height = 0;

            startX = klineX;
            if ((i - begin) == 0)
                axisX = axisX + spaceWidth;
            else
                axisX = axisX + spaceWidth + shapeWidth;

            if ((i - begin) == 0) {
                bias1x = bias1x + startX + spaceWidth + shapeWidth / 2;
                bias1Height = (bias1 + Math.abs(min)) * scale;
                bias1y = startY + volumeHeight - bias1Height;
            } else {
                double x1 = bias1x;
                double y1 = bias1y;

                bias1x = bias1x + spaceWidth + shapeWidth;
                bias1Height = (bias1 + Math.abs(min)) * scale;
                bias1y = startY + volumeHeight - bias1Height;

                paint.setColor(GlobalColor.colorM5);
                canvas.drawLine((int) Math.round(x1), (int) y1, (int) Math.round(bias1x), (int) bias1y, paint);
            }

            if ((i - begin) == 0) {
                bias2x = bias2x + startX + spaceWidth + shapeWidth / 2;
                bias2Height = (bias2 + Math.abs(min)) * scale;
                bias2y = startY + volumeHeight - bias2Height;
            } else {
                double x1 = bias2x;
                double y1 = bias2y;

                bias2x = bias2x + spaceWidth + shapeWidth;
                bias2Height = (bias2 + Math.abs(min)) * scale;
                bias2y = startY + volumeHeight - bias2Height;

                paint.setColor(GlobalColor.colorM10);
                canvas.drawLine((int) Math.round(x1), (int) y1, (int) Math.round(bias2x), (int) bias2y, paint);
            }

            if ((i - begin) == 0) {
                bias3x = bias3x + startX + spaceWidth + shapeWidth / 2;
                bias3Height = (bias3 + Math.abs(min)) * scale;
                bias3y = startY + volumeHeight - bias3Height;
            } else {
                double x1 = bias3x;
                double y1 = bias3y;

                bias3x = bias3x + spaceWidth + shapeWidth;

                bias3Height = (bias3 + Math.abs(min)) * scale;
                bias3y = startY + volumeHeight - bias3Height;

                //paint.setColor(GlobalColor.colorM20);
                paint.setARGB(255, 255, 0, 255);
                canvas.drawLine((int) Math.round(x1), (int) y1, (int) Math.round(bias3x), (int) bias3y, paint);
            }

            if (i == (begin + count - 1)) {
                //labelDif.text = "BIAS6:" + Utils.StockFormat(exchange+stockCode, bias1);
                //labelDea.text = "BIAS12:" + Utils.StockFormat(exchange+stockCode, bias2);
                //labelMacd.text = "BIAS24:" + Utils.StockFormat(exchange+stockCode, bias3);
            }
        } // end for
    } // end if
}

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

private void drawMACD(Canvas canvas, JSONObject quoteData, int begin, int count, double shapeWidth,
        double spaceWidth, double highPrice, double lowPrice, double highVolume, int actualDataLen)
        throws JSONException {
    if (quoteData == null || quoteData.isNull("MACD")) {
        isNetworkErrorDisplay();/*from   ww w.jav a  2 s . c o m*/
        return;
    }
    double max = 0.001;
    double min = -0.001;
    int len = quoteData.getJSONArray("MACD").length();
    for (int i = begin; i < (begin + count) && i < len; i++) {
        double dif = quoteData.getJSONArray("MACD").getJSONArray(i).getDouble(1);
        double dea = quoteData.getJSONArray("MACD").getJSONArray(i).getDouble(2);
        double macd = quoteData.getJSONArray("MACD").getJSONArray(i).getDouble(3);

        if (dif > max)
            max = dif;
        if (dea > max)
            max = dea;
        if (macd > max)
            max = macd;

        if (dif < 0) {
            if (dif < min)
                min = dif;
        }
        if (dea < 0) {
            if (dea < min)
                min = dea;
        }
        if (macd < 0) {
            if (macd < min)
                min = macd;
        }
    }

    max = max + (max - min) * 0.1;
    min = min - (max - min) * 0.1;
    if (max <= 0) {
        max = -min / 5;
    }
    max = Math.max(max, 0);

    double scale = this.volumeHeight / (max - min);
    double lbl1value = max - (max - min) / 3;
    double lbl2value = max - (max - min) * 2 / 3;

    if (Math.abs(lbl1value) < Math.abs(lbl2value)) {
        lbl1value = 0;
    } else {
        lbl2value = 0;
    }
    int startX = klineX;
    int startY = klineY;

    int axisY10 = (int) (startY + volumeHeight - (max - min) * scale);

    paint.setColor(GlobalColor.clrLine);
    Graphics.drawDashline(canvas, startX, axisY10, width, axisY10, paint);

    int axisY0 = (int) (startY + volumeHeight - (lbl1value - min) * scale);
    Graphics.drawDashline(canvas, startX, axisY0, width, axisY0, paint);

    int axisYM10 = (int) (startY + volumeHeight - (lbl2value - min) * scale);
    Graphics.drawDashline(canvas, startX, axisYM10, width, axisYM10, paint);

    if (isTrackStatus == false) {
        tPaint.setColor(GlobalColor.colorKlabel);
        canvas.drawText(Utils.dataFormation(max, stockdigit), startX - tips / 4, axisY10 + axisLabelHeight / 2,
                tPaint);
        canvas.drawText(Utils.dataFormation(lbl1value, stockdigit), startX - tips / 4,
                axisY0 + axisLabelHeight / 2, tPaint);
        canvas.drawText(Utils.dataFormation(lbl2value, stockdigit), startX - tips / 4,
                axisYM10 + axisLabelHeight / 2, tPaint);
    }
    canvas.drawLine(startX, height - axisLabelHeight, width, height - axisLabelHeight, paint);

    if (quoteData != null) {
        double axisX = klineX;

        double dif = 0, dea = 0, macd = 0, difx1 = 0, difx2 = 0, deax1 = 0, deax2 = 0;
        int dify1 = 0, dify2 = 0, deay1 = 0, deay2 = 0;
        for (int i = begin; i < (begin + count) && i < len; i++) {
            dif = quoteData.getJSONArray("MACD").getJSONArray(i).getDouble(1);
            dea = quoteData.getJSONArray("MACD").getJSONArray(i).getDouble(2);
            macd = quoteData.getJSONArray("MACD").getJSONArray(i).getDouble(3);

            if ((i - begin) == 0)
                axisX = axisX + spaceWidth;
            else
                axisX = axisX + spaceWidth + shapeWidth;

            if ((i - begin) == 0) {
                difx2 = difx2 + klineX + spaceWidth + shapeWidth / 2;
                dify2 = (int) (startY + volumeHeight - (dif - min) * scale);
            } else {
                difx1 = difx2;
                dify1 = dify2;
                difx2 = difx2 + spaceWidth + shapeWidth;
                dify2 = (int) (startY + volumeHeight - (dif - min) * scale);

                paint.setColor(GlobalColor.colorM5);
                canvas.drawLine((float) difx1, (float) dify1, (float) difx2, (float) dify2, paint);
            }

            if ((i - begin) == 0) {
                deax2 = deax2 + klineX + spaceWidth + shapeWidth / 2;
                deay2 = (int) (startY + volumeHeight - (dea - min) * scale);
            } else {
                deax1 = deax2;
                deay1 = deay2;
                deax2 = deax2 + spaceWidth + shapeWidth;
                deay2 = (int) (startY + volumeHeight - (dea - min) * scale);

                paint.setColor(GlobalColor.colorM10);
                canvas.drawLine((float) deax1, (float) deay1, (float) deax2, (float) deay2, paint);
            }

            if (macd >= 0) {
                paint.setColor(GlobalColor.colorKdown);
                canvas.drawLine((int) (axisX + shapeWidth / 2),
                        (int) (startY + volumeHeight - (0 - min) * scale), (int) (axisX + shapeWidth / 2),
                        (int) (startY + volumeHeight - (macd - min) * scale), paint);
            } else {
                paint.setARGB(255, 84, 255, 255);
                canvas.drawLine((int) (axisX + shapeWidth / 2),
                        (int) (startY + volumeHeight - (0 - min) * scale), (int) (axisX + shapeWidth / 2),
                        (int) (startY + volumeHeight - (macd - min) * scale), paint);
            }

            if (i == (begin + count - 1)) {
                //
            }
        } // end for
    } // end if
}

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

public void drawVOLUME(Canvas canvas, JSONObject quoteData, int begin, int count, double shapeWidth,
        double spaceWidth, double highPrice, double lowPrice, double highVolume, int actualDataLen)
        throws JSONException {
    if (quoteData == null || quoteData.isNull("MA")) {
        isNetworkErrorDisplay();/*w w  w.ja  v a 2  s  .c o m*/
        return;
    }

    axisX = klineX;
    for (int i = begin; i < (begin + count); i++) {
        highVolume = Arith.max(highVolume, quoteData.getJSONArray("MA").getJSONArray(i).getDouble(5),
                quoteData.getJSONArray("MA").getJSONArray(i).getDouble(6));
    }
    if (highVolume > 0) {
        scale = volumeHeight / highVolume;
    } else {
        scale = 999999;
    }

    double ratio = highVolume / rowNum;
    ratio = Math.round(ratio);

    String lblvalue = "12345", labelRatio = "";
    String lbhighVolume = String.valueOf(Math.round(highVolume));
    int ratiolen = lbhighVolume.length() - lblvalue.length();
    double scaleVol = 1;
    switch (ratiolen) {
    case 1:
        labelRatio = "x10";
        scaleVol = 10;
        break;
    case 2:
        labelRatio = "x100";
        scaleVol = 100;
        break;
    case 3:
        labelRatio = "x1000";
        scaleVol = 1000;
        break;
    case 4:
        labelRatio = "x1";
        scaleVol = 10000;
        break;
    case 5:
        labelRatio = "x1";
        scaleVol = 1000000;
        break;
    case 6:
        labelRatio = "x1";
        scaleVol = 1000000;
        break;
    default:
        labelRatio = "x1";
        scaleVol = 1;
        break;
    }

    double AxisLabelVolume = 0;
    paint.setColor(GlobalColor.clrLine);
    tPaint.setTextAlign(Paint.Align.RIGHT);
    for (int i = 0; i <= rowNum; i++) {
        if (i == rowNum || i == 0) {
            canvas.drawLine(klineX, klineY + rowHeight * i, width, klineY + rowHeight * i, paint);
        } else {
            Graphics.drawDashline(canvas, klineX, klineY + rowHeight * i, width, klineY + rowHeight * i, paint);
        }
        if (i != rowNum && isTrackStatus == false) {
            AxisLabelVolume = Math.round(highVolume - ratio * i);
            if (i == 0) {
                tPaint.setColor(GlobalColor.colorTicklabel);
                canvas.drawText(Utils.dataFormation(Math.round(AxisLabelVolume / scaleVol), 0),
                        klineX - tips / 4, klineY + rowHeight * i + axisLabelHeight / 2, tPaint);
            } else {
                tPaint.setColor(GlobalColor.colorTicklabel);
                canvas.drawText(Utils.dataFormation(Math.round(AxisLabelVolume / scaleVol), 0),
                        klineX - tips / 4, klineY + rowHeight * i + axisLabelHeight / 2, tPaint);
            }
        }
    }

    if (isTrackStatus == false) {
        tPaint.setColor(GlobalColor.colorTicklabel);
        canvas.drawText(labelRatio, klineX - tips / 4, height - axisLabelHeight, tPaint);
    }

    // K
    if (quoteData != null) {
        for (int i = begin; i < (begin + count); i++) {
            if (i == 0) {
                drawVolumeKLine(canvas, i - begin, quoteData.getJSONArray("K").getJSONArray(i).getDouble(1),
                        quoteData.getJSONArray("K").getJSONArray(i).getDouble(4),
                        quoteData.getJSONArray("K").getJSONArray(i).getDouble(5));
            } else {
                drawVolumeKLine(canvas, i - begin, quoteData.getJSONArray("K").getJSONArray(i).getDouble(1),
                        quoteData.getJSONArray("K").getJSONArray(i).getDouble(4),
                        quoteData.getJSONArray("K").getJSONArray(i).getDouble(5));
            }

            if (i == (begin + count - 1)) {
                // Util.drawString(g2, labelVolume, "VOLUME:", css);
            }
        }

        drawVolumeMACD(canvas, quoteData, begin, count, shapeWidth, spaceWidth, highPrice, lowPrice,
                highVolume);
    }
}

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

public void drawVOLUME(Canvas canvas, JSONObject quoteData, int begin, int count, double shapeWidth,
        double spaceWidth, double highPrice, double lowPrice, double highVolume, int actualDataLen)
        throws JSONException {
    if (quoteData == null || quoteData.isNull("MA")) {
        isNetworkErrorDisplay();/*from   www  .  java  2 s . c o m*/
        return;
    }
    axisX = klineX;
    for (int i = begin; i < (begin + count); i++) {
        highVolume = Arith.max(highVolume, quoteData.getJSONArray("MA").getJSONArray(i).getDouble(5),
                quoteData.getJSONArray("MA").getJSONArray(i).getDouble(6));
    }
    if (highVolume > 0) {
        scale = volumeHeight / highVolume;
    } else {
        scale = 999999;
    }

    double ratio = highVolume / rowNum;
    ratio = Math.round(ratio);

    String lblvalue = "12345", labelRatio = "";
    String lbhighVolume = String.valueOf(Math.round(highVolume));
    int ratiolen = lbhighVolume.length() - lblvalue.length();
    double scaleVol = 1;
    switch (ratiolen) {
    case 1:
        labelRatio = "x10";
        scaleVol = 10;
        break;
    case 2:
        labelRatio = "x100";
        scaleVol = 100;
        break;
    case 3:
        labelRatio = "x1000";
        scaleVol = 1000;
        break;
    case 4:
        labelRatio = "x1";
        scaleVol = 10000;
        break;
    case 5:
        labelRatio = "x1";
        scaleVol = 1000000;
        break;
    case 6:
        labelRatio = "x1";
        scaleVol = 1000000;
        break;
    default:
        labelRatio = "x1";
        scaleVol = 1;
        break;
    }

    double AxisLabelVolume = 0;
    paint.setColor(GlobalColor.clrLine);
    tPaint.setTextAlign(Paint.Align.RIGHT);
    for (int i = 0; i <= rowNum; i++) {
        if (i == rowNum || i == 0) {
            canvas.drawLine(klineX, klineY + rowHeight * i, width, klineY + rowHeight * i, paint);
        } else {
            Graphics.drawDashline(canvas, klineX, klineY + rowHeight * i, width, klineY + rowHeight * i, paint);
        }
        if (i != rowNum && isTrackStatus == false) {
            AxisLabelVolume = Math.round(highVolume - ratio * i);
            if (i == 0) {
                tPaint.setColor(GlobalColor.colorTicklabel);
                canvas.drawText(Utils.dataFormation(Math.round(AxisLabelVolume / scaleVol), 0),
                        klineX - tips / 4, klineY + rowHeight * i + axisLabelHeight / 2, tPaint);
            } else {
                tPaint.setColor(GlobalColor.colorTicklabel);
                canvas.drawText(Utils.dataFormation(Math.round(AxisLabelVolume / scaleVol), 0),
                        klineX - tips / 4, klineY + rowHeight * i + axisLabelHeight / 2, tPaint);
            }
        }
    }

    if (isTrackStatus == false) {
        tPaint.setColor(GlobalColor.colorTicklabel);
        canvas.drawText(labelRatio, klineX - tips / 4, height - axisLabelHeight, tPaint);
    }

    // K
    if (quoteData != null) {
        for (int i = begin; i < (begin + count); i++) {
            if (i == 0) {
                drawVolumeKLine(canvas, i - begin, quoteData.getJSONArray("K").getJSONArray(i).getDouble(1),
                        quoteData.getJSONArray("K").getJSONArray(i).getDouble(4),
                        quoteData.getJSONArray("K").getJSONArray(i).getDouble(5));
            } else {
                drawVolumeKLine(canvas, i - begin, quoteData.getJSONArray("K").getJSONArray(i).getDouble(1),
                        quoteData.getJSONArray("K").getJSONArray(i).getDouble(4),
                        quoteData.getJSONArray("K").getJSONArray(i).getDouble(5));
            }

            if (i == (begin + count - 1)) {
                // Util.drawString(g2, labelVolume, "VOLUME:", css);
            }
        }

        drawVolumeMACD(canvas, quoteData, begin, count, shapeWidth, spaceWidth, highPrice, lowPrice,
                highVolume);
    }
}

From source file:com.lt.adamlee.aagame.GameView.java

public void onDraw(Canvas c) {
    try {/*  w ww  .j a  va 2  s  .c  om*/
        if (mainpage == -1) {
            this.eg.exitdialog(c);
        }
        if (mainpage == 1) {
            if (bak2) {
                internalcounter2++;
                if (internalcounter2 % 10 == 0) {
                    counter1234++;
                }
                if (counter1234 >= 2) {
                    counter1234 = 0;
                    internalcounter2 = 0;
                    bak2 = false;
                }
            }
            if (bak4) {
                this.internalcounter4++;
                if (this.internalcounter4 % 10 == 0) {
                    this.counter12346++;
                }
                if (this.counter12346 >= 2) {
                    this.counter12346 = 0;
                    this.internalcounter4 = 0;
                    bak4 = false;
                }
            }
            c.drawBitmap(this.mainpageimage, 0.0f, 0.0f, null);
            c.drawBitmap(this.play, F.wf(110.0f), F.hf(175.0f), null);
            c.drawBitmap(this.moreapps, F.wf(45.0f), F.hf(340.0f), null);
            c.drawBitmap(this.help, F.wf(130.0f), F.hf(340.0f), null);
            c.drawBitmap(this.leaderboard, F.wf(215.0f), F.hf(340.0f), null);
        }
        if (mainpage == 5) {
            help(c);
        }
        if (mainpage == 6) {
            this.anim.levelanim(c);
        }
        if (mainpage == 7) {
            if (this.bakc) {
                this.internalcounterc++;
                if (this.internalcounterc % 10 == 0) {
                    this.counterc++;
                }
                if (this.counterc >= 2) {
                    this.counterc = 0;
                    this.internalcounterc = 0;
                    this.bakc = false;
                }
            }
            this.level.Level_Canvas(c);
        }
        if (mainpage == 3) {
            float[] fArr;
            if (baka) {
                this.internalcountera++;
                if (this.internalcountera % 10 == 0) {
                    this.countera++;
                }
                if (this.countera >= 2) {
                    this.countera = 0;
                    this.internalcountera = 0;
                    baka = false;
                }
            }
            view.drawRectangle(c);
            if (levelcounter % 3 == 0) {
                if (rotation[0] <= 0.0f && rotation[0] <= 0.0f) {
                    changeangle = 2.0d;
                }
                if (rotation[0] > 0.0f && rotation[0] >= 360.0f) {
                    changeangle = -2.0d;
                }
            }
            if (levelcounter % 3 == 1) {
                changeangle = 2.0d;
            }
            if (levelcounter % 3 == 2) {
                changeangle = -2.0d;
            }
            x = (int) F.wf(160.0f);
            y = (int) F.hf(159.0f);
            r = (int) F.wf(10.0f);
            int i = 0;
            while (i < blinedraw.length) {
                if (blinedraw[i]) {
                    c.save();
                    c.rotate(rotation[i], (float) (screenW / 2), F.hf(272.0f));
                    c.drawLine((float) (screenW / 2), F.hf(272.0f), (float) (screenW / 2),
                            F.hf(272.0f) - F.hf(105.0f), paint4);
                    c.drawCircle((float) x, (float) y, (float) r, paint3);
                    c.drawBitmap(this.cartoonbomb,
                            new Rect(0, 0, this.cartoonbomb.getWidth(), this.cartoonbomb.getHeight()),
                            new Rect(x - (this.cartoonbomb.getWidth() / 2),
                                    y - (this.cartoonbomb.getHeight() / 2),
                                    x + (this.cartoonbomb.getWidth() / 2),
                                    y + (this.cartoonbomb.getHeight() / 2)),
                            null);
                    if (i >= saveline) {
                        c.drawText((Circle.var - (i - saveline) + ""), (float) x, (float) ((int) F.hf(163.0f)),
                                this.innercircletext);
                    }
                    savex[i] = x;
                    savey[i] = y;
                    if (changeangle > 0.0d && rotation[i] >= 360.0f) {
                        rotation[i] = 0.0f;
                    }
                    if (changeangle < 0.0d && rotation[i] <= -360.0f) {
                        rotation[i] = 0.0f;
                    }
                    if (!(errorcircle || !GameActivity.isResume || circleblink)) {
                        fArr = rotation;
                        fArr[i] = (float) (((double) fArr[i]) + changeangle);
                    }
                    c.restore();
                    if (circleblink) {
                        holdcounter++;
                        if (holdcounter > 32000) {
                            holdcounter = 0;
                        }
                        if (holdcounter % 5 == 0) {
                            hcm++;
                        }
                        if (hcm > 32000) {
                            hcm = 0;
                        }
                        if (hcm <= 9) {
                            h = (int) F.wf(160.0f);
                            j = (int) F.hf(159.0f);
                            k = (int) F.wf(11.0f);
                            paint7.setAlpha(a1);
                            paint7.setColor(SupportMenu.CATEGORY_MASK);
                            paint7.setAntiAlias(true);
                            paint7.setFilterBitmap(true);
                            paint7.setStrokeWidth(2.0f);
                            c.drawCircle((float) h, (float) j, (float) k, paint7);
                            c.drawCircle((float) x, (float) y, (float) r, paint3);
                            if (i >= saveline) {
                                c.drawText((Circle.var - (i - saveline) + ""), (float) x,
                                        (float) ((int) F.hf(163.0f)), this.innercircletext);
                            }
                        }
                        if (hcm >= 11) {
                            circleblink = false;
                            mainpage = 6;
                            //                                GameActivity.vimapad.isBottomAdVisible(true);
                            //                                GameActivity.vimapad.isTopAdVisible(true);
                            holdcounter = 0;
                            hcm = 0;
                        }
                    }
                }
                i++;
            }
            i = 0;
            while (i < circledrawboolean.length) {
                if (circledrawboolean[i]) {
                    c.save();
                    c.rotate(rotation[i], (float) (screenW / 2), F.hf(272.0f));
                    c.drawLine((float) (screenW / 2), F.hf(272.0f), (float) (screenW / 2),
                            F.hf(272.0f) - F.hf(105.0f), paint4);
                    c.drawCircle((float) x, (float) y, (float) r, paint3);
                    if (i >= saveline) {
                        c.drawText((Circle.var - (i - saveline) + ""), (float) x, (float) ((int) F.hf(163.0f)),
                                this.innercircletext);
                    }
                    savex[i] = x;
                    savey[i] = y;
                    if (changeangle > 0.0d && rotation[i] >= 360.0f) {
                        rotation[i] = 0.0f;
                    }
                    if (changeangle < 0.0d && rotation[i] <= -360.0f) {
                        rotation[i] = 0.0f;
                    }
                    if (!(errorcircle || !GameActivity.isResume || circleblink)) {
                        fArr = rotation;
                        fArr[i] = (float) (((double) fArr[i]) + changeangle);
                    }
                    c.restore();
                    if (colcircle) {
                        this.displaycount3++;
                        textdisplayboolean = false;
                        if (this.displaycount3 <= 70
                                || (this.displaycount3 >= 80 && this.displaycount3 <= 90)) {
                            paint6.setAntiAlias(true);
                        }
                        paint6.setFilterBitmap(true);
                        paint6.setColor(ViewCompat.MEASURED_STATE_MASK);
                        c.drawCircle((float) (screenW / 2), F.hf(272.0f), F.wf(39.0f), paint6);
                        paint6.setColor(SupportMenu.CATEGORY_MASK);
                        paint6.setAntiAlias(true);
                        paint6.setFilterBitmap(true);
                        paint6.setTypeface(tf);
                        paint6.setAlpha(Circle.a);
                        paint6.setTextAlign(Paint.Align.CENTER);
                        c.drawText(String.valueOf(levelcounter), F.wf(160.0f), F.hf(278.0f), paint6);
                        paint6.setColor(getResources().getColor(R.color.common_signin_btn_default_background));
                        paint6.setAlpha(20);
                        paint6.setAntiAlias(true);
                        paint6.setFilterBitmap(true);
                        c.drawRect(0.0f, 0.0f, (float) screenW, (float) screenH, paint6);
                        if (this.displaycount3 <= 70 || this.displaycount3 >= 80) {
                        }
                        if (this.displaycount3 > 90) {
                            int j;
                            this.displaycount3 = 0;
                            colcircle = false;
                            circleblink = false;
                            bak4 = true;
                            reset();
                            levelcounter++;
                            errorcircle = false;
                            linecounter = NoOfInitialLines - 1;
                            for (j = 0; j < NoOfInitialLines; j++) {
                                blinedraw[j] = true;
                            }
                            for (j = 0; j < rotation.length; j++) {
                                rotation[j] = 0.0f;
                            }
                            for (j = 0; j < NoOfInitialLines; j++) {
                                rotation[j] = (float) ((j + 1) * (360 / NoOfInitialLines));
                                if (rotation[j] > 360.0f) {
                                    rotation[j] = rotation[j] - 360.0f;
                                }
                            }
                        }
                    }
                }
                i++;
            }
            this.paint21.setColor(-1);
            this.paint21.setTypeface(tf);
            this.paint21.setTextAlign(Paint.Align.CENTER);
            this.paint21.setAntiAlias(true);
            this.paint21.setFilterBitmap(true);
            if (textdisplayboolean) {
                c.drawText(String.valueOf(levelcounter), F.wf(160.0f), F.hf(278.0f), this.paint21);
            }
        }
    } catch (Exception e) {
    }
}

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

public void drawRSI(Canvas canvas, JSONObject quoteData, int begin, int count, double shapeWidth,
        double spaceWidth, double highPrice, double lowPrice, double highVolume, int actualDataLen)
        throws JSONException {
    if (quoteData.isNull("RSI") || quoteData.getJSONArray("RSI").length() < 1) {
        isNetworkErrorDisplay();//w w w.j  a va 2  s .c o  m
        return;
    }

    double max = 100.0;
    double min = 0.0;

    int len = quoteData.getJSONArray("RSI").length();
    for (int i = begin; i < (begin + count) && i < len; i++) {
        double k = quoteData.getJSONArray("RSI").getJSONArray(i).getDouble(1);
        double d = quoteData.getJSONArray("RSI").getJSONArray(i).getDouble(2);
        double j = quoteData.getJSONArray("RSI").getJSONArray(i).getDouble(3);

        if (k > max)
            max = k;
        if (d > max)
            max = d;
        if (j > max)
            max = j;

        if (k < 0) {
            if (k < min)
                min = k;
        }
        if (d < 0) {
            if (d < min)
                min = d;
        }
        if (j < 0) {
            if (j < min)
                min = j;
        }
    }
    double scale = this.volumeHeight / (max + Math.abs(min));

    int startX = klineX;
    int startY = klineY;

    int axisY100 = (int) (startY + volumeHeight - (100 + Math.abs(min)) * scale);
    paint.setColor(GlobalColor.clrLine);
    Graphics.drawDashline(canvas, startX, axisY100, width, axisY100, paint);

    String axisLabel1 = "";
    if (zs)
        axisLabel1 = "100.00";
    else
        axisLabel1 = "100.00";

    int axisY80 = (int) (startY + volumeHeight - (80 + Math.abs(min)) * scale);
    Graphics.drawDashline(canvas, startX, axisY80, width, axisY80, paint);

    String axisLabel2 = "80.00";

    int axisY50 = (int) (startY + volumeHeight - (50 + Math.abs(min)) * scale);
    Graphics.drawDashline(canvas, startX, axisY50, width, axisY50, paint);

    String axisLabel3 = "50.00";

    int axisY20 = (int) (startY + volumeHeight - (20 + Math.abs(min)) * scale);
    Graphics.drawDashline(canvas, startX, axisY20, width, axisY20, paint);

    String axisLabel4 = "20.00";

    int axisY0 = (int) (startY + volumeHeight - (0 + Math.abs(min)) * scale);
    Graphics.drawDashline(canvas, startX, axisY0, width, axisY0, paint);

    if (isTrackStatus == false) {
        tPaint.setColor(GlobalColor.colorKlabel);
        canvas.drawText(axisLabel1, startX - tips / 4, (float) (axisY100 + axisLabelHeight / 2), tPaint);
        canvas.drawText(axisLabel2, startX - tips / 4, (float) (axisY80 + axisLabelHeight / 2), tPaint);
        canvas.drawText(axisLabel3, startX - tips / 4, (float) (axisY50 + axisLabelHeight / 2), tPaint);
        canvas.drawText(axisLabel4, startX - tips / 4, (float) (axisY20 + axisLabelHeight / 2), tPaint);
    }
    canvas.drawLine(klineX, height - axisLabelHeight, width, height - axisLabelHeight, paint);

    if (quoteData != null) {
        double axisX = klineX;

        double bias1x = klineX;
        double bias1y = 0;

        double bias2x = klineX;
        double bias2y = 0;

        double bias3x = klineX;
        double bias3y = 0;

        for (int i = begin; i < (begin + count); i++) {
            double rsi1 = quoteData.getJSONArray("RSI").getJSONArray(i).getDouble(1);
            double rsi2 = quoteData.getJSONArray("RSI").getJSONArray(i).getDouble(2);
            double rsi3 = quoteData.getJSONArray("RSI").getJSONArray(i).getDouble(3);

            double bias1Height = 0;
            double bias2Height = 0;
            double bias3Height = 0;

            bias1Height = scale * rsi1;
            bias2Height = scale * rsi2;
            bias3Height = scale * rsi3;

            //klineX = 0;
            if ((i - begin) == 0)
                axisX = axisX + spaceWidth;
            else
                axisX = axisX + spaceWidth + shapeWidth;

            if ((i - begin) == 0) {
                bias1x = bias1x + spaceWidth + shapeWidth / 2;
                bias1y = height - axisLabelHeight - bias1Height;
            } else {
                double x1 = bias1x;
                double y1 = bias1y;

                bias1x = bias1x + spaceWidth + shapeWidth;

                bias1y = height - axisLabelHeight - bias1Height;

                paint.setColor(GlobalColor.colorM5);
                canvas.drawLine((int) Math.round(x1), (int) y1, (int) Math.round(bias1x), (int) bias1y, paint);
            }

            if ((i - begin) == 0) {
                bias2x = bias2x + spaceWidth + shapeWidth / 2;
                bias2y = height - axisLabelHeight - bias2Height;
            } else {
                double x1 = bias2x;
                double y1 = bias2y;
                bias2x = bias2x + spaceWidth + shapeWidth;
                bias2y = height - axisLabelHeight - bias2Height;
                paint.setColor(GlobalColor.colorM10);
                canvas.drawLine((int) Math.round(x1), (int) y1, (int) Math.round(bias2x), (int) bias2y, paint);
            }

            if ((i - begin) == 0) {
                bias3x = bias3x + spaceWidth + shapeWidth / 2;
                bias3y = height - axisLabelHeight - bias3Height;
            } else {
                double x1 = bias3x;
                double y1 = bias3y;
                bias3x = bias3x + spaceWidth + shapeWidth;
                bias3y = height - axisLabelHeight - bias3Height;
                paint.setARGB(255, 255, 0, 255);
                canvas.drawLine((int) Math.round(x1), (int) y1, (int) Math.round(bias3x), (int) bias3y, paint);
            }

            if (i == (begin + count - 1)) {
                //labelDif.text = "RSI6:" + Utils.StockFormat(exchange+stockCode, rsi1);
                //labelDea.text = "RSI12:" + Utils.StockFormat(exchange+stockCode, rsi2);
                //labelMacd.text = "RSI24:" + Utils.StockFormat(exchange+stockCode, rsi3);
            }
        } // end for
    } // end if
}

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

public void drawRSI(Canvas canvas, JSONObject quoteData, int begin, int count, double shapeWidth,
        double spaceWidth, double highPrice, double lowPrice, double highVolume, int actualDataLen)
        throws JSONException {

    if (quoteData.isNull("RSI") || quoteData.getJSONArray("RSI").length() < 1) {
        isNetworkErrorDisplay();//from w w w. j  a  v a  2  s  .co m
        return;
    }

    double max = 100.0;
    double min = 0.0;

    int len = quoteData.getJSONArray("RSI").length();
    for (int i = begin; i < (begin + count) && i < len; i++) {
        double k = quoteData.getJSONArray("RSI").getJSONArray(i).getDouble(1);
        double d = quoteData.getJSONArray("RSI").getJSONArray(i).getDouble(2);
        double j = quoteData.getJSONArray("RSI").getJSONArray(i).getDouble(3);

        if (k > max)
            max = k;
        if (d > max)
            max = d;
        if (j > max)
            max = j;

        if (k < 0) {
            if (k < min)
                min = k;
        }
        if (d < 0) {
            if (d < min)
                min = d;
        }
        if (j < 0) {
            if (j < min)
                min = j;
        }
    }
    double scale = this.volumeHeight / (max + Math.abs(min));

    int startX = klineX;
    int startY = klineY;

    int axisY100 = (int) (startY + volumeHeight - (100 + Math.abs(min)) * scale);
    paint.setColor(GlobalColor.clrLine);
    Graphics.drawDashline(canvas, startX, axisY100, width, axisY100, paint);

    String axisLabel1 = "";
    if (zs)
        axisLabel1 = "100.00";
    else
        axisLabel1 = "100.00";

    int axisY80 = (int) (startY + volumeHeight - (80 + Math.abs(min)) * scale);
    Graphics.drawDashline(canvas, startX, axisY80, width, axisY80, paint);

    String axisLabel2 = "80.00";

    int axisY50 = (int) (startY + volumeHeight - (50 + Math.abs(min)) * scale);
    Graphics.drawDashline(canvas, startX, axisY50, width, axisY50, paint);

    String axisLabel3 = "50.00";

    int axisY20 = (int) (startY + volumeHeight - (20 + Math.abs(min)) * scale);
    Graphics.drawDashline(canvas, startX, axisY20, width, axisY20, paint);

    String axisLabel4 = "20.00";

    int axisY0 = (int) (startY + volumeHeight - (0 + Math.abs(min)) * scale);
    Graphics.drawDashline(canvas, startX, axisY0, width, axisY0, paint);

    if (isTrackStatus == false) {
        tPaint.setColor(GlobalColor.colorKlabel);
        canvas.drawText(axisLabel1, startX - tips / 4, (float) (axisY100 + axisLabelHeight / 2), tPaint);
        canvas.drawText(axisLabel2, startX - tips / 4, (float) (axisY80 + axisLabelHeight / 2), tPaint);
        canvas.drawText(axisLabel3, startX - tips / 4, (float) (axisY50 + axisLabelHeight / 2), tPaint);
        canvas.drawText(axisLabel4, startX - tips / 4, (float) (axisY20 + axisLabelHeight / 2), tPaint);
    }
    canvas.drawLine(klineX, height - axisLabelHeight, width, height - axisLabelHeight, paint);

    if (quoteData != null) {
        double axisX = klineX;

        double bias1x = klineX;
        double bias1y = 0;

        double bias2x = klineX;
        double bias2y = 0;

        double bias3x = klineX;
        double bias3y = 0;

        for (int i = begin; i < (begin + count); i++) {
            double rsi1 = quoteData.getJSONArray("RSI").getJSONArray(i).getDouble(1);
            double rsi2 = quoteData.getJSONArray("RSI").getJSONArray(i).getDouble(2);
            double rsi3 = quoteData.getJSONArray("RSI").getJSONArray(i).getDouble(3);

            double bias1Height = 0;
            double bias2Height = 0;
            double bias3Height = 0;

            bias1Height = scale * rsi1;
            bias2Height = scale * rsi2;
            bias3Height = scale * rsi3;

            //klineX = 0;
            if ((i - begin) == 0)
                axisX = axisX + spaceWidth;
            else
                axisX = axisX + spaceWidth + shapeWidth;

            if ((i - begin) == 0) {
                bias1x = bias1x + spaceWidth + shapeWidth / 2;
                bias1y = height - axisLabelHeight - bias1Height;
            } else {
                double x1 = bias1x;
                double y1 = bias1y;

                bias1x = bias1x + spaceWidth + shapeWidth;

                bias1y = height - axisLabelHeight - bias1Height;

                paint.setColor(GlobalColor.colorM5);
                canvas.drawLine((int) Math.round(x1), (int) y1, (int) Math.round(bias1x), (int) bias1y, paint);
            }

            if ((i - begin) == 0) {
                bias2x = bias2x + spaceWidth + shapeWidth / 2;
                bias2y = height - axisLabelHeight - bias2Height;
            } else {
                double x1 = bias2x;
                double y1 = bias2y;
                bias2x = bias2x + spaceWidth + shapeWidth;
                bias2y = height - axisLabelHeight - bias2Height;
                paint.setColor(GlobalColor.colorM10);
                canvas.drawLine((int) Math.round(x1), (int) y1, (int) Math.round(bias2x), (int) bias2y, paint);
            }

            if ((i - begin) == 0) {
                bias3x = bias3x + spaceWidth + shapeWidth / 2;
                bias3y = height - axisLabelHeight - bias3Height;
            } else {
                double x1 = bias3x;
                double y1 = bias3y;
                bias3x = bias3x + spaceWidth + shapeWidth;
                bias3y = height - axisLabelHeight - bias3Height;
                paint.setARGB(255, 255, 0, 255);
                canvas.drawLine((int) Math.round(x1), (int) y1, (int) Math.round(bias3x), (int) bias3y, paint);
            }

            if (i == (begin + count - 1)) {
                //labelDif.text = "RSI6:" + Utils.StockFormat(exchange+stockCode, rsi1);
                //labelDea.text = "RSI12:" + Utils.StockFormat(exchange+stockCode, rsi2);
                //labelMacd.text = "RSI24:" + Utils.StockFormat(exchange+stockCode, rsi3);
            }
        } // end for
    } // end if
}

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

public void drawKDJ(Canvas canvas, JSONObject quoteData, int begin, int count, double shapeWidth,
        double spaceWidth, double highPrice, double lowPrice, double highVolume, int actualDataLen)
        throws JSONException {
    if (quoteData.isNull("KDJ") || quoteData.getJSONArray("KDJ").length() < 1) {
        isNetworkErrorDisplay();//from   w  ww. java2 s  .c o  m
        return;
    }

    //this.shapeWidth = shapeWidth;
    //this.spaceWidth = spaceWidth;

    double max = 0.001;
    double min = -0.001;

    int len = quoteData.getJSONArray("KDJ").length();
    for (int i = begin; i < (begin + count) && i < len; i++) {
        double k = quoteData.getJSONArray("KDJ").getJSONArray(i).getDouble(1);
        double d = quoteData.getJSONArray("KDJ").getJSONArray(i).getDouble(2);
        double j = quoteData.getJSONArray("KDJ").getJSONArray(i).getDouble(3);

        if (k > max)
            max = k;
        if (d > max)
            max = d;
        if (j > max)
            max = j;

        if (k < 0) {
            if (k < min)
                min = k;
        }
        if (d < 0) {
            if (d < min)
                min = d;
        }
        if (j < 0) {
            if (j < min)
                min = j;
        }
    }
    max = Math.max(max, 100);
    min = Math.min(min, 0.0);
    double scale = this.volumeHeight / (Math.max(max, 100) + Math.abs(min));

    int startX = klineX;
    int startY = klineY;

    int axisY100 = (int) (startY + volumeHeight - (100 + Math.abs(min)) * scale);

    paint.setColor(GlobalColor.clrLine);
    Graphics.drawDashline(canvas, startX, axisY100, width, axisY100, paint);

    String axisLabel1 = "100.00";

    int axisY80 = (int) (startY + volumeHeight - (80 + Math.abs(min)) * scale);

    Graphics.drawDashline(canvas, startX, axisY80, width, axisY80, paint);

    String axisLabel2 = "80.00";

    int axisY50 = (int) (startY + volumeHeight - (50 + Math.abs(min)) * scale);

    Graphics.drawDashline(canvas, startX, axisY50, width, axisY50, paint);

    String axisLabel3 = "50.00";

    int axisY20 = (int) (startY + volumeHeight - (20 + Math.abs(min)) * scale);

    Graphics.drawDashline(canvas, startX, axisY20, width, axisY20, paint);

    String axisLabel4 = "20.00";

    int axisY0 = (int) (startY + volumeHeight - (0 + Math.abs(min)) * scale);

    Graphics.drawDashline(canvas, startX, axisY0, width, axisY0, paint);

    String axisLabel5 = "0.00";
    if (isTrackStatus == false) {
        tPaint.setColor(GlobalColor.colorKlabel);
        canvas.drawText(axisLabel1, startX - tips / 4, axisY100 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel2, startX - tips / 4, axisY80 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel3, startX - tips / 4, axisY50 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel4, startX - tips / 4, axisY20 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel5, startX - tips / 4, axisY0 + axisLabelHeight / 2, tPaint);
    }
    canvas.drawLine(startX, height - axisLabelHeight, width, height - axisLabelHeight, paint);

    if (quoteData != null) {

        double axisX = klineX;
        double difx = klineX;

        double deax = klineX;
        double jx = klineX;

        int kHeight = 0;
        int ky = 0;
        int dHeight = 0;
        int dy = 0;
        int jHeight = 0;
        int jy = 0;

        for (int i = begin; i < (begin + count); i++) {
            double k = quoteData.getJSONArray("KDJ").getJSONArray(i).getDouble(1);
            double d = quoteData.getJSONArray("KDJ").getJSONArray(i).getDouble(2);
            double j = quoteData.getJSONArray("KDJ").getJSONArray(i).getDouble(3);

            //klineX = 0;
            if ((i - begin) == 0)
                axisX = axisX + spaceWidth;
            else
                axisX = axisX + spaceWidth + shapeWidth;

            if ((i - begin) == 0) {
                difx = difx + spaceWidth + shapeWidth / 2;
                kHeight = (int) ((k + Math.abs(min)) * scale);
                ky = startY + volumeHeight - kHeight;
            } else {
                double x1 = difx;
                double y1 = ky;

                difx = difx + spaceWidth + shapeWidth;
                kHeight = (int) ((k + Math.abs(min)) * scale);
                ky = startY + volumeHeight - kHeight;

                paint.setColor(GlobalColor.colorM5);
                canvas.drawLine((int) Math.round(x1), (int) y1, (int) Math.round(difx), (int) ky, paint);
            }

            if ((i - begin) == 0) {
                deax = deax + spaceWidth + shapeWidth / 2;
                dHeight = (int) ((d + Math.abs(min)) * scale);
                dy = startY + volumeHeight - dHeight;
            } else {
                double x1 = deax;
                double y1 = dy;

                deax = deax + spaceWidth + shapeWidth;
                dHeight = (int) ((d + Math.abs(min)) * scale);
                dy = startY + volumeHeight - dHeight;

                paint.setColor(GlobalColor.colorM10);
                canvas.drawLine((int) Math.round(x1), (int) y1, (int) Math.round(deax), (int) dy, paint);
            }

            if ((i - begin) == 0) {
                jx = jx + spaceWidth + shapeWidth / 2;
                jHeight = (int) ((j + Math.abs(min)) * scale);
                jy = startY + volumeHeight - jHeight;
            } else {
                double x1 = jx;
                double y1 = jy;

                jx = jx + spaceWidth + shapeWidth;
                jHeight = (int) ((j + Math.abs(min)) * scale);
                jy = startY + volumeHeight - jHeight;

                paint.setARGB(255, 255, 0, 255);
                canvas.drawLine((int) Math.round(x1), (int) y1, (int) Math.round(jx), (int) jy, paint);
            }

            if (i == (begin + count - 1)) {
                //labelDif.text = "K:" + Utils.StockFormat(exchange+stockCode, k);
                //labelDea.text = "D:" + Utils.StockFormat(exchange+stockCode, d);
                //labelMacd.text = "J:" + Utils.StockFormat(exchange+stockCode, j);
            }
        } // end for
    } // end if
}