Example usage for android.graphics Canvas drawLine

List of usage examples for android.graphics Canvas drawLine

Introduction

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

Prototype

public void drawLine(float startX, float startY, float stopX, float stopY, @NonNull Paint paint) 

Source Link

Document

Draw a line segment with the specified start and stop x,y coordinates, using the specified paint.

Usage

From source file:com.example.anumbrella.viewpager.LinePagerIndicator.java

/**
 * ?//from   www .  j  a  v  a2  s. co m
 *
 * @param canvas
 */
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (mViewPager == null) {
        return;
    }

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

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

    final float lineWidthAndGap = mLineWidth + mGapWidth;
    final float indicatorWidth = (count * lineWidthAndGap) - mGapWidth;
    final float paddingTop = getPaddingTop();
    final float paddingLeft = getPaddingLeft();
    final float paddingRight = getPaddingRight();

    float verticalOffset = paddingTop + ((getHeight() - paddingTop - getPaddingBottom()) / 2.0f);
    float horizontalOffset = paddingLeft;

    //???
    if (mCentered) {
        horizontalOffset += ((getWidth() - paddingLeft - paddingRight) / 2.0f) - (indicatorWidth / 2.0f);
    }

    //
    for (int i = 0; i < count; i++) {
        float dx1 = horizontalOffset + (i * lineWidthAndGap);
        float dx2 = dx1 + mLineWidth;
        canvas.drawLine(dx1, verticalOffset, dx2, verticalOffset,
                (i == mCurrentPage) ? mPaintSelected : mPaintUnselected);
    }
}

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

public void drawHKIndex(Canvas canvas) {
    Paint paint = this.mPaint;
    paint.setTypeface(Typeface.DEFAULT_BOLD);
    paint.setAntiAlias(true);//from ww w  .java  2 s .co m
    tPaint.setColor(GlobalColor.clrLine);
    tPaint.setStyle(Paint.Style.STROKE);
    tPaint.setStrokeWidth(1);
    this.x = 0;
    this.y = 0;
    startX = x + tips / 2;
    endX = width - tips / 2;
    canvas.drawRect(startX, DY + DY / 4, endX, height - DY / 4, tPaint);
    canvas.drawLine(startX, DY * 5 + DY / 2, endX, DY * 5 + DY / 2, tPaint);
    canvas.drawLine(startX, DY * 11 + DY / 8, endX, DY * 11 + DY / 8, tPaint);
    //canvas.drawLine(startX, DY*16+DY/4, endX, DY*16+DY/4, tPaint);
    if (quoteData != null) {
        try {
            JSONArray jArr = quoteData.getJSONArray("data");
            JSONObject jo = jArr.getJSONObject(0);
            double zrsp = jo.getDouble("zrsp");

            paint.setTextSize(mTextSize);
            paint.setTextAlign(Paint.Align.LEFT);
            paint.setColor(GlobalColor.colorLabelName);
            canvas.translate(0, DY * 2);
            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);

            canvas.translate(0, DY * 1.5f);
            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);
            //            canvas.translate(0, DY);
            //            canvas.drawText("??", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("??", x + tips, y, paint);

            canvas.translate(0, DY * 1.5f);
            //            canvas.drawText("?", x + tips, y, paint);
            //            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);

            canvas.translate(width, -DY * 13f);
            paint.setTextAlign(Paint.Align.RIGHT);

            double zjcj = jo.getDouble("zjcj");
            setColor(paint, zjcj, zrsp);

            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(zjcj, stockdigit), x - tips, y, paint);

            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);
            String zhangdie = Utils.dataFormation(zhangd, stockdigit);
            if (zhangdie.equals("-"))
                canvas.drawText("", x - tips, y, paint);
            else
                canvas.drawText(zhangdie, x - tips, 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(0, DY);
            String zhangfu = Utils.dataFormation(zhangf * 100, stockdigit);
            if (zhangfu.equals("-"))
                canvas.drawText("", x - tips, y, paint);
            else
                canvas.drawText(zhangfu + "%", x - tips, y, paint);

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

            canvas.translate(0, DY * 1.5f);
            paint.setColor(GlobalColor.colorLabelName);
            canvas.drawText(Utils.dataFormation(zrsp, stockdigit), x - tips, y, paint);

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

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

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

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

            canvas.translate(0, DY * 1.5f);
            //canvas.drawText(Utils.dataFormation(jo.getDouble("lb"), 1), x - tips, y, paint);

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

            paint.setColor(GlobalColor.colorPriceEqual);
            canvas.translate(0, DY);
            canvas.drawText(String.valueOf(jo.getInt("pj")), x - tips, y, paint);

            paint.setColor(GlobalColor.colorPriceDown);
            canvas.translate(0, DY);
            canvas.drawText(String.valueOf(jo.getInt("dj")), x - tips, y, paint);
        } catch (JSONException e) {
            Log.e(TAG, e.toString());
        }
    }
}

