Skip to content

Commit e49c2c0

Browse files
committed
Add documentation
1 parent 21936bc commit e49c2c0

32 files changed

Lines changed: 924 additions & 1428 deletions

Sources/AndroidNFC/AvailableNfcAntenna.swift

Lines changed: 17 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,72 +3,47 @@ import AndroidOS
33
import SwiftJava
44
import SwiftJavaJNICore
55

6+
/// Represents a single NFC antenna location on the device.
7+
///
8+
/// Coordinates are expressed in millimeters relative to the top-left corner of the device
9+
/// as reported by `NfcAntennaInfo`. Used to help users align their device with an NFC tag.
10+
///
11+
/// See also: [android.nfc.AvailableNfcAntenna](https://developer.android.com/reference/android/nfc/AvailableNfcAntenna)
612
@available(Android 31, *)
713
@JavaClass("android.nfc.AvailableNfcAntenna", implements: Parcelable.self)
814
open class AvailableNfcAntenna: JavaObject {
15+
/// Creates an antenna location at the given coordinates.
16+
///
17+
/// - Parameter arg0: X coordinate in millimeters from the top-left of the device.
18+
/// - Parameter arg1: Y coordinate in millimeters from the top-left of the device.
919
@JavaMethod
1020
@_nonoverride public convenience init(_ arg0: Int32, _ arg1: Int32, environment: JNIEnvironment? = nil)
1121

12-
/// Java method `getLocationX`.
13-
///
14-
/// ### Java method signature
15-
/// ```java
16-
/// public int android.nfc.AvailableNfcAntenna.getLocationX()
17-
/// ```
22+
/// Returns the X coordinate of this antenna in millimeters from the top-left of the device.
1823
@JavaMethod
1924
open func getLocationX() -> Int32
2025

21-
/// Java method `getLocationY`.
22-
///
23-
/// ### Java method signature
24-
/// ```java
25-
/// public int android.nfc.AvailableNfcAntenna.getLocationY()
26-
/// ```
26+
/// Returns the Y coordinate of this antenna in millimeters from the top-left of the device.
2727
@JavaMethod
2828
open func getLocationY() -> Int32
2929

30-
/// Java method `describeContents`.
31-
///
32-
/// ### Java method signature
33-
/// ```java
34-
/// public int android.nfc.AvailableNfcAntenna.describeContents()
35-
/// ```
30+
/// Describes the kinds of special objects contained in this `Parcelable` instance.
3631
@JavaMethod
3732
open func describeContents() -> Int32
3833

39-
/// Java method `writeToParcel`.
40-
///
41-
/// ### Java method signature
42-
/// ```java
43-
/// public void android.nfc.AvailableNfcAntenna.writeToParcel(android.os.Parcel,int)
44-
/// ```
34+
/// Flattens this object into a `Parcel`.
4535
@JavaMethod
4636
open func writeToParcel(_ arg0: Parcel?, _ arg1: Int32)
4737

48-
/// Java method `equals`.
49-
///
50-
/// ### Java method signature
51-
/// ```java
52-
/// public boolean android.nfc.AvailableNfcAntenna.equals(java.lang.Object)
53-
/// ```
38+
/// Returns `true` if this antenna location equals the given object.
5439
@JavaMethod
5540
open override func equals(_ arg0: JavaObject?) -> Bool
5641

57-
/// Java method `toString`.
58-
///
59-
/// ### Java method signature
60-
/// ```java
61-
/// public java.lang.String android.nfc.AvailableNfcAntenna.toString()
62-
/// ```
42+
/// Returns a string representation of this antenna location.
6343
@JavaMethod
6444
open override func toString() -> String
6545

66-
/// Java method `hashCode`.
67-
///
68-
/// ### Java method signature
69-
/// ```java
70-
/// public int android.nfc.AvailableNfcAntenna.hashCode()
71-
/// ```
46+
/// Returns a hash code for this antenna location.
7247
@JavaMethod
7348
open override func hashCode() -> Int32
7449
}

Sources/AndroidNFC/CardEmulation.swift

Lines changed: 78 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -4,162 +4,138 @@ import AndroidContent
44
import SwiftJava
55
import SwiftJavaJNICore
66

