Example usage for android.graphics Rect height

List of usage examples for android.graphics Rect height

Introduction

In this page you can find the example usage for android.graphics Rect height.

Prototype

public final int height() 

Source Link

Usage

From source file:com.icloud.listenbook.base.view.DraggableGridViewPager.java

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    final int childCount = getChildCount();
    mPageCount = (childCount + mPageSize - 1) / mPageSize;
    mGridWidth = (getWidth() - mPaddingLeft - mPaddingRight - (mColCount - 1) * mGridGap) / mColCount;
    mGridHeight = (getHeight() - mPaddingTop - mPaddingButtom - (mRowCount - 1) * mGridGap) / mRowCount;

    mMaxOverScrollSize = mGridWidth / 2;
    mEdgeSize = mGridWidth / 2;/*from   w w w.  jav a 2s  .  c om*/
    newPositions.clear();
    // ? 
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        final Rect rect = getRectByPosition(i);
        child.measure(MeasureSpec.makeMeasureSpec(rect.width(), MeasureSpec.EXACTLY),
                MeasureSpec.makeMeasureSpec(rect.height(), MeasureSpec.EXACTLY));
        DEBUG_LOG("child.layout position=" + i + ", rect=" + rect);
        child.layout(rect.left, rect.top, rect.right, rect.bottom);
        newPositions.add(-1);
    }
    // ??
    if (mCurItem > 0 && mCurItem < mPageCount) {
        final int curItem = mCurItem;
        mCurItem = 0;
        setCurrentItem(curItem);
    }
}

From source file:com.icloud.listenbook.base.view.DraggableGridViewPager.java

/**
 * ?/*from   w  w w .j av a  2  s . c o  m*/
 * */
private int getTargetByXY(int x, int y) {
    // ?
    final int position = getPositionByXY(x, y);
    if (position < 0) {
        return -1;
    }
    // ?
    final Rect r = getRectByPosition(position);
    final int page = position / mPageSize;
    // ?? ??
    r.inset(r.width() / 4, r.height() / 4);
    // ??
    r.offset(-getWidth() * page, 0);
    // ?? ?
    if (!r.contains(x, y)) {
        return -1;
    }
    return position;
}

From source file:com.example.firstocr.ViewfinderView.java

@SuppressWarnings("unused")
@Override//from  w  ww. j  a  v  a 2  s  .  c om
public void onDraw(Canvas canvas) {
    Rect frame = cameraManager.getFramingRect();
    if (frame == null) {
        return;
    }
    int width = canvas.getWidth();
    int height = canvas.getHeight();

    // Draw the exterior (i.e. outside the framing rect) darkened
    paint.setColor(maskColor);
    canvas.drawRect(0, 0, width, frame.top, paint);
    canvas.drawRect(0, frame.top, frame.left, frame.bottom + 1, paint);
    canvas.drawRect(frame.right + 1, frame.top, width, frame.bottom + 1, paint);
    canvas.drawRect(0, frame.bottom + 1, width, height, paint);

    // If we have an OCR result, overlay its information on the viewfinder.
    if (resultText != null) {

        // Only draw text/bounding boxes on viewfinder if it hasn't been resized since the OCR was requested.
        Point bitmapSize = resultText.getBitmapDimensions();
        previewFrame = cameraManager.getFramingRectInPreview();
        if (bitmapSize.x == previewFrame.width() && bitmapSize.y == previewFrame.height()) {

            float scaleX = frame.width() / (float) previewFrame.width();
            float scaleY = frame.height() / (float) previewFrame.height();

            if (DRAW_REGION_BOXES) {
                regionBoundingBoxes = resultText.getRegionBoundingBoxes();
                for (int i = 0; i < regionBoundingBoxes.size(); i++) {
                    paint.setAlpha(0xA0);
                    paint.setColor(Color.MAGENTA);
                    paint.setStyle(Style.STROKE);
                    paint.setStrokeWidth(1);
                    rect = regionBoundingBoxes.get(i);
                    canvas.drawRect(frame.left + rect.left * scaleX, frame.top + rect.top * scaleY,
                            frame.left + rect.right * scaleX, frame.top + rect.bottom * scaleY, paint);
                }
            }

            if (DRAW_TEXTLINE_BOXES) {
                // Draw each textline
                textlineBoundingBoxes = resultText.getTextlineBoundingBoxes();
                paint.setAlpha(0xA0);
                paint.setColor(Color.RED);
                paint.setStyle(Style.STROKE);
                paint.setStrokeWidth(1);
                for (int i = 0; i < textlineBoundingBoxes.size(); i++) {
                    rect = textlineBoundingBoxes.get(i);
                    canvas.drawRect(frame.left + rect.left * scaleX, frame.top + rect.top * scaleY,
                            frame.left + rect.right * scaleX, frame.top + rect.bottom * scaleY, paint);
                }
            }

            if (DRAW_STRIP_BOXES) {
                stripBoundingBoxes = resultText.getStripBoundingBoxes();
                paint.setAlpha(0xFF);
                paint.setColor(Color.YELLOW);
                paint.setStyle(Style.STROKE);
                paint.setStrokeWidth(1);
                for (int i = 0; i < stripBoundingBoxes.size(); i++) {
                    rect = stripBoundingBoxes.get(i);
                    canvas.drawRect(frame.left + rect.left * scaleX, frame.top + rect.top * scaleY,
                            frame.left + rect.right * scaleX, frame.top + rect.bottom * scaleY, paint);
                }
            }

            if (DRAW_WORD_BOXES || DRAW_WORD_TEXT) {
                // Split the text into words
                wordBoundingBoxes = resultText.getWordBoundingBoxes();
                //      for (String w : words) {
                //        Log.e("ViewfinderView", "word: " + w);
                //      }
                //Log.d("ViewfinderView", "There are " + words.length + " words in the string array.");
                //Log.d("ViewfinderView", "There are " + wordBoundingBoxes.size() + " words with bounding boxes.");
            }

            if (DRAW_WORD_BOXES) {
                paint.setAlpha(0xFF);
                paint.setColor(0xFF00CCFF);
                paint.setStyle(Style.STROKE);
                paint.setStrokeWidth(1);
                for (int i = 0; i < wordBoundingBoxes.size(); i++) {
                    // Draw a bounding box around the word
                    rect = wordBoundingBoxes.get(i);
                    canvas.drawRect(frame.left + rect.left * scaleX, frame.top + rect.top * scaleY,
                            frame.left + rect.right * scaleX, frame.top + rect.bottom * scaleY, paint);
                }
            }

            if (DRAW_WORD_TEXT) {
                words = resultText.getText().replace("\n", " ").split(" ");
                int[] wordConfidences = resultText.getWordConfidences();
                for (int i = 0; i < wordBoundingBoxes.size(); i++) {
                    boolean isWordBlank = true;
                    try {
                        if (!words[i].equals("")) {
                            isWordBlank = false;
                        }
                    } catch (ArrayIndexOutOfBoundsException e) {
                        e.printStackTrace();
                    }

                    // Only draw if word has characters
                    if (!isWordBlank) {
                        // Draw a white background around each word
                        rect = wordBoundingBoxes.get(i);
                        paint.setColor(Color.WHITE);
                        paint.setStyle(Style.FILL);
                        if (DRAW_TRANSPARENT_WORD_BACKGROUNDS) {
                            // Higher confidence = more opaque, less transparent background
                            paint.setAlpha(wordConfidences[i] * 255 / 100);
                        } else {
                            paint.setAlpha(255);
                        }
                        canvas.drawRect(frame.left + rect.left * scaleX, frame.top + rect.top * scaleY,
                                frame.left + rect.right * scaleX, frame.top + rect.bottom * scaleY, paint);

                        // Draw the word in black text
                        paint.setColor(Color.BLACK);
                        paint.setAlpha(0xFF);
                        paint.setAntiAlias(true);
                        paint.setTextAlign(Align.LEFT);

                        // Adjust text size to fill rect
                        paint.setTextSize(100);
                        paint.setTextScaleX(1.0f);
                        // ask the paint for the bounding rect if it were to draw this text
                        Rect bounds = new Rect();
                        paint.getTextBounds(words[i], 0, words[i].length(), bounds);
                        // get the height that would have been produced
                        int h = bounds.bottom - bounds.top;
                        // figure out what textSize setting would create that height of text
                        float size = (((float) (rect.height()) / h) * 100f);
                        // and set it into the paint
                        paint.setTextSize(size);
                        // Now set the scale.
                        // do calculation with scale of 1.0 (no scale)
                        paint.setTextScaleX(1.0f);
                        // ask the paint for the bounding rect if it were to draw this text.
                        paint.getTextBounds(words[i], 0, words[i].length(), bounds);
                        // determine the width
                        int w = bounds.right - bounds.left;
                        // calculate the baseline to use so that the entire text is visible including the descenders
                        int text_h = bounds.bottom - bounds.top;
                        int baseline = bounds.bottom + ((rect.height() - text_h) / 2);
                        // determine how much to scale the width to fit the view
                        float xscale = ((float) (rect.width())) / w;
                        // set the scale for the text paint
                        paint.setTextScaleX(xscale);
                        canvas.drawText(words[i], frame.left + rect.left * scaleX,
                                frame.top + rect.bottom * scaleY - baseline, paint);
                    }

                }
            }

            //        if (DRAW_CHARACTER_BOXES || DRAW_CHARACTER_TEXT) {
            //          characterBoundingBoxes = resultText.getCharacterBoundingBoxes();
            //        }
            //
            //        if (DRAW_CHARACTER_BOXES) {
            //          // Draw bounding boxes around each character
            //          paint.setAlpha(0xA0);
            //          paint.setColor(0xFF00FF00);
            //          paint.setStyle(Style.STROKE);
            //          paint.setStrokeWidth(1);
            //          for (int c = 0; c < characterBoundingBoxes.size(); c++) {
            //            Rect characterRect = characterBoundingBoxes.get(c);
            //            canvas.drawRect(frame.left + characterRect.left * scaleX,
            //                frame.top + characterRect.top * scaleY, 
            //                frame.left + characterRect.right * scaleX, 
            //                frame.top + characterRect.bottom * scaleY, paint);
            //          }
            //        }
            //
            //        if (DRAW_CHARACTER_TEXT) {
            //          // Draw letters individually
            //          for (int i = 0; i < characterBoundingBoxes.size(); i++) {
            //            Rect r = characterBoundingBoxes.get(i);
            //
            //            // Draw a white background for every letter
            //            int meanConfidence = resultText.getMeanConfidence();
            //            paint.setColor(Color.WHITE);
            //            paint.setAlpha(meanConfidence * (255 / 100));
            //            paint.setStyle(Style.FILL);
            //            canvas.drawRect(frame.left + r.left * scaleX,
            //                frame.top + r.top * scaleY, 
            //                frame.left + r.right * scaleX, 
            //                frame.top + r.bottom * scaleY, paint);
            //
            //            // Draw each letter, in black
            //            paint.setColor(Color.BLACK);
            //            paint.setAlpha(0xFF);
            //            paint.setAntiAlias(true);
            //            paint.setTextAlign(Align.LEFT);
            //            String letter = "";
            //            try {
            //              char c = resultText.getText().replace("\n","").replace(" ", "").charAt(i);
            //              letter = Character.toString(c);
            //
            //              if (!letter.equals("-") && !letter.equals("_")) {
            //
            //                // Adjust text size to fill rect
            //                paint.setTextSize(100);
            //                paint.setTextScaleX(1.0f);
            //
            //                // ask the paint for the bounding rect if it were to draw this text
            //                Rect bounds = new Rect();
            //                paint.getTextBounds(letter, 0, letter.length(), bounds);
            //
            //                // get the height that would have been produced
            //                int h = bounds.bottom - bounds.top;
            //
            //                // figure out what textSize setting would create that height of text
            //                float size  = (((float)(r.height())/h)*100f);
            //
            //                // and set it into the paint
            //                paint.setTextSize(size);
            //
            //                // Draw the text as is. We don't really need to set the text scale, because the dimensions
            //                // of the Rect should already be suited for drawing our letter. 
            //                canvas.drawText(letter, frame.left + r.left * scaleX, frame.top + r.bottom * scaleY, paint);
            //              }
            //            } catch (StringIndexOutOfBoundsException e) {
            //              e.printStackTrace();
            //            } catch (Exception e) {
            //              e.printStackTrace();
            //            }
            //          }
            //        }
        }

    }
    // Draw a two pixel solid border inside the framing rect
    paint.setAlpha(0);
    paint.setStyle(Style.FILL);
    paint.setColor(frameColor);
    canvas.drawRect(frame.left, frame.top, frame.right + 1, frame.top + 2, paint);
    canvas.drawRect(frame.left, frame.top + 2, frame.left + 2, frame.bottom - 1, paint);
    canvas.drawRect(frame.right - 1, frame.top, frame.right + 1, frame.bottom - 1, paint);
    canvas.drawRect(frame.left, frame.bottom - 1, frame.right + 1, frame.bottom + 1, paint);

    // Draw the framing rect corner UI elements
    paint.setColor(cornerColor);
    canvas.drawRect(frame.left - 15, frame.top - 15, frame.left + 15, frame.top, paint);
    canvas.drawRect(frame.left - 15, frame.top, frame.left, frame.top + 15, paint);
    canvas.drawRect(frame.right - 15, frame.top - 15, frame.right + 15, frame.top, paint);
    canvas.drawRect(frame.right, frame.top - 15, frame.right + 15, frame.top + 15, paint);
    canvas.drawRect(frame.left - 15, frame.bottom, frame.left + 15, frame.bottom + 15, paint);
    canvas.drawRect(frame.left - 15, frame.bottom - 15, frame.left, frame.bottom, paint);
    canvas.drawRect(frame.right - 15, frame.bottom, frame.right + 15, frame.bottom + 15, paint);
    canvas.drawRect(frame.right, frame.bottom - 15, frame.right + 15, frame.bottom + 15, paint);

    // Request another update at the animation interval, but don't repaint the entire viewfinder mask.
    //postInvalidateDelayed(ANIMATION_DELAY, frame.left, frame.top, frame.right, frame.bottom);
}

