1 /*
2  * Copyright (C) 2015 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.nfc;
18 
19 import android.annotation.NonNull;
20 import android.os.Parcel;
21 import android.os.Parcelable;
22 
23 import java.util.ArrayList;
24 import java.util.List;
25 
26 
27 /**
28  * Contains information on all available Nfc
29  * antennas on an Android device as well as information
30  * on the device itself in relation positioning of the
31  * antennas.
32  */
33 public final class NfcAntennaInfo implements Parcelable {
34     // Width of the device in millimeters.
35     private final int mDeviceWidth;
36     // Height of the device in millimeters.
37     private final int mDeviceHeight;
38     // Whether the device is foldable.
39     private final boolean mDeviceFoldable;
40     // All available Nfc Antennas on the device.
41     private final List<AvailableNfcAntenna> mAvailableNfcAntennas;
42 
NfcAntennaInfo(int deviceWidth, int deviceHeight, boolean deviceFoldable, @NonNull List<AvailableNfcAntenna> availableNfcAntennas)43     public NfcAntennaInfo(int deviceWidth, int deviceHeight, boolean deviceFoldable,
44             @NonNull List<AvailableNfcAntenna> availableNfcAntennas) {
45         this.mDeviceWidth = deviceWidth;
46         this.mDeviceHeight = deviceHeight;
47         this.mDeviceFoldable = deviceFoldable;
48         this.mAvailableNfcAntennas = availableNfcAntennas;
49     }
50 
51     /**
52      * Width of the device in millimeters.
53      */
getDeviceWidth()54     public int getDeviceWidth() {
55         return mDeviceWidth;
56     }
57 
58     /**
59      * Height of the device in millimeters.
60      */
getDeviceHeight()61     public int getDeviceHeight() {
62         return mDeviceHeight;
63     }
64 
65     /**
66      * Whether the device is foldable. When the device is foldable,
67      * the 0, 0 is considered to be bottom-left when the device is unfolded and
68      * the screens are facing the user. For non-foldable devices 0, 0
69      * is bottom-left when the user is facing the screen.
70      */
isDeviceFoldable()71     public boolean isDeviceFoldable() {
72         return mDeviceFoldable;
73     }
74 
75     /**
76      * Get all NFC antennas that exist on the device.
77      */
78     @NonNull
getAvailableNfcAntennas()79     public List<AvailableNfcAntenna> getAvailableNfcAntennas() {
80         return mAvailableNfcAntennas;
81     }
82 
NfcAntennaInfo(Parcel in)83     private NfcAntennaInfo(Parcel in) {
84         this.mDeviceWidth = in.readInt();
85         this.mDeviceHeight = in.readInt();
86         this.mDeviceFoldable = in.readByte() != 0;
87         this.mAvailableNfcAntennas = new ArrayList<>();
88         in.readTypedList(this.mAvailableNfcAntennas,
89                 AvailableNfcAntenna.CREATOR);
90     }
91 
92     public static final @NonNull Parcelable.Creator<NfcAntennaInfo> CREATOR =
93             new Parcelable.Creator<NfcAntennaInfo>() {
94         @Override
95         public NfcAntennaInfo createFromParcel(Parcel in) {
96             return new NfcAntennaInfo(in);
97         }
98 
99         @Override
100         public NfcAntennaInfo[] newArray(int size) {
101             return new NfcAntennaInfo[size];
102         }
103     };
104 
105     @Override
describeContents()106     public int describeContents() {
107         return 0;
108     }
109 
110     @Override
writeToParcel(@onNull Parcel dest, int flags)111     public void writeToParcel(@NonNull Parcel dest, int flags) {
112         dest.writeInt(mDeviceWidth);
113         dest.writeInt(mDeviceHeight);
114         dest.writeByte((byte) (mDeviceFoldable ? 1 : 0));
115         dest.writeTypedList(mAvailableNfcAntennas, 0);
116     }
117 }
118