Example usage for android.view View getMeasuredWidth

List of usage examples for android.view View getMeasuredWidth

Introduction

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

Prototype

public final int getMeasuredWidth() 

Source Link

Document

Like #getMeasuredWidthAndState() , but only returns the raw width component (that is the result is masked by #MEASURED_SIZE_MASK ).

Usage

From source file:cc.softwarefactory.lokki.android.fragments.MapViewFragment.java

public Bitmap createDrawableFromView(View view) {

    Log.e(TAG, "createDrawableFromView");
    DisplayMetrics displayMetrics = new DisplayMetrics();
    getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    view.setLayoutParams(new WindowManager.LayoutParams(WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.WRAP_CONTENT));
    view.measure(displayMetrics.widthPixels, displayMetrics.heightPixels);
    view.layout(0, 0, displayMetrics.widthPixels, displayMetrics.heightPixels);
    view.buildDrawingCache();/*from  w  w w .  j  ava2  s.  c  o  m*/
    Bitmap bitmap = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(),
            Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(bitmap);
    view.draw(canvas);

    return bitmap;
}

From source file:android.support.v7.internal.view.menu.ActionMenuPresenter.java

public boolean flagActionItems() {
    final ArrayList<MenuItemImpl> visibleItems = mMenu.getVisibleItems();
    final int itemsSize = visibleItems.size();
    int maxActions = mMaxItems;
    int widthLimit = mActionItemWidthLimit;
    final int querySpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
    final ViewGroup parent = (ViewGroup) mMenuView;

    int requiredItems = 0;
    int requestedItems = 0;
    int firstActionWidth = 0;
    boolean hasOverflow = false;
    for (int i = 0; i < itemsSize; i++) {
        MenuItemImpl item = visibleItems.get(i);
        if (item.requiresActionButton()) {
            requiredItems++;//from  www . j a  v  a  2  s.  c o m
        } else if (item.requestsActionButton()) {
            requestedItems++;
        } else {
            hasOverflow = true;
        }
        if (mExpandedActionViewsExclusive && item.isActionViewExpanded()) {
            // Overflow everything if we have an expanded action view and we're
            // space constrained.
            maxActions = 0;
        }
    }

    // Reserve a spot for the overflow item if needed.
    if (mReserveOverflow && (hasOverflow || requiredItems + requestedItems > maxActions)) {
        maxActions--;
    }
    maxActions -= requiredItems;

    final SparseBooleanArray seenGroups = mActionButtonGroups;
    seenGroups.clear();

    int cellSize = 0;
    int cellsRemaining = 0;
    if (mStrictWidthLimit) {
        cellsRemaining = widthLimit / mMinCellSize;
        final int cellSizeRemaining = widthLimit % mMinCellSize;
        cellSize = mMinCellSize + cellSizeRemaining / cellsRemaining;
    }

    // Flag as many more requested items as will fit.
    for (int i = 0; i < itemsSize; i++) {
        MenuItemImpl item = visibleItems.get(i);

        if (item.requiresActionButton()) {
            View v = getItemView(item, mScrapActionButtonView, parent);
            if (mScrapActionButtonView == null) {
                mScrapActionButtonView = v;
            }
            if (mStrictWidthLimit) {
                cellsRemaining -= ActionMenuView.measureChildForCells(v, cellSize, cellsRemaining, querySpec,
                        0);
            } else {
                v.measure(querySpec, querySpec);
            }
            final int measuredWidth = v.getMeasuredWidth();
            widthLimit -= measuredWidth;
            if (firstActionWidth == 0) {
                firstActionWidth = measuredWidth;
            }
            final int groupId = item.getGroupId();
            if (groupId != 0) {
                seenGroups.put(groupId, true);
            }
            item.setIsActionButton(true);
        } else if (item.requestsActionButton()) {
            // Items in a group with other items that already have an action slot
            // can break the max actions rule, but not the width limit.
            final int groupId = item.getGroupId();
            final boolean inGroup = seenGroups.get(groupId);
            boolean isAction = (maxActions > 0 || inGroup) && widthLimit > 0
                    && (!mStrictWidthLimit || cellsRemaining > 0);

            if (isAction) {
                View v = getItemView(item, mScrapActionButtonView, parent);
                if (mScrapActionButtonView == null) {
                    mScrapActionButtonView = v;
                }
                if (mStrictWidthLimit) {
                    final int cells = ActionMenuView.measureChildForCells(v, cellSize, cellsRemaining,
                            querySpec, 0);
                    cellsRemaining -= cells;
                    if (cells == 0) {
                        isAction = false;
                    }
                } else {
                    v.measure(querySpec, querySpec);
                }
                final int measuredWidth = v.getMeasuredWidth();
                widthLimit -= measuredWidth;
                if (firstActionWidth == 0) {
                    firstActionWidth = measuredWidth;
                }

                if (mStrictWidthLimit) {
                    isAction &= widthLimit >= 0;
                } else {
                    // Did this push the entire first item past the limit?
                    isAction &= widthLimit + firstActionWidth > 0;
                }
            }

            if (isAction && groupId != 0) {
                seenGroups.put(groupId, true);
            } else if (inGroup) {
                // We broke the width limit. Demote the whole group, they all overflow now.
                seenGroups.put(groupId, false);
                for (int j = 0; j < i; j++) {
                    MenuItemImpl areYouMyGroupie = visibleItems.get(j);
                    if (areYouMyGroupie.getGroupId() == groupId) {
                        // Give back the action slot
                        if (areYouMyGroupie.isActionButton()) {
                            maxActions++;
                        }
                        areYouMyGroupie.setIsActionButton(false);
                    }
                }
            }

            if (isAction) {
                maxActions--;
            }

            item.setIsActionButton(isAction);
        }
    }
    return true;
}