From source file:com.jjoe64.graphview.GridLabelRenderer.java

/**
 * calculates the vertical label size//from   w w w.j av  a2 s . co m
 * @param canvas canvas
 */
protected void calcLabelVerticalSize(Canvas canvas) {
    // test label with first and last label
    String testLabel = mLabelFormatter.formatLabel(mGraphView.getViewport().getMaxY(false), false);
    if (testLabel == null)
        testLabel = "";

    Rect textBounds = new Rect();
    mPaintLabel.getTextBounds(testLabel, 0, testLabel.length(), textBounds);
    mLabelVerticalWidth = textBounds.width();
    mLabelVerticalHeight = textBounds.height();

    testLabel = mLabelFormatter.formatLabel(mGraphView.getViewport().getMinY(false), false);
    if (testLabel == null)
        testLabel = "";

    mPaintLabel.getTextBounds(testLabel, 0, testLabel.length(), textBounds);
    mLabelVerticalWidth = Math.max(mLabelVerticalWidth, textBounds.width());

    // add some pixel to get a margin
    mLabelVerticalWidth += 6;

    // space between text and graph content
    mLabelVerticalWidth += mStyles.labelsSpace;

    // multiline
    int lines = 1;
    for (byte c : testLabel.getBytes()) {
        if (c == '\n')
            lines++;
    }
    mLabelVerticalHeight *= lines;
}

