Example usage for android.graphics Paint setStyle

List of usage examples for android.graphics Paint setStyle

Introduction

In this page you can find the example usage for android.graphics Paint setStyle.

Prototype

public void setStyle(Style style) 

Source Link

Document

Set the paint's style, used for controlling how primitives' geometries are interpreted (except for drawBitmap, which always assumes Fill).

Usage

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

private void doDraw(Canvas canvas) {

    if (mSuggestions == null)
        return;//from www .j  a  va  2s .  co m
    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.example.SmartBoard.DrawingView.java

public void onDrawLine(Canvas canvas) {
    Paint paint = drawPaint;
    if (points[1] == null) //point4 null when user did not touch and move on screen.
        return;/*from www .java  2  s .c  o  m*/

    //draw stroke
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(5);

    if (finished) {

        JSONObject objectProperties = new JSONObject();
        String key = UUID.randomUUID().toString();

        try {
            objectProperties.put("id", key);
            objectProperties.put("clientId", client.getClientId());
            objectProperties.put("type", "Line");
            objectProperties.put("color", drawPaint.getColor());
            objectProperties.put("size", 5);
            objectProperties.put("startx", linePath.startx());
            objectProperties.put("starty", linePath.starty());
            objectProperties.put("stopx", linePath.stopx());
            objectProperties.put("stopy", linePath.stopy());
            objectProperties.put("gradient", linePath.getGradient());
            objectProperties.put("length", linePath.length());

        } catch (JSONException e) {
            e.printStackTrace();
        }

        objectDrawables.put(key, objectProperties);

        mqtt.publishLine(objectProperties);

        //reset to start drawing again
        points = new Point[4];
        colorballs.clear();
        return;

    }

    canvas.drawLine(linePath.startx(), linePath.starty(), linePath.stopx(), linePath.stopy(), paint);

    // draw the balls on the canvas
    paint.setTextSize(18);
    paint.setStrokeWidth(0);
    for (int i = 0; i < colorballs.size(); i++) {
        ColorBall ball = colorballs.get(i);
        canvas.drawBitmap(ball.getBitmap(), ball.getX(), ball.getY(), paint);
        canvas.drawText("" + (i + 1), ball.getX(), ball.getY(), paint);
    }
}

From source file:radialdemo.RadialMenuWidget.java

@Override
protected void onDraw(Canvas c) {

    Paint paint = new Paint();
    paint.setAntiAlias(true);// ww  w  .  j  a va 2s  .c  o m
    paint.setStrokeWidth(3);

    // draws a dot at the source of the press
    if (showSource == true) {
        paint.setColor(outlineColor);
        paint.setAlpha(outlineAlpha);
        paint.setStyle(Paint.Style.STROKE);
        c.drawCircle(xSource, ySource, cRadius / 10, paint);

        paint.setColor(selectedColor);
        paint.setAlpha(selectedAlpha);
        paint.setStyle(Paint.Style.FILL);
        c.drawCircle(xSource, ySource, cRadius / 10, paint);
    }
    //inner
    for (int i = 0; i < Wedges.length; i++) {
        RadialMenuWedge f = Wedges[i];
        paint.setColor(outlineColor);
        paint.setAlpha(outlineAlpha);
        paint.setStyle(Paint.Style.STROKE);
        c.drawPath(f, paint);
        if (f == enabled && Wedge2Shown == true) {
            paint.setColor(wedge2Color);
            paint.setAlpha(wedge2Alpha);
            paint.setStyle(Paint.Style.FILL);
            c.drawPath(f, paint);
        } else if (f != enabled && Wedge2Shown == true) {
            paint.setColor(disabledColor);
            paint.setAlpha(disabledAlpha);
            paint.setStyle(Paint.Style.FILL);
            c.drawPath(f, paint);
        } else if (f == enabled && Wedge2Shown == false) {
            paint.setColor(wedge2Color);
            paint.setAlpha(wedge2Alpha);
            paint.setStyle(Paint.Style.FILL);
            c.drawPath(f, paint);
        } else if (f == selected) {
            paint.setColor(wedge2Color);
            paint.setAlpha(wedge2Alpha);
            paint.setStyle(Paint.Style.FILL);
            c.drawPath(f, paint);
        } else {
            paint.setColor(defaultColor);
            paint.setAlpha(defaultAlpha);
            paint.setStyle(Paint.Style.FILL);
            c.drawPath(f, paint);
        }
        //button content
        Rect rf = iconRect[i];

        if ((menuEntries.get(i).getIcon() != 0) && (menuEntries.get(i).getLabel() != null)) {

            // This will look for a "new line" and split into multiple lines
            String menuItemName = menuEntries.get(i).getLabel();
            String[] stringArray = menuItemName.split("\n");

            paint.setColor(textColor);
            if (f != enabled && Wedge2Shown == true) {
                paint.setAlpha(disabledAlpha);
            } else {
                paint.setAlpha(textAlpha);
            }
            paint.setStyle(Paint.Style.FILL);
            paint.setTextSize(textSize);

            Rect rect = new Rect();
            float textHeight = 0;
            for (int j = 0; j < stringArray.length; j++) {
                paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rect);
                textHeight = textHeight + (rect.height() + 3);
            }

            Rect rf2 = new Rect();
            rf2.set(rf.left, rf.top - ((int) textHeight / 2), rf.right, rf.bottom - ((int) textHeight / 2));

            float textBottom = rf2.bottom;
            for (int j = 0; j < stringArray.length; j++) {
                paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rect);
                float textLeft = rf.centerX() - rect.width() / 2;
                textBottom = textBottom + (rect.height() + 3);
                c.drawText(stringArray[j], textLeft - rect.left, textBottom - rect.bottom, paint);
            }

            // Puts in the Icon
            Drawable drawable = getResources().getDrawable(menuEntries.get(i).getIcon());
            drawable.setBounds(rf2);
            if (f != enabled && Wedge2Shown == true) {
                drawable.setAlpha(disabledAlpha);
            } else {
                drawable.setAlpha(pictureAlpha);
            }
            drawable.draw(c);

            // Icon Only
        } else if (menuEntries.get(i).getIcon() != 0) {
            // Puts in the Icon
            Drawable drawable = getResources().getDrawable(menuEntries.get(i).getIcon());
            drawable.setBounds(rf);
            if (f != enabled && Wedge2Shown == true) {
                drawable.setAlpha(disabledAlpha);
            } else {
                drawable.setAlpha(pictureAlpha);
            }
            drawable.draw(c);

            // Text Only
        } else {
            // Puts in the Text if no Icon
            paint.setColor(textColor);
            if (f != enabled && Wedge2Shown == true) {
                paint.setAlpha(disabledAlpha);
            } else {
                paint.setAlpha(textAlpha);
            }
            paint.setStyle(Paint.Style.FILL);
            paint.setTextSize(textSize + 10);

            // This will look for a "new line" and split into multiple lines
            String menuItemName = menuEntries.get(i).getLabel();
            String[] stringArray = menuItemName.split("\n");

            // gets total height
            Rect rect = new Rect();
            float textHeight = 0;
            for (int j = 0; j < stringArray.length; j++) {
                paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rect);
                textHeight = textHeight + (rect.height() + 3);
            }

            float textBottom = rf.centerY() - (textHeight / 2);
            for (int j = 0; j < stringArray.length; j++) {
                paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rect);
                float textLeft = rf.centerX() - rect.width() / 2;
                textBottom = textBottom + (rect.height() + 3);
                c.drawText(stringArray[j], textLeft - rect.left, textBottom - rect.bottom, paint);
            }
        }

    }

    // Animate the outer ring in/out
    if (animateOuterIn == true) {
        animateOuterWedges(ANIMATE_IN);
    } else if (animateOuterOut == true) {
        animateOuterWedges(ANIMATE_OUT);
    }
    //outer
    if (Wedge2Shown == true) {

        for (int i = 0; i < Wedges2.length; i++) {
            RadialMenuWedge f = Wedges2[i];
            paint.setColor(outlineColor);
            paint.setAlpha(20);
            paint.setStyle(Paint.Style.STROKE);
            c.drawPath(f, paint);
            if (f == selected2) {
                paint.setColor(selectedColor);
                paint.setAlpha(selectedAlpha);
                paint.setStyle(Paint.Style.FILL);
                c.drawPath(f, paint);
            } else {
                paint.setColor(wedge2Color);
                paint.setAlpha(wedge2Alpha);
                paint.setStyle(Paint.Style.FILL);
                c.drawPath(f, paint);
            }

            Rect rf = iconRect2[i];
            if ((wedge2Data.getChildren().get(i).getIcon() != 0)
                    && (wedge2Data.getChildren().get(i).getLabel() != null)) {

                // This will look for a "new line" and split into multiple
                // lines
                String menuItemName = wedge2Data.getChildren().get(i).getLabel();
                String[] stringArray = menuItemName.split("\n");

                paint.setColor(textColor);
                paint.setAlpha(textAlpha);
                paint.setStyle(Paint.Style.FILL);
                paint.setTextSize(animateTextSize);

                Rect rect = new Rect();
                float textHeight = 0;
                for (int j = 0; j < stringArray.length; j++) {
                    paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rect);
                    textHeight = textHeight + (rect.height() + 3);
                }

                Rect rf2 = new Rect();
                rf2.set(rf.left, rf.top - ((int) textHeight / 2), rf.right, rf.bottom - ((int) textHeight / 2));

                float textBottom = rf2.bottom;
                for (int j = 0; j < stringArray.length; j++) {
                    paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rect);
                    float textLeft = rf.centerX() - rect.width() / 2;
                    textBottom = textBottom + (rect.height() + 3);
                    c.drawText(stringArray[j], textLeft - rect.left, textBottom - rect.bottom, paint);
                }

                // Puts in the Icon
                Drawable drawable = getResources().getDrawable(wedge2Data.getChildren().get(i).getIcon());
                drawable.setBounds(rf2);
                drawable.setAlpha(pictureAlpha);
                drawable.draw(c);

                // Icon Only
            } else if (wedge2Data.getChildren().get(i).getIcon() != 0) {
                // Puts in the Icon
                Drawable drawable = getResources().getDrawable(wedge2Data.getChildren().get(i).getIcon());
                drawable.setBounds(rf);
                drawable.setAlpha(pictureAlpha);
                drawable.draw(c);

                // Text Only
            } else {
                // Puts in the Text if no Icon
                paint.setColor(textColor);
                paint.setAlpha(textAlpha);
                paint.setStyle(Paint.Style.FILL);
                paint.setTextSize(animateTextSize);

                // This will look for a "new line" and split into multiple
                // lines
                String menuItemName = wedge2Data.getChildren().get(i).getLabel();
                String[] stringArray = menuItemName.split("\n");

                // gets total height
                Rect rect = new Rect();
                float textHeight = 0;
                for (int j = 0; j < stringArray.length; j++) {
                    paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rect);
                    textHeight = textHeight + (rect.height() + 3);
                }

                float textBottom = rf.centerY() - (textHeight / 2);
                for (int j = 0; j < stringArray.length; j++) {
                    paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rect);
                    float textLeft = rf.centerX() - rect.width() / 2;
                    textBottom = textBottom + (rect.height() + 3);
                    c.drawText(stringArray[j], textLeft - rect.left, textBottom - rect.bottom, paint);
                }
            }
        }
    }

    //Check if the user has given input for centre circle
    if (centerCircle != null) {
        // Draws the Middle Circle
        paint.setColor(outlineColor);
        paint.setAlpha(outlineAlpha);
        paint.setStyle(Paint.Style.STROKE);
        c.drawCircle(xPosition, yPosition, cRadius, paint);
        if (inCircle == true) {
            paint.setColor(selectedColor);
            paint.setAlpha(selectedAlpha);
            paint.setStyle(Paint.Style.FILL);
            c.drawCircle(xPosition, yPosition, cRadius, paint);
            helper.onCloseAnimation(this, xPosition, yPosition, xSource, ySource);
        } else {
            paint.setColor(defaultColor);
            paint.setAlpha(defaultAlpha);
            paint.setStyle(Paint.Style.FILL);
            c.drawCircle(xPosition, yPosition, cRadius, paint);
        }

        // Draw the circle picture
        if ((centerCircle.getIcon() != 0) && (centerCircle.getLabel() != null)) {

            // This will look for a "new line" and split into multiple lines
            String menuItemName = centerCircle.getLabel();
            String[] stringArray = menuItemName.split("\n");

            paint.setColor(textColor);
            paint.setAlpha(textAlpha);
            paint.setStyle(Paint.Style.FILL);
            paint.setTextSize(textSize);

            Rect rectText = new Rect();
            Rect rectIcon = new Rect();
            Drawable drawable = getResources().getDrawable(centerCircle.getIcon());

            int h = getIconSize(drawable.getIntrinsicHeight(), MinIconSize, MaxIconSize);
            int w = getIconSize(drawable.getIntrinsicWidth(), MinIconSize, MaxIconSize);
            rectIcon.set(xPosition - w / 2, yPosition - h / 2, xPosition + w / 2, yPosition + h / 2);

            float textHeight = 0;
            for (int j = 0; j < stringArray.length; j++) {
                paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rectText);
                textHeight = textHeight + (rectText.height() + 3);
            }

            rectIcon.set(rectIcon.left, rectIcon.top - ((int) textHeight / 2), rectIcon.right,
                    rectIcon.bottom - ((int) textHeight / 2));

            float textBottom = rectIcon.bottom;
            for (int j = 0; j < stringArray.length; j++) {
                paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rectText);
                float textLeft = xPosition - rectText.width() / 2;
                textBottom = textBottom + (rectText.height() + 3);
                c.drawText(stringArray[j], textLeft - rectText.left, textBottom - rectText.bottom, paint);
            }

            // Puts in the Icon
            drawable.setBounds(rectIcon);
            drawable.setAlpha(pictureAlpha);
            drawable.draw(c);

            // Icon Only
        } else if (centerCircle.getIcon() != 0) {

            Rect rect = new Rect();

            Drawable drawable = getResources().getDrawable(centerCircle.getIcon());

            int h = getIconSize(drawable.getIntrinsicHeight(), MinIconSize, MaxIconSize);
            int w = getIconSize(drawable.getIntrinsicWidth(), MinIconSize, MaxIconSize);
            rect.set(xPosition - w / 2, yPosition - h / 2, xPosition + w / 2, yPosition + h / 2);

            drawable.setBounds(rect);
            drawable.setAlpha(pictureAlpha);
            drawable.draw(c);

            // Text Only
        } else {
            // Puts in the Text if no Icon
            paint.setColor(textColor);
            paint.setAlpha(textAlpha);
            paint.setStyle(Paint.Style.FILL);
            paint.setTextSize(textSize);

            // This will look for a "new line" and split into multiple lines
            String menuItemName = centerCircle.getLabel();
            String[] stringArray = menuItemName.split("\n");

            // gets total height
            Rect rect = new Rect();
            float textHeight = 0;
            for (int j = 0; j < stringArray.length; j++) {
                paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rect);
                textHeight = textHeight + (rect.height() + 3);
            }

            float textBottom = yPosition - (textHeight / 2);
            for (int j = 0; j < stringArray.length; j++) {
                paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rect);
                float textLeft = xPosition - rect.width() / 2;
                textBottom = textBottom + (rect.height() + 3);
                c.drawText(stringArray[j], textLeft - rect.left, textBottom - rect.bottom, paint);
            }

        }
    }

    // Draws Text in TextBox
    if (headerString != null) {

        paint.setTextSize(headerTextSize);
        paint.getTextBounds(headerString, 0, headerString.length(), this.textRect);
        if (HeaderBoxBounded == false) {
            determineHeaderBox();
            HeaderBoxBounded = true;
        }

        paint.setColor(outlineColor);
        paint.setAlpha(outlineAlpha);
        paint.setStyle(Paint.Style.STROKE);
        c.drawRoundRect(this.textBoxRect, scalePX(5), scalePX(5), paint);
        paint.setColor(headerBackgroundColor);
        paint.setAlpha(headerBackgroundAlpha);
        paint.setStyle(Paint.Style.FILL);
        c.drawRoundRect(this.textBoxRect, scalePX(5), scalePX(5), paint);

        paint.setColor(headerTextColor);
        paint.setAlpha(headerTextAlpha);
        paint.setStyle(Paint.Style.FILL);
        paint.setTextSize(headerTextSize);
        c.drawText(headerString, headerTextLeft, headerTextBottom, paint);
    }

}

