Example usage for android.graphics Rect Rect

List of usage examples for android.graphics Rect Rect

Introduction

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

Prototype

public Rect() 

Source Link

Document

Create a new empty Rect.

Usage

From source file:androidx.mediarouter.app.MediaRouteControllerDialog.java

/**
 * Updates the height of views and hide artwork or metadata if space is limited.
 *//*from  w w w.ja  v  a 2 s.  c om*/
void updateLayoutHeightInternal(boolean animate) {
    // Measure the size of widgets and get the height of main components.
    int oldHeight = getLayoutHeight(mMediaMainControlLayout);
    setLayoutHeight(mMediaMainControlLayout, ViewGroup.LayoutParams.MATCH_PARENT);
    updateMediaControlVisibility(canShowPlaybackControlLayout());
    View decorView = getWindow().getDecorView();
    decorView.measure(MeasureSpec.makeMeasureSpec(getWindow().getAttributes().width, MeasureSpec.EXACTLY),
            MeasureSpec.UNSPECIFIED);
    setLayoutHeight(mMediaMainControlLayout, oldHeight);
    int artViewHeight = 0;
    if (mCustomControlView == null && mArtView.getDrawable() instanceof BitmapDrawable) {
        Bitmap art = ((BitmapDrawable) mArtView.getDrawable()).getBitmap();
        if (art != null) {
            artViewHeight = getDesiredArtHeight(art.getWidth(), art.getHeight());
            mArtView.setScaleType(art.getWidth() >= art.getHeight() ? ImageView.ScaleType.FIT_XY
                    : ImageView.ScaleType.FIT_CENTER);
        }
    }
    int mainControllerHeight = getMainControllerHeight(canShowPlaybackControlLayout());
    int volumeGroupListCount = mGroupMemberRoutes.size();
    // Scale down volume group list items in landscape mode.
    int expandedGroupListHeight = getGroup() == null ? 0
            : mVolumeGroupListItemHeight * getGroup().getRoutes().size();
    if (volumeGroupListCount > 0) {
        expandedGroupListHeight += mVolumeGroupListPaddingTop;
    }
    expandedGroupListHeight = Math.min(expandedGroupListHeight, mVolumeGroupListMaxHeight);
    int visibleGroupListHeight = mIsGroupExpanded ? expandedGroupListHeight : 0;

    int desiredControlLayoutHeight = Math.max(artViewHeight, visibleGroupListHeight) + mainControllerHeight;
    Rect visibleRect = new Rect();
    decorView.getWindowVisibleDisplayFrame(visibleRect);
    // Height of non-control views in decor view.
    // This includes title bar, button bar, and dialog's vertical padding which should be
    // always shown.
    int nonControlViewHeight = mDialogAreaLayout.getMeasuredHeight()
            - mDefaultControlLayout.getMeasuredHeight();
    // Maximum allowed height for controls to fit screen.
    int maximumControlViewHeight = visibleRect.height() - nonControlViewHeight;

    // Show artwork if it fits the screen.
    if (mCustomControlView == null && artViewHeight > 0
            && desiredControlLayoutHeight <= maximumControlViewHeight) {
        mArtView.setVisibility(View.VISIBLE);
        setLayoutHeight(mArtView, artViewHeight);
    } else {
        if (getLayoutHeight(mVolumeGroupList)
                + mMediaMainControlLayout.getMeasuredHeight() >= mDefaultControlLayout.getMeasuredHeight()) {
            mArtView.setVisibility(View.GONE);
        }
        artViewHeight = 0;
        desiredControlLayoutHeight = visibleGroupListHeight + mainControllerHeight;
    }
    // Show the playback control if it fits the screen.
    if (canShowPlaybackControlLayout() && desiredControlLayoutHeight <= maximumControlViewHeight) {
        mPlaybackControlLayout.setVisibility(View.VISIBLE);
    } else {
        mPlaybackControlLayout.setVisibility(View.GONE);
    }
    updateMediaControlVisibility(mPlaybackControlLayout.getVisibility() == View.VISIBLE);
    mainControllerHeight = getMainControllerHeight(mPlaybackControlLayout.getVisibility() == View.VISIBLE);
    desiredControlLayoutHeight = Math.max(artViewHeight, visibleGroupListHeight) + mainControllerHeight;

    // Limit the volume group list height to fit the screen.
    if (desiredControlLayoutHeight > maximumControlViewHeight) {
        visibleGroupListHeight -= (desiredControlLayoutHeight - maximumControlViewHeight);
        desiredControlLayoutHeight = maximumControlViewHeight;
    }
    // Update the layouts with the computed heights.
    mMediaMainControlLayout.clearAnimation();
    mVolumeGroupList.clearAnimation();
    mDefaultControlLayout.clearAnimation();
    if (animate) {
        animateLayoutHeight(mMediaMainControlLayout, mainControllerHeight);
        animateLayoutHeight(mVolumeGroupList, visibleGroupListHeight);
        animateLayoutHeight(mDefaultControlLayout, desiredControlLayoutHeight);
    } else {
        setLayoutHeight(mMediaMainControlLayout, mainControllerHeight);
        setLayoutHeight(mVolumeGroupList, visibleGroupListHeight);
        setLayoutHeight(mDefaultControlLayout, desiredControlLayoutHeight);
    }
    // Maximize the window size with a transparent layout in advance for smooth animation.
    setLayoutHeight(mExpandableAreaLayout, visibleRect.height());
    rebuildVolumeGroupList(animate);
}

