@craft-native/android 0.0.134 → 0.0.135
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -0
- package/package.json +1 -1
- package/templates/CraftBridge.kt.template +56 -0
package/README.md
CHANGED
|
@@ -456,6 +456,14 @@ await window.craft.restorePurchases();
|
|
|
456
456
|
window.craft.setKeepAwake(true); // Prevent screen dimming
|
|
457
457
|
window.craft.setKeepAwake(false); // Allow screen dimming
|
|
458
458
|
|
|
459
|
+
// Screen brightness, 0 to 1: always available (no config flag, no permission).
|
|
460
|
+
// A window-level override, so it ends with the window; resetBrightness hands the
|
|
461
|
+
// screen back to the system, auto-brightness included. `brightness` from
|
|
462
|
+
// 'craft-native/mobile' wraps all three.
|
|
463
|
+
const level = await window.craft.getBrightness();
|
|
464
|
+
await window.craft.setBrightness(0.1);
|
|
465
|
+
await window.craft.resetBrightness();
|
|
466
|
+
|
|
459
467
|
// Speech: short spoken cues through TextToSpeech, with transient may-duck audio
|
|
460
468
|
// focus so the person's music dips instead of stopping. Always available (no
|
|
461
469
|
// config flag). A device with no TTS engine resolves false.
|
package/package.json
CHANGED
|
@@ -418,6 +418,7 @@ class CraftBridge(
|
|
|
418
418
|
appReview: true,
|
|
419
419
|
flashlight: {{ENABLE_CAMERA}} && ${hasFlashlight()},
|
|
420
420
|
speech: true,
|
|
421
|
+
brightness: true,
|
|
421
422
|
openURL: true,
|
|
422
423
|
vibrationPattern: true,
|
|
423
424
|
appState: true,
|
|
@@ -687,6 +688,18 @@ class CraftBridge(
|
|
|
687
688
|
return CraftAndroid.setKeepAwake(enabled);
|
|
688
689
|
},
|
|
689
690
|
|
|
691
|
+
// Screen brightness, 0 to 1. resetBrightness hands the screen
|
|
692
|
+
// back to the system setting (auto-brightness included).
|
|
693
|
+
getBrightness: function() {
|
|
694
|
+
return Promise.resolve().then(function() { return CraftAndroid.getBrightness(); });
|
|
695
|
+
},
|
|
696
|
+
setBrightness: function(level) {
|
|
697
|
+
return Promise.resolve().then(function() { return CraftAndroid.setBrightness(Number(level)); });
|
|
698
|
+
},
|
|
699
|
+
resetBrightness: function() {
|
|
700
|
+
return Promise.resolve().then(function() { return CraftAndroid.resetBrightness(); });
|
|
701
|
+
},
|
|
702
|
+
|
|
690
703
|
// Orientation Lock
|
|
691
704
|
lockOrientation: function(orientation) {
|
|
692
705
|
return CraftAndroid.lockOrientation(orientation);
|
|
@@ -3628,6 +3641,49 @@ class CraftBridge(
|
|
|
3628
3641
|
)
|
|
3629
3642
|
}
|
|
3630
3643
|
|
|
3644
|
+
// ==================== Screen Brightness ====================
|
|
3645
|
+
//
|
|
3646
|
+
// The window's own brightness override (WindowManager.LayoutParams
|
|
3647
|
+
// .screenBrightness): no permission, and it lasts only while this window
|
|
3648
|
+
// is in front, so leaving the app hands the screen back by itself.
|
|
3649
|
+
// resetBrightness releases it, which also gives auto-brightness back -
|
|
3650
|
+
// setting the old system level instead would freeze it there.
|
|
3651
|
+
@Volatile private var brightnessOverride: Float? = null
|
|
3652
|
+
|
|
3653
|
+
@JavascriptInterface
|
|
3654
|
+
fun getBrightness(): Double {
|
|
3655
|
+
brightnessOverride?.let { return it.toDouble() }
|
|
3656
|
+
return try {
|
|
3657
|
+
Settings.System.getInt(activity.contentResolver, Settings.System.SCREEN_BRIGHTNESS) / 255.0
|
|
3658
|
+
} catch (e: Exception) {
|
|
3659
|
+
0.5
|
|
3660
|
+
}
|
|
3661
|
+
}
|
|
3662
|
+
|
|
3663
|
+
@JavascriptInterface
|
|
3664
|
+
fun setBrightness(level: Double): Double {
|
|
3665
|
+
if (!level.isFinite()) return getBrightness()
|
|
3666
|
+
val clamped = level.coerceIn(0.0, 1.0).toFloat()
|
|
3667
|
+
brightnessOverride = clamped
|
|
3668
|
+
activity.runOnUiThread {
|
|
3669
|
+
val params = activity.window.attributes
|
|
3670
|
+
params.screenBrightness = clamped
|
|
3671
|
+
activity.window.attributes = params
|
|
3672
|
+
}
|
|
3673
|
+
return clamped.toDouble()
|
|
3674
|
+
}
|
|
3675
|
+
|
|
3676
|
+
@JavascriptInterface
|
|
3677
|
+
fun resetBrightness(): Double {
|
|
3678
|
+
brightnessOverride = null
|
|
3679
|
+
activity.runOnUiThread {
|
|
3680
|
+
val params = activity.window.attributes
|
|
3681
|
+
params.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE
|
|
3682
|
+
activity.window.attributes = params
|
|
3683
|
+
}
|
|
3684
|
+
return getBrightness()
|
|
3685
|
+
}
|
|
3686
|
+
|
|
3631
3687
|
// ==================== Keep Awake ====================
|
|
3632
3688
|
|
|
3633
3689
|
@JavascriptInterface
|