From source file:com.android.hcframe.DraggableGridViewPager.java

@Override
protected void onDraw(Canvas canvas) {
    // TODO Auto-generated method stub
    super.onDraw(canvas);
    // draw divider
    if (mShowDivider && mGridGap == 0) {
        HcLog.D(TAG + " onDraw draw divider!==========================");
        for (int k = 0; k < mPageCount; k++) {
            for (int i = 0; i < mRowCount; i++) {
                for (int j = 1; j < mColCount; j++) {
                    canvas.drawLine((mGridWidth * mColCount * k) + mGridWidth * j,
                            mGridHeight * i + mDividerPaddingTop, (mGridWidth * mColCount * k) + mGridWidth * j,
                            mGridHeight * (i + 1) - mDividerPaddingBottom, mDividerPaint);
                }//from   w w w  . j a v a  2 s.  c  o m
            }
        }

    }

    if (mShowRowDivider && mGridGap == 0) {
        for (int k = 0; k < mPageCount; k++) {
            for (int i = 1; i < mRowCount; i++) {
                canvas.drawLine(0, mGridHeight * i, getWidth(), mGridHeight * i, mDividerPaint);
            }
        }
    }

}

From source file:io.bunnyblue.noticedog.app.ui.pageview.LinePageIndicator.java

protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (this.mViewPager != null) {
        int count = this.mViewPager.getAdapter().getCount();
        if (count == 0) {
            return;
        }/*from  w  w w.  j  a  v  a2  s .  c om*/
        if (this.mCurrentPage >= count) {
            setCurrentItem(count - 1);
            return;
        }
        float lineWidthAndGap = this.mLineWidth + this.mGapWidth;
        float indicatorWidth = (((float) count) * lineWidthAndGap) - this.mGapWidth;
        float paddingTop = (float) getPaddingTop();
        float paddingLeft = (float) getPaddingLeft();
        float paddingRight = (float) getPaddingRight();
        float verticalOffset = paddingTop
                + (((((float) getHeight()) - paddingTop) - ((float) getPaddingBottom())) / 2.0f);
        float horizontalOffset = paddingLeft;
        if (this.mCentered) {
            horizontalOffset += (((((float) getWidth()) - paddingLeft) - paddingRight) / 2.0f)
                    - (indicatorWidth / 2.0f);
        }
        int i = 0;
        while (i < count) {
            float dx1 = horizontalOffset + (((float) i) * lineWidthAndGap);
            canvas.drawLine(dx1, verticalOffset, dx1 + this.mLineWidth, verticalOffset,
                    i == this.mCurrentPage ? this.mPaintSelected : this.mPaintUnselected);
            i++;
        }
    }
}

From source file:com.diedrico.diedricoapp.PicMenuActivity.java

License:asdf

