Step counter test1

This commit is contained in:
2026-08-14 18:16:55 +08:00
parent 5d07c8c8bd
commit 905400a59a
17 changed files with 1397 additions and 136 deletions
@@ -1,3 +1,7 @@
/**
* @file CameraPermissions.kt
* @brief Runtime-permission requirements for the bowling camera feature.
*/
package com.example.jnicpp.bowling
import android.Manifest
@@ -7,30 +11,48 @@ import android.os.Build
import androidx.core.content.ContextCompat
/**
* Single source of truth for which runtime permissions this feature needs
* and whether they're currently granted. The actual request flow (which
* must be owned by an Activity/Fragment via ActivityResultContracts) lives
* in [BowlingCameraActivity]; this object just centralizes the "what" so
* both the manifest expectations and the request flow can't drift apart.
* @brief Single source of truth for which runtime permissions this feature
* needs and whether they're currently granted.
*
* The actual request flow (which must be owned by an Activity/Fragment via
* ActivityResultContracts) lives in [BowlingCameraActivity]; this object
* just centralizes the "what" so both the manifest expectations and the
* request flow can't drift apart.
*/
object CameraPermissions {
/**
* @brief The permissions this feature requires on the current device.
*
* Always includes camera and microphone. Also includes
* `WRITE_EXTERNAL_STORAGE` on API 28 and below, since scoped storage
* (API 29+) lets an app insert into MediaStore's shared Movies
* collection without it, but below that it's required to save the
* recorded video into the gallery.
*/
val REQUIRED: Array<String> = buildList {
add(Manifest.permission.CAMERA)
add(Manifest.permission.RECORD_AUDIO)
// Scoped storage (API 29+) lets an app insert into MediaStore's
// shared Movies collection without this permission; below that, it's
// required to save the recorded video into the gallery.
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.P) {
add(Manifest.permission.WRITE_EXTERNAL_STORAGE)
}
}.toTypedArray()
/**
* @brief Checks whether every permission in [REQUIRED] is currently granted.
* @param context Context used to query permission state.
* @return true if all required permissions are granted, false otherwise.
*/
fun allGranted(context: Context): Boolean =
REQUIRED.all { permission ->
ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED
}
/**
* @brief Lists which of [REQUIRED] are not currently granted.
* @param context Context used to query permission state.
* @return The subset of [REQUIRED] that is not yet granted; empty if all are granted.
*/
fun missing(context: Context): List<String> =
REQUIRED.filter { permission ->
ContextCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED