Example usage for android.view View getHeight

List of usage examples for android.view View getHeight

Introduction

In this page you can find the example usage for android.view View getHeight.

Prototype

@ViewDebug.ExportedProperty(category = "layout")
public final int getHeight() 

Source Link

Document

Return the height of your view.

Usage

From source file:com.android.launcher3.Launcher.java

private Rect getViewBounds(View v) {
    int[] pos = new int[2];
    v.getLocationOnScreen(pos);//from   w w  w  .j a v  a  2 s.  c om
    return new Rect(pos[0], pos[1], pos[0] + v.getWidth(), pos[1] + v.getHeight());
}

From source file:com.android.mms.ui.ComposeMessageActivity.java

/**
 * smoothScrollToEnd will scroll the message list to the bottom if the list is already near
 * the bottom. Typically this is called to smooth scroll a newly received message into view.
 * It's also called when sending to scroll the list to the bottom, regardless of where it is,
 * so the user can see the just sent message. This function is also called when the message
 * list view changes size because the keyboard state changed or the compose message field grew.
 *
 * @param force always scroll to the bottom regardless of current list position
 * @param listSizeChange the amount the message list view size has vertically changed
 *///from  w  w  w  . ja  v  a2 s .  c om
private void smoothScrollToEnd(boolean force, int listSizeChange) {
    int lastItemVisible = mMsgListView.getLastVisiblePosition();
    int lastItemInList = mMsgListAdapter.getCount() - 1;
    if (lastItemVisible < 0 || lastItemInList < 0) {
        if (LogTag.VERBOSE || Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
            Log.v(TAG, "smoothScrollToEnd: lastItemVisible=" + lastItemVisible + ", lastItemInList="
                    + lastItemInList + ", mMsgListView not ready");
        }
        return;
    }

    View lastChildVisible = mMsgListView.getChildAt(lastItemVisible - mMsgListView.getFirstVisiblePosition());
    int lastVisibleItemBottom = 0;
    int lastVisibleItemHeight = 0;
    if (lastChildVisible != null) {
        lastVisibleItemBottom = lastChildVisible.getBottom();
        lastVisibleItemHeight = lastChildVisible.getHeight();
    }

    if (LogTag.VERBOSE || Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
        Log.v(TAG, "smoothScrollToEnd newPosition: " + lastItemInList + " mLastSmoothScrollPosition: "
                + mLastSmoothScrollPosition + " first: " + mMsgListView.getFirstVisiblePosition()
                + " lastItemVisible: " + lastItemVisible + " lastVisibleItemBottom: " + lastVisibleItemBottom
                + " lastVisibleItemBottom + listSizeChange: " + (lastVisibleItemBottom + listSizeChange)
                + " mMsgListView.getHeight() - mMsgListView.getPaddingBottom(): "
                + (mMsgListView.getHeight() - mMsgListView.getPaddingBottom()) + " listSizeChange: "
                + listSizeChange);
    }
    // Only scroll if the list if we're responding to a newly sent message (force == true) or
    // the list is already scrolled to the end. This code also has to handle the case where
    // the listview has changed size (from the keyboard coming up or down or the message entry
    // field growing/shrinking) and it uses that grow/shrink factor in listSizeChange to
    // compute whether the list was at the end before the resize took place.
    // For example, when the keyboard comes up, listSizeChange will be negative, something
    // like -524. The lastChild listitem's bottom value will be the old value before the
    // keyboard became visible but the size of the list will have changed. The test below
    // add listSizeChange to bottom to figure out if the old position was already scrolled
    // to the bottom. We also scroll the list if the last item is taller than the size of the
    // list. This happens when the keyboard is up and the last item is an mms with an
    // attachment thumbnail, such as picture. In this situation, we want to scroll the list so
    // the bottom of the thumbnail is visible and the top of the item is scroll off the screen.
    int listHeight = mMsgListView.getHeight();
    boolean lastItemTooTall = lastVisibleItemHeight > listHeight;
    boolean willScroll = force || ((listSizeChange != 0 || lastItemInList != mLastSmoothScrollPosition)
            && lastVisibleItemBottom + listSizeChange <= listHeight - mMsgListView.getPaddingBottom());
    if (willScroll || (lastItemTooTall && lastItemInList == lastItemVisible)) {
        if (Math.abs(listSizeChange) > SMOOTH_SCROLL_THRESHOLD) {
            // When the keyboard comes up, the window manager initiates a cross fade
            // animation that conflicts with smooth scroll. Handle that case by jumping the
            // list directly to the end.
            if (LogTag.VERBOSE || Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
                Log.v(TAG, "keyboard state changed. setSelection=" + lastItemInList);
            }
            if (lastItemTooTall) {
                // If the height of the last item is taller than the whole height of the list,
                // we need to scroll that item so that its top is negative or above the top of
                // the list. That way, the bottom of the last item will be exposed above the
                // keyboard.
                mMsgListView.setSelectionFromTop(lastItemInList, listHeight - lastVisibleItemHeight);
            } else {
                mMsgListView.setSelection(lastItemInList);
            }
        } else if (lastItemInList - lastItemVisible > MAX_ITEMS_TO_INVOKE_SCROLL_SHORTCUT) {
            if (LogTag.VERBOSE || Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
                Log.v(TAG, "too many to scroll, setSelection=" + lastItemInList);
            }
            mMsgListView.setSelection(lastItemInList);
        } else {
            if (LogTag.VERBOSE || Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
                Log.v(TAG, "smooth scroll to " + lastItemInList);
            }
            if (lastItemTooTall) {
                // If the height of the last item is taller than the whole height of the list,
                // we need to scroll that item so that its top is negative or above the top of
                // the list. That way, the bottom of the last item will be exposed above the
                // keyboard. We should use smoothScrollToPositionFromTop here, but it doesn't
                // seem to work -- the list ends up scrolling to a random position.
                mMsgListView.setSelectionFromTop(lastItemInList, listHeight - lastVisibleItemHeight);
            } else {
                mMsgListView.smoothScrollToPosition(lastItemInList);
            }
            mLastSmoothScrollPosition = lastItemInList;
        }
    }
}

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 ww.  j av 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