From source file:com.roger.lineselectionwebview.LSWebView.java

/**
 * Calculates the context menu display rect
 * //w  ww .j  a  v a 2 s.  c  o m
 * @param menuBounds
 * @return The display Rect
 */
protected Rect getContextMenuBounds(String menuBounds) {
    try {

        JSONObject menuBoundsObject = new JSONObject(menuBounds);

        float scale = getDensityIndependentValue(getScale(), mContext);

        Rect displayRect = new Rect();
        displayRect.left = (int) (getDensityDependentValue(menuBoundsObject.getInt("left"), getContext())
                * scale);
        displayRect.top = (int) (getDensityDependentValue(menuBoundsObject.getInt("top") - 25, getContext())
                * scale);
        displayRect.right = (int) (getDensityDependentValue(menuBoundsObject.getInt("right"), getContext())
                * scale);
        displayRect.bottom = (int) (getDensityDependentValue(menuBoundsObject.getInt("bottom") + 25,
                getContext()) * scale);

        return displayRect;

    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return null;
}

From source file:android.hqs.view.pager.indicator.TitlePageIndicator.java

/**
 * Calculate the bounds for a view's title
 *
 * @param index//from   ww w  .  j  a v a2s .  c o  m
 * @param paint
 * @return
 */
private Rect calcBounds(int index, Paint paint) {
    //Calculate the text bounds
    Rect bounds = new Rect();
    CharSequence title = getTitle(index);
    bounds.right = (int) paint.measureText(title, 0, title.length());
    bounds.bottom = (int) (paint.descent() - paint.ascent());
    return bounds;
}

From source file:com.chrynan.guitarchords.view.GuitarChordView.java

protected float getVerticalCenterTextPosition(float originalYPosition, String text, Paint textPaint) {
    Rect bounds = new Rect();
    textPaint.getTextBounds(text, 0, text.length(), bounds);
    return originalYPosition + (bounds.height() / 2);
}

From source file:android.support.v7.widget.helper.ItemTouchHelper.java

/**
 * If user drags the view to the edge, trigger a scroll if necessary.
 *//*from w w w  .  j  a v  a 2 s . co  m*/
private boolean scrollIfNecessary() {
    if (mSelected == null) {
        mDragScrollStartTimeInMs = Long.MIN_VALUE;
        return false;
    }
    final long now = System.currentTimeMillis();
    final long scrollDuration = mDragScrollStartTimeInMs == Long.MIN_VALUE ? 0 : now - mDragScrollStartTimeInMs;
    RecyclerView.LayoutManager lm = mRecyclerView.getLayoutManager();
    if (mTmpRect == null) {
        mTmpRect = new Rect();
    }
    int scrollX = 0;
    int scrollY = 0;
    lm.calculateItemDecorationsForChild(mSelected.itemView, mTmpRect);
    if (lm.canScrollHorizontally()) {
        int curX = (int) (mSelectedStartX + mDx);
        final int leftDiff = curX - mTmpRect.left - mRecyclerView.getPaddingLeft();
        if (mDx < 0 && leftDiff < 0) {
            scrollX = leftDiff;
        } else if (mDx > 0) {
            final int rightDiff = curX + mSelected.itemView.getWidth() + mTmpRect.right
                    - (mRecyclerView.getWidth() - mRecyclerView.getPaddingRight());
            if (rightDiff > 0) {
                scrollX = rightDiff;
            }
        }
    }
    if (lm.canScrollVertically()) {
        int curY = (int) (mSelectedStartY + mDy);
        final int topDiff = curY - mTmpRect.top - mRecyclerView.getPaddingTop();
        if (mDy < 0 && topDiff < 0) {
            scrollY = topDiff;
        } else if (mDy > 0) {
            final int bottomDiff = curY + mSelected.itemView.getHeight() + mTmpRect.bottom
                    - (mRecyclerView.getHeight() - mRecyclerView.getPaddingBottom());
            if (bottomDiff > 0) {
                scrollY = bottomDiff;
            }
        }
    }
    if (scrollX != 0) {
        scrollX = mCallback.interpolateOutOfBoundsScroll(mRecyclerView, mSelected.itemView.getWidth(), scrollX,
                mRecyclerView.getWidth(), scrollDuration);
    }
    if (scrollY != 0) {
        scrollY = mCallback.interpolateOutOfBoundsScroll(mRecyclerView, mSelected.itemView.getHeight(), scrollY,
                mRecyclerView.getHeight(), scrollDuration);
    }
    if (scrollX != 0 || scrollY != 0) {
        if (mDragScrollStartTimeInMs == Long.MIN_VALUE) {
            mDragScrollStartTimeInMs = now;
        }
        mRecyclerView.scrollBy(scrollX, scrollY);
        return true;
    }
    mDragScrollStartTimeInMs = Long.MIN_VALUE;
    return false;
}

From source file:com.roger.lineselectionwebview.LSWebView.java

@Override
public void tsjiSelectionClientRects(String rectStr, String selectContext) {
    // ???bottom/*from  www.  j a v  a 2 s  .c  o m*/
    // top+ ??bottom
    try {
        float scale = getDensityIndependentValue(getScale(), mContext);
        JSONArray jsonArray = new JSONArray(rectStr);
        int length = jsonArray.length();
        this.selectContext = selectContext;
        // TODO ,?new
        rectList = new ArrayList<Rect>();
        for (int i = 0; i < length; i++) {
            JSONObject jsonObject = jsonArray.getJSONObject(i);

            Rect handleRect = new Rect();
            handleRect.left = (int) (getDensityDependentValue(jsonObject.getInt("left"), getContext()) * scale);
            handleRect.top = (int) (getDensityDependentValue(jsonObject.getInt("top"), getContext()) * scale);
            handleRect.right = (int) (getDensityDependentValue(jsonObject.getInt("right"), getContext())
                    * scale);
            handleRect.bottom = (int) (getDensityDependentValue(jsonObject.getInt("bottom"), getContext())
                    * scale);
            // TODO
            // handleRect.bottom = 92;
            rectList.add(handleRect);
        }
    } catch (JSONException e) {
        // e.printStackTrace();
    }
}

From source file:com.mobiroller.tools.inappbrowser.MobirollerInAppBrowser.java

/**
 * Display a new browser with the specified URL.
 *
 * @param url           The url to load.
 * @param jsonObject/*  w ww  .ja  v a 2  s .co m*/
 */
public String showWebPage(final String url, final HashMap<String, Boolean> features) {
    // Determine if we should hide the location bar.
    showLocationBar = true;
    showZoomControls = false;
    openWindowHidden = false;
    if (features != null) {
        Boolean show = features.get(LOCATION);
        if (show != null) {
            showLocationBar = show.booleanValue();
        }
        Boolean zoom = features.get(ZOOM);
        if (zoom != null) {
            showZoomControls = zoom.booleanValue();
        }
        Boolean hidden = features.get(HIDDEN);
        if (hidden != null) {
            openWindowHidden = hidden.booleanValue();
        }
        Boolean hardwareBack = features.get(HARDWARE_BACK_BUTTON);
        if (hardwareBack != null) {
            hadwareBackButton = hardwareBack.booleanValue();
        }
        Boolean cache = features.get(CLEAR_ALL_CACHE);
        if (cache != null) {
            clearAllCache = cache.booleanValue();
        } else {
            cache = features.get(CLEAR_SESSION_CACHE);
            if (cache != null) {
                clearSessionCache = cache.booleanValue();
            }
        }
    }

    final CordovaWebView thatWebView = this.webView;

    // Create dialog in new thread
    Runnable runnable = new Runnable() {
        /**
         * Convert our DIP units to Pixels
         *
         * @return int
         */
        private int dpToPixels(int dipValue) {
            int value = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) dipValue,
                    cordova.getActivity().getResources().getDisplayMetrics());

            return value;
        }

        @SuppressLint("NewApi")
        public void run() {
            // Let's create the main dialog
            dialog = new MobirollerInAppBrowserDialog(cordova.getActivity(),
                    android.R.style.Theme_Translucent_NoTitleBar);
            dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);
            dialog.setInAppBroswer(getInAppBrowser());

            // Main container layout
            LinearLayout main = new LinearLayout(cordova.getActivity());
            main.setBackgroundColor(Color.TRANSPARENT);
            main.setOrientation(LinearLayout.VERTICAL);

            // Toolbar layout
            RelativeLayout toolbar = new RelativeLayout(cordova.getActivity());
            //Please, no more black!
            toolbar.setBackgroundColor(Color.TRANSPARENT);
            toolbar.setLayoutParams(new RelativeLayout.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT,
                    this.dpToPixels(44)));
            toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2));
            toolbar.setHorizontalGravity(Gravity.LEFT);
            toolbar.setVerticalGravity(Gravity.TOP);

            // Action Button Container layout
            RelativeLayout actionButtonContainer = new RelativeLayout(cordova.getActivity());
            actionButtonContainer.setLayoutParams(new RelativeLayout.LayoutParams(
                    WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT));
            actionButtonContainer.setHorizontalGravity(Gravity.LEFT);
            actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL);
            actionButtonContainer.setId(1);

            // Back button
            Button back = new Button(cordova.getActivity());
            RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams(
                    WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.MATCH_PARENT);
            backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT);
            back.setLayoutParams(backLayoutParams);
            back.setContentDescription("Back Button");
            back.setId(2);
            Resources activityRes = cordova.getActivity().getResources();
            int backResId = activityRes.getIdentifier("ic_action_previous_item", "drawable",
                    cordova.getActivity().getPackageName());
            Drawable backIcon = activityRes.getDrawable(backResId);
            if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
                back.setBackgroundDrawable(backIcon);
            } else {
                back.setBackground(backIcon);
            }
            back.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    goBack();
                }
            });

            // Forward button
            Button forward = new Button(cordova.getActivity());
            RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams(
                    WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.MATCH_PARENT);
            forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2);
            forward.setLayoutParams(forwardLayoutParams);
            forward.setContentDescription("Forward Button");
            forward.setId(3);
            int fwdResId = activityRes.getIdentifier("ic_action_next_item", "drawable",
                    cordova.getActivity().getPackageName());
            Drawable fwdIcon = activityRes.getDrawable(fwdResId);
            if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
                forward.setBackgroundDrawable(fwdIcon);
            } else {
                forward.setBackground(fwdIcon);
            }
            forward.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    goForward();
                }
            });

            // Edit Text Box
            edittext = new EditText(cordova.getActivity());
            RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(
                    WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
            textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1);
            textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5);
            edittext.setLayoutParams(textLayoutParams);
            edittext.setId(4);
            edittext.setSingleLine(true);
            edittext.setText(url);
            edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
            edittext.setImeOptions(EditorInfo.IME_ACTION_GO);
            edittext.setInputType(InputType.TYPE_NULL); // Will not except input... Makes the text NON-EDITABLE
            edittext.setOnKeyListener(new View.OnKeyListener() {
                public boolean onKey(View v, int keyCode, KeyEvent event) {
                    // If the event is a key-down event on the "enter" button
                    if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                        navigate(edittext.getText().toString());
                        return true;
                    }
                    return false;
                }
            });

            // Close/Done button
            Button close = new Button(cordova.getActivity());
            RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(
                    WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.MATCH_PARENT);
            closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            close.setLayoutParams(closeLayoutParams);
            forward.setContentDescription("Close Button");
            close.setId(5);
            int closeResId = activityRes.getIdentifier("ic_action_remove", "drawable",
                    cordova.getActivity().getPackageName());
            Drawable closeIcon = activityRes.getDrawable(closeResId);
            if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
                close.setBackgroundDrawable(closeIcon);
            } else {
                close.setBackground(closeIcon);
            }
            close.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    closeDialog();
                }
            });

            // WebView
            inAppWebView = new WebView(cordova.getActivity());
            inAppWebView.setLayoutParams(new LinearLayout.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT,
                    WindowManager.LayoutParams.MATCH_PARENT));
            inAppWebView.setWebChromeClient(new MobirollerInAppChromeClient(thatWebView));
            WebViewClient client = new InAppBrowserClient(thatWebView, edittext);
            inAppWebView.setWebViewClient(client);
            WebSettings settings = inAppWebView.getSettings();
            settings.setJavaScriptEnabled(true);
            settings.setJavaScriptCanOpenWindowsAutomatically(true);
            settings.setBuiltInZoomControls(showZoomControls);
            settings.setPluginState(android.webkit.WebSettings.PluginState.ON);

            //Toggle whether this is enabled or not!
            Bundle appSettings = cordova.getActivity().getIntent().getExtras();
            boolean enableDatabase = appSettings == null ? true
                    : appSettings.getBoolean("InAppBrowserStorageEnabled", true);
            if (enableDatabase) {
                String databasePath = cordova.getActivity().getApplicationContext()
                        .getDir("inAppBrowserDB", Context.MODE_PRIVATE).getPath();
                settings.setDatabasePath(databasePath);
                settings.setDatabaseEnabled(true);
            }
            settings.setDomStorageEnabled(true);

            if (clearAllCache) {
                CookieManager.getInstance().removeAllCookie();
            } else if (clearSessionCache) {
                CookieManager.getInstance().removeSessionCookie();
            }

            inAppWebView.loadUrl(url);
            inAppWebView.setId(6);
            inAppWebView.getSettings().setLoadWithOverviewMode(true);
            inAppWebView.getSettings().setUseWideViewPort(true);
            inAppWebView.requestFocus();
            inAppWebView.requestFocusFromTouch();

            // Add the back and forward buttons to our action button container layout
            actionButtonContainer.addView(back);
            actionButtonContainer.addView(forward);

            // Add the views to our toolbar
            //                toolbar.addView(actionButtonContainer);
            //                toolbar.addView(edittext);
            toolbar.addView(close);

            // Don't add the toolbar if its been disabled
            if (getShowLocationBar()) {
                // Add our toolbar to our main view/layout
                main.addView(toolbar);
            }

            // Add our webview to our main view/layout
            main.addView(inAppWebView);

            WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
            lp.copyFrom(dialog.getWindow().getAttributes());
            lp.width = WindowManager.LayoutParams.MATCH_PARENT;
            lp.height = WindowManager.LayoutParams.MATCH_PARENT;

            //Mobiroller Needs
            DisplayMetrics metrics = cordova.getActivity().getResources().getDisplayMetrics();
            Rect windowRect = new Rect();
            webView.getView().getWindowVisibleDisplayFrame(windowRect);

            int bottomGap = 0;
            if (features.containsKey("hasTabs")) {
                if (features.get("hasTabs")) {
                    bottomGap += Math.ceil(44 * metrics.density);
                }
            }
            lp.height = (windowRect.bottom - windowRect.top) - (bottomGap);
            lp.gravity = Gravity.TOP;
            lp.format = PixelFormat.TRANSPARENT;
            close.setAlpha(0);
            //Mobiroller Needs

            dialog.setContentView(main);
            dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            dialog.show();
            dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            dialog.getWindow().setAttributes(lp);
            // the goal of openhidden is to load the url and not display it
            // Show() needs to be called to cause the URL to be loaded
            if (openWindowHidden) {
                dialog.hide();
            }
        }
    };
    this.cordova.getActivity().runOnUiThread(runnable);
    return "";
}

