From 03e33037e80d9785d4ec9b646a70a94a8bf33b04 Mon Sep 17 00:00:00 2001 From: Imanol Fernandez Date: Thu, 29 Aug 2019 17:28:46 +0200 Subject: [PATCH] Hide scrollbar in Awesome bar suggestion list if all the content fits. (#1701) --- .../vrbrowser/ui/views/CustomListView.java | 20 +++++++++---------- .../ui/widgets/SuggestionsWidget.java | 3 ++- app/src/main/res/layout/list_popup_window.xml | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/views/CustomListView.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/views/CustomListView.java index 3fb794d12..2780a540b 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/views/CustomListView.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/views/CustomListView.java @@ -45,18 +45,18 @@ public boolean isInTouchMode() { protected void onLayout(boolean changed, int l, int t, int r, int b) { super.onLayout(changed, l, t, r, b); - boolean scrollVisible = false; - - if (getChildCount() > 0) { - View first = getChildAt(0); - View last = getChildAt(getChildCount() - 1); - if (first.getTop() < 0 || last.getBottom() > getHeight()) { - scrollVisible = true; - } + boolean fits = getCount() == 0; + + // Check if all the items fit on the ListView + int last = getLastVisiblePosition(); + int first = getFirstVisiblePosition(); + if (!fits && first == 0 && last == getCount() - 1) { + fits = getChildAt(first).getTop() >= 0 && getChildAt(last).getBottom() <= getHeight(); } - setVerticalScrollBarEnabled(scrollVisible); - setFastScrollAlwaysVisible(scrollVisible); + // Hide scrollbar is all item fit. + setVerticalScrollBarEnabled(!fits); + setFastScrollAlwaysVisible(!fits); } diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/SuggestionsWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/SuggestionsWidget.java index f6f414fc9..aba8ab914 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/SuggestionsWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/SuggestionsWidget.java @@ -23,13 +23,14 @@ import org.mozilla.gecko.util.ThreadUtils; import org.mozilla.vrbrowser.R; import org.mozilla.vrbrowser.audio.AudioEngine; +import org.mozilla.vrbrowser.ui.views.CustomListView; import java.util.ArrayList; import java.util.List; public class SuggestionsWidget extends UIWidget implements WidgetManagerDelegate.FocusChangeListener { - private ListView mList; + private CustomListView mList; private SuggestionsAdapter mAdapter; private Animation mScaleUpAnimation; private Animation mScaleDownAnimation; diff --git a/app/src/main/res/layout/list_popup_window.xml b/app/src/main/res/layout/list_popup_window.xml index 881cb8cfe..b32c18d82 100644 --- a/app/src/main/res/layout/list_popup_window.xml +++ b/app/src/main/res/layout/list_popup_window.xml @@ -4,7 +4,7 @@ android:layout_height="match_parent" android:layout_width="match_parent"> -