android.view.View.MeasureSpec Java Examples

The following examples show how to use android.view.View.MeasureSpec. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ScreenshotUtil.java    From MAD-Spy with MIT License 6 votes vote down vote up
/**
 * Measures and takes a screenshot of the given View {@link View}
 *
 * @param view The view which the screenshot is taken.
 * @return A {@link Bitmap} for the taken screenshot
 */
public Bitmap takeScreenshotForView(View view){
    // Measures
    view.measure(MeasureSpec.makeMeasureSpec(view.getWidth(), MeasureSpec.EXACTLY),
            MeasureSpec.makeMeasureSpec(view.getHeight(), MeasureSpec.EXACTLY));

    view.layout((int) view.getX(), (int) view.getY(),
            (int) view.getX() + view.getMeasuredWidth(), (int) view.getY() + view.getMeasuredHeight());

    view.setDrawingCacheEnabled(true);
    view.buildDrawingCache(true);
    Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache());
    view.setDrawingCacheEnabled(false);

    return bitmap;
}
 
Example #2
Source File: MediaDownloadProgressView.java    From FimiX8-RE with MIT License 6 votes vote down vote up
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int widthSpecMode = MeasureSpec.getMode(widthMeasureSpec);
    int widthSpecSize = MeasureSpec.getSize(widthMeasureSpec);
    int heightSpecMode = MeasureSpec.getMode(heightMeasureSpec);
    int heightSpecSize = MeasureSpec.getSize(heightMeasureSpec);
    if (widthSpecMode == NTLMConstants.FLAG_NEGOTIATE_KEY_EXCHANGE || widthSpecMode == Integer.MIN_VALUE) {
        this.mWidth = widthSpecSize;
    } else {
        this.mWidth = 0;
    }
    if (heightSpecMode == Integer.MIN_VALUE || heightSpecMode == 0) {
        this.mHeight = dipToPx(15);
    } else {
        this.mHeight = heightSpecSize;
    }
    setMeasuredDimension(this.mWidth, this.mHeight);
}
 
Example #3
Source File: DataReductionPromoView.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int width = MeasureSpec.getSize(widthMeasureSpec);
    int height = MeasureSpec.getSize(heightMeasureSpec);

    if (width >= 2 * mIllustration.getWidth() && width > height) {
        mPromoContent.setOrientation(LinearLayout.HORIZONTAL);
        setMaxChildWidth(mMaxChildWidthHorizontal);
        ApiCompatibilityUtils.setPaddingRelative(
                mIllustration, 0, 0, mIllustrationPaddingSide, 0);
    } else {
        mPromoContent.setOrientation(LinearLayout.VERTICAL);
        setMaxChildWidth(mMaxChildWidth);
        mIllustration.setPadding(0, 0, 0, mIllustrationPaddingBottom);
    }

    setMaxChildHeight(height - mFrameHeightMargin);
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
 
Example #4
Source File: SwipeRefreshLayout.java    From letv with Apache License 2.0 6 votes vote down vote up
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    if (this.mTarget == null) {
        ensureTarget();
    }
    if (this.mTarget != null) {
        this.mTarget.measure(MeasureSpec.makeMeasureSpec((getMeasuredWidth() - getPaddingLeft()) - getPaddingRight(), 1073741824), MeasureSpec.makeMeasureSpec((getMeasuredHeight() - getPaddingTop()) - getPaddingBottom(), 1073741824));
        this.mCircleView.measure(MeasureSpec.makeMeasureSpec(this.mCircleWidth, 1073741824), MeasureSpec.makeMeasureSpec(this.mCircleHeight, 1073741824));
        if (!(this.mUsingCustomStart || this.mOriginalOffsetCalculated)) {
            this.mOriginalOffsetCalculated = true;
            int i = -this.mCircleView.getMeasuredHeight();
            this.mOriginalOffsetTop = i;
            this.mCurrentTargetOffsetTop = i;
        }
        this.mCircleViewIndex = -1;
        for (int index = 0; index < getChildCount(); index++) {
            if (getChildAt(index) == this.mCircleView) {
                this.mCircleViewIndex = index;
                return;
            }
        }
    }
}
 