From source file:net.exclaimindustries.geohashdroid.wiki.WikiPictureEditor.java

private static void drawStrings(String[] strings, Canvas c, Paint textPaint, Paint backgroundPaint) {
    // FIXME: The math here is ugly and blunt and probably not too
    // efficient or flexible.  It might even fail.  This needs to be
    // fixed and made less-ugly later.

    // We need SOME strings.  If we've got nothing, bail out.
    if (strings.length < 1)
        return;/*from   ww w  .  jav  a 2 s  .  com*/

    // First, init our variables.  This is as good a place as any to do so.
    Rect textBounds = new Rect();
    int[] heights = new int[strings.length];
    int totalHeight = INFOBOX_MARGIN * 2;
    int longestWidth = 0;

    // Now, loop through the strings, adding to the height and keeping track
    // of the longest width.
    int i = 0;
    for (String s : strings) {
        textPaint.getTextBounds(s, 0, s.length(), textBounds);
        if (textBounds.width() > longestWidth)
            longestWidth = textBounds.width();
        totalHeight += textBounds.height();
        heights[i] = textBounds.height();
        i++;
    }

    // Now, we have us a rectangle.  Draw that.
    Rect drawBounds = new Rect(c.getWidth() - longestWidth - (INFOBOX_MARGIN * 2), 0, c.getWidth(),
            totalHeight);

    c.drawRect(drawBounds, backgroundPaint);

    // Now, place each of the strings.  We'll assume the topmost one is in
    // index 0.  They should all be left-justified, too.
    i = 0;
    int curHeight = 0;
    for (String s : strings) {
        Log.d(DEBUG_TAG, "Drawing " + s + " at " + (drawBounds.left + INFOBOX_MARGIN) + ","
                + (INFOBOX_MARGIN + (INFOBOX_PADDING * (i + 1)) + curHeight));
        c.drawText(s, drawBounds.left + INFOBOX_MARGIN,
                INFOBOX_MARGIN + (INFOBOX_PADDING * (i + 1)) + curHeight, textPaint);
        curHeight += heights[i];
        i++;
    }
}

