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.cssweb.android.view.KlineViewSingle.java

public void drawROC(Canvas canvas, JSONObject quoteData, int begin, int count, double shapeWidth,
        double spaceWidth, double highPrice, double lowPrice, double highVolume, int actualDataLen,
        String indicator) throws JSONException {
    this.shapeWidth = shapeWidth;
    this.spaceWidth = spaceWidth;
    if (quoteData.isNull(indicator) || quoteData.getJSONArray(indicator).length() < 1) {
        isNetworkErrorDisplay();// ww  w.  j  a  va2s.c o  m
        return;
    }
    double max = 0.001;
    double min = 9999999999f;
    double wr = 0, wr2 = 0;
    int len = quoteData.getJSONArray(indicator).length();
    for (int i = begin; i < (begin + count) && i < len; i++) {
        wr = quoteData.getJSONArray(indicator).getJSONArray(i).getDouble(1);
        wr2 = quoteData.getJSONArray(indicator).getJSONArray(i).getDouble(2);
        max = Arith.max(wr, wr2, max);
        min = Arith.min(wr, wr2, min);
    }
    max = max * 1.1;
    min = min - Math.abs(min) * 0.1;
    double scale = (double) (this.volumeHeight) / (max - min);

    int startX = klineX;
    int startY = klineY;

    double AxisLabelVolume = max;
    String lblvalue = "12345";
    int ratiolen = String.valueOf(Math.round(AxisLabelVolume)).length() - String.valueOf(lblvalue).length();

    String labelRatio = "";
    int 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 = "x10000";
        scaleVol = 10000;
        break;
    default:
        labelRatio = "";
        scaleVol = 1;
        break;
    }

    int axisY1 = (int) (startY + volumeHeight - (max - min) * scale);
    paint.setColor(GlobalColor.clrLine);
    Graphics.drawDashline(canvas, startX, axisY1, width, axisY1, paint);

    String axisLabel1 = Utils.dataFormation(max / scaleVol, 1);

    int axisY2 = (int) (startY + volumeHeight - (max - min) * 3 / 4 * scale);
    Graphics.drawDashline(canvas, startX, axisY2, width, axisY2, paint);

    String axisLabel2 = Utils.dataFormation((min + (max - min) * 3 / 4) / scaleVol, 1);

    int axisY3 = (int) (startY + volumeHeight - (max - min) * 2 / 4 * scale);
    Graphics.drawDashline(canvas, startX, axisY3, klineX + klineWidth, axisY3, paint);

    String axisLabel3 = Utils.dataFormation((min + (max - min) * 2 / 4) / scaleVol, 1);

    int axisY4 = (int) (startY + volumeHeight - (max - min) / 4 * scale);
    Graphics.drawDashline(canvas, startX, axisY4, klineX + klineWidth, axisY4, paint);

    String axisLabel4 = Utils.dataFormation((min + (max - min) * 1 / 4) / scaleVol, 1);

    if (isTrackStatus == false) {
        tPaint.setColor(GlobalColor.colorKlabel);
        canvas.drawText(labelRatio, startX - tips / 4, startY + volumeHeight + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel1, startX - tips / 4, axisY1 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel2, startX - tips / 4, axisY2 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel3, startX - tips / 4, axisY3 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel4, startX - tips / 4, axisY4 + axisLabelHeight / 2, tPaint);
    }

    canvas.drawLine(startX, height - axisLabelHeight, width, height - axisLabelHeight, paint);

    if (quoteData != null) {
        double currX = 0, currY1 = 0, currY2 = 0;//???
        double nextX = 0, nextY1 = 0, nextY2 = 0;//??

        int kHeight = 0;

        for (int i = begin; i < (begin + count) && i < len; i++) {
            wr = quoteData.getJSONArray(indicator).getJSONArray(i).getDouble(1);
            wr2 = quoteData.getJSONArray(indicator).getJSONArray(i).getDouble(2);

            if ((i - begin) == 0) {
                currX = startX;
                currX = nextX = currX + spaceWidth + shapeWidth / 2;
                kHeight = (int) ((wr - min) * scale);
                currY1 = nextY1 = startY + volumeHeight - kHeight;

                kHeight = (int) ((wr2 - min) * scale);
                currY2 = nextY2 = startY + volumeHeight - kHeight;
            } else {
                nextX = currX + spaceWidth + shapeWidth;
                kHeight = (int) ((wr - min) * scale);
                nextY1 = startY + volumeHeight - kHeight;

                kHeight = (int) ((wr2 - min) * scale);
                nextY2 = startY + volumeHeight - kHeight;
            }
            paint.setColor(GlobalColor.colorM5);
            canvas.drawLine((float) currX, (float) currY1, (float) nextX, (float) nextY1, paint);

            paint.setColor(GlobalColor.colorM10);
            canvas.drawLine((float) currX, (float) currY2, (float) nextX, (float) nextY2, paint);

            currX = nextX;
            currY1 = nextY1;
            currY2 = nextY2;

            if (i == (begin + count - 1)) {

            }
        } // end for
    } // end if
}

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

