Skip to content

Commit

Permalink
Merge pull request #5 from javiersantos/system-apps
Browse files Browse the repository at this point in the history
Add System Apps
  • Loading branch information
javiersantos committed Jun 4, 2015
2 parents 4b5e1fb + c54aa45 commit fdf9762
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
32 changes: 26 additions & 6 deletions app/src/main/java/com/javiersantos/mlmanager/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,17 @@ public class MainActivity extends AppCompatActivity {

// General variables
private List<String> appListName = new ArrayList<String>();
private List<String> appListApk = new ArrayList<String>();
private List<String> appListAPK = new ArrayList<String>();
private List<String> appListVersion = new ArrayList<String>();
private List<String> appListSource = new ArrayList<String>();
private List<String> appListData = new ArrayList<String>();
private List<Drawable> appListIcon = new ArrayList<Drawable>();
private List<String> appSystemListName = new ArrayList<String>();
private List<String> appSystemListAPK = new ArrayList<String>();
private List<String> appSystemListVersion = new ArrayList<String>();
private List<String> appSystemListSource = new ArrayList<String>();
private List<String> appSystemListData = new ArrayList<String>();
private List<Drawable> appSystemListIcon = new ArrayList<Drawable>();

// Configuration variables
private Boolean doubleBackToExitPressedOnce = false;
Expand All @@ -63,10 +69,12 @@ protected void onCreate(Bundle savedInstanceState) {
recyclerView.setLayoutManager(linearLayoutManager);

getInstalledApps();
AppAdapter appAdapter = new AppAdapter(createList(appListName, appListApk, appListVersion, appListSource, appListData, appListIcon), this);
AppAdapter appAdapter = new AppAdapter(createList(appListName, appListAPK, appListVersion, appListSource, appListData, appListIcon), this);
AppAdapter appSystemAdapter = new AppAdapter(createList(appSystemListName, appSystemListAPK, appSystemListVersion, appSystemListSource, appSystemListData, appSystemListIcon), this);

recyclerView.setAdapter(appAdapter);

setNavigationDrawer(appAdapter);
setNavigationDrawer(appAdapter, appSystemAdapter, recyclerView);
setFAB();

}
Expand All @@ -85,8 +93,8 @@ private void setInitialConfiguration() {
}
}

private void setNavigationDrawer(AppAdapter appAdapter) {
UtilsUI.setNavigationDrawer(this, getApplicationContext(), toolbar, appAdapter);
private void setNavigationDrawer(AppAdapter appAdapter, AppAdapter appSystemAdapter, RecyclerView recyclerView) {
UtilsUI.setNavigationDrawer(this, getApplicationContext(), toolbar, appAdapter, appSystemAdapter, recyclerView);
}

private void setFAB() {
Expand Down Expand Up @@ -138,13 +146,25 @@ public int compare(PackageInfo p1, PackageInfo p2) {
Log.i("App", packageInfo.applicationInfo.sourceDir);
Log.i("App", packageInfo.applicationInfo.dataDir);
appListName.add(packageManager.getApplicationLabel(packageInfo.applicationInfo).toString());
appListApk.add(packageInfo.packageName);
appListAPK.add(packageInfo.packageName);
appListVersion.add(packageInfo.versionName);
appListSource.add(packageInfo.applicationInfo.sourceDir);
appListData.add(packageInfo.applicationInfo.dataDir);
appListIcon.add(packageManager.getApplicationIcon(packageInfo.applicationInfo));
} else {
// System Apps
Log.i("App", packageManager.getApplicationLabel(packageInfo.applicationInfo).toString());
Log.i("App", packageInfo.packageName);
Log.i("App", packageInfo.versionName);
Log.i("App", packageInfo.applicationInfo.packageName);
Log.i("App", packageInfo.applicationInfo.sourceDir);
Log.i("App", packageInfo.applicationInfo.dataDir);
appSystemListName.add(packageManager.getApplicationLabel(packageInfo.applicationInfo).toString());
appSystemListAPK.add(packageInfo.packageName);
appSystemListVersion.add(packageInfo.versionName);
appSystemListSource.add(packageInfo.applicationInfo.sourceDir);
appSystemListData.add(packageInfo.applicationInfo.dataDir);
appSystemListIcon.add(packageManager.getApplicationIcon(packageInfo.applicationInfo));
}
}
}
Expand Down
14 changes: 11 additions & 3 deletions app/src/main/java/com/javiersantos/mlmanager/utils/UtilsUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.AdapterView;
Expand Down Expand Up @@ -37,7 +38,7 @@ public static int darker (int color, double factor) {
return Color.argb(a, Math.max( (int)(r * factor), 0 ), Math.max( (int)(g * factor), 0 ), Math.max( (int)(b * factor), 0 ) );
}

public static Drawer setNavigationDrawer (Activity activity, final Context context, Toolbar toolbar, AppAdapter appAdapter) {
public static Drawer setNavigationDrawer (Activity activity, final Context context, Toolbar toolbar, final AppAdapter appAdapter, final AppAdapter appSystemAdapter, final RecyclerView recyclerView) {
int header;
appPreferences = new AppPreferences(context);

Expand All @@ -59,6 +60,7 @@ public static Drawer setNavigationDrawer (Activity activity, final Context conte
.withStatusBarColor(UtilsUI.darker(appPreferences.getPrimaryColorPref(), 0.8))
.addDrawerItems(
new PrimaryDrawerItem().withName(context.getResources().getString(R.string.action_apps)).withIcon(FontAwesome.Icon.faw_mobile).withBadge(Integer.toString(appAdapter.getItemCount())),
new PrimaryDrawerItem().withName(context.getResources().getString(R.string.action_system_apps)).withIcon(FontAwesome.Icon.faw_android).withBadge(Integer.toString(appSystemAdapter.getItemCount())),
new DividerDrawerItem(),
new SecondaryDrawerItem().withName(context.getResources().getString(R.string.action_settings)).withIcon(FontAwesome.Icon.faw_cog),
new SecondaryDrawerItem().withName(context.getResources().getString(R.string.action_about)).withIcon(FontAwesome.Icon.faw_info)
Expand All @@ -67,10 +69,16 @@ public static Drawer setNavigationDrawer (Activity activity, final Context conte
@Override
public boolean onItemClick(AdapterView<?> parent, View view, int position, long id, IDrawerItem drawerItem) {
switch (position) {
case 2:
context.startActivity(new Intent(context, SettingsActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
case 0:
recyclerView.setAdapter(appAdapter);
break;
case 1:
recyclerView.setAdapter(appSystemAdapter);
break;
case 3:
context.startActivity(new Intent(context, SettingsActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
break;
case 4:
context.startActivity(new Intent(context, AboutActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
break;
default:
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/layout/app_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
android:id="@+id/imgIcon"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:adjustViewBounds="true"
android:maxWidth="50dp"
android:maxHeight="50dp"
android:src="@mipmap/ic_launcher"
android:layout_marginRight="14dp"
android:layout_marginEnd="20dp"
Expand Down

0 comments on commit fdf9762

Please # to comment.