Commit e0a5273b authored by Amit Kumar's avatar Amit Kumar
Browse files

Fix icon resolution and masking

parent a582c823
......@@ -22,34 +22,29 @@ public class AppUtil {
/**
* Uses the PackageManager to find all launchable apps.
* @param context
* @return
*/
public static List<AppItem> loadLaunchableApps(Context context) {
public static List<AppItem> loadLaunchableApps(Context context, int iconWidth) {
PackageManager packageManager = context.getPackageManager();
List<ApplicationInfo> apps = packageManager.getInstalledApplications(0);
List<AppItem> launchableApps = new ArrayList<>();
for(ApplicationInfo app: apps) {
for (ApplicationInfo app : apps) {
String packageName = app.packageName;
Intent intent = packageManager.getLaunchIntentForPackage(packageName);
if(intent != null) {
if (intent != null) {
String componentName = intent.getComponent().toString();
boolean iconFromIconPack = true;
Drawable appIcon;
Drawable appIcon = null;
// Load icon from icon pack if present
if(IconPackUtil.iconPackPresent) {
if (IconPackUtil.iconPackPresent) {
appIcon = IconPackUtil.getIconFromIconPack(context, componentName);
if(appIcon == null) {
appIcon = app.loadIcon(packageManager);
iconFromIconPack = false;
appIcon = GraphicsUtil.scaleImage(context, appIcon, 1f);
appIcon = GraphicsUtil.maskImage(context, appIcon);
}
} else {
}
if (appIcon == null) {
appIcon = app.loadIcon(packageManager);
iconFromIconPack = false;
appIcon = GraphicsUtil.scaleImage(context, appIcon, 1f, iconWidth);
appIcon = GraphicsUtil.maskImage(context, appIcon);
}
AppItem launchableApp = new AppItem(
......@@ -77,10 +72,6 @@ public class AppUtil {
/**
* Currently picks four apps for the dock (Phone, SMS, Browser, Camera)
*
* @param context
* @param launchableApps
* @return
*/
public static List<AppItem> getPinnedApps(Context context, List<AppItem> launchableApps) {
PackageManager pm = context.getPackageManager();
......@@ -92,10 +83,10 @@ public class AppUtil {
};
List<AppItem> pinnedApps = new ArrayList<>();
for(Intent intent:intents) {
for (Intent intent : intents) {
String packageName = getPackageNameForIntent(intent, pm);
for(AppItem app:launchableApps) {
if(app.getPackageName().equals(packageName)) {
for (AppItem app : launchableApps) {
if (app.getPackageName().equals(packageName)) {
pinnedApps.add(app);
break;
}
......@@ -108,7 +99,7 @@ public class AppUtil {
private static String getPackageNameForIntent(Intent intent, PackageManager pm) {
List<ResolveInfo> activities = pm.queryIntentActivities(intent,
PackageManager.MATCH_DEFAULT_ONLY);
if(activities.size() == 0) return null;
if (activities.size() == 0) return null;
return activities.get(0).activityInfo.packageName;
}
......@@ -120,28 +111,26 @@ public class AppUtil {
/**
* Create an AppItem object given just a package name
* @param context
* @param packageName
* @return
*/
public static AppItem createAppItem(Context context, String packageName) {
public static AppItem createAppItem(Context context, String packageName, int iconWidth) {
try {
PackageManager packageManager = context.getPackageManager();
ApplicationInfo appInfo = packageManager.getApplicationInfo(packageName, 0);
Intent intent = packageManager.getLaunchIntentForPackage(packageName);
if(intent == null)
if (intent == null) {
return null;
}
String componentName = intent.getComponent().toString();
Drawable appIcon;
boolean iconFromIconPack = true;
if(IconPackUtil.iconPackPresent) {
if (IconPackUtil.iconPackPresent) {
appIcon = IconPackUtil.getIconFromIconPack(context, componentName);
if(appIcon == null) {
if (appIcon == null) {
appIcon = appInfo.loadIcon(packageManager);
iconFromIconPack = false;
appIcon = GraphicsUtil.scaleImage(context, appIcon, 1f);
appIcon = GraphicsUtil.scaleImage(context, appIcon, 1f, iconWidth);
appIcon = GraphicsUtil.maskImage(context, appIcon);
}
} else {
......
......@@ -22,6 +22,7 @@ import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
import android.view.Display;
import android.view.DragEvent;
import android.view.Gravity;
......@@ -227,7 +228,7 @@ public class DesktopActivity extends AppCompatActivity {
}
}
AppItem appItem = AppUtil.createAppItem(this, packageName);
AppItem appItem = AppUtil.createAppItem(this, packageName, iconWidth);
if (appItem != null) {
View view = prepareApp(appItem);
int current = getCurrentAppsPageNumber();
......@@ -256,7 +257,7 @@ public class DesktopActivity extends AppCompatActivity {
// Cache icons before loading apps
IconPackUtil.cacheIconsFromIconPack(this);
launchableApps = AppUtil.loadLaunchableApps(getApplicationContext());
launchableApps = AppUtil.loadLaunchableApps(getApplicationContext(), iconWidth);
pinnedApps = AppUtil.getPinnedApps(this, launchableApps);
launchableApps.removeAll(pinnedApps);
......@@ -293,9 +294,9 @@ public class DesktopActivity extends AppCompatActivity {
double screenInches = Math.sqrt(x + y);
Log.d("debug", "Screen inches : " + screenInches);
if (screenInches <= 4.7) {
if (screenInches <= 4.5) {
nRows = 4;
} else if (screenInches <= 5.4) {
} else if (screenInches <= 5.2) {
nRows = 5;
} else {
nRows = 6;
......@@ -316,7 +317,8 @@ public class DesktopActivity extends AppCompatActivity {
hotBackground = getResources().getDrawable(R.drawable.rounded_corners_icon_hot, null);
defaultBackground = getResources().getDrawable(R.drawable.rounded_corners_icon, null);
scrollCorner = getResources().getDimensionPixelSize(R.dimen.scrollCorner);
scrollCorner = getResources().getDimensionPixelSize(R.dimen.scrollCorner) * mPagerWidth
/ 480;
wobbleAnimation = AnimationUtils.loadAnimation(this, R.anim.wobble);
wobbleReverseAnimation = AnimationUtils.loadAnimation(this, R.anim.wobble_reverse);
transparentBackground = getResources().getDrawable(R.drawable.transparent, null);
......@@ -751,7 +753,7 @@ public class DesktopActivity extends AppCompatActivity {
}
}
folderItem.setIcon(GraphicsUtil.generateFolderIcon(this, folderItem));
folderItem.setIcon(GraphicsUtil.generateFolderIcon(this, folderItem, iconWidth));
//output = prepareApp(folderItem);
return folderItem;
} else {
......@@ -799,6 +801,11 @@ public class DesktopActivity extends AppCompatActivity {
final Intent intent = app.getIntent();
icon.setImageDrawable(app.getIcon());
label.setText(app.getLabel());
if (nRows < 6) {
label.setTextSize(12);
} else {
label.setTextSize(14);
}
List<Object> tags = new ArrayList<>();
tags.add(icon);
tags.add(label);
......@@ -1245,13 +1252,9 @@ public class DesktopActivity extends AppCompatActivity {
activeFolder.getSubApps().remove(app);
assert app != null;
app.setBelongsToFolder(false);
Log.i(TAG, "removeAppFromFolder: Size:" + activeFolder.getSubApps().size());
if (activeFolder.getSubApps().size() == 1) {
AppItem item = activeFolder.getSubApps().get(0);
activeFolder.getSubApps().remove(item);
item.setBelongsToFolder(false);
View view = prepareApp(item);
if (activeFolder.getSubApps().size() == 0) {
View view = prepareApp(app);
if (folderFromDock) {
addToDock(view, dock.indexOfChild(activeFolderView));
} else {
......@@ -1261,16 +1264,32 @@ public class DesktopActivity extends AppCompatActivity {
((ViewGroup) activeFolderView.getParent()).removeView(activeFolderView);
} else {
updateIcon(activeFolderView, activeFolder,
GraphicsUtil.generateFolderIcon(this, activeFolder));
if (activeFolder.getSubApps().size() == 1) {
AppItem item = activeFolder.getSubApps().get(0);
activeFolder.getSubApps().remove(item);
item.setBelongsToFolder(false);
View view = prepareApp(item);
if (folderFromDock) {
addToDock(view, dock.indexOfChild(activeFolderView));
} else {
GridLayout gridLayout = pages.get(getCurrentAppsPageNumber());
addAppToPage(gridLayout, view, gridLayout.indexOfChild(activeFolderView));
}
((ViewGroup) activeFolderView.getParent()).removeView(activeFolderView);
} else {
updateIcon(activeFolderView, activeFolder,
GraphicsUtil.generateFolderIcon(this, activeFolder, iconWidth));
}
if (movingApp.getParent() != null) {
((ViewGroup) movingApp.getParent()).removeView(movingApp);
}
int current = getCurrentAppsPageNumber();
addAppToPage(pages.get(current), movingApp);
}
hideFolderWindowContainer();
if (movingApp.getParent() != null) {
((ViewGroup) movingApp.getParent()).removeView(movingApp);
}
movingApp.setVisibility(View.VISIBLE);
int current = getCurrentAppsPageNumber();
addAppToPage(pages.get(current), movingApp);
}
}
......@@ -1329,7 +1348,7 @@ public class DesktopActivity extends AppCompatActivity {
AppItem app1 = (AppItem) ((List<Object>) collidingApp.getTag()).get(2);
AppItem app2 = (AppItem) ((List<Object>) movingApp.getTag()).get(2);
Drawable folderIcon = GraphicsUtil.generateFolderIcon(this,
Drawable folderIcon = GraphicsUtil.generateFolderIcon(this, iconWidth,
app1.getIcon(), app2.getIcon());
AppItem folder;
......@@ -1357,7 +1376,7 @@ public class DesktopActivity extends AppCompatActivity {
} else {
app2.setBelongsToFolder(true);
app1.getSubApps().add(app2);
updateIcon(collidingApp, app1, GraphicsUtil.generateFolderIcon(this, app1));
updateIcon(collidingApp, app1, GraphicsUtil.generateFolderIcon(this, app1, iconWidth));
}
......
......@@ -2,7 +2,6 @@ package org.indin.blisslaunchero;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
......@@ -13,6 +12,7 @@ import android.renderscript.Allocation;
import android.renderscript.Element;
import android.renderscript.RenderScript;
import android.renderscript.ScriptIntrinsicBlur;
import android.support.v4.content.ContextCompat;
import android.util.Log;
public class GraphicsUtil {
......@@ -41,16 +41,14 @@ 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.
* @param context
* @param sources
* @return
*/
public static Drawable generateFolderIcon(Context context, Drawable ...sources) {
for(Drawable d:sources)
if(!(d instanceof BitmapDrawable)) {
public static Drawable generateFolderIcon(Context context, int iconWidth, Drawable... sources) {
for (Drawable d : sources) {
if (!(d instanceof BitmapDrawable)) {
Log.d(TAG, "Unknown type of icon found");
return context.getResources().getDrawable(R.mipmap.ic_folder, null);
}
}
int width = sources[0].getIntrinsicWidth();
int height = width; // Square icons
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
......@@ -64,26 +62,26 @@ public class GraphicsUtil {
int yIncrement = bitmap.getHeight() / 10;
int count = 0;
int total = 0;
for(Drawable d:sources) {
BitmapDrawable bd = (BitmapDrawable)d;
bd.setBounds(x, y, (int)(x+width/2.5f), (int)(y+height/2.5f));
for (Drawable d : sources) {
BitmapDrawable bd = (BitmapDrawable) d;
bd.setBounds(x, y, (int) (x + width / 2.5f), (int) (y + height / 2.5f));
bd.draw(canvas);
x += (int)(width/2.5f + xIncrement);
x += (int) (width / 2.5f + xIncrement);
count++;
total++;
if(count == 2) {
if (count == 2) {
count = 0;
y += (int)(height/2.5f + yIncrement);
y += (int) (height / 2.5f + yIncrement);
x = xOrigin;
}
if(total > 3) {
if (total > 3) {
break;
}
}
Drawable output = new BitmapDrawable(context.getResources(), bitmap);
if(IconPackUtil.iconPackPresent) {
output = GraphicsUtil.scaleImage(context, output, 0.90f);
if (IconPackUtil.iconPackPresent) {
output = GraphicsUtil.scaleImage(context, output, 1f, iconWidth);
output = GraphicsUtil.maskImage(context, output);
}
return output;
......@@ -92,30 +90,24 @@ public class GraphicsUtil {
/**
* A utility method that simplifies calls to the generateFolderIcon() method that
* expects an array of Drawables.
* @param context
* @param app
* @return
*/
public static Drawable generateFolderIcon(Context context, AppItem app) {
public static Drawable generateFolderIcon(Context context, AppItem app, int iconWidth) {
Drawable[] drawables = new Drawable[app.getSubApps().size()];
for(int i=0;i<app.getSubApps().size();i++) {
for (int i = 0; i < app.getSubApps().size(); i++) {
drawables[i] = app.getSubApps().get(i).getIcon();
}
return generateFolderIcon(context, drawables);
return generateFolderIcon(context, iconWidth, drawables);
}
/**
* Scales icons to match the icon pack
* @param context
* @param image
* @param scaleFactor
* @return
*/
public static Drawable scaleImage(Context context, Drawable image, float scaleFactor) {
public static Drawable scaleImage(Context context, Drawable image, float scaleFactor,
int iconWidth) {
if ((image == null) || !(image instanceof BitmapDrawable)) {
return image;
}
Bitmap b = ((BitmapDrawable)image).getBitmap();
Bitmap b = ((BitmapDrawable) image).getBitmap();
int sizeX = Math.round(image.getIntrinsicWidth() * scaleFactor);
int sizeY = Math.round(image.getIntrinsicHeight() * scaleFactor);
Bitmap bitmapResized = Bitmap.createScaledBitmap(b, sizeX, sizeY, false);
......@@ -127,18 +119,27 @@ public class GraphicsUtil {
if ((image == null) || !(image instanceof BitmapDrawable)) {
return image;
}
double scale = 0.64;
Bitmap original = Bitmap.createScaledBitmap(((BitmapDrawable)image).getBitmap(),
(int)(image.getIntrinsicWidth() * scale),
(int)(image.getIntrinsicWidth() * scale), true);
Bitmap mask = ((BitmapDrawable)IconPackUtil.getIconMask()).getBitmap();
Bitmap result = Bitmap.createBitmap(mask.getWidth(), mask.getHeight(), Bitmap.Config.ARGB_8888);
double scale = 0.85;
Drawable maskDrawable;
if(IconPackUtil.getIconMask() != null){
maskDrawable = IconPackUtil.getIconMask();
}else
maskDrawable = ContextCompat.getDrawable(context, R.drawable.iconmask);
Bitmap mask = ((BitmapDrawable) maskDrawable).getBitmap();
Bitmap original = Bitmap.createScaledBitmap(((BitmapDrawable) image).getBitmap(),
(int) (mask.getWidth() * scale),
(int) (mask.getHeight() * scale), true);
Bitmap result = Bitmap.createBitmap(mask.getWidth(), mask.getHeight(),
Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(result);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
canvas.drawBitmap(original, (canvas.getWidth() - original.getWidth())/2, (canvas.getHeight() - original.getHeight())/2, null);
canvas.drawBitmap(original, (canvas.getWidth() - original.getWidth()) / 2,
(canvas.getHeight() - original.getHeight()) / 2, null);
canvas.drawBitmap(mask, 0, 0, paint);
paint.setXfermode(null);
return new BitmapDrawable(context.getResources(), result);
}
}
}
\ No newline at end of file
......@@ -7,6 +7,7 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import android.util.DisplayMetrics;
import android.util.Log;
......@@ -85,12 +86,19 @@ public class IconPackUtil {
iconMapper.put(componentName, drawableId);
}
}
iconBackground1 = iconPackResources.getDrawable(
iconPackResources.getIdentifier("iconback_d", "drawable", ICON_PACK_PACKAGE),
null);
if(iconBackground1 == null){
iconBackground1 = ContextCompat.getDrawable(context, R.drawable.iconback_d);
}
iconBackground2 = iconPackResources.getDrawable(
iconPackResources.getIdentifier("iconback_d", "drawable", ICON_PACK_PACKAGE),
null);
if(iconBackground2 == null){
iconBackground2 = ContextCompat.getDrawable(context, R.drawable.iconback_d);
}
folderBackground = iconPackResources.getDrawable(
iconPackResources.getIdentifier("iconback_d", "drawable", ICON_PACK_PACKAGE),
null);
......
......@@ -9,7 +9,7 @@ import android.widget.ImageView;
* Created by falcon on 16/2/18.
*/
public class SquareImageView extends ImageView {
public class SquareImageView extends android.support.v7.widget.AppCompatImageView {
public SquareImageView(Context context) {
......@@ -30,7 +30,9 @@ public class SquareImageView extends ImageView {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int width = getMeasuredWidth();
setMeasuredDimension(width, width);
int height = getMeasuredHeight();
int size = width < height ? width : height;
setMeasuredDimension(size, size);
}
......
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#e5e5e5"
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM17,13L7,13v-2h10v2z"/>
</vector>
......@@ -24,5 +24,4 @@
android:maxLines="1"
android:textColor="@color/app_label_color"
android:textSize="@dimen/labelSize" />
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="uninstall_app" type="id">uninstallApp</item>
</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