Skip to content

Commit

Permalink
For mozilla-mobile#5509 - Show the toolbar and floating buttons when …
Browse files Browse the repository at this point in the history
…TalkBack is enabled
  • Loading branch information
Ionut Cristian Bedregeanu committed Oct 5, 2021
1 parent 041b154 commit 4fc74d9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
18 changes: 17 additions & 1 deletion app/src/main/java/org/mozilla/focus/browser/DisplayToolbar.kt
Expand Up @@ -6,8 +6,13 @@ package org.mozilla.focus.browser

import android.content.Context
import android.util.AttributeSet
import android.view.accessibility.AccessibilityManager
import com.google.android.material.appbar.AppBarLayout
import kotlinx.android.synthetic.main.browser_display_toolbar.view.*
import com.google.android.material.appbar.AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS
import com.google.android.material.appbar.AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL
import com.google.android.material.appbar.AppBarLayout.LayoutParams.SCROLL_FLAG_SNAP
import kotlinx.android.synthetic.main.browser_display_toolbar.view.browserToolbar
import kotlinx.android.synthetic.main.browser_display_toolbar.view.urlbar

/**
* The toolbar of the BrowserFragment; displaying the URL and other controls.
Expand All @@ -22,6 +27,17 @@ class DisplayToolbar(

@Suppress("MagicNumber") // A mathematical expression - No need to add constants for 100% and 50%.
override fun onOffsetChanged(appBarLayout: AppBarLayout, verticalOffset: Int) {

val accessibilityManager = context.getSystemService(Context.ACCESSIBILITY_SERVICE) as AccessibilityManager
if (accessibilityManager.isTouchExplorationEnabled) {
(urlbar.layoutParams as LayoutParams).scrollFlags = LayoutParams.SCROLL_FLAG_NO_SCROLL
browserToolbar.alpha = 1f
return
} else {
(urlbar.layoutParams as LayoutParams).scrollFlags =
SCROLL_FLAG_SCROLL or SCROLL_FLAG_ENTER_ALWAYS or SCROLL_FLAG_SNAP
}

// When scrolling the toolbar away we want to fade out the content on the toolbar
// with an alpha animation. This will avoid that the text clashes with the status bar.

Expand Down
Expand Up @@ -13,6 +13,7 @@
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import android.util.AttributeSet;
import android.view.View;
import android.view.accessibility.AccessibilityManager;

/**
* A Behavior implementation that will hide/show a FloatingActionButton based on whether an AppBarLayout
Expand Down Expand Up @@ -58,7 +59,11 @@ public void onDependentViewRemoved(CoordinatorLayout parent, FloatingActionButto

@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
if (verticalOffset == 0 && !visible) {
// Always display floating buttons if Talk Back is enabled
AccessibilityManager accessibilityManager =
(AccessibilityManager) layout.getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);

if (verticalOffset == 0 && !visible || (accessibilityManager != null && accessibilityManager.isTouchExplorationEnabled())) {
showButton();
} else if (Math.abs(verticalOffset) >= appBarLayout.getTotalScrollRange() && visible) {
hideButton();
Expand Down
Expand Up @@ -9,7 +9,6 @@
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import android.util.AttributeSet;
import android.view.View;
import android.view.accessibility.AccessibilityManager;
import android.view.animation.AnimationUtils;

import org.mozilla.focus.R;
Expand All @@ -32,17 +31,11 @@ public FloatingEraseButton(Context context, AttributeSet attrs, int defStyleAttr
public void updateSessionsCount(int tabCount) {
final CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) getLayoutParams();
final FloatingActionButtonBehavior behavior = (FloatingActionButtonBehavior) params.getBehavior();
AccessibilityManager accessibilityManager = (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);

keepHidden = tabCount != 1;

if (behavior != null) {
if (accessibilityManager != null && accessibilityManager.isTouchExplorationEnabled()) {
// Always display erase button if Talk Back is enabled
behavior.setAutoHideEnabled(false);
} else {
behavior.setAutoHideEnabled(!keepHidden);
}
behavior.setAutoHideEnabled(!keepHidden);
}

if (keepHidden) {
Expand Down

0 comments on commit 4fc74d9

Please sign in to comment.