List of usage examples for android.graphics Rect width
public final int width()
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(); size[1] = r.height();/*from w w w . j a va 2s.c o m*/ 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.android.launcher3.CellLayout.java
void visualizeDropLocation(View v, Bitmap dragOutline, int cellX, int cellY, int spanX, int spanY, boolean resize, DropTarget.DragObject dragObject) { final int oldDragCellX = mDragCell[0]; final int oldDragCellY = mDragCell[1]; if (dragOutline == null && v == null) { return;/*from w w w.java 2 s . c o m*/ } if (cellX != oldDragCellX || cellY != oldDragCellY) { Point dragOffset = dragObject.dragView.getDragVisualizeOffset(); Rect dragRegion = dragObject.dragView.getDragRegion(); mDragCell[0] = cellX; mDragCell[1] = cellY; // Find the top left corner of the rect the object will occupy final int[] topLeft = mTmpPoint; cellToPoint(cellX, cellY, topLeft); int left = topLeft[0]; int top = topLeft[1]; if (v != null && dragOffset == null) { // When drawing the drag outline, it did not account for margin offsets // added by the view's parent. MarginLayoutParams lp = (MarginLayoutParams) v.getLayoutParams(); left += lp.leftMargin; top += lp.topMargin; // Offsets due to the size difference between the View and the dragOutline. // There is a size difference to account for the outer blur, which may lie // outside the bounds of the view. top += (v.getHeight() - dragOutline.getHeight()) / 2; // We center about the x axis left += ((mCellWidth * spanX) + ((spanX - 1) * mWidthGap) - dragOutline.getWidth()) / 2; } else { if (dragOffset != null && dragRegion != null) { // Center the drag region *horizontally* in the cell and apply a drag // outline offset left += dragOffset.x + ((mCellWidth * spanX) + ((spanX - 1) * mWidthGap) - dragRegion.width()) / 2; int cHeight = getShortcutsAndWidgets().getCellContentHeight(); int cellPaddingY = (int) Math.max(0, ((mCellHeight - cHeight) / 2f)); top += dragOffset.y + cellPaddingY; } else { // Center the drag outline in the cell left += ((mCellWidth * spanX) + ((spanX - 1) * mWidthGap) - dragOutline.getWidth()) / 2; top += ((mCellHeight * spanY) + ((spanY - 1) * mHeightGap) - dragOutline.getHeight()) / 2; } } final int oldIndex = mDragOutlineCurrent; mDragOutlineAnims[oldIndex].animateOut(); mDragOutlineCurrent = (oldIndex + 1) % mDragOutlines.length; Rect r = mDragOutlines[mDragOutlineCurrent]; r.set(left, top, left + dragOutline.getWidth(), top + dragOutline.getHeight()); if (resize) { cellToRect(cellX, cellY, spanX, spanY, r); } mDragOutlineAnims[mDragOutlineCurrent].setTag(dragOutline); mDragOutlineAnims[mDragOutlineCurrent].animateIn(); if (dragObject.stateAnnouncer != null) { String msg; if (isHotseat()) { msg = getContext().getString(R.string.move_to_hotseat_position, Math.max(cellX, cellY) + 1); } else { msg = getContext().getString(R.string.move_to_empty_cell, cellY + 1, cellX + 1); } dragObject.stateAnnouncer.announce(msg); } } }
From source file:com.nttec.everychan.ui.presentation.BoardFragment.java
/** * ? ? ?/*from w w w. ja v a 2 s . c o m*/ * @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: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(); bmpHeight = bounds.height();//w w w . jav a2s . co m } // 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); }
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//from www. ja v a 2s .co 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.aidy.launcher3.ui.workspace.Workspace.java
public int[] estimateItemSize(int hSpan, int vSpan, ItemInfoBean 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(); size[1] = r.height();/*from w ww . ja v a 2s. c o m*/ 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.klinker.android.launcher.launcher3.Workspace.java
public int[] estimateItemSize(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, itemInfo.spanX, itemInfo.spanY); size[0] = r.width(); size[1] = r.height();/*from ww w . j ava 2s .c om*/ 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.android.leanlauncher.CellLayout.java
void visualizeDropLocation(View v, Bitmap dragOutline, int originX, int originY, int cellX, int cellY, int spanX, int spanY, boolean resize, Point dragOffset, Rect dragRegion) { final int oldDragCellX = mDragCell[0]; final int oldDragCellY = mDragCell[1]; if (dragOutline == null && v == null) { return;//from w w w . j a v a2 s . c o m } if (cellX != oldDragCellX || cellY != oldDragCellY) { mDragCell[0] = cellX; mDragCell[1] = cellY; // Find the top left corner of the rect the object will occupy final int[] topLeft = mTmpPoint; cellToPoint(cellX, cellY, topLeft); int left = topLeft[0]; int top = topLeft[1]; if (v != null && dragOffset == null) { // When drawing the drag outline, it did not account for margin offsets // added by the view's parent. MarginLayoutParams lp = (MarginLayoutParams) v.getLayoutParams(); left += lp.leftMargin; top += lp.topMargin; // Offsets due to the size difference between the View and the dragOutline. // There is a size difference to account for the outer blur, which may lie // outside the bounds of the view. top += (v.getHeight() - dragOutline.getHeight()) / 2; // We center about the x axis left += ((mCellWidth * spanX) + ((spanX - 1) * mWidthGap) - dragOutline.getWidth()) / 2; } else { if (dragOffset != null && dragRegion != null) { // Center the drag region *horizontally* in the cell and apply a drag // outline offset left += dragOffset.x + ((mCellWidth * spanX) + ((spanX - 1) * mWidthGap) - dragRegion.width()) / 2; int cHeight = getShortcutsAndWidgets().getCellContentHeight(); int cellPaddingY = (int) Math.max(0, ((mCellHeight - cHeight) / 2f)); top += dragOffset.y + cellPaddingY; } else { // Center the drag outline in the cell left += ((mCellWidth * spanX) + ((spanX - 1) * mWidthGap) - dragOutline.getWidth()) / 2; top += ((mCellHeight * spanY) + ((spanY - 1) * mHeightGap) - dragOutline.getHeight()) / 2; } } final int oldIndex = mDragOutlineCurrent; mDragOutlineAnims[oldIndex].animateOut(); mDragOutlineCurrent = (oldIndex + 1) % mDragOutlines.length; Rect r = mDragOutlines[mDragOutlineCurrent]; r.set(left, top, left + dragOutline.getWidth(), top + dragOutline.getHeight()); if (resize) { cellToRect(cellX, cellY, spanX, spanY, r); } mDragOutlineAnims[mDragOutlineCurrent].setTag(dragOutline); mDragOutlineAnims[mDragOutlineCurrent].animateIn(); } }
From source file:xyz.klinker.blur.launcher3.Workspace.java
public int[] estimateItemSize(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, 0, 0, itemInfo.spanX, itemInfo.spanY); size[0] = r.width(); size[1] = r.height();/*from w ww .ja v a 2 s. c o m*/ 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.marlonjones.voidlauncher.CellLayout.java
void visualizeDropLocation(View v, DragPreviewProvider outlineProvider, int cellX, int cellY, int spanX, int spanY, boolean resize, DropTarget.DragObject dragObject) { final int oldDragCellX = mDragCell[0]; final int oldDragCellY = mDragCell[1]; if (outlineProvider == null || outlineProvider.gerenatedDragOutline == null) { return;//from w w w .j av a2 s .c o m } Bitmap dragOutline = outlineProvider.gerenatedDragOutline; if (cellX != oldDragCellX || cellY != oldDragCellY) { Point dragOffset = dragObject.dragView.getDragVisualizeOffset(); Rect dragRegion = dragObject.dragView.getDragRegion(); mDragCell[0] = cellX; mDragCell[1] = cellY; final int oldIndex = mDragOutlineCurrent; mDragOutlineAnims[oldIndex].animateOut(); mDragOutlineCurrent = (oldIndex + 1) % mDragOutlines.length; Rect r = mDragOutlines[mDragOutlineCurrent]; if (resize) { cellToRect(cellX, cellY, spanX, spanY, r); } else { // Find the top left corner of the rect the object will occupy final int[] topLeft = mTmpPoint; cellToPoint(cellX, cellY, topLeft); int left = topLeft[0]; int top = topLeft[1]; if (v != null && dragOffset == null) { // When drawing the drag outline, it did not account for margin offsets // added by the view's parent. MarginLayoutParams lp = (MarginLayoutParams) v.getLayoutParams(); left += lp.leftMargin; top += lp.topMargin; // Offsets due to the size difference between the View and the dragOutline. // There is a size difference to account for the outer blur, which may lie // outside the bounds of the view. top += (v.getHeight() - dragOutline.getHeight()) / 2; // We center about the x axis left += ((mCellWidth * spanX) + ((spanX - 1) * mWidthGap) - dragOutline.getWidth()) / 2; } else { if (dragOffset != null && dragRegion != null) { // Center the drag region *horizontally* in the cell and apply a drag // outline offset left += dragOffset.x + ((mCellWidth * spanX) + ((spanX - 1) * mWidthGap) - dragRegion.width()) / 2; int cHeight = getShortcutsAndWidgets().getCellContentHeight(); int cellPaddingY = (int) Math.max(0, ((mCellHeight - cHeight) / 2f)); top += dragOffset.y + cellPaddingY; } else { // Center the drag outline in the cell left += ((mCellWidth * spanX) + ((spanX - 1) * mWidthGap) - dragOutline.getWidth()) / 2; top += ((mCellHeight * spanY) + ((spanY - 1) * mHeightGap) - dragOutline.getHeight()) / 2; } } r.set(left, top, left + dragOutline.getWidth(), top + dragOutline.getHeight()); } Utilities.scaleRectAboutCenter(r, getChildrenScale()); mDragOutlineAnims[mDragOutlineCurrent].setTag(dragOutline); mDragOutlineAnims[mDragOutlineCurrent].animateIn(); if (dragObject.stateAnnouncer != null) { String msg; if (isHotseat()) { msg = getContext().getString(R.string.move_to_hotseat_position, Math.max(cellX, cellY) + 1); } else { msg = getContext().getString(R.string.move_to_empty_cell, cellY + 1, cellX + 1); } dragObject.stateAnnouncer.announce(msg); } } }