From 2076970d4052dd6438896f35319018202c6d7b73 Mon Sep 17 00:00:00 2001 From: Marvin W Date: Wed, 5 Aug 2020 15:48:51 +0200 Subject: [PATCH] Disable fragment transitions when system transitions/animations are disabled Fixes #1119 --- README.md | 2 +- .../src/main/AndroidManifest.xml | 2 +- .../org/microg/gms/ui/SettingsFragment.java | 13 +-- ...xposureNotificationsPreferencesFragment.kt | 4 +- .../gms/ui/PushNotificationAllAppsFragment.kt | 2 +- .../microg/gms/ui/PushNotificationFragment.kt | 2 +- .../ui/PushNotificationPreferencesFragment.kt | 4 +- .../org/microg/gms/ui/SafetyNetFragment.kt | 2 +- .../main/kotlin/org/microg/gms/ui/Utils.kt | 33 +++++++ .../src/main/res/navigation/nav_settings.xml | 90 ++++--------------- .../src/main/res/values/themes.xml | 4 +- 11 files changed, 66 insertions(+), 92 deletions(-) diff --git a/README.md b/README.md index b378765f..4b47042c 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ microG GmsCore is a FLOSS (Free/Libre Open Source Software) framework to allow a License ------- - Copyright 2013-2019 microG Project Team + Copyright 2013-2020 microG Project Team Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/play-services-core/src/main/AndroidManifest.xml b/play-services-core/src/main/AndroidManifest.xml index 0b38be30..2b9e6147 100644 --- a/play-services-core/src/main/AndroidManifest.xml +++ b/play-services-core/src/main/AndroidManifest.xml @@ -360,7 +360,7 @@ android:name="org.microg.gms.auth.login.LoginActivity" android:configChanges="keyboardHidden|orientation|screenSize" android:exported="true" - android:theme="@style/LoginBlueTheme"> + android:theme="@style/Theme.LoginBlue"> diff --git a/play-services-core/src/main/java/org/microg/gms/ui/SettingsFragment.java b/play-services-core/src/main/java/org/microg/gms/ui/SettingsFragment.java index b8dba158..c0e37661 100644 --- a/play-services-core/src/main/java/org/microg/gms/ui/SettingsFragment.java +++ b/play-services-core/src/main/java/org/microg/gms/ui/SettingsFragment.java @@ -4,6 +4,7 @@ import android.os.Build; import android.os.Bundle; import androidx.annotation.Nullable; +import androidx.navigation.NavOptions; import androidx.navigation.fragment.NavHostFragment; import com.google.android.gms.R; @@ -43,7 +44,7 @@ public class SettingsFragment extends ResourceSettingsFragment { private void updateDetails() { findPreference(PREF_ABOUT).setSummary(getString(R.string.about_version_str, AboutFragment.getSelfVersion(getContext()))); findPreference(PREF_ABOUT).setOnPreferenceClickListener(preference -> { - NavHostFragment.findNavController(SettingsFragment.this).navigate(R.id.openAbout); + UtilsKt.navigate(NavHostFragment.findNavController(SettingsFragment.this), getContext(), R.id.openAbout, null); return true; }); if (GcmPrefs.get(getContext()).isEnabled()) { @@ -55,7 +56,7 @@ public class SettingsFragment extends ResourceSettingsFragment { findPreference(PREF_GCM).setSummary(R.string.service_status_disabled_short); } findPreference(PREF_GCM).setOnPreferenceClickListener(preference -> { - NavHostFragment.findNavController(SettingsFragment.this).navigate(R.id.openGcmSettings); + UtilsKt.navigate(NavHostFragment.findNavController(SettingsFragment.this), getContext(), R.id.openGcmSettings, null); return true; }); @@ -75,7 +76,7 @@ public class SettingsFragment extends ResourceSettingsFragment { findPreference(PREF_SNET).setSummary(R.string.service_status_disabled_short); } findPreference(PREF_SNET).setOnPreferenceClickListener(preference -> { - NavHostFragment.findNavController(SettingsFragment.this).navigate(R.id.openSafetyNetSettings); + UtilsKt.navigate(NavHostFragment.findNavController(SettingsFragment.this), getContext(), R.id.openSafetyNetSettings, null); return true; }); @@ -86,7 +87,7 @@ public class SettingsFragment extends ResourceSettingsFragment { // Preferences.splitBackendString(unifiedNlPrefs.getGeocoderBackends()).length; // findPreference(PREF_UNIFIEDNLP).setSummary(getResources().getQuantityString(R.plurals.pref_unifiednlp_summary, backendCount, backendCount)); findPreference(PREF_UNIFIEDNLP).setOnPreferenceClickListener(preference -> { - NavHostFragment.findNavController(SettingsFragment.this).navigate(R.id.openUnifiedNlpSettings); + UtilsKt.navigate(NavHostFragment.findNavController(SettingsFragment.this), getContext(), R.id.openUnifiedNlpSettings, null); return true; }); if (Build.VERSION.SDK_INT >= 21) { @@ -97,7 +98,7 @@ public class SettingsFragment extends ResourceSettingsFragment { findPreference(PREF_EXPOSURE).setSummary(R.string.service_status_disabled_short); } findPreference(PREF_EXPOSURE).setOnPreferenceClickListener(preference -> { - NavHostFragment.findNavController(SettingsFragment.this).navigate(R.id.openExposureNotificationSettings); + UtilsKt.navigate(NavHostFragment.findNavController(SettingsFragment.this), getContext(), R.id.openExposureNotificationSettings, null); return true; }); } else { @@ -107,7 +108,7 @@ public class SettingsFragment extends ResourceSettingsFragment { boolean checkinEnabled = CheckinPrefs.get(getContext()).isEnabled(); findPreference(PREF_CHECKIN).setSummary(checkinEnabled ? R.string.service_status_enabled_short : R.string.service_status_disabled_short); findPreference(PREF_CHECKIN).setOnPreferenceClickListener(preference -> { - NavHostFragment.findNavController(SettingsFragment.this).navigate(R.id.openCheckinSettings); + UtilsKt.navigate(NavHostFragment.findNavController(SettingsFragment.this), getContext(), R.id.openCheckinSettings, null); return true; }); } diff --git a/play-services-core/src/main/kotlin/org/microg/gms/ui/ExposureNotificationsPreferencesFragment.kt b/play-services-core/src/main/kotlin/org/microg/gms/ui/ExposureNotificationsPreferencesFragment.kt index 6d27fa22..69bf37c5 100644 --- a/play-services-core/src/main/kotlin/org/microg/gms/ui/ExposureNotificationsPreferencesFragment.kt +++ b/play-services-core/src/main/kotlin/org/microg/gms/ui/ExposureNotificationsPreferencesFragment.kt @@ -40,7 +40,7 @@ class ExposureNotificationsPreferencesFragment : PreferenceFragmentCompat() { collectedRpis = preferenceScreen.findPreference("pref_exposure_collected_rpis") ?: collectedRpis advertisingId = preferenceScreen.findPreference("pref_exposure_advertising_id") ?: advertisingId collectedRpis.onPreferenceClickListener = Preference.OnPreferenceClickListener { - findNavController().navigate(R.id.openExposureRpis) + findNavController().navigate(requireContext(), R.id.openExposureRpis) true } } @@ -82,7 +82,7 @@ class ExposureNotificationsPreferencesFragment : PreferenceFragmentCompat() { pref.title = applicationInfo.loadLabel(context.packageManager) pref.icon = applicationInfo.loadIcon(context.packageManager) pref.onPreferenceClickListener = Preference.OnPreferenceClickListener { - findNavController().navigate(R.id.openExposureAppDetails, bundleOf( + findNavController().navigate(requireContext(), R.id.openExposureAppDetails, bundleOf( "package" to applicationInfo.packageName )) true diff --git a/play-services-core/src/main/kotlin/org/microg/gms/ui/PushNotificationAllAppsFragment.kt b/play-services-core/src/main/kotlin/org/microg/gms/ui/PushNotificationAllAppsFragment.kt index af330906..94095117 100644 --- a/play-services-core/src/main/kotlin/org/microg/gms/ui/PushNotificationAllAppsFragment.kt +++ b/play-services-core/src/main/kotlin/org/microg/gms/ui/PushNotificationAllAppsFragment.kt @@ -67,7 +67,7 @@ class PushNotificationAllAppsFragment : PreferenceFragmentCompat() { pref.icon = applicationInfo?.loadIcon(context.packageManager) ?: AppCompatResources.getDrawable(context, android.R.mipmap.sym_def_app_icon) pref.onPreferenceClickListener = Preference.OnPreferenceClickListener { - findNavController().navigate(R.id.openGcmAppDetailsFromAll, bundleOf( + findNavController().navigate(requireContext(), R.id.openGcmAppDetailsFromAll, bundleOf( "package" to app.packageName )) true diff --git a/play-services-core/src/main/kotlin/org/microg/gms/ui/PushNotificationFragment.kt b/play-services-core/src/main/kotlin/org/microg/gms/ui/PushNotificationFragment.kt index 6345c62b..2af9e2cf 100644 --- a/play-services-core/src/main/kotlin/org/microg/gms/ui/PushNotificationFragment.kt +++ b/play-services-core/src/main/kotlin/org/microg/gms/ui/PushNotificationFragment.kt @@ -49,7 +49,7 @@ class PushNotificationFragment : Fragment(R.layout.push_notification_fragment) { override fun onOptionsItemSelected(item: MenuItem): Boolean { return when (item.itemId) { MENU_ADVANCED -> { - findNavController().navigate(R.id.openGcmAdvancedSettings) + findNavController().navigate(requireContext(), R.id.openGcmAdvancedSettings) true } else -> super.onOptionsItemSelected(item) diff --git a/play-services-core/src/main/kotlin/org/microg/gms/ui/PushNotificationPreferencesFragment.kt b/play-services-core/src/main/kotlin/org/microg/gms/ui/PushNotificationPreferencesFragment.kt index d9301b9d..43e5fca8 100644 --- a/play-services-core/src/main/kotlin/org/microg/gms/ui/PushNotificationPreferencesFragment.kt +++ b/play-services-core/src/main/kotlin/org/microg/gms/ui/PushNotificationPreferencesFragment.kt @@ -47,7 +47,7 @@ class PushNotificationPreferencesFragment : PreferenceFragmentCompat() { pushAppsAll = preferenceScreen.findPreference("pref_push_apps_all") ?: pushAppsAll pushAppsNone = preferenceScreen.findPreference("pref_push_apps_none") ?: pushAppsNone pushAppsAll.onPreferenceClickListener = Preference.OnPreferenceClickListener { - findNavController().navigate(R.id.openAllGcmApps) + findNavController().navigate(requireContext(), R.id.openAllGcmApps) true } } @@ -89,7 +89,7 @@ class PushNotificationPreferencesFragment : PreferenceFragmentCompat() { pref.title = applicationInfo.loadLabel(context.packageManager) pref.icon = applicationInfo.loadIcon(context.packageManager) pref.onPreferenceClickListener = Preference.OnPreferenceClickListener { - findNavController().navigate(R.id.openGcmAppDetails, bundleOf( + findNavController().navigate(requireContext(), R.id.openGcmAppDetails, bundleOf( "package" to app.packageName )) true diff --git a/play-services-core/src/main/kotlin/org/microg/gms/ui/SafetyNetFragment.kt b/play-services-core/src/main/kotlin/org/microg/gms/ui/SafetyNetFragment.kt index b611a1ac..7daf880d 100644 --- a/play-services-core/src/main/kotlin/org/microg/gms/ui/SafetyNetFragment.kt +++ b/play-services-core/src/main/kotlin/org/microg/gms/ui/SafetyNetFragment.kt @@ -48,7 +48,7 @@ class SafetyNetFragment : Fragment(R.layout.safety_net_fragment) { override fun onOptionsItemSelected(item: MenuItem): Boolean { return when (item.itemId) { MENU_ADVANCED -> { - findNavController().navigate(R.id.openSafetyNetAdvancedSettings) + findNavController().navigate(requireContext(), R.id.openSafetyNetAdvancedSettings) true } else -> super.onOptionsItemSelected(item) diff --git a/play-services-core/src/main/kotlin/org/microg/gms/ui/Utils.kt b/play-services-core/src/main/kotlin/org/microg/gms/ui/Utils.kt index aac8b144..9bfce06a 100644 --- a/play-services-core/src/main/kotlin/org/microg/gms/ui/Utils.kt +++ b/play-services-core/src/main/kotlin/org/microg/gms/ui/Utils.kt @@ -5,9 +5,17 @@ package org.microg.gms.ui +import android.content.Context import android.content.pm.ApplicationInfo import android.content.pm.PackageManager +import android.os.Build +import android.os.Bundle +import android.provider.Settings import android.util.Log +import androidx.annotation.IdRes +import androidx.navigation.NavController +import androidx.navigation.navOptions +import androidx.navigation.ui.R fun PackageManager.getApplicationInfoIfExists(packageName: String?, flags: Int = 0): ApplicationInfo? = packageName?.let { try { @@ -17,3 +25,28 @@ fun PackageManager.getApplicationInfoIfExists(packageName: String?, flags: Int = null } } + +fun NavController.navigate(context: Context, @IdRes resId: Int, args: Bundle? = null) { + navigate(resId, args, if (context.systemAnimationsEnabled) navOptions { + anim { + enter = R.anim.nav_default_enter_anim + exit = R.anim.nav_default_exit_anim + popEnter = R.anim.nav_default_pop_enter_anim + popExit = R.anim.nav_default_pop_exit_anim + } + } else null) +} + +val Context.systemAnimationsEnabled: Boolean + get() { + val duration: Float + val transition: Float + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + duration = Settings.Global.getFloat(contentResolver, Settings.Global.ANIMATOR_DURATION_SCALE, 1f) + transition = Settings.Global.getFloat(contentResolver, Settings.Global.TRANSITION_ANIMATION_SCALE, 1f) + } else { + duration = Settings.System.getFloat(contentResolver, Settings.System.ANIMATOR_DURATION_SCALE, 1f) + transition = Settings.System.getFloat(contentResolver, Settings.System.TRANSITION_ANIMATION_SCALE, 1f) + } + return duration != 0f && transition != 0f + } diff --git a/play-services-core/src/main/res/navigation/nav_settings.xml b/play-services-core/src/main/res/navigation/nav_settings.xml index f8c633a7..b5393954 100644 --- a/play-services-core/src/main/res/navigation/nav_settings.xml +++ b/play-services-core/src/main/res/navigation/nav_settings.xml @@ -11,60 +11,28 @@ android:label="@string/gms_settings_name"> + app:destination="@id/nav_unlp" /> + app:destination="@id/selfcheckFragment" /> + app:destination="@id/checkinFragment" /> + app:destination="@id/gcmFragment" /> + app:destination="@id/safetyNetFragment" /> + app:destination="@id/googleMoreFragment" /> + app:destination="@id/exposureNotificationsFragment" /> + app:destination="@id/aboutFragment" /> + app:destination="@id/gcmAppFragment" /> + app:destination="@id/gcmAllAppsFragment" /> + app:destination="@id/gcmAdvancedFragment" /> + app:destination="@id/gcmAppFragment" /> + app:destination="@id/safetyNetAdvancedFragment" /> + app:destination="@id/exposureNotificationsRpisFragment" /> + app:destination="@id/exposureNotificationsAppFragment" /> true -