Example usage for android.graphics Canvas drawRect

List of usage examples for android.graphics Canvas drawRect

Introduction

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

Prototype

public void drawRect(float left, float top, float right, float bottom, @NonNull Paint paint) 

Source Link

Document

Draw the specified Rect using the specified paint.

Usage

From source file:net.droidsolutions.droidcharts.core.renderer.xy.AbstractXYItemRenderer.java

/**
 * Draws a horizontal line across the chart to represent a 'range marker'.
 *
 * @param g2  the graphics device./*from ww  w  .j av  a 2  s .  c om*/
 * @param plot  the plot.
 * @param rangeAxis  the range axis.
 * @param marker  the marker line.
 * @param dataArea  the axis data area.
 */
public void drawRangeMarker(Canvas g2, XYPlot plot, ValueAxis rangeAxis, Marker marker, Rectangle2D dataArea) {

    if (marker instanceof ValueMarker) {
        ValueMarker vm = (ValueMarker) marker;
        double value = vm.getValue();
        Range range = rangeAxis.getRange();
        if (!range.contains(value)) {
            return;
        }

        double v = rangeAxis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge());
        PlotOrientation orientation = plot.getOrientation();
        Line2D line = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            line = new Line2D.Double(v, dataArea.getMinY(), v, dataArea.getMaxY());
        } else if (orientation == PlotOrientation.VERTICAL) {
            line = new Line2D.Double(dataArea.getMinX(), v, dataArea.getMaxX(), v);
        }

        Paint oPiant = marker.getPaint();
        oPiant.setStyle(Paint.Style.STROKE);
        int oOldAlpha = oPiant.getAlpha();
        oPiant.setAlpha(marker.getAlpha());
        oPiant.setStrokeWidth(marker.getStroke());
        g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(), (float) line.getY2(),
                oPiant);
        oPiant.setAlpha(oOldAlpha);
        String label = marker.getLabel();
        RectangleAnchor anchor = marker.getLabelAnchor();
        if (label != null) {
            Font labelFont = marker.getLabelFont();
            Paint paint = marker.getLabelPaint();
            paint.setTypeface(labelFont.getTypeFace());
            paint.setTextSize(labelFont.getSize());
            Point2D coordinates = calculateRangeMarkerTextAnchorPoint(g2, orientation, dataArea,
                    line.getBounds2D(), marker.getLabelOffset(), LengthAdjustmentType.EXPAND, anchor);
            TextUtilities.drawAlignedString(label, g2, (float) coordinates.getX(), (float) coordinates.getY(),
                    marker.getLabelTextAnchor(), paint);
        }

    } else if (marker instanceof IntervalMarker) {
        IntervalMarker im = (IntervalMarker) marker;
        double start = im.getStartValue();
        double end = im.getEndValue();
        Range range = rangeAxis.getRange();
        if (!(range.intersects(start, end))) {
            return;
        }

        double start2d = rangeAxis.valueToJava2D(start, dataArea, plot.getRangeAxisEdge());
        double end2d = rangeAxis.valueToJava2D(end, dataArea, plot.getRangeAxisEdge());
        double low = Math.min(start2d, end2d);
        double high = Math.max(start2d, end2d);

        PlotOrientation orientation = plot.getOrientation();
        Rectangle2D rect = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            // clip left and right bounds to data area
            low = Math.max(low, dataArea.getMinX());
            high = Math.min(high, dataArea.getMaxX());
            rect = new Rectangle2D.Double(low, dataArea.getMinY(), high - low, dataArea.getHeight());
        } else if (orientation == PlotOrientation.VERTICAL) {
            // clip top and bottom bounds to data area
            low = Math.max(low, dataArea.getMinY());
            high = Math.min(high, dataArea.getMaxY());
            rect = new Rectangle2D.Double(dataArea.getMinX(), low, dataArea.getWidth(), high - low);
        }

        Paint p = marker.getPaint();
        int oldAlpha = p.getAlpha();
        p.setAlpha(marker.getAlpha());
        p.setStyle(Paint.Style.FILL);

        g2.drawRect((float) rect.getMinX(), (float) rect.getMinY(), (float) rect.getMaxX(),
                (float) rect.getMaxY(), p);
        p.setAlpha(oldAlpha);

        // now draw the outlines, if visible...
        if (im.getOutlinePaint() != null && im.getOutlineStroke() != null) {
            if (orientation == PlotOrientation.VERTICAL) {
                Line2D line = new Line2D.Double();
                double x0 = dataArea.getMinX();
                double x1 = dataArea.getMaxX();
                Paint oPiant = im.getOutlinePaint();
                oPiant.setStyle(Paint.Style.STROKE);
                int oOldAlpha = oPiant.getAlpha();
                oPiant.setAlpha(marker.getAlpha());
                oPiant.setStrokeWidth(im.getOutlineStroke());
                if (range.contains(start)) {
                    line.setLine(x0, start2d, x1, start2d);
                    g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(),
                            (float) line.getY2(), oPiant);
                }
                if (range.contains(end)) {
                    line.setLine(x0, end2d, x1, end2d);
                    g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(),
                            (float) line.getY2(), oPiant);
                }
                oPiant.setAlpha(oOldAlpha);
            } else { // PlotOrientation.HORIZONTAL
                Line2D line = new Line2D.Double();
                double y0 = dataArea.getMinY();
                double y1 = dataArea.getMaxY();
                Paint oPiant = im.getOutlinePaint();
                oPiant.setStyle(Paint.Style.STROKE);
                int oOldAlpha = oPiant.getAlpha();
                oPiant.setAlpha(marker.getAlpha());
                oPiant.setStrokeWidth(im.getOutlineStroke());
                if (range.contains(start)) {
                    line.setLine(start2d, y0, start2d, y1);
                    g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(),
                            (float) line.getY2(), oPiant);
                }
                if (range.contains(end)) {
                    line.setLine(end2d, y0, end2d, y1);
                    g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(),
                            (float) line.getY2(), oPiant);
                }
                oPiant.setAlpha(oOldAlpha);
            }
        }

        String label = marker.getLabel();
        RectangleAnchor anchor = marker.getLabelAnchor();
        if (label != null) {
            Font labelFont = marker.getLabelFont();

            Paint paint = marker.getLabelPaint();
            paint.setTypeface(labelFont.getTypeFace());
            paint.setTextSize(labelFont.getSize());
            Point2D coordinates = calculateRangeMarkerTextAnchorPoint(g2, orientation, dataArea, rect,
                    marker.getLabelOffset(), marker.getLabelOffsetType(), anchor);
            TextUtilities.drawAlignedString(label, g2, (float) coordinates.getX(), (float) coordinates.getY(),
                    marker.getLabelTextAnchor(), paint);
        }
    }
}

