Skip to content

Commit

Permalink
Options for list to hide useless apps
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyAdshead committed Feb 21, 2017
1 parent 48c802d commit d0cb9e2
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 8 deletions.
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 51 additions & 4 deletions app/src/main/java/com/baronkiko/launcherhijack/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,70 @@
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

public class MainActivity extends AppCompatActivity {
private ListView mListAppInfo;
private MenuItem launcher, sysApps;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(com.baronkiko.launcherhijack.R.layout.activity_main);
public boolean onCreateOptionsMenu(Menu menu)
{
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.mainmenu, menu);
sysApps = menu.getItem(0);
launcher = menu.getItem(1);
launcher.setChecked(true);
sysApps.setChecked(true);
UpdateList();
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.launcher:
launcher.setChecked(!launcher.isChecked());
if (launcher.isChecked())
sysApps.setChecked(true);
UpdateList();
return true;

case R.id.sysApps:
sysApps.setChecked(!sysApps.isChecked());
UpdateList();
return true;

default:
return super.onOptionsItemSelected(item);
}
}

private void UpdateList()
{
boolean sys = sysApps.isChecked();
boolean l = launcher.isChecked();

mListAppInfo = (ListView) findViewById(R.id.lvApps);
// create new adapter
AppInfoAdapter adapter = new AppInfoAdapter(this, Utilities.getInstalledApplication(this, 2), getPackageManager());
AppInfoAdapter adapter = new AppInfoAdapter(this, Utilities.getInstalledApplication(this, l, sys), getPackageManager());
// set adapter to list view
mListAppInfo.setAdapter(adapter);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(com.baronkiko.launcherhijack.R.layout.activity_main);

mListAppInfo = (ListView) findViewById(R.id.lvApps);

// implement event when an item on list view is selected
mListAppInfo.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
Expand Down
7 changes: 3 additions & 4 deletions app/src/main/java/com/baronkiko/launcherhijack/Utilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ public class Utilities {
/*
* Get all installed application on mobile and return a list
* @param c Context of application
* @param type 0 = all, 1 = user apps, 2 = launchers
* @return list of installed applications
*/
public static List<ApplicationInfo> getInstalledApplication(Context c, int type) {
public static List<ApplicationInfo> getInstalledApplication(Context c, boolean launchers, boolean systemApps) {
List<ApplicationInfo> list, results;

if (type < 2) // Get all apps
if (!launchers) // Get all apps
list = c.getPackageManager().getInstalledApplications(PackageManager.GET_META_DATA);
else // Get launchers
{
Expand All @@ -36,7 +35,7 @@ public static List<ApplicationInfo> getInstalledApplication(Context c, int type)
list.add(resolveInfo.activityInfo.applicationInfo);
}

if (type == 0)
if (!systemApps)
return list;

// Filter system apps
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/res/menu/mainmenu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">

<item android:title="Hide System Apps"
android:checkable="true"
android:id="@+id/sysApps" />
<item android:title="Launchers Only"
android:id="@+id/launcher"
android:checkable="true" />
</menu>

0 comments on commit d0cb9e2

Please sign in to comment.