private PicAnalyzer.AsyncResponse analyzerFinished() { //We receive the important points and lines, we have to paint them
    return new PicAnalyzer.AsyncResponse() {
        @Override//from  www.  jav  a 2s  . c o  m
        public void processFinish(List<PointVector> points, List<LineVector> lines, List<Double> planos) {
            //Set that the analyzer finished
            analyzerFinished = Boolean.TRUE;

            //Save the points in another var, if the user select that there are errors in the scan, he can select the points and lines manually
            allPoints = points;
            allLines = lines;

            //First we have to delete the short lines, we get the top module and then we discard the short ones
            Collections.sort(lines, new Comparator<LineVector>() {
                @Override
                public int compare(LineVector line1, LineVector line2) {
                    return (line1.getModuleTwoDimensionalVector() - line2.getModuleTwoDimensionalVector() >= 0)
                            ? -1
                            : 1;
                }
            });

            landLine = lines.get(0); //This is the landLine
            double minModule = lines.get(0).getModuleTwoDimensionalVector() / 6;

            for (LineVector linevector : new ArrayList<>(lines)) {
                if (linevector.getModuleTwoDimensionalVector() < minModule) {
                    lines.remove(linevector);
                }
            }

            pointDiedrico = new ArrayList<>();
            lineDiedrico = new ArrayList<>();

            ////Delete the wrong lines, the ones that don't have x's view and y's view respectively (cota and alejamiento). Then we differ between if it is a line(in diedrico) or a plane
            for (int j = 1; j < lines.size(); j++) { //Start in 1 because in 0 the line is the landLine
                LineVector line1 = lines.get(j);
                for (int k = 1; k < lines.size(); k++) {
                    LineVector line2 = lines.get(k);

                    if (line1.equals(line2)) {
                        if (k == lines.size() - 1) { //The last line of the list
                            lines.remove(k);
                            j--;
                            break;
                        }
                        continue;
                    }

                    if (line1.getLineYA() > lines.get(0).getYEquation(line1.getLineXA())
                            && line2.getLineYA() < lines.get(0).getYEquation(line1.getLineXA())
                            || line2.getLineYA() > lines.get(0).getYEquation(line1.getLineXA())
                                    && line1.getLineYA() < lines.get(0).getYEquation(line1.getLineXA())) {
                        if (line1.getLineXA() > line2.getLineXA() - 50
                                && line1.getLineXA() < line2.getLineXA() + 50) { //Has found a result, then we delete the points from the list, and put them in pointDiedricoList and we continue
                            if (line1.getLineYA() > landLine.getLineYA()) {//We store the cota and alejamiento, the cota is the line over the landline
                                lineDiedrico.add(new LineDiedrico(line1, line2));
                            } else {
                                lineDiedrico.add(new LineDiedrico(line2, line1));
                            }

                            lines.remove(k);
                            lines.remove(j);

                            j--;
                            break;
                        }
                    }

                    if (k == lines.size() - 1) { //The line doesn't have a couple
                        lines.remove(j);
                        j--;
                    }
                }
            }

            //Also, boofcv finds a lot of useless points near the lines, so we have to delete them
            Iterator<LineVector> lineVectorIterator = lines.iterator();
            while (lineVectorIterator.hasNext()) {
                LineVector lineVector = lineVectorIterator.next();

                points = Stream.of(points)
                        .filter((PointVector point) -> point
                                .getPointY() < lineVector.getYEquation(point.getPointX()) - 15
                                || point.getPointY() > lineVector.getYEquation(point.getPointX()) + 15)
                        .toList();
            }

            //Then we have to delete the groups of points and take only one of them
            for (int j = 0; j < points.size(); j++) {
                PointVector point1 = points.get(j);
                for (int k = 0; k < points.size(); k++) {
                    PointVector point2 = points.get(k);

                    if (point1.equals(point2)) {
                        continue;
                    }

                    if (point1.getPointX() > point2.getPointX() - 20
                            && point1.getPointX() < point2.getPointX() + 20
                            && point1.getPointY() > point2.getPointY() - 20
                            && point1.getPointY() < point2.getPointY() + 20) { //Has found a result, then we delete the points from the list
                        points.remove(k);
                        k--;
                    }
                }
            }

            //Delete the wrong point, the ones that don't have x's view and y's view respectively (cota and alejamiento). The correct points will be in pointDiedrico
            for (int j = 0; j < points.size(); j++) {
                PointVector point1 = points.get(j);
                for (int k = 0; k < points.size(); k++) {
                    PointVector point2 = points.get(k);

                    if (point1.equals(point2)) {
                        if (k == points.size() - 1) { //The last point of the list
                            points.remove(k);
                            j--;
                            break;
                        }
                        continue;
                    }

                    if (point1.getPointY() > lines.get(0).getYEquation(point1.getPointX())
                            && point2.getPointY() < lines.get(0).getYEquation(point2.getPointX())
                            || point2.getPointY() > lines.get(0).getYEquation(point2.getPointX())
                                    && point1.getPointY() < lines.get(0).getYEquation(point1.getPointX())) {
                        if (point1.getPointX() > point2.getPointX() - 15
                                && point1.getPointX() < point2.getPointX() + 15) {
                            //Has found a result, then we delete the points from the list, and put them in pointDiedricoList and we continue
                            if (point1.getPointY() > lines.get(0).getYEquation(point1.getPointX())) { //We store the cota and alejamiento, the cota is the point over the landline
                                pointDiedrico.add(new PointDiedrico(point1, point2));
                            } else {
                                pointDiedrico.add(new PointDiedrico(point2, point1));
                            }

                            points.remove(k);
                            points.remove(j);

                            j--;
                            break;
                        }
                    }

                    if (k == points.size() - 1) { //The point doesn't have a couple
                        points.remove(j);
                        j--;
                    }
                }
            }

            int indexColors = 0; //Counter for the color array
            int[] colors = context.getResources().getIntArray(R.array.rainbow);

            Paint paintMax;
            paintMax = new Paint();
            paintMax.setStyle(Paint.Style.FILL);

            Canvas canvas = new Canvas(thresholdingBitmap);

            for (int i = 0; i < pointDiedrico.size(); i++) {
                paintMax.setColor(colors[indexColors++]);
                if (indexColors >= colors.length)
                    indexColors = 0;

                canvas.drawCircle(pointDiedrico.get(i).getX().getPointX(),
                        pointDiedrico.get(i).getX().getPointY(), 3, paintMax);
                canvas.drawCircle(pointDiedrico.get(i).getY().getPointX(),
                        pointDiedrico.get(i).getY().getPointY(), 3, paintMax);
            }

            //Paint the landLine with color blue
            paintMax.setColor(Color.BLUE);
            canvas.drawLine(lines.get(0).getLineXA(), lines.get(0).getLineYA(), lines.get(0).getLineXB(),
                    lines.get(0).getLineYB(), paintMax);

            //Paint the interesting lines
            for (int i = 0; i < lineDiedrico.size(); i++) {
                paintMax.setColor(colors[indexColors++]);
                if (indexColors >= colors.length)
                    indexColors = 0;
                canvas.drawLine(lineDiedrico.get(i).getX().getLineXA(), lineDiedrico.get(i).getX().getLineYA(),
                        lineDiedrico.get(i).getX().getLineXB(), lineDiedrico.get(i).getX().getLineYB(),
                        paintMax);
                canvas.drawLine(lineDiedrico.get(i).getY().getLineXA(), lineDiedrico.get(i).getY().getLineYA(),
                        lineDiedrico.get(i).getY().getLineXB(), lineDiedrico.get(i).getY().getLineYB(),
                        paintMax);
            }

            imageView.setImageBitmap(thresholdingBitmap);
        }
    };
}

