2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-17 15:26:23 +00:00

[fenix] For https://github.com/mozilla-mobile/fenix/issues/22851 Add logo animation for wallpapers

This commit is contained in:
Arturo Mejia 2022-01-26 18:06:56 -05:00 committed by mergify[bot]
parent 07bc214d56
commit 9de688d1c9
6 changed files with 101 additions and 1 deletions

View File

@ -21,7 +21,7 @@ import org.mozilla.fenix.ext.components
import org.mozilla.fenix.helpers.HomeActivityTestRule import org.mozilla.fenix.helpers.HomeActivityTestRule
// BEFORE INCREASING THESE VALUES, PLEASE CONSULT WITH THE PERF TEAM. // BEFORE INCREASING THESE VALUES, PLEASE CONSULT WITH THE PERF TEAM.
private const val EXPECTED_SUPPRESSION_COUNT = 20 private const val EXPECTED_SUPPRESSION_COUNT = 21
@Suppress("TopLevelPropertyNaming") // it's silly this would have a different naming convention b/c no const @Suppress("TopLevelPropertyNaming") // it's silly this would have a different naming convention b/c no const
private val EXPECTED_RUNBLOCKING_RANGE = 0..1 // CI has +1 counts compared to local runs: increment these together private val EXPECTED_RUNBLOCKING_RANGE = 0..1 // CI has +1 counts compared to local runs: increment these together
private const val EXPECTED_RECYCLER_VIEW_CONSTRAINT_LAYOUT_CHILDREN = 4 private const val EXPECTED_RECYCLER_VIEW_CONSTRAINT_LAYOUT_CHILDREN = 4

View File

@ -5,8 +5,10 @@
package org.mozilla.fenix package org.mozilla.fenix
import android.content.Context import android.content.Context
import android.os.StrictMode
import mozilla.components.support.locale.LocaleManager import mozilla.components.support.locale.LocaleManager
import mozilla.components.support.locale.LocaleManager.getSystemDefault import mozilla.components.support.locale.LocaleManager.getSystemDefault
import org.mozilla.fenix.ext.components
/** /**
* A single source for setting feature flags that are mostly based on build type. * A single source for setting feature flags that are mostly based on build type.
@ -96,4 +98,16 @@ object FeatureFlags {
* Enables history improvement features. * Enables history improvement features.
*/ */
val historyImprovementFeatures = Config.channel.isNightlyOrDebug val historyImprovementFeatures = Config.channel.isNightlyOrDebug
/**
* Enables themed wallpapers feature.
*/
fun isThemedWallpapersFeatureEnabled(context: Context): Boolean {
val strictMode = context.components.strictMode
return strictMode.resetAfter(StrictMode.allowThreadDiskReads()) {
val langTag = LocaleManager.getCurrentLocale(context)
?.toLanguageTag() ?: getSystemDefault().toLanguageTag()
listOf("en-US", "es-US").contains(langTag) && Config.channel.isNightlyOrDebug
}
}
} }

View File

@ -17,6 +17,7 @@ import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.View.AccessibilityDelegate import android.view.View.AccessibilityDelegate
import android.view.ViewGroup import android.view.ViewGroup
import android.view.ViewTreeObserver
import android.view.accessibility.AccessibilityEvent import android.view.accessibility.AccessibilityEvent
import android.widget.Button import android.widget.Button
import android.widget.LinearLayout import android.widget.LinearLayout
@ -824,6 +825,25 @@ class HomeFragment : Fragment() {
// triggered to cause an automatic update on warm start (no tab selection occurs). So we // triggered to cause an automatic update on warm start (no tab selection occurs). So we
// update it manually here. // update it manually here.
requireComponents.useCases.sessionUseCases.updateLastAccess() requireComponents.useCases.sessionUseCases.updateLastAccess()
if (shouldAnimateLogoForWallpaper()) {
_binding?.sessionControlRecyclerView?.viewTreeObserver?.addOnGlobalLayoutListener(
homeLayoutListenerForLogoAnimation
)
}
}
// To try to find a good time to show the logo animation, we are waiting until all
// the sub-recyclerviews (recentBookmarks, collections, recentTabs,recentVisits
// and pocketStories) on the home screen have been layout.
private val homeLayoutListenerForLogoAnimation = object : ViewTreeObserver.OnGlobalLayoutListener {
override fun onGlobalLayout() {
_binding?.let { safeBindings ->
requireComponents.wallpaperManager.animateLogoIfNeeded(safeBindings.wordmark)
safeBindings.sessionControlRecyclerView.viewTreeObserver.removeOnGlobalLayoutListener(
this
)
}
}
} }
override fun onPause() { override fun onPause() {
@ -1203,6 +1223,23 @@ class HomeFragment : Fragment() {
} }
} }
// We want to show the animation in a time when the user less distracted
// The Heuristics are:
// 1) The animation hasn't shown before.
// 2) The user has onboarded.
// 3) It's the third time the user enters the app.
// 4) The user is part of the right audience.
@Suppress("MagicNumber")
private fun shouldAnimateLogoForWallpaper(): Boolean {
val localContext = context ?: return false
val settings = localContext.settings()
return shouldEnableWallpaper() && settings.shouldAnimateFirefoxLogo &&
onboarding.userHasBeenOnboarded() &&
settings.numberOfAppLaunches >= 3 &&
FeatureFlags.isThemedWallpapersFeatureEnabled(localContext)
}
private fun shouldEnableWallpaper() = private fun shouldEnableWallpaper() =
FeatureFlags.showWallpapers && !(activity as HomeActivity).themeManager.currentTheme.isPrivate FeatureFlags.showWallpapers && !(activity as HomeActivity).themeManager.currentTheme.isPrivate

