Skip to content

Commit 51c240b

Browse files
authored
Merge pull request #34 from PureSwift/feature/docs
Add documentation and availability annotations for `AndroidOS`
2 parents a489a09 + 5aea2d0 commit 51c240b

130 files changed

Lines changed: 2663 additions & 348 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Sources/AndroidInput/Syscalls.swift

Lines changed: 341 additions & 341 deletions
Large diffs are not rendered by default.

Sources/AndroidOS/AndroidAPI.swift

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,23 @@ public extension AndroidAPI {
3434

3535
internal extension AndroidAPI {
3636

37+
/**
38+
Returns the targetSdkVersion of the caller, or __ANDROID_API_FUTURE__ if there is no known target SDK version (for code not running in the context of an app).
39+
40+
The returned value is the same as the AndroidManifest.xml targetSdkVersion. This is mostly useful for the OS to decide what behavior an app is expecting. See also android_get_device_api_level().
41+
42+
Available since API level 24. Returns the API level of the device we're actually running on, or -1 on failure.
43+
44+
The returned value is the same as the Java Build.VERSION.SDK_INT. This is mostly useful for an app to work out what version of the OS it's running on. See also android_get_application_target_sdk_version().
45+
46+
Available since API level 29.
47+
*/
3748
static func deviceAPILevel() throws -> Int32 {
38-
#if os(Android) && canImport(CAndroidNDK)
39-
try ndkValue().get()
40-
#else
41-
try jniValue()
42-
#endif
49+
if #available(Android 24, *) {
50+
try ndkValue().get()
51+
} else {
52+
try jniValue()
53+
}
4354
}
4455

4556
/// `Build.VERSION.SDK_INT`

Sources/AndroidOS/BadParcelableException.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
import SwiftJava
33
import CSwiftJavaJNI
44

5+
/// Thrown when a `Parcelable` encounters an error during marshalling or unmarshalling,
6+
/// such as when a class cannot be found or data is malformed.
7+
///
8+
/// See also: [android.os.BadParcelableException](https://developer.android.com/reference/android/os/BadParcelableException)
59
@JavaClass("android.os.BadParcelableException")
610
open class BadParcelableException: RuntimeException {
711
@JavaMethod

Sources/AndroidOS/BaseBundle.swift

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,104 +2,158 @@
22
import SwiftJava
33
import CSwiftJavaJNI
44

5+
/// A mapping from String keys to values of various types. The only types currently supported
6+
/// are: Boolean, Int, Long, Double, String, and arrays of each of these types.
7+
///
8+
/// This is the base class for `Bundle` and `PersistableBundle`.
9+
///
10+
/// See also: [android.os.BaseBundle](https://developer.android.com/reference/android/os/BaseBundle)
11+
@available(Android 21, *)
512
@JavaClass("android.os.BaseBundle")
613
open class BaseBundle: JavaObject {
14+
/// Inserts a String value into the mapping, replacing any existing value for the given key.
715
@JavaMethod
816
open func putString(_ arg0: String, _ arg1: String)
917

18+
/// Inserts a boolean array value into the mapping.
1019
@JavaMethod
1120
open func putBooleanArray(_ arg0: String, _ arg1: [Bool])
1221

22+
/// Inserts an int array value into the mapping.
1323
@JavaMethod
1424
open func putIntArray(_ arg0: String, _ arg1: [Int32])
1525

26+
/// Inserts a long array value into the mapping.
1627
@JavaMethod
1728
open func putLongArray(_ arg0: String, _ arg1: [Int64])
1829

30+
/// Inserts a double array value into the mapping.
1931
@JavaMethod
2032
open func putDoubleArray(_ arg0: String, _ arg1: [Double])
2133

34+
/// Inserts a String array value into the mapping.
2235
@JavaMethod
2336
open func putStringArray(_ arg0: String, _ arg1: [String])
2437

38+
/// Returns the value associated with the given key, or nil if no mapping of the desired type
39+
/// exists for the given key.
2540
@JavaMethod
2641
open func getBooleanArray(_ arg0: String) -> [Bool]
2742

43+
/// Returns the value associated with the given key, or nil if no mapping of the desired type
44+
/// exists for the given key.
2845
@JavaMethod
2946
open func getIntArray(_ arg0: String) -> [Int32]
3047

48+
/// Returns the value associated with the given key, or nil if no mapping of the desired type
49+
/// exists for the given key.
3150
@JavaMethod
3251
open func getLongArray(_ arg0: String) -> [Int64]
3352

53+
/// Returns the value associated with the given key, or nil if no mapping of the desired type
54+
/// exists for the given key.
3455
@JavaMethod
3556
open func getDoubleArray(_ arg0: String) -> [Double]
3657

58+
/// Removes any entry with the given key from the mapping.
3759
@JavaMethod
3860
open func remove(_ arg0: String)
3961

62+
/// Returns the number of mappings contained in this Bundle.
4063
@JavaMethod
4164
open func size() -> Int32
4265

66+
/// Returns the entry with the given key as an object.
4367
@JavaMethod
4468
open func get(_ arg0: String) -> JavaObject!
4569

70+
/// Returns the value associated with the given key, or `false` if no mapping of the desired type
71+
/// exists for the given key.
4672
@JavaMethod
4773
open func getBoolean(_ arg0: String) -> Bool
4874

75+
/// Returns the value associated with the given key, or `arg1` if no mapping of the desired type
76+
/// exists for the given key.
4977
@JavaMethod
5078
open func getBoolean(_ arg0: String, _ arg1: Bool) -> Bool
5179

80+
/// Inserts a Boolean value into the mapping.
5281
@JavaMethod
5382
open func putBoolean(_ arg0: String, _ arg1: Bool)
5483

84+
/// Returns the value associated with the given key, or `0` if no mapping of the desired type
85+
/// exists for the given key.
5586
@JavaMethod
5687
open func getInt(_ arg0: String) -> Int32
5788

89+
/// Returns the value associated with the given key, or `arg1` if no mapping of the desired type
90+
/// exists for the given key.
5891
@JavaMethod
5992
open func getInt(_ arg0: String, _ arg1: Int32) -> Int32
6093

94+
/// Inserts an int value into the mapping.
6195
@JavaMethod
6296
open func putInt(_ arg0: String, _ arg1: Int32)
6397

98+
/// Returns the value associated with the given key, or `arg1` if no mapping of the desired type
99+
/// exists for the given key.
64100
@JavaMethod
65101
open func getLong(_ arg0: String, _ arg1: Int64) -> Int64
66102

103+
/// Returns the value associated with the given key, or `0L` if no mapping of the desired type
104+
/// exists for the given key.
67105
@JavaMethod
68106
open func getLong(_ arg0: String) -> Int64
69107

108+
/// Inserts a long value into the mapping.
70109
@JavaMethod
71110
open func putLong(_ arg0: String, _ arg1: Int64)
72111

112+
/// Returns the value associated with the given key, or `arg1` if no mapping of the desired type
113+
/// exists for the given key.
73114
@JavaMethod
74115
open func getDouble(_ arg0: String, _ arg1: Double) -> Double
75116

117+
/// Returns the value associated with the given key, or `0.0` if no mapping of the desired type
118+
/// exists for the given key.
76119
@JavaMethod
77120
open func getDouble(_ arg0: String) -> Double
78121

122+
/// Inserts a double value into the mapping.
79123
@JavaMethod
80124
open func putDouble(_ arg0: String, _ arg1: Double)
81125

126+
/// Removes all elements from the mapping.
82127
@JavaMethod
83128
open func clear()
84129

130+
/// Returns true if the mapping is empty, false otherwise.
85131
@JavaMethod
86132
open func isEmpty() -> Bool
87133

134+
/// Inserts all mappings from the given `PersistableBundle` into this Bundle.
88135
@JavaMethod
89136
open func putAll(_ arg0: PersistableBundle?)
90137

138+
/// Returns a Set containing the Strings used as keys in this Bundle.
91139
@JavaMethod
92140
open func keySet() -> JavaSet<JavaString>!
93141

142+
/// Returns true if the given key is contained in the mapping.
94143
@JavaMethod
95144
open func containsKey(_ arg0: String) -> Bool
96145

146+
/// Returns the value associated with the given key, or nil if no mapping exists.
97147
@JavaMethod
98148
open func getStringArray(_ arg0: String) -> [String]
99149

150+
/// Returns the value associated with the given key, or nil if no mapping of the desired type
151+
/// exists for the given key.
100152
@JavaMethod
101153
open func getString(_ arg0: String) -> String
102154

155+
/// Returns the value associated with the given key, or `arg1` if no mapping of the desired type
156+
/// exists for the given key.
103157
@JavaMethod
104158
open func getString(_ arg0: String, _ arg1: String) -> String
105159
}

Sources/AndroidOS/BatteryManager.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,27 @@
22
import SwiftJava
33
import CSwiftJavaJNI
44

5+
/// Provides information about battery state and charging status.
6+
///
7+
/// Obtain an instance via `Context.getSystemService(Context.BATTERY_SERVICE)`.
8+
///
9+
/// See [android.os.BatteryManager](https://developer.android.com/reference/android/os/BatteryManager)
10+
@available(Android 21, *)
511
@JavaClass("android.os.BatteryManager")
612
open class BatteryManager: JavaObject {
13+
/// Returns whether the device is currently charging.
714
@JavaMethod
815
open func isCharging() -> Bool
916

17+
/// Returns an estimate of how long until the battery is fully charged, in milliseconds, or `-1` if unknown.
1018
@JavaMethod
1119
open func computeChargeTimeRemaining() -> Int64
1220

21+
/// Returns the value of the given integer battery property (e.g., `BATTERY_PROPERTY_CAPACITY`).
1322
@JavaMethod
1423
open func getIntProperty(_ arg0: Int32) -> Int32
1524

25+
/// Returns the value of the given long battery property (e.g., `BATTERY_PROPERTY_ENERGY_COUNTER`).
1626
@JavaMethod
1727
open func getLongProperty(_ arg0: Int32) -> Int64
1828
}

0 commit comments

Comments
 (0)