Commit 2fcee5ff authored by Amit Kumar's avatar Amit Kumar
Browse files

Add uninstall feature

parent 4d086943
......@@ -6,7 +6,7 @@ android {
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "org.indin.blisslauncher"
minSdkVersion 23
minSdkVersion 22
targetSdkVersion 26
versionCode 1
versionName "1.0"
......
......@@ -13,6 +13,7 @@ public class AppItem {
private Intent intent;
private String componentName;
private boolean iconFromIconPack;
private boolean isSystemApp;
// Folder specific
private boolean belongsToFolder;
......@@ -20,14 +21,16 @@ public class AppItem {
private String folderID;
private List<AppItem> subApps;
public AppItem(CharSequence label, String packageName, Drawable icon,
Intent intent, String componentName, boolean iconFromIconPack) {
Intent intent, String componentName, boolean iconFromIconPack, boolean isSystemApp) {
this.label = label;
this.packageName = packageName;
this.icon = icon;
this.intent = intent;
this.componentName = componentName;
this.iconFromIconPack = iconFromIconPack;
this.isSystemApp = isSystemApp;
}
public CharSequence getLabel() {
......@@ -50,6 +53,14 @@ public class AppItem {
return icon;
}
public boolean isSystemApp(){
return isSystemApp;
}
public void setSystemApp(boolean isSystemApp){
this.isSystemApp = isSystemApp;
}
public void setIcon(Drawable icon) {
this.icon = icon;
}
......
......@@ -23,13 +23,13 @@ public class AppUtil {
/**
* Uses the PackageManager to find all launchable apps.
*/
public static List<AppItem> loadLaunchableApps(Context context, int iconWidth) {
public static List<AppItem> loadLaunchableApps(Context context) {
PackageManager packageManager = context.getPackageManager();
List<ApplicationInfo> apps = packageManager.getInstalledApplications(0);
List<AppItem> launchableApps = new ArrayList<>();
for (ApplicationInfo app : apps) {
String packageName = app.packageName;
for (ApplicationInfo appInfo : apps) {
String packageName = appInfo.packageName;
Intent intent = packageManager.getLaunchIntentForPackage(packageName);
if (intent != null) {
String componentName = intent.getComponent().toString();
......@@ -41,19 +41,26 @@ public class AppUtil {
appIcon = IconPackUtil.getIconFromIconPack(context, componentName);
}
if (appIcon == null) {
appIcon = app.loadIcon(packageManager);
appIcon = appInfo.loadIcon(packageManager);
iconFromIconPack = false;
appIcon = GraphicsUtil.scaleImage(context, appIcon, 1f, iconWidth);
appIcon = GraphicsUtil.scaleImage(context, appIcon, 1f);
appIcon = GraphicsUtil.maskImage(context, appIcon);
}
boolean isSystemApp = false;
if ((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
isSystemApp = true;
}
AppItem launchableApp = new AppItem(
app.loadLabel(packageManager),
appInfo.loadLabel(packageManager),
packageName,
appIcon,
intent,
componentName,
iconFromIconPack
iconFromIconPack,
isSystemApp
);
launchableApps.add(launchableApp);
}
......@@ -112,7 +119,7 @@ public class AppUtil {
/**
* Create an AppItem object given just a package name
*/
public static AppItem createAppItem(Context context, String packageName, int iconWidth) {
public static AppItem createAppItem(Context context, String packageName) {
try {
PackageManager packageManager = context.getPackageManager();
ApplicationInfo appInfo = packageManager.getApplicationInfo(packageName, 0);
......@@ -130,7 +137,7 @@ public class AppUtil {
if (appIcon == null) {
appIcon = appInfo.loadIcon(packageManager);
iconFromIconPack = false;
appIcon = GraphicsUtil.scaleImage(context, appIcon, 1f, iconWidth);
appIcon = GraphicsUtil.scaleImage(context, appIcon, 1f);
appIcon = GraphicsUtil.maskImage(context, appIcon);
}
} else {
......@@ -138,13 +145,13 @@ public class AppUtil {
iconFromIconPack = false;
}
AppItem appItem = new AppItem(appInfo.loadLabel(packageManager),
return new AppItem(appInfo.loadLabel(packageManager),
packageName,
appIcon,
intent,
componentName,
iconFromIconPack);
return appItem;
iconFromIconPack,
(appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0);
} catch (PackageManager.NameNotFoundException e) {
return null;
}
......
......@@ -42,7 +42,7 @@ public class GraphicsUtil {
* Takes 1 or more drawables and merges them to form a single Drawable.
* However, if more than 4 drawables are provided, only the first 4 are used.
*/
public static Drawable generateFolderIcon(Context context, int iconWidth, Drawable... sources) {
public static Drawable generateFolderIcon(Context context, Drawable... sources) {
for (Drawable d : sources) {
if (!(d instanceof BitmapDrawable)) {
Log.d(TAG, "Unknown type of icon found");
......@@ -81,7 +81,7 @@ public class GraphicsUtil {
Drawable output = new BitmapDrawable(context.getResources(), bitmap);
if (IconPackUtil.iconPackPresent) {
output = GraphicsUtil.scaleImage(context, output, 1f, iconWidth);
output = GraphicsUtil.scaleImage(context, output, 1f);
output = GraphicsUtil.maskImage(context, output);
}
return output;
......@@ -91,19 +91,18 @@ public class GraphicsUtil {
* A utility method that simplifies calls to the generateFolderIcon() method that
* expects an array of Drawables.
*/
public static Drawable generateFolderIcon(Context context, AppItem app, int iconWidth) {
public static Drawable generateFolderIcon(Context context, AppItem app) {
Drawable[] drawables = new Drawable[app.getSubApps().size()];
for (int i = 0; i < app.getSubApps().size(); i++) {
drawables[i] = app.getSubApps().get(i).getIcon();
}
return generateFolderIcon(context, iconWidth, drawables);
return generateFolderIcon(context, drawables);
}
/**
* Scales icons to match the icon pack
*/
public static Drawable scaleImage(Context context, Drawable image, float scaleFactor,
int iconWidth) {
public static Drawable scaleImage(Context context, Drawable image, float scaleFactor) {
if ((image == null) || !(image instanceof BitmapDrawable)) {
return image;
}
......
......@@ -77,9 +77,7 @@
android:rowCount="4"
android:minHeight="230dp"
android:minWidth="240dp"
android:useDefaultMargins="true">
</GridLayout>
android:useDefaultMargins="true" />
</RelativeLayout>
......
......@@ -12,9 +12,8 @@
<org.indin.blisslaunchero.SquareImageView
android:id="@+id/app_icon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginBottom="4dp"
android:background="@drawable/rounded_corners_icon"
android:foreground="?attr/selectableItemBackground"
android:scaleType="fitCenter" />
......@@ -26,6 +25,7 @@
android:ellipsize="end"
android:gravity="center"
android:maxLines="1"
android:layout_marginBottom="4dp"
android:textColor="@color/app_label_color"
android:textSize="@dimen/labelSize" />
</LinearLayout>
......
......@@ -3,8 +3,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/appGrid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:columnCount="@integer/col_count"
android:rowCount="6"
android:paddingLeft="@dimen/app_grid_padding"
android:paddingRight="@dimen/app_grid_padding"/>
......@@ -21,5 +21,6 @@
<!--uninstall icon size -->
<dimen name="uninstallIconSize">36dp</dimen>
<dimen name="dp_32">32dp</dimen>
</resources>
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment