From a7c124d9002d62b9c7da40f48e3b2a278199403e Mon Sep 17 00:00:00 2001 From: Jon F Hancock Date: Sun, 22 Jan 2012 16:46:36 -0800 Subject: [PATCH] Added handling for dynamic icon packs like Droidicon and Tha Icon Ultimate --- src/org/adw/launcher/LauncherModel.java | 99 ++++++++++++++------ src/org/adw/launcher/MyLauncherSettings.java | 3 + 2 files changed, 71 insertions(+), 31 deletions(-) diff --git a/src/org/adw/launcher/LauncherModel.java b/src/org/adw/launcher/LauncherModel.java index 31f9510be..326ce670d 100644 --- a/src/org/adw/launcher/LauncherModel.java +++ b/src/org/adw/launcher/LauncherModel.java @@ -20,6 +20,9 @@ import static android.util.Log.e; import static android.util.Log.w; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; import java.lang.ref.WeakReference; import java.net.URISyntaxException; import java.text.Collator; @@ -47,6 +50,7 @@ import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Rect; +import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Process; @@ -1619,37 +1623,70 @@ static Drawable getIcon(PackageManager manager, Context context, ActivityInfo ac Resources themeResources = null; if(AlmostNexusSettingsHelper.getThemeIcons(context)){ activityInfo.name=activityInfo.name.toLowerCase().replace(".", "_"); - try { - themeResources = manager.getResourcesForApplication(themePackage); - } catch (NameNotFoundException e) { - //e.printStackTrace(); - } - if(themeResources!=null){ - int resource_id = themeResources.getIdentifier(activityInfo.name, "drawable", themePackage); - if(resource_id!=0){ - icon=themeResources.getDrawable(resource_id); - } - - // use IconShader - if(icon==null){ - if (compiledIconShaderName==null || - compiledIconShaderName.compareTo(themePackage)!=0){ - compiledIconShader = null; - resource_id = themeResources.getIdentifier("shader", "xml", themePackage); - if(resource_id!=0){ - XmlResourceParser xpp = themeResources.getXml(resource_id); - compiledIconShader = IconShader.parseXml(xpp); - } - } - - if(compiledIconShader!=null){ - icon = Utilities.createIconThumbnail(activityInfo.loadIcon(manager), context); - try { - icon = IconShader.processIcon(icon, compiledIconShader); - } catch (Exception e) {} - } - } - } + + if (themePackage.contains("droidicon")) { + Uri CONTENT_URI = Uri + .parse("content://" + + themePackage +".provider.DynamicIconsProvider" + + "/icon"); + Uri content = Uri.withAppendedPath(CONTENT_URI, + activityInfo.name); + + try { + ContentResolver cr = context.getContentResolver(); + cr.acquireContentProviderClient(content); + InputStream in = cr + .openAssetFileDescriptor(content, "") + .createInputStream(); + BitmapFactory.Options opts = new BitmapFactory.Options(); + + opts.inDensity = 120; + Bitmap defaultIcon = BitmapFactory.decodeStream(in, + null, opts); + + icon = new BitmapDrawable(defaultIcon); + } catch (FileNotFoundException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (NullPointerException e) { + e.printStackTrace(); + } + } else { + try { + themeResources = manager.getResourcesForApplication(themePackage); + } catch (NameNotFoundException e) { + //e.printStackTrace(); + } + if(themeResources!=null){ + int resource_id = themeResources.getIdentifier(activityInfo.name, "drawable", themePackage); + if(resource_id!=0){ + icon=themeResources.getDrawable(resource_id); + } + + // use IconShader + if(icon==null){ + if (compiledIconShaderName==null || + compiledIconShaderName.compareTo(themePackage)!=0){ + compiledIconShader = null; + resource_id = themeResources.getIdentifier("shader", "xml", themePackage); + if(resource_id!=0){ + XmlResourceParser xpp = themeResources.getXml(resource_id); + compiledIconShader = IconShader.parseXml(xpp); + } + } + + if(compiledIconShader!=null){ + icon = Utilities.createIconThumbnail(activityInfo.loadIcon(manager), context); + try { + icon = IconShader.processIcon(icon, compiledIconShader); + } catch (Exception e) {} + } + } + } + } } if(icon==null){ diff --git a/src/org/adw/launcher/MyLauncherSettings.java b/src/org/adw/launcher/MyLauncherSettings.java index 1d78378f9..f4a6c7ae2 100644 --- a/src/org/adw/launcher/MyLauncherSettings.java +++ b/src/org/adw/launcher/MyLauncherSettings.java @@ -286,6 +286,9 @@ public void onClick(DialogInterface dialog, int which) { intent.addCategory("android.intent.category.DEFAULT"); PackageManager pm=getPackageManager(); List themes=pm.queryIntentActivities(intent, 0); + intent=new Intent("org.adw.launcher.THEMES.DYNAMIC"); + intent.addCategory("android.intent.category.DEFAULT"); + themes.addAll(pm.queryIntentActivities(intent, 0)); String[] entries = new String[themes.size()+1]; String[] values = new String[themes.size()+1]; entries[0]=Launcher.THEME_DEFAULT;