From source file:io.jawg.osmcontributor.ui.utils.views.ItemDividerDecoration.java

@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
    float yPositionThreshold = LINE_HEIGHT_PX + 1.0f; // [px]
    float zPositionThreshold = 1.0f; // [px]
    int left = parent.getPaddingLeft();
    int right = parent.getWidth() - parent.getPaddingRight();

    for (int i = 0, count = parent.getChildCount() - 1; i < count; i++) {
        View child = parent.getChildAt(i);
        View nextChild = parent.getChildAt(i + 1);
        if (child.getVisibility() != View.VISIBLE || nextChild.getVisibility() != View.VISIBLE) {
            continue;
        }/*from  w ww  .  j  a  va  2  s .  c o m*/

        // check if the next item is placed at the bottom
        float childBottom = child.getBottom() + ViewCompat.getTranslationY(child);
        float nextChildTop = nextChild.getTop() + ViewCompat.getTranslationY(nextChild);
        if (Math.abs(nextChildTop - childBottom) >= yPositionThreshold) {
            continue;
        }

        // check if the next item is placed on the same plane
        float childZ = ViewCompat.getTranslationZ(child) + ViewCompat.getElevation(child);
        float nextChildZ = ViewCompat.getTranslationZ(nextChild) + ViewCompat.getElevation(nextChild);
        if (Math.abs(nextChildZ - childZ) >= zPositionThreshold) {
            continue;
        }

        float childAlpha = ViewCompat.getAlpha(child);
        float nextChildAlpha = ViewCompat.getAlpha(nextChild);
        paint.setAlpha((int) (255 * Math.min(childAlpha, nextChildAlpha) + 0.5f));

        int top = child.getBottom();
        int ty = (int) (ViewCompat.getTranslationY(child) + 0.5f);
        c.drawLine(left, top + ty, right, top + ty, paint);
    }
}

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