From source file:com.base.view.slidemenu.SlideMenu.java

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    final int count = getChildCount();
    final int paddingLeft = getPaddingLeft();
    final int paddingRight = getPaddingRight();
    final int paddingTop = getPaddingTop();
    final int statusBarHeight = mSlideMode == MODE_SLIDE_WINDOW ? STATUS_BAR_HEIGHT : 0;
    for (int index = 0; index < count; index++) {
        View child = getChildAt(index);
        final int measureWidth = child.getMeasuredWidth();
        final int measureHeight = child.getMeasuredHeight();
        LayoutParams layoutParams = (LayoutParams) child.getLayoutParams();
        switch (layoutParams.role) {
        case LayoutParams.ROLE_CONTENT:
            // we should display the content in front of all other views
            child.bringToFront();/*from w w w  .  j a  va 2s . c  o  m*/
            child.layout(mCurrentContentOffset + paddingLeft, paddingTop,
                    paddingLeft + measureWidth + mCurrentContentOffset, paddingTop + measureHeight);
            break;
        case LayoutParams.ROLE_PRIMARY_MENU:
            mContentBoundsRight = measureWidth;
            child.layout(paddingLeft, statusBarHeight + paddingTop, paddingLeft + measureWidth,
                    statusBarHeight + paddingTop + measureHeight);
            break;
        case LayoutParams.ROLE_SECONDARY_MENU:
            mContentBoundsLeft = -measureWidth;
            child.layout(r - l - paddingRight - measureWidth, statusBarHeight + paddingTop,
                    r - l - paddingRight, statusBarHeight + paddingTop + measureHeight);
            break;
        default:
            continue;
        }
    }
}

From source file:com.daniel.view.swipelistview.SwipeListViewTouchListener.java

/**
 * Set current item's back view/* ww w  .j a  va 2 s .c  o  m*/
 *
 * @param backView
 */
private void setBackView(View backView) {
    this.backView = backView;
    if (backView != null && frontView != null) {
        if (swipeMode == SwipeListView.SWIPE_MODE_LEFT || swipeMode == SwipeListView.SWIPE_MODE_BOTH) {
            setLeftOffset(frontView.getMeasuredWidth() - backView.getMeasuredWidth());
        } else if (swipeMode == SwipeListView.SWIPE_MODE_BOTH || swipeMode == SwipeListView.SWIPE_MODE_RIGHT) {
            setRightOffset(frontView.getMeasuredHeight() - backView.getMeasuredWidth());
        }
    }
    backView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            swipeListView.onClickBackView(downPosition);
        }
    });
}

From source file:com.android.mail.browse.ConversationContainer.java

private void layoutOverlay(View child, int childTop, int childBottom) {
    final int top = childTop - mOffsetY;
    final int bottom = childBottom - mOffsetY;

    final MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams();
    final int childLeft = getPaddingLeft() + lp.leftMargin;

    child.layout(childLeft, top, childLeft + child.getMeasuredWidth(), bottom);
}

