List of usage examples for android.graphics Rect height
public final int height()
From source file:com.android.launcher3.Workspace.java
private static Rect getDrawableBounds(Drawable d) { Rect bounds = new Rect(); d.copyBounds(bounds);// w ww .j ava 2s . co m if (bounds.width() == 0 || bounds.height() == 0) { bounds.set(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); } else { bounds.offsetTo(0, 0); } if (d instanceof PreloadIconDrawable) { int inset = -((PreloadIconDrawable) d).getOutset(); bounds.inset(inset, inset); } return bounds; }
From source file:com.android.launcher3.Workspace.java
/** * Draw the View v into the given Canvas. * * @param v the view to draw/*from ww w .j a v a2 s . c o m*/ * @param destCanvas the canvas to draw on * @param padding the horizontal and vertical padding to use when drawing */ private static void drawDragView(View v, Canvas destCanvas, int padding) { final Rect clipRect = sTempRect; v.getDrawingRect(clipRect); boolean textVisible = false; destCanvas.save(); if (v instanceof TextView) { Drawable d = ((TextView) v).getCompoundDrawables()[1]; Rect bounds = getDrawableBounds(d); clipRect.set(0, 0, bounds.width() + padding, bounds.height() + padding); destCanvas.translate(padding / 2 - bounds.left, padding / 2 - bounds.top); d.draw(destCanvas); } else { if (v instanceof FolderIcon) { // For FolderIcons the text can bleed into the icon area, and so we need to // hide the text completely (which can't be achieved by clipping). if (((FolderIcon) v).getTextVisible()) { ((FolderIcon) v).setTextVisible(false); textVisible = true; } } destCanvas.translate(-v.getScrollX() + padding / 2, -v.getScrollY() + padding / 2); destCanvas.clipRect(clipRect, Op.REPLACE); v.draw(destCanvas); // Restore text visibility of FolderIcon if necessary if (textVisible) { ((FolderIcon) v).setTextVisible(true); } } destCanvas.restore(); }
From source file:com.android.launcher2.Workspace.java
private void getFinalPositionForDropAnimation(int[] loc, float[] scaleXY, DragView dragView, CellLayout layout, ItemInfo info, int[] targetCell, boolean external, boolean scale) { // Now we animate the dragView, (ie. the widget or shortcut preview) into its final // location and size on the home screen. int spanX = info.spanX; int spanY = info.spanY; Rect r = estimateItemPosition(layout, info, targetCell[0], targetCell[1], spanX, spanY); loc[0] = r.left;// w w w . ja va 2s . c om loc[1] = r.top; setFinalTransitionTransform(layout); float cellLayoutScale = mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(layout, loc); resetTransitionTransform(layout); float dragViewScaleX; float dragViewScaleY; if (scale) { dragViewScaleX = (1.0f * r.width()) / dragView.getMeasuredWidth(); dragViewScaleY = (1.0f * r.height()) / dragView.getMeasuredHeight(); } else { dragViewScaleX = 1f; dragViewScaleY = 1f; } // The animation will scale the dragView about its center, so we need to center about // the final location. loc[0] -= (dragView.getMeasuredWidth() - cellLayoutScale * r.width()) / 2; loc[1] -= (dragView.getMeasuredHeight() - cellLayoutScale * r.height()) / 2; scaleXY[0] = dragViewScaleX * cellLayoutScale; scaleXY[1] = dragViewScaleY * cellLayoutScale; }
From source file:net.robotmedia.acv.ui.widget.OcrLayout.java
public boolean createTriggerCaptureBox(Point pt) { final int IDEAL_CAP_WIDTH = 100; final int IDEAL_CAP_HALF_WIDTH = IDEAL_CAP_WIDTH / 2; final int IDEAL_CAP_HEIGHT = 450; final int IDEAL_CAP_ABOVE_PT = 35; final int IDEAL_LOOKAHEAD = 30; final int FALLBACK_WIDTH = 70; final int FALLBACK_HEIGHT = 200; final int FALLBACK_ABOVE_PT = 10; View v = this.comicView; if (v != null) { try {//from w w w. j a va 2s . c o m // Only create the bitmap that contains the entire screen once if (this.lastScreenshot == null) { this.lastScreenshot = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888); this.captureCanvas = new Canvas(this.lastScreenshot); } v.layout(0, 0, v.getWidth(), v.getHeight()); // Draw the comic view to the lastScreenshot bitmap v.draw(this.captureCanvas); Rect cropRect = new Rect(); if (this.textOrientation == TEXT_ORIENTATION_HORIZONTAL) { cropRect.left = Math.max(0, pt.x - IDEAL_CAP_ABOVE_PT); cropRect.top = Math.max(0, pt.y - IDEAL_CAP_HALF_WIDTH); cropRect.right = Math.min(v.getWidth(), pt.x + IDEAL_CAP_HEIGHT); cropRect.bottom = Math.min(v.getHeight(), pt.y + IDEAL_CAP_HALF_WIDTH); } else // Vertical or Auto { cropRect.left = Math.max(0, pt.x - IDEAL_CAP_HALF_WIDTH); cropRect.top = Math.max(0, pt.y - IDEAL_CAP_ABOVE_PT); cropRect.right = Math.min(v.getWidth(), pt.x + IDEAL_CAP_HALF_WIDTH); cropRect.bottom = Math.min(v.getHeight(), pt.y + IDEAL_CAP_HEIGHT); } // Get bitmap that contains the area to crop Bitmap cropBmp = Bitmap.createBitmap(this.lastScreenshot, cropRect.left, cropRect.top, cropRect.width(), cropRect.height()); // Get the click point relative to the cropped area Point ptInCropRect = new Point(pt.x - cropRect.left, pt.y - cropRect.top); // Crop Pix pixs = ReadFile.readBitmap(cropBmp); if (pixs == null) { return false; } cropBmp.recycle(); // Convert to grayscale pixs = Convert.convertTo8(pixs); if (pixs == null) { return false; } Pix tempOtsu = Binarize.otsuAdaptiveThreshold(pixs, 2000, 2000, 0, 0, 0.0f); if (tempOtsu == null) { return false; } float ave = 0.0f; // Get the average intensity of the pixels around the click point if (this.textOrientation == TEXT_ORIENTATION_HORIZONTAL) { ave = Pix.averageInRect(tempOtsu, (int) (ptInCropRect.x * 0.9), (int) (ptInCropRect.y - (tempOtsu.getHeight() * 0.95) / 2.0), (int) (tempOtsu.getWidth() * 0.25), (int) (tempOtsu.getHeight() * 0.95)); } else // Vertical or Auto { ave = Pix.averageInRect(tempOtsu, (int) (ptInCropRect.x - (tempOtsu.getWidth() * 0.95) / 2.0), (int) (ptInCropRect.y * 0.9), (int) (tempOtsu.getWidth() * 0.95), (int) (tempOtsu.getHeight() * 0.25)); } tempOtsu.recycle(); // If background is dark if (ave >= 0.51f) { // Negate image boolean invertStatus = pixs.invert(); if (!invertStatus) { return false; } } // Blur to reduce noise pixs = Convolve.blockconvGray(pixs, 1, 1); if (pixs == null) { return false; } // Apply unsharp mask pixs = Enhance.unsharpMasking(pixs, 5, 2.5f); if (pixs == null) { return false; } // Binarize pixs = Binarize.otsuAdaptiveThreshold(pixs, 2000, 2000, 0, 0, 0.0f); if (pixs == null) { return false; } // Remove black pixels connected to the border. // This eliminates annoying things like text bubbles. pixs = Seedfill.removeBorderConnComps(pixs, 8); if (pixs == null) { return false; } // Find the black pixel closest to the click point Point nearestPixel = LeptUtils.findNearestBlackPixel(pixs, ptInCropRect.x, ptInCropRect.y, 40); // Get a bounding box surrounding the clicked text Rect boundingBox = BoundingTextRect.getBoundingRect(pixs, nearestPixel.x, nearestPixel.y, (this.textOrientation != TEXT_ORIENTATION_HORIZONTAL), IDEAL_LOOKAHEAD); // Form the capture box size and position based on click point and bounding box this.captureBox = new Rect(); this.captureBox.left = pt.x - ptInCropRect.x + boundingBox.left; this.captureBox.top = pt.y - ptInCropRect.y + boundingBox.top; this.captureBox.right = this.captureBox.left + boundingBox.width(); this.captureBox.bottom = this.captureBox.top + boundingBox.height(); // If could not find adequate bounding rectangle, fallback to a default size if (this.captureBox.width() <= 2 || this.captureBox.height() <= 2) { if (this.textOrientation == TEXT_ORIENTATION_HORIZONTAL) { this.captureBox = new Rect(); this.captureBox.left = Math.max(0, pt.x - FALLBACK_ABOVE_PT); this.captureBox.top = Math.max(0, pt.y - FALLBACK_WIDTH / 2); this.captureBox.right = Math.min(v.getWidth(), pt.x + FALLBACK_HEIGHT); this.captureBox.bottom = Math.min(v.getHeight(), pt.y + FALLBACK_WIDTH / 2); } else // Vertical or Auto { this.captureBox = new Rect(); this.captureBox.left = Math.max(0, pt.x - FALLBACK_WIDTH / 2); this.captureBox.top = Math.max(0, pt.y - FALLBACK_ABOVE_PT); this.captureBox.right = Math.min(v.getWidth(), pt.x + FALLBACK_WIDTH / 2); this.captureBox.bottom = Math.min(v.getHeight(), pt.y + FALLBACK_HEIGHT); } } pixs.recycle(); } catch (Exception e) { // If we're here, it's probably an out-of-memory exception Log.e(LOG_TAG, "Exception in processTriggerCapture()! " + e); return false; } } this.isTriggerCapture = true; return true; }
From source file:android.support.designox.widget.CoordinatorLayout.java
/** * Calculate the desired child rect relative to an anchor rect, respecting both * gravity and anchorGravity.//from ww w .ja va 2 s . c om * * @param child child view to calculate a rect for * @param layoutDirection the desired layout direction for the CoordinatorLayout * @param anchorRect rect in CoordinatorLayout coordinates of the anchor view area * @param out rect to set to the output values */ void getDesiredAnchoredChildRect(View child, int layoutDirection, Rect anchorRect, Rect out) { final LayoutParams lp = (LayoutParams) child.getLayoutParams(); final int absGravity = GravityCompat.getAbsoluteGravity(resolveAnchoredChildGravity(lp.gravity), layoutDirection); final int absAnchorGravity = GravityCompat.getAbsoluteGravity(resolveGravity(lp.anchorGravity), layoutDirection); final int hgrav = absGravity & Gravity.HORIZONTAL_GRAVITY_MASK; final int vgrav = absGravity & Gravity.VERTICAL_GRAVITY_MASK; final int anchorHgrav = absAnchorGravity & Gravity.HORIZONTAL_GRAVITY_MASK; final int anchorVgrav = absAnchorGravity & Gravity.VERTICAL_GRAVITY_MASK; final int childWidth = child.getMeasuredWidth(); final int childHeight = child.getMeasuredHeight(); int left; int top; // Align to the anchor. This puts us in an assumed right/bottom child view gravity. // If this is not the case we will subtract out the appropriate portion of // the child size below. switch (anchorHgrav) { default: case Gravity.LEFT: left = anchorRect.left; break; case Gravity.RIGHT: left = anchorRect.right; break; case Gravity.CENTER_HORIZONTAL: left = anchorRect.left + anchorRect.width() / 2; break; } switch (anchorVgrav) { default: case Gravity.TOP: top = anchorRect.top; break; case Gravity.BOTTOM: top = anchorRect.bottom; break; case Gravity.CENTER_VERTICAL: top = anchorRect.top + anchorRect.height() / 2; break; } // Offset by the child view's gravity itself. The above assumed right/bottom gravity. switch (hgrav) { default: case Gravity.LEFT: left -= childWidth; break; case Gravity.RIGHT: // Do nothing, we're already in position. break; case Gravity.CENTER_HORIZONTAL: left -= childWidth / 2; break; } switch (vgrav) { default: case Gravity.TOP: top -= childHeight; break; case Gravity.BOTTOM: // Do nothing, we're already in position. break; case Gravity.CENTER_VERTICAL: top -= childHeight / 2; break; } final int width = getWidth(); final int height = getHeight(); // Obey margins and padding left = Math.max(getPaddingLeft() + lp.leftMargin, Math.min(left, width - getPaddingRight() - childWidth - lp.rightMargin)); top = Math.max(getPaddingTop() + lp.topMargin, Math.min(top, height - getPaddingBottom() - childHeight - lp.bottomMargin)); out.set(left, top, left + childWidth, top + childHeight); }
From source file:cc.flydev.launcher.Workspace.java
public int[] estimateItemSize(int hSpan, int vSpan, ItemInfo itemInfo, boolean springLoaded) { int[] size = new int[2]; if (getChildCount() > 0) { // Use the first non-custom page to estimate the child position CellLayout cl = (CellLayout) getChildAt(numCustomPages()); Rect r = estimateItemPosition(cl, itemInfo, 0, 0, hSpan, vSpan); size[0] = r.width();/*from www .j ava2 s. c o m*/ size[1] = r.height(); if (springLoaded) { size[0] *= mSpringLoadedShrinkFactor; size[1] *= mSpringLoadedShrinkFactor; } return size; } else { size[0] = Integer.MAX_VALUE; size[1] = Integer.MAX_VALUE; return size; } }
From source file:com.nttec.everychan.ui.presentation.BoardFragment.java
/** * ? ? ?/*from w w w .j a va 2 s . c om*/ * @param itemPosition ? ? (?) listView * @param isTablet true, ? (?? ? ??) * @param coordinates ?? */ private void showPostPopupDialog(final int itemPosition, final boolean isTablet, final Point coordinates, final String refererPost) { final int bgShadowResource = ThemeUtils.getThemeResId(activity.getTheme(), R.attr.dialogBackgroundShadow); final int bgColor = ThemeUtils.getThemeColor(activity.getTheme(), R.attr.activityRootBackground, Color.BLACK); final int measuredWidth = isTablet ? adapter.measureViewWidth(itemPosition) : -1; //? ?? ? final View tmpV = new View(activity); final Dialog tmpDlg = new Dialog(activity); tmpDlg.getWindow().setBackgroundDrawableResource(bgShadowResource); tmpDlg.requestWindowFeature(Window.FEATURE_NO_TITLE); tmpDlg.setCanceledOnTouchOutside(true); tmpDlg.setContentView(tmpV); final Rect activityWindowRect; final int dlgWindowWidth; final int dlgWindowHeight; if (isTablet) { activityWindowRect = new Rect(); activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(activityWindowRect); dlgWindowWidth = Math.max(coordinates.x, activityWindowRect.width() - coordinates.x); dlgWindowHeight = Math.max(coordinates.y, activityWindowRect.height() - coordinates.y); tmpDlg.getWindow().setLayout(dlgWindowWidth, dlgWindowHeight); } else { activityWindowRect = null; dlgWindowWidth = -1; dlgWindowHeight = -1; } tmpDlg.show(); Runnable next = new Runnable() { @SuppressLint("RtlHardcoded") @Override public void run() { int dlgWidth = tmpV.getWidth(); int dlgHeight = tmpV.getHeight(); tmpDlg.hide(); tmpDlg.cancel(); int newWidth = isTablet ? Math.min(measuredWidth, dlgWidth) : dlgWidth; View view = adapter.getView(itemPosition, null, null, newWidth, refererPost); view.setBackgroundColor(bgColor); //Logger.d(TAG, "measured: "+view.findViewById(R.id.post_frame_main).getMeasuredWidth()+ // "x"+view.findViewById(R.id.post_frame_main).getMeasuredHeight()); Dialog dialog = new Dialog(activity); dialog.getWindow().setBackgroundDrawableResource(bgShadowResource); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCanceledOnTouchOutside(true); dialog.setContentView(view); if (isTablet) { view.findViewById(R.id.post_frame_main).measure( MeasureSpec.makeMeasureSpec(newWidth, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); int newWindowWidth = dlgWindowWidth - dlgWidth + newWidth; int newWindowHeight = dlgWindowHeight - dlgHeight + Math.min(view.findViewById(R.id.post_frame_main).getMeasuredHeight(), dlgHeight); dialog.getWindow().setLayout(newWindowWidth, newWindowHeight); WindowManager.LayoutParams params = dialog.getWindow().getAttributes(); if (coordinates.x > activityWindowRect.width() - coordinates.x && coordinates.x + newWindowWidth > activityWindowRect.width()) { params.x = activityWindowRect.width() - coordinates.x; params.gravity = Gravity.RIGHT; } else { params.x = coordinates.x; params.gravity = Gravity.LEFT; } if (coordinates.y > activityWindowRect.height() - coordinates.y && coordinates.y + newWindowHeight > activityWindowRect.height()) { params.y = activityWindowRect.height() - coordinates.y; params.gravity |= Gravity.BOTTOM; } else { params.y = coordinates.y; params.gravity |= Gravity.TOP; } dialog.getWindow().setAttributes(params); // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { CompatibilityImpl.setDimAmount(dialog.getWindow(), 0.1f); } else { dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); } } dialog.show(); dialogs.add(dialog); } }; if (tmpV.getWidth() != 0) { next.run(); } else { AppearanceUtils.callWhenLoaded(tmpDlg.getWindow().getDecorView(), next); } }
From source file:android.support.design.widget.CoordinatorLayout.java
private void getDesiredAnchoredChildRectWithoutConstraints(View child, int layoutDirection, Rect anchorRect, Rect out, LayoutParams lp, int childWidth, int childHeight) { final int absGravity = GravityCompat.getAbsoluteGravity(resolveAnchoredChildGravity(lp.gravity), layoutDirection);//from ww w . j a v a2s . co m final int absAnchorGravity = GravityCompat.getAbsoluteGravity(resolveGravity(lp.anchorGravity), layoutDirection); final int hgrav = absGravity & Gravity.HORIZONTAL_GRAVITY_MASK; final int vgrav = absGravity & Gravity.VERTICAL_GRAVITY_MASK; final int anchorHgrav = absAnchorGravity & Gravity.HORIZONTAL_GRAVITY_MASK; final int anchorVgrav = absAnchorGravity & Gravity.VERTICAL_GRAVITY_MASK; int left; int top; // Align to the anchor. This puts us in an assumed right/bottom child view gravity. // If this is not the case we will subtract out the appropriate portion of // the child size below. switch (anchorHgrav) { default: case Gravity.LEFT: left = anchorRect.left; break; case Gravity.RIGHT: left = anchorRect.right; break; case Gravity.CENTER_HORIZONTAL: left = anchorRect.left + anchorRect.width() / 2; break; } switch (anchorVgrav) { default: case Gravity.TOP: top = anchorRect.top; break; case Gravity.BOTTOM: top = anchorRect.bottom; break; case Gravity.CENTER_VERTICAL: top = anchorRect.top + anchorRect.height() / 2; break; } // Offset by the child view's gravity itself. The above assumed right/bottom gravity. switch (hgrav) { default: case Gravity.LEFT: left -= childWidth; break; case Gravity.RIGHT: // Do nothing, we're already in position. break; case Gravity.CENTER_HORIZONTAL: left -= childWidth / 2; break; } switch (vgrav) { default: case Gravity.TOP: top -= childHeight; break; case Gravity.BOTTOM: // Do nothing, we're already in position. break; case Gravity.CENTER_VERTICAL: top -= childHeight / 2; break; } out.set(left, top, left + childWidth, top + childHeight); }
From source file:com.klinker.android.launcher.launcher3.Workspace.java
/** * Returns a new bitmap to show when the given View is being dragged around. * Responsibility for the bitmap is transferred to the caller. * @param expectedPadding padding to add to the drag view. If a different padding was used * its value will be changed//w w w .j av a 2 s . c o m */ public Bitmap createDragBitmap(View v, AtomicInteger expectedPadding) { Bitmap b; int padding = expectedPadding.get(); if (v instanceof TextView) { Drawable d = getTextViewIcon((TextView) v); Rect bounds = getDrawableBounds(d); b = Bitmap.createBitmap(bounds.width() + padding, bounds.height() + padding, Bitmap.Config.ARGB_8888); expectedPadding.set(padding - bounds.left - bounds.top); } else { b = Bitmap.createBitmap(v.getWidth() + padding, v.getHeight() + padding, Bitmap.Config.ARGB_8888); } mCanvas.setBitmap(b); drawDragView(v, mCanvas, padding); mCanvas.setBitmap(null); return b; }
From source file:com.klinker.android.launcher.launcher3.Workspace.java
public void onExternalDragStartedWithItem(View v) { // Compose a drag bitmap with the view scaled to the icon size DeviceProfile grid = mLauncher.getDeviceProfile(); int iconSize = grid.iconSizePx; int bmpWidth = v.getMeasuredWidth(); int bmpHeight = v.getMeasuredHeight(); // If this is a text view, use its drawable instead if (v instanceof TextView) { Drawable d = getTextViewIcon((TextView) v); Rect bounds = getDrawableBounds(d); bmpWidth = bounds.width();//from w w w . ja v a 2 s. c o m bmpHeight = bounds.height(); } // Compose the bitmap to create the icon from Bitmap b = Bitmap.createBitmap(bmpWidth, bmpHeight, Bitmap.Config.ARGB_8888); mCanvas.setBitmap(b); drawDragView(v, mCanvas, 0); mCanvas.setBitmap(null); // The outline is used to visualize where the item will land if dropped mDragOutline = createDragOutline(b, DRAG_BITMAP_PADDING, iconSize, iconSize, true); }