public void drawOther(Canvas canvas, JSONObject quoteData, int begin, int count, double shapeWidth,
        double spaceWidth, double highPrice, double lowPrice, double highVolume, int actualDataLen,
        String indicator) throws JSONException {
    this.shapeWidth = shapeWidth;
    this.spaceWidth = spaceWidth;
    if (quoteData.isNull(indicator) || quoteData.getJSONArray(indicator).length() < 1) {
        isNetworkErrorDisplay();//  w  ww. j  a v a 2  s . co  m
        return;
    }
    double max = 0.001;
    double min = 9999999999f;
    double wr = 0, wr2 = 0;
    int len = quoteData.getJSONArray(indicator).length();
    for (int i = begin; i < (begin + count) && i < len; i++) {
        wr = quoteData.getJSONArray(indicator).getJSONArray(i).getDouble(1);
        wr2 = quoteData.getJSONArray(indicator).getJSONArray(i).getDouble(2);
        max = Arith.max(wr, wr2, max);
        min = Arith.min(wr, wr2, min);
    }
    max = max + (max - min) / 10;
    min = min - (max - min) / 10;
    double scale = (double) (this.volumeHeight) / (max - min);

    int startX = klineX;
    int startY = klineY;

    double AxisLabelVolume = max;
    String lblvalue = "12345";
    int ratiolen = String.valueOf(Math.round(AxisLabelVolume)).length() - String.valueOf(lblvalue).length();

    String labelRatio = "";
    int 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 = "x10000";
        scaleVol = 10000;
        break;
    default:
        labelRatio = "";
        scaleVol = 1;
        break;
    }

    int axisY1 = (int) (startY + volumeHeight - (max - min) * scale);
    paint.setColor(GlobalColor.clrLine);
    Graphics.drawDashline(canvas, startX, axisY1, width, axisY1, paint);

    String axisLabel1 = String.valueOf((int) max / scaleVol);

    int axisY2 = (int) (startY + volumeHeight - (max - min) * 3 / 4 * scale);
    Graphics.drawDashline(canvas, startX, axisY2, width, axisY2, paint);

    String axisLabel2 = String.valueOf((int) (min + (max - min) * 3 / 4) / scaleVol);

    int axisY3 = (int) (startY + volumeHeight - (max - min) * 2 / 4 * scale);
    Graphics.drawDashline(canvas, startX, axisY3, klineX + klineWidth, axisY3, paint);

    String axisLabel3 = String.valueOf((int) (min + (max - min) * 2 / 4) / scaleVol);

    int axisY4 = (int) (startY + volumeHeight - (max - min) / 4 * scale);
    Graphics.drawDashline(canvas, startX, axisY4, klineX + klineWidth, axisY4, paint);

    String axisLabel4 = String.valueOf((int) (min + (max - min) * 1 / 4) / scaleVol);

    if (isTrackStatus == false) {
        tPaint.setColor(GlobalColor.colorKlabel);
        canvas.drawText(labelRatio, startX - tips / 4, startY + volumeHeight + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel1, startX - tips / 4, axisY1 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel2, startX - tips / 4, axisY2 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel3, startX - tips / 4, axisY3 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel4, startX - tips / 4, axisY4 + axisLabelHeight / 2, tPaint);
    }

    canvas.drawLine(startX, height - axisLabelHeight, width, height - axisLabelHeight, paint);

    if (quoteData != null) {
        double currX = 0, currY1 = 0, currY2 = 0;//???
        double nextX = 0, nextY1 = 0, nextY2 = 0;//??

        int kHeight = 0;

        for (int i = begin; i < (begin + count) && i < len; i++) {
            wr = quoteData.getJSONArray(indicator).getJSONArray(i).getLong(1);
            wr2 = quoteData.getJSONArray(indicator).getJSONArray(i).getLong(2);

            if ((i - begin) == 0) {
                currX = startX;
                currX = nextX = currX + spaceWidth + shapeWidth / 2;
                kHeight = (int) ((wr - min) * scale);
                currY1 = nextY1 = startY + volumeHeight - kHeight;

                kHeight = (int) ((wr2 - min) * scale);
                currY2 = nextY2 = startY + volumeHeight - kHeight;
            } else {
                nextX = currX + spaceWidth + shapeWidth;
                kHeight = (int) ((wr - min) * scale);
                nextY1 = startY + volumeHeight - kHeight;

                kHeight = (int) ((wr2 - min) * scale);
                nextY2 = startY + volumeHeight - kHeight;
            }
            paint.setColor(GlobalColor.colorM5);
            canvas.drawLine((float) currX, (float) currY1, (float) nextX, (float) nextY1, paint);

            paint.setColor(GlobalColor.colorM10);
            canvas.drawLine((float) currX, (float) currY2, (float) nextX, (float) nextY2, paint);

            currX = nextX;
            currY1 = nextY1;
            currY2 = nextY2;

            if (i == (begin + count - 1)) {

            }
        } // end for
    } // end if
}

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

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

    long max = 1;
    long min = 99999999999999l;
    long obv, maobv;
    int len = quoteData.getJSONArray("OBV").length();
    for (int i = begin; i < (begin + count) && i < len; i++) {
        obv = quoteData.getJSONArray("OBV").getJSONArray(i).getLong(1);
        maobv = quoteData.getJSONArray("OBV").getJSONArray(i).getLong(2);
        max = Arith.max(obv, maobv, max);
        min = Arith.min(obv, maobv, min);
    }
    max = max + (max - min) / 10;
    min = min - (max - min) / 10;
    double scale = (double) (this.volumeHeight) / (max - min);

    int startX = klineX;
    int startY = klineY;

    double AxisLabelVolume = max;
    String lblvalue = "12345";
    int ratiolen = String.valueOf(Math.round(AxisLabelVolume)).length() - String.valueOf(lblvalue).length();

    String labelRatio = "";
    int 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 = "x10000";
        scaleVol = 10000;
        break;
    case 5:
        labelRatio = "x1";
        scaleVol = 1000000;
        break;
    case 6:
        labelRatio = "x1";
        scaleVol = 1000000;
        break;
    default:
        labelRatio = "x1";
        scaleVol = 1;
        break;
    }

    int axisY1 = (int) (startY + volumeHeight - (max - min) * scale);
    paint.setColor(GlobalColor.clrLine);
    Graphics.drawDashline(canvas, startX, axisY1, width, axisY1, paint);

    String axisLabel1 = String.valueOf((int) max / scaleVol);

    int axisY2 = (int) (startY + volumeHeight - (max - min) * 3 / 4 * scale);
    Graphics.drawDashline(canvas, startX, axisY2, width, axisY2, paint);

    String axisLabel2 = String.valueOf((int) (min + (max - min) * 3 / 4) / scaleVol);

    int axisY3 = (int) (startY + volumeHeight - (max - min) * 2 / 4 * scale);
    Graphics.drawDashline(canvas, startX, axisY3, width, axisY3, paint);

    String axisLabel3 = String.valueOf((int) (min + (max - min) * 2 / 4) / scaleVol);

    int axisY4 = (int) (startY + volumeHeight - (max - min) / 4 * scale);
    Graphics.drawDashline(canvas, startX, axisY4, width, axisY4, paint);

    String axisLabel4 = String.valueOf((int) (min + (max - min) * 1 / 4) / scaleVol);

    if (isTrackStatus == false) {
        tPaint.setColor(GlobalColor.colorKlabel);
        canvas.drawText(labelRatio, startX - tips / 4, startY + volumeHeight + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel1, startX - tips / 4, axisY1 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel2, startX - tips / 4, axisY2 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel3, startX - tips / 4, axisY3 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel4, startX - tips / 4, axisY4 + axisLabelHeight / 2, tPaint);
    }
    canvas.drawLine(startX, height - axisLabelHeight, width, height - axisLabelHeight, paint);

    if (quoteData != null) {
        double currX = 0, currY1 = 0, currY2 = 0;//???
        double nextX = 0, nextY1 = 0, nextY2 = 0;//??

        int kHeight = 0;

        for (int i = begin; i < (begin + count) && i < len; i++) {
            obv = quoteData.getJSONArray("OBV").getJSONArray(i).getLong(1);
            maobv = quoteData.getJSONArray("OBV").getJSONArray(i).getLong(2);

            startX = klineX;

            if ((i - begin) == 0) {
                currX = 0;
                currX = nextX = currX + startX + spaceWidth + shapeWidth / 2;
                kHeight = (int) ((obv - min) * scale);
                currY1 = nextY1 = startY + volumeHeight - kHeight;
                kHeight = (int) ((maobv - min) * scale);
                currY2 = nextY2 = startY + volumeHeight - kHeight;
            } else {
                nextX = currX + spaceWidth + shapeWidth;
            }
            // obv
            kHeight = (int) ((obv - min) * scale);
            nextY1 = startY + volumeHeight - kHeight;
            paint.setColor(GlobalColor.colorM5);
            canvas.drawLine((int) currX, (int) currY1, (int) nextX, (int) nextY1, paint);

            // maobv
            kHeight = (int) ((maobv - min) * scale);
            nextY2 = startY + volumeHeight - kHeight;
            paint.setColor(GlobalColor.colorM10);
            canvas.drawLine((int) currX, (int) currY2, (int) nextX, (int) nextY2, paint);

            currX = nextX;
            currY1 = nextY1;
            currY2 = nextY2;

            if (i == (begin + count - 1)) {

            }
        } // end for
    } // end if
}

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

public void drawOBV(Canvas canvas, JSONObject quoteData, int begin, int count, double shapeWidth,
        double spaceWidth, double highPrice, double lowPrice, double highVolume, int actualDataLen)
        throws JSONException {
    //      this.shapeWidth = shapeWidth;
    //      this.spaceWidth = spaceWidth;
    if (quoteData.isNull("OBV") || quoteData.getJSONArray("OBV").length() < 1) {
        isNetworkErrorDisplay();/*from   w w w .  j ava2s .  c  o  m*/
        return;
    }
    long max = 1;
    long min = 99999999999999l;
    long obv, maobv;
    int len = quoteData.getJSONArray("OBV").length();
    for (int i = begin; i < (begin + count) && i < len; i++) {
        obv = quoteData.getJSONArray("OBV").getJSONArray(i).getLong(1);
        maobv = quoteData.getJSONArray("OBV").getJSONArray(i).getLong(2);
        max = Arith.max(obv, maobv, max);
        min = Arith.min(obv, maobv, min);
    }
    max = max + (max - min) / 10;
    min = min - (max - min) / 10;
    double scale = (double) (this.volumeHeight) / (max - min);

    int startX = klineX;
    int startY = klineY;

    double AxisLabelVolume = max;
    String lblvalue = "12345";
    int ratiolen = String.valueOf(Math.round(AxisLabelVolume)).length() - String.valueOf(lblvalue).length();

    String labelRatio = "";
    int 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 = "x10000";
        scaleVol = 10000;
        break;
    case 5:
        labelRatio = "x1";
        scaleVol = 1000000;
        break;
    case 6:
        labelRatio = "x1";
        scaleVol = 1000000;
        break;
    default:
        labelRatio = "x1";
        scaleVol = 1;
        break;
    }

    int axisY1 = (int) (startY + volumeHeight - (max - min) * scale);
    paint.setColor(GlobalColor.clrLine);
    Graphics.drawDashline(canvas, startX, axisY1, width, axisY1, paint);

    String axisLabel1 = String.valueOf((int) max / scaleVol);

    int axisY2 = (int) (startY + volumeHeight - (max - min) * 3 / 4 * scale);
    Graphics.drawDashline(canvas, startX, axisY2, width, axisY2, paint);

    String axisLabel2 = String.valueOf((int) (min + (max - min) * 3 / 4) / scaleVol);

    int axisY3 = (int) (startY + volumeHeight - (max - min) * 2 / 4 * scale);
    Graphics.drawDashline(canvas, startX, axisY3, width, axisY3, paint);

    String axisLabel3 = String.valueOf((int) (min + (max - min) * 2 / 4) / scaleVol);

    int axisY4 = (int) (startY + volumeHeight - (max - min) / 4 * scale);
    Graphics.drawDashline(canvas, startX, axisY4, width, axisY4, paint);

    String axisLabel4 = String.valueOf((int) (min + (max - min) * 1 / 4) / scaleVol);

    if (isTrackStatus == false) {
        tPaint.setColor(GlobalColor.colorKlabel);
        canvas.drawText(labelRatio, startX - tips / 4, startY + volumeHeight + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel1, startX - tips / 4, axisY1 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel2, startX - tips / 4, axisY2 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel3, startX - tips / 4, axisY3 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel4, startX - tips / 4, axisY4 + axisLabelHeight / 2, tPaint);
    }
    canvas.drawLine(startX, height - axisLabelHeight, width, height - axisLabelHeight, paint);

    if (quoteData != null) {
        double currX = 0, currY1 = 0, currY2 = 0;//???
        double nextX = 0, nextY1 = 0, nextY2 = 0;//??

        int kHeight = 0;

        for (int i = begin; i < (begin + count) && i < len; i++) {
            obv = quoteData.getJSONArray("OBV").getJSONArray(i).getLong(1);
            maobv = quoteData.getJSONArray("OBV").getJSONArray(i).getLong(2);

            startX = klineX;

            if ((i - begin) == 0) {
                currX = 0;
                currX = nextX = currX + startX + spaceWidth + shapeWidth / 2;
                kHeight = (int) ((obv - min) * scale);
                currY1 = nextY1 = startY + volumeHeight - kHeight;
                kHeight = (int) ((maobv - min) * scale);
                currY2 = nextY2 = startY + volumeHeight - kHeight;
            } else {
                nextX = currX + spaceWidth + shapeWidth;
            }
            // obv
            kHeight = (int) ((obv - min) * scale);
            nextY1 = startY + volumeHeight - kHeight;
            paint.setColor(GlobalColor.colorM5);
            canvas.drawLine((int) currX, (int) currY1, (int) nextX, (int) nextY1, paint);

            // maobv
            kHeight = (int) ((maobv - min) * scale);
            nextY2 = startY + volumeHeight - kHeight;
            paint.setColor(GlobalColor.colorM10);
            canvas.drawLine((int) currX, (int) currY2, (int) nextX, (int) nextY2, paint);

            currX = nextX;
            currY1 = nextY1;
            currY2 = nextY2;

            if (i == (begin + count - 1)) {

            }
        } // end for
    } // end if
}

From source file:org.telegram.ui.Cells.ContextLinkCell.java

@Override
protected void onDraw(Canvas canvas) {
    if (titleLayout != null) {
        canvas.save();//from   ww w. j a v  a 2 s  .co  m
        canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline),
                titleY);
        titleLayout.draw(canvas);
        canvas.restore();
    }

    if (descriptionLayout != null) {
        descriptionTextPaint.setColor(DESCRIPTION_TEXT_COLOR/*0xff8a8a8a*/);
        canvas.save();
        canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline),
                descriptionY);
        descriptionLayout.draw(canvas);
        canvas.restore();
    }

    if (linkLayout != null) {
        descriptionTextPaint.setColor(Theme.MSG_LINK_TEXT_COLOR);
        canvas.save();
        canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline),
                linkY);
        linkLayout.draw(canvas);
        canvas.restore();
    }

    if (!mediaWebpage) {
        if (documentAttachType == DOCUMENT_ATTACH_TYPE_AUDIO
                || documentAttachType == DOCUMENT_ATTACH_TYPE_MUSIC) {
            radialProgress.setProgressColor(buttonPressed ? Theme.MSG_IN_AUDIO_SELECTED_PROGRESS_COLOR
                    : Theme.MSG_IN_AUDIO_PROGRESS_COLOR);
            radialProgress.draw(canvas);
        } else if (inlineResult != null && inlineResult.type.equals("file")) {
            int w = Theme.inlineDocDrawable.getIntrinsicWidth();
            int h = Theme.inlineDocDrawable.getIntrinsicHeight();
            int x = linkImageView.getImageX() + (AndroidUtilities.dp(52) - w) / 2;
            int y = linkImageView.getImageY() + (AndroidUtilities.dp(52) - h) / 2;
            canvas.drawRect(linkImageView.getImageX(), linkImageView.getImageY(),
                    linkImageView.getImageX() + AndroidUtilities.dp(52),
                    linkImageView.getImageY() + AndroidUtilities.dp(52), LetterDrawable.paint);
            Theme.inlineDocDrawable.setBounds(x, y, x + w, y + h);
            Theme.inlineDocDrawable.draw(canvas);
        } else if (inlineResult != null
                && (inlineResult.type.equals("audio") || inlineResult.type.equals("voice"))) {
            int w = Theme.inlineAudioDrawable.getIntrinsicWidth();
            int h = Theme.inlineAudioDrawable.getIntrinsicHeight();
            int x = linkImageView.getImageX() + (AndroidUtilities.dp(52) - w) / 2;
            int y = linkImageView.getImageY() + (AndroidUtilities.dp(52) - h) / 2;
            canvas.drawRect(linkImageView.getImageX(), linkImageView.getImageY(),
                    linkImageView.getImageX() + AndroidUtilities.dp(52),
                    linkImageView.getImageY() + AndroidUtilities.dp(52), LetterDrawable.paint);
            Theme.inlineAudioDrawable.setBounds(x, y, x + w, y + h);
            Theme.inlineAudioDrawable.draw(canvas);
        } else if (inlineResult != null
                && (inlineResult.type.equals("venue") || inlineResult.type.equals("geo"))) {
            int w = Theme.inlineLocationDrawable.getIntrinsicWidth();
            int h = Theme.inlineLocationDrawable.getIntrinsicHeight();
            int x = linkImageView.getImageX() + (AndroidUtilities.dp(52) - w) / 2;
            int y = linkImageView.getImageY() + (AndroidUtilities.dp(52) - h) / 2;
            canvas.drawRect(linkImageView.getImageX(), linkImageView.getImageY(),
                    linkImageView.getImageX() + AndroidUtilities.dp(52),
                    linkImageView.getImageY() + AndroidUtilities.dp(52), LetterDrawable.paint);
            Theme.inlineLocationDrawable.setBounds(x, y, x + w, y + h);
            Theme.inlineLocationDrawable.draw(canvas);
        } else {
            letterDrawable.draw(canvas);
        }
    } else {
        if (inlineResult != null && (inlineResult.send_message instanceof TLRPC.TL_botInlineMessageMediaGeo
                || inlineResult.send_message instanceof TLRPC.TL_botInlineMessageMediaVenue)) {
            int w = Theme.inlineLocationDrawable.getIntrinsicWidth();
            int h = Theme.inlineLocationDrawable.getIntrinsicHeight();
            int x = linkImageView.getImageX() + (linkImageView.getImageWidth() - w) / 2;
            int y = linkImageView.getImageY() + (linkImageView.getImageHeight() - h) / 2;
            canvas.drawRect(linkImageView.getImageX(), linkImageView.getImageY(),
                    linkImageView.getImageX() + linkImageView.getImageWidth(),
                    linkImageView.getImageY() + linkImageView.getImageHeight(), LetterDrawable.paint);
            Theme.inlineLocationDrawable.setBounds(x, y, x + w, y + h);
            Theme.inlineLocationDrawable.draw(canvas);
        }
    }
    if (drawLinkImageView) {
        canvas.save();
        if (scaled && scale != 0.8f || !scaled && scale != 1.0f) {
            long newTime = System.currentTimeMillis();
            long dt = (newTime - lastUpdateTime);
            lastUpdateTime = newTime;
            if (scaled && scale != 0.8f) {
                scale -= dt / 400.0f;
                if (scale < 0.8f) {
                    scale = 0.8f;
                }
            } else {
                scale += dt / 400.0f;
                if (scale > 1.0f) {
                    scale = 1.0f;
                }
            }
            invalidate();
        }
        canvas.scale(scale, scale, getMeasuredWidth() / 2, getMeasuredHeight() / 2);
        linkImageView.draw(canvas);
        canvas.restore();
    }
    if (mediaWebpage && (documentAttachType == DOCUMENT_ATTACH_TYPE_PHOTO
            || documentAttachType == DOCUMENT_ATTACH_TYPE_GIF)) {
        radialProgress.setProgressColor(0xffffffff);
        radialProgress.draw(canvas);
    }

    if (needDivider && !mediaWebpage) {
        if (LocaleController.isRTL) {
            canvas.drawLine(0, getMeasuredHeight() - 1,
                    getMeasuredWidth() - AndroidUtilities.dp(AndroidUtilities.leftBaseline),
                    getMeasuredHeight() - 1, paint);
        } else {
            canvas.drawLine(AndroidUtilities.dp(AndroidUtilities.leftBaseline), getMeasuredHeight() - 1,
                    getMeasuredWidth(), getMeasuredHeight() - 1, paint);
        }
    }
    if (needShadow && shadowDrawable != null) {
        shadowDrawable.setBounds(0, 0, getMeasuredWidth(), AndroidUtilities.dp(3));
        shadowDrawable.draw(canvas);
    }
}

