Code example for Picture

Methods: beginRecordingendRecording

0
        p1 = projection.fromPixels(screenWidth / 2, (screenHeight / 2) - (ydpi / 2));
        p2 = projection.fromPixels(screenWidth / 2, (screenHeight / 2) + (ydpi / 2));
 
        final int yMetersPerInch = ((GeoPoint) p1).distanceTo(p2);
 
        final Canvas canvas = scaleBarPicture.beginRecording((int) xdpi, (int) ydpi);
 
        if (latitudeBar) {
            final String xMsg = scaleBarLengthText(xMetersPerInch, imperial, nautical);
            final Rect xTextRect = new Rect();
            textPaint.getTextBounds(xMsg, 0, xMsg.length(), xTextRect);
 
            final int textSpacing = (int) (xTextRect.height() / 5.0);
 
            canvas.drawRect(0, 0, xdpi, lineWidth, barPaint);
            canvas.drawRect(xdpi, 0, xdpi + lineWidth,
                    xTextRect.height() + lineWidth + textSpacing, barPaint);
 
            if (!longitudeBar) {
                canvas.drawRect(0, 0, lineWidth, xTextRect.height() + lineWidth + textSpacing,
                        barPaint);
            } 
 
//            canvas.drawText(xMsg, xdpi / 2 - xTextRect.width() / 2, xTextRect.height() + lineWidth 
//                    + textSpacing, textPaint); 
        } 
 
        if (longitudeBar) {
            //TODO: 
            final String yMsg = scaleBarLengthText(yMetersPerInch, imperial, nautical);
            final Rect yTextRect = new Rect();
            textPaint.getTextBounds(yMsg, 0, yMsg.length(), yTextRect);
 
            final int textSpacing = (int) (yTextRect.height() / 5.0);
            final int width = (int) (yTextRect.height() + lineWidth *2 + textSpacing * 3);
            //final int width = (int) (yTextRect.height() + lineWidth + textSpacing); 
            canvas.drawRect(0, 0, width, ydpi + lineWidth, textBgPaint); //background
            canvas.drawRect(0, 0, lineWidth, ydpi, barPaint); //left line
            canvas.drawRect(0, ydpi, width, ydpi + lineWidth, barPaint); //bottom line
 
            if (!latitudeBar) {
                canvas.drawRect(0, 0, width, lineWidth, barPaint); //top line
            } 
             
            //canvas.drawRect(yTextRect, textBgPaint); 
            //left, top, right, bottom 
             
 
            final float x = yTextRect.height() + lineWidth + textSpacing;
            final float y = ydpi / 2 + yTextRect.width() / 2;
 
            canvas.rotate(-90, x, y);
            canvas.drawText(yMsg, x, y + textSpacing, textPaint);
 
        } 
 
        scaleBarPicture.endRecording();
    } 
 
    private String scaleBarLengthText(final int meters, final boolean imperial,
            final boolean nautical) {
        if (this.imperial) {
Contextual code suggestions in your IDE  Get Codota for Java