7+
/// Manages NFC card emulation services, AID routing, and payment preferences.
8+
///
9+
/// Card emulation allows Android devices to act as NFC cards. Obtain an instance via
10+
/// `CardEmulation.getInstance(_:)`. Requires the `FEATURE_NFC_HOST_CARD_EMULATION` feature.
11+
///
12+
/// See also: [android.nfc.cardemulation.CardEmulation](https://developer.android.com/reference/android/nfc/cardemulation/CardEmulation)
713
@available(Android 19, *)
814
@JavaClass("android.nfc.cardemulation.CardEmulation")
915
open class CardEmulation: JavaObject {
10-
/// Java method `setShouldDefaultToObserveModeForService`.
16+
/// Sets whether the given service should default to observe mode.
1117
///
12-
/// ### Java method signature
13-
/// ```java
14-
/// public boolean android.nfc.cardemulation.CardEmulation.setShouldDefaultToObserveModeForService(android.content.ComponentName,boolean)
15-
/// ```
18+
/// - Parameter arg0: The component name of the card emulation service.
19+
/// - Parameter arg1: `true` to default to observe mode.
20+
/// - Returns: `true` if the setting was applied.
1621
@available(Android 35, *)
17-
@JavaMethod
22+
@JavaMethod
1823
open func setShouldDefaultToObserveModeForService(_ arg0: ComponentName?, _ arg1: Bool) -> Bool
1924

20-
/// Java method `registerPollingLoopFilterForService`.
25+
/// Registers a polling loop filter for the given service.
2126
///
22-
/// ### Java method signature
23-
/// ```java
24-
/// public boolean android.nfc.cardemulation.CardEmulation.registerPollingLoopFilterForService(android.content.ComponentName,java.lang.String,boolean)
25-
/// ```
27+
/// - Parameter arg0: The component name of the card emulation service.
28+
/// - Parameter arg1: A hex string filter for matching polling loop data.
29+
/// - Parameter arg2: `true` to auto-transact when the filter matches.
30+
/// - Returns: `true` if the filter was registered.
2631
@available(Android 35, *)
27-
@JavaMethod
32+
@JavaMethod
2833
open func registerPollingLoopFilterForService(_ arg0: ComponentName?, _ arg1: String, _ arg2: Bool) -> Bool
2934

30-
/// Java method `registerPollingLoopPatternFilterForService`.
35+
/// Registers a regex pattern filter for the given service's polling loop data.
3136
///
32-
/// ### Java method signature
33-
/// ```java
34-
/// public boolean android.nfc.cardemulation.CardEmulation.registerPollingLoopPatternFilterForService(android.content.ComponentName,java.lang.String,boolean)
35-
/// ```
37+
/// - Parameter arg0: The component name of the card emulation service.
38+
/// - Parameter arg1: A regex pattern to match against polling loop data.
39+
/// - Parameter arg2: `true` to auto-transact when the pattern matches.
40+
/// - Returns: `true` if the filter was registered.
3641
@available(Android 35, *)
37-
@JavaMethod
42+
@JavaMethod
3843
open func registerPollingLoopPatternFilterForService(_ arg0: ComponentName?, _ arg1: String, _ arg2: Bool) -> Bool
3944

40-
/// Java method `removePollingLoopPatternFilterForService`.
45+
/// Removes a previously registered polling loop pattern filter.
4146
///
42-
/// ### Java method signature
43-
/// ```java
44-
/// public boolean android.nfc.cardemulation.CardEmulation.removePollingLoopPatternFilterForService(android.content.ComponentName,java.lang.String)
45-
/// ```
47+
/// - Parameter arg0: The component name of the card emulation service.
48+
/// - Parameter arg1: The pattern string to remove.
49+
/// - Returns: `true` if the filter was removed.
4650
@available(Android 35, *)
47-
@JavaMethod
51+
@JavaMethod
4852
open func removePollingLoopPatternFilterForService(_ arg0: ComponentName?, _ arg1: String) -> Bool
4953

50-
/// Java method `getRouteDestinationForPreferredPaymentService`.
51-
///
52-
/// ### Java method signature
53-
/// ```java
54-
/// public java.lang.String android.nfc.cardemulation.CardEmulation.getRouteDestinationForPreferredPaymentService()
55-
/// ```
54+
/// Returns the route destination (e.g., `"HCE"`, `"OffHost"`) for the preferred payment service.
5655
@available(Android 35, *)
57-
@JavaMethod
56+
@JavaMethod
5857
open func getRouteDestinationForPreferredPaymentService() -> String
5958

60-
/// Java method `isDefaultServiceForCategory`.
59+
/// Returns `true` if the given service is the default for the specified category.
6160
///
62-
/// ### Java method signature
63-
/// ```java
64-
/// public boolean android.nfc.cardemulation.CardEmulation.isDefaultServiceForCategory(android.content.ComponentName,java.lang.String)
65-
/// ```
66-
@JavaMethod
61+
/// - Parameter arg0: The component name of the card emulation service.
62+
/// - Parameter arg1: One of `CATEGORY_PAYMENT` or `CATEGORY_OTHER`.
63+
@JavaMethod
6764
open func isDefaultServiceForCategory(_ arg0: ComponentName?, _ arg1: String) -> Bool
6865

69-
/// Java method `isDefaultServiceForAid`.
66+
/// Returns `true` if the given service is the default handler for the specified AID.
7067
///
71-
/// ### Java method signature
72-
/// ```java
73-
/// public boolean android.nfc.cardemulation.CardEmulation.isDefaultServiceForAid(android.content.ComponentName,java.lang.String)
74-
/// ```
75-
@JavaMethod
68+
/// - Parameter arg0: The component name of the card emulation service.
69+
/// - Parameter arg1: The AID as a hex string.
70+
@JavaMethod
7671
open func isDefaultServiceForAid(_ arg0: ComponentName?, _ arg1: String) -> Bool
7772

78-
/// Java method `categoryAllowsForegroundPreference`.
73+
/// Returns `true` if the given category allows foreground preference selection.
7974
///
80-
/// ### Java method signature
81-
/// ```java
82-
/// public boolean android.nfc.cardemulation.CardEmulation.categoryAllowsForegroundPreference(java.lang.String)
83-
/// ```
84-
@JavaMethod
75+
/// - Parameter arg0: One of `CATEGORY_PAYMENT` or `CATEGORY_OTHER`.
76+
@JavaMethod
8577
open func categoryAllowsForegroundPreference(_ arg0: String) -> Bool
8678

87-
/// Java method `getSelectionModeForCategory`.
79+
/// Returns the selection mode for the given category (e.g., `SELECTION_MODE_PREFER_DEFAULT`).
8880
///
89-
/// ### Java method signature
90-
/// ```java
91-
/// public int android.nfc.cardemulation.CardEmulation.getSelectionModeForCategory(java.lang.String)
92-
/// ```
93-
@JavaMethod
81+
/// - Parameter arg0: One of `CATEGORY_PAYMENT` or `CATEGORY_OTHER`.
82+
@JavaMethod
9483
open func getSelectionModeForCategory(_ arg0: String) -> Int32
9584

96-
/// Java method `removePollingLoopFilterForService`.
85+
/// Removes a previously registered polling loop filter for the given service.
9786
///
98-
/// ### Java method signature
99-
/// ```java
100-
/// public boolean android.nfc.cardemulation.CardEmulation.removePollingLoopFilterForService(android.content.ComponentName,java.lang.String)
101-
/// ```
87+
/// - Parameter arg0: The component name of the card emulation service.
88+
/// - Parameter arg1: The hex string filter to remove.
89+
/// - Returns: `true` if the filter was removed.
10290
@available(Android 35, *)
103-
@JavaMethod
91+
@JavaMethod
10492
open func removePollingLoopFilterForService(_ arg0: ComponentName?, _ arg1: String) -> Bool
10593

106-
/// Java method `unsetOffHostForService`.
94+
/// Clears the off-host secure element association for the given service.
10795
///
108-
/// ### Java method signature
109-
/// ```java
110-
/// public boolean android.nfc.cardemulation.CardEmulation.unsetOffHostForService(android.content.ComponentName)
111-
/// ```
96+
/// - Parameter arg0: The component name of the card emulation service.
97+
/// - Returns: `true` if the association was cleared.
11298
@available(Android 26, *)
113-
@JavaMethod
99+
@JavaMethod
114100
open func unsetOffHostForService(_ arg0: ComponentName?) -> Bool
115101

116-
/// Java method `setOffHostForService`.
102+
/// Binds the given service to a specific off-host secure element.
117103
///
118-
/// ### Java method signature
119-
/// ```java
120-
/// public boolean android.nfc.cardemulation.CardEmulation.setOffHostForService(android.content.ComponentName,java.lang.String)
121-
/// ```
104+
/// - Parameter arg0: The component name of the card emulation service.
105+
/// - Parameter arg1: The off-host secure element name (e.g., `"eSE"`, `"SIM"`).
106+
/// - Returns: `true` if the binding was applied.
122107
@available(Android 26, *)
123-
@JavaMethod
108+
@JavaMethod
124109
open func setOffHostForService(_ arg0: ComponentName?, _ arg1: String) -> Bool
125110

126-
/// Java method `removeAidsForService`.
111+
/// Removes AIDs registered by the given service for the specified category.
127112
///
128-
/// ### Java method signature
129-
/// ```java
130-
/// public boolean android.nfc.cardemulation.CardEmulation.removeAidsForService(android.content.ComponentName,java.lang.String)
131-
/// ```
132-
@JavaMethod
113+
/// - Parameter arg0: The component name of the card emulation service.
114+
/// - Parameter arg1: One of `CATEGORY_PAYMENT` or `CATEGORY_OTHER`.
115+
/// - Returns: `true` if the AIDs were removed.
116+
@JavaMethod
133117
open func removeAidsForService(_ arg0: ComponentName?, _ arg1: String) -> Bool
134118

135-
/// Java method `setPreferredService`.
119+
/// Sets the given service as the preferred card emulation service while the activity is foreground.
136120
///
137-
/// ### Java method signature
138-
/// ```java
139-
/// public boolean android.nfc.cardemulation.CardEmulation.setPreferredService(android.app.Activity,android.content.ComponentName)
140-
/// ```
121+
/// - Parameter arg0: The foreground activity.
122+
/// - Parameter arg1: The component name of the service to prefer.
123+
/// - Returns: `true` if the preference was set.
141124
@available(Android 21, *)
142-
@JavaMethod
125+
@JavaMethod
143126
open func setPreferredService(_ arg0: Activity?, _ arg1: ComponentName?) -> Bool
144127

145-
/// Java method `unsetPreferredService`.
128+
/// Clears the preferred card emulation service set by `setPreferredService(_:_:)`.
146129
///
147-
/// ### Java method signature
148-
/// ```java
149-
/// public boolean android.nfc.cardemulation.CardEmulation.unsetPreferredService(android.app.Activity)
150-
/// ```
130+
/// - Parameter arg0: The foreground activity.
131+
/// - Returns: `true` if the preference was cleared.
151132
@available(Android 21, *)
152-
@JavaMethod
133+
@JavaMethod
153134
open func unsetPreferredService(_ arg0: Activity?) -> Bool
154135

155-
/// Java method `supportsAidPrefixRegistration`.
156-
///
157-
/// ### Java method signature
158-
/// ```java
159-
/// public boolean android.nfc.cardemulation.CardEmulation.supportsAidPrefixRegistration()
160-
/// ```
136+
/// Returns `true` if the device supports AID prefix and subset registration.
161137
@available(Android 23, *)
162-
@JavaMethod
138+
@JavaMethod
163139
open func supportsAidPrefixRegistration() -> Bool
164140
}
165141
@available(Android 19, *)
@@ -189,12 +165,10 @@ extension JavaClass<CardEmulation> {
189165
@JavaStaticField(isFinal: true)
190166
public var SELECTION_MODE_PREFER_DEFAULT: Int32
191167

192-
/// Java method `getInstance`.
193-
///
194-
/// ### Java method signature
195-
/// ```java
196-
/// public static synchronized android.nfc.cardemulation.CardEmulation android.nfc.cardemulation.CardEmulation.getInstance(android.nfc.NfcAdapter)
197-
/// ```
168+
/// Returns a `CardEmulation` instance for the given NFC adapter.
169+
///
170+
/// - Parameter arg0: The `NfcAdapter` for this device.
171+
/// - Returns: A `CardEmulation` instance.
198172
@JavaStaticMethod
199173
public func getInstance(_ arg0: NfcAdapter?) -> CardEmulation!
200174
}

Sources/AndroidNFC/FormatException.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
import SwiftJava
33
import SwiftJavaJNICore
44

5+
/// Thrown when an NDEF message cannot be parsed or is not a valid NDEF format.
6+
///
7+
/// See also: [android.nfc.FormatException](https://developer.android.com/reference/android/nfc/FormatException)
58
@JavaClass("android.nfc.FormatException")
69
open class FormatException: JavaObject {
710
@JavaMethod

0 commit comments

Comments
 (0)