Example #5
Source File: TabPageIndicator.java    From letv with Apache License 2.0 6 votes vote down vote up
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    boolean lockedExpanded = widthMode == 1073741824;
    setFillViewport(lockedExpanded);
    int childCount = this.mTabLayout.getChildCount();
    if (childCount <= 1 || !(widthMode == 1073741824 || widthMode == Integer.MIN_VALUE)) {
        this.mMaxTabWidth = -1;
    } else if (childCount > 2) {
        this.mMaxTabWidth = (int) (((float) MeasureSpec.getSize(widthMeasureSpec)) * 0.4f);
    } else {
        this.mMaxTabWidth = MeasureSpec.getSize(widthMeasureSpec) / 2;
    }
    int oldWidth = getMeasuredWidth();
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    int newWidth = getMeasuredWidth();
    if (lockedExpanded && oldWidth != newWidth) {
        setCurrentItem(this.mSelectedTabIndex);
    }
}
 
Example #6
Source File: QuickReturnHeaderHelper.java    From QuickReturnHeader with Apache License 2.0 6 votes vote down vote up
public View createView() {
    inflater = LayoutInflater.from(context);
    content = inflater.inflate(contentResId, null);

    realHeader = inflater.inflate(headerResId, null);
    realHeaderLayoutParams = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    realHeaderLayoutParams.gravity = Gravity.TOP;

    // Use measured height here as an estimate of the header height, later on after the layout is complete 
    // we'll use the actual height
    int widthMeasureSpec = MeasureSpec.makeMeasureSpec(LayoutParams.MATCH_PARENT, MeasureSpec.EXACTLY);
    int heightMeasureSpec = MeasureSpec.makeMeasureSpec(LayoutParams.WRAP_CONTENT, MeasureSpec.EXACTLY);
    realHeader.measure(widthMeasureSpec, heightMeasureSpec);
    headerHeight = realHeader.getMeasuredHeight();

    listView = (ListView) content.findViewById(android.R.id.list);
    if (listView != null) {
        createListView();
    } else {
        createScrollView();
    }
    return root;
}
 
Example #7
Source File: WidgetUtils.java    From SprintNBA with Apache License 2.0 6 votes vote down vote up
/**
 * 测量控件
 *
 * @param view
 */
public static void measureView(View view) {
    ViewGroup.LayoutParams p = view.getLayoutParams();
    if (p == null) {
        p = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
    }
    int childWidthSpec = ViewGroup.getChildMeasureSpec(0, 0 + 0, p.width);
    int lpHeight = p.height;
    int childHeightSpec;
    if (lpHeight > 0) {
        childHeightSpec = MeasureSpec.makeMeasureSpec(lpHeight,
                MeasureSpec.EXACTLY);
    } else {
        childHeightSpec = MeasureSpec.makeMeasureSpec(0,
                MeasureSpec.UNSPECIFIED);
    }
    view.measure(childWidthSpec, childHeightSpec);
}
 
Example #8
Source File: RatioResolutionPolicy.java    From 30-android-libraries-in-30-days with Apache License 2.0 6 votes vote down vote up
@Override
public void onMeasure(final RenderSurfaceView pRenderSurfaceView, final int pWidthMeasureSpec, final int pHeightMeasureSpec) {
	BaseResolutionPolicy.throwOnNotMeasureSpecEXACTLY(pWidthMeasureSpec, pHeightMeasureSpec);

	final int specWidth = MeasureSpec.getSize(pWidthMeasureSpec);
	final int specHeight = MeasureSpec.getSize(pHeightMeasureSpec);

	final float desiredRatio = this.mRatio;
	final float realRatio = (float)specWidth / specHeight;

	int measuredWidth;
	int measuredHeight;
	if(realRatio < desiredRatio) {
		measuredWidth = specWidth;
		measuredHeight = Math.round(measuredWidth / desiredRatio);
	} else {
		measuredHeight = specHeight;
		measuredWidth = Math.round(measuredHeight * desiredRatio);
	}

	pRenderSurfaceView.setMeasuredDimensionProxy(measuredWidth, measuredHeight);
}
 
