diff options
author | Arc Wang <arcwang@google.com> | 2021-06-05 20:38:07 +0800 |
---|---|---|
committer | Arc Wang <arcwang@google.com> | 2021-06-22 11:04:24 +0800 |
commit | 4a97095e364f279194af6b7d5721e8892ae12cf9 (patch) | |
tree | 01637f53bcef87270ef72d5ef2a1c4dfb02eae5c /src/com/android/settings/widget/LoadingViewController.java | |
parent | f64fbb683024acfa0fca8df47facca7aaac7967b (diff) |
Fix 'No Apps' UI issues of ManageApplications
Fixes below UI issues
- "No Apps" may not show in fragments of profile tab.
Fix it by using ConstraintLayout to specify alignments
of each view and removing extra padding.
-- "No Apps" may flicker by moving position.
The flicker is from unnecessary visibility changes.
This change integrates empty view visibility
control in LoadingViewController to simplify code
and avoid unnecessary visibility changes.
Bug: 189390795
Bug: 183398721
Test: atest com.android.settings.deviceinfo
make RunSettingsRoboTests -j ROBOTEST_FILTER=com.android.settings.deviceinfo
Manual visual, observe UI
Settings -> Storage -> Games
Settings -> Notifications -> App Settings
Settings > Apps > Special app access > Media management apps
Change-Id: I9a2500f2fd1dd073ab88f26187541964719523d0
Diffstat (limited to 'src/com/android/settings/widget/LoadingViewController.java')
-rw-r--r-- | src/com/android/settings/widget/LoadingViewController.java | 68 |
1 files changed, 60 insertions, 8 deletions
diff --git a/src/com/android/settings/widget/LoadingViewController.java b/src/com/android/settings/widget/LoadingViewController.java index 294e55e7ea..66eebf387b 100644 --- a/src/com/android/settings/widget/LoadingViewController.java +++ b/src/com/android/settings/widget/LoadingViewController.java @@ -22,34 +22,66 @@ import android.view.View; import android.view.animation.Animation; import android.view.animation.AnimationUtils; +import androidx.annotation.Nullable; + /** - * A helper class that manages show/hide loading spinner. + * A helper class that manages show/hide loading spinner, content view and empty view (optional). */ public class LoadingViewController { private static final long DELAY_SHOW_LOADING_CONTAINER_THRESHOLD_MS = 100L; - public final Handler mFgHandler; - public final View mLoadingView; - public final View mContentView; + private final Handler mFgHandler; + private final View mLoadingView; + private final View mContentView; + private final View mEmptyView; public LoadingViewController(View loadingView, View contentView) { + this(loadingView, contentView, null /* emptyView*/); + } + + public LoadingViewController(View loadingView, View contentView, @Nullable View emptyView) { mLoadingView = loadingView; mContentView = contentView; + mEmptyView = emptyView; mFgHandler = new Handler(Looper.getMainLooper()); } private Runnable mShowLoadingContainerRunnable = new Runnable() { public void run() { - handleLoadingContainer(false /* done */, false /* animate */); + showLoadingView(); } }; + /** + * Shows content view and hides loading view & empty view. + */ public void showContent(boolean animate) { // Cancel any pending task to show the loading animation and show the list of // apps directly. mFgHandler.removeCallbacks(mShowLoadingContainerRunnable); - handleLoadingContainer(true /* show */, animate); + handleLoadingContainer(true /* showContent */, false /* showEmpty*/, animate); + } + + /** + * Shows empty view and hides loading view & content view. + */ + public void showEmpty(boolean animate) { + if (mEmptyView == null) { + return; + } + + // Cancel any pending task to show the loading animation and show the list of + // apps directly. + mFgHandler.removeCallbacks(mShowLoadingContainerRunnable); + handleLoadingContainer(false /* showContent */, true /* showEmpty */, animate); + } + + /** + * Shows loading view and hides content view & empty view. + */ + public void showLoadingView() { + handleLoadingContainer(false /* showContent */, false /* showEmpty */, false /* animate */); } public void showLoadingViewDelayed() { @@ -57,8 +89,9 @@ public class LoadingViewController { mShowLoadingContainerRunnable, DELAY_SHOW_LOADING_CONTAINER_THRESHOLD_MS); } - public void handleLoadingContainer(boolean done, boolean animate) { - handleLoadingContainer(mLoadingView, mContentView, done, animate); + private void handleLoadingContainer(boolean showContent, boolean showEmpty, boolean animate) { + handleLoadingContainer(mLoadingView, mContentView, mEmptyView, + showContent, showEmpty, animate); } /** @@ -75,6 +108,25 @@ public class LoadingViewController { setViewShown(content, done, animate); } + /** + * Show/hide loading view and content view and empty view. + * + * @param loading The loading spinner view + * @param content The content view + * @param empty The empty view shows no item summary to users. + * @param showContent If true, content is set visible and loading is set invisible. + * @param showEmpty If true, empty is set visible and loading is set invisible. + * @param animate Whether or not content/loading views should animate in/out. + */ + public static void handleLoadingContainer(View loading, View content, View empty, + boolean showContent, boolean showEmpty, boolean animate) { + if (empty != null) { + setViewShown(empty, showEmpty, animate); + } + setViewShown(content, showContent, animate); + setViewShown(loading, !showContent && !showEmpty, animate); + } + private static void setViewShown(final View view, boolean shown, boolean animate) { if (animate) { Animation animation = AnimationUtils.loadAnimation(view.getContext(), |