diff options
author | linus_lee <llee@cyngn.com> | 2014-10-02 12:41:23 -0700 |
---|---|---|
committer | linus_lee <llee@cyngn.com> | 2014-11-20 12:03:04 -0800 |
commit | c31ae4d5e088270223183acfc83faf4268297bdf (patch) | |
tree | 2cefc7560f352c7dd23fa77d9eb2ea63f174add9 /src/com/cyngn/eleven/widgets | |
parent | 93e7c9facbf9fe1f1e85c7e7d18fb40aaf47ef2e (diff) | |
download | android_packages_apps_Eleven-c31ae4d5e088270223183acfc83faf4268297bdf.tar.gz android_packages_apps_Eleven-c31ae4d5e088270223183acfc83faf4268297bdf.tar.bz2 android_packages_apps_Eleven-c31ae4d5e088270223183acfc83faf4268297bdf.zip |
Eleven: Add loading dialogs to all fragments
Some fragments intentionally don't show the loading dialog on recreate to prevent a split second flash on the screen
Loading is delayed by 300ms for better user experience
Fixed a small bug in the RecentStore
https://cyanogen.atlassian.net/browse/MUSIC-63
Change-Id: I5bd7ee25234d0146887f152bbcb57fed6bbb2c01
Diffstat (limited to 'src/com/cyngn/eleven/widgets')
-rw-r--r-- | src/com/cyngn/eleven/widgets/LoadingEmptyContainer.java | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/com/cyngn/eleven/widgets/LoadingEmptyContainer.java b/src/com/cyngn/eleven/widgets/LoadingEmptyContainer.java new file mode 100644 index 0000000..0522439 --- /dev/null +++ b/src/com/cyngn/eleven/widgets/LoadingEmptyContainer.java @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2014 Cyanogen, Inc. + */ +package com.cyngn.eleven.widgets; + +import android.content.Context; +import android.os.Handler; +import android.util.AttributeSet; +import android.view.View; +import android.widget.FrameLayout; +import android.widget.LinearLayout; +import android.widget.TextView; + +import com.cyngn.eleven.R; + +/** + * This class is the default empty state view for most listviews/fragments + * It allows the ability to set a main text, a main highlight text and a secondary text + * By default this container has some strings loaded, but other classes can call the apis to change + * the text + */ +public class LoadingEmptyContainer extends FrameLayout { + private static final int LOADING_DELAY = 300; + + private Handler mHandler; + private Runnable mShowLoadingRunnable; + + public LoadingEmptyContainer(Context context, AttributeSet attrs) { + super(context, attrs); + + mHandler = new Handler(); + mShowLoadingRunnable = new Runnable() { + @Override + public void run() { + findViewById(R.id.progressbar).setVisibility(View.VISIBLE); + getNoResultsContainer().setVisibility(View.INVISIBLE); + } + }; + } + + @Override + protected void onFinishInflate() { + super.onFinishInflate(); + + hideAll(); + } + + public void hideAll() { + findViewById(R.id.progressbar).setVisibility(View.INVISIBLE); + getNoResultsContainer().setVisibility(View.INVISIBLE); + } + + public void showLoading() { + hideAll(); + + if (!mHandler.hasCallbacks(mShowLoadingRunnable)) { + mHandler.postDelayed(mShowLoadingRunnable, LOADING_DELAY); + } + } + + public void showNoResults() { + mHandler.removeCallbacks(mShowLoadingRunnable); + + findViewById(R.id.progressbar).setVisibility(View.INVISIBLE); + getNoResultsContainer().setVisibility(View.VISIBLE); + } + + public NoResultsContainer getNoResultsContainer() { + return (NoResultsContainer)findViewById(R.id.no_results_container); + } +} |