Example #9
Source File: IcsListPopupWindow.java    From Libraries-for-Android-Developers with MIT License 6 votes vote down vote up
private void measureScrapChild(View child, int position, int widthMeasureSpec) {
    ListView.LayoutParams p = (ListView.LayoutParams) child.getLayoutParams();
    if (p == null) {
        p = new ListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT, 0);
        child.setLayoutParams(p);
    }
    //XXX p.viewType = mAdapter.getItemViewType(position);
    //XXX p.forceAdd = true;

    int childWidthSpec = ViewGroup.getChildMeasureSpec(widthMeasureSpec,
            mDropDownList.getPaddingLeft() + mDropDownList.getPaddingRight(), p.width);
    int lpHeight = p.height;
    int childHeightSpec;
    if (lpHeight > 0) {
        childHeightSpec = MeasureSpec.makeMeasureSpec(lpHeight, MeasureSpec.EXACTLY);
    } else {
        childHeightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
    }
    child.measure(childWidthSpec, childHeightSpec);
}
 
Example #10
Source File: RcRollerView.java    From FimiX8-RE with MIT License 6 votes vote down vote up
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    int wSpecMode = MeasureSpec.getMode(widthMeasureSpec);
    int wSpecSize = MeasureSpec.getSize(widthMeasureSpec);
    int hSpecMode = MeasureSpec.getMode(heightMeasureSpec);
    int hSpecSize = MeasureSpec.getSize(heightMeasureSpec);
    int resultWidth = wSpecSize;
    int resultHeight = hSpecSize;
    if (wSpecMode == Integer.MIN_VALUE && hSpecMode == Integer.MIN_VALUE) {
        resultWidth = this.bitmap.getWidth();
        resultHeight = this.bitmap.getHeight();
    } else if (wSpecMode == Integer.MIN_VALUE) {
        resultWidth = this.bitmap.getWidth();
        resultHeight = hSpecSize;
    } else if (hSpecMode == Integer.MIN_VALUE) {
        resultWidth = wSpecSize;
        resultHeight = this.bitmap.getHeight();
    }
    setMeasuredDimension(resultWidth, resultHeight);
}
 
Example #11
Source File: ZoomInRightEnter.java    From SprintNBA with Apache License 2.0 5 votes vote down vote up
@Override
public void setAnimation(View view) {
	view.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
	int w = view.getMeasuredWidth();

	animatorSet.playTogether(//
			ObjectAnimator.ofFloat(view, "scaleX", 0.1f, 0.475f, 1),//
			ObjectAnimator.ofFloat(view, "scaleY", 0.1f, 0.475f, 1),//
			ObjectAnimator.ofFloat(view, "translationX", w, -48, 0),//
			ObjectAnimator.ofFloat(view, "alpha", 0, 1, 1));
}
 
Example #12
Source File: VideoViewTV.java    From letv with Apache License 2.0 5 votes vote down vote up
public int resolveAdjustedSize(int desiredSize, int measureSpec) {
    int result = desiredSize;
    int specMode = MeasureSpec.getMode(measureSpec);
    int specSize = MeasureSpec.getSize(measureSpec);
    switch (specMode) {
        case Integer.MIN_VALUE:
            return Math.min(desiredSize, specSize);
        case 0:
            return desiredSize;
        case 1073741824:
            return specSize;
        default:
            return result;
    }
}
 
