2 * Copyright (C) 2014 The CyanogenMod Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.lineageos.eleven.widgets;
18 import android.content.Context;
19 import android.os.Handler;
20 import android.util.AttributeSet;
21 import android.view.View;
22 import android.widget.FrameLayout;
24 import org.lineageos.eleven.R;
27 * This class is the default empty state view for most listviews/fragments
28 * It allows the ability to set a main text, a main highlight text and a secondary text
29 * By default this container has some strings loaded, but other classes can call the apis to change
32 public class LoadingEmptyContainer extends FrameLayout {
33 private static final int LOADING_DELAY = 300;
35 private Handler mHandler;
36 private Runnable mShowLoadingRunnable;
38 public LoadingEmptyContainer(Context context, AttributeSet attrs) {
39 super(context, attrs);
41 mHandler = new Handler();
42 mShowLoadingRunnable = new Runnable() {
45 findViewById(R.id.progressbar).setVisibility(View.VISIBLE);
46 getNoResultsContainer().setVisibility(View.INVISIBLE);
52 protected void onFinishInflate() {
53 super.onFinishInflate();
58 public void hideAll() {
59 findViewById(R.id.progressbar).setVisibility(View.INVISIBLE);
60 getNoResultsContainer().setVisibility(View.INVISIBLE);
63 public void showLoading() {
66 if (!mHandler.hasCallbacks(mShowLoadingRunnable)) {
67 mHandler.postDelayed(mShowLoadingRunnable, LOADING_DELAY);
71 public void showNoResults() {
72 mHandler.removeCallbacks(mShowLoadingRunnable);
74 findViewById(R.id.progressbar).setVisibility(View.INVISIBLE);
75 getNoResultsContainer().setVisibility(View.VISIBLE);
78 public NoResultsContainer getNoResultsContainer() {
79 return (NoResultsContainer)findViewById(R.id.no_results_container);