Commit 2dcff919 authored by Amit Kumar's avatar Amit Kumar

Fix #29, #33

parents 331fcf0b 9f9d6103
package org.indin.blisslaunchero.framework; package org.indin.blisslaunchero.framework;
import org.indin.blisslaunchero.framework.customviews.AdaptiveIconDrawableCompat;
import org.indin.blisslaunchero.framework.utils.ResourceUtils;
import org.xmlpull.v1.XmlPullParser;
import android.content.Context; import android.content.Context;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.res.AssetManager; import android.content.res.AssetManager;
...@@ -13,6 +9,10 @@ import android.graphics.drawable.Drawable; ...@@ -13,6 +9,10 @@ import android.graphics.drawable.Drawable;
import android.support.v4.content.res.ResourcesCompat; import android.support.v4.content.res.ResourcesCompat;
import android.util.Log; import android.util.Log;
import org.indin.blisslaunchero.framework.customviews.AdaptiveIconDrawableCompat;
import org.indin.blisslaunchero.framework.utils.ResourceUtils;
import org.xmlpull.v1.XmlPullParser;
/** /**
* Created by falcon on 19/4/18. * Created by falcon on 19/4/18.
*/ */
...@@ -43,7 +43,7 @@ public class AdaptiveIconProvider { ...@@ -43,7 +43,7 @@ public class AdaptiveIconProvider {
XmlResourceParser manifestParser; XmlResourceParser manifestParser;
String iconName = null; String iconName = null;
int iconId; int iconId = 0;
try { try {
manifestParser = assetManager.openXmlResourceParser("AndroidManifest.xml"); manifestParser = assetManager.openXmlResourceParser("AndroidManifest.xml");
int eventType; int eventType;
...@@ -52,18 +52,20 @@ public class AdaptiveIconProvider { ...@@ -52,18 +52,20 @@ public class AdaptiveIconProvider {
while ((eventType = manifestParser.nextToken()) != XmlPullParser.END_DOCUMENT) { while ((eventType = manifestParser.nextToken()) != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_TAG && manifestParser.getName().equals( if (eventType == XmlPullParser.START_TAG && manifestParser.getName().equals(
matcher)) { matcher)) {
iconId = manifestParser.getAttributeResourceValue( for (int i = 0; i < manifestParser.getAttributeCount(); i++) {
ANDROID_SCHEMA, "icon", if (manifestParser.getAttributeName(i).equalsIgnoreCase("icon")) {
0); iconId = Integer.parseInt(
manifestParser.getAttributeValue(i).substring(1));
break;
}
}
if (iconId != 0) { if (iconId != 0) {
iconName = resources.getResourceName(iconId); iconName = resources.getResourceName(iconId);
if (iconName.contains("/")) { if (iconName.contains("/")) {
iconName = iconName.split("/")[1]; iconName = iconName.split("/")[1];
} }
break; break;
} } else {
if (iconId == 0) {
matcher = "activity"; matcher = "activity";
} }
} }
...@@ -73,15 +75,21 @@ public class AdaptiveIconProvider { ...@@ -73,15 +75,21 @@ public class AdaptiveIconProvider {
} }
XmlResourceParser parser = null; XmlResourceParser parser = null;
if (iconId != 0) {
parser = resources.getXml(iconId);
}
for (int dir = 0; dir < IC_DIRS.length && parser == null; dir++) { for (int dir = 0; dir < IC_DIRS.length && parser == null; dir++) {
for (int config = 0; config < IC_CONFIGS.length && parser == null; config++) { for (int config = 0; config < IC_CONFIGS.length && parser == null; config++) {
for (String name : iconName != null && !iconName.equals("ic_launcher") for (String name : iconName != null && !iconName.equals("ic_launcher")
? new String[]{iconName, "ic_launcher"} : new String[]{"ic_launcher"}) { ? new String[]{iconName, "ic_launcher"} : new String[]{"ic_launcher"}) {
try { try {
parser = assetManager.openXmlResourceParser( String path = "res/" + IC_DIRS[dir] + IC_CONFIGS[config] + "/" + name
"res/" + IC_DIRS[dir] + IC_CONFIGS[config] + "/" + name + ".xml";
+ ".xml"); Log.i(TAG, "path: " + path);
parser = assetManager.openXmlResourceParser(path);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace();
continue; continue;
} }
...@@ -96,7 +104,8 @@ public class AdaptiveIconProvider { ...@@ -96,7 +104,8 @@ public class AdaptiveIconProvider {
if (parser != null) { if (parser != null) {
int event; int event;
while ((event = parser.getEventType()) != XmlPullParser.END_DOCUMENT) { while ((event = parser.getEventType()) != XmlPullParser.END_DOCUMENT) {
Log.i(TAG, packageName + ":parserName: " + parser.getName()+" "+parser.getAttributeCount()); Log.i(TAG, packageName + ":parserName: " + parser.getName() + " "
+ parser.getAttributeCount());
if (event == XmlPullParser.START_TAG) { if (event == XmlPullParser.START_TAG) {
switch (parser.getName()) { switch (parser.getName()) {
case "background": case "background":
......
...@@ -182,6 +182,7 @@ public class IconsHandler { ...@@ -182,6 +182,7 @@ public class IconsHandler {
systemIcon = new AdaptiveIconProvider().load(ctx, componentName.getPackageName()); systemIcon = new AdaptiveIconProvider().load(ctx, componentName.getPackageName());
if(systemIcon != null){ if(systemIcon != null){
Log.i(TAG, "getDrawableIconForPackage: herrrre");
cacheStoreDrawable(componentName.toString(), systemIcon); cacheStoreDrawable(componentName.toString(), systemIcon);
return systemIcon; return systemIcon;
} }
......
...@@ -30,6 +30,9 @@ public class PackageAddedRemovedHandler extends BroadcastReceiver { ...@@ -30,6 +30,9 @@ public class PackageAddedRemovedHandler extends BroadcastReceiver {
if (launchIntent == null) {//for some plugin app if (launchIntent == null) {//for some plugin app
return; return;
} }
BlissLauncher.getApplication(ctx).resetIconsHandler();
AppAddEvent appAddEvent = new AppAddEvent(); AppAddEvent appAddEvent = new AppAddEvent();
appAddEvent.packageName = packageName; appAddEvent.packageName = packageName;
EventBus.getDefault().post(appAddEvent); EventBus.getDefault().post(appAddEvent);
...@@ -43,6 +46,8 @@ public class PackageAddedRemovedHandler extends BroadcastReceiver { ...@@ -43,6 +46,8 @@ public class PackageAddedRemovedHandler extends BroadcastReceiver {
launchIntent.getComponent(), user); launchIntent.getComponent(), user);
} }
BlissLauncher.getApplication(ctx).resetIconsHandler();
AppChangeEvent appChangeEvent = new AppChangeEvent(); AppChangeEvent appChangeEvent = new AppChangeEvent();
appChangeEvent.packageName = packageName; appChangeEvent.packageName = packageName;
EventBus.getDefault().post(appChangeEvent); EventBus.getDefault().post(appChangeEvent);
...@@ -56,8 +61,6 @@ public class PackageAddedRemovedHandler extends BroadcastReceiver { ...@@ -56,8 +61,6 @@ public class PackageAddedRemovedHandler extends BroadcastReceiver {
EventBus.getDefault().post(appRemoveEvent); EventBus.getDefault().post(appRemoveEvent);
} }
BlissLauncher.getApplication(ctx).resetIconsHandler();
// Reload application list // Reload application list
final AppProvider provider = BlissLauncher.getApplication(ctx).getAppProvider(); final AppProvider provider = BlissLauncher.getApplication(ctx).getAppProvider();
if (provider != null) { if (provider != null) {
......
...@@ -44,7 +44,6 @@ import android.os.Bundle; ...@@ -44,7 +44,6 @@ import android.os.Bundle;
import android.os.UserManager; import android.os.UserManager;
import android.provider.MediaStore; import android.provider.MediaStore;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.util.Log;
public class AppUtils { public class AppUtils {
...@@ -84,7 +83,6 @@ public class AppUtils { ...@@ -84,7 +83,6 @@ public class AppUtils {
Drawable appIcon = iconsHandler.getDrawableIconForPackage( Drawable appIcon = iconsHandler.getDrawableIconForPackage(
activityInfo.getComponentName(), user); activityInfo.getComponentName(), user);
Log.i(TAG, "loadAll: here");
boolean isSystemApp = false; boolean isSystemApp = false;
if ((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { if ((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
......
...@@ -33,8 +33,6 @@ subprojects { ...@@ -33,8 +33,6 @@ subprojects {
spotless { spotless {
java { java {
target '**/*.java' target '**/*.java'
importOrder 'java', 'javax', 'org', 'com', 'com.diffplug', '' // A sequence of package names
removeUnusedImports() // removes any unused imports removeUnusedImports() // removes any unused imports
} }
} }
......
Markdown is supported
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