From source file:com.actionbarsherlock.widget.ActivityChooserView.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    View child = mActivityChooserContent;
    // If the default action is not visible we want to be as tall as the
    // ActionBar so if this widget is used in the latter it will look as
    // a normal action button.
    if (mDefaultActivityButton.getVisibility() != VISIBLE) {
        heightMeasureSpec = MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(heightMeasureSpec),
                MeasureSpec.EXACTLY);//  w w  w .  j a  v a  2  s .c om
    }
    measureChild(child, widthMeasureSpec, heightMeasureSpec);
    setMeasuredDimension(child.getMeasuredWidth(), child.getMeasuredHeight());
}

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

public boolean flagActionItems() {
    final ArrayList<MenuItemImpl> visibleItems = mMenu.getVisibleItems();
    final int itemsSize = visibleItems.size();
    int maxActions = mMaxItems;
    int widthLimit = mActionItemWidthLimit;
    final int querySpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
    final ViewGroup parent = (ViewGroup) mMenuView;

    int requiredItems = 0;
    int requestedItems = 0;
    int firstActionWidth = 0;
    boolean hasOverflow = false;
    for (int i = 0; i < itemsSize; i++) {
        MenuItemImpl item = visibleItems.get(i);
        if (item.requiresActionButton()) {
            requiredItems++;/*from ww  w.  ja v  a  2  s.co m*/
        } else if (item.requestsActionButton()) {
            requestedItems++;
        } else {
            hasOverflow = true;
        }
        if (mExpandedActionViewsExclusive && item.isActionViewExpanded()) {
            // Overflow everything if we have an expanded action view and we're
            // space constrained.
            maxActions = 0;
        }
    }

    // Reserve a spot for the overflow item if needed.
    if (mReserveOverflow && (hasOverflow || requiredItems + requestedItems > maxActions)) {
        maxActions--;
    }
    maxActions -= requiredItems;

    final SparseBooleanArray seenGroups = mActionButtonGroups;
    seenGroups.clear();

    int cellSize = 0;
    int cellsRemaining = 0;
    if (mStrictWidthLimit) {
        cellsRemaining = widthLimit / mMinCellSize;
        final int cellSizeRemaining = widthLimit % mMinCellSize;
        cellSize = mMinCellSize + cellSizeRemaining / cellsRemaining;
    }

    // Flag as many more requested items as will fit.
    for (int i = 0; i < itemsSize; i++) {
        MenuItemImpl item = visibleItems.get(i);

        if (item.requiresActionButton()) {
            View v = getItemView(item, mScrapActionButtonView, parent);
            if (mScrapActionButtonView == null) {
                mScrapActionButtonView = v;
            }
            if (mStrictWidthLimit) {
                cellsRemaining -= ActionMenuView.measureChildForCells(v, cellSize, cellsRemaining, querySpec,
                        0);
            } else {
                v.measure(querySpec, querySpec);
            }
            final int measuredWidth = v.getMeasuredWidth();
            widthLimit -= measuredWidth;
            if (firstActionWidth == 0) {
                firstActionWidth = measuredWidth;
            }
            final int groupId = item.getGroupId();
            if (groupId != 0) {
                seenGroups.put(groupId, true);
            }
            item.setIsActionButton(true);
        } else if (item.requestsActionButton()) {
            // Items in a group with other items that already have an action slot
            // can break the max actions rule, but not the width limit.
            final int groupId = item.getGroupId();
            final boolean inGroup = seenGroups.get(groupId);
            boolean isAction = (maxActions > 0 || inGroup) && widthLimit > 0
                    && (!mStrictWidthLimit || cellsRemaining > 0);

            if (isAction) {
                View v = getItemView(item, mScrapActionButtonView, parent);
                if (mScrapActionButtonView == null) {
                    mScrapActionButtonView = v;
                }
                if (mStrictWidthLimit) {
                    final int cells = ActionMenuView.measureChildForCells(v, cellSize, cellsRemaining,
                            querySpec, 0);
                    cellsRemaining -= cells;
                    if (cells == 0) {
                        isAction = false;
                    }
                } else {
                    v.measure(querySpec, querySpec);
                }
                final int measuredWidth = v.getMeasuredWidth();
                widthLimit -= measuredWidth;
                if (firstActionWidth == 0) {
                    firstActionWidth = measuredWidth;
                }

                if (mStrictWidthLimit) {
                    isAction &= widthLimit >= 0;
                } else {
                    // Did this push the entire first item past the limit?
                    isAction &= widthLimit + firstActionWidth > 0;
                }
            }

            if (isAction && groupId != 0) {
                seenGroups.put(groupId, true);
            } else if (inGroup) {
                // We broke the width limit. Demote the whole group, they all overflow now.
                seenGroups.put(groupId, false);
                for (int j = 0; j < i; j++) {
                    MenuItemImpl areYouMyGroupie = visibleItems.get(j);
                    if (areYouMyGroupie.getGroupId() == groupId) {
                        // Give back the action slot
                        if (areYouMyGroupie.isActionButton())
                            maxActions++;
                        areYouMyGroupie.setIsActionButton(false);
                    }
                }
            }

            if (isAction)
                maxActions--;

            item.setIsActionButton(isAction);
        } else {
            // Neither requires nor requests an action button.
            item.setIsActionButton(false);
        }
    }
    return true;
}