From source file:com.wanikani.androidnotifier.graph.HistogramPlot.java

protected void drawBar(Canvas canvas, Samples bar, float left, float right) {
    long base, height;
    float top, tbl;
    Paint lpaint;//w  w w . j  a  v  a 2 s  . co  m
    Paint paint;
    Path path;
    RectF rect;

    top = vp.getY(vp.yMax);
    base = 0;
    for (Sample sample : bar.samples) {
        if (sample.value > 0) {
            height = sample.value;

            if (base > vp.yMax)
                ;
            else if (base + height > vp.yMax) {
                path = new Path();
                path.moveTo(left, vp.getY(base));
                path.lineTo(left, top);
                path.lineTo(left + (right - left) / 3, top - 10);
                path.lineTo(left + (right - left) * 2 / 3, top + 5);
                path.lineTo(right, top);
                path.lineTo(right, vp.getY(base));
                path.close();
                canvas.drawPath(path, pas.series.get(sample.series));
            } else {
                rect = new RectF(left, vp.getY(base + height), right, vp.getY(base));
                rect.intersect(meas.plotArea);
                paint = pas.series.get(sample.series);
                paint.setStyle(Style.FILL);
                canvas.drawRect(rect, paint);
                paint.setStyle(Style.STROKE);
                canvas.drawRect(rect, paint);
            }
            base += height;
        }
    }

    if (base <= vp.yMax) {
        lpaint = pas.levelupPaint;
        tbl = vp.getY(base) - meas.headroom / 2;
    } else {
        lpaint = pas.levelupPaintInside;
        tbl = vp.getY(vp.yMax) + meas.margin;
    }

    if (base > 0 && drawTotal)
        canvas.drawText(Long.toString(base), (left + right) / 2, tbl, lpaint);
}