Example #13
Source File: ActionMenuPresenter.java    From zhangshangwuda with Apache License 2.0 5 votes vote down vote up
@Override
public void initForMenu(Context context, MenuBuilder menu) {
    super.initForMenu(context, menu);

    final Resources res = context.getResources();

    if (!mReserveOverflowSet) {
        mReserveOverflow = reserveOverflow(mContext);
    }

    if (!mWidthLimitSet) {
        mWidthLimit = res.getDisplayMetrics().widthPixels / 2;
    }

    // Measure for initial configuration
    if (!mMaxItemsSet) {
        mMaxItems = getResources_getInteger(context, R.integer.abs__max_action_buttons);
    }

    int width = mWidthLimit;
    if (mReserveOverflow) {
        if (mOverflowButton == null) {
            mOverflowButton = new OverflowMenuButton(mSystemContext);
            final int spec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
            mOverflowButton.measure(spec, spec);
        }
        width -= mOverflowButton.getMeasuredWidth();
    } else {
        mOverflowButton = null;
    }

    mActionItemWidthLimit = width;

    mMinCellSize = (int) (ActionMenuView.MIN_CELL_SIZE * res.getDisplayMetrics().density);

    // Drop a scrap view as it may no longer reflect the proper context/config.
    mScrapActionButtonView = null;
}
 
Example #14
Source File: RelativeResolutionPolicy.java    From tilt-game-android with MIT License 5 votes vote down vote up
@Override
public void onMeasure(final IResolutionPolicy.Callback pResolutionPolicyCallback, final int pWidthMeasureSpec, final int pHeightMeasureSpec) {
	BaseResolutionPolicy.throwOnNotMeasureSpecEXACTLY(pWidthMeasureSpec, pHeightMeasureSpec);

	final int measuredWidth = (int) (MeasureSpec.getSize(pWidthMeasureSpec) * this.mWidthScale);
	final int measuredHeight = (int) (MeasureSpec.getSize(pHeightMeasureSpec) * this.mHeightScale);

	pResolutionPolicyCallback.onResolutionChanged(measuredWidth, measuredHeight);
}
 
Example #15
Source File: PieView.java    From quickmark with MIT License 5 votes vote down vote up
private int measureWidth(int pWidthMeasureSpec) {
	int result = 0;
	int widthMode = MeasureSpec.getMode(pWidthMeasureSpec);// �õ�ģʽ
	int widthSize = MeasureSpec.getSize(pWidthMeasureSpec);// �õ��ߴ�

	switch (widthMode) {
	/**
	 * mode�������������ȡֵ�ֱ�ΪMeasureSpec.UNSPECIFIED, MeasureSpec.EXACTLY,
	 * MeasureSpec.AT_MOST?
	 * 
	 * 
	 * MeasureSpec.EXACTLY�Ǿ�ȷ�ߴ磬
	 * �����ǽ��ؼ���layout_width��layout_heightָ��Ϊ������ֵʱ��andorid
	 * :layout_width="50dip"������ΪFILL_PARENT�ǣ����ǿؼ���С�Ѿ�ȷ������������Ǿ�ȷ�ߴ�?
	 * 
	 * 
	 * MeasureSpec.AT_MOST�����ߴ磬
	 * ���ؼ���layout_width��layout_heightָ��ΪWRAP_CONTENT�J
	 * ���ؼ���Сһ����������ӿռ�����ݽ��б仯����ʱ�ؼ��ߴ�ֻҪ���������ؼ�����Ėc?�ߴ缴��
	 * ����ˣ���ʱ��mode��AT_MOST��size�����˸��ؼ���������ߴ�?
	 * 
	 * 
	 * MeasureSpec.UNSPECIFIED��δָ���ߴ磬����������࣬د?���Ǹ��ؼ���AdapterView��
	 * ͨ��measure���������ģʽ?
	 */
	case MeasureSpec.AT_MOST:
	case MeasureSpec.EXACTLY:
		result = widthSize;
		break;
	}
	return result;
}
 