/**
 *  ?  ? ?//from   w w w  .j  a  va  2s  .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:cn.androidy.materialdesignsample.ryanharterviewpager.ViewPager.java

/**
 * This method will be invoked when the current page is scrolled, either as part
 * of a programmatically initiated smooth scroll or a user initiated touch scroll.
 * If you override this method you must call through to the superclass implementation
 * (e.g. super.onPageScrolled(position, offset, offsetPixels)) before onPageScrolled
 * returns./*from   ww w . j a  v a2  s  .  c o m*/
 *
 * @param position Position index of the first page currently being displayed.
 *                 Page position+1 will be visible if positionOffset is nonzero.
 * @param offset Value from [0, 1) indicating the offset from the page at position.
 * @param offsetPixels Value in pixels indicating the offset from position.
 */
protected void onPageScrolled(int position, float offset, int offsetPixels) {
    // Offset any decor views if needed - keep them on-screen at all times.
    if (mDecorChildCount > 0) {
        // TODO This is where I start getting tired. Refactor this better later.
        if (isOrientationHorizontal()) {
            final int scrollX = getScrollX();
            int paddingLeft = getPaddingLeft();
            int paddingRight = getPaddingRight();
            final int width = getWidth();
            final int childCount = getChildCount();
            for (int i = 0; i < childCount; i++) {
                final View child = getChildAt(i);
                final LayoutParams lp = (LayoutParams) child.getLayoutParams();
                if (!lp.isDecor)
                    continue;

                final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
                int childLeft = 0;
                switch (hgrav) {
                default:
                    childLeft = paddingLeft;
                    break;
                case Gravity.LEFT:
                    childLeft = paddingLeft;
                    paddingLeft += child.getWidth();
                    break;
                case Gravity.CENTER_HORIZONTAL:
                    childLeft = Math.max((width - child.getMeasuredWidth()) / 2, paddingLeft);
                    break;
                case Gravity.RIGHT:
                    childLeft = width - paddingRight - child.getMeasuredWidth();
                    paddingRight += child.getMeasuredWidth();
                    break;
                }
                childLeft += scrollX;

                final int childOffset = childLeft - child.getLeft();
                if (childOffset != 0) {
                    child.offsetLeftAndRight(childOffset);
                }
            }
        } else {
            final int scrollY = getScrollY();
            int paddingTop = getPaddingTop();
            int paddingBottom = getPaddingBottom();
            final int height = getHeight();
            final int childCount = getChildCount();
            for (int i = 0; i < childCount; i++) {
                final View child = getChildAt(i);
                final LayoutParams lp = (LayoutParams) child.getLayoutParams();
                if (!lp.isDecor)
                    continue;

                final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;
                int childTop = 0;
                switch (vgrav) {
                default:
                    childTop = paddingTop;
                    break;
                case Gravity.TOP:
                    childTop = paddingTop;
                    paddingTop += child.getHeight();
                    break;
                case Gravity.CENTER_VERTICAL:
                    childTop = Math.max((height - child.getMeasuredHeight()) / 2, paddingTop);
                    break;
                case Gravity.BOTTOM:
                    childTop = height - paddingBottom - child.getMeasuredHeight();
                    paddingBottom += child.getMeasuredHeight();
                    break;
                }
                childTop += scrollY;

                final int childOffset = childTop - child.getTop();
                if (childOffset != 0) {
                    child.offsetTopAndBottom(childOffset);
                }
            }
        }
    }

    if (mOnPageChangeListener != null) {
        mOnPageChangeListener.onPageScrolled(position, offset, offsetPixels);
    }
    if (mInternalPageChangeListener != null) {
        mInternalPageChangeListener.onPageScrolled(position, offset, offsetPixels);
    }

    if (mPageTransformer != null) {
        final boolean horizontal = isOrientationHorizontal();
        final int scroll = horizontal ? getScrollX() : getScrollY();
        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            final View child = getChildAt(i);
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();

            if (lp.isDecor)
                continue;

            float transformPos;
            if (horizontal) {
                transformPos = (float) (child.getLeft() - scroll) / getClientWidth();
            } else {
                transformPos = (float) (child.getTop() - scroll) / getClientHeight();
            }
            mPageTransformer.transformPage(child, transformPos);
        }
    }

    mCalledSuper = true;
}