From source file:com.aidy.bottomdrawerlayout.AllDrawerLayout.java

@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
    Log.i(TAG, "drawChild()");
    final int height = getHeight();
    final boolean drawingContent = isContentView(child);
    int clipLeft = 0, clipRight = getWidth();
    int clipTop = 0, clipBottom = getHeight();

    final int restoreCount = canvas.save();
    if (drawingContent) {
        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            final View v = getChildAt(i);
            if (v == child || v.getVisibility() != VISIBLE || !hasOpaqueBackground(v) || !isDrawerView(v)
                    || v.getHeight() < height) {
                Log.i(TAG, "drawChild() -- 0");
                continue;
            }//from www  .j a  va 2  s .c  o  m
            switch (getDrawerViewAbsoluteGravity(v)) {
            case Gravity.LEFT:
                Log.i(TAG, "drawChild() -- 1");
                if (checkDrawerViewAbsoluteGravity(v, Gravity.LEFT)) {
                    final int vright = v.getRight();
                    if (vright > clipLeft)
                        clipLeft = vright;
                }
                break;
            case Gravity.RIGHT:
                Log.i(TAG, "drawChild() -- 2");
                if (checkDrawerViewAbsoluteGravity(v, Gravity.RIGHT)) {
                    final int vleft = v.getLeft();
                    if (vleft < clipRight)
                        clipRight = vleft;
                }
                break;
            case Gravity.TOP:
                Log.i(TAG, "drawChild() -- 3");
                if (checkDrawerViewAbsoluteGravity(v, Gravity.TOP)) {
                    final int vbottom = v.getBottom();
                    if (vbottom > clipTop) {
                        clipTop = vbottom;
                    }
                }
                break;
            case Gravity.BOTTOM:
                Log.i(TAG, "drawChild() -- 4");
                if (checkDrawerViewAbsoluteGravity(v, Gravity.BOTTOM)) {
                    final int vtop = v.getTop();
                    if (vtop < clipBottom) {
                        clipBottom = vtop;
                    }
                }
                break;
            default:
                Log.i(TAG, "drawChild() -- 5");
                final int vtop = v.getTop();
                if (vtop < clipBottom) {
                    clipBottom = vtop;
                }
                break;
            }
        }
        canvas.clipRect(clipLeft, clipTop, clipRight, clipBottom);
    }
    final boolean result = super.drawChild(canvas, child, drawingTime);
    canvas.restoreToCount(restoreCount);

    if (mScrimOpacity > 0 && drawingContent) {
        Log.i(TAG, "drawChild() -- drawingContent");
        final int baseAlpha = (mScrimColor & 0xff000000) >>> 24;
        final int imag = (int) (baseAlpha * mScrimOpacity);
        final int color = imag << 24 | (mScrimColor & 0xffffff);
        mScrimPaint.setColor(color);
        canvas.drawRect(clipLeft, clipTop, clipRight, clipBottom, mScrimPaint);
    } else if (mShadowLeft != null && checkDrawerViewAbsoluteGravity(child, Gravity.LEFT)) {
        Log.i(TAG, "drawChild() -- LEFT");
        final int shadowWidth = mShadowLeft.getIntrinsicWidth();
        final int childRight = child.getRight();
        final int drawerPeekDistance = mLeftDragger.getEdgeSize();
        final float alpha = Math.max(0, Math.min((float) childRight / drawerPeekDistance, 1.f));
        mShadowLeft.setBounds(childRight, child.getTop(), childRight + shadowWidth, child.getBottom());
        mShadowLeft.setAlpha((int) (0xff * alpha));
        mShadowLeft.draw(canvas);
    } else if (mShadowRight != null && checkDrawerViewAbsoluteGravity(child, Gravity.RIGHT)) {
        Log.i(TAG, "drawChild() -- Gravity.RIGHT");
        final int shadowWidth = mShadowRight.getIntrinsicWidth();
        final int childLeft = child.getLeft();
        final int showing = getWidth() - childLeft;
        final int drawerPeekDistance = mRightDragger.getEdgeSize();
        final float alpha = Math.max(0, Math.min((float) showing / drawerPeekDistance, 1.f));
        mShadowRight.setBounds(childLeft - shadowWidth, child.getTop(), childLeft, child.getBottom());
        mShadowRight.setAlpha((int) (0xff * alpha));
        mShadowRight.draw(canvas);
    } else if (mShadowTop != null && checkDrawerViewAbsoluteGravity(child, Gravity.TOP)) {
        Log.i(TAG, "drawChild() -- Gravity.TOP");
        final int shadowHeight = mShadowTop.getIntrinsicHeight();
        final int childBottom = child.getBottom();
        final int drawerPeekDistance = mTopDragger.getEdgeSize();
        final float alpha = Math.max(0, Math.min((float) childBottom / drawerPeekDistance, 1.f));
        mShadowTop.setBounds(child.getLeft(), childBottom, child.getRight(), childBottom + shadowHeight);
        mShadowTop.setAlpha((int) (0xff * alpha));
        mShadowTop.draw(canvas);
    } else if (mShadowBottom != null && checkDrawerViewAbsoluteGravity(child, Gravity.BOTTOM)) {
        Log.i(TAG, "drawChild() -- Gravity.BOTTOM");
        final int shadowHeight = mShadowBottom.getIntrinsicWidth();
        final int childTop = child.getTop();
        final int showing = getHeight() - childTop;
        final int drawerPeekDistance = mBottomDragger.getEdgeSize();
        final float alpha = Math.max(0, Math.min((float) showing / drawerPeekDistance, 1.f));
        mShadowRight.setBounds(child.getLeft(), childTop - shadowHeight, child.getRight(), childTop);
        mShadowRight.setAlpha((int) (0xff * alpha));
        mShadowRight.draw(canvas);
    }
    return result;
}

