summaryrefslogtreecommitdiffstats
path: root/camera2/portability/src/com/android/ex/camera2/portability/Size.java
diff options
context:
space:
mode:
authorAngus Kong <shkong@google.com>2014-06-10 16:07:45 -0700
committerEd Heyl <edheyl@google.com>2014-06-18 10:24:46 -0700
commit8097973089420749dcd1ab4974a629c2466b31cc (patch)
treedede361c4237dde7ff9ab10511afac5cf2cd5ff1 /camera2/portability/src/com/android/ex/camera2/portability/Size.java
parentcef46862d6937bc98bf1a6b087c5daa22b5239f3 (diff)
downloadandroid_frameworks_ex-8097973089420749dcd1ab4974a629c2466b31cc.tar.gz
android_frameworks_ex-8097973089420749dcd1ab4974a629c2466b31cc.tar.bz2
android_frameworks_ex-8097973089420749dcd1ab4974a629c2466b31cc.zip
Refactor out Camera.Parameters.
Change-Id: Ibc1ddac509381530e887b7491069e6367e9a6088
Diffstat (limited to 'camera2/portability/src/com/android/ex/camera2/portability/Size.java')
-rw-r--r--camera2/portability/src/com/android/ex/camera2/portability/Size.java151
1 files changed, 151 insertions, 0 deletions
diff --git a/camera2/portability/src/com/android/ex/camera2/portability/Size.java b/camera2/portability/src/com/android/ex/camera2/portability/Size.java
new file mode 100644
index 0000000..9ae21aa
--- /dev/null
+++ b/camera2/portability/src/com/android/ex/camera2/portability/Size.java
@@ -0,0 +1,151 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.ex.camera2.portability;
+
+import android.graphics.Point;
+import android.hardware.Camera;
+import android.text.TextUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * An immutable simple size container.
+ */
+public class Size {
+ public static final String DELIMITER = ",";
+
+ /**
+ * An helper method to build a list of this class from a list of
+ * {@link android.hardware.Camera.Size}.
+ *
+ * @param cameraSizes Source.
+ * @return The built list.
+ */
+ public static List<Size> buildListFromCameraSizes(List<Camera.Size> cameraSizes) {
+ ArrayList<Size> list = new ArrayList<Size>(cameraSizes.size());
+ for (Camera.Size cameraSize : cameraSizes) {
+ list.add(new Size(cameraSize));
+ }
+ return list;
+ }
+
+ /**
+ * Encode List of this class as comma-separated list of integers.
+ *
+ * @param sizes List of this class to encode.
+ * @return encoded string.
+ */
+ public static String listToString(List<Size> sizes) {
+ ArrayList<Integer> flatSizes = new ArrayList<>();
+ for (Size s : sizes) {
+ flatSizes.add(s.width());
+ flatSizes.add(s.height());
+ }
+ return TextUtils.join(DELIMITER, flatSizes);
+ }
+
+ /**
+ * Decode comma-separated even-length list of integers into a List of this class.
+ *
+ * @param encodedSizes encoded string.
+ * @return List of this class.
+ */
+ public static List<Size> stringToList(String encodedSizes) {
+ String[] flatSizes = TextUtils.split(encodedSizes, DELIMITER);
+ ArrayList<Size> list = new ArrayList<>();
+ for (int i = 0; i < flatSizes.length; i += 2) {
+ int width = Integer.parseInt(flatSizes[i]);
+ int height = Integer.parseInt(flatSizes[i + 1]);
+ list.add(new Size(width,height));
+ }
+ return list;
+ }
+
+ private final Point val;
+
+ /**
+ * Constructor.
+ */
+ public Size(int width, int height) {
+ val = new Point(width, height);
+ }
+
+ /**
+ * Copy constructor.
+ */
+ public Size(Size other) {
+ if (other == null) {
+ val = new Point(0, 0);
+ } else {
+ val = new Point(other.width(), other.height());
+ }
+ }
+
+ /**
+ * Constructor from a source {@link android.hardware.Camera.Size}.
+ *
+ * @param other The source size.
+ */
+ public Size(Camera.Size other) {
+ if (other == null) {
+ val = new Point(0, 0);
+ } else {
+ val = new Point(other.width, other.height);
+ }
+ }
+
+ /**
+ * Constructor from a source {@link android.graphics.Point}.
+ *
+ * @param p The source size.
+ */
+ public Size(Point p) {
+ if (p == null) {
+ val = new Point(0, 0);
+ } else {
+ val = new Point(p);
+ }
+ }
+
+ public int width() {
+ return val.x;
+ }
+
+ public int height() {
+ return val.y;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o instanceof Size) {
+ Size other = (Size) o;
+ return val.equals(other.val);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return val.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return "Size: (" + this.width() + " x " + this.height() + ")";
+ }
+}