From source file:cn.ieclipse.af.view.StaggeredGridView.java

/**
 * Measure and layout all currently visible children.
 *
 * @param queryAdapter true to requery the adapter for view data
 *//*from  w w w  . j a v  a  2s  .  co m*/
final void layoutChildren(boolean queryAdapter) {
    final int paddingLeft = getPaddingLeft();
    final int paddingRight = getPaddingRight();
    final int itemMargin = mItemMargin;
    final int colWidth = (getWidth() - paddingLeft - paddingRight - itemMargin * (mColCount - 1)) / mColCount;
    int rebuildLayoutRecordsBefore = -1;
    int rebuildLayoutRecordsAfter = -1;

    Arrays.fill(mItemBottoms, Integer.MIN_VALUE);

    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        View child = getChildAt(i);
        LayoutParams lp = (LayoutParams) child.getLayoutParams();
        final int col = lp.column;
        final int position = mFirstPosition + i;
        final boolean needsLayout = queryAdapter || child.isLayoutRequested();

        if (queryAdapter) {
            View newView = obtainView(position, child);
            if (newView != child) {
                removeViewAt(i);
                addView(newView, i);
                child = newView;
            }
            lp = (LayoutParams) child.getLayoutParams(); // Might have changed
        }

        final int span = Math.min(mColCount, lp.span);
        final int widthSize = colWidth * span + itemMargin * (span - 1);

        if (needsLayout) {
            final int widthSpec = MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY);

            final int heightSpec;
            if (lp.height == LayoutParams.WRAP_CONTENT) {
                heightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
            } else {
                heightSpec = MeasureSpec.makeMeasureSpec(lp.height, MeasureSpec.EXACTLY);
            }

            child.measure(widthSpec, heightSpec);
        }

        int childTop = mItemBottoms[col] > Integer.MIN_VALUE ? mItemBottoms[col] + mItemMargin : child.getTop();
        if (span > 1) {
            int lowest = childTop;
            for (int j = col + 1; j < col + span; j++) {
                final int bottom = mItemBottoms[j] + mItemMargin;
                if (bottom > lowest) {
                    lowest = bottom;
                }
            }
            childTop = lowest;
        }
        final int childHeight = child.getMeasuredHeight();
        final int childBottom = childTop + childHeight;
        final int childLeft = paddingLeft + col * (colWidth + itemMargin);
        final int childRight = childLeft + child.getMeasuredWidth();
        child.layout(childLeft, childTop, childRight, childBottom);

        for (int j = col; j < col + span; j++) {
            mItemBottoms[j] = childBottom;
        }

        final LayoutRecord rec = mLayoutRecords.get(position);
        if (rec != null && rec.height != childHeight) {
            // Invalidate our layout records for everything before this.
            rec.height = childHeight;
            rebuildLayoutRecordsBefore = position;
        }

        if (rec != null && rec.span != span) {
            // Invalidate our layout records for everything after this.
            rec.span = span;
            rebuildLayoutRecordsAfter = position;
        }
    }

    // Update mItemBottoms for any empty columns
    for (int i = 0; i < mColCount; i++) {
        if (mItemBottoms[i] == Integer.MIN_VALUE) {
            mItemBottoms[i] = mItemTops[i];
        }
    }

    if (rebuildLayoutRecordsBefore >= 0 || rebuildLayoutRecordsAfter >= 0) {
        if (rebuildLayoutRecordsBefore >= 0) {
            invalidateLayoutRecordsBeforePosition(rebuildLayoutRecordsBefore);
        }
        if (rebuildLayoutRecordsAfter >= 0) {
            invalidateLayoutRecordsAfterPosition(rebuildLayoutRecordsAfter);
        }
        for (int i = 0; i < childCount; i++) {
            final int position = mFirstPosition + i;
            final View child = getChildAt(i);
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            LayoutRecord rec = mLayoutRecords.get(position);
            if (rec == null) {
                rec = new LayoutRecord();
                mLayoutRecords.put(position, rec);
            }
            rec.column = lp.column;
            rec.height = child.getHeight();
            rec.id = lp.id;
            rec.span = Math.min(mColCount, lp.span);
        }
    }
}

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/*from   w  w  w .  j a  v  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 = ((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;
}

From source file:com.cognizant.trumobi.PersonaLauncher.java

public void showActions(final PersonaItemInfo info, final View view) {
    int[] xy = new int[2];
    // fills the array with the computed coordinates
    view.getLocationInWindow(xy);/*from   w ww .  jav  a 2 s. co  m*/
    // rectangle holding the clicked view area
    Rect rect = new Rect(xy[0], xy[1], xy[0] + view.getWidth(), xy[1] + view.getHeight());

    // a new PersonaQuickActionWindow object
    final PersonaQuickActionWindow qa = new PersonaQuickActionWindow(this, view, rect);
    view.setTag(R.id.TAG_PREVIEW, qa);

    // adds an item to the badge and defines the quick action to be
    // triggered
    // when the item is clicked on
    qa.addItem(getResources().getDrawable(android.R.drawable.ic_menu_delete), R.string.menu_delete,
            new OnClickListener() {
                public void onClick(View v) {
                    final PersonaLauncherModel model = PersonaLauncher.getModel();
                    if (info.container == PersonaLauncherSettings.Favorites.CONTAINER_DESKTOP) {
                        if (info instanceof PersonaLauncherAppWidgetInfo) {
                            model.removeDesktopAppWidget((PersonaLauncherAppWidgetInfo) info);
                        } else {
                            model.removeDesktopItem(info);
                        }
                    } else {
                        // in a folder?
                        PersonaFolderInfo source = sModel.getFolderById(PersonaLauncher.this, info.container);
                        if (source instanceof PersonaUserFolderInfo) {
                            final PersonaUserFolderInfo personaUserFolderInfo = (PersonaUserFolderInfo) source;
                            model.removeUserFolderItem(personaUserFolderInfo, info);
                        }
                    }
                    if (info instanceof PersonaUserFolderInfo) {
                        final PersonaUserFolderInfo personaUserFolderInfo = (PersonaUserFolderInfo) info;
                        PersonaLauncherModel.deleteUserFolderContentsFromDatabase(PersonaLauncher.this,
                                personaUserFolderInfo);
                        model.removeUserFolder(personaUserFolderInfo);
                    } else if (info instanceof PersonaLauncherAppWidgetInfo) {
                        final PersonaLauncherAppWidgetInfo personaLauncherAppWidgetInfo = (PersonaLauncherAppWidgetInfo) info;
                        final PersonaLauncherAppWidgetHost appWidgetHost = PersonaLauncher.this
                                .getAppWidgetHost();
                        PersonaLauncher.this.getWorkspace()
                                .unbindWidgetScrollableId(personaLauncherAppWidgetInfo.appWidgetId);
                        if (appWidgetHost != null) {
                            appWidgetHost.deleteAppWidgetId(personaLauncherAppWidgetInfo.appWidgetId);
                        }
                    }
                    PersonaLauncherModel.deleteItemFromDatabase(PersonaLauncher.this, info);
                    if (view instanceof PersonaActionButton)
                        ((PersonaActionButton) view).UpdateLaunchInfo(null);
                    else
                        ((ViewGroup) view.getParent()).removeView(view);

                    qa.dismiss();
                }
            });

    if (info instanceof PersonaApplicationInfo) {
        qa.addItem(getResources().getDrawable(android.R.drawable.ic_menu_edit), R.string.menu_edit,
                new OnClickListener() {
                    public void onClick(View v) {
                        editShirtcut((PersonaApplicationInfo) info);
                        qa.dismiss();
                    }
                });
    } else if (info instanceof PersonaLauncherAppWidgetInfo) {
        qa.addItem(getResources().getDrawable(android.R.drawable.ic_menu_edit), R.string.menu_edit,
                new OnClickListener() {
                    public void onClick(View v) {
                        editWidget(view);
                        qa.dismiss();
                    }
                });
    }
    if (info instanceof PersonaApplicationInfo || info instanceof PersonaLauncherAppWidgetInfo) {
        qa.addItem(getResources().getDrawable(android.R.drawable.ic_menu_manage), R.string.menu_uninstall,
                new OnClickListener() {
                    public void onClick(View v) {
                        String UninstallPkg = null;
                        if (info instanceof PersonaApplicationInfo) {
                            try {
                                final PersonaApplicationInfo appInfo = (PersonaApplicationInfo) info;
                                if (appInfo.iconResource != null)
                                    UninstallPkg = appInfo.iconResource.packageName;
                                else {
                                    PackageManager mgr = PersonaLauncher.this.getPackageManager();
                                    ResolveInfo res = mgr.resolveActivity(appInfo.intent, 0);
                                    UninstallPkg = res.activityInfo.packageName;
                                }
                                // Dont uninstall ADW ;-)
                                if (this.getClass().getPackage().getName().equals(UninstallPkg))
                                    UninstallPkg = null;
                            } catch (Exception e) {
                                PersonaLog.w(LOG_TAG, "Could not load shortcut icon: " + info);
                                UninstallPkg = null;
                            }
                        } else if (info instanceof PersonaLauncherAppWidgetInfo) {
                            PersonaLauncherAppWidgetInfo appwidget = (PersonaLauncherAppWidgetInfo) info;
                            final AppWidgetProviderInfo aw = AppWidgetManager.getInstance(PersonaLauncher.this)
                                    .getAppWidgetInfo(appwidget.appWidgetId);
                            if (aw != null)
                                UninstallPkg = aw.provider.getPackageName();
                        }
                        if (UninstallPkg != null) {
                            Intent uninstallIntent = new Intent(Intent.ACTION_DELETE,
                                    Uri.parse("package:" + UninstallPkg));
                            PersonaLauncher.this.startActivity(uninstallIntent);
                        }
                        qa.dismiss();
                    }
                });
    }
    // shows the quick action window on the screen
    qa.show();
}

From source file:android.support.v7.widget.RecyclerView.java

@Override
public void requestChildFocus(View child, View focused) {
    if (!mLayout.onRequestChildFocus(this, child, focused)) {
        mTempRect.set(0, 0, focused.getWidth(), focused.getHeight());
        offsetDescendantRectToMyCoords(focused, mTempRect);
        offsetRectIntoDescendantCoords(child, mTempRect);
        requestChildRectangleOnScreen(child, mTempRect, !mFirstLayoutComplete);
    }/*from  w ww .  j  av a  2s.c  o m*/
    super.requestChildFocus(child, focused);
}