Example usage for android.util Size getWidth

List of usage examples for android.util Size getWidth

Introduction

In this page you can find the example usage for android.util Size getWidth.

Prototype

public int getWidth() 

Source Link

Document

Get the width of the size (in pixels).

Usage

From source file:Main.java

/**
 * Validate if a size is less than 1080p. Some devices
 * can't handle recording above that resolution.
 *///from   w  w w.ja  v  a 2  s . c  om
public static boolean verifyVideoSize(Size option) {
    return (option.getWidth() <= 1080);
}

From source file:Main.java

public static boolean isWide(Size size) {
    double ratio = ((double) size.getWidth()) / ((double) size.getHeight());
    return ratio > 1.68 && ratio < 1.87;
}

From source file:Main.java

@TargetApi(21)
public static Size chooseVideoSize(Size[] choices) {
    for (Size size : choices) {
        if (size.getWidth() == size.getHeight() * 4 / 3 && size.getWidth() <= 720) {
            return size;
        }/*  www.ja  v  a  2  s  .c  o m*/
    }
    return choices[choices.length - 1];
}

From source file:Main.java

public static Size getMaxSize(Size[] sizes) {
    if (sizes == null || sizes.length == 0) {
        throw new IllegalArgumentException("sizes was empty");
    }//from  w  w  w . ja va  2s.c om

    Size maxSize = sizes[0];
    for (int i = 1; i < sizes.length; i++) {
        if (sizes[i].getWidth() * sizes[i].getHeight() > maxSize.getWidth() * maxSize.getHeight()) {
            maxSize = sizes[i];
        }
    }

    return maxSize;
}

From source file:com.google.android.apps.watchme.StreamerActivity.java

private static Size chooseOptimalSize(Size[] choices, int width, int height) {
    List<Size> bigEnough = new ArrayList<Size>();
    for (Size option : choices) {
        if (option.getHeight() == option.getWidth() * height / width && option.getWidth() >= width
                && option.getHeight() >= height) {
            bigEnough.add(option);// w w  w.j a  v  a 2s .c o m
        }
    }
    if (bigEnough.size() > 0) {
        return Collections.min(bigEnough, new CompareSizeByArea());
    } else {
        return choices[0];
    }
}

From source file:org.odk.collect.android.fragments.Camera2VideoFragment.java

/**
 * In this sample, we choose a video size with 3x4 aspect ratio. Also, we don't use sizes
 * larger than 1080p, since MediaRecorder cannot handle such a high-resolution video.
 *
 * @param choices The list of available sizes
 * @return The video size//from   ww w  .j  a v  a2  s . c  o  m
 */
private static Size chooseVideoSize(Size[] choices) {
    for (Size size : choices) {
        if (size.getWidth() == size.getHeight() * 4 / 3 && size.getWidth() <= 1080) {
            return size;
        }
    }
    Timber.e("Couldn't find any suitable video size");
    return choices[choices.length - 1];
}

From source file:wisc.drivesense.vediorecorder.CameraFragment.java

/**
 * In this sample, we choose a video size with 3x4 aspect ratio. Also, we don't use sizes
 * larger than 1080p, since MediaRecorder cannot handle such a high-resolution video.
 *
 * @param choices The list of available sizes
 * @return The video size/*from  w w  w .  j a v a2s .c  o  m*/
 */
private static Size chooseVideoSize(Size[] choices) {
    for (Size size : choices) {
        //Log.d(TAG, String.valueOf(size.getWidth()) + "," + String.valueOf(size.getHeight()));
        if (size.getWidth() == size.getHeight() * 4 / 3 && size.getWidth() <= 1080) {
            return size;
        }
    }
    Log.e(TAG, "Couldn't find any suitable video size");
    return choices[choices.length - 1];
}

From source file:com.tzutalin.dlibtest.CameraConnectionFragment.java

/**
 * Given {@code choices} of {@code Size}s supported by a camera, chooses the smallest one whose
 * width and height are at least as large as the respective requested values, and whose aspect
 * ratio matches with the specified value.
 *
 * @param choices     The list of sizes that the camera supports for the intended output class
 * @param width       The minimum desired width
 * @param height      The minimum desired height
 * @param aspectRatio The aspect ratio// w w w  . j a  v a2s  .com
 * @return The optimal {@code Size}, or an arbitrary one if none were big enough
 */
@SuppressLint("LongLogTag")
@DebugLog
private static Size chooseOptimalSize(final Size[] choices, final int width, final int height,
        final Size aspectRatio) {
    // Collect the supported resolutions that are at least as big as the preview Surface
    final List<Size> bigEnough = new ArrayList<Size>();
    for (final Size option : choices) {
        if (option.getHeight() >= MINIMUM_PREVIEW_SIZE && option.getWidth() >= MINIMUM_PREVIEW_SIZE) {
            Timber.tag(TAG).i("Adding size: " + option.getWidth() + "x" + option.getHeight());
            bigEnough.add(option);
        } else {
            Timber.tag(TAG).i("Not adding size: " + option.getWidth() + "x" + option.getHeight());
        }
    }

    // Pick the smallest of those, assuming we found any
    if (bigEnough.size() > 0) {
        final Size chosenSize = Collections.min(bigEnough, new CompareSizesByArea());
        Timber.tag(TAG).i("Chosen size: " + chosenSize.getWidth() + "x" + chosenSize.getHeight());
        return chosenSize;
    } else {
        Timber.tag(TAG).e("Couldn't find any suitable preview size");
        return choices[0];
    }
}

From source file:com.android.camera2.its.ItsSerializer.java

@SuppressWarnings("unchecked")
private static Object serializeSize(Size size) throws org.json.JSONException {
    JSONObject sizeObj = new JSONObject();
    sizeObj.put("width", size.getWidth());
    sizeObj.put("height", size.getHeight());
    return sizeObj;
}

From source file:com.android.rahul.myselfieapp.Fragment.CamVideoFragment.java

/**
 * In this sample, we choose a video size with 3x4 aspect ratio. Also, we don't use sizes
 * larger than 1080p, since MediaRecorder cannot handle such a high-resolution video.
 *
 * @param choices The list of available sizes
 * @return The video size/*from   ww  w .  j  a  v  a 2s .  c  o  m*/
 */
private static Size chooseVideoSize(Size[] choices) {
    for (Size size : choices) {
        if (size.getWidth() == size.getHeight() * 4 / 3 && size.getWidth() <= 1080) {
            return size;
        }
    }
    Log.e(TAG, "Couldn't find any suitable video size");
    return choices[choices.length - 1];
}