π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Replace deprecated Ensu system bar and haptic APIs
Manav Rathi296909068142
diff --git a/android/apps/ensu/app/src/main/java/io/ente/ensu/MainActivity.kt b/android/apps/ensu/app/src/main/java/io/ente/ensu/MainActivity.ktindex 37471fee8e..811f6d47d1 100644--- a/android/apps/ensu/app/src/main/java/io/ente/ensu/MainActivity.kt+++ b/android/apps/ensu/app/src/main/java/io/ente/ensu/MainActivity.kt@@ -1,21 +1,44 @@package io.ente.ensu+import android.os.Buildimport android.os.Bundleimport androidx.activity.ComponentActivity+import androidx.activity.SystemBarStyleimport androidx.activity.compose.setContent+import androidx.activity.enableEdgeToEdge+import androidx.compose.foundation.background+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.safeDrawingPadding+import androidx.compose.ui.Modifier+import androidx.compose.ui.graphics.toArgbimport androidx.lifecycle.viewmodel.compose.viewModel-import io.ente.ensu.designsystem.Themeimport io.ente.ensu.designsystem.EnsuColor-import io.ente.ensu.platform.ApplySystemBars+import io.ente.ensu.designsystem.Themeclass MainActivity : ComponentActivity() {override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)+ enableEdgeToEdge(+ navigationBarStyle = SystemBarStyle.auto(+ EnsuColor.backgroundBaseLight.toArgb(),+ EnsuColor.backgroundBaseDark.toArgb()+ )+ )+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {+ window.isNavigationBarContrastEnforced = false+ }setContent {Theme {- ApplySystemBars(backgroundColor = EnsuColor.backgroundBase())val appViewModel: AppViewModel = viewModel()- App(appViewModel = appViewModel)+ Box(+ modifier = Modifier+ .fillMaxSize()+ .background(EnsuColor.backgroundBase())+ .safeDrawingPadding()+ ) {+ App(appViewModel = appViewModel)+ }}}}diff --git a/android/apps/ensu/app/src/main/java/io/ente/ensu/platform/Haptics.kt b/android/apps/ensu/app/src/main/java/io/ente/ensu/platform/Haptics.ktindex a9ca97cd8d..4d91e3fcc8 100644--- a/android/apps/ensu/app/src/main/java/io/ente/ensu/platform/Haptics.kt+++ b/android/apps/ensu/app/src/main/java/io/ente/ensu/platform/Haptics.kt@@ -2,10 +2,9 @@ package io.ente.ensu.platformimport android.content.Contextimport android.os.Build+import android.os.VibrationAttributesimport android.os.VibrationEffect-import android.os.Vibratorimport android.os.VibratorManager-import android.provider.Settingsimport android.view.HapticFeedbackConstantsimport android.view.Viewimport androidx.compose.runtime.Composable@@ -16,20 +15,28 @@ import androidx.compose.ui.platform.LocalViewclass Haptics(private val context: Context,- private val view: View?+ private val view: View) {fun perform(type: HapticFeedbackType) {- if (!isHapticsEnabled(context)) return-- if (shouldForceVibrationFallback()) {- vibrate(type)+ val feedback = mapToHapticConstant(type)+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {+ if (!view.performHapticFeedback(feedback)) {+ view.performHapticFeedback(HapticFeedbackConstants.CONTEXT_CLICK)+ }return}- val performed = view?.performHapticFeedback(mapToHapticConstant(type)) ?: false- if (!performed) {- vibrate(type)+ if (!shouldForceVibrationFallback() && view.performHapticFeedback(feedback)) return++ val vibrator = context.getSystemService(VibratorManager::class.java)?.defaultVibrator ?: return+ val effect = when (type) {+ HapticFeedbackType.LongPress -> VibrationEffect.EFFECT_HEAVY_CLICK+ else -> VibrationEffect.EFFECT_TICK}+ vibrator.vibrate(+ VibrationEffect.createPredefined(effect),+ VibrationAttributes.createForUsage(VibrationAttributes.USAGE_TOUCH)+ )}private fun shouldForceVibrationFallback(): Boolean {@@ -51,54 +58,6 @@ class Haptics(else -> HapticFeedbackConstants.KEYBOARD_TAP}}-- private fun vibrate(type: HapticFeedbackType) {- val vibrator = getVibrator() ?: return- if (!vibrator.hasVibrator()) return-- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {- val effect = when (type) {- HapticFeedbackType.LongPress -> VibrationEffect.EFFECT_HEAVY_CLICK- HapticFeedbackType.TextHandleMove -> VibrationEffect.EFFECT_TICK- else -> VibrationEffect.EFFECT_TICK- }- vibrator.vibrate(VibrationEffect.createPredefined(effect))- return- }-- val (duration, amplitude) = when (type) {- HapticFeedbackType.LongPress -> 40L to 180- HapticFeedbackType.TextHandleMove -> 10L to 60- else -> 10L to 60- }-- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {- vibrator.vibrate(VibrationEffect.createOneShot(duration, amplitude))- } else {- @Suppress("DEPRECATION")- vibrator.vibrate(duration)- }- }-- private fun getVibrator(): Vibrator? {- return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {- val manager = context.getSystemService(VibratorManager::class.java)- manager?.defaultVibrator- } else {- @Suppress("DEPRECATION")- context.getSystemService(Context.VIBRATOR_SERVICE) as? Vibrator- }- }-- private fun isHapticsEnabled(context: Context): Boolean {- return try {- // The manual vibration fallback must honor the system haptics setting.- @Suppress("DEPRECATION")- Settings.System.getInt(context.contentResolver, Settings.System.HAPTIC_FEEDBACK_ENABLED, 1) == 1- } catch (_: Throwable) {- true- }- }}@Composablediff --git a/android/apps/ensu/app/src/main/java/io/ente/ensu/platform/SystemBars.kt b/android/apps/ensu/app/src/main/java/io/ente/ensu/platform/SystemBars.ktdeleted file mode 100644index af16915870..0000000000--- a/android/apps/ensu/app/src/main/java/io/ente/ensu/platform/SystemBars.kt+++ /dev/null@@ -1,29 +0,0 @@-package io.ente.ensu.platform--import android.app.Activity-import androidx.compose.foundation.isSystemInDarkTheme-import androidx.compose.runtime.Composable-import androidx.compose.runtime.SideEffect-import androidx.compose.ui.graphics.Color-import androidx.compose.ui.graphics.toArgb-import androidx.compose.ui.platform.LocalView-import androidx.core.view.WindowInsetsControllerCompat--@Composable-fun ApplySystemBars(backgroundColor: Color) {- val view = LocalView.current- val isDark = isSystemInDarkTheme()-- // These setters still control bar colors on older Android versions.- @Suppress("DEPRECATION")- SideEffect {- val window = (view.context as Activity).window- window.statusBarColor = backgroundColor.toArgb()- window.navigationBarColor = backgroundColor.toArgb()-- WindowInsetsControllerCompat(window, view).apply {- isAppearanceLightStatusBars = !isDark- isAppearanceLightNavigationBars = !isDark- }- }-}