From source file:net.toload.main.hd.candidate.CandidateView.java

private void doDraw(Canvas canvas) {

    if (mSuggestions == null)
        return;/*from  ww  w  .ja  v  a2  s. com*/
    if (DEBUG)
        Log.i(TAG, "CandidateView:doDraw():Suggestion mCount:" + mCount + " mSuggestions.size:"
                + mSuggestions.size());
    mTotalWidth = 0;

    updateFontSize();

    if (mBgPadding == null) {
        mBgPadding = new Rect(0, 0, 0, 0);
        if (getBackground() != null) {
            getBackground().getPadding(mBgPadding);
        }
    }

    final int height = mHeight;
    final Rect bgPadding = mBgPadding;
    final Paint candidatePaint = mCandidatePaint;
    final Paint candidateEmojiPaint = mCandidatePaint;
    candidateEmojiPaint.setTextSize((float) (candidateEmojiPaint.getTextSize() * 0.9));

    final Paint selKeyPaint = mSelKeyPaint;
    final int touchX = mTouchX;
    final int scrollX = getScrollX();
    final boolean scrolled = mScrolled;

    final int textBaseLine = (int) (((height - mCandidatePaint.getTextSize()) / 2) - mCandidatePaint.ascent());

    // Modified by jeremy '10, 3, 29.  Update mselectedindex if touched and build wordX[i] and wordwidth[i]
    int x = 0;
    final int count = mCount; //Cache count here '11,8,18
    for (int i = 0; i < count; i++) {
        if (count != mCount || mSuggestions == null || count != mSuggestions.size() || mSuggestions.size() == 0
                || i >= mSuggestions.size())
            return; // mSuggestion is updated, force abort

        String suggestion = mSuggestions.get(i).getWord();
        if (i == 0 && mSuggestions.size() > 1 && mSuggestions.get(1).isRuntimeBuiltPhraseRecord()
                && suggestion.length() > 8) {
            suggestion = suggestion.substring(0, 2) + "..";
        }
        float base = (suggestion == null) ? 0 : candidatePaint.measureText("");
        float textWidth = (suggestion == null) ? 0 : candidatePaint.measureText(suggestion);

        if (textWidth < base) {
            textWidth = base;
        }

        final int wordWidth = (int) textWidth + X_GAP * 2;

        mWordX[i] = x;

        mWordWidth[i] = wordWidth;

        if (touchX + scrollX >= x && touchX + scrollX < x + wordWidth && !scrolled) {
            mSelectedIndex = i;
        }
        x += wordWidth;
    }

    mTotalWidth = x;

    if (DEBUG)
        Log.i(TAG,
                "CandidateView:doDraw():mTotalWidth :" + mTotalWidth + "  this.getWidth():" + this.getWidth());

    //Jeremy '11,8,11. If the candidate list is within 1 page and has more records, get full records first.
    if (mTotalWidth < this.getWidth())
        checkHasMoreRecords();

    // Paint all the suggestions and lines.
    if (canvas != null) {

        // Moved from above by jeremy '10 3, 29. Paint mSelectedindex in highlight here
        if (count > 0 && mSelectedIndex >= 0) {
            //    candidatePaint.setColor(mColorComposingCode);
            //    canvas.drawRect(mWordX[mSelectedIndex],bgPadding.top, mWordWidth[mSelectedIndex] , height, candidatePaint);

            canvas.translate(mWordX[mSelectedIndex], 0);
            mDrawableSuggestHighlight.setBounds(0, bgPadding.top, mWordWidth[mSelectedIndex], height);
            mDrawableSuggestHighlight.draw(canvas);
            canvas.translate(-mWordX[mSelectedIndex], 0);

        }
        if (mTransparentCandidateView) {
            canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);

            Paint backgroundPaint = new Paint();
            backgroundPaint.setColor(ContextCompat.getColor(mContext, R.color.third_background_light));
            backgroundPaint.setAlpha(33);
            backgroundPaint.setStyle(Paint.Style.FILL);

            canvas.drawRect(0.5f, bgPadding.top, mScreenWidth, height, backgroundPaint);
        }

        for (int i = 0; i < count; i++) {

            if (count != mCount || mSuggestions == null || count != mSuggestions.size()
                    || mSuggestions.size() == 0 || i >= mSuggestions.size())
                break;

            boolean isEmoji = mSuggestions.get(i).isEmojiRecord();
            String suggestion = mSuggestions.get(i).getWord();
            if (i == 0 && mSuggestions.size() > 1 && mSuggestions.get(1).isRuntimeBuiltPhraseRecord()
                    && suggestion.length() > 8) {
                suggestion = suggestion.substring(0, 2) + "..";
            }

            int c = i + 1;
            switch (mSuggestions.get(i).getRecordType()) {
            case Mapping.RECORD_COMPOSING_CODE:
                if (mSelectedIndex == 0) {

                    if (mTransparentCandidateView) {
                        candidatePaint.setColor(mColorInvertedTextTransparent);
                    } else {
                        candidatePaint.setColor(mColorComposingCodeHighlight);
                    }
                } else
                    candidatePaint.setColor(mColorComposingCode);
                break;
            case Mapping.RECORD_CHINESE_PUNCTUATION_SYMBOL:
            case Mapping.RECORD_RELATED_PHRASE:
                selKeyPaint.setColor(mColorSelKeyShifted);
                if (i == mSelectedIndex)
                    candidatePaint.setColor(mColorNormalTextHighlight);
                else
                    candidatePaint.setColor(mColorNormalText);
                break;
            case Mapping.RECORD_EXACT_MATCH_TO_CODE:
            case Mapping.RECORD_PARTIAL_MATCH_TO_CODE:
            case Mapping.RECORD_RUNTIME_BUILT_PHRASE:
            case Mapping.RECORD_ENGLISH_SUGGESTION:
            default:
                selKeyPaint.setColor(mColorSelKey);
                if (i == mSelectedIndex)
                    candidatePaint.setColor(mColorNormalTextHighlight);
                else
                    candidatePaint.setColor(mColorNormalText);
                break;

            }

            if (isEmoji) {
                canvas.drawText(suggestion, mWordX[i] + X_GAP, Math.round(textBaseLine * 0.95),
                        candidateEmojiPaint);
            } else {
                canvas.drawText(suggestion, mWordX[i] + X_GAP, textBaseLine, candidatePaint);
            }
            if (mShowNumber) {
                //Jeremy '11,6,17 changed from <=10 to mDisplaySelkey length. The length maybe 11 or 12 if shifted with space.
                if (c <= mDisplaySelkey.length()) {
                    //Jeremy '11,6,11 Drawing text using relative font dimensions.
                    canvas.drawText(mDisplaySelkey.substring(c - 1, c),
                            mWordX[i] + mWordWidth[i] - height * 0.3f, height * 0.4f, selKeyPaint);
                }
            }
            //Draw spacer
            candidatePaint.setColor(mColorSpacer);
            canvas.drawLine(mWordX[i] + mWordWidth[i] + 0.5f, bgPadding.top + (mVerticalPadding / 2),
                    mWordX[i] + mWordWidth[i] + 0.5f, height - (mVerticalPadding / 2), candidatePaint);
            candidatePaint.setFakeBoldText(false);

        }

        if (mTargetScrollX != getScrollX()) {
            if (DEBUG)
                Log.i(TAG, "CandidateView:doDraw():mTargetScrollX :" + mTargetScrollX + "  getScrollX():"
                        + getScrollX());
            scrollToTarget();
        }

    }

}

