Java Code Examples for android.view.View.MeasureSpec#getSize()

The following examples show how to use android.view.View.MeasureSpec#getSize() . 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: RootHostDelegate.java    From litho with Apache License 2.0 6 votes vote down vote up
/**
 * Returns true if the delegate has defined a size and filled the measureOutput array, returns
 * false if not in which case the hosting view should call super.onMeasure.
 */
public boolean onMeasure(int widthMeasureSpec, int heightMeasureSpec, int[] measureOutput) {
  int width = MeasureSpec.getSize(widthMeasureSpec);
  int height = MeasureSpec.getSize(heightMeasureSpec);
  if (MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.EXACTLY
      && MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.EXACTLY) {
    // If the measurements are exact, postpone LayoutState calculation from measure to layout.
    // This is part of the fix for android's double measure bug. Doing this means that if we get
    // remeasured with different exact measurements, we don't compute two layouts.
    mDoMeasureInLayout = true;
    measureOutput[0] = width;
    measureOutput[1] = height;
    return true;
  }

  if (mRenderState != null) {
    mRenderState.measure(widthMeasureSpec, heightMeasureSpec, measureOutput);
    mDoMeasureInLayout = false;
    return true;
  }

  return false;
}
 
Example 2
Source File: PagerTitleStrip.java    From letv with Apache License 2.0 6 votes vote down vote up
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    if (MeasureSpec.getMode(widthMeasureSpec) != 1073741824) {
        throw new IllegalStateException("Must measure with an exact width");
    }
    int height;
    int heightPadding = getPaddingTop() + getPaddingBottom();
    int childHeightSpec = getChildMeasureSpec(heightMeasureSpec, heightPadding, -2);
    int widthSize = MeasureSpec.getSize(widthMeasureSpec);
    int childWidthSpec = getChildMeasureSpec(widthMeasureSpec, (int) (((float) widthSize) * 0.2f), -2);
    this.mPrevText.measure(childWidthSpec, childHeightSpec);
    this.mCurrText.measure(childWidthSpec, childHeightSpec);
    this.mNextText.measure(childWidthSpec, childHeightSpec);
    if (MeasureSpec.getMode(heightMeasureSpec) == 1073741824) {
        height = MeasureSpec.getSize(heightMeasureSpec);
    } else {
        height = Math.max(getMinHeight(), this.mCurrText.getMeasuredHeight() + heightPadding);
    }
    setMeasuredDimension(widthSize, ViewCompat.resolveSizeAndState(height, heightMeasureSpec, ViewCompat.getMeasuredState(this.mCurrText) << 16));
}
 
Example 3
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 4
Source File: X8TabItem.java    From FimiX8-RE with MIT License 6 votes vote down vote up
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int i;
    int modeWidth = MeasureSpec.getMode(widthMeasureSpec);
    int modeHeight = MeasureSpec.getMode(heightMeasureSpec);
    int sizeWidth = MeasureSpec.getSize(widthMeasureSpec);
    int sizeHeight = MeasureSpec.getSize(heightMeasureSpec);
    if (modeWidth != NTLMConstants.FLAG_NEGOTIATE_KEY_EXCHANGE && this.tabWidth > -1) {
        for (i = 0; i < getChildCount(); i++) {
            ((LayoutParams) ((TextView) getChildAt(i)).getLayoutParams()).width = this.tabWidth;
        }
    }
    if (modeHeight != NTLMConstants.FLAG_NEGOTIATE_KEY_EXCHANGE && this.tabHeight > -1) {
        for (i = 0; i < getChildCount(); i++) {
            ((LayoutParams) ((TextView) getChildAt(i)).getLayoutParams()).height = this.tabHeight;
        }
    }
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
 
Example 5
Source File: PiewController.java    From quickmark with MIT License 5 votes vote down vote up
public static 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 6
Source File: VideoViewH264mp4.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 7
Source File: PercentLayoutHelper.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public void adjustChildren(int widthMeasureSpec, int heightMeasureSpec) {
    if (Log.isLoggable(TAG, 3)) {
        Log.d(TAG, "adjustChildren: " + this.mHost + " widthMeasureSpec: " + MeasureSpec.toString(widthMeasureSpec) + " heightMeasureSpec: " + MeasureSpec.toString(heightMeasureSpec));
    }
    int widthHint = MeasureSpec.getSize(widthMeasureSpec);
    int heightHint = MeasureSpec.getSize(heightMeasureSpec);
    if (Log.isLoggable(TAG, 3)) {
        Log.d(TAG, "widthHint = " + widthHint + " , heightHint = " + heightHint);
    }
    int N = this.mHost.getChildCount();
    for (int i = 0; i < N; i++) {
        View view = this.mHost.getChildAt(i);
        LayoutParams params = view.getLayoutParams();
        if (Log.isLoggable(TAG, 3)) {
            Log.d(TAG, "should adjust " + view + " " + params);
        }
        if (params instanceof PercentLayoutParams) {
            PercentLayoutInfo info = ((PercentLayoutParams) params).getPercentLayoutInfo();
            if (Log.isLoggable(TAG, 3)) {
                Log.d(TAG, "using " + info);
            }
            if (info != null) {
                supportTextSize(widthHint, heightHint, view, info);
                supportPadding(widthHint, heightHint, view, info);
                supportMinOrMaxDimesion(widthHint, heightHint, view, info);
                if (params instanceof MarginLayoutParams) {
                    info.fillMarginLayoutParams((MarginLayoutParams) params, widthHint, heightHint);
                } else {
                    info.fillLayoutParams(params, widthHint, heightHint);
                }
            }
        }
    }
}
 