From source file:info.bartowski.easteregg.MLand.java

@Override
public void onDraw(Canvas c) {
    super.onDraw(c);

    if (SHOW_TOUCHES) {
        for (Player p : mPlayers) {
            if (p.mTouchX > 0) {
                mTouchPaint.setColor(0x80FFFFFF & p.color);
                mPlayerTracePaint.setColor(0x80FFFFFF & p.color);
                float x1 = p.mTouchX;
                float y1 = p.mTouchY;
                c.drawCircle(x1, y1, 100, mTouchPaint);
                float x2 = p.getX() + p.getPivotX();
                float y2 = p.getY() + p.getPivotY();
                float angle = PI_2 - (float) Math.atan2(x2 - x1, y2 - y1);
                x1 += 100 * Math.cos(angle);
                y1 += 100 * Math.sin(angle);
                c.drawLine(x1, y1, x2, y2, mPlayerTracePaint);
            }//from  www  .j av  a  2  s .  co m
        }
    }

    if (!DEBUG_DRAW)
        return;

    final Paint pt = new Paint();
    pt.setColor(0xFFFFFFFF);
    for (Player p : mPlayers) {
        final int L = p.corners.length;
        final int N = L / 2;
        for (int i = 0; i < N; i++) {
            final int x = (int) p.corners[i * 2];
            final int y = (int) p.corners[i * 2 + 1];
            c.drawCircle(x, y, 4, pt);
            c.drawLine(x, y, p.corners[(i * 2 + 2) % L], p.corners[(i * 2 + 3) % L], pt);
        }
    }

    pt.setStyle(Paint.Style.STROKE);
    pt.setStrokeWidth(getResources().getDisplayMetrics().density);

    final int M = getChildCount();
    pt.setColor(0x8000FF00);
    for (int i = 0; i < M; i++) {
        final View v = getChildAt(i);
        if (v instanceof Player)
            continue;
        if (!(v instanceof GameView))
            continue;
        if (v instanceof Pop) {
            final Pop pop = (Pop) v;
            c.drawCircle(pop.cx, pop.cy, pop.r, pt);
        } else {
            final Rect r = new Rect();
            v.getHitRect(r);
            c.drawRect(r, pt);
        }
    }

    pt.setColor(Color.BLACK);
    final StringBuilder sb = new StringBuilder("obstacles: ");
    for (Obstacle ob : mObstaclesInPlay) {
        sb.append(ob.hitRect.toShortString());
        sb.append(" ");
    }
    pt.setTextSize(20f);
    c.drawText(sb.toString(), 20, 100, pt);
}

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