From source file:com.aidy.launcher3.ui.folder.Folder.java

private void centerAboutIcon() {
    DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();

    DragLayer parent = (DragLayer) mLauncher.findViewById(R.id.drag_layer);
    int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth();
    int height = getFolderHeight();

    float scale = parent.getDescendantRectRelativeToSelf(mFolderIcon, mTempRect);

    LauncherAppState app = LauncherAppState.getInstance();
    DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();

    int centerX = (int) (mTempRect.left + mTempRect.width() * scale / 2);
    int centerY = (int) (mTempRect.top + mTempRect.height() * scale / 2);
    int centeredLeft = centerX - width / 2;
    int centeredTop = centerY - height / 2;
    int currentPage = mLauncher.getWorkspace().getNextPage();
    // In case the workspace is scrolling, we need to use the final scroll
    // to compute
    // the folders bounds.
    mLauncher.getWorkspace().setFinalScrollForPageChange(currentPage);
    // We first fetch the currently visible CellLayoutChildren
    CellLayout currentLayout = (CellLayout) mLauncher.getWorkspace().getChildAt(currentPage);
    ShortcutAndWidgetContainer boundingLayout = currentLayout.getShortcutsAndWidgets();
    Rect bounds = new Rect();
    parent.getDescendantRectRelativeToSelf(boundingLayout, bounds);
    // We reset the workspaces scroll
    mLauncher.getWorkspace().resetFinalScrollForPageChange(currentPage);

    // We need to bound the folder to the currently visible
    // CellLayoutChildren
    int left = Math.min(Math.max(bounds.left, centeredLeft), bounds.left + bounds.width() - width);
    int top = Math.min(Math.max(bounds.top, centeredTop), bounds.top + bounds.height() - height);
    if (grid.isPhone() && (grid.availableWidthPx - width) < grid.iconSizePx) {
        // Center the folder if it is full (on phones only)
        left = (grid.availableWidthPx - width) / 2;
    } else if (width >= bounds.width()) {
        // If the folder doesn't fit within the bounds, center it about the
        // desired bounds
        left = bounds.left + (bounds.width() - width) / 2;
    }//from  w w  w  .  ja v  a  2  s. c  o  m
    if (height >= bounds.height()) {
        top = bounds.top + (bounds.height() - height) / 2;
    }

    int folderPivotX = width / 2 + (centeredLeft - left);
    int folderPivotY = height / 2 + (centeredTop - top);
    setPivotX(folderPivotX);
    setPivotY(folderPivotY);
    mFolderIconPivotX = (int) (mFolderIcon.getMeasuredWidth() * (1.0f * folderPivotX / width));
    mFolderIconPivotY = (int) (mFolderIcon.getMeasuredHeight() * (1.0f * folderPivotY / height));

    lp.width = width;
    lp.height = height;
    lp.x = left;
    lp.y = top;
}

