blob: 20ad187e3eb4ddf361494ea434116d6e7f5919ac [file] [log] [blame]
Sascha Haeberlinge3dfd5a2014-08-05 15:54:42 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.camera.util;
18
Paul Rohde01d56032014-12-18 11:45:34 -080019import android.annotation.TargetApi;
Sascha Haeberlingf2627902014-09-02 14:20:57 -070020import android.graphics.Point;
Paul Rohde01d56032014-12-18 11:45:34 -080021import android.os.Build.VERSION_CODES;
Sascha Haeberlingf2627902014-09-02 14:20:57 -070022
23import java.util.ArrayList;
24import java.util.List;
25
Sascha Haeberlinge3dfd5a2014-08-05 15:54:42 -070026/**
27 * Simple size class until we are 'L' only and can use android.util.Size.
28 */
29public class Size {
30 private final int width;
31 private final int height;
32
Paul Rohde01d56032014-12-18 11:45:34 -080033 @TargetApi(VERSION_CODES.L)
Sascha Haeberlinge3dfd5a2014-08-05 15:54:42 -070034 public static Size[] convert(android.util.Size[] sizes) {
35 Size[] converted = new Size[sizes.length];
36 for (int i = 0; i < sizes.length; ++i) {
37 converted[i] = new Size(sizes[i].getWidth(), sizes[i].getHeight());
38 }
39 return converted;
40 }
41
Sascha Haeberlingf2627902014-09-02 14:20:57 -070042 public static List<Size> convert(List<com.android.ex.camera2.portability.Size> sizes) {
43 ArrayList<Size> converted = new ArrayList<>(sizes.size());
44 for (com.android.ex.camera2.portability.Size size : sizes) {
45 converted.add(new Size(size.width(), size.height()));
46 }
47 return converted;
48 }
49
50 public Size(Point point) {
51 this.width = point.x;
52 this.height = point.y;
53 }
54
Paul Rohde01d56032014-12-18 11:45:34 -080055 @TargetApi(VERSION_CODES.L)
Sascha Haeberlinge3dfd5a2014-08-05 15:54:42 -070056 public Size(android.util.Size size) {
57 this.width = size.getWidth();
58 this.height = size.getHeight();
59 }
60
61 public Size(int width, int height) {
62 this.width = width;
63 this.height = height;
64 }
65
66 public int getWidth() {
67 return width;
68 }
69
70 public int getHeight() {
71 return height;
72 }
73
74 @Override
75 public String toString() {
76 return width + " x " + height;
77 }
78
79 @Override
80 public boolean equals(Object other) {
81 if (!(other instanceof Size)) {
82 return false;
83 }
84
85 Size otherSize = (Size) other;
86 return otherSize.width == this.width && otherSize.height == this.height;
87 }
88}