/**
 * Draws a line perpendicular to the range axis.
 *
 * @param g2  the graphics device.//from  w  w w .ja  v a 2  s  .co m
 * @param plot  the plot.
 * @param axis  the value axis.
 * @param dataArea  the area for plotting data (not yet adjusted for any 3D
 *                  effect).
 * @param value  the value at which the grid line should be drawn.
 * @param paint  the paint.
 * @param stroke  the stroke.
 */
public void drawRangeLine(Canvas g2, XYPlot plot, ValueAxis axis, Rectangle2D dataArea, double value,
        Paint paint, Float stroke) {

    Range range = axis.getRange();
    if (!range.contains(value)) {
        return;
    }

    PlotOrientation orientation = plot.getOrientation();
    Line2D line = null;
    double v = axis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge());
    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.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(stroke);

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

}

From source file:com.nextgis.mobile.fragment.MapFragment.java

protected void drawScaleRuler() {
    int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_MM, 10,
            getResources().getDisplayMetrics());
    int notch = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_MM, 1,
            getResources().getDisplayMetrics());
    Bitmap ruler = Bitmap.createBitmap(px, px, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(ruler);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(ContextCompat.getColor(getActivity(), R.color.primary_dark));
    paint.setStrokeWidth(4);//from   ww w . ja v a  2 s  . c om
    paint.setStyle(Paint.Style.STROKE);
    canvas.drawLine(0, px, px, px, paint);
    canvas.drawLine(0, px, 0, 0, paint);
    canvas.drawLine(0, 0, notch, 0, paint);
    canvas.drawLine(px, px, px, px - notch, paint);
    mScaleRuler.setImageBitmap(ruler);
}

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