From source file:com.facebook.litho.LayoutState.java

void createDisplayList(LayoutOutput output) {
    ThreadUtils.assertMainThread();/*w  w w  .  jav  a2 s .c  o m*/

    final Component component = output.getComponent();
    ComponentsSystrace.beginSection("createDisplayList: " + component.getSimpleName());
    final ComponentLifecycle lifecycle = component.getLifecycle();
    final DisplayList displayList = DisplayList.createDisplayList(lifecycle.getClass().getSimpleName());

    if (displayList == null) {
        ComponentsSystrace.endSection();
        return;
    }

    final ComponentContext context = mContext;

    Drawable drawable = (Drawable) ComponentsPools.acquireMountContent(context, lifecycle.getId());
    if (drawable == null) {
        drawable = (Drawable) lifecycle.createMountContent(context);
    }

    final LayoutOutput clickableOutput = findInteractiveRoot(this, output);
    boolean isStateEnabled = false;

    if (clickableOutput != null && clickableOutput.getNodeInfo() != null) {
        final NodeInfo nodeInfo = clickableOutput.getNodeInfo();

        if (nodeInfo.hasTouchEventHandlers() || nodeInfo.getFocusState() == FOCUS_SET_TRUE) {
            isStateEnabled = true;
        }
    }

    if (isStateEnabled) {
        drawable.setState(DRAWABLE_STATE_ENABLED);
    } else {
        drawable.setState(DRAWABLE_STATE_NOT_ENABLED);
    }

    lifecycle.mount(context, drawable, component);
    lifecycle.bind(context, drawable, component);

    final Rect rect = mDisplayListCreateRect;

    output.getMountBounds(rect);
    drawable.setBounds(0, 0, rect.width(), rect.height());

    try {
        final Canvas canvas = displayList.start(rect.width(), rect.height());
        drawable.draw(canvas);

        displayList.end(canvas);
        displayList.setBounds(rect.left, rect.top, rect.right, rect.bottom);

        output.setDisplayList(displayList);
    } catch (DisplayListException e) {
        // Display list creation failed. Make sure the DisplayList for this output is set
        // to null.
        output.setDisplayList(null);
    }

    lifecycle.unbind(context, drawable, component);
    lifecycle.unmount(context, drawable, component);
    ComponentsPools.release(context, lifecycle, drawable);
    ComponentsSystrace.endSection();
}