Example #16
Source File: ZoomInBottomEnter.java    From FlycoDialog_Master with MIT License 5 votes vote down vote up
@Override
public void setAnimation(View view) {
	view.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
	int h = view.getMeasuredHeight();

	animatorSet.playTogether(ObjectAnimator.ofFloat(view, "scaleX", 0.1f, 0.475f, 1),
			ObjectAnimator.ofFloat(view, "scaleY", 0.1f, 0.475f, 1),
			ObjectAnimator.ofFloat(view, "translationY", h, -60, 0), ObjectAnimator.ofFloat(view, "alpha", 0, 1, 1));
}
 
Example #17
Source File: DismissibleListItemView.java    From Klyph with MIT License 5 votes vote down vote up
protected void onMeasure(int paramInt1, int paramInt2)
{
	this.mWidth = View.MeasureSpec.getSize(paramInt1);
	this.mDismissWidthThreshold = ((int) (0.5F * this.mWidth));
	int i = View.MeasureSpec.getSize(paramInt2);
	int j = View.MeasureSpec.getMode(paramInt2);
	this.mPanel.measure(View.MeasureSpec.makeMeasureSpec(this.mWidth, 1073741824), View.MeasureSpec.makeMeasureSpec(i, j));
	super.onMeasure(paramInt1, View.MeasureSpec.makeMeasureSpec(this.mPanel.getMeasuredHeight(), 1073741824));
	setScrollLimits(-this.mWidth, this.mWidth);
}
 
Example #18
Source File: ActionMenuPresenter.java    From android-apps with MIT License 5 votes vote down vote up
@Override
public void initForMenu(Context context, MenuBuilder menu) {
    super.initForMenu(context, menu);

    final Resources res = context.getResources();

    if (!mReserveOverflowSet) {
        mReserveOverflow = reserveOverflow(mContext);
    }

    if (!mWidthLimitSet) {
        mWidthLimit = res.getDisplayMetrics().widthPixels / 2;
    }

    // Measure for initial configuration
    if (!mMaxItemsSet) {
        mMaxItems = getResources_getInteger(context, R.integer.abs__max_action_buttons);
    }

    int width = mWidthLimit;
    if (mReserveOverflow) {
        if (mOverflowButton == null) {
            mOverflowButton = new OverflowMenuButton(mSystemContext);
            final int spec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
            mOverflowButton.measure(spec, spec);
        }
        width -= mOverflowButton.getMeasuredWidth();
    } else {
        mOverflowButton = null;
    }

    mActionItemWidthLimit = width;

    mMinCellSize = (int) (ActionMenuView.MIN_CELL_SIZE * res.getDisplayMetrics().density);

    // Drop a scrap view as it may no longer reflect the proper context/config.
    mScrapActionButtonView = null;
}
 
Example #19
Source File: HListView.java    From letv with Apache License 2.0 5 votes vote down vote up
private void measureItem(View child) {
    int childWidthSpec;
    ViewGroup.LayoutParams p = child.getLayoutParams();
    if (p == null) {
        p = new ViewGroup.LayoutParams(-2, -1);
    }
    int childHeightSpec = ViewGroup.getChildMeasureSpec(this.mHeightMeasureSpec, this.mListPadding.top + this.mListPadding.bottom, p.height);
    int lpWidth = p.width;
    if (lpWidth > 0) {
        childWidthSpec = MeasureSpec.makeMeasureSpec(lpWidth, 1073741824);
    } else {
        childWidthSpec = MeasureSpec.makeMeasureSpec(0, 0);
    }
    child.measure(childWidthSpec, childHeightSpec);
}
 
Example #20
Source File: VideoViewH264mp4_4D.java    From letv with Apache License 2.0 5 votes vote down vote up
public int resolveAdjustedSize(int desiredSize, int measureSpec) {
    int result = desiredSize;
    int specMode = MeasureSpec.getMode(measureSpec);
    int specSize = MeasureSpec.getSize(measureSpec);
    switch (specMode) {
        case Integer.MIN_VALUE:
            return Math.min(desiredSize, specSize);
        case 0:
            return desiredSize;
        case 1073741824:
            return specSize;
        default:
            return result;
    }
}
 
