For #1072: Adds cap to auto bounce
parent
7accf07d48
commit
486bfc2d68
|
@ -17,6 +17,7 @@ import org.mozilla.fenix.R
|
||||||
import android.animation.ValueAnimator
|
import android.animation.ValueAnimator
|
||||||
import androidx.interpolator.view.animation.FastOutSlowInInterpolator
|
import androidx.interpolator.view.animation.FastOutSlowInInterpolator
|
||||||
import org.mozilla.fenix.ext.increaseTapArea
|
import org.mozilla.fenix.ext.increaseTapArea
|
||||||
|
import org.mozilla.fenix.utils.Settings
|
||||||
|
|
||||||
class QuickActionSheet @JvmOverloads constructor(
|
class QuickActionSheet @JvmOverloads constructor(
|
||||||
context: Context,
|
context: Context,
|
||||||
|
@ -42,16 +43,24 @@ class QuickActionSheet @JvmOverloads constructor(
|
||||||
bounceSheet(quickActionSheetBehavior)
|
bounceSheet(quickActionSheetBehavior)
|
||||||
}
|
}
|
||||||
|
|
||||||
bounceSheet(quickActionSheetBehavior, bounceAnimationLength)
|
val settings = Settings.getInstance(context)
|
||||||
|
if (settings.shouldAutoBounceQuickActionSheet) {
|
||||||
|
settings.incrementAutomaticBounceQuickActionSheetCount()
|
||||||
|
bounceSheet(quickActionSheetBehavior, demoBounceAnimationLength)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun bounceSheet(
|
private fun bounceSheet(
|
||||||
quickActionSheetBehavior: QuickActionSheetBehavior,
|
quickActionSheetBehavior: QuickActionSheetBehavior,
|
||||||
duration: Long = quickBounceAnimationLength
|
duration: Long = bounceAnimationLength
|
||||||
) {
|
) {
|
||||||
val normalPeekHeight = quickActionSheetBehavior.peekHeight
|
val normalPeekHeight = quickActionSheetBehavior.peekHeight
|
||||||
|
|
||||||
|
val peakHeightMultiplier = if (duration == demoBounceAnimationLength)
|
||||||
|
demoBounceAnimationPeekHeightMultiplier else bounceAnimationPeekHeightMultiplier
|
||||||
|
|
||||||
val valueAnimator = ValueAnimator.ofFloat(normalPeekHeight.toFloat(),
|
val valueAnimator = ValueAnimator.ofFloat(normalPeekHeight.toFloat(),
|
||||||
normalPeekHeight * bounceAnimationPeekHeightMultiplier)
|
normalPeekHeight * peakHeightMultiplier)
|
||||||
|
|
||||||
valueAnimator.addUpdateListener {
|
valueAnimator.addUpdateListener {
|
||||||
quickActionSheetBehavior.peekHeight = (it.animatedValue as Float).toInt()
|
quickActionSheetBehavior.peekHeight = (it.animatedValue as Float).toInt()
|
||||||
|
@ -66,8 +75,9 @@ class QuickActionSheet @JvmOverloads constructor(
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val grabHandleIncreasedTapArea = 50
|
const val grabHandleIncreasedTapArea = 50
|
||||||
const val bounceAnimationLength = 500L
|
const val demoBounceAnimationLength = 600L
|
||||||
const val quickBounceAnimationLength = 400L
|
const val bounceAnimationLength = 400L
|
||||||
|
const val demoBounceAnimationPeekHeightMultiplier = 4.5f
|
||||||
const val bounceAnimationPeekHeightMultiplier = 3f
|
const val bounceAnimationPeekHeightMultiplier = 3f
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,16 @@ class Settings private constructor(context: Context) {
|
||||||
val isTelemetryEnabled: Boolean
|
val isTelemetryEnabled: Boolean
|
||||||
get() = preferences.getBoolean(appContext.getPreferenceKey(R.string.pref_key_telemetry), true)
|
get() = preferences.getBoolean(appContext.getPreferenceKey(R.string.pref_key_telemetry), true)
|
||||||
|
|
||||||
|
val shouldAutoBounceQuickActionSheet: Boolean
|
||||||
|
get() = autoBounceQuickActionSheetCount < 2
|
||||||
|
|
||||||
|
private val autoBounceQuickActionSheetCount: Int
|
||||||
|
get() = (preferences.getInt(appContext.getPreferenceKey(R.string.pref_key_bounce_quick_action), 0))
|
||||||
|
|
||||||
|
fun incrementAutomaticBounceQuickActionSheetCount() {
|
||||||
|
preferences.edit().putInt(appContext.getPreferenceKey(R.string.pref_key_bounce_quick_action),
|
||||||
|
autoBounceQuickActionSheetCount + 1).apply()
|
||||||
|
}
|
||||||
fun setDefaultSearchEngineByName(name: String) {
|
fun setDefaultSearchEngineByName(name: String) {
|
||||||
preferences.edit()
|
preferences.edit()
|
||||||
.putString(appContext.getPreferenceKey(R.string.pref_key_search_engine), name)
|
.putString(appContext.getPreferenceKey(R.string.pref_key_search_engine), name)
|
||||||
|
|
|
@ -36,4 +36,5 @@
|
||||||
<!-- Search Settings -->
|
<!-- Search Settings -->
|
||||||
<string name="pref_key_show_search_suggestions" translatable="false">pref_key_show_search_suggestions</string>
|
<string name="pref_key_show_search_suggestions" translatable="false">pref_key_show_search_suggestions</string>
|
||||||
|
|
||||||
|
<string name = "pref_key_bounce_quick_action" translatable="false">pref_key_bounce_quick_action</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in New Issue