diff --git a/Demo/app/src/main/swift-bridge/CatalogBridge/Catalog.swift b/Demo/app/src/main/swift-bridge/CatalogBridge/Catalog.swift index 4cffdff..83d7be8 100644 --- a/Demo/app/src/main/swift-bridge/CatalogBridge/Catalog.swift +++ b/Demo/app/src/main/swift-bridge/CatalogBridge/Catalog.swift @@ -53,11 +53,21 @@ package enum Catalog { summary: "Build info, SDK level and system clocks (android.os)", demo: CatalogDemos.androidOS ), + CatalogEntry( + name: "AndroidApp", + summary: "ActivityManager memory info (android.app)", + demo: CatalogDemos.androidApp + ), CatalogEntry( name: "AndroidContent", summary: "Package and application info via Context (android.content)", demo: CatalogDemos.androidContent ), + CatalogEntry( + name: "AndroidGraphics", + summary: "Bitmap creation and colors (android.graphics)", + demo: CatalogDemos.androidGraphics + ), CatalogEntry( name: "AndroidLocation", summary: "Location providers and their state (android.location)", @@ -78,5 +88,15 @@ package enum Catalog { summary: "NFC adapter availability (android.nfc)", demo: CatalogDemos.androidNFC ), + CatalogEntry( + name: "AndroidUtil", + summary: "Display metrics and density (android.util)", + demo: CatalogDemos.androidUtil + ), + CatalogEntry( + name: "AndroidView", + summary: "ViewConfiguration touch and gesture constants (android.view)", + demo: CatalogDemos.androidView + ), ] } diff --git a/Demo/app/src/main/swift-bridge/CatalogBridge/CatalogDemos.swift b/Demo/app/src/main/swift-bridge/CatalogBridge/CatalogDemos.swift index 2814802..2e99b04 100644 --- a/Demo/app/src/main/swift-bridge/CatalogBridge/CatalogDemos.swift +++ b/Demo/app/src/main/swift-bridge/CatalogBridge/CatalogDemos.swift @@ -7,10 +7,14 @@ // import AndroidKit +import AndroidApp +import AndroidGraphics import AndroidLocation import AndroidMedia import AndroidNet import AndroidNFC +import AndroidUtil +import AndroidView enum CatalogDemos { @@ -27,11 +31,108 @@ enum CatalogDemos { let clock = try JavaClass() out("Uptime: \(clock.uptimeMillis() / 1000)s") out("Elapsed realtime: \(clock.elapsedRealtime() / 1000)s") + + if let context = Catalog.context { + let contextClass = try JavaClass() + if let battery = context.getSystemService(contextClass.BATTERY_SERVICE)? + .as(AndroidOS.BatteryManager.self) { + let capacity = try JavaClass().BATTERY_PROPERTY_CAPACITY + out("Battery level: \(battery.getIntProperty(capacity))%") + out("Charging: \(battery.isCharging())") + } + if let power = context.getSystemService(contextClass.POWER_SERVICE)? + .as(AndroidOS.PowerManager.self) { + out("Screen interactive: \(power.isInteractive())") + } + } } catch { out("Error: \(error)") } } + // MARK: - AndroidApp + + static func androidApp(_ out: (String) -> Void) { + guard let context = Catalog.context else { + out("No Android Context available") + return + } + do { + let serviceName = try JavaClass().ACTIVITY_SERVICE + guard let manager = context.getSystemService(serviceName)? + .as(AndroidApp.ActivityManager.self) else { + out("ActivityManager unavailable") + return + } + out("Memory class: \(manager.getMemoryClass()) MB") + out("Low RAM device: \(manager.isLowRamDevice())") + let info = AndroidApp.ActivityManager.MemoryInfo() + manager.getMemoryInfo(info) + let mb: Int64 = 1024 * 1024 + out("Available memory: \(info.availMem / mb) MB") + out("Total memory: \(info.totalMem / mb) MB") + out("Low memory: \(info.lowMemory)") + } catch { + out("Error: \(error)") + } + } + + // MARK: - AndroidGraphics + + static func androidGraphics(_ out: (String) -> Void) { + do { + let config = AndroidGraphics.Bitmap.Config(.ARGB_8888) + guard let bitmap = try JavaClass() + .createBitmap(64, 64, config) else { + out("Unable to create bitmap") + return + } + out("Bitmap: \(bitmap.getWidth())×\(bitmap.getHeight()) ARGB_8888") + out("Byte count: \(bitmap.getByteCount())") + bitmap.recycle() + + let colorClass = try JavaClass() + let magenta = colorClass.rgb(Int32(255), Int32(0), Int32(128)) + out("Color.rgb(255, 0, 128) = #\(String(UInt32(bitPattern: magenta), radix: 16, uppercase: true))") + } catch { + out("Error: \(error)") + } + } + + // MARK: - AndroidView + + static func androidView(_ out: (String) -> Void) { + guard let context = Catalog.context else { + out("No Android Context available") + return + } + do { + let configClass = try JavaClass() + if let configuration = configClass.get(context) { + out("Scaled touch slop: \(configuration.getScaledTouchSlop()) px") + } + out("Long press timeout: \(configClass.getLongPressTimeout()) ms") + out("Double tap timeout: \(configClass.getDoubleTapTimeout()) ms") + } catch { + out("Error: \(error)") + } + } + + // MARK: - AndroidUtil + + static func androidUtil(_ out: (String) -> Void) { + guard let context = Catalog.context else { + out("No Android Context available") + return + } + guard let metrics = context.getResources()?.getDisplayMetrics() else { + out("DisplayMetrics unavailable") + return + } + out("Display: \(metrics.widthPixels)×\(metrics.heightPixels) px") + out("Density: \(metrics.density) (\(metrics.densityDpi) dpi)") + } + // MARK: - AndroidContent static func androidContent(_ out: (String) -> Void) {