View File

@ -443,6 +443,16 @@ class Settings(private val appContext: Context) : PreferencesHolder {
featureFlag = FeatureFlags.inactiveTabs featureFlag = FeatureFlags.inactiveTabs
) )
/**
* Indicates if the Firefox logo on the home screen should be animated,
* to show users that they can change the wallpaper by tapping on the Firefox logo.
*/
var shouldAnimateFirefoxLogo by featureFlagPreference(
appContext.getPreferenceKey(R.string.pref_key_show_logo_animation),
default = FeatureFlags.showWallpapers,
featureFlag = FeatureFlags.showWallpapers
)
/** /**
* Indicates if the user has enabled the search term tab groups feature. * Indicates if the user has enabled the search term tab groups feature.
*/ */

View File

@ -4,11 +4,15 @@
package org.mozilla.fenix.wallpapers package org.mozilla.fenix.wallpapers
import android.animation.AnimatorSet
import android.animation.ObjectAnimator
import android.content.Context import android.content.Context
import android.content.res.Configuration import android.content.res.Configuration
import android.graphics.Bitmap import android.graphics.Bitmap
import android.graphics.BitmapFactory import android.graphics.BitmapFactory
import android.graphics.drawable.BitmapDrawable import android.graphics.drawable.BitmapDrawable
import android.os.Handler
import android.os.Looper
import android.view.View import android.view.View
import androidx.appcompat.app.AppCompatDelegate import androidx.appcompat.app.AppCompatDelegate
import mozilla.components.support.base.log.logger.Logger import mozilla.components.support.base.log.logger.Logger
@ -135,6 +139,39 @@ class WallpaperManager(
} }
} }
/**
* Animates the Firefox logo, if it hasn't been animated before, otherwise nothing will happen.
* After animating the first time, the [Settings.shouldAnimateFirefoxLogo] setting
* will be updated.
*/
@Suppress("MagicNumber")
fun animateLogoIfNeeded(logo: View) {
if (!settings.shouldAnimateFirefoxLogo) {
return
}
Handler(Looper.getMainLooper()).postDelayed(
{
val animator1 = ObjectAnimator.ofFloat(logo, "rotation", 0f, 10f)
val animator2 = ObjectAnimator.ofFloat(logo, "rotation", 10f, 0f)
val animator3 = ObjectAnimator.ofFloat(logo, "rotation", 0f, 10f)
val animator4 = ObjectAnimator.ofFloat(logo, "rotation", 10f, 0f)
animator1.duration = 200
animator2.duration = 200
animator3.duration = 200
animator4.duration = 200
val set = AnimatorSet()
set.play(animator1).before(animator2).after(animator3).before(animator4)
set.start()
settings.shouldAnimateFirefoxLogo = false
},
ANIMATION_DELAY_MS
)
}
companion object { companion object {
const val DEFAULT_RESOURCE = R.attr.homeBackground const val DEFAULT_RESOURCE = R.attr.homeBackground
val defaultWallpaper = Wallpaper( val defaultWallpaper = Wallpaper(
@ -144,5 +181,6 @@ class WallpaperManager(
isDark = false, isDark = false,
themeCollection = WallpaperThemeCollection.None themeCollection = WallpaperThemeCollection.None
) )
private const val ANIMATION_DELAY_MS = 1500L
} }
} }

View File

@ -191,6 +191,7 @@
<string name="pref_key_wallpapers" translatable="false">pref_key_wallpapers</string> <string name="pref_key_wallpapers" translatable="false">pref_key_wallpapers</string>
<string name="pref_key_current_wallpaper" translatable="false">pref_key_current_wallpaper</string> <string name="pref_key_current_wallpaper" translatable="false">pref_key_current_wallpaper</string>
<string name="pref_key_wallpapers_switched_by_logo_tap">pref_key_wallpapers_switched_by_logo_tap</string> <string name="pref_key_wallpapers_switched_by_logo_tap">pref_key_wallpapers_switched_by_logo_tap</string>
<string name="pref_key_show_logo_animation" translatable="false">pref_key_show_logo_animation</string>
<string name="pref_key_encryption_key_generated" translatable="false">pref_key_encryption_key_generated</string> <string name="pref_key_encryption_key_generated" translatable="false">pref_key_encryption_key_generated</string>