From source file:com.llf.android.launcher3.Folder.java

private void centerAboutIcon() {
    DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();

    DragLayer parent = (DragLayer) mLauncher.findViewById(R.id.drag_layer);
    int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth();
    int height = getFolderHeight();

    float scale = parent.getDescendantRectRelativeToSelf(mFolderIcon, mTempRect);

    LauncherAppState app = LauncherAppState.getInstance();
    DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();

    int centerX = (int) (mTempRect.left + mTempRect.width() * scale / 2);
    int centerY = (int) (mTempRect.top + mTempRect.height() * scale / 2);
    int centeredLeft = centerX - width / 2;
    int centeredTop = centerY - height / 2;
    int currentPage = mLauncher.getWorkspace().getNextPage();
    // In case the workspace is scrolling, we need to use the final scroll
    // to compute
    // the folders bounds.
    mLauncher.getWorkspace().setFinalScrollForPageChange(currentPage);
    // We first fetch the currently visible CellLayoutChildren
    CellLayout currentLayout = (CellLayout) mLauncher.getWorkspace().getChildAt(currentPage);
    ShortcutAndWidgetContainer boundingLayout = currentLayout.getShortcutsAndWidgets();
    Rect bounds = new Rect();
    parent.getDescendantRectRelativeToSelf(boundingLayout, bounds);
    // We reset the workspaces scroll
    mLauncher.getWorkspace().resetFinalScrollForPageChange(currentPage);

    // We need to bound the folder to the currently visible
    // CellLayoutChildren
    int left = Math.min(Math.max(bounds.left, centeredLeft), bounds.left + bounds.width() - width);
    int top = Math.min(Math.max(bounds.top, centeredTop), bounds.top + bounds.height() - height);
    if (grid.isPhone() && (grid.availableWidthPx - width) < grid.iconSizePx) {
        // Center the folder if it is full (on phones only)
        left = (grid.availableWidthPx - width) / 2;
    } else if (width >= bounds.width()) {
        // If the folder doesn't fit within the bounds, center it about the
        // desired bounds
        left = bounds.left + (bounds.width() - width) / 2;
    }//w  ww .  j a  va 2 s.c o m
    if (height >= bounds.height()) {
        top = bounds.top + (bounds.height() - height) / 2;
    }

    int folderPivotX = width / 2 + (centeredLeft - left);
    int folderPivotY = height / 2 + (centeredTop - top);
    // setPivotX(folderPivotX);
    ViewHelper.setPivotX(this, folderPivotX);
    // setPivotY(folderPivotY);
    ViewHelper.setPivotY(this, folderPivotY);
    mFolderIconPivotX = (int) (mFolderIcon.getMeasuredWidth() * (1.0f * folderPivotX / width));
    mFolderIconPivotY = (int) (mFolderIcon.getMeasuredHeight() * (1.0f * folderPivotY / height));

    lp.width = width;
    lp.height = height;
    lp.x = left;
    lp.y = top;
}

From source file:com.jjoe64.graphview.GridLabelRenderer.java

/**
 * calculates the vertical second scale//  w  w w  . j a v  a 2  s .  co m
 * label size
 * @param canvas canvas
 */
