List of usage examples for android.graphics Point Point
public Point(int x, int y)
From source file:com.phonemetra.turbo.launcher.Workspace.java
public void beginDragShared(View child, DragSource source) { // The drag bitmap follows the touch point around on the screen final Bitmap b = createDragBitmap(child, new Canvas(), DRAG_BITMAP_PADDING); final int bmpWidth = b.getWidth(); final int bmpHeight = b.getHeight(); float scale = mLauncher.getDragLayer().getLocationInDragLayer(child, mTempXY); int dragLayerX = Math.round(mTempXY[0] - (bmpWidth - scale * child.getWidth()) / 2); int dragLayerY = Math.round(mTempXY[1] - (bmpHeight - scale * bmpHeight) / 2 - DRAG_BITMAP_PADDING / 2); LauncherAppState app = LauncherAppState.getInstance(); DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); Point dragVisualizeOffset = null; Rect dragRect = null;// ww w . j a v a2 s. c o m if (child instanceof BubbleTextView || child instanceof PagedViewIcon) { int iconSize = grid.iconSizePx; int top = child.getPaddingTop(); int left = (bmpWidth - iconSize) / 2; int right = left + iconSize; int bottom = top + iconSize; dragLayerY += top; // Note: The drag region is used to calculate drag layer offsets, but the // dragVisualizeOffset in addition to the dragRect (the size) to position the outline. dragVisualizeOffset = new Point(-DRAG_BITMAP_PADDING / 2, DRAG_BITMAP_PADDING / 2); dragRect = new Rect(left, top, right, bottom); } else if (child instanceof FolderIcon) { int previewSize = grid.folderIconSizePx; dragRect = new Rect(0, child.getPaddingTop(), child.getWidth(), previewSize); } // Clear the pressed state if necessary if (child instanceof BubbleTextView) { BubbleTextView icon = (BubbleTextView) child; icon.clearPressedOrFocusedBackground(); } if (child.getTag() == null || !(child.getTag() instanceof ItemInfo)) { String msg = "Drag started with a view that has no tag set. This " + "will cause a crash (issue 11627249) down the line. " + "View: " + child + " tag: " + child.getTag(); throw new IllegalStateException(msg); } DragView dv = mDragController.startDrag(b, dragLayerX, dragLayerY, source, child.getTag(), DragController.DRAG_ACTION_MOVE, dragVisualizeOffset, dragRect, scale); dv.setIntrinsicIconScaleFactor(source.getIntrinsicIconScaleFactor()); if (child.getParent() instanceof ShortcutAndWidgetContainer) { mDragSourceInternal = (ShortcutAndWidgetContainer) child.getParent(); } b.recycle(); }
From source file:com.android.launcher4.Workspace.java
public void beginExternalDragShared(View child, DragSource source) { LauncherAppState app = LauncherAppState.getInstance(); DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); int iconSize = grid.iconSizePx; // Notify launcher of drag start mLauncher.onDragStarted(child);/*w ww. j a va 2 s . c o m*/ // Compose a new drag bitmap that is of the icon size AtomicInteger padding = new AtomicInteger(DRAG_BITMAP_PADDING); final Bitmap tmpB = createDragBitmap(child, padding); Bitmap b = Bitmap.createBitmap(iconSize, iconSize, Bitmap.Config.ARGB_8888); Paint p = new Paint(); p.setFilterBitmap(true); mCanvas.setBitmap(b); mCanvas.drawBitmap(tmpB, new Rect(0, 0, tmpB.getWidth(), tmpB.getHeight()), new Rect(0, 0, iconSize, iconSize), p); mCanvas.setBitmap(null); // Find the child's location on the screen int bmpWidth = tmpB.getWidth(); float iconScale = (float) bmpWidth / iconSize; float scale = mLauncher.getDragLayer().getLocationInDragLayer(child, mTempXY) * iconScale; int dragLayerX = Math.round(mTempXY[0] - (bmpWidth - scale * child.getWidth()) / 2); int dragLayerY = Math.round(mTempXY[1]); // Note: The drag region is used to calculate drag layer offsets, but the // dragVisualizeOffset in addition to the dragRect (the size) to position the outline. Point dragVisualizeOffset = new Point(-padding.get() / 2, padding.get() / 2); Rect dragRect = new Rect(0, 0, iconSize, iconSize); if (child.getTag() == null || !(child.getTag() instanceof ItemInfo)) { String msg = "Drag started with a view that has no tag set. This " + "will cause a crash (issue 11627249) down the line. " + "View: " + child + " tag: " + child.getTag(); throw new IllegalStateException(msg); } // Start the drag DragView dv = mDragController.startDrag(b, dragLayerX, dragLayerY, source, child.getTag(), DragController.DRAG_ACTION_MOVE, dragVisualizeOffset, dragRect, scale); dv.setIntrinsicIconScaleFactor(source.getIntrinsicIconScaleFactor()); // Recycle temporary bitmaps tmpB.recycle(); }
From source file:com.android.launcher3.Workspace.java
public void beginDragShared(View child, DragSource source) { child.clearFocus();// w w w . j ava 2s. c o m child.setPressed(false); // The outline is used to visualize where the item will land if dropped mDragOutline = createDragOutline(child, DRAG_BITMAP_PADDING); mLauncher.onDragStarted(child); // The drag bitmap follows the touch point around on the screen AtomicInteger padding = new AtomicInteger(DRAG_BITMAP_PADDING); final Bitmap b = createDragBitmap(child, padding); final int bmpWidth = b.getWidth(); final int bmpHeight = b.getHeight(); float scale = mLauncher.getDragLayer().getLocationInDragLayer(child, mTempXY); int dragLayerX = Math.round(mTempXY[0] - (bmpWidth - scale * child.getWidth()) / 2); int dragLayerY = Math.round(mTempXY[1] - (bmpHeight - scale * bmpHeight) / 2 - padding.get() / 2); LauncherAppState app = LauncherAppState.getInstance(); DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); Point dragVisualizeOffset = null; Rect dragRect = null; if (child instanceof BubbleTextView) { int iconSize = grid.iconSizePx; int top = child.getPaddingTop(); int left = (bmpWidth - iconSize) / 2; int right = left + iconSize; int bottom = top + iconSize; dragLayerY += top; // Note: The drag region is used to calculate drag layer offsets, but the // dragVisualizeOffset in addition to the dragRect (the size) to position the outline. dragVisualizeOffset = new Point(-padding.get() / 2, padding.get() / 2); dragRect = new Rect(left, top, right, bottom); } else if (child instanceof FolderIcon) { int previewSize = grid.folderIconSizePx; dragRect = new Rect(0, child.getPaddingTop(), child.getWidth(), previewSize); } // Clear the pressed state if necessary if (child instanceof BubbleTextView) { BubbleTextView icon = (BubbleTextView) child; icon.clearPressedBackground(); } if (child.getTag() == null || !(child.getTag() instanceof ItemInfo)) { String msg = "Drag started with a view that has no tag set. This " + "will cause a crash (issue 11627249) down the line. " + "View: " + child + " tag: " + child.getTag(); throw new IllegalStateException(msg); } DragView dv = mDragController.startDrag(b, dragLayerX, dragLayerY, source, child.getTag(), DragController.DRAG_ACTION_MOVE, dragVisualizeOffset, dragRect, scale); dv.setIntrinsicIconScaleFactor(source.getIntrinsicIconScaleFactor()); if (child.getParent() instanceof ShortcutAndWidgetContainer) { mDragSourceInternal = (ShortcutAndWidgetContainer) child.getParent(); } b.recycle(); }
From source file:com.android.launcher3.Workspace.java
public void beginExternalDragShared(View child, DragSource source) { LauncherAppState app = LauncherAppState.getInstance(); DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); int iconSize = grid.iconSizePx; // Notify launcher of drag start mLauncher.onDragStarted(child);// w w w . j av a 2s. c om // Compose a new drag bitmap that is of the icon size AtomicInteger padding = new AtomicInteger(DRAG_BITMAP_PADDING); final Bitmap tmpB = createDragBitmap(child, padding); Bitmap b = Bitmap.createBitmap(iconSize, iconSize, Bitmap.Config.ARGB_8888); Paint p = new Paint(); p.setFilterBitmap(true); mCanvas.setBitmap(b); mCanvas.drawBitmap(tmpB, new Rect(0, 0, tmpB.getWidth(), tmpB.getHeight()), new Rect(0, 0, iconSize, iconSize), p); mCanvas.setBitmap(null); // Find the child's location on the screen int bmpWidth = tmpB.getWidth(); float iconScale = (float) bmpWidth / iconSize; float scale = mLauncher.getDragLayer().getLocationInDragLayer(child, mTempXY) * iconScale; int dragLayerX = Math.round(mTempXY[0] - (bmpWidth - scale * child.getWidth()) / 2); int dragLayerY = Math.round((float) mTempXY[1]); //bug410615 coverity problem. // Note: The drag region is used to calculate drag layer offsets, but the // dragVisualizeOffset in addition to the dragRect (the size) to position the outline. Point dragVisualizeOffset = new Point(-padding.get() / 2, padding.get() / 2); Rect dragRect = new Rect(0, 0, iconSize, iconSize); if (child.getTag() == null || !(child.getTag() instanceof ItemInfo)) { String msg = "Drag started with a view that has no tag set. This " + "will cause a crash (issue 11627249) down the line. " + "View: " + child + " tag: " + child.getTag(); throw new IllegalStateException(msg); } // Start the drag DragView dv = mDragController.startDrag(b, dragLayerX, dragLayerY, source, child.getTag(), DragController.DRAG_ACTION_MOVE, dragVisualizeOffset, dragRect, scale); dv.setIntrinsicIconScaleFactor(source.getIntrinsicIconScaleFactor()); // Recycle temporary bitmaps tmpB.recycle(); }
From source file:com.nttec.everychan.ui.presentation.BoardFragment.java
private Point getSpanCoordinates(View widget, ClickableURLSpan span) { TextView parentTextView = (TextView) widget; Rect parentTextViewRect = new Rect(); // Initialize values for the computing of clickedText position SpannableString completeText = (SpannableString) (parentTextView).getText(); Layout textViewLayout = parentTextView.getLayout(); int startOffsetOfClickedText = completeText.getSpanStart(span); int endOffsetOfClickedText = completeText.getSpanEnd(span); double startXCoordinatesOfClickedText = textViewLayout.getPrimaryHorizontal(startOffsetOfClickedText); double endXCoordinatesOfClickedText = textViewLayout.getPrimaryHorizontal(endOffsetOfClickedText); // Get the rectangle of the clicked text int currentLineStartOffset = textViewLayout.getLineForOffset(startOffsetOfClickedText); int currentLineEndOffset = textViewLayout.getLineForOffset(endOffsetOfClickedText); boolean keywordIsInMultiLine = currentLineStartOffset != currentLineEndOffset; textViewLayout.getLineBounds(currentLineStartOffset, parentTextViewRect); // Update the rectangle position to his real position on screen int[] parentTextViewLocation = { 0, 0 }; parentTextView.getLocationOnScreen(parentTextViewLocation); double parentTextViewTopAndBottomOffset = (parentTextViewLocation[1] - parentTextView.getScrollY() + parentTextView.getCompoundPaddingTop()); Rect windowRect = new Rect(); activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(windowRect); parentTextViewTopAndBottomOffset -= windowRect.top; parentTextViewRect.top += parentTextViewTopAndBottomOffset; parentTextViewRect.bottom += parentTextViewTopAndBottomOffset; parentTextViewRect.left += (parentTextViewLocation[0] + startXCoordinatesOfClickedText + parentTextView.getCompoundPaddingLeft() - parentTextView.getScrollX()); parentTextViewRect.right = (int) (parentTextViewRect.left + endXCoordinatesOfClickedText - startXCoordinatesOfClickedText); int x = (parentTextViewRect.left + parentTextViewRect.right) / 2; int y = (parentTextViewRect.top + parentTextViewRect.bottom) / 2; if (keywordIsInMultiLine) { x = parentTextViewRect.left;// w w w. ja v a2s . c o m } return new Point(x, y); }
From source file:self.philbrown.droidQuery.$.java
/** * @return the coordinates of the first view in the current selection. *//*from ww w . ja v a 2 s . co m*/ public Point offset() { int[] loc = new int[2]; view(0).getLocationOnScreen(loc); return new Point(loc[0], loc[1]); }
From source file:self.philbrown.droidQuery.$.java
/** * Gets the coordinates of {@code v}//from w w w .j av a2s. co m * @param v * @return the coordinates of the given view */ private Point offset(View v) { int[] loc = new int[2]; v.getLocationOnScreen(loc); return new Point(loc[0], loc[1]); }
From source file:self.philbrown.droidQuery.$.java
/** * @return the coordinates of the first view in the current selection, * relative to the offset parent.//from w w w .j a v a 2s . c o m */ public Point position() { return new Point(view(0).getLeft(), view(0).getTop()); }
From source file:self.philbrown.droidQuery.$.java
/** * Get the coordinates of the {@code view}, relative to the offset parent * @param view//from w ww .ja v a 2 s .co m * @return the coordinates of the given view, relative to the offset parent */ private Point position(View view) { return new Point(view.getLeft(), view.getTop()); }