From source file:com.anysoftkeyboard.keyboards.views.AnyKeyboardBaseView.java

private void onBufferDraw(Canvas canvas) {
    if (mKeyboardChanged) {
        invalidateAllKeys();//w  ww  .  ja  v  a2  s  .c  om
        mKeyboardChanged = false;
    }

    canvas.getClipBounds(mDirtyRect);

    if (mKeyboard == null)
        return;

    final boolean drawKeyboardNameText = (mKeyboardNameTextSize > 1f)
            && AnyApplication.getConfig().getShowKeyboardNameText();

    final boolean drawHintText = (mHintTextSize > 1) && AnyApplication.getConfig().getShowHintTextOnKeys();
    // TODO: calls to AnyApplication.getConfig().getXXXXX() functions are
    // not yet implemented,
    // but need to when allowing preferences to override theme settings of
    // these values
    // right now just using what should be the default values for these
    // unimplemented preferences

    final boolean useCustomKeyTextColor = false;
    // TODO: final boolean useCustomKeyTextColor =
    // AnyApplication.getConfig().getUseCustomTextColorOnKeys();
    final ColorStateList keyTextColor = useCustomKeyTextColor
            ? new ColorStateList(new int[][] { { 0 } }, new int[] { 0xFF6666FF })
            : mKeyTextColor;
    // TODO: ? AnyApplication.getConfig().getCustomKeyTextColorOnKeys() :
    // mKeyTextColor;

    final boolean useCustomHintColor = drawHintText && false;
    // TODO: final boolean useCustomHintColor = drawHintText &&
    // AnyApplication.getConfig().getUseCustomHintColorOnKeys();
    final ColorStateList hintColor = useCustomHintColor
            ? new ColorStateList(new int[][] { { 0 } }, new int[] { 0xFFFF6666 })
            : mHintTextColor;
    // TODO: ? AnyApplication.getConfig().getCustomHintColorOnKeys() :
    // mHintTextColor;

    // allow preferences to override theme settings for hint text position
    final boolean useCustomHintAlign = drawHintText && AnyApplication.getConfig().getUseCustomHintAlign();
    final int hintAlign = useCustomHintAlign ? AnyApplication.getConfig().getCustomHintAlign()
            : mHintLabelAlign;
    final int hintVAlign = useCustomHintAlign ? AnyApplication.getConfig().getCustomHintVAlign()
            : mHintLabelVAlign;

    final Paint paint = mPaint;
    final Drawable keyBackground = mKeyBackground;
    final Rect clipRegion = mClipRegion;
    final int kbdPaddingLeft = getPaddingLeft();
    final int kbdPaddingTop = getPaddingTop();
    final Key[] keys = mKeys;
    final Key invalidKey = mInvalidatedKey;

    boolean drawSingleKey = false;
    if (invalidKey != null && canvas.getClipBounds(clipRegion)) {
        // TODO we should use Rect.inset and Rect.contains here.
        // Is clipRegion completely contained within the invalidated key?
        if (invalidKey.x + kbdPaddingLeft - 1 <= clipRegion.left
                && invalidKey.y + kbdPaddingTop - 1 <= clipRegion.top
                && invalidKey.x + invalidKey.width + kbdPaddingLeft + 1 >= clipRegion.right
                && invalidKey.y + invalidKey.height + kbdPaddingTop + 1 >= clipRegion.bottom) {
            drawSingleKey = true;
        }
    }
    final int keyCount = keys.length;
    for (int i = 0; i < keyCount; i++) {
        final AnyKey key = (AnyKey) keys[i];
        final boolean keyIsSpace = isSpaceKey(key);

        if (drawSingleKey && (invalidKey != key)) {
            continue;
        }
        if (!mDirtyRect.intersects(key.x + kbdPaddingLeft, key.y + kbdPaddingTop,
                key.x + key.width + kbdPaddingLeft, key.y + key.height + kbdPaddingTop)) {
            continue;
        }
        int[] drawableState = key.getCurrentDrawableState(mDrawableStatesProvider);

        if (keyIsSpace)
            paint.setColor(mKeyboardNameTextColor.getColorForState(drawableState, 0xFF000000));
        else
            paint.setColor(keyTextColor.getColorForState(drawableState, 0xFF000000));
        keyBackground.setState(drawableState);

        // Switch the character to uppercase if shift is pressed
        CharSequence label = key.label == null ? null : adjustCase(key).toString();

        final Rect bounds = keyBackground.getBounds();
        if ((key.width != bounds.right) || (key.height != bounds.bottom)) {
            keyBackground.setBounds(0, 0, key.width, key.height);
        }
        canvas.translate(key.x + kbdPaddingLeft, key.y + kbdPaddingTop);
        keyBackground.draw(canvas);

        if (TextUtils.isEmpty(label)) {
            Drawable iconToDraw = getIconToDrawForKey(key, false);
            if (iconToDraw != null/* && shouldDrawIcon */) {
                //http://developer.android.com/reference/android/graphics/drawable/Drawable.html#getCurrent()
                //http://stackoverflow.com/a/103600/1324235
                final boolean is9Patch = iconToDraw.getCurrent() instanceof NinePatchDrawable;

                // Special handing for the upper-right number hint icons
                final int drawableWidth;
                final int drawableHeight;
                final int drawableX;
                final int drawableY;

                drawableWidth = is9Patch ? key.width : iconToDraw.getIntrinsicWidth();
                drawableHeight = is9Patch ? key.height : iconToDraw.getIntrinsicHeight();
                drawableX = (key.width + mKeyBackgroundPadding.left - mKeyBackgroundPadding.right
                        - drawableWidth) / 2;
                drawableY = (key.height + mKeyBackgroundPadding.top - mKeyBackgroundPadding.bottom
                        - drawableHeight) / 2;

                canvas.translate(drawableX, drawableY);
                iconToDraw.setBounds(0, 0, drawableWidth, drawableHeight);
                iconToDraw.draw(canvas);
                canvas.translate(-drawableX, -drawableY);
                if (keyIsSpace && drawKeyboardNameText) {
                    // now a little hack, I'll set the label now, so it get
                    // drawn.
                    label = mKeyboardName;
                }
            } else {
                // ho... no icon.
                // I'll try to guess the text
                label = guessLabelForKey(key.codes[0]);
                if (TextUtils.isEmpty(label)) {
                    Log.w(TAG, "That's unfortunate, for key " + key.codes[0] + " at (" + key.x + ", " + key.y
                            + ") there is no icon nor label. Action ID is " + mKeyboardActionType);
                }
            }
        }

        if (label != null) {
            // For characters, use large font. For labels like "Done", use
            // small font.
            final FontMetrics fm;
            if (keyIsSpace) {
                paint.setTextSize(mKeyboardNameTextSize);
                paint.setTypeface(Typeface.DEFAULT_BOLD);
                if (mKeyboardNameFM == null)
                    mKeyboardNameFM = paint.getFontMetrics();
                fm = mKeyboardNameFM;
            } else if (label.length() > 1 && key.codes.length < 2) {
                paint.setTextSize(mLabelTextSize);
                paint.setTypeface(Typeface.DEFAULT_BOLD);
                if (mLabelFM == null)
                    mLabelFM = paint.getFontMetrics();
                fm = mLabelFM;
            } else {
                fm = setPaintToKeyText(paint);
            }

            final float labelHeight = -fm.top;
            // Draw a drop shadow for the text
            paint.setShadowLayer(mShadowRadius, mShadowOffsetX, mShadowOffsetY, mShadowColor);

            // (+)This is the trick to get RTL/LTR text correct
            // no matter what: StaticLayout
            // this should be in the top left corner of the key
            float textWidth = paint.measureText(label, 0, label.length());
            // I'm going to try something if the key is too small for the
            // text:
            // 1) divide the text size by 1.5
            // 2) if still too large, divide by 2.5
            // 3) show no text
            if (textWidth > key.width) {
                Log.d(TAG, "Label '" + label + "' is too large for the key. Reducing by 1.5.");
                paint.setTextSize(mKeyTextSize / 1.5f);
                textWidth = paint.measureText(label, 0, label.length());
                if (textWidth > key.width) {
                    Log.d(TAG, "Label '" + label + "' is too large for the key. Reducing by 2.5.");
                    paint.setTextSize(mKeyTextSize / 2.5f);
                    textWidth = paint.measureText(label, 0, label.length());
                    if (textWidth > key.width) {
                        Log.d(TAG, "Label '" + label + "' is too large for the key. Showing no text.");
                        paint.setTextSize(0f);
                        textWidth = paint.measureText(label, 0, label.length());
                    }
                }
            }

            // the center of the drawable space, which is value used
            // previously for vertically
            // positioning the key label
            final float centerY = mKeyBackgroundPadding.top
                    + ((key.height - mKeyBackgroundPadding.top - mKeyBackgroundPadding.bottom)
                            / (keyIsSpace ? 3 : 2));// the label on the space is a bit higher

            // the X coordinate for the center of the main label text is
            // unaffected by the hints
            final float centerX = mKeyBackgroundPadding.left
                    + (key.width - mKeyBackgroundPadding.left - mKeyBackgroundPadding.right) / 2;

            final float textX = centerX;
            final float textY;
            // Some devices (mostly pre-Honeycomb, have issues with RTL text
            // drawing.
            // Of course, there is no issue with a single character :)
            // so, we'll use the RTL secured drawing (via StaticLayout) for
            // labels.
            if (label.length() > 1 && !AnyApplication.getConfig().workaround_alwaysUseDrawText()) {
                // calculate Y coordinate of top of text based on center
                // location
                textY = centerY - ((labelHeight - paint.descent()) / 2);
                canvas.translate(textX, textY);
                Log.d(TAG, "Using RTL fix for key draw '" + label + "'");
                // RTL fix. But it costs, let do it when in need (more than
                // 1 character)
                StaticLayout labelText = new StaticLayout(label, new TextPaint(paint), (int) textWidth,
                        Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
                labelText.draw(canvas);
            } else {
                // to get Y coordinate of baseline from center of text,
                // first add half the height (to get to
                // bottom of text), then subtract the part below the
                // baseline. Note that fm.top is negative.
                textY = centerY + ((labelHeight - paint.descent()) / 2);
                canvas.translate(textX, textY);
                canvas.drawText(label, 0, label.length(), 0, 0, paint);
            }
            canvas.translate(-textX, -textY);
            // (-)

            // Turn off drop shadow
            paint.setShadowLayer(0, 0, 0, 0);
        }

        if (drawHintText) {
            if ((key.popupCharacters != null && key.popupCharacters.length() > 0) || (key.popupResId != 0)
                    || (key.longPressCode != 0)) {
                Paint.Align oldAlign = paint.getTextAlign();

                String hintText = null;

                if (key.hintLabel != null && key.hintLabel.length() > 0) {
                    hintText = key.hintLabel.toString();
                    // it is the responsibility of the keyboard layout
                    // designer to ensure that they do
                    // not put too many characters in the hint label...
                } else if (key.longPressCode != 0) {
                    if (Character.isLetterOrDigit(key.longPressCode))
                        hintText = Character.toString((char) key.longPressCode);
                } else if (key.popupCharacters != null) {
                    final String hintString = key.popupCharacters.toString();
                    final int hintLength = hintString.length();
                    if (hintLength <= 3)
                        hintText = hintString;
                }

                // if hintText is still null, it means it didn't fit one of
                // the above
                // cases, so we should provide the hint using the default
                if (hintText == null) {
                    if (mHintOverflowLabel != null)
                        hintText = mHintOverflowLabel.toString();
                    else {
                        // theme does not provide a defaultHintLabel
                        // use  if hints are above, ... if hints are
                        // below
                        // (to avoid being too close to main label/icon)
                        if (hintVAlign == Gravity.TOP)
                            hintText = "";
                        else
                            hintText = "...";
                    }
                }

                if (mKeyboard.isShifted())
                    hintText = hintText.toUpperCase();

                // now draw hint
                paint.setTypeface(Typeface.DEFAULT);
                paint.setColor(hintColor.getColorForState(drawableState, 0xFF000000));
                paint.setTextSize(mHintTextSize);
                // get the hint text font metrics so that we know the size
                // of the hint when
                // we try to position the main label (to try to make sure
                // they don't overlap)
                if (mHintTextFM == null) {
                    mHintTextFM = paint.getFontMetrics();
                }

                final float hintX;
                final float hintY;

                // the (float) 0.5 value is added or subtracted to just give
                // a little more room
                // in case the theme designer didn't account for the hint
                // label location
                if (hintAlign == Gravity.LEFT) {
                    // left
                    paint.setTextAlign(Paint.Align.LEFT);
                    hintX = mKeyBackgroundPadding.left + (float) 0.5;
                } else if (hintAlign == Gravity.CENTER) {
                    // center
                    paint.setTextAlign(Paint.Align.CENTER);
                    hintX = mKeyBackgroundPadding.left
                            + (key.width - mKeyBackgroundPadding.left - mKeyBackgroundPadding.right) / 2;
                } else {
                    // right
                    paint.setTextAlign(Paint.Align.RIGHT);
                    hintX = key.width - mKeyBackgroundPadding.right - (float) 0.5;
                }

                if (hintVAlign == Gravity.TOP) {
                    // above
                    hintY = mKeyBackgroundPadding.top - mHintTextFM.top + (float) 0.5;
                } else {
                    // below
                    hintY = key.height - mKeyBackgroundPadding.bottom - mHintTextFM.bottom - (float) 0.5;
                }

                canvas.drawText(hintText, hintX, hintY, paint);
                paint.setTextAlign(oldAlign);
            }
        }

        canvas.translate(-key.x - kbdPaddingLeft, -key.y - kbdPaddingTop);
    }
    mInvalidatedKey = null;
    // Overlay a dark rectangle to dim the keyboard
    if (mMiniKeyboard != null && mMiniKeyboardVisible) {
        paint.setColor((int) (mBackgroundDimAmount * 0xFF) << 24);
        canvas.drawRect(0, 0, getWidth(), getHeight(), paint);
    }

    if (FeaturesSet.DEBUG_LOG) {
        if (mShowTouchPoints) {
            for (PointerTracker tracker : mPointerTrackers) {
                int startX = tracker.getStartX();
                int startY = tracker.getStartY();
                int lastX = tracker.getLastX();
                int lastY = tracker.getLastY();
                paint.setAlpha(128);
                paint.setColor(0xFFFF0000);
                canvas.drawCircle(startX, startY, 3, paint);
                canvas.drawLine(startX, startY, lastX, lastY, paint);
                paint.setColor(0xFF0000FF);
                canvas.drawCircle(lastX, lastY, 3, paint);
                paint.setColor(0xFF00FF00);
                canvas.drawCircle((startX + lastX) / 2, (startY + lastY) / 2, 2, paint);
            }
        }
    }

    mDrawPending = false;
    mDirtyRect.setEmpty();
}