From source file:net.droidsolutions.droidcharts.core.renderer.xy.AbstractXYItemRenderer.java

/**
 * Draws a vertical line on the chart to represent a 'range marker'.
 *
 * @param g2  the graphics device./*ww w  .  j av a  2 s  .com*/
 * @param plot  the plot.
 * @param domainAxis  the domain axis.
 * @param marker  the marker line.
 * @param dataArea  the axis data area.
 */
public void drawDomainMarker(Canvas g2, XYPlot plot, ValueAxis domainAxis, Marker marker,
        Rectangle2D dataArea) {

    if (marker instanceof ValueMarker) {
        ValueMarker vm = (ValueMarker) marker;
        double value = vm.getValue();
        Range range = domainAxis.getRange();
        if (!range.contains(value)) {
            return;
        }

        double v = domainAxis.valueToJava2D(value, dataArea, plot.getDomainAxisEdge());

        PlotOrientation orientation = plot.getOrientation();
        Line2D line = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            line = new Line2D.Double(dataArea.getMinX(), v, dataArea.getMaxX(), v);
        } else if (orientation == PlotOrientation.VERTICAL) {
            line = new Line2D.Double(v, dataArea.getMinY(), v, dataArea.getMaxY());
        }

        Paint paint = marker.getPaint();
        int oldAlpha = paint.getAlpha();
        paint.setAlpha(marker.getAlpha());
        Float stroke = marker.getStroke();

        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(stroke);

        g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(), (float) line.getY2(),
                paint);

        String label = marker.getLabel();
        RectangleAnchor anchor = marker.getLabelAnchor();
        if (label != null) {
            Font labelFont = marker.getLabelFont();

            Paint lPaint = marker.getLabelPaint();
            lPaint.setTypeface(labelFont.getTypeFace());
            lPaint.setTextSize(labelFont.getSize());
            int lOldAlpha = lPaint.getAlpha();
            lPaint.setAlpha(marker.getAlpha());
            Point2D coordinates = calculateDomainMarkerTextAnchorPoint(g2, orientation, dataArea,
                    line.getBounds2D(), marker.getLabelOffset(), LengthAdjustmentType.EXPAND, anchor);
            TextUtilities.drawAlignedString(label, g2, (float) coordinates.getX(), (float) coordinates.getY(),
                    marker.getLabelTextAnchor(), lPaint);
            lPaint.setAlpha(lOldAlpha);
        }
        paint.setAlpha(oldAlpha);
    } else if (marker instanceof IntervalMarker) {
        IntervalMarker im = (IntervalMarker) marker;
        double start = im.getStartValue();
        double end = im.getEndValue();
        Range range = domainAxis.getRange();
        if (!(range.intersects(start, end))) {
            return;
        }

        double start2d = domainAxis.valueToJava2D(start, dataArea, plot.getDomainAxisEdge());
        double end2d = domainAxis.valueToJava2D(end, dataArea, plot.getDomainAxisEdge());
        double low = Math.min(start2d, end2d);
        double high = Math.max(start2d, end2d);

        PlotOrientation orientation = plot.getOrientation();
        Rectangle2D rect = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            // clip top and bottom bounds to data area
            low = Math.max(low, dataArea.getMinY());
            high = Math.min(high, dataArea.getMaxY());
            rect = new Rectangle2D.Double(dataArea.getMinX(), low, dataArea.getWidth(), high - low);
        } else if (orientation == PlotOrientation.VERTICAL) {
            // clip left and right bounds to data area
            low = Math.max(low, dataArea.getMinX());
            high = Math.min(high, dataArea.getMaxX());
            rect = new Rectangle2D.Double(low, dataArea.getMinY(), high - low, dataArea.getHeight());
        }

        Paint p = marker.getPaint();
        int oldAlpha = p.getAlpha();
        p.setAlpha(marker.getAlpha());
        p.setStyle(Paint.Style.FILL);

        g2.drawRect((float) rect.getMinX(), (float) rect.getMinY(), (float) rect.getMaxX(),
                (float) rect.getMaxY(), p);
        p.setAlpha(oldAlpha);
        // now draw the outlines, if visible...
        if (im.getOutlinePaint() != null && im.getOutlineStroke() != null) {
            if (orientation == PlotOrientation.VERTICAL) {
                Line2D line = new Line2D.Double();
                double y0 = dataArea.getMinY();
                double y1 = dataArea.getMaxY();
                Paint oPiant = im.getOutlinePaint();
                oPiant.setStyle(Paint.Style.STROKE);
                int oOldAlpha = oPiant.getAlpha();
                oPiant.setAlpha(marker.getAlpha());
                oPiant.setStrokeWidth(im.getOutlineStroke());

                if (range.contains(start)) {
                    line.setLine(start2d, y0, start2d, y1);
                    g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(),
                            (float) line.getY2(), oPiant);
                }
                if (range.contains(end)) {
                    line.setLine(end2d, y0, end2d, y1);
                    g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(),
                            (float) line.getY2(), oPiant);
                }
                oPiant.setAlpha(oOldAlpha);
            } else { // PlotOrientation.HORIZONTAL
                Line2D line = new Line2D.Double();
                double x0 = dataArea.getMinX();
                double x1 = dataArea.getMaxX();
                Paint oPiant = im.getOutlinePaint();
                oPiant.setStyle(Paint.Style.STROKE);
                int oOldAlpha = oPiant.getAlpha();
                oPiant.setAlpha(marker.getAlpha());
                oPiant.setStrokeWidth(im.getOutlineStroke());
                if (range.contains(start)) {
                    line.setLine(x0, start2d, x1, start2d);
                    g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(),
                            (float) line.getY2(), oPiant);
                }
                if (range.contains(end)) {
                    line.setLine(x0, end2d, x1, end2d);
                    g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(),
                            (float) line.getY2(), oPiant);
                }
                oPiant.setAlpha(oOldAlpha);
            }
        }

        String label = marker.getLabel();
        RectangleAnchor anchor = marker.getLabelAnchor();
        if (label != null) {
            Font labelFont = marker.getLabelFont();
            Paint paint = marker.getLabelPaint();
            paint.setTypeface(labelFont.getTypeFace());
            paint.setTextSize(labelFont.getSize());
            Point2D coordinates = calculateDomainMarkerTextAnchorPoint(g2, orientation, dataArea, rect,
                    marker.getLabelOffset(), marker.getLabelOffsetType(), anchor);
            TextUtilities.drawAlignedString(label, g2, (float) coordinates.getX(), (float) coordinates.getY(),
                    marker.getLabelTextAnchor(), paint);
        }

    }

}

