• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
17 package com.android.camera.util;
18 
19 import android.graphics.Point;
20 
21 import java.util.ArrayList;
22 import java.util.List;
23 
24 /**
25  * Simple size class until we are 'L' only and can use android.util.Size.
26  */
27 public class Size {
28     private final int width;
29     private final int height;
30 
convert(android.util.Size[] sizes)31     public static Size[] convert(android.util.Size[] sizes) {
32         Size[] converted = new Size[sizes.length];
33         for (int i = 0; i < sizes.length; ++i) {
34             converted[i] = new Size(sizes[i].getWidth(), sizes[i].getHeight());
35         }
36         return converted;
37     }
38 
convert(List<com.android.ex.camera2.portability.Size> sizes)39     public static List<Size> convert(List<com.android.ex.camera2.portability.Size> sizes) {
40         ArrayList<Size> converted = new ArrayList<>(sizes.size());
41         for (com.android.ex.camera2.portability.Size size : sizes) {
42             converted.add(new Size(size.width(), size.height()));
43         }
44         return converted;
45     }
46 
Size(Point point)47     public Size(Point point) {
48         this.width = point.x;
49         this.height = point.y;
50     }
51 
Size(android.util.Size size)52     public Size(android.util.Size size) {
53         this.width = size.getWidth();
54         this.height = size.getHeight();
55     }
56 
Size(int width, int height)57     public Size(int width, int height) {
58         this.width = width;
59         this.height = height;
60     }
61 
getWidth()62     public int getWidth() {
63         return width;
64     }
65 
getHeight()66     public int getHeight() {
67         return height;
68     }
69 
70     @Override
toString()71     public String toString() {
72         return width + " x " + height;
73     }
74 
75     @Override
equals(Object other)76     public boolean equals(Object other) {
77         if (!(other instanceof Size)) {
78             return false;
79         }
80 
81         Size otherSize = (Size) other;
82         return otherSize.width == this.width && otherSize.height == this.height;
83     }
84 }
85