Java Code Examples for io.vov.vitamio.utils.ScreenResolution

The following examples show how to use io.vov.vitamio.utils.ScreenResolution. These examples are extracted from open source projects. 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 Project: BambooPlayer   Source File: VideoView.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Set the display options
 *
 * @param layout      <ul>
 *                    <li>{@link #VIDEO_LAYOUT_ORIGIN}
 *                    <li>{@link #VIDEO_LAYOUT_SCALE}
 *                    <li>{@link #VIDEO_LAYOUT_STRETCH}
 *                    <li>{@link #VIDEO_LAYOUT_ZOOM}
 *                    </ul>
 * @param aspectRatio video aspect ratio, will audo detect if 0.
 */
public void setVideoLayout(int layout, float aspectRatio) {
  LayoutParams lp = getLayoutParams();
  Pair<Integer, Integer> res = ScreenResolution.getResolution(mContext);
  int windowWidth = res.first.intValue(), windowHeight = res.second.intValue();
  float windowRatio = windowWidth / (float) windowHeight;
  float videoRatio = aspectRatio <= 0.01f ? mVideoAspectRatio : aspectRatio;
  mSurfaceHeight = mVideoHeight;
  mSurfaceWidth = mVideoWidth;
  if (VIDEO_LAYOUT_ORIGIN == layout && mSurfaceWidth < windowWidth && mSurfaceHeight < windowHeight) {
    lp.width = (int) (mSurfaceHeight * videoRatio);
    lp.height = mSurfaceHeight;
  } else if (layout == VIDEO_LAYOUT_ZOOM) {
    lp.width = windowRatio > videoRatio ? windowWidth : (int) (videoRatio * windowHeight);
    lp.height = windowRatio < videoRatio ? windowHeight : (int) (windowWidth / videoRatio);
  } else {
    boolean full = layout == VIDEO_LAYOUT_STRETCH;
    lp.width = (full || windowRatio < videoRatio) ? windowWidth : (int) (videoRatio * windowHeight);
    lp.height = (full || windowRatio > videoRatio) ? windowHeight : (int) (windowWidth / videoRatio);
  }
  setLayoutParams(lp);
  getHolder().setFixedSize(mSurfaceWidth, mSurfaceHeight);
  Log.d("VIDEO: %dx%dx%f, Surface: %dx%d, LP: %dx%d, Window: %dx%dx%f", mVideoWidth, mVideoHeight, mVideoAspectRatio, mSurfaceWidth, mSurfaceHeight, lp.width, lp.height, windowWidth, windowHeight, windowRatio);
  mVideoLayout = layout;
  mAspectRatio = aspectRatio;
}
 
Example 2
Source Project: MyHearts   Source File: VideoView.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Set the display options
 *
 * @param layout      <ul>
 *                    <li>{@link #VIDEO_LAYOUT_ORIGIN}
 *                    <li>{@link #VIDEO_LAYOUT_SCALE}
 *                    <li>{@link #VIDEO_LAYOUT_STRETCH}
 *                    <li>{@link #VIDEO_LAYOUT_FIT_PARENT}
 *                    <li>{@link #VIDEO_LAYOUT_ZOOM}
 *                    </ul>
 * @param aspectRatio video aspect ratio, will audo detect if 0.
 */
public void setVideoLayout(int layout, float aspectRatio) {
	LayoutParams lp = getLayoutParams();
	Pair<Integer, Integer> res = ScreenResolution.getResolution(mContext);
	int windowWidth = res.first.intValue(), windowHeight = res.second.intValue();
	float windowRatio = windowWidth / (float) windowHeight;
	float videoRatio = aspectRatio <= 0.01f ? mVideoAspectRatio : aspectRatio;
	mSurfaceHeight = mVideoHeight;
	mSurfaceWidth = mVideoWidth;
	if (VIDEO_LAYOUT_ORIGIN == layout && mSurfaceWidth < windowWidth && mSurfaceHeight < windowHeight) {
		lp.width = (int) (mSurfaceHeight * videoRatio);
		lp.height = mSurfaceHeight;
	} else if (layout == VIDEO_LAYOUT_ZOOM) {
		lp.width = windowRatio > videoRatio ? windowWidth : (int) (videoRatio * windowHeight);
		lp.height = windowRatio < videoRatio ? windowHeight : (int) (windowWidth / videoRatio);
	} else if (layout == VIDEO_LAYOUT_FIT_PARENT) {
		ViewGroup parent = (ViewGroup) getParent();
		float parentRatio = ((float) parent.getWidth()) / ((float) parent.getHeight());
		lp.width = (parentRatio < videoRatio) ? parent.getWidth() : Math.round(((float) parent.getHeight()) * videoRatio);
		lp.height = (parentRatio > videoRatio) ? parent.getHeight() : Math.round(((float) parent.getWidth()) / videoRatio);
	} else {
		boolean full = layout == VIDEO_LAYOUT_STRETCH;
		lp.width = (full || windowRatio < videoRatio) ? windowWidth : (int) (videoRatio * windowHeight);
		lp.height = (full || windowRatio > videoRatio) ? windowHeight : (int) (windowWidth / videoRatio);
	}
	setLayoutParams(lp);
	getHolder().setFixedSize(mSurfaceWidth, mSurfaceHeight);
   Log.d("VIDEO: %dx%dx%f, Surface: %dx%d, LP: %dx%d, Window: %dx%dx%f", mVideoWidth, mVideoHeight, mVideoAspectRatio, mSurfaceWidth, mSurfaceHeight, lp.width, lp.height, windowWidth, windowHeight, windowRatio);
   mVideoLayout = layout;
   mAspectRatio = aspectRatio;
 }
 
Example 3
Source Project: HPlayer   Source File: Utility.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 按 屏幕比例 缩放图片
 */
public static void resizeImageViewOnScreenSize(Context context, View view, int numColumns,
                                               int horizontalSpacing, int zoomX, int zoomY) {
    if (view == null) {
        return;
    }
    if (screenPair == null) {
        screenPair = ScreenResolution.getResolution(context);
    }
    android.view.ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
    layoutParams.width = screenPair.first / numColumns - horizontalSpacing * (numColumns - 1);
    layoutParams.height = layoutParams.width * zoomY / zoomX;
}
 
Example 4
Source Project: HPlayer   Source File: VideoView.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Set the display options
 *
 * @param layout      <ul>
 *                    <li>{@link #VIDEO_LAYOUT_ORIGIN}
 *                    <li>{@link #VIDEO_LAYOUT_SCALE}
 *                    <li>{@link #VIDEO_LAYOUT_STRETCH}
 *                    <li>{@link #VIDEO_LAYOUT_FIT_PARENT}
 *                    <li>{@link #VIDEO_LAYOUT_ZOOM}
 *                    </ul>
 * @param aspectRatio video aspect ratio, will audo detect if 0.
 */
public void setVideoLayout(int layout, float aspectRatio) {
	LayoutParams lp = getLayoutParams();
	Pair<Integer, Integer> res = ScreenResolution.getResolution(mContext);
	int windowWidth = res.first.intValue(), windowHeight = res.second.intValue();
	float windowRatio = windowWidth / (float) windowHeight;
	float videoRatio = aspectRatio <= 0.01f ? mVideoAspectRatio : aspectRatio;
	mSurfaceHeight = mVideoHeight;
	mSurfaceWidth = mVideoWidth;
	if (VIDEO_LAYOUT_ORIGIN == layout && mSurfaceWidth < windowWidth && mSurfaceHeight < windowHeight) {
		lp.width = (int) (mSurfaceHeight * videoRatio);
		lp.height = mSurfaceHeight;
	} else if (layout == VIDEO_LAYOUT_ZOOM) {
		lp.width = windowRatio > videoRatio ? windowWidth : (int) (videoRatio * windowHeight);
		lp.height = windowRatio < videoRatio ? windowHeight : (int) (windowWidth / videoRatio);
	} else if (layout == VIDEO_LAYOUT_FIT_PARENT) {
		ViewGroup parent = (ViewGroup) getParent();
		float parentRatio = ((float) parent.getWidth()) / ((float) parent.getHeight());
		lp.width = (parentRatio < videoRatio) ? parent.getWidth() : Math.round(((float) parent.getHeight()) * videoRatio);
		lp.height = (parentRatio > videoRatio) ? parent.getHeight() : Math.round(((float) parent.getWidth()) / videoRatio);
	} else {
		boolean full = layout == VIDEO_LAYOUT_STRETCH;
		lp.width = (full || windowRatio < videoRatio) ? windowWidth : (int) (videoRatio * windowHeight);
		lp.height = (full || windowRatio > videoRatio) ? windowHeight : (int) (windowWidth / videoRatio);
	}
	setLayoutParams(lp);
	getHolder().setFixedSize(mSurfaceWidth, mSurfaceHeight);
   Log.d("VIDEO: %dx%dx%f, Surface: %dx%d, LP: %dx%d, Window: %dx%dx%f", mVideoWidth, mVideoHeight, mVideoAspectRatio, mSurfaceWidth, mSurfaceHeight, lp.width, lp.height, windowWidth, windowHeight, windowRatio);
   mVideoLayout = layout;
   mAspectRatio = aspectRatio;
       // 初始化
       videoWidth = lp.width;
       videoHeight = lp.height;
       currentScale = 1f;
 }
 
Example 5
Source Project: video-player   Source File: VideoView.java    License: MIT License 5 votes vote down vote up
/**
 * Set the display options
 *
 * @param layout      <ul>
 *                    <li>{@link #VIDEO_LAYOUT_ORIGIN}
 *                    <li>{@link #VIDEO_LAYOUT_SCALE}
 *                    <li>{@link #VIDEO_LAYOUT_STRETCH}
 *                    <li>{@link #VIDEO_LAYOUT_FIT_PARENT}
 *                    <li>{@link #VIDEO_LAYOUT_ZOOM}
 *                    </ul>
 * @param aspectRatio video aspect ratio, will audo detect if 0.
 */
public void setVideoLayout(int layout, float aspectRatio) {
	LayoutParams lp = getLayoutParams();
	Pair<Integer, Integer> res = ScreenResolution.getResolution(mContext);
	int windowWidth = res.first.intValue(), windowHeight = res.second.intValue();
	float windowRatio = windowWidth / (float) windowHeight;
	float videoRatio = aspectRatio <= 0.01f ? mVideoAspectRatio : aspectRatio;
	mSurfaceHeight = mVideoHeight;
	mSurfaceWidth = mVideoWidth;
	if (VIDEO_LAYOUT_ORIGIN == layout && mSurfaceWidth < windowWidth && mSurfaceHeight < windowHeight) {
		lp.width = (int) (mSurfaceHeight * videoRatio);
		lp.height = mSurfaceHeight;
	} else if (layout == VIDEO_LAYOUT_ZOOM) {
		lp.width = windowRatio > videoRatio ? windowWidth : (int) (videoRatio * windowHeight);
		lp.height = windowRatio < videoRatio ? windowHeight : (int) (windowWidth / videoRatio);
	} else if (layout == VIDEO_LAYOUT_FIT_PARENT) {
		ViewGroup parent = (ViewGroup) getParent();
		float parentRatio = ((float) parent.getWidth()) / ((float) parent.getHeight());
		lp.width = (parentRatio < videoRatio) ? parent.getWidth() : Math.round(((float) parent.getHeight()) * videoRatio);
		lp.height = (parentRatio > videoRatio) ? parent.getHeight() : Math.round(((float) parent.getWidth()) / videoRatio);
	} else {
		boolean full = layout == VIDEO_LAYOUT_STRETCH;
		lp.width = (full || windowRatio < videoRatio) ? windowWidth : (int) (videoRatio * windowHeight);
		lp.height = (full || windowRatio > videoRatio) ? windowHeight : (int) (windowWidth / videoRatio);
	}
	setLayoutParams(lp);
	getHolder().setFixedSize(mSurfaceWidth, mSurfaceHeight);
   Log.d("VIDEO: %dx%dx%f, Surface: %dx%d, LP: %dx%d, Window: %dx%dx%f", mVideoWidth, mVideoHeight, mVideoAspectRatio, mSurfaceWidth, mSurfaceHeight, lp.width, lp.height, windowWidth, windowHeight, windowRatio);
   mVideoLayout = layout;
   mAspectRatio = aspectRatio;
 }
 
Example 6
Source Project: NetEasyNews   Source File: VideoView.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Set the display options
 *
 * @param layout      <ul>
 *                    <li>{@link #VIDEO_LAYOUT_ORIGIN}
 *                    <li>{@link #VIDEO_LAYOUT_SCALE}
 *                    <li>{@link #VIDEO_LAYOUT_STRETCH}
 *                    <li>{@link #VIDEO_LAYOUT_FIT_PARENT}
 *                    <li>{@link #VIDEO_LAYOUT_ZOOM}
 *                    </ul>
 * @param aspectRatio video aspect ratio, will audo detect if 0.
 */
public void setVideoLayout(int layout, float aspectRatio) {
	LayoutParams lp = getLayoutParams();
	Pair<Integer, Integer> res = ScreenResolution.getResolution(mContext);
	int windowWidth = res.first.intValue(), windowHeight = res.second.intValue();
	float windowRatio = windowWidth / (float) windowHeight;
	float videoRatio = aspectRatio <= 0.01f ? mVideoAspectRatio : aspectRatio;
	mSurfaceHeight = mVideoHeight;
	mSurfaceWidth = mVideoWidth;
	if (VIDEO_LAYOUT_ORIGIN == layout && mSurfaceWidth < windowWidth && mSurfaceHeight < windowHeight) {
		lp.width = (int) (mSurfaceHeight * videoRatio);
		lp.height = mSurfaceHeight;
	} else if (layout == VIDEO_LAYOUT_ZOOM) {
		lp.width = windowRatio > videoRatio ? windowWidth : (int) (videoRatio * windowHeight);
		lp.height = windowRatio < videoRatio ? windowHeight : (int) (windowWidth / videoRatio);
	} else if (layout == VIDEO_LAYOUT_FIT_PARENT) {
		ViewGroup parent = (ViewGroup) getParent();
		float parentRatio = ((float) parent.getWidth()) / ((float) parent.getHeight());
		lp.width = (parentRatio < videoRatio) ? parent.getWidth() : Math.round(((float) parent.getHeight()) * videoRatio);
		lp.height = (parentRatio > videoRatio) ? parent.getHeight() : Math.round(((float) parent.getWidth()) / videoRatio);
	} else {
		boolean full = layout == VIDEO_LAYOUT_STRETCH;
		lp.width = (full || windowRatio < videoRatio) ? windowWidth : (int) (videoRatio * windowHeight);
		lp.height = (full || windowRatio > videoRatio) ? windowHeight : (int) (windowWidth / videoRatio);
	}
	setLayoutParams(lp);
	getHolder().setFixedSize(mSurfaceWidth, mSurfaceHeight);
   Log.d("VIDEO: %dx%dx%f, Surface: %dx%d, LP: %dx%d, Window: %dx%dx%f", mVideoWidth, mVideoHeight, mVideoAspectRatio, mSurfaceWidth, mSurfaceHeight, lp.width, lp.height, windowWidth, windowHeight, windowRatio);
   mVideoLayout = layout;
   mAspectRatio = aspectRatio;
 }
 
Example 7
Source Project: react-native-android-vitamio   Source File: VideoView.java    License: MIT License 5 votes vote down vote up
/**
 * Set the display options
 *
 * @param layout      <ul>
 *                    <li>{@link #VIDEO_LAYOUT_ORIGIN}
 *                    <li>{@link #VIDEO_LAYOUT_SCALE}
 *                    <li>{@link #VIDEO_LAYOUT_STRETCH}
 *                    <li>{@link #VIDEO_LAYOUT_ZOOM}
 *                    <li>{@link #VIDEO_LAYOUT_FIT_PARENT}
 *                    </ul>
 * @param aspectRatio video aspect ratio, will audo detect if 0.
 */
public void setVideoLayout(int layout, float aspectRatio) {
  LayoutParams lp = getLayoutParams();
  Pair<Integer, Integer> res = ScreenResolution.getResolution(mContext);
  int windowWidth = res.first.intValue(), windowHeight = res.second.intValue();
  float windowRatio = windowWidth / (float) windowHeight;
  float videoRatio = aspectRatio <= 0.01f ? mVideoAspectRatio : aspectRatio;
  mSurfaceHeight = mVideoHeight;
  mSurfaceWidth = mVideoWidth;
  if (VIDEO_LAYOUT_ORIGIN == layout && mSurfaceWidth < windowWidth && mSurfaceHeight < windowHeight) {
    lp.width = (int) (mSurfaceHeight * videoRatio);
    lp.height = mSurfaceHeight;
  } else if (layout == VIDEO_LAYOUT_ZOOM) {
    lp.width = windowRatio > videoRatio ? windowWidth : (int) (videoRatio * windowHeight);
    lp.height = windowRatio < videoRatio ? windowHeight : (int) (windowWidth / videoRatio);
  } else if (layout == VIDEO_LAYOUT_FIT_PARENT) {
    ViewGroup parent = (ViewGroup) getParent();
    float parentRatio = ((float) parent.getWidth()) / ((float) parent.getHeight());
    lp.width = (parentRatio < videoRatio) ? parent.getWidth() : Math.round(((float) parent.getHeight()) * videoRatio);
    lp.height = (parentRatio > videoRatio) ? parent.getHeight() : Math.round(((float) parent.getWidth()) / videoRatio);
  } else {
    boolean full = layout == VIDEO_LAYOUT_STRETCH;
    lp.width = (full || windowRatio < videoRatio) ? windowWidth : (int) (videoRatio * windowHeight);
    lp.height = (full || windowRatio > videoRatio) ? windowHeight : (int) (windowWidth / videoRatio);
  }
  setLayoutParams(lp);
  getHolder().setFixedSize(mSurfaceWidth, mSurfaceHeight);
  Log.d("VIDEO: %dx%dx%f, Surface: %dx%d, LP: %dx%d, Window: %dx%dx%f", mVideoWidth, mVideoHeight, mVideoAspectRatio, mSurfaceWidth, mSurfaceHeight, lp.width, lp.height, windowWidth, windowHeight, windowRatio);
  mVideoLayout = layout;
  mAspectRatio = aspectRatio;
}
 
Example 8
Source Project: Vitamio   Source File: VideoView.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Set the display options
 *
 * @param layout      <ul>
 *                    <li>{@link #VIDEO_LAYOUT_ORIGIN}
 *                    <li>{@link #VIDEO_LAYOUT_SCALE}
 *                    <li>{@link #VIDEO_LAYOUT_STRETCH}
 *                    <li>{@link #VIDEO_LAYOUT_ZOOM}
 *                    <li>{@link #VIDEO_LAYOUT_FIT_PARENT}
 *                    </ul>
 * @param aspectRatio video aspect ratio, will audo detect if 0.
 */
public void setVideoLayout(int layout, float aspectRatio) {
  LayoutParams lp = getLayoutParams();
  Pair<Integer, Integer> res = ScreenResolution.getResolution(mContext);
  int windowWidth = res.first.intValue(), windowHeight = res.second.intValue();
  float windowRatio = windowWidth / (float) windowHeight;
  float videoRatio = aspectRatio <= 0.01f ? mVideoAspectRatio : aspectRatio;
  mSurfaceHeight = mVideoHeight;
  mSurfaceWidth = mVideoWidth;
  if (VIDEO_LAYOUT_ORIGIN == layout && mSurfaceWidth < windowWidth && mSurfaceHeight < windowHeight) {
    lp.width = (int) (mSurfaceHeight * videoRatio);
    lp.height = mSurfaceHeight;
  } else if (layout == VIDEO_LAYOUT_ZOOM) {
    lp.width = windowRatio > videoRatio ? windowWidth : (int) (videoRatio * windowHeight);
    lp.height = windowRatio < videoRatio ? windowHeight : (int) (windowWidth / videoRatio);
  } else if (layout == VIDEO_LAYOUT_FIT_PARENT) {
    ViewGroup parent = (ViewGroup) getParent();
    float parentRatio = ((float) parent.getWidth()) / ((float) parent.getHeight());
    lp.width = (parentRatio < videoRatio) ? parent.getWidth() : Math.round(((float) parent.getHeight()) * videoRatio);
    lp.height = (parentRatio > videoRatio) ? parent.getHeight() : Math.round(((float) parent.getWidth()) / videoRatio);
  } else {
    boolean full = layout == VIDEO_LAYOUT_STRETCH;
    lp.width = (full || windowRatio < videoRatio) ? windowWidth : (int) (videoRatio * windowHeight);
    lp.height = (full || windowRatio > videoRatio) ? windowHeight : (int) (windowWidth / videoRatio);
  }
  setLayoutParams(lp);
  getHolder().setFixedSize(mSurfaceWidth, mSurfaceHeight);
  Log.d("VIDEO: %dx%dx%f, Surface: %dx%d, LP: %dx%d, Window: %dx%dx%f", mVideoWidth, mVideoHeight, mVideoAspectRatio, mSurfaceWidth, mSurfaceHeight, lp.width, lp.height, windowWidth, windowHeight, windowRatio);
  mVideoLayout = layout;
  mAspectRatio = aspectRatio;
}
 
Example 9
Source Project: HPlayer   Source File: PlayerGesture.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 设置当前屏幕的宽(与方向有关)
 */
public void setScreenWidth(Context context) {
    Pair<Integer, Integer> screenPair = ScreenResolution.getResolution(context);
    width = screenPair.first;
}