From source file:com.jjoe64.graphview.series.BarGraphSeries.java

/**
 * draws the bars on the canvas/*w  w  w  .j a  v  a  2 s.co m*/
 *
 * @param graphView corresponding graphview
 * @param canvas canvas
 * @param isSecondScale whether we are plotting the second scale or not
 */
@Override
public void draw(GraphView graphView, Canvas canvas, boolean isSecondScale) {
    mPaint.setTextAlign(Paint.Align.CENTER);
    if (mValuesOnTopSize == 0) {
        mValuesOnTopSize = graphView.getGridLabelRenderer().getTextSize();
    }
    mPaint.setTextSize(mValuesOnTopSize);

    resetDataPoints();

    // get data
    double maxX = graphView.getViewport().getMaxX(false);
    double minX = graphView.getViewport().getMinX(false);

    double maxY;
    double minY;
    if (isSecondScale) {
        maxY = graphView.getSecondScale().getMaxY(false);
        minY = graphView.getSecondScale().getMinY(false);
    } else {
        maxY = graphView.getViewport().getMaxY(false);
        minY = graphView.getViewport().getMinY(false);
    }

    // Iterate through all bar graph series
    // so we know how wide to make our bar,
    // and in what position to put it in
    int numBarSeries = 0;
    int currentSeriesOrder = 0;
    int numValues = 0;
    boolean isCurrentSeries;
    SortedSet<Double> xVals = new TreeSet<Double>();
    for (Series inspectedSeries : graphView.getSeries()) {
        if (inspectedSeries instanceof BarGraphSeries) {
            isCurrentSeries = (inspectedSeries == this);
            if (isCurrentSeries) {
                currentSeriesOrder = numBarSeries;
            }
            numBarSeries++;

            // calculate the number of slots for bars based on the minimum distance between
            // x coordinates in the series.  This is divided into the range to find
            // the placement and width of bar slots
            // (sections of the x axis for each bar or set of bars)
            // TODO: Move this somewhere more general and cache it, so we don't recalculate it for each series
            Iterator<E> curValues = inspectedSeries.getValues(minX, maxX);
            if (curValues.hasNext()) {
                xVals.add(curValues.next().getX());
                if (isCurrentSeries) {
                    numValues++;
                }
                while (curValues.hasNext()) {
                    xVals.add(curValues.next().getX());
                    if (isCurrentSeries) {
                        numValues++;
                    }
                }
            }
        }
    }
    if (numValues == 0) {
        return;
    }

    double minGap = 0;

    if (mDataWidth > 0.0) {
        minGap = mDataWidth;
    } else {
        Double lastVal = null;

        for (Double curVal : xVals) {
            if (lastVal != null) {
                double curGap = Math.abs(curVal - lastVal);
                if (minGap == 0 || (curGap > 0 && curGap < minGap)) {
                    minGap = curGap;
                }
            }
            lastVal = curVal;
        }
    }

    int numBarSlots = (minGap == 0) ? 1 : (int) Math.round((maxX - minX) / minGap) + 1;

    Iterator<E> values = getValues(minX, maxX);

    // Calculate the overall bar slot width - this includes all bars across
    // all series, and any spacing between sets of bars
    int barSlotWidth = numBarSlots == 1 ? graphView.getGraphContentWidth()
            : graphView.getGraphContentWidth() / (numBarSlots - 1);

    // Total spacing (both sides) between sets of bars
    double spacing = Math.min(barSlotWidth * mSpacing / 100, barSlotWidth * 0.98f);
    // Width of an individual bar
    double barWidth = (barSlotWidth - spacing) / numBarSeries;
    // Offset from the center of a given bar to start drawing
    double offset = barSlotWidth / 2;

    double diffY = maxY - minY;
    double diffX = maxX - minX;
    double contentHeight = graphView.getGraphContentHeight();
    double contentWidth = graphView.getGraphContentWidth();
    double contentLeft = graphView.getGraphContentLeft();
    double contentTop = graphView.getGraphContentTop();

    // draw data
    int i = 0;
    while (values.hasNext()) {
        E value = values.next();

        double valY = value.getY() - minY;
        double ratY = valY / diffY;
        double y = contentHeight * ratY;

        double valY0 = 0 - minY;
        double ratY0 = valY0 / diffY;
        double y0 = contentHeight * ratY0;

        double valueX = value.getX();
        double valX = valueX - minX;
        double ratX = valX / diffX;
        double x = contentWidth * ratX;

        // hook for value dependent color
        if (getValueDependentColor() != null) {
            mPaint.setColor(getValueDependentColor().get(value));
        } else {
            mPaint.setColor(getColor());
        }

        double left = x + contentLeft - offset + spacing / 2 + currentSeriesOrder * barWidth;
        double top = (contentTop - y) + contentHeight;
        double right = left + barWidth;
        double bottom = (contentTop - y0) + contentHeight
                - (graphView.getGridLabelRenderer().isHighlightZeroLines() ? 4 : 1);

        boolean reverse = top > bottom;

        if (mAnimated) {
            if ((Double.isNaN(mLastAnimatedValue) || mLastAnimatedValue < valueX)) {
                long currentTime = System.currentTimeMillis();
                if (mAnimationStart == 0) {
                    // start animation
                    mAnimationStart = currentTime;
                    mAnimationStartFrameNo = 0;
                } else {
                    // anti-lag: wait a few frames
                    if (mAnimationStartFrameNo < 15) {
                        // second time
                        mAnimationStart = currentTime;
                        mAnimationStartFrameNo++;
                    }
                }
                float timeFactor = (float) (currentTime - mAnimationStart) / ANIMATION_DURATION;
                float factor = mAnimationInterpolator.getInterpolation(timeFactor);
                if (timeFactor <= 1.0) {
                    double barHeight = bottom - top;
                    barHeight = barHeight * factor;
                    top = bottom - barHeight;
                    ViewCompat.postInvalidateOnAnimation(graphView);
                } else {
                    // animation finished
                    mLastAnimatedValue = valueX;
                }
            }
        }

        if (reverse) {
            double tmp = top;
            top = bottom + (graphView.getGridLabelRenderer().isHighlightZeroLines() ? 4 : 1);
            bottom = tmp;
        }

        // overdraw
        left = Math.max(left, contentLeft);
        right = Math.min(right, contentLeft + contentWidth);
        bottom = Math.min(bottom, contentTop + contentHeight);
        top = Math.max(top, contentTop);

        mDataPoints.put(new RectD(left, top, right, bottom), value);

        Paint p;
        if (mCustomPaint != null) {
            p = mCustomPaint;
        } else {
            p = mPaint;
        }
        canvas.drawRect((float) left, (float) top, (float) right, (float) bottom, p);

        // set values on top of graph
        if (mDrawValuesOnTop) {
            if (reverse) {
                top = bottom + mValuesOnTopSize + 4;
                if (top > contentTop + contentHeight)
                    top = contentTop + contentHeight;
            } else {
                top -= 4;
                if (top <= contentTop)
                    top += contentTop + 4;
            }

            mPaint.setColor(mValuesOnTopColor);
            canvas.drawText(
                    graphView.getGridLabelRenderer().getLabelFormatter().formatLabel(value.getY(), false),
                    (float) (left + right) / 2, (float) top, mPaint);
        }

        i++;
    }
}