Example #21
Source File: NestedScrollView.java    From letv with Apache License 2.0 5 votes vote down vote up
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    if (this.mFillViewport && MeasureSpec.getMode(heightMeasureSpec) != 0 && getChildCount() > 0) {
        View child = getChildAt(0);
        int height = getMeasuredHeight();
        if (child.getMeasuredHeight() < height) {
            child.measure(getChildMeasureSpec(widthMeasureSpec, getPaddingLeft() + getPaddingRight(), ((FrameLayout.LayoutParams) child.getLayoutParams()).width), MeasureSpec.makeMeasureSpec((height - getPaddingTop()) - getPaddingBottom(), 1073741824));
        }
    }
}
 
Example #22
Source File: TextBubble.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Calculates the new position for the bubble, updating mXPosition, mYPosition, mYOffset and
 * the bubble arrow offset information without updating the UI. To see the changes,
 * showAtCalculatedPosition should be called explicitly.
 */
private void calculateNewPosition() {
    measureContentView();

    // Center the bubble below of the anchor, arrow pointing upward.  The overlap determines how
    // much of the bubble's arrow overlaps the anchor view.
    int[] anchorCoordinates = {0, 0};
    mAnchorView.getLocationOnScreen(anchorCoordinates);
    anchorCoordinates[0] += mAnchorView.getWidth() / 2;
    anchorCoordinates[1] += (int) (mAnchorView.getHeight() * (1.0 - mYOverlapPercentage));

    mWidth = mContentView.getMeasuredWidth()
            + mCachedPaddingRect.left + mCachedPaddingRect.right;
    mHeight = mContentView.getMeasuredHeight()
            + mCachedPaddingRect.top + mCachedPaddingRect.bottom;
    mXPosition = anchorCoordinates[0] - (mWidth / 2);
    mYPosition = anchorCoordinates[1];

    // Make sure the bubble stays on screen.
    View rootView = mAnchorView.getRootView();
    if (mXPosition > rootView.getWidth() - mWidth) {
        mXPosition = rootView.getWidth() - mWidth;
    } else if (mXPosition < 0) {
        mXPosition = 0;
    }

    // Center the tip of the arrow.
    int tipCenterXPosition = anchorCoordinates[0] - mXPosition;
    ((BubbleBackgroundDrawable) getBackground()).setBubbleArrowXCenter(tipCenterXPosition);

    // Update the popup's dimensions.
    setWidth(MeasureSpec.makeMeasureSpec(mWidth, MeasureSpec.EXACTLY));
    setHeight(MeasureSpec.makeMeasureSpec(mHeight, MeasureSpec.EXACTLY));
}
 
Example #23
Source File: TextBubble.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Calculates the new position for the bubble, updating mXPosition, mYPosition, mYOffset and
 * the bubble arrow offset information without updating the UI. To see the changes,
 * showAtCalculatedPosition should be called explicitly.
 */
