TYPE3
[iec.git] / src / type3_AndroidCloud / anbox-master / android / appmgr / src / org / anbox / appmgr / AppListFragment.java
1 /*
2  * The MIT License (MIT)
3  *
4  * Copyright 2016 Arnab Chakraborty. http://arnab.ch
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy of this
7  * software and associated documentation files (the "Software"), to deal in the Software
8  * without restriction, including without limitation the rights to use, copy, modify,
9  * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to the following
11  * conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all copies
14  * or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
17  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
18  * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
20  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
21  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22  */
23
24 package org.anbox.appmgr;
25
26 import android.os.Bundle;
27 import android.support.v4.app.ListFragment;
28 import android.support.v4.app.LoaderManager;
29 import android.support.v4.content.Loader;
30 import java.util.ArrayList;
31
32 /**
33  * Created by Arnab Chakraborty
34  */
35 public class AppListFragment extends ListFragment implements LoaderManager.LoaderCallbacks<ArrayList<AppModel>> {
36     AppListAdapter mAdapter;
37
38     @Override
39     public void onActivityCreated(Bundle savedInstanceState) {
40         super.onActivityCreated(savedInstanceState);
41
42         setEmptyText("No Applications");
43
44         mAdapter = new AppListAdapter(getActivity());
45         setListAdapter(mAdapter);
46
47         // till the data is loaded display a spinner
48         setListShown(false);
49
50         // create the loader to load the apps list in background
51         getLoaderManager().initLoader(0, null, this);
52     }
53
54     @Override
55     public Loader<ArrayList<AppModel>> onCreateLoader(int id, Bundle bundle) {
56         return new AppsLoader(getActivity());
57     }
58
59     @Override
60     public void onLoadFinished(Loader<ArrayList<AppModel>> loader, ArrayList<AppModel> apps) {
61         mAdapter.setData(apps);
62
63         if (isResumed()) {
64             setListShown(true);
65         } else {
66             setListShownNoAnimation(true);
67         }
68     }
69
70     @Override
71     public void onLoaderReset(Loader<ArrayList<AppModel>> loader) {
72         mAdapter.setData(null);
73     }
74 }