From source file:com.center.mycode.view.swipelayout.SwipeRevealLayout.java

/**
 * {@inheritDoc}/* www  .  ja v  a 2  s.  c  o  m*/
 */
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    mAborted = false;

    for (int index = 0; index < getChildCount(); index++) {
        final View child = getChildAt(index);

        int left, right, top, bottom;
        left = right = top = bottom = 0;

        final int minLeft = getPaddingLeft();
        final int maxRight = Math.max(r - getPaddingRight() - l, 0);
        final int minTop = getPaddingTop();
        final int maxBottom = Math.max(b - getPaddingBottom() - t, 0);

        switch (mDragEdge) {
        case DRAG_EDGE_RIGHT:
            left = Math.max(r - child.getMeasuredWidth() - getPaddingRight() - l, minLeft);
            top = Math.min(getPaddingTop(), maxBottom);
            right = Math.max(r - getPaddingRight() - l, minLeft);
            bottom = Math.min(child.getMeasuredHeight() + getPaddingTop(), maxBottom);
            break;

        case DRAG_EDGE_LEFT:
            left = Math.min(getPaddingLeft(), maxRight);
            top = Math.min(getPaddingTop(), maxBottom);
            right = Math.min(child.getMeasuredWidth() + getPaddingLeft(), maxRight);
            bottom = Math.min(child.getMeasuredHeight() + getPaddingTop(), maxBottom);
            break;

        case DRAG_EDGE_TOP:
            left = Math.min(getPaddingLeft(), maxRight);
            top = Math.min(getPaddingTop(), maxBottom);
            right = Math.min(child.getMeasuredWidth() + getPaddingLeft(), maxRight);
            bottom = Math.min(child.getMeasuredHeight() + getPaddingTop(), maxBottom);
            break;

        case DRAG_EDGE_BOTTOM:
            left = Math.min(getPaddingLeft(), maxRight);
            top = Math.max(b - child.getMeasuredHeight() - getPaddingBottom() - t, minTop);
            right = Math.min(child.getMeasuredWidth() + getPaddingLeft(), maxRight);
            bottom = Math.max(b - getPaddingBottom() - t, minTop);
            break;
        }

        child.layout(left, top, right, bottom);
    }

    // taking account offset when mode is SAME_LEVEL
    if (mMode == MODE_SAME_LEVEL) {
        switch (mDragEdge) {
        case DRAG_EDGE_LEFT:
            mSecondaryView.offsetLeftAndRight(-mSecondaryView.getWidth());
            break;

        case DRAG_EDGE_RIGHT:
            mSecondaryView.offsetLeftAndRight(mSecondaryView.getWidth());
            break;

        case DRAG_EDGE_TOP:
            mSecondaryView.offsetTopAndBottom(-mSecondaryView.getHeight());
            break;

        case DRAG_EDGE_BOTTOM:
            mSecondaryView.offsetTopAndBottom(mSecondaryView.getHeight());
        }
    }

    initRects();

    if (mIsOpenBeforeInit) {
        open(false);
    } else {
        close(false);
    }

    mLastMainLeft = mMainView.getLeft();
    mLastMainTop = mMainView.getTop();
}

From source file:cc.mintcoin.wallet.ui.SendCoinsFragment.java

private void popup(@Nonnull final View anchor, @Nonnull final View contentView) {
    contentView.measure(MeasureSpec.makeMeasureSpec(MeasureSpec.UNSPECIFIED, 0),
            MeasureSpec.makeMeasureSpec(MeasureSpec.UNSPECIFIED, 0));

    popupWindow = new PopupWindow(contentView, contentView.getMeasuredWidth(), contentView.getMeasuredHeight(),
            false);//from w w  w.  ja  va  2 s.co  m
    popupWindow.showAsDropDown(anchor);

    // hack
    contentView.setBackgroundResource(
            popupWindow.isAboveAnchor() ? R.drawable.popup_frame_above : R.drawable.popup_frame_below);
}