2 * The MIT License (MIT)
4 * Copyright 2016 Arnab Chakraborty. http://arnab.ch
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
13 * The above copyright notice and this permission notice shall be included in all copies
14 * or substantial portions of the Software.
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.
24 package org.anbox.appmgr;
26 import android.content.Intent;
27 import android.os.Bundle;
28 import android.support.v4.app.LoaderManager;
29 import android.support.v4.content.Loader;
30 import android.view.View;
31 import android.widget.GridView;
33 import java.util.ArrayList;
36 * Created by Arnab Chakraborty
38 public class AppsGridFragment extends GridFragment implements LoaderManager.LoaderCallbacks<ArrayList<AppModel>> {
40 AppListAdapter mAdapter;
43 public void onActivityCreated(Bundle savedInstanceState) {
44 super.onActivityCreated(savedInstanceState);
46 setEmptyText("No Applications");
48 mAdapter = new AppListAdapter(getActivity());
49 setGridAdapter(mAdapter);
51 // till the data is loaded display a spinner
54 // create the loader to load the apps list in background
55 getLoaderManager().initLoader(0, null, this);
59 public Loader<ArrayList<AppModel>> onCreateLoader(int id, Bundle bundle) {
60 return new AppsLoader(getActivity());
64 public void onLoadFinished(Loader<ArrayList<AppModel>> loader, ArrayList<AppModel> apps) {
65 mAdapter.setData(apps);
70 setGridShownNoAnimation(true);
75 public void onLoaderReset(Loader<ArrayList<AppModel>> loader) {
76 mAdapter.setData(null);
80 public void onGridItemClick(GridView g, View v, int position, long id) {
81 AppModel app = (AppModel) getGridAdapter().getItem(position);
83 Intent intent = getActivity().getPackageManager().getLaunchIntentForPackage(app.getApplicationPackageName());
86 startActivity(intent);