/**
 * Draws a line perpendicular to the domain axis.
 *
 * @param g2  the graphics device.//from w  w  w.j a v  a2s. c o  m
 * @param plot  the plot.
 * @param axis  the value axis.
 * @param dataArea  the area for plotting data (not yet adjusted for any 3D
 *                  effect).
 * @param value  the value at which the grid line should be drawn.
 * @param paint  the paint (<code>null</code> not permitted).
 * @param stroke  the stroke (<code>null</code> not permitted).
 *
 * @since 1.0.5
 */
public void drawDomainLine(Canvas g2, XYPlot plot, ValueAxis axis, Rectangle2D dataArea, double value,
        Paint paint, Float stroke) {

    Range range = axis.getRange();
    if (!range.contains(value)) {
        return;
    }

    PlotOrientation orientation = plot.getOrientation();
    Line2D line = null;
    double v = axis.valueToJava2D(value, dataArea, plot.getDomainAxisEdge());
    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.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(stroke);

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

}

From source file:com.almalence.opencam.SavingService.java

protected void drawTextWithBackground(Canvas canvas, Paint paint, String text, int foreground, int background,
        int imageWidth, int imageHeight) {
    Rect text_bounds = new Rect();
    paint.setColor(foreground);//ww w . j av  a 2 s  . co  m
    String[] resText = text.split("\n");
    String maxLengthText = "";

    if (resText.length > 1) {
        maxLengthText = resText[0].length() > resText[1].length() ? resText[0] : resText[1];
    } else if (resText.length > 0) {
        maxLengthText = resText[0];
    }

    final float scale = getResources().getDisplayMetrics().density;
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(background);
    paint.setAlpha(64);
    paint.getTextBounds(text, 0, maxLengthText.length(), text_bounds);
    final int padding = (int) (2 * scale + 0.5f); // convert dps to pixels

    int textWidth = 0;
    int textHeight = text_bounds.bottom - text_bounds.top;
    if (paint.getTextAlign() == Paint.Align.RIGHT || paint.getTextAlign() == Paint.Align.CENTER) {
        float width = paint.measureText(maxLengthText); // n.b., need to use
        // measureText
        // rather than
        // getTextBounds
        // here
        textWidth = (int) width;
    }

    text_bounds.left = imageWidth - textWidth - resText.length * padding;
    text_bounds.right = imageWidth - padding;
    if (resText.length > 1) {
        text_bounds.top = imageHeight - resText.length * padding - resText.length * textHeight - textHeight;
    } else {
        text_bounds.top = imageHeight - 2 * padding - textHeight;
        textHeight /= 3;
    }
    text_bounds.bottom = imageHeight - padding;

    paint.setColor(foreground);
    if (resText.length > 0) {
        canvas.drawText(resText[0], imageWidth - 5 * padding,
                imageHeight - resText.length * textHeight - textHeight / 2, paint);
    }
    if (resText.length > 1) {
        canvas.drawText(resText[1], imageWidth - 5 * padding, imageHeight - (resText.length - 1) * textHeight,
                paint);
    }
    if (resText.length > 2) {
        canvas.drawText(resText[2], imageWidth - 5 * padding,
                imageHeight - (resText.length - 2) * textHeight + textHeight / 2, paint);
    }
    if (resText.length > 3) {
        canvas.drawText(resText[3], imageWidth - 5 * padding, imageHeight - textHeight / 4, paint);
    }
}