From source file:cc.flydev.launcher.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.java2 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);
    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.trailbehind.android.iburn.map.MapActivity.java

LinkedList<String> getUrlList() {
    final IMapSource mapSource = BURN_MAP_SOURCE;

    final WgsPoint startPoint = BURN_START_POINT;
    final WgsPoint endPoint = BURN_END_POINT;

    final int tileSize = mapSource.getTileSize();

    final LinkedList<String> urlList = new LinkedList<String>();
    for (int zoom = mapSource.getMinZoom(), endZoom = mapSource
            .getMaxZoom(), i = 0; zoom <= endZoom; zoom++, i++) {
        // switching to coord system
        final MapPos mapStartPos = mapSource.wgsToMapPos(startPoint.toInternalWgs(), zoom);
        final MapPos mapEndPos = mapSource.wgsToMapPos(endPoint.toInternalWgs(), zoom);

        final Rect overlayRect = new Rect();
        overlayRect.left = mapStartPos.getX() / tileSize;
        overlayRect.top = mapStartPos.getY() / tileSize;

        overlayRect.right = mapEndPos.getX() / tileSize;
        overlayRect.bottom = mapEndPos.getY() / tileSize;

        for (int x = overlayRect.left; x <= overlayRect.right; x++) {
            for (int y = overlayRect.top; y <= overlayRect.bottom; y++) {
                final int tileX = x * tileSize;
                final int tileY = y * tileSize;

                urlList.add(mapSource.buildPath(tileX, tileY, zoom));
            }/*  w w w .  ja va  2  s.com*/
        }
    }
    return urlList;
}