private void drawQihuo(Canvas canvas) {
    //stockdigit = 0;
    Paint paint = this.mPaint;
    tPaint.setColor(GlobalColor.clrLine);
    tPaint.setStyle(Paint.Style.STROKE);
    tPaint.setStrokeWidth(1);/*from   w  w  w. j a  va2s  .c om*/
    this.x = 0;
    this.y = 0;
    startX = x + tips / 2;
    endX = width - tips / 2;
    canvas.drawRect(startX, DY / 4, endX, height - DY / 4, tPaint);
    canvas.drawLine(startX, DY * 2 + DY / 4, endX, DY * 2 + DY / 4, tPaint);
    canvas.drawLine(startX, DY * 8 + DY / 4, endX, DY * 8 + DY / 4, tPaint);
    canvas.drawLine(startX, DY * 11 + DY / 4, endX, DY * 11 + DY / 4, tPaint);
    //canvas.drawLine(startX, DY*16+DY/4, endX, DY*16+DY/4, tPaint);
    if (quoteData != null) {
        try {
            JSONArray jArr = quoteData.getJSONArray("data");
            JSONObject jo = jArr.getJSONObject(0);
            String str = "";
            double zrsp = jo.getDouble("zrsp");

            canvas.translate(0, DY);

            paint.setTypeface(Typeface.DEFAULT_BOLD);
            paint.setAntiAlias(true);
            paint.setTextSize(mTextSize);
            paint.setTextAlign(Paint.Align.LEFT);
            paint.setColor(GlobalColor.colorLabelName);
            canvas.drawText("?", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);

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

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

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

            paint.setColor(GlobalColor.colorStockName);
            paint.setTextAlign(Paint.Align.RIGHT);
            canvas.translate(width / 2, -DY);
            canvas.drawText(Utils.getAmountFormat(jo.getInt("ssl1"), true), x - tips, y, paint);

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

            canvas.translate(-width, DY);

            paint.setTextAlign(Paint.Align.LEFT);
            paint.setColor(GlobalColor.colorLabelName);

            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x + tips, y, paint);

            canvas.translate(width / 2, -DY * 5);

            paint.setTextAlign(Paint.Align.RIGHT);
            double zjcj = jo.getDouble("zjcj");
            setColor(paint, zjcj, zrsp);
            canvas.drawText(Utils.dataFormation(zjcj, stockdigit), x, y, paint);

            canvas.translate(0, DY);
            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);
            }
            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(0, DY);
            String zhangfu = Utils.dataFormation(zhangf * 100, 1);
            if (zhangfu.equals("-"))
                canvas.drawText("", x, y, paint);
            else
                canvas.drawText(zhangfu + "%", x, y, paint);

            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(jo.getDouble("jrjs"), stockdigit), x, y, paint);
            paint.setColor(GlobalColor.colorpriceUp);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("wp"), true), x, y, paint);
            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getInt("cjsl"), true), x, y, paint);

            canvas.translate(0, -DY * 5);

            paint.setTextAlign(Paint.Align.LEFT);
            paint.setColor(GlobalColor.colorLabelName);

            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x + tips, y, paint);

            canvas.translate(width / 2, -DY * 5);

            paint.setTextAlign(Paint.Align.RIGHT);
            double jrkp = jo.getDouble("jrkp");
            setColor(paint, jrkp, zrsp);
            canvas.drawText(Utils.dataFormation(jrkp, stockdigit), x - tips, y, paint);

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

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

            paint.setColor(GlobalColor.colorLabelName);
            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(jo.getDouble("zrjs"), stockdigit), x - tips, y, paint);
            paint.setColor(GlobalColor.colorPriceDown);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("np"), true), x - tips, y, paint);
            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjje"), true), x - tips, y, paint);

            canvas.translate(-width, DY);

            paint.setTextAlign(Paint.Align.LEFT);
            paint.setColor(GlobalColor.colorLabelName);

            canvas.drawText("?", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText(" ", x + tips, y, paint);

            canvas.translate(width / 2, -DY * 2);

            paint.setTextAlign(Paint.Align.RIGHT);
            double zt = jo.getDouble("zt");
            setColor(paint, zt, zrsp);
            canvas.drawText(Utils.dataFormation(zt, stockdigit), x, y, paint);

            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(jo.getDouble("jrcc"), 0), x, y, paint);

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

            paint.setTextAlign(Paint.Align.LEFT);
            paint.setColor(GlobalColor.colorLabelName);
            canvas.translate(0, -DY * 2);

            canvas.drawText("?", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText(" ", x + tips, y, paint);

            canvas.translate(width / 2, -DY * 2);

            paint.setTextAlign(Paint.Align.RIGHT);
            double dt = jo.getDouble("dt");
            setColor(paint, dt, zrsp);
            canvas.drawText(Utils.dataFormation(dt, stockdigit), x - tips, y, paint);

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

            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(jo.getDouble("jrpc"), 0), x - tips, y, paint);
        } catch (JSONException e) {
            Log.e(TAG, e.toString());
        }
    }
}