From source file:com.example.SmartBoard.DrawingView.java

public void onDrawRectangle(Canvas canvas) {
    Paint paint = drawPaint;
    if (points[3] == null) //point4 null when user did not touch and move on screen.
        return;/*from ww  w.ja  v  a 2  s. c o  m*/
    int left, top, right, bottom;
    left = points[0].x;
    top = points[0].y;
    right = points[0].x;
    bottom = points[0].y;
    for (int i = 1; i < points.length; i++) {
        left = left > points[i].x ? points[i].x : left;
        top = top > points[i].y ? points[i].y : top;
        right = right < points[i].x ? points[i].x : right;
        bottom = bottom < points[i].y ? points[i].y : bottom;
    }

    //draw stroke
    paint.setStyle(Paint.Style.STROKE);
    // paint.setColor(Color.parseColor("#AADB1255"));
    paint.setStrokeWidth(5);

    if (finished) {

        Rect rect = new Rect(left + colorballs.get(0).getWidthOfBall() / 2,
                top + colorballs.get(0).getWidthOfBall() / 2, right + colorballs.get(2).getWidthOfBall() / 2,
                bottom + colorballs.get(2).getWidthOfBall() / 2);

        JSONObject objectProperties = new JSONObject();
        String key = UUID.randomUUID().toString();

        try {
            objectProperties.put("type", "Rectangle");
            objectProperties.put("clientId", client.getClientId());
            objectProperties.put("id", key);
            objectProperties.put("color", drawPaint.getColor());
            objectProperties.put("size", 5);
            objectProperties.put("dimens", rect.flattenToString());

        } catch (JSONException e) {

        }

        objectDrawables.put(key, objectProperties);

        mqtt.publishRectangle(objectProperties);
        //reset to start drawing again
        points = new Point[4];
        colorballs.clear();
        return;
    }

    //temporary canvas drawing on resize mode
    canvas.drawRect(left + colorballs.get(0).getWidthOfBall() / 2, top + colorballs.get(0).getWidthOfBall() / 2,
            right + colorballs.get(2).getWidthOfBall() / 2, bottom + colorballs.get(2).getWidthOfBall() / 2,
            paint);

    //draw the corners
    BitmapDrawable bitmap = new BitmapDrawable();
    // draw the balls on the canvas
    paint.setTextSize(18);
    paint.setStrokeWidth(0);

    for (int i = 0; i < colorballs.size(); i++) {
        ColorBall ball = colorballs.get(i);
        canvas.drawBitmap(ball.getBitmap(), ball.getX(), ball.getY(), paint);
        //  System.out.println("RectMode");

        canvas.drawText("" + (i + 1), ball.getX(), ball.getY(), paint);
    }
}