List of usage examples for android.view View clearFocus
public void clearFocus()
From source file:app.umitems.greenclock.widget.sgv.StaggeredGridView.java
/** * Important: this method will leave offscreen views attached if they * are required to maintain the invariant that child view with index i * is always the view corresponding to position mFirstPosition + i. *//*from ww w.ja v a 2s . c om*/ private void recycleOffscreenViews() { if (getChildCount() == 0) { return; } final int height = getHeight(); final int clearAbove = -mItemMargin; final int clearBelow = height + mItemMargin; for (int i = getChildCount() - 1; i >= 0; i--) { final View child = getChildAt(i); if (child.getTop() <= clearBelow) { // There may be other offscreen views, but we need to maintain // the invariant documented above. break; } child.clearFocus(); if (mInLayout) { removeViewsInLayout(i, 1); } else { removeViewAt(i); } mRecycler.addScrap(child); } while (getChildCount() > 0) { final View child = getChildAt(0); if (child.getBottom() >= clearAbove) { // There may be other offscreen views, but we need to maintain // the invariant documented above. break; } child.clearFocus(); if (mInLayout) { removeViewsInLayout(0, 1); } else { removeViewAt(0); } mRecycler.addScrap(child); mFirstPosition++; } final int childCount = getChildCount(); if (childCount > 0) { // Repair the top and bottom column boundaries from the views we still have Arrays.fill(mItemTops, Integer.MAX_VALUE); Arrays.fill(mItemBottoms, Integer.MIN_VALUE); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); final int top = child.getTop() - mItemMargin; final int bottom = child.getBottom(); LayoutRecord rec = mLayoutRecords.get(mFirstPosition + i); // It's possible the layout record could be null for visible views because // they are cleared between adapter data set changes, but the views are left // attached for the purpose of animations. Hence, populate the layout record again. if (rec == null) { rec = recreateLayoutRecord(mFirstPosition + i, child, lp); } // In LTR layout, iterate across each column that this child is laid out in, // starting from the child's first column (lp.column). For each column, update // mItemTops and mItemBottoms appropriately to take into account this child's // dimension. In RTL layout, iterate in reverse, where the child's starting // column would start from the right-most. final int span = Math.min(mColCount, lp.span); for (int spanIndex = 0; spanIndex < span; spanIndex++) { final int col = mIsRtlLayout ? lp.column - spanIndex : lp.column + spanIndex; final int colTop = top - rec.getMarginAbove(spanIndex); final int colBottom = bottom + rec.getMarginBelow(spanIndex); if (colTop < mItemTops[col]) { mItemTops[col] = colTop; } if (colBottom > mItemBottoms[col]) { mItemBottoms[col] = colBottom; } } } for (int col = 0; col < mColCount; col++) { if (mItemTops[col] == Integer.MAX_VALUE) { // If one was untouched, both were. final int top = getPaddingTop(); mItemTops[col] = top; mItemBottoms[col] = top; } } } mCurrentScrollState = getScrollState(); }
From source file:com.klinker.android.launcher.launcher3.Workspace.java
public void beginDragShared(View child, Point relativeTouchPos, DragSource source, boolean accessible) { child.clearFocus(); child.setPressed(false);/* w w w. j a va2 s .c o m*/ // 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); DeviceProfile grid = mLauncher.getDeviceProfile(); Point dragVisualizeOffset = null; Rect dragRect = null; if (child instanceof BubbleTextView) { BubbleTextView icon = (BubbleTextView) child; int iconSize = grid.iconSizePx; int top = child.getPaddingTop(); int left = (bmpWidth - iconSize) / 2; int right = left + iconSize; int bottom = top + iconSize; if (icon.isLayoutHorizontal()) { // If the layout is horizontal, then if we are just picking up the icon, then just // use the child position since the icon is top-left aligned. Otherwise, offset // the drag layer position horizontally so that the icon is under the current // touch position. if (icon.getIcon().getBounds().contains(relativeTouchPos.x, relativeTouchPos.y)) { dragLayerX = Math.round(mTempXY[0]); } else { dragLayerX = Math.round(mTempXY[0] + relativeTouchPos.x - (bmpWidth / 2)); } } 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, accessible); dv.setIntrinsicIconScaleFactor(source.getIntrinsicIconScaleFactor()); if (child.getParent() instanceof ShortcutAndWidgetContainer) { mDragSourceInternal = (ShortcutAndWidgetContainer) child.getParent(); } b.recycle(); }
From source file:cc.flydev.launcher.Workspace.java
void startDrag(CellLayout.CellInfo cellInfo) { View child = cellInfo.cell; // Make sure the drag was started by a long press as opposed to a long click. if (!child.isInTouchMode()) { return;/*from ww w . j a v a 2 s. c o m*/ } mDragInfo = cellInfo; child.setVisibility(INVISIBLE); CellLayout layout = (CellLayout) child.getParent().getParent(); layout.prepareChildForDrag(child); child.clearFocus(); child.setPressed(false); final Canvas canvas = new Canvas(); // The outline is used to visualize where the item will land if dropped mDragOutline = createDragOutline(child, canvas, DRAG_BITMAP_PADDING); beginDragShared(child, this); }
From source file:xyz.klinker.blur.launcher3.Workspace.java
public void beginDragShared(View child, Point relativeTouchPos, DragSource source, boolean accessible) { child.clearFocus(); child.setPressed(false);//w w w .j a v a 2 s . c o m // 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); DeviceProfile grid = mLauncher.getDeviceProfile(); Point dragVisualizeOffset = null; Rect dragRect = null; if (child instanceof BubbleTextView) { BubbleTextView icon = (BubbleTextView) child; int iconSize = grid.iconSizePx; int top = child.getPaddingTop(); int left = (bmpWidth - iconSize) / 2; int right = left + iconSize; int bottom = top + iconSize; if (icon.isLayoutHorizontal()) { // If the layout is horizontal, then if we are just picking up the icon, then just // use the child position since the icon is top-left aligned. Otherwise, offset // the drag layer position horizontally so that the icon is under the current // touch position. if (icon.getIcon().getBounds().contains(relativeTouchPos.x, relativeTouchPos.y)) { dragLayerX = Math.round(mTempXY[0]); } else { dragLayerX = Math.round(mTempXY[0] + relativeTouchPos.x - (bmpWidth / 2)); } } 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; dragVisualizeOffset = new Point(-padding.get() / 2, padding.get() / 2 - child.getPaddingTop()); 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); } if (child.getParent() instanceof ShortcutAndWidgetContainer) { mDragSourceInternal = (ShortcutAndWidgetContainer) child.getParent(); } DragView dv = mDragController.startDrag(b, dragLayerX, dragLayerY, source, child.getTag(), DragController.DRAG_ACTION_MOVE, dragVisualizeOffset, dragRect, scale, accessible); dv.setIntrinsicIconScaleFactor(source.getIntrinsicIconScaleFactor()); b.recycle(); }
From source file:com.n2hsu.launcher.Workspace.java
void startDrag(CellLayout.CellInfo cellInfo) { View child = cellInfo.cell; // Make sure the drag was started by a long press as opposed to a long // click./*from w w w .j av a 2s . c o m*/ if (!child.isInTouchMode()) { return; } mDragInfo = cellInfo; child.setVisibility(INVISIBLE); CellLayout layout = (CellLayout) child.getParent().getParent(); layout.prepareChildForDrag(child); child.clearFocus(); child.setPressed(false); final Canvas canvas = new Canvas(); // The outline is used to visualize where the item will land if dropped mDragOutline = createDragOutline(child, canvas, DRAG_BITMAP_PADDING); beginDragShared(child, this); }
From source file:com.example.launcher3.Workspace.java
/** * /* www . j a v a2s . co m*/ * * @param cellInfo */ void startDrag(CellLayout.CellInfo cellInfo) { Log.d(TAG, ""); View child = cellInfo.cell; // Make sure the drag was started by a long press as opposed to a long // click. if (!child.isInTouchMode()) { return; } mDragInfo = cellInfo; child.setVisibility(INVISIBLE); CellLayout layout = (CellLayout) child.getParent().getParent(); layout.prepareChildForDrag(child); child.clearFocus(); child.setPressed(false); final Canvas canvas = new Canvas(); // The outline is used to visualize where the item will land if dropped mDragOutline = createDragOutline(child, canvas, DRAG_BITMAP_PADDING); beginDragShared(child, this); }
From source file:com.zyk.launcher.Workspace.java
public void beginDragShared(View child, DragSource source) { // mLauncher.setDragController(true); ////w w w .j a va 2s .c o m child.clearFocus(); //??false?false? 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 = Utils.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.aidy.launcher3.ui.workspace.Workspace.java
public void startDrag(CellLayout.CellInfo cellInfo) { View child = cellInfo.cell; // Make sure the drag was started by a long press as opposed to a long // click./*from w w w . j ava2s. c o m*/ if (!child.isInTouchMode()) { return; } mDragInfo = cellInfo; child.setVisibility(INVISIBLE); CellLayout layout = (CellLayout) child.getParent().getParent(); layout.prepareChildForDrag(child); child.clearFocus(); child.setPressed(false); final Canvas canvas = new Canvas(); // The outline is used to visualize where the item will land if dropped mDragOutline = createDragOutline(child, canvas, DRAG_BITMAP_PADDING); beginDragShared(child, this); }
From source file:self.philbrown.droidQuery.$.java
/** * Removes focus from all views in the current selection. * @return this//from w ww . j a v a 2s.co m */ public $ focusout() { for (int i = 0; i < this.views.size(); i++) { View view = this.views.get(i); view.clearFocus(); } return this; }
From source file:com.android.launcher3.Workspace.java
public void beginDragShared(View child, DragSource source) { child.clearFocus(); child.setPressed(false);//from w w w . j a v a 2 s . c o m // 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(); }