private Size chooseVideoSize(Size[] choices){
  int sw=mTextureView.getWidth();
  int sh=mTextureView.getHeight();
  mPreviewSurfaceAspectRatio=(float)sw / sh;
  Log.i(TAG,"chooseVideoSize() for landscape:" + (mPreviewSurfaceAspectRatio > 1.f) + " aspect: "+ mPreviewSurfaceAspectRatio+ " : "+ Arrays.toString(choices));
  Size sizeToReturn=null;
  if (mPreviewSurfaceAspectRatio > 1.f) {
    for (    Size size : choices) {
      if (size.getHeight() == size.getWidth() * 9 / 16 && size.getHeight() <= 1080) {
        sizeToReturn=size;
      }
    }
    if (sizeToReturn == null)     sizeToReturn=choices[0];
    mVideoSizeAspectRatio=(float)sizeToReturn.getWidth() / sizeToReturn.getHeight();
  }
 else {
    ArrayList<Size> potentials=new ArrayList<>();
    for (    Size size : choices) {
      float aspect=(float)size.getHeight() / size.getWidth();
      if (aspect == mPreviewSurfaceAspectRatio)       potentials.add(size);
    }
    Log.i(TAG,"---potentials: " + potentials.size());
    if (potentials.size() > 0) {
      for (      Size potential : potentials)       if (potential.getHeight() == sw) {
        sizeToReturn=potential;
        break;
      }
      if (sizeToReturn == null)       Log.i(TAG,"---no perfect match, check for 'normal'");
      for (      Size potential : potentials)       if (potential.getHeight() == 1080 || potential.getHeight() == 720) {
        sizeToReturn=potential;
        break;
      }
      if (sizeToReturn == null)       Log.i(TAG,"---no 'normal' match, return largest ");
      if (sizeToReturn == null)       sizeToReturn=potentials.get(0);
    }
    if (sizeToReturn == null)     sizeToReturn=choices[0];
    mVideoSizeAspectRatio=(float)sizeToReturn.getHeight() / sizeToReturn.getWidth();
  }
  return sizeToReturn;
}

private Size chooseVideoSize ( Size [ ] choices ) { int sw = mTextureView . getWidth ( ) ; int sh = mTextureView . getHeight ( ) ; mPreviewSurfaceAspectRatio = ( float ) sw / sh ; Log . i ( TAG , "chooseVideoSize() for landscape:" + ( mPreviewSurfaceAspectRatio > 1.f ) + " aspect: " + mPreviewSurfaceAspectRatio + " : " + Arrays . toString ( choices ) ) ; Size sizeToReturn = null ; if ( mPreviewSurfaceAspectRatio > 1.f ) { for ( Size size : choices ) { if ( size . getHeight ( ) == size . getWidth ( ) * 9 / 16 && size . getHeight ( ) <= 1080 ) { sizeToReturn = size ; } } if ( sizeToReturn == null ) sizeToReturn = choices [ 0 ] ; mVideoSizeAspectRatio = ( float ) sizeToReturn . getWidth ( ) / sizeToReturn . getHeight ( ) ; } else { ArrayList < Size > potentials = new ArrayList < > ( ) ; for ( Size size : choices ) { float aspect = ( float ) size . getHeight ( ) / size . getWidth ( ) ; if ( aspect == mPreviewSurfaceAspectRatio ) potentials . add ( size ) ; } Log . i ( TAG , "---potentials: " + potentials . size ( ) ) ; if ( potentials . size ( ) > 0 ) { for ( Size potential : potentials ) if ( potential . getHeight ( ) == sw ) { sizeToReturn = potential ; break ; } if ( sizeToReturn == null ) Log . i ( TAG , "---no perfect match, check for 'normal'" ) ; for ( Size potential : potentials ) if ( potential . getHeight ( ) == 1080 || potential . getHeight ( ) == 720 ) { sizeToReturn = potential ; break ; } if ( sizeToReturn == null ) Log . i ( TAG , "---no 'normal' match, return largest " ) ; if ( sizeToReturn == null ) sizeToReturn = potentials . get ( 0 ) ; } if ( sizeToReturn == null ) sizeToReturn = choices [ 0 ] ; mVideoSizeAspectRatio = ( float ) sizeToReturn . getHeight ( ) / sizeToReturn . getWidth ( ) ; } return sizeToReturn ; }
choosevideosize makes a few assumptions for the sake of our use - case .