Example 8
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 9
Source File: VideoViewH264LeMobile_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 10
Source File: X8MapPointMarkerViewGroup.java    From FimiX8-RE with MIT License 5 votes vote down vote up
private int measureHeight(int measureSpec, int height) {
    int mode = MeasureSpec.getMode(measureSpec);
    int size = MeasureSpec.getSize(measureSpec);
    if (mode == NTLMConstants.FLAG_NEGOTIATE_KEY_EXCHANGE) {
        return size;
    }
    int result = height;
    if (mode == Integer.MIN_VALUE) {
        return Math.min(result, size);
    }
    return result;
}
 
Example 11
Source File: X8BatteryReturnLandingView.java    From FimiX8-RE with MIT License 5 votes vote down vote up
private int measureHeight(int measureSpec, int height) {
    int mode = MeasureSpec.getMode(measureSpec);
    int size = MeasureSpec.getSize(measureSpec);
    if (mode == NTLMConstants.FLAG_NEGOTIATE_KEY_EXCHANGE) {
        return size;
    }
    int result = height;
    if (mode == Integer.MIN_VALUE) {
        return Math.min(result, size);
    }
    return result;
}
 
Example 12
Source File: AwLayoutSizer.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Calculate the size of the view.
 * This is designed to be used to implement the android.view.View#onMeasure() method.
 */
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int heightMode = MeasureSpec.getMode(heightMeasureSpec);
    int heightSize = MeasureSpec.getSize(heightMeasureSpec);
    int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    int widthSize = MeasureSpec.getSize(widthMeasureSpec);

    int contentHeightPix = (int) (mContentHeightCss * mPageScaleFactor * mDIPScale);
    int contentWidthPix = (int) (mContentWidthCss * mPageScaleFactor * mDIPScale);

    int measuredHeight = contentHeightPix;
    int measuredWidth = contentWidthPix;

    mLastMeasuredPageScaleFactor = mPageScaleFactor;

    // Always use the given size unless unspecified. This matches WebViewClassic behavior.
    mWidthMeasurementIsFixed = (widthMode != MeasureSpec.UNSPECIFIED);
    mHeightMeasurementIsFixed = (heightMode == MeasureSpec.EXACTLY);
    mHeightMeasurementLimited =
        (heightMode == MeasureSpec.AT_MOST) && (contentHeightPix > heightSize);
    mHeightMeasurementLimit = heightSize;

    if (mHeightMeasurementIsFixed || mHeightMeasurementLimited) {
        measuredHeight = heightSize;
    }

    if (mWidthMeasurementIsFixed) {
        measuredWidth = widthSize;
    }

    if (measuredHeight < contentHeightPix) {
        measuredHeight |= View.MEASURED_STATE_TOO_SMALL;
    }

    if (measuredWidth < contentWidthPix) {
        measuredWidth |= View.MEASURED_STATE_TOO_SMALL;
    }

    mDelegate.setMeasuredDimension(measuredWidth, measuredHeight);
}
 
Example 13
Source File: VideoViewH264m3u8_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 14
Source File: LabelsView.java    From FimiX8-RE with MIT License 5 votes vote down vote up
private int measureHeight(int measureSpec, int contentHeight) {
    int result;
    int specMode = MeasureSpec.getMode(measureSpec);
    int specSize = MeasureSpec.getSize(measureSpec);
    if (specMode == NTLMConstants.FLAG_NEGOTIATE_KEY_EXCHANGE) {
        result = specSize;
    } else {
        result = (getPaddingTop() + contentHeight) + getPaddingBottom();
        if (specMode == Integer.MIN_VALUE) {
            result = Math.min(result, specSize);
        }
    }
    return Math.max(result, getSuggestedMinimumHeight());
}
 
