Sascha Haeberling | e3dfd5a | 2014-08-05 15:54:42 -0700 | [diff] [blame] | 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 | |
Paul Rohde | 01d5603 | 2014-12-18 11:45:34 -0800 | [diff] [blame^] | 19 | import android.annotation.TargetApi; |
Sascha Haeberling | f262790 | 2014-09-02 14:20:57 -0700 | [diff] [blame] | 20 | import android.graphics.Point; |
Paul Rohde | 01d5603 | 2014-12-18 11:45:34 -0800 | [diff] [blame^] | 21 | import android.os.Build.VERSION_CODES; |
Sascha Haeberling | f262790 | 2014-09-02 14:20:57 -0700 | [diff] [blame] | 22 | |
| 23 | import java.util.ArrayList; |
| 24 | import java.util.List; |
| 25 | |
Sascha Haeberling | e3dfd5a | 2014-08-05 15:54:42 -0700 | [diff] [blame] | 26 | /** |
| 27 | * Simple size class until we are 'L' only and can use android.util.Size. |
| 28 | */ |
| 29 | public class Size { |
| 30 | private final int width; |
| 31 | private final int height; |
| 32 | |
Paul Rohde | 01d5603 | 2014-12-18 11:45:34 -0800 | [diff] [blame^] | 33 | @TargetApi(VERSION_CODES.L) |
Sascha Haeberling | e3dfd5a | 2014-08-05 15:54:42 -0700 | [diff] [blame] | 34 | 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 Haeberling | f262790 | 2014-09-02 14:20:57 -0700 | [diff] [blame] | 42 | 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 Rohde | 01d5603 | 2014-12-18 11:45:34 -0800 | [diff] [blame^] | 55 | @TargetApi(VERSION_CODES.L) |
Sascha Haeberling | e3dfd5a | 2014-08-05 15:54:42 -0700 | [diff] [blame] | 56 | 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 | } |