protected void calcLabelVerticalSecondScaleSize(Canvas canvas) {
    if (mGraphView.mSecondScale == null) {
        mLabelVerticalSecondScaleWidth = 0;
        mLabelVerticalSecondScaleHeight = 0;
        return;
    }

    // test label
    double testY = ((mGraphView.mSecondScale.getMaxY() - mGraphView.mSecondScale.getMinY()) * 0.783)
            + mGraphView.mSecondScale.getMinY();
    String testLabel = mGraphView.mSecondScale.getLabelFormatter().formatLabel(testY, false);
    Rect textBounds = new Rect();
    mPaintLabel.getTextBounds(testLabel, 0, testLabel.length(), textBounds);
    mLabelVerticalSecondScaleWidth = textBounds.width();
    mLabelVerticalSecondScaleHeight = textBounds.height();

    // multiline
    int lines = 1;
    for (byte c : testLabel.getBytes()) {
        if (c == '\n')
            lines++;
    }
    mLabelVerticalSecondScaleHeight *= lines;
}

From source file:radialdemo.RadialMenuWidget.java

@Override
protected void onDraw(Canvas c) {

    Paint paint = new Paint();
    paint.setAntiAlias(true);/*from  w w w.j av  a  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.pdftron.pdf.tools.Tool.java

public void onDraw(Canvas canvas, android.graphics.Matrix tfm) {
    // Draw page number
    if (mShowPageNum && mPageNumberIndicatorVisible) {
        int width = mPDFView.getWidth();
        int height = mPDFView.getHeight();
        int page_num = mPDFView.getCurrentPage();
        boolean restore = false;
        float yOffset = 0;

        try {// ww  w  . j  av a  2s .c om
            // During page sliding, PDFViewCtrl might apply extra transformation
            // matrix to Canvas for animation. However, page number should not
            // move; hence applying the inverse to offset it.
            if (!tfm.isIdentity()) {
                canvas.save();
                restore = true;
                tfm.invert(mTempMtx1);
                canvas.getMatrix(mTempMtx2);
                mTempMtx2.postConcat(mTempMtx1);
                canvas.setMatrix(mTempMtx2);

                // Workaround for bug found in Android > ICS with hardware acceleration turned
                // ON. See http://code.google.com/p/android/issues/detail?id=24517 for more info
                if (Build.VERSION.SDK_INT >= 14
                        /*Build.VERSION_CODES.ICE_CREAM_SANDWICH*/ && mPDFView.isHardwareAccelerated()) {
                    Rect rectangle = new Rect();
                    ((android.app.Activity) mPDFView.getContext()).getWindow().getDecorView()
                            .getWindowVisibleDisplayFrame(rectangle);
                    yOffset = rectangle.top;
                }
            }

            int page_count = mPDFView.getDoc().getPageCount();
            String str = String.format(getStringFromResId(R.string.tools_misc_pagerange), page_num, page_count);

            Rect r = new Rect();
            mPaint4PageNum.getTextBounds(str, 0, str.length(), r);
            float str_width = r.width();
            float str_height = r.height();

            float margin = str_height / 1.5f;
            float left = width - str_width * 1.5f - margin + mPDFView.getScrollX();

            float top = mPDFView.getScrollY() + height - mPageNumPosAdjust - str_height * 3.0f + yOffset;

            float right = left + str_width + margin * 2;
            float bottom = top + str_height + margin * 2;

            mTempPageDrawingRectF.set(left, top, right, bottom);
            mPaint4PageNum.setColor(
                    mPDFView.getContext().getResources().getColor(R.color.tools_pageindicator_background));
            canvas.drawRoundRect(mTempPageDrawingRectF, margin, margin, mPaint4PageNum);

            mPaint4PageNum
                    .setColor(mPDFView.getContext().getResources().getColor(R.color.tools_pageindicator_text));
            left += margin;
            top += str_height / 2 + margin + mPaint4PageNum.descent();

            canvas.drawText(str, left, top - 0.5f, mPaint4PageNum);

        } catch (Exception e) {

        } finally {
            if (restore) {
                canvas.restore();
            }
        }
    }
}