Example usage for android.graphics.drawable Drawable getIntrinsicHeight

List of usage examples for android.graphics.drawable Drawable getIntrinsicHeight

Introduction

In this page you can find the example usage for android.graphics.drawable Drawable getIntrinsicHeight.

Prototype

public int getIntrinsicHeight() 

Source Link

Document

Returns the drawable's intrinsic height.

Usage

From source file:radialdemo.RadialMenuWidget.java

@Override
protected void onDraw(Canvas c) {

    Paint paint = new Paint();
    paint.setAntiAlias(true);/*from   ww w  .ja va2 s. c om*/
    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);
    }

}