Java Code Examples for android.view.View.getDefaultSize()

The following are Jave code examples for showing how to use getDefaultSize() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: AppRTC-Android   File: RendererCommon.java   View Source Code Vote up 6 votes
public Point measure(int widthSpec, int heightSpec, int frameWidth, int frameHeight) {
  // Calculate max allowed layout size.
  final int maxWidth = View.getDefaultSize(Integer.MAX_VALUE, widthSpec);
  final int maxHeight = View.getDefaultSize(Integer.MAX_VALUE, heightSpec);
  if (frameWidth == 0 || frameHeight == 0 || maxWidth == 0 || maxHeight == 0) {
    return new Point(maxWidth, maxHeight);
  }
  // Calculate desired display size based on scaling type, video aspect ratio,
  // and maximum layout size.
  final float frameAspect = frameWidth / (float) frameHeight;
  final float displayAspect = maxWidth / (float) maxHeight;
  final ScalingType scalingType = (frameAspect > 1.0f) == (displayAspect > 1.0f)
      ? scalingTypeMatchOrientation
      : scalingTypeMismatchOrientation;
  final Point layoutSize = getDisplaySize(scalingType, frameAspect, maxWidth, maxHeight);

  // If the measure specification is forcing a specific size - yield.
  if (View.MeasureSpec.getMode(widthSpec) == View.MeasureSpec.EXACTLY) {
    layoutSize.x = maxWidth;
  }
  if (View.MeasureSpec.getMode(heightSpec) == View.MeasureSpec.EXACTLY) {
    layoutSize.y = maxHeight;
  }
  return layoutSize;
}
 
Example 2
Project: AndroidRTC   File: RendererCommon.java   View Source Code Vote up 6 votes
public Point measure(int widthSpec, int heightSpec, int frameWidth, int frameHeight) {
  // Calculate max allowed layout size.
  final int maxWidth = View.getDefaultSize(Integer.MAX_VALUE, widthSpec);
  final int maxHeight = View.getDefaultSize(Integer.MAX_VALUE, heightSpec);
  if (frameWidth == 0 || frameHeight == 0 || maxWidth == 0 || maxHeight == 0) {
    return new Point(maxWidth, maxHeight);
  }
  // Calculate desired display size based on scaling type, video aspect ratio,
  // and maximum layout size.
  final float frameAspect = frameWidth / (float) frameHeight;
  final float displayAspect = maxWidth / (float) maxHeight;
  final ScalingType scalingType = (frameAspect > 1.0f) == (displayAspect > 1.0f)
      ? scalingTypeMatchOrientation
      : scalingTypeMismatchOrientation;
  final Point layoutSize = getDisplaySize(scalingType, frameAspect, maxWidth, maxHeight);

  // If the measure specification is forcing a specific size - yield.
  if (View.MeasureSpec.getMode(widthSpec) == View.MeasureSpec.EXACTLY) {
    layoutSize.x = maxWidth;
  }
  if (View.MeasureSpec.getMode(heightSpec) == View.MeasureSpec.EXACTLY) {
    layoutSize.y = maxHeight;
  }
  return layoutSize;
}
 
Example 3
Project: VideoCRE   File: RendererCommon.java   View Source Code Vote up 6 votes
public Point measure(int widthSpec, int heightSpec, int frameWidth, int frameHeight) {
  // Calculate max allowed layout size.
  final int maxWidth = View.getDefaultSize(Integer.MAX_VALUE, widthSpec);
  final int maxHeight = View.getDefaultSize(Integer.MAX_VALUE, heightSpec);
  if (frameWidth == 0 || frameHeight == 0 || maxWidth == 0 || maxHeight == 0) {
    return new Point(maxWidth, maxHeight);
  }
  // Calculate desired display size based on scaling type, video aspect ratio,
  // and maximum layout size.
  final float frameAspect = frameWidth / (float) frameHeight;
  final float displayAspect = maxWidth / (float) maxHeight;
  final ScalingType scalingType = (frameAspect > 1.0f) == (displayAspect > 1.0f)
      ? scalingTypeMatchOrientation
      : scalingTypeMismatchOrientation;
  final Point layoutSize = getDisplaySize(scalingType, frameAspect, maxWidth, maxHeight);

  // If the measure specification is forcing a specific size - yield.
  if (View.MeasureSpec.getMode(widthSpec) == View.MeasureSpec.EXACTLY) {
    layoutSize.x = maxWidth;
  }
  if (View.MeasureSpec.getMode(heightSpec) == View.MeasureSpec.EXACTLY) {
    layoutSize.y = maxHeight;
  }
  return layoutSize;
}
 
Example 4
Project: BestPracticeApp   File: SimpleViewPager.java   View Source Code Vote up 5 votes
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int width = View.getDefaultSize(0, widthMeasureSpec);
    int height = View.getDefaultSize(0, heightMeasureSpec);
    setMeasuredDimension(width, height);

    int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        View childAt = getChildAt(i);
        int spec_w = MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY);
        int spec_h = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
        childAt.measure(spec_w, spec_h);
    }

}