From source file:net.droidsolutions.droidcharts.core.plot.XYPlot.java

/**
 * Draws the quadrants./*from   w  ww . ja  v  a2 s . c  o  m*/
 * 
 * @param g2
 *            the graphics device.
 * @param area
 *            the area.
 * 
 * @see #setQuadrantOrigin(Point2D)
 * @see #setQuadrantPaint(int, Paint)
 */
protected void drawQuadrants(Canvas g2, Rectangle2D area) {
    // 0 | 1
    // --+--
    // 2 | 3
    boolean somethingToDraw = false;

    ValueAxis xAxis = getDomainAxis();
    if (xAxis == null) { // we can't draw quadrants without a valid x-axis
        return;
    }
    double x = xAxis.getRange().constrain(this.quadrantOrigin.getX());
    double xx = xAxis.valueToJava2D(x, area, getDomainAxisEdge());

    ValueAxis yAxis = getRangeAxis();
    if (yAxis == null) { // we can't draw quadrants without a valid y-axis
        return;
    }
    double y = yAxis.getRange().constrain(this.quadrantOrigin.getY());
    double yy = yAxis.valueToJava2D(y, area, getRangeAxisEdge());

    double xmin = xAxis.getLowerBound();
    double xxmin = xAxis.valueToJava2D(xmin, area, getDomainAxisEdge());

    double xmax = xAxis.getUpperBound();
    double xxmax = xAxis.valueToJava2D(xmax, area, getDomainAxisEdge());

    double ymin = yAxis.getLowerBound();
    double yymin = yAxis.valueToJava2D(ymin, area, getRangeAxisEdge());

    double ymax = yAxis.getUpperBound();
    double yymax = yAxis.valueToJava2D(ymax, area, getRangeAxisEdge());

    Rectangle2D[] r = new Rectangle2D[] { null, null, null, null };
    if (this.quadrantPaint[0] != null) {
        if (x > xmin && y < ymax) {
            if (this.orientation == PlotOrientation.HORIZONTAL) {
                r[0] = new Rectangle2D.Double(Math.min(yymax, yy), Math.min(xxmin, xx), Math.abs(yy - yymax),
                        Math.abs(xx - xxmin));
            } else { // PlotOrientation.VERTICAL
                r[0] = new Rectangle2D.Double(Math.min(xxmin, xx), Math.min(yymax, yy), Math.abs(xx - xxmin),
                        Math.abs(yy - yymax));
            }
            somethingToDraw = true;
        }
    }
    if (this.quadrantPaint[1] != null) {
        if (x < xmax && y < ymax) {
            if (this.orientation == PlotOrientation.HORIZONTAL) {
                r[1] = new Rectangle2D.Double(Math.min(yymax, yy), Math.min(xxmax, xx), Math.abs(yy - yymax),
                        Math.abs(xx - xxmax));
            } else { // PlotOrientation.VERTICAL
                r[1] = new Rectangle2D.Double(Math.min(xx, xxmax), Math.min(yymax, yy), Math.abs(xx - xxmax),
                        Math.abs(yy - yymax));
            }
            somethingToDraw = true;
        }
    }
    if (this.quadrantPaint[2] != null) {
        if (x > xmin && y > ymin) {
            if (this.orientation == PlotOrientation.HORIZONTAL) {
                r[2] = new Rectangle2D.Double(Math.min(yymin, yy), Math.min(xxmin, xx), Math.abs(yy - yymin),
                        Math.abs(xx - xxmin));
            } else { // PlotOrientation.VERTICAL
                r[2] = new Rectangle2D.Double(Math.min(xxmin, xx), Math.min(yymin, yy), Math.abs(xx - xxmin),
                        Math.abs(yy - yymin));
            }
            somethingToDraw = true;
        }
    }
    if (this.quadrantPaint[3] != null) {
        if (x < xmax && y > ymin) {
            if (this.orientation == PlotOrientation.HORIZONTAL) {
                r[3] = new Rectangle2D.Double(Math.min(yymin, yy), Math.min(xxmax, xx), Math.abs(yy - yymin),
                        Math.abs(xx - xxmax));
            } else { // PlotOrientation.VERTICAL
                r[3] = new Rectangle2D.Double(Math.min(xx, xxmax), Math.min(yymin, yy), Math.abs(xx - xxmax),
                        Math.abs(yy - yymin));
            }
            somethingToDraw = true;
        }
    }
    if (somethingToDraw) {

        for (int i = 0; i < 4; i++) {
            if (this.quadrantPaint[i] != null && r[i] != null) {
                Paint paint = this.quadrantPaint[i];
                paint.setStyle(Paint.Style.FILL);
                int oldAlpha = paint.getAlpha();
                paint.setAlpha(getBackgroundAlpha());
                g2.drawRect((float) r[i].getMinX(), (float) r[i].getMinY(), (float) r[i].getMaxX(),
                        (float) r[i].getMaxY(), paint);
                paint.setAlpha(oldAlpha);
            }
        }

    }
}

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

public void onDraw(Canvas c) {
    try {/*  w  w w . j a v a2 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.anysoftkeyboard.keyboards.views.AnyKeyboardBaseView.java

private void onBufferDraw(Canvas canvas) {
    if (mKeyboardChanged) {
        invalidateAllKeys();//from w w  w  . j  av  a2s.  c  o m
        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();
}