From 39eb1073350bd4789be505f14c22b759fdd6a1e7 Mon Sep 17 00:00:00 2001 From: Colin Lee Date: Thu, 2 May 2019 15:08:49 -0500 Subject: [PATCH] For #2206: Quick Action Bar fixes, do not hide, add shadow, peek initially (#2238) --- .../fenix/components/toolbar/ToolbarUIView.kt | 14 ++++- .../quickactionsheet/QuickActionSheet.kt | 61 +++++++++++-------- .../quickactionsheet/QuickActionUIView.kt | 22 +++++-- 3 files changed, 63 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/components/toolbar/ToolbarUIView.kt b/app/src/main/java/org/mozilla/fenix/components/toolbar/ToolbarUIView.kt index 447f98ab98..8efdf0c0e3 100644 --- a/app/src/main/java/org/mozilla/fenix/components/toolbar/ToolbarUIView.kt +++ b/app/src/main/java/org/mozilla/fenix/components/toolbar/ToolbarUIView.kt @@ -48,9 +48,11 @@ class ToolbarUIView( ?: sessionManager.selectedSession view.apply { + elevation = resources.pxToDp(TOOLBAR_ELEVATION).toFloat() + setOnUrlCommitListener { actionEmitter.onNext(SearchAction.UrlCommitted(it, sessionId, state?.engine)) - false + false } onUrlClicked = { actionEmitter.onNext(SearchAction.ToolbarClicked) @@ -61,8 +63,12 @@ class ToolbarUIView( val isCustomTabSession = (session?.isCustomTabSession() == true) - urlBoxView = if (isCustomTabSession) { null } else urlBackground - progressBarGravity = if (isCustomTabSession) { PROGRESS_BOTTOM } else PROGRESS_TOP + urlBoxView = if (isCustomTabSession) { + null + } else urlBackground + progressBarGravity = if (isCustomTabSession) { + PROGRESS_BOTTOM + } else PROGRESS_TOP textColor = ContextCompat.getColor(context, R.color.photonGrey30) @@ -73,6 +79,7 @@ class ToolbarUIView( actionEmitter.onNext(SearchAction.EditingCanceled) return false } + override fun onTextChanged(text: String) { url = text actionEmitter.onNext(SearchAction.TextChanged(text)) @@ -186,6 +193,7 @@ class ToolbarUIView( } companion object { + private const val TOOLBAR_ELEVATION = 16 private const val PROGRESS_BOTTOM = 0 private const val PROGRESS_TOP = 1 const val browserActionMarginDp = 8 diff --git a/app/src/main/java/org/mozilla/fenix/quickactionsheet/QuickActionSheet.kt b/app/src/main/java/org/mozilla/fenix/quickactionsheet/QuickActionSheet.kt index 2f09cf56cb..4c438b6332 100644 --- a/app/src/main/java/org/mozilla/fenix/quickactionsheet/QuickActionSheet.kt +++ b/app/src/main/java/org/mozilla/fenix/quickactionsheet/QuickActionSheet.kt @@ -4,21 +4,21 @@ package org.mozilla.fenix.quickactionsheet +import android.animation.ValueAnimator import android.content.Context +import android.os.Bundle import android.util.AttributeSet import android.view.View -import android.widget.LinearLayout -import androidx.coordinatorlayout.widget.CoordinatorLayout -import androidx.core.widget.NestedScrollView -import com.google.android.material.bottomsheet.BottomSheetBehavior -import mozilla.components.browser.toolbar.BrowserToolbar -import org.mozilla.fenix.R -import android.animation.ValueAnimator -import android.os.Bundle import android.view.accessibility.AccessibilityEvent import android.view.accessibility.AccessibilityNodeInfo import android.widget.ImageButton +import android.widget.LinearLayout +import androidx.coordinatorlayout.widget.CoordinatorLayout +import androidx.core.widget.NestedScrollView import androidx.interpolator.view.animation.FastOutSlowInInterpolator +import com.google.android.material.bottomsheet.BottomSheetBehavior +import mozilla.components.browser.toolbar.BrowserToolbar +import org.mozilla.fenix.R import org.mozilla.fenix.utils.Settings const val POSITION_SNAP_BUFFER = 1f @@ -69,8 +69,10 @@ class QuickActionSheet @JvmOverloads constructor( val peakHeightMultiplier = if (duration == demoBounceAnimationLength) demoBounceAnimationPeekHeightMultiplier else bounceAnimationPeekHeightMultiplier - ValueAnimator.ofFloat(normalPeekHeight.toFloat(), - normalPeekHeight * peakHeightMultiplier)?.let { + ValueAnimator.ofFloat( + normalPeekHeight.toFloat(), + normalPeekHeight * peakHeightMultiplier + )?.let { it.addUpdateListener { quickActionSheetBehavior.peekHeight = (it.animatedValue as Float).toInt() @@ -88,18 +90,18 @@ class QuickActionSheet @JvmOverloads constructor( private val quickActionSheetBehavior: QuickActionSheetBehavior ) : View.AccessibilityDelegate() { private var finalState = BottomSheetBehavior.STATE_COLLAPSED - get() = when (quickActionSheetBehavior.state) { - BottomSheetBehavior.STATE_EXPANDED, - BottomSheetBehavior.STATE_HIDDEN, - BottomSheetBehavior.STATE_COLLAPSED -> { - quickActionSheetBehavior.state + get() = when (quickActionSheetBehavior.state) { + BottomSheetBehavior.STATE_EXPANDED, + BottomSheetBehavior.STATE_HIDDEN, + BottomSheetBehavior.STATE_COLLAPSED -> { + quickActionSheetBehavior.state + } + else -> field + } + set(value) { + field = value + quickActionSheetBehavior.state = value } - else -> field - } - set(value) { - field = value - quickActionSheetBehavior.state = value - } override fun performAccessibilityAction(host: View?, action: Int, args: Bundle?): Boolean { when (action) { @@ -123,11 +125,13 @@ class QuickActionSheet @JvmOverloads constructor( override fun onInitializeAccessibilityNodeInfo(host: View?, info: AccessibilityNodeInfo?) { super.onInitializeAccessibilityNodeInfo(host, info) - info?.addAction(when (finalState) { - BottomSheetBehavior.STATE_COLLAPSED, - BottomSheetBehavior.STATE_HIDDEN -> AccessibilityNodeInfo.AccessibilityAction.ACTION_EXPAND - else -> AccessibilityNodeInfo.AccessibilityAction.ACTION_COLLAPSE - }) + info?.addAction( + when (finalState) { + BottomSheetBehavior.STATE_COLLAPSED, + BottomSheetBehavior.STATE_HIDDEN -> AccessibilityNodeInfo.AccessibilityAction.ACTION_EXPAND + else -> AccessibilityNodeInfo.AccessibilityAction.ACTION_COLLAPSE + } + ) } } @@ -167,9 +171,12 @@ class QuickActionSheetBehavior( } private fun repositionQuickActionSheet(quickActionSheetContainer: NestedScrollView, toolbar: BrowserToolbar) { + val handleHeight = quickActionSheetContainer.findViewById(R.id.quick_action_sheet_handle).height if (toolbar.translationY >= toolbar.height.toFloat() - POSITION_SNAP_BUFFER) { - state = STATE_HIDDEN + peekHeight = handleHeight + state = STATE_COLLAPSED } else if (state == STATE_HIDDEN || state == STATE_SETTLING) { + peekHeight = handleHeight state = STATE_COLLAPSED } diff --git a/app/src/main/java/org/mozilla/fenix/quickactionsheet/QuickActionUIView.kt b/app/src/main/java/org/mozilla/fenix/quickactionsheet/QuickActionUIView.kt index e42fa13331..1573e3c50d 100644 --- a/app/src/main/java/org/mozilla/fenix/quickactionsheet/QuickActionUIView.kt +++ b/app/src/main/java/org/mozilla/fenix/quickactionsheet/QuickActionUIView.kt @@ -7,6 +7,7 @@ package org.mozilla.fenix.quickactionsheet import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.ImageButton import android.widget.LinearLayout import androidx.core.widget.NestedScrollView import com.google.android.material.bottomsheet.BottomSheetBehavior @@ -16,6 +17,7 @@ import io.reactivex.functions.Consumer import kotlinx.android.synthetic.main.fragment_browser.* import kotlinx.android.synthetic.main.layout_quick_action_sheet.* import kotlinx.android.synthetic.main.layout_quick_action_sheet.view.* +import mozilla.components.support.ktx.android.content.res.pxToDp import org.mozilla.fenix.R import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.ext.components @@ -35,6 +37,11 @@ class QuickActionUIView( val quickActionSheetBehavior = BottomSheetBehavior.from(nestedScrollQuickAction as View) as QuickActionSheetBehavior + // set initial state + animateOverlay(initialOverlayAlpha) + quickActionSheetBehavior.isHideable = false + quickActionSheetBehavior.peekHeight = view.resources.pxToDp(initialPeekHeightInDps) + quickActionSheetBehavior.setBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() { override fun onStateChanged(v: View, state: Int) { updateImportantForAccessibility(state) @@ -47,6 +54,8 @@ class QuickActionUIView( } override fun onSlide(bottomSheet: View, slideOffset: Float) { + quickActionSheetBehavior.peekHeight = + bottomSheet.findViewById(R.id.quick_action_sheet_handle).height animateOverlay(slideOffset) } }) @@ -80,10 +89,10 @@ class QuickActionUIView( private fun updateImportantForAccessibility(state: Int) { view.findViewById(R.id.quick_action_buttons_layout).importantForAccessibility = - if (state == BottomSheetBehavior.STATE_COLLAPSED || state == BottomSheetBehavior.STATE_HIDDEN) - View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS - else - View.IMPORTANT_FOR_ACCESSIBILITY_AUTO + if (state == BottomSheetBehavior.STATE_COLLAPSED || state == BottomSheetBehavior.STATE_HIDDEN) + View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS + else + View.IMPORTANT_FOR_ACCESSIBILITY_AUTO } private fun sendTelemetryEvent(state: Int) { @@ -99,4 +108,9 @@ class QuickActionUIView( view.quick_action_read.visibility = if (it.readable) View.VISIBLE else View.GONE view.quick_action_bookmark.isSelected = it.bookmarked } + + companion object { + const val initialOverlayAlpha = 0.5f + const val initialPeekHeightInDps = 30 + } }