Jinsuk Kim | 78d695d | 2014-05-13 16:36:15 +0900 | [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 android.hardware.hdmi; |
| 18 | |
Jinsuk Kim | 66d1eb2 | 2014-06-06 16:12:18 +0900 | [diff] [blame] | 19 | import android.annotation.SystemApi; |
Jinsuk Kim | 78d695d | 2014-05-13 16:36:15 +0900 | [diff] [blame] | 20 | import android.os.Parcel; |
| 21 | import android.os.Parcelable; |
| 22 | |
| 23 | /** |
| 24 | * A class that describes the HDMI port hotplug event. |
Jinsuk Kim | 66d1eb2 | 2014-06-06 16:12:18 +0900 | [diff] [blame] | 25 | * |
| 26 | * @hide |
Jinsuk Kim | 78d695d | 2014-05-13 16:36:15 +0900 | [diff] [blame] | 27 | */ |
Jinsuk Kim | 66d1eb2 | 2014-06-06 16:12:18 +0900 | [diff] [blame] | 28 | @SystemApi |
Jinsuk Kim | 78d695d | 2014-05-13 16:36:15 +0900 | [diff] [blame] | 29 | public final class HdmiHotplugEvent implements Parcelable { |
| 30 | |
| 31 | private final int mPort; |
| 32 | private final boolean mConnected; |
| 33 | |
| 34 | /** |
| 35 | * Constructor. |
| 36 | * |
| 37 | * <p>Marked as hidden so only system can create the instance. |
| 38 | * |
| 39 | * @hide |
| 40 | */ |
| 41 | public HdmiHotplugEvent(int port, boolean connected) { |
| 42 | mPort = port; |
| 43 | mConnected = connected; |
| 44 | } |
| 45 | |
| 46 | /** |
Yuncheol Heo | 2b0da5c | 2014-10-22 14:32:27 +0900 | [diff] [blame] | 47 | * Returns the port number for which the event occurred. |
Jinsuk Kim | 78d695d | 2014-05-13 16:36:15 +0900 | [diff] [blame] | 48 | * |
| 49 | * @return port number |
| 50 | */ |
| 51 | public int getPort() { |
| 52 | return mPort; |
| 53 | } |
| 54 | |
| 55 | /** |
Yuncheol Heo | 2b0da5c | 2014-10-22 14:32:27 +0900 | [diff] [blame] | 56 | * Returns the connection status associated with this event |
Jinsuk Kim | 78d695d | 2014-05-13 16:36:15 +0900 | [diff] [blame] | 57 | * |
| 58 | * @return true if the device gets connected; otherwise false |
| 59 | */ |
| 60 | public boolean isConnected() { |
| 61 | return mConnected; |
| 62 | } |
| 63 | |
| 64 | /** |
Yuncheol Heo | 2b0da5c | 2014-10-22 14:32:27 +0900 | [diff] [blame] | 65 | * Describes the kinds of special objects contained in this Parcelable's |
Jinsuk Kim | 78d695d | 2014-05-13 16:36:15 +0900 | [diff] [blame] | 66 | * marshalled representation. |
| 67 | */ |
| 68 | @Override |
| 69 | public int describeContents() { |
| 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | /** |
Yuncheol Heo | 2b0da5c | 2014-10-22 14:32:27 +0900 | [diff] [blame] | 74 | * Flattens this object in to a Parcel. |
Jinsuk Kim | 78d695d | 2014-05-13 16:36:15 +0900 | [diff] [blame] | 75 | * |
| 76 | * @param dest The Parcel in which the object should be written. |
| 77 | * @param flags Additional flags about how the object should be written. |
| 78 | * May be 0 or {@link Parcelable#PARCELABLE_WRITE_RETURN_VALUE}. |
| 79 | */ |
| 80 | @Override |
| 81 | public void writeToParcel(Parcel dest, int flags) { |
| 82 | dest.writeInt(mPort); |
| 83 | dest.writeByte((byte) (mConnected ? 1 : 0)); |
| 84 | } |
| 85 | |
| 86 | public static final Parcelable.Creator<HdmiHotplugEvent> CREATOR |
| 87 | = new Parcelable.Creator<HdmiHotplugEvent>() { |
| 88 | /** |
Yuncheol Heo | 2b0da5c | 2014-10-22 14:32:27 +0900 | [diff] [blame] | 89 | * Rebuilds a {@link HdmiHotplugEvent} previously stored with |
Jinsuk Kim | 78d695d | 2014-05-13 16:36:15 +0900 | [diff] [blame] | 90 | * {@link Parcelable#writeToParcel(Parcel, int)}. |
| 91 | * |
| 92 | * @param p {@link HdmiHotplugEvent} object to read the Rating from |
| 93 | * @return a new {@link HdmiHotplugEvent} created from the data in the parcel |
| 94 | */ |
Yuncheol Heo | 2b0da5c | 2014-10-22 14:32:27 +0900 | [diff] [blame] | 95 | @Override |
Jinsuk Kim | 78d695d | 2014-05-13 16:36:15 +0900 | [diff] [blame] | 96 | public HdmiHotplugEvent createFromParcel(Parcel p) { |
| 97 | int port = p.readInt(); |
| 98 | boolean connected = p.readByte() == 1; |
| 99 | return new HdmiHotplugEvent(port, connected); |
| 100 | } |
Yuncheol Heo | 2b0da5c | 2014-10-22 14:32:27 +0900 | [diff] [blame] | 101 | @Override |
Jinsuk Kim | 78d695d | 2014-05-13 16:36:15 +0900 | [diff] [blame] | 102 | public HdmiHotplugEvent[] newArray(int size) { |
| 103 | return new HdmiHotplugEvent[size]; |
| 104 | } |
| 105 | }; |
| 106 | } |