Example 15
Source File: LabelsView.java    From FimiX8-RE with MIT License 5 votes vote down vote up
private int measureWidth(int measureSpec, int contentWidth) {
    int result;
    int specMode = MeasureSpec.getMode(measureSpec);
    int specSize = MeasureSpec.getSize(measureSpec);
    if (specMode == NTLMConstants.FLAG_NEGOTIATE_KEY_EXCHANGE) {
        result = specSize;
    } else {
        result = (getPaddingLeft() + contentWidth) + getPaddingRight();
        if (specMode == Integer.MIN_VALUE) {
            result = Math.min(result, specSize);
        }
    }
    return Math.max(result, getSuggestedMinimumWidth());
}
 
Example 16
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 17
Source File: DragSortItemView.java    From DongWeather with Apache License 2.0 5 votes vote down vote up
/**
 * 
 */
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    
    int height = MeasureSpec.getSize(heightMeasureSpec);
    int width = MeasureSpec.getSize(widthMeasureSpec);

    int heightMode = MeasureSpec.getMode(heightMeasureSpec);

    final View child = getChildAt(0);
    if (child == null) {
        setMeasuredDimension(0, width);
        return;
    }

    if (child.isLayoutRequested()) {
        // Always let child be as tall as it wants.
        measureChild(child, widthMeasureSpec,
                MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    }

    if (heightMode == MeasureSpec.UNSPECIFIED) {
        ViewGroup.LayoutParams lp = getLayoutParams();

        if (lp.height > 0) {
            height = lp.height;
        } else {
            height = child.getMeasuredHeight();
        }
    }

    setMeasuredDimension(width, height);
}
 
Example 18
Source File: DragSortItemView.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 
 */
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    
    int height = MeasureSpec.getSize(heightMeasureSpec);
    int width = MeasureSpec.getSize(widthMeasureSpec);

    int heightMode = MeasureSpec.getMode(heightMeasureSpec);

    final View child = getChildAt(0);
    if (child == null) {
        setMeasuredDimension(0, width);
        return;
    }

    if (child.isLayoutRequested()) {
        // Always let child be as tall as it wants.
        measureChild(child, widthMeasureSpec,
                MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    }

    if (heightMode == MeasureSpec.UNSPECIFIED) {
        ViewGroup.LayoutParams lp = getLayoutParams();

        if (lp.height > 0) {
            height = lp.height;
        } else {
            height = child.getMeasuredHeight();
        }
    }

    setMeasuredDimension(width, height);
}
 
Example 19
Source File: X8MapVideoCardView.java    From FimiX8-RE with MIT License 4 votes vote down vote up
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int w_size = MeasureSpec.getSize(widthMeasureSpec);
    int h_size = MeasureSpec.getSize(heightMeasureSpec);
    measureChildren(widthMeasureSpec, heightMeasureSpec);
    setMeasuredDimension(w_size, h_size);
}
 
Example 20
Source File: LinearLayoutSoftKeyboardDetect.java    From CordovaYoutubeVideoPlayer with MIT License 4 votes vote down vote up
@Override
/**
 * Start listening to new measurement events.  Fire events when the height
 * gets smaller fire a show keyboard event and when height gets bigger fire
 * a hide keyboard event.
 *
 * Note: We are using app.postMessage so that this is more compatible with the API
 *
 * @param widthMeasureSpec
 * @param heightMeasureSpec
 */
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    LOG.v(TAG, "We are in our onMeasure method");

    // Get the current height of the visible part of the screen.
    // This height will not included the status bar.\
    int width, height;

    height = MeasureSpec.getSize(heightMeasureSpec);
    width = MeasureSpec.getSize(widthMeasureSpec);
    LOG.v(TAG, "Old Height = %d", oldHeight);
    LOG.v(TAG, "Height = %d", height);
    LOG.v(TAG, "Old Width = %d", oldWidth);
    LOG.v(TAG, "Width = %d", width);

    // If the oldHeight = 0 then this is the first measure event as the app starts up.
    // If oldHeight == height then we got a measurement change that doesn't affect us.
    if (oldHeight == 0 || oldHeight == height) {
        LOG.d(TAG, "Ignore this event");
    }
    // Account for orientation change and ignore this event/Fire orientation change
    else if (screenHeight == width)
    {
        int tmp_var = screenHeight;
        screenHeight = screenWidth;
        screenWidth = tmp_var;
        LOG.v(TAG, "Orientation Change");
    }
    // If the height as gotten bigger then we will assume the soft keyboard has
    // gone away.
    else if (height > oldHeight) {
        if (app != null)
            app.appView.sendJavascript("cordova.fireDocumentEvent('hidekeyboard');");
    }
    // If the height as gotten smaller then we will assume the soft keyboard has 
    // been displayed.
    else if (height < oldHeight) {
        if (app != null)
            app.appView.sendJavascript("cordova.fireDocumentEvent('showkeyboard');");
    }

    // Update the old height for the next event
    oldHeight = height;
    oldWidth = width;
}