List of usage examples for android.view View getWidth
@ViewDebug.ExportedProperty(category = "layout") public final int getWidth()
From source file:com.deepak.myclock.widget.sgv.StaggeredGridView.java
/** * Add animators for animating out stale views * @param animationOutMode The animation mode to play for stale views *//*from w w w.j a v a2 s.c o m*/ private void addOutAnimatorsForStaleViews(List<Animator> animators, SgvAnimationHelper.AnimationOut animationOutMode) { if (animationOutMode == SgvAnimationHelper.AnimationOut.NONE) { return; } for (final View v : mViewsToAnimateOut) { // For each stale view to animate out, retrieve the animators for the view, then attach // the StaleViewAnimationEndListener which checks to see if the view should be recycled // at the end of the animation. final List<Animator> viewAnimators = new ArrayList<Animator>(); switch (animationOutMode) { case SLIDE: final LayoutParams lp = (LayoutParams) v.getLayoutParams(); // Bias towards sliding right, but depending on the column that this view // is laid out in, slide towards the nearest side edge. int endTranslation = (int) (v.getWidth() * 1.5); if (lp.column < (mColCount / 2)) { endTranslation = -endTranslation; } SgvAnimationHelper.addSlideOutAnimators(viewAnimators, v, (int) v.getTranslationX(), endTranslation); break; case COLLAPSE: SgvAnimationHelper.addCollapseOutAnimators(viewAnimators, v); break; case FLY_DOWN: SgvAnimationHelper.addFlyOutAnimators(viewAnimators, v, (int) v.getTranslationY(), getHeight()); break; case FADE: SgvAnimationHelper.addFadeAnimators(viewAnimators, v, v.getAlpha(), 0 /* end alpha */); break; default: throw new IllegalStateException("Unknown animationOutMode: " + animationOutMode); } if (viewAnimators.size() > 0) { addStaleViewAnimationEndListener(v, viewAnimators); animators.addAll(viewAnimators); } } }
From source file:cc.flydev.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 ava 2 s . co 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(); } mDragController.startDrag(b, dragLayerX, dragLayerY, source, child.getTag(), DragController.DRAG_ACTION_MOVE, dragVisualizeOffset, dragRect, scale); if (child.getParent() instanceof ShortcutAndWidgetContainer) { mDragSourceInternal = (ShortcutAndWidgetContainer) child.getParent(); } b.recycle(); }
From source file:com.android.launcher3.Launcher.java
private Rect getViewBounds(View v) { int[] pos = new int[2]; v.getLocationOnScreen(pos);//from w ww.j av a 2 s .c o m return new Rect(pos[0], pos[1], pos[0] + v.getWidth(), pos[1] + v.getHeight()); }
From source file:com.aidy.launcher3.ui.workspace.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;// w w w. jav a 2s. 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(); } mDragController.startDrag(b, dragLayerX, dragLayerY, source, child.getTag(), DragController.DRAG_ACTION_MOVE, dragVisualizeOffset, dragRect, scale); if (child.getParent() instanceof ShortcutAndWidgetContainer) { mDragSourceInternal = (ShortcutAndWidgetContainer) child.getParent(); } b.recycle(); }
From source file:com.example.launcher3.Workspace.java
public void beginDragShared(View child, DragSource source) { Log.d(TAG, ".."); // 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;/*from w w w . j av a2s . com*/ if (child instanceof BubbleTextView || child instanceof PagedViewIcon) { Log.d(TAG, "if.."); 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) { Log.d(TAG, "else.."); int previewSize = grid.folderIconSizePx; dragRect = new Rect(0, child.getPaddingTop(), child.getWidth(), previewSize); } // Clear the pressed state if necessary if (child instanceof BubbleTextView) { Log.d(TAG, "if(child instanceof BubbleTextView).."); BubbleTextView icon = (BubbleTextView) child; icon.clearPressedOrFocusedBackground(); } mDragController.startDrag(b, dragLayerX, dragLayerY, source, child.getTag(), DragController.DRAG_ACTION_MOVE, dragVisualizeOffset, dragRect, scale); if (child.getParent() instanceof ShortcutAndWidgetContainer) { Log.d(TAG, "if(child.getParent() instanceof ShortcutAndWidgetContainer).."); mDragSourceInternal = (ShortcutAndWidgetContainer) child.getParent(); } b.recycle(); }
From source file:com.auratech.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.jav 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(); } else if (child instanceof FolderIcon) { // Dismiss the folder cling if we haven't already mLauncher.getLauncherClings().markFolderClingDismissed(); } 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
/** * Returns a new bitmap to be used as the object outline, e.g. to visualize the drop location. * Responsibility for the bitmap is transferred to the caller. *///from w w w . j a v a2 s . co m private Bitmap createDragOutline(View v, int padding) { final int outlineColor = getResources().getColor(R.color.outline_color); final Bitmap b = Bitmap.createBitmap(v.getWidth() + padding, v.getHeight() + padding, Bitmap.Config.ARGB_8888); mCanvas.setBitmap(b); drawDragView(v, mCanvas, padding); mOutlineHelper.applyExpensiveOutlineWithBlur(b, mCanvas, outlineColor, outlineColor); mCanvas.setBitmap(null); return b; }
From source file:com.nttec.everychan.ui.presentation.BoardFragment.java
/** * ? ? ?// w w w . ja v a 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:com.android.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/* www.j a va 2s. co m*/ */ public Bitmap createDragBitmap(View v, AtomicInteger expectedPadding) { Bitmap b; int padding = expectedPadding.get(); if (v instanceof TextView) { Drawable d = ((TextView) v).getCompoundDrawables()[1]; 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; }