Example usage for android.graphics Rect width

List of usage examples for android.graphics Rect width

Introduction

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

Prototype

public final int width() 

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 .j  a  v a2 s  .com
    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   ww  w. j  ava 2 s  . c om
 * **/
private void animateDragged() {
    if (mLastDragged >= 0) {
        final View v = getChildAt(mLastDragged);

        final Rect r = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
        r.inset(-r.width() / 20, -r.height() / 20);
        v.measure(MeasureSpec.makeMeasureSpec(r.width(), MeasureSpec.EXACTLY),
                MeasureSpec.makeMeasureSpec(r.height(), MeasureSpec.EXACTLY));
        v.layout(r.left, r.top, r.right, r.bottom);

        AnimationSet animSet = new AnimationSet(true);
        ScaleAnimation scale = new ScaleAnimation(0.9091f, 1, 0.9091f, 1, v.getWidth() / 2, v.getHeight() / 2);
        scale.setDuration(ANIMATION_DURATION);
        AlphaAnimation alpha = new AlphaAnimation(1, .5f);
        alpha.setDuration(ANIMATION_DURATION);

        animSet.addAnimation(scale);
        animSet.addAnimation(alpha);
        animSet.setFillEnabled(true);
        animSet.setFillAfter(true);

        v.clearAnimation();
        v.startAnimation(animSet);
    }
}

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  ww .j a  va 2 s  . c om
    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.example.firstocr.ViewfinderView.java

@SuppressWarnings("unused")
@Override/*from  ww  w. ja va 2  s .co m*/
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.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;
    }/*from  ww  w . jav a2 s. co  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.icloud.listenbook.base.view.DraggableGridViewPager.java

/**
 * ?/*  w  ww.  j  a va  2s .  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.jjoe64.graphview.GridLabelRenderer.java

/**
 * calculates the vertical label size/*from  w w  w  . j ava2s.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.jjoe64.graphview.GridLabelRenderer.java

/**
 * calculates the vertical second scale//  w ww . j a v a2 s. c  o 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:com.jjoe64.graphview.GridLabelRenderer.java

/**
 * calculates the horizontal label size/*  w  w  w .j  a v a 2s .  c o m*/
 * @param canvas canvas
 */
protected void calcLabelHorizontalSize(Canvas canvas) {
    // test label
    double testX = ((mGraphView.getViewport().getMaxX(false) - mGraphView.getViewport().getMinX(false)) * 0.783)
            + mGraphView.getViewport().getMinX(false);
    String testLabel = mLabelFormatter.formatLabel(testX, true);
    if (testLabel == null) {
        testLabel = "";
    }
    Rect textBounds = new Rect();
    mPaintLabel.getTextBounds(testLabel, 0, testLabel.length(), textBounds);
    mLabelHorizontalWidth = textBounds.width();

    if (!mLabelHorizontalHeightFixed) {
        mLabelHorizontalHeight = textBounds.height();

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

        mLabelHorizontalHeight = (int) Math.max(mLabelHorizontalHeight, mStyles.textSize);
    }

    if (mStyles.horizontalLabelsAngle > 0f && mStyles.horizontalLabelsAngle <= 180f) {
        int adjHorizontalHeightH = (int) Math.round(
                Math.abs(mLabelHorizontalHeight * Math.cos(Math.toRadians(mStyles.horizontalLabelsAngle))));
        int adjHorizontalHeightW = (int) Math.round(
                Math.abs(mLabelHorizontalWidth * Math.sin(Math.toRadians(mStyles.horizontalLabelsAngle))));
        int adjHorizontalWidthH = (int) Math.round(
                Math.abs(mLabelHorizontalHeight * Math.sin(Math.toRadians(mStyles.horizontalLabelsAngle))));
        int adjHorizontalWidthW = (int) Math.round(
                Math.abs(mLabelHorizontalWidth * Math.cos(Math.toRadians(mStyles.horizontalLabelsAngle))));

        mLabelHorizontalHeight = adjHorizontalHeightH + adjHorizontalHeightW;
        mLabelHorizontalWidth = adjHorizontalWidthH + adjHorizontalWidthW;
    }

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

From source file:com.wb.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);
    //*/modified by xuchao for folder fullscreen 20140513
    int centeredLeft = (mLauncher.getWindowManager().getDefaultDisplay().getWidth() - width) / 2;
    int centeredTop = (mLauncher.getWindowManager().getDefaultDisplay().getHeight() - height) / 2;
    //*//*from  w  ww . j ava  2  s. c o m*/
    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;
    }
    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;
}