package com.yydcdut.note.utils.camera.param; import android.hardware.Camera; /** * Created by yuyidong on 15/8/5. */ public class Size { public Size(int width, int height) { mWidth = width; mHeight = height; } public int getWidth() { return mWidth; } public int getHeight() { return mHeight; } @Override public boolean equals(final Object obj) { if (obj == null) { return false; } if (this == obj) { return true; } if (obj instanceof Size) { Size other = (Size) obj; return mWidth == other.mWidth && mHeight == other.mHeight; } return false; } @Override public String toString() { return mWidth + "x" + mHeight; } private static NumberFormatException invalidSize(String s) { throw new NumberFormatException("Invalid Size: \"" + s + "\""); } public static Size parseSize(String string) throws NumberFormatException { if (string == null) { throw new IllegalArgumentException("string must not be null"); } int sep_ix = string.indexOf('*'); if (sep_ix < 0) { sep_ix = string.indexOf('x'); } if (sep_ix < 0) { throw invalidSize(string); } try { return new Size(Integer.parseInt(string.substring(0, sep_ix)), Integer.parseInt(string.substring(sep_ix + 1))); } catch (NumberFormatException e) { throw invalidSize(string); } } public static Size parseSize(Camera.Size size) { if (size == null) { throw new IllegalArgumentException("size must not be null"); } return new Size(size.width, size.height); } @Override public int hashCode() { // assuming most sizes are <2^16, doing a rotate will give us perfect hashing return mHeight ^ ((mWidth << (Integer.SIZE / 2)) | (mWidth >>> (Integer.SIZE / 2))); } private final int mWidth; private final int mHeight; public static Size translate(int width, int height) { return new Size(width, height); } }