private void calculateNewPosition() {
    measureContentView();

    // Center the bubble below of the anchor, arrow pointing upward.  The overlap determines how
    // much of the bubble's arrow overlaps the anchor view.
    int[] anchorCoordinates = {0, 0};
    mAnchorView.getLocationOnScreen(anchorCoordinates);
    anchorCoordinates[0] += mAnchorView.getWidth() / 2;
    anchorCoordinates[1] += (int) (mAnchorView.getHeight() * (1.0 - mYOverlapPercentage));

    mWidth = mContentView.getMeasuredWidth()
            + mCachedPaddingRect.left + mCachedPaddingRect.right;
    mHeight = mContentView.getMeasuredHeight()
            + mCachedPaddingRect.top + mCachedPaddingRect.bottom;
    mXPosition = anchorCoordinates[0] - (mWidth / 2);
    mYPosition = anchorCoordinates[1];

    // Make sure the bubble stays on screen.
    View rootView = mAnchorView.getRootView();
    if (mXPosition > rootView.getWidth() - mWidth) {
        mXPosition = rootView.getWidth() - mWidth;
    } else if (mXPosition < 0) {
        mXPosition = 0;
    }

    // Center the tip of the arrow.
    int tipCenterXPosition = anchorCoordinates[0] - mXPosition;
    ((BubbleBackgroundDrawable) getBackground()).setBubbleArrowXCenter(tipCenterXPosition);

    // Update the popup's dimensions.
    setWidth(MeasureSpec.makeMeasureSpec(mWidth, MeasureSpec.EXACTLY));
    setHeight(MeasureSpec.makeMeasureSpec(mHeight, MeasureSpec.EXACTLY));
}
 
Example #24
Source File: ActionMenuPresenter.java    From CSipSimple with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void initForMenu(Context context, MenuBuilder menu) {
    super.initForMenu(context, menu);

    final Resources res = context.getResources();

    if (!mReserveOverflowSet) {
        mReserveOverflow = reserveOverflow(mContext);
    }

    if (!mWidthLimitSet) {
        mWidthLimit = res.getDisplayMetrics().widthPixels / 2;
    }

    // Measure for initial configuration
    if (!mMaxItemsSet) {
        mMaxItems = getResources_getInteger(context, R.integer.abs__max_action_buttons);
    }

    int width = mWidthLimit;
    if (mReserveOverflow) {
        if (mOverflowButton == null) {
            mOverflowButton = new OverflowMenuButton(mSystemContext);
            final int spec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
            mOverflowButton.measure(spec, spec);
        }
        width -= mOverflowButton.getMeasuredWidth();
    } else {
        mOverflowButton = null;
    }

    mActionItemWidthLimit = width;

    mMinCellSize = (int) (ActionMenuView.MIN_CELL_SIZE * res.getDisplayMetrics().density);

    // Drop a scrap view as it may no longer reflect the proper context/config.
    mScrapActionButtonView = null;
}
 
Example #25
Source File: ViewFlow.java    From NewXmPluginSDK with Apache License 2.0 5 votes vote down vote up
@Override protected void onSizeChanged(int w, int h, int oldw, int oldh) {
	super.onSizeChanged(w, h, oldw, oldh);

	final int count = getChildCount();
	for (int i = 0; i < count ; ++i) {
		final View child = getChildAt(i);
		child.measure(MeasureSpec.makeMeasureSpec(getChildWidth(), MeasureSpec.EXACTLY),
				MeasureSpec.makeMeasureSpec(getChildHeight(), MeasureSpec.EXACTLY));
	}

	if (mFirstLayout) {
		mScroller.startScroll(0, 0, mCurrentScreen * getChildWidth(), 0, 0);
		mFirstLayout = false;
	}
}
 
Example #26
Source File: ActionMenuPresenter.java    From zen4android with MIT License 5 votes vote down vote up
@Override
public void initForMenu(Context context, MenuBuilder menu) {
    super.initForMenu(context, menu);

    final Resources res = context.getResources();

    if (!mReserveOverflowSet) {
        mReserveOverflow = reserveOverflow(mContext);
    }

    if (!mWidthLimitSet) {
        mWidthLimit = res.getDisplayMetrics().widthPixels / 2;
    }

    // Measure for initial configuration
    if (!mMaxItemsSet) {
        mMaxItems = getResources_getInteger(context, R.integer.abs__max_action_buttons);
    }

    int width = mWidthLimit;
    if (mReserveOverflow) {
        if (mOverflowButton == null) {
            mOverflowButton = new OverflowMenuButton(mSystemContext);
            final int spec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
            mOverflowButton.measure(spec, spec);
        }
        width -= mOverflowButton.getMeasuredWidth();
    } else {
        mOverflowButton = null;
    }

    mActionItemWidthLimit = width;

    mMinCellSize = (int) (ActionMenuView.MIN_CELL_SIZE * res.getDisplayMetrics().density);

    // Drop a scrap view as it may no longer reflect the proper context/config.
    mScrapActionButtonView = null;
}
 