From source file:de.treichels.hott.ui.android.html.AndroidCurveImageGenerator.java

private Bitmap getBitmap(final Curve curve, final float scale, final boolean description) {
    final boolean pitchCurve = curve.getPoint()[0].getPosition() == 0;
    final float scale1 = scale * 0.75f; // smaller images on the android
    // platform//  ww w.j  a va2s. c om

    final Bitmap image = Bitmap.createBitmap((int) (10 + 200 * scale1), (int) (10 + 250 * scale1),
            Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(image);

    final Paint backgroundPaint = new Paint();
    backgroundPaint.setColor(Color.WHITE);
    backgroundPaint.setStyle(Style.FILL);

    final Paint forgroundPaint = new Paint();
    forgroundPaint.setColor(Color.BLACK);
    forgroundPaint.setStyle(Style.STROKE);
    forgroundPaint.setStrokeWidth(1.0f);
    forgroundPaint.setStrokeCap(Cap.BUTT);
    forgroundPaint.setStrokeJoin(Join.ROUND);
    forgroundPaint.setStrokeMiter(0.0f);

    final Paint curvePaint = new Paint(forgroundPaint);
    curvePaint.setFlags(Paint.ANTI_ALIAS_FLAG);
    curvePaint.setStrokeWidth(2.0f);

    final Paint pointPaint = new Paint(curvePaint);
    pointPaint.setStrokeWidth(5.0f);
    pointPaint.setStyle(Style.FILL_AND_STROKE);

    final Paint helpLinePaint = new Paint(forgroundPaint);
    helpLinePaint.setColor(Color.GRAY);
    helpLinePaint.setPathEffect(new DashPathEffect(new float[] { 5.0f, 5.0f }, 2.5f));

    final Paint textPaint = new Paint(forgroundPaint);
    textPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
    textPaint.setTextSize(12.0f);
    textPaint.setTextAlign(Align.CENTER);
    textPaint.setStyle(Style.FILL);

    canvas.drawRect(0, 0, 10 + 200 * scale1, 10 + 250 * scale1, backgroundPaint);
    canvas.drawRect(5, 5, 5 + 200 * scale1, 5 + 250 * scale1, forgroundPaint);

    canvas.drawLine(5, 5 + 25 * scale1, 5 + 200 * scale1, 5 + 25 * scale1, helpLinePaint);
    canvas.drawLine(5, 5 + 225 * scale1, 5 + 200 * scale1, 5 + 225 * scale1, helpLinePaint);
    if (!pitchCurve) {
        canvas.drawLine(5, 5 + 125 * scale1, 5 + 200 * scale1, 5 + 125 * scale1, helpLinePaint);
        canvas.drawLine(5 + 100 * scale1, 5, 5 + 100 * scale1, 5 + 250 * scale1, helpLinePaint);
    }

    if (curve.getPoint() != null) {
        int numPoints = 0;
        for (final CurvePoint p : curve.getPoint()) {
            if (p.isEnabled()) {
                numPoints++;
            }
        }

        final double[] xVals = new double[numPoints];
        final double[] yVals = new double[numPoints];

        int i = 0;
        for (final CurvePoint p : curve.getPoint()) {
            if (p.isEnabled()) {
                if (i == 0) {
                    xVals[i] = pitchCurve ? 0 : -100;
                } else if (i == numPoints - 1) {
                    xVals[i] = 100;
                } else {
                    xVals[i] = p.getPosition();
                }
                yVals[i] = p.getValue();

                if (description) {
                    float x0;
                    float y0;
                    if (pitchCurve) {
                        x0 = (float) (5 + xVals[i] * 2 * scale1);
                        y0 = (float) (5 + (225 - yVals[i] * 2) * scale1);
                    } else {
                        x0 = (float) (5 + (100 + xVals[i]) * scale1);
                        y0 = (float) (5 + (125 - yVals[i]) * scale1);
                    }

                    canvas.drawPoint(x0, y0, pointPaint);
                    if (y0 < 5 + 125 * scale1) {
                        canvas.drawRect(x0 - 4, y0 + 5, x0 + 3, y0 + 18, backgroundPaint);
                        canvas.drawText(Integer.toString(p.getNumber() + 1), x0 - 1, y0 + 16, textPaint);
                    } else {
                        canvas.drawRect(x0 - 4, y0 - 5, x0 + 3, y0 - 18, backgroundPaint);
                        canvas.drawText(Integer.toString(p.getNumber() + 1), x0 - 1, y0 - 7, textPaint);
                    }
                }

                i++;
            }
        }

        if (numPoints > 2 && curve.isSmoothing()) {
            final SplineInterpolator s = new SplineInterpolator();
            final PolynomialSplineFunction function = s.interpolate(xVals, yVals);

            float x0 = 5;
            float y0;
            if (pitchCurve) {
                y0 = (float) (5 + (225 - yVals[0] * 2) * scale1);
            } else {
                y0 = (float) (5 + (125 - yVals[0]) * scale1);
            }

            while (x0 < 4 + 200 * scale1) {
                final float x1 = x0 + 1;
                float y1;
                if (pitchCurve) {
                    y1 = (float) (5 + (225 - function.value((x1 - 5) / scale1 / 2) * 2) * scale1);
                } else {
                    y1 = (float) (5 + (125 - function.value((x1 - 5) / scale1 - 100)) * scale1);
                }

                canvas.drawLine(x0, y0, x1, y1, curvePaint);

                x0 = x1;
                y0 = y1;
            }
        } else {
            for (i = 0; i < numPoints - 1; i++) {
                float x0, y0, x1, y1;

                if (pitchCurve) {
                    x0 = (float) (5 + xVals[i] * 2 * scale1);
                    y0 = (float) (5 + (225 - yVals[i] * 2) * scale1);

                    x1 = (float) (5 + xVals[i + 1] * 2 * scale1);
                    y1 = (float) (5 + (225 - yVals[i + 1] * 2) * scale1);
                } else {
                    x0 = (float) (5 + (100 + xVals[i]) * scale1);
                    y0 = (float) (5 + (125 - yVals[i]) * scale1);

                    x1 = (float) (5 + (100 + xVals[i + 1]) * scale1);
                    y1 = (float) (5 + (125 - yVals[i + 1]) * scale1);
                }

                canvas.drawLine(x0, y0, x1, y1, curvePaint);
            }
        }
    }

    return image;
}

From source file:net.cpacm.library.indicator.ViewpagerIndicator.LinePageIndicator.java

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

    if (mViewPager == null) {
        return;// w w  w  .  j  ava2  s.co  m
    }
    int count = mViewPager.getAdapter().getCount();
    if (mViewPager.getAdapter() instanceof InfinitePagerAdapter) {
        count = ((InfinitePagerAdapter) mViewPager.getAdapter()).getRealCount();
        mCurrentPage = mCurrentPage % count;
    }
    if (count == 0) {
        return;
    }

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

    final float lineWidthAndGap = mLineWidth + mGapWidth;
    final float indicatorWidth = (count * lineWidthAndGap) - mGapWidth;
    final float paddingTop = getPaddingTop();
    final float paddingLeft = getPaddingLeft();
    final float paddingRight = getPaddingRight();

    float verticalOffset = paddingTop + ((getHeight() - paddingTop - getPaddingBottom()) / 2.0f);
    float horizontalOffset = paddingLeft;
    if (mCentered) {
        horizontalOffset += ((getWidth() - paddingLeft - paddingRight) / 2.0f) - (indicatorWidth / 2.0f);
    }

    //Draw stroked circles
    for (int i = 0; i < count; i++) {
        float dx1 = horizontalOffset + (i * lineWidthAndGap);
        float dx2 = dx1 + mLineWidth;
        canvas.drawLine(dx1, verticalOffset, dx2, verticalOffset,
                (i == mCurrentPage) ? mPaintSelected : mPaintUnselected);
    }
}

From source file:tbs.simplecars.ui.PagerSlidingTabStrip.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (isInEditMode() || tabCount == 0) {
        return;/*from   www  . jav  a  2 s.co  m*/
    }

    final int height = getHeight();

    rectPaint.setColor(indicatorColor);

    final View currentTab = tabsContainer.getChildAt(currentPosition);
    float lineLeft = currentTab.getLeft();
    float lineRight = currentTab.getRight();

    // if there is an offset, start interpolating left and right coordinates between current and next tab
    if (currentPositionOffset > 0f && currentPosition < tabCount - 1) {
        final View nextTab = tabsContainer.getChildAt(currentPosition + 1);
        final float nextTabLeft = nextTab.getLeft();
        final float nextTabRight = nextTab.getRight();

        lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft);
        lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight);
    }
    canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint);
    // draw underline
    rectPaint.setColor(underlineColor);
    canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint);
    // draw divider

    dividerPaint.setColor(dividerColor);
    for (int i = 0; i < tabCount - 1; i++) {
        View tab = tabsContainer.getChildAt(i);
        canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding, dividerPaint);
    }
}