Karthik Ravi Shankar | cdf9ce7 | 2017-04-12 15:31:20 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 android.app; |
| 18 | |
| 19 | import android.content.ComponentName; |
| 20 | import android.os.Parcel; |
| 21 | import android.os.Parcelable; |
| 22 | |
| 23 | import java.io.PrintWriter; |
| 24 | |
| 25 | /** |
| 26 | * Display properties to be used by VR mode when creating a virtual display. |
| 27 | * |
| 28 | * @hide |
| 29 | */ |
Karthik Ravi Shankar | 2b9aaed | 2017-05-01 01:34:19 -0700 | [diff] [blame] | 30 | public class Vr2dDisplayProperties implements Parcelable { |
Karthik Ravi Shankar | cdf9ce7 | 2017-04-12 15:31:20 -0700 | [diff] [blame] | 31 | |
| 32 | /** |
| 33 | * The actual width, height and dpi. |
| 34 | */ |
| 35 | private final int mWidth; |
| 36 | private final int mHeight; |
| 37 | private final int mDpi; |
| 38 | |
Karthik Ravi Shankar | 2b9aaed | 2017-05-01 01:34:19 -0700 | [diff] [blame] | 39 | public Vr2dDisplayProperties(int width, int height, int dpi) { |
Karthik Ravi Shankar | cdf9ce7 | 2017-04-12 15:31:20 -0700 | [diff] [blame] | 40 | mWidth = width; |
| 41 | mHeight = height; |
| 42 | mDpi = dpi; |
| 43 | } |
| 44 | |
| 45 | @Override |
| 46 | public int hashCode() { |
| 47 | int result = getWidth(); |
| 48 | result = 31 * result + getHeight(); |
| 49 | result = 31 * result + getDpi(); |
| 50 | return result; |
| 51 | } |
| 52 | |
| 53 | @Override |
| 54 | public String toString() { |
Karthik Ravi Shankar | 2b9aaed | 2017-05-01 01:34:19 -0700 | [diff] [blame] | 55 | return "Vr2dDisplayProperties{" + |
Karthik Ravi Shankar | cdf9ce7 | 2017-04-12 15:31:20 -0700 | [diff] [blame] | 56 | "mWidth=" + mWidth + |
| 57 | ", mHeight=" + mHeight + |
| 58 | ", mDpi=" + mDpi + |
| 59 | "}"; |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public boolean equals(Object o) { |
| 64 | if (this == o) return true; |
| 65 | if (o == null || getClass() != o.getClass()) return false; |
| 66 | |
Karthik Ravi Shankar | 2b9aaed | 2017-05-01 01:34:19 -0700 | [diff] [blame] | 67 | Vr2dDisplayProperties that = (Vr2dDisplayProperties) o; |
Karthik Ravi Shankar | cdf9ce7 | 2017-04-12 15:31:20 -0700 | [diff] [blame] | 68 | |
| 69 | if (getWidth() != that.getWidth()) return false; |
| 70 | if (getHeight() != that.getHeight()) return false; |
| 71 | return getDpi() == that.getDpi(); |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public int describeContents() { |
| 76 | return 0; |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | public void writeToParcel(Parcel dest, int flags) { |
| 81 | dest.writeInt(mWidth); |
| 82 | dest.writeInt(mHeight); |
| 83 | dest.writeInt(mDpi); |
| 84 | } |
| 85 | |
Karthik Ravi Shankar | 2b9aaed | 2017-05-01 01:34:19 -0700 | [diff] [blame] | 86 | public static final Parcelable.Creator<Vr2dDisplayProperties> CREATOR |
| 87 | = new Parcelable.Creator<Vr2dDisplayProperties>() { |
Karthik Ravi Shankar | cdf9ce7 | 2017-04-12 15:31:20 -0700 | [diff] [blame] | 88 | @Override |
Karthik Ravi Shankar | 2b9aaed | 2017-05-01 01:34:19 -0700 | [diff] [blame] | 89 | public Vr2dDisplayProperties createFromParcel(Parcel source) { |
| 90 | return new Vr2dDisplayProperties(source); |
Karthik Ravi Shankar | cdf9ce7 | 2017-04-12 15:31:20 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | @Override |
Karthik Ravi Shankar | 2b9aaed | 2017-05-01 01:34:19 -0700 | [diff] [blame] | 94 | public Vr2dDisplayProperties[] newArray(int size) { |
| 95 | return new Vr2dDisplayProperties[size]; |
Karthik Ravi Shankar | cdf9ce7 | 2017-04-12 15:31:20 -0700 | [diff] [blame] | 96 | } |
| 97 | }; |
| 98 | |
Karthik Ravi Shankar | 2b9aaed | 2017-05-01 01:34:19 -0700 | [diff] [blame] | 99 | private Vr2dDisplayProperties(Parcel source) { |
Karthik Ravi Shankar | cdf9ce7 | 2017-04-12 15:31:20 -0700 | [diff] [blame] | 100 | mWidth = source.readInt(); |
| 101 | mHeight = source.readInt(); |
| 102 | mDpi = source.readInt(); |
| 103 | } |
| 104 | |
| 105 | public void dump(PrintWriter pw, String prefix) { |
Karthik Ravi Shankar | 2b9aaed | 2017-05-01 01:34:19 -0700 | [diff] [blame] | 106 | pw.println(prefix + "Vr2dDisplayProperties:"); |
Karthik Ravi Shankar | cdf9ce7 | 2017-04-12 15:31:20 -0700 | [diff] [blame] | 107 | pw.println(prefix + " width=" + mWidth); |
| 108 | pw.println(prefix + " height=" + mHeight); |
| 109 | pw.println(prefix + " dpi=" + mDpi); |
| 110 | } |
| 111 | |
| 112 | public int getWidth() { |
| 113 | return mWidth; |
| 114 | } |
| 115 | |
| 116 | public int getHeight() { |
| 117 | return mHeight; |
| 118 | } |
| 119 | |
| 120 | public int getDpi() { |
| 121 | return mDpi; |
| 122 | } |
| 123 | } |