Example #27
Source File: FillResolutionPolicy.java    From tilt-game-android with MIT License 5 votes vote down vote up
@Override
public void onMeasure(final IResolutionPolicy.Callback pResolutionPolicyCallback, final int pWidthMeasureSpec, final int pHeightMeasureSpec) {
	BaseResolutionPolicy.throwOnNotMeasureSpecEXACTLY(pWidthMeasureSpec, pHeightMeasureSpec);

	final int measuredWidth = MeasureSpec.getSize(pWidthMeasureSpec);
	final int measuredHeight = MeasureSpec.getSize(pHeightMeasureSpec);

	pResolutionPolicyCallback.onResolutionChanged(measuredWidth, measuredHeight);
}
 
Example #28
Source File: UIImplementation.java    From react-native-GPay with MIT License 5 votes vote down vote up
/**
 * Updates the styles of the {@link ReactShadowNode} based on the Measure specs received by
 * parameters.
 */
public void updateRootView(
    ReactShadowNode rootCSSNode, int widthMeasureSpec, int heightMeasureSpec) {
  int widthMode = MeasureSpec.getMode(widthMeasureSpec);
  int widthSize = MeasureSpec.getSize(widthMeasureSpec);
  switch (widthMode) {
    case EXACTLY:
      rootCSSNode.setStyleWidth(widthSize);
      break;
    case AT_MOST:
      rootCSSNode.setStyleMaxWidth(widthSize);
      break;
    case UNSPECIFIED:
      rootCSSNode.setStyleWidthAuto();
      break;
  }

  int heightMode = MeasureSpec.getMode(heightMeasureSpec);
  int heightSize = MeasureSpec.getSize(heightMeasureSpec);
  switch (heightMode) {
    case EXACTLY:
      rootCSSNode.setStyleHeight(heightSize);
      break;
    case AT_MOST:
      rootCSSNode.setStyleMaxHeight(heightSize);
      break;
    case UNSPECIFIED:
      rootCSSNode.setStyleHeightAuto();
      break;
  }
}
 
Example #29
Source File: GridLayoutManager.java    From letv with Apache License 2.0 5 votes vote down vote up
private int updateSpecWithExtra(int spec, int startInset, int endInset) {
    if (startInset == 0 && endInset == 0) {
        return spec;
    }
    int mode = MeasureSpec.getMode(spec);
    if (mode == Integer.MIN_VALUE || mode == 1073741824) {
        return MeasureSpec.makeMeasureSpec(Math.max(0, (MeasureSpec.getSize(spec) - startInset) - endInset), mode);
    }
    return spec;
}
 
Example #30
Source File: GridLayout.java    From Virtualview-Android with MIT License 5 votes vote down vote up
private int getRealHeight(int mode, int size) {
    int ret = size;

    switch (mode) {
        case View.MeasureSpec.AT_MOST:
        case View.MeasureSpec.UNSPECIFIED: {
            int h = 0;
            if (mSubViews.size() > 0) {
                int count = mSubViews.size();
                int row = count / mColCount + ((count % mColCount) > 0 ? 1 : 0);
                if (mItemHeight > 0) {
                    h = row * mItemHeight + mPaddingTop + mPaddingBottom + (row - 1) * mItemVerticalMargin;
                } else {
                    h = row * (mSubViews.get(0).getComMeasuredHeight()) + mPaddingTop + mPaddingBottom + (row - 1) * mItemVerticalMargin;
                }
            }

            if (View.MeasureSpec.AT_MOST == mode) {
                ret = Math.min(size, h);
            } else {
                ret = h;
            }
            break;
        }
    }

    return ret;
}