diff options
author | dhacker29 <dhackerdvm@gmail.com> | 2017-12-05 13:13:24 -0600 |
---|---|---|
committer | Aaron Kling <webgeek1234@gmail.com> | 2017-12-05 13:13:24 -0600 |
commit | b3a48c7e6e9d2631099e9415e9979ee0f8d1e95c (patch) | |
tree | 9f7e0832d9f910238932e7e6f6e4d8d46d892edf /src/org/lineageos/appdrawer/AppDrawerActivity.java | |
download | android_packages_apps_AppDrawer-cm-14.1.tar.gz android_packages_apps_AppDrawer-cm-14.1.tar.bz2 android_packages_apps_AppDrawer-cm-14.1.zip |
Initial commitcm-14.1
Diffstat (limited to 'src/org/lineageos/appdrawer/AppDrawerActivity.java')
-rw-r--r-- | src/org/lineageos/appdrawer/AppDrawerActivity.java | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/src/org/lineageos/appdrawer/AppDrawerActivity.java b/src/org/lineageos/appdrawer/AppDrawerActivity.java new file mode 100644 index 0000000..dd851a1 --- /dev/null +++ b/src/org/lineageos/appdrawer/AppDrawerActivity.java @@ -0,0 +1,128 @@ +/* + * Copyright (C) 2015 The CyanogenMod Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.lineageos.appdrawer; + +import android.app.Activity; +import android.app.AlertDialog; +import android.app.ProgressDialog; +import android.content.ActivityNotFoundException; +import android.content.Intent; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager; +import android.os.AsyncTask; +import android.os.Bundle; +import android.view.View; +import android.widget.AdapterView; +import android.widget.GridView; +import android.widget.Toast; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class AppDrawerActivity extends Activity { + private PackageManager packageManager = null; + private List<ApplicationInfo> applist = null; + private ApplicationAdapter listadaptor = null; + private GridView grid; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + packageManager = getPackageManager(); + + new LoadApplications().execute(); + + grid = (GridView)findViewById(R.id.grid); + grid.setAdapter(listadaptor); + grid.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView<?> parent, View view, int position, long id) { + ApplicationInfo app = applist.get(position); + try { + Intent intent = packageManager + .getLaunchIntentForPackage(app.packageName); + + if (null != intent) { + startActivity(intent); + } + } catch (ActivityNotFoundException e) { + Toast.makeText(AppDrawerActivity.this, e.getMessage(), + Toast.LENGTH_LONG).show(); + } catch (Exception e) { + Toast.makeText(AppDrawerActivity.this, e.getMessage(), + Toast.LENGTH_LONG).show(); + } + } + }); + } + + private List<ApplicationInfo> checkForLaunchIntent(List<ApplicationInfo> list) { + ArrayList<ApplicationInfo> applist = new ArrayList<ApplicationInfo>(); + for (ApplicationInfo info : list) { + try { + if (null != packageManager.getLaunchIntentForPackage(info.packageName)) { + applist.add(info); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + Collections.sort(applist, new ApplicationInfo.DisplayNameComparator(packageManager)); + return applist; + } + + private class LoadApplications extends AsyncTask<Void, Void, Void> { + private ProgressDialog progress = null; + + @Override + protected Void doInBackground(Void... params) { + applist = checkForLaunchIntent(packageManager.getInstalledApplications( + PackageManager.GET_META_DATA)); + listadaptor = new ApplicationAdapter(AppDrawerActivity.this, + R.layout.grid_item, applist); + + return null; + } + + @Override + protected void onCancelled() { + super.onCancelled(); + } + + @Override + protected void onPostExecute(Void result) { + grid.setAdapter(listadaptor); + progress.dismiss(); + super.onPostExecute(result); + } + + @Override + protected void onPreExecute() { + progress = ProgressDialog.show(AppDrawerActivity.this, null, + "Loading application info..."); + super.onPreExecute(); + } + + @Override + protected void onProgressUpdate(Void... values) { + super.onProgressUpdate(values); + } + } +} |