From bc1b0b43640b560ababb96d760edbd72c8a76502 Mon Sep 17 00:00:00 2001 From: Bastian <8929967+Kaiserdragon2@users.noreply.github.com> Date: Thu, 13 Jan 2022 13:21:01 +0100 Subject: [PATCH] get installed icon packs --- .../iconrequest/IconPackManager.java | 292 +++++++++++++++++ .../iconrequest/RequestActivity.java | 300 +++++++++++++++++- .../iconrequest/SettingActivity.java | 9 +- 3 files changed, 586 insertions(+), 15 deletions(-) create mode 100644 app/src/main/java/de/kaiserdragon/iconrequest/IconPackManager.java diff --git a/app/src/main/java/de/kaiserdragon/iconrequest/IconPackManager.java b/app/src/main/java/de/kaiserdragon/iconrequest/IconPackManager.java new file mode 100644 index 0000000..a018823 --- /dev/null +++ b/app/src/main/java/de/kaiserdragon/iconrequest/IconPackManager.java @@ -0,0 +1,292 @@ +package de.kaiserdragon.iconrequest; + +import android.content.Context; +import android.content.Intent; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.PorterDuff; +import android.graphics.PorterDuffXfermode; +import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.Drawable; + +import org.xmlpull.v1.XmlPullParser; +import org.xmlpull.v1.XmlPullParserException; +import org.xmlpull.v1.XmlPullParserFactory; + +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Random; +/* +public static class IconPackManager { + private android.app.Application mContext; + + public class IconPack { + public String packageName; + public String name; + + private boolean mLoaded = false; + private HashMap mPackagesDrawables = new HashMap(); + + private List mBackImages = new ArrayList(); + private Bitmap mMaskImage = null; + private Bitmap mFrontImage = null; + private float mFactor = 1.0f; + + Resources iconPackres = null; + + public void load() { + // load appfilter.xml from the icon pack package + PackageManager pm = getPackageManager(); + try { + XmlPullParser xpp = null; + + iconPackres = pm.getResourcesForApplication(packageName); + int appfilterid = iconPackres.getIdentifier("appfilter", "xml", packageName); + if (appfilterid > 0) { + xpp = iconPackres.getXml(appfilterid); + } else { + // no resource found, try to open it from assests folder + try { + InputStream appfilterstream = iconPackres.getAssets().open("appfilter.xml"); + + XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); + factory.setNamespaceAware(true); + xpp = factory.newPullParser(); + xpp.setInput(appfilterstream, "utf-8"); + } catch (IOException e1) { + //Ln.d("No appfilter.xml file"); + } + } + + if (xpp != null) { + int eventType = xpp.getEventType(); + while (eventType != XmlPullParser.END_DOCUMENT) { + if (eventType == XmlPullParser.START_TAG) { + if (xpp.getName().equals("iconback")) { + for (int i = 0; i < xpp.getAttributeCount(); i++) { + if (xpp.getAttributeName(i).startsWith("img")) { + String drawableName = xpp.getAttributeValue(i); + Bitmap iconback = loadBitmap(drawableName); + if (iconback != null) + mBackImages.add(iconback); + } + } + } else if (xpp.getName().equals("iconmask")) { + if (xpp.getAttributeCount() > 0 && xpp.getAttributeName(0).equals("img1")) { + String drawableName = xpp.getAttributeValue(0); + mMaskImage = loadBitmap(drawableName); + } + } else if (xpp.getName().equals("iconupon")) { + if (xpp.getAttributeCount() > 0 && xpp.getAttributeName(0).equals("img1")) { + String drawableName = xpp.getAttributeValue(0); + mFrontImage = loadBitmap(drawableName); + } + } else if (xpp.getName().equals("scale")) { + // mFactor + if (xpp.getAttributeCount() > 0 && xpp.getAttributeName(0).equals("factor")) { + mFactor = Float.valueOf(xpp.getAttributeValue(0)); + } + } else if (xpp.getName().equals("item")) { + String componentName = null; + String drawableName = null; + + for (int i = 0; i < xpp.getAttributeCount(); i++) { + if (xpp.getAttributeName(i).equals("component")) { + componentName = xpp.getAttributeValue(i); + } else if (xpp.getAttributeName(i).equals("drawable")) { + drawableName = xpp.getAttributeValue(i); + } + } + if (!mPackagesDrawables.containsKey(componentName)) + mPackagesDrawables.put(componentName, drawableName); + } + } + eventType = xpp.next(); + } + } + mLoaded = true; + } catch (PackageManager.NameNotFoundException e) { + //Ln.d("Cannot load icon pack"); + } catch (XmlPullParserException e) { + //Ln.d("Cannot parse icon pack appfilter.xml"); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private Bitmap loadBitmap(String drawableName) { + int id = iconPackres.getIdentifier(drawableName, "drawable", packageName); + if (id > 0) { + Drawable bitmap = iconPackres.getDrawable(id); + if (bitmap instanceof BitmapDrawable) + return ((BitmapDrawable) bitmap).getBitmap(); + } + return null; + } + + private Drawable loadDrawable(String drawableName) { + int id = iconPackres.getIdentifier(drawableName, "drawable", packageName); + if (id > 0) { + Drawable bitmap = iconPackres.getDrawable(id); + return bitmap; + } + return null; + } + + public Drawable getDrawableIconForPackage(String appPackageName, Drawable defaultDrawable) { + if (!mLoaded) + load(); + + PackageManager pm = mContext.getPackageManager(); + Intent launchIntent = pm.getLaunchIntentForPackage(appPackageName); + String componentName = null; + if (launchIntent != null) + componentName = pm.getLaunchIntentForPackage(appPackageName).getComponent().toString(); + String drawable = mPackagesDrawables.get(componentName); + if (drawable != null) { + return loadDrawable(drawable); + } else { + // try to get a resource with the component filename + if (componentName != null) { + int start = componentName.indexOf("{") + 1; + int end = componentName.indexOf("}", start); + if (end > start) { + drawable = componentName.substring(start, end).toLowerCase(Locale.getDefault()).replace(".", "_").replace("/", "_"); + if (iconPackres.getIdentifier(drawable, "drawable", packageName) > 0) + return loadDrawable(drawable); + } + } + } + return defaultDrawable; + } + + public Bitmap getIconForPackage(String appPackageName, Bitmap defaultBitmap) { + if (!mLoaded) + load(); + + PackageManager pm = mContext.getPackageManager(); + Intent launchIntent = pm.getLaunchIntentForPackage(appPackageName); + String componentName = null; + if (launchIntent != null) + componentName = pm.getLaunchIntentForPackage(appPackageName).getComponent().toString(); + String drawable = mPackagesDrawables.get(componentName); + if (drawable != null) { + return loadBitmap(drawable); + } else { + // try to get a resource with the component filename + if (componentName != null) { + int start = componentName.indexOf("{") + 1; + int end = componentName.indexOf("}", start); + if (end > start) { + drawable = componentName.substring(start, end).toLowerCase(Locale.getDefault()).replace(".", "_").replace("/", "_"); + if (iconPackres.getIdentifier(drawable, "drawable", packageName) > 0) + return loadBitmap(drawable); + } + } + } + return generateBitmap(appPackageName, defaultBitmap); + } + + private Bitmap generateBitmap(String appPackageName, Bitmap defaultBitmap) { + // the key for the cache is the icon pack package name and the app package name + String key = packageName + ":" + appPackageName; + + // if generated bitmaps cache already contains the package name return it +// Bitmap cachedBitmap = BitmapCache.getInstance(mContext).getBitmap(key); +// if (cachedBitmap != null) +// return cachedBitmap; + + // if no support images in the icon pack return the bitmap itself + if (mBackImages.size() == 0) + return defaultBitmap; + + Random r = new Random(); + int backImageInd = r.nextInt(mBackImages.size()); + Bitmap backImage = mBackImages.get(backImageInd); + int w = backImage.getWidth(); + int h = backImage.getHeight(); + + // create a bitmap for the result + Bitmap result = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); + Canvas mCanvas = new Canvas(result); + + // draw the background first + mCanvas.drawBitmap(backImage, 0, 0, null); + + // create a mutable mask bitmap with the same mask + Bitmap scaledBitmap = defaultBitmap; + if (defaultBitmap != null && (defaultBitmap.getWidth() > w || defaultBitmap.getHeight() > h)) + Bitmap.createScaledBitmap(defaultBitmap, (int) (w * mFactor), (int) (h * mFactor), false); + + if (mMaskImage != null) { + // draw the scaled bitmap with mask + Bitmap mutableMask = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); + Canvas maskCanvas = new Canvas(mutableMask); + maskCanvas.drawBitmap(mMaskImage, 0, 0, new Paint()); + + // paint the bitmap with mask into the result + Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); + paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT)); + mCanvas.drawBitmap(scaledBitmap, (w - scaledBitmap.getWidth()) / 2, (h - scaledBitmap.getHeight()) / 2, null); + mCanvas.drawBitmap(mutableMask, 0, 0, paint); + paint.setXfermode(null); + } else // draw the scaled bitmap without mask + { + mCanvas.drawBitmap(scaledBitmap, (w - scaledBitmap.getWidth()) / 2, (h - scaledBitmap.getHeight()) / 2, null); + } + + // paint the front + if (mFrontImage != null) { + mCanvas.drawBitmap(mFrontImage, 0, 0, null); + } + + // store the bitmap in cache +// BitmapCache.getInstance(mContext).putBitmap(key, result); + + // return it + return result; + } + + private HashMap iconPacks = null; + + public HashMap getAvailableIconPacks(boolean forceReload) { + if (iconPacks == null || forceReload) { + iconPacks = new HashMap(); + + // find apps with intent-filter "com.gau.go.launcherex.theme" and return build the HashMap + PackageManager pm = mContext.getPackageManager(); + + List adwlauncherthemes = pm.queryIntentActivities(new Intent("org.adw.launcher.THEMES"), PackageManager.GET_META_DATA); + List golauncherthemes = pm.queryIntentActivities(new Intent("com.gau.go.launcherex.theme"), PackageManager.GET_META_DATA); + + // merge those lists + List rinfo = new ArrayList(adwlauncherthemes); + rinfo.addAll(golauncherthemes); + + for (ResolveInfo ri : rinfo) { + IconPack ip = new IconPack(); + ip.packageName = ri.activityInfo.packageName; + + ApplicationInfo ai = null; + try { + ai = pm.getApplicationInfo(ip.packageName, PackageManager.GET_META_DATA); + ip.name = mContext.getPackageManager().getApplicationLabel(ai).toString(); + iconPacks.put(ip.packageName, ip); + } catch (PackageManager.NameNotFoundException e) { + // shouldn't happen + e.printStackTrace(); + } + } + } + return iconPacks; + } +}*/ diff --git a/app/src/main/java/de/kaiserdragon/iconrequest/RequestActivity.java b/app/src/main/java/de/kaiserdragon/iconrequest/RequestActivity.java index 7758a1e..94df62a 100644 --- a/app/src/main/java/de/kaiserdragon/iconrequest/RequestActivity.java +++ b/app/src/main/java/de/kaiserdragon/iconrequest/RequestActivity.java @@ -1,18 +1,23 @@ package de.kaiserdragon.iconrequest; - +import de.kaiserdragon.iconrequest.SettingActivity; import android.content.ClipData; import android.content.ClipboardManager; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.content.res.AssetManager; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.PorterDuff; +import android.graphics.PorterDuffXfermode; +import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; @@ -48,6 +53,7 @@ import androidx.core.content.res.ResourcesCompat; import org.xmlpull.v1.XmlPullParser; +import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserFactory; import java.io.BufferedInputStream; @@ -68,16 +74,20 @@ import java.util.Arrays; import java.util.Collections; import java.util.Date; +import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Objects; +import java.util.Random; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; + + public class RequestActivity extends AppCompatActivity { private static final String TAG = "RequestActivity"; private static final int BUFFER = 2048; @@ -92,6 +102,8 @@ public class RequestActivity extends AppCompatActivity { private ActivityResultLauncher activityResultLauncher; private Context context; + + public static void deleteDirectory(File path) { if (path.exists()) { File[] files = path.listFiles(); @@ -107,6 +119,7 @@ public static void deleteDirectory(File path) { path.delete(); } + public static void createZipFile(final String path, final boolean keepDirectoryStructure, final String out_file) { @@ -273,6 +286,8 @@ public boolean onOptionsItemSelected(MenuItem item) { actionSendText(actionSave()); return true; } else if (item.getItemId() == R.id.action_copy) { + //IconPackManager iconPackManager = new IconPackManager(); + if (DEBUG) Log.v(TAG, String.valueOf(getAvailableIconPacks(true))); actionSave(); actionCopy(); return true; @@ -285,6 +300,7 @@ public boolean onOptionsItemSelected(MenuItem item) { } } + private boolean visible(Drawable one, Drawable two) { Bitmap bmp1 = getBitmapFromDrawable(one); Bitmap bmp2 = getBitmapFromDrawable(two); @@ -558,19 +574,20 @@ private Drawable getHighResIcon(PackageManager pm, ResolveInfo resolveInfo) { int iconId = resolveInfo.getIconResource();//Get the resource Id for the activity icon if (iconId != 0) { - icon = ResourcesCompat.getDrawable(pm.getResourcesForActivity(componentName), iconId, null); - //icon = context.getPackageManager().getApplicationIcon(resolveInfo.activityInfo.packageName); - //icon =pm.getDrawable(resolveInfo.activityInfo.packageName, iconId, null); - //Drawable adaptiveDrawable = resolveInfo.loadIcon(pm); + //Resources.Theme theme = context.getTheme(); + icon = ResourcesCompat.getDrawable(pm.getResourcesForActivity(componentName), iconId, null); //loads unthemed + //icon = context.getPackageManager().getApplicationIcon(resolveInfo.activityInfo.packageName); //loads themed OnePlus + //icon =pm.getDrawable(resolveInfo.activityInfo.packageName, iconId, null); //loads unthemed + //Drawable adaptiveDrawable = resolveInfo.loadIcon(pm); //loads themed OnePlus //PackageManager packageManager = getPackageManager(); - //icon = resolveInfo.loadIcon(packageManager); - //icon = context.getDrawable(pm.getResourcesForActivity(componentName),iconId,null); + //icon = resolveInfo.loadIcon(packageManager); //loads themed OnePlus + return icon; } return resolveInfo.loadIcon(pm); } catch (PackageManager.NameNotFoundException e) { //fails return the normal icon - return resolveInfo.loadIcon(pm); + return resolveInfo.loadIcon(pm); } catch (Resources.NotFoundException e) { return resolveInfo.loadIcon(pm); } @@ -688,4 +705,269 @@ private class ViewHolder { } } -} + + + private android.app.Application mContext; + + public class IconPack { + public String packageName; + public String name; + + private boolean mLoaded = false; + private HashMap mPackagesDrawables = new HashMap(); + + private List mBackImages = new ArrayList(); + private Bitmap mMaskImage = null; + private Bitmap mFrontImage = null; + private float mFactor = 1.0f; + + Resources iconPackres = null; + + public void load() { + // load appfilter.xml from the icon pack package + PackageManager pm = mContext.getPackageManager(); + try { + XmlPullParser xpp = null; + + iconPackres = pm.getResourcesForApplication(packageName); + int appfilterid = iconPackres.getIdentifier("appfilter", "xml", packageName); + if (appfilterid > 0) { + xpp = iconPackres.getXml(appfilterid); + } else { + // no resource found, try to open it from assests folder + try { + InputStream appfilterstream = iconPackres.getAssets().open("appfilter.xml"); + + XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); + factory.setNamespaceAware(true); + xpp = factory.newPullParser(); + xpp.setInput(appfilterstream, "utf-8"); + } catch (IOException e1) { + //Ln.d("No appfilter.xml file"); + } + } + + if (xpp != null) { + int eventType = xpp.getEventType(); + while (eventType != XmlPullParser.END_DOCUMENT) { + if (eventType == XmlPullParser.START_TAG) { + if (xpp.getName().equals("iconback")) { + for (int i = 0; i < xpp.getAttributeCount(); i++) { + if (xpp.getAttributeName(i).startsWith("img")) { + String drawableName = xpp.getAttributeValue(i); + Bitmap iconback = loadBitmap(drawableName); + if (iconback != null) + mBackImages.add(iconback); + } + } + } else if (xpp.getName().equals("iconmask")) { + if (xpp.getAttributeCount() > 0 && xpp.getAttributeName(0).equals("img1")) { + String drawableName = xpp.getAttributeValue(0); + mMaskImage = loadBitmap(drawableName); + } + } else if (xpp.getName().equals("iconupon")) { + if (xpp.getAttributeCount() > 0 && xpp.getAttributeName(0).equals("img1")) { + String drawableName = xpp.getAttributeValue(0); + mFrontImage = loadBitmap(drawableName); + } + } else if (xpp.getName().equals("scale")) { + // mFactor + if (xpp.getAttributeCount() > 0 && xpp.getAttributeName(0).equals("factor")) { + mFactor = Float.valueOf(xpp.getAttributeValue(0)); + } + } else if (xpp.getName().equals("item")) { + String componentName = null; + String drawableName = null; + + for (int i = 0; i < xpp.getAttributeCount(); i++) { + if (xpp.getAttributeName(i).equals("component")) { + componentName = xpp.getAttributeValue(i); + } else if (xpp.getAttributeName(i).equals("drawable")) { + drawableName = xpp.getAttributeValue(i); + } + } + if (!mPackagesDrawables.containsKey(componentName)) + mPackagesDrawables.put(componentName, drawableName); + } + } + eventType = xpp.next(); + } + } + mLoaded = true; + } catch (PackageManager.NameNotFoundException e) { + //Ln.d("Cannot load icon pack"); + } catch (XmlPullParserException e) { + //Ln.d("Cannot parse icon pack appfilter.xml"); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private Bitmap loadBitmap(String drawableName) { + int id = iconPackres.getIdentifier(drawableName, "drawable", packageName); + if (id > 0) { + Drawable bitmap = iconPackres.getDrawable(id); + if (bitmap instanceof BitmapDrawable) + return ((BitmapDrawable) bitmap).getBitmap(); + } + return null; + } + + private Drawable loadDrawable(String drawableName) { + int id = iconPackres.getIdentifier(drawableName, "drawable", packageName); + if (id > 0) { + Drawable bitmap = iconPackres.getDrawable(id); + return bitmap; + } + return null; + } + + public Drawable getDrawableIconForPackage(String appPackageName, Drawable defaultDrawable) { + if (!mLoaded) + load(); + + PackageManager pm = mContext.getPackageManager(); + Intent launchIntent = pm.getLaunchIntentForPackage(appPackageName); + String componentName = null; + if (launchIntent != null) + componentName = pm.getLaunchIntentForPackage(appPackageName).getComponent().toString(); + String drawable = mPackagesDrawables.get(componentName); + if (drawable != null) { + return loadDrawable(drawable); + } else { + // try to get a resource with the component filename + if (componentName != null) { + int start = componentName.indexOf("{") + 1; + int end = componentName.indexOf("}", start); + if (end > start) { + drawable = componentName.substring(start, end).toLowerCase(Locale.getDefault()).replace(".", "_").replace("/", "_"); + if (iconPackres.getIdentifier(drawable, "drawable", packageName) > 0) + return loadDrawable(drawable); + } + } + } + return defaultDrawable; + } + + public Bitmap getIconForPackage(String appPackageName, Bitmap defaultBitmap) { + if (!mLoaded) + load(); + + PackageManager pm = mContext.getPackageManager(); + Intent launchIntent = pm.getLaunchIntentForPackage(appPackageName); + String componentName = null; + if (launchIntent != null) + componentName = pm.getLaunchIntentForPackage(appPackageName).getComponent().toString(); + String drawable = mPackagesDrawables.get(componentName); + if (drawable != null) { + return loadBitmap(drawable); + } else { + // try to get a resource with the component filename + if (componentName != null) { + int start = componentName.indexOf("{") + 1; + int end = componentName.indexOf("}", start); + if (end > start) { + drawable = componentName.substring(start, end).toLowerCase(Locale.getDefault()).replace(".", "_").replace("/", "_"); + if (iconPackres.getIdentifier(drawable, "drawable", packageName) > 0) + return loadBitmap(drawable); + } + } + } + return generateBitmap(appPackageName, defaultBitmap); + } + + private Bitmap generateBitmap(String appPackageName, Bitmap defaultBitmap) { + // the key for the cache is the icon pack package name and the app package name + String key = packageName + ":" + appPackageName; + + // if generated bitmaps cache already contains the package name return it +// Bitmap cachedBitmap = BitmapCache.getInstance(mContext).getBitmap(key); +// if (cachedBitmap != null) +// return cachedBitmap; + + // if no support images in the icon pack return the bitmap itself + if (mBackImages.size() == 0) + return defaultBitmap; + + Random r = new Random(); + int backImageInd = r.nextInt(mBackImages.size()); + Bitmap backImage = mBackImages.get(backImageInd); + int w = backImage.getWidth(); + int h = backImage.getHeight(); + + // create a bitmap for the result + Bitmap result = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); + Canvas mCanvas = new Canvas(result); + + // draw the background first + mCanvas.drawBitmap(backImage, 0, 0, null); + + // create a mutable mask bitmap with the same mask + Bitmap scaledBitmap = defaultBitmap; + if (defaultBitmap != null && (defaultBitmap.getWidth() > w || defaultBitmap.getHeight() > h)) + Bitmap.createScaledBitmap(defaultBitmap, (int) (w * mFactor), (int) (h * mFactor), false); + + if (mMaskImage != null) { + // draw the scaled bitmap with mask + Bitmap mutableMask = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); + Canvas maskCanvas = new Canvas(mutableMask); + maskCanvas.drawBitmap(mMaskImage, 0, 0, new Paint()); + + // paint the bitmap with mask into the result + Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); + paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT)); + mCanvas.drawBitmap(scaledBitmap, (w - scaledBitmap.getWidth()) / 2, (h - scaledBitmap.getHeight()) / 2, null); + mCanvas.drawBitmap(mutableMask, 0, 0, paint); + paint.setXfermode(null); + } else // draw the scaled bitmap without mask + { + mCanvas.drawBitmap(scaledBitmap, (w - scaledBitmap.getWidth()) / 2, (h - scaledBitmap.getHeight()) / 2, null); + } + + // paint the front + if (mFrontImage != null) { + mCanvas.drawBitmap(mFrontImage, 0, 0, null); + } + + // store the bitmap in cache +// BitmapCache.getInstance(mContext).putBitmap(key, result); + + // return it + return result; + } + } + private HashMap iconPacks = null; + + public HashMap getAvailableIconPacks(boolean forceReload) { + if (iconPacks == null || forceReload) { + iconPacks = new HashMap(); + + // find apps with intent-filter "com.gau.go.launcherex.theme" and return build the HashMap + PackageManager pm = getPackageManager(); + + List adwlauncherthemes = pm.queryIntentActivities(new Intent("org.adw.launcher.THEMES"), PackageManager.GET_META_DATA); + List golauncherthemes = pm.queryIntentActivities(new Intent("com.gau.go.launcherex.theme"), PackageManager.GET_META_DATA); + + // merge those lists + List rinfo = new ArrayList(adwlauncherthemes); + rinfo.addAll(golauncherthemes); + + for (ResolveInfo ri : rinfo) { + IconPack ip = new IconPack(); + ip.packageName = ri.activityInfo.packageName; + + ApplicationInfo ai = null; + try { + ai = pm.getApplicationInfo(ip.packageName, PackageManager.GET_META_DATA); + ip.name = getPackageManager().getApplicationLabel(ai).toString(); + iconPacks.put(ip.packageName, ip); + } catch (PackageManager.NameNotFoundException e) { + // shouldn't happen + e.printStackTrace(); + } + } + } + return iconPacks; + } + } + diff --git a/app/src/main/java/de/kaiserdragon/iconrequest/SettingActivity.java b/app/src/main/java/de/kaiserdragon/iconrequest/SettingActivity.java index 0277928..0eb0f8b 100644 --- a/app/src/main/java/de/kaiserdragon/iconrequest/SettingActivity.java +++ b/app/src/main/java/de/kaiserdragon/iconrequest/SettingActivity.java @@ -1,5 +1,6 @@ package de.kaiserdragon.iconrequest; +import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; import android.view.View; @@ -62,13 +63,9 @@ public void start(View view, int update) { AppCompatDelegate.setDefaultNightMode(update); } else { if (view == (CheckBox) findViewById(R.id.checkBoxRows)) { - if (((CheckBox) view).isChecked()) { - saveDataBool("SettingRow", true); - } else saveDataBool("SettingRow", false); + saveDataBool("SettingRow", ((CheckBox) view).isChecked()); } else if (view == (CheckBox) findViewById(R.id.checkBoxOnly)) { - if (((CheckBox) view).isChecked()) { - saveDataBool("SettingOnlyNew", true); - } else saveDataBool("SettingOnlyNew", false); + saveDataBool("SettingOnlyNew", ((CheckBox) view).isChecked()); } }