Skip to content

Commit

Permalink
Documentation & README
Browse files Browse the repository at this point in the history
  • Loading branch information
forestlover authored and forestlover committed May 18, 2017
1 parent 445e81b commit 8b65765
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 45 deletions.
23 changes: 23 additions & 0 deletions iconpack/src/main/java/com/sofaking/iconpack/Constants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.sofaking.iconpack;

/**
* Created by nadavfima on 18/05/2017.
*/

public class Constants {

static final String FILE_APPFILTER = "appfilter";
static final String FILE_DRAWABLE = "drawable";

static final String COMPONENT = "component";
static final String DRAWABLE = "drawable";
static final String BACKGROUND = "iconback";
static final String BACKGROUND_IMG = "img";
static final String MASK = "iconmask";
static final String FRONT = "iconupon";
static final String SCALE = "scale";
static final String ITEM = "item";
static final String FACTOR = "factor";
static final String IMG_1_VALUE = "img1";

}
12 changes: 1 addition & 11 deletions iconpack/src/main/java/com/sofaking/iconpack/IconMasking.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,13 @@
* Created by nadavfima on 14/05/2017.
*/

public class IconMasking {

static final String BACKGROUND = "iconback";
static final String BACKGROUND_IMG = "img";
static final String MASK = "iconmask";
static final String FRONT = "iconupon";
static final String SCALE = "scale";
static final String ITEM = "item";
static final String FACTOR = "factor";
static final String IMG_1_VALUE = "img1";
class IconMasking {


private List<Bitmap> mBackImages = new ArrayList<Bitmap>();
Bitmap mMaskImage = null;
Bitmap mFrontImage = null;


private float mFactor = 1.0f;


Expand Down
61 changes: 39 additions & 22 deletions iconpack/src/main/java/com/sofaking/iconpack/IconPack.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.support.annotation.MainThread;
import android.support.annotation.Nullable;
import android.support.annotation.WorkerThread;

import com.sofaking.iconpack.exceptions.AppFilterNotLoadedException;
import com.sofaking.iconpack.exceptions.IconMaskingUnavailableException;
import com.sofaking.iconpack.exceptions.XMLNotFoundException;
import com.sofaking.iconpack.utils.ResourceHelper;
import com.sofaking.iconpack.utils.RoundsExecutor;
import com.sofaking.iconpack.utils.XmlParserGenerator;
import com.sofaking.iconpack.utils.XmlPullParserGenerator;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
Expand All @@ -44,11 +45,6 @@
public class IconPack {


private static final String FILE_APPFILTER = "appfilter";
private static final String FILE_DRAWABLE = "drawable";
private static final String COMPONENT = "component";
private static final String DRAWABLE = "drawable";

private final Handler mHandler;
private final String mPackageName;
private final WeakReference<Context> mContextReference;
Expand Down Expand Up @@ -131,7 +127,7 @@ public void run() {
public void initAppFilter(boolean initMasking, final AppFilterListener listener) {
mAppFilterLoading = true;
try {
final XmlPullParser parser = XmlParserGenerator.getXmlPullParser(mPackResources, mPackageName, FILE_APPFILTER);
final XmlPullParser parser = XmlPullParserGenerator.getXmlPullParser(mPackResources, mPackageName, Constants.FILE_APPFILTER);

onLoadAppFilter(parser, initMasking);

Expand Down Expand Up @@ -216,21 +212,42 @@ public void run() {
}
}

/**
* @return - @{@link XmlPullParser} of the drawable.xml from the icon pack
* @throws XMLNotFoundException
* @throws XmlPullParserException
* @deprecated - This method is deprecated and will be removed soon
*/
public XmlPullParser getDrawableXmlPullParser() throws XMLNotFoundException, XmlPullParserException {
return XmlParserGenerator.getXmlPullParser(mPackResources, mPackageName, FILE_DRAWABLE);
return XmlPullParserGenerator.getXmlPullParser(mPackResources, mPackageName, Constants.FILE_DRAWABLE);
}

/**
* @param drawableName
* @return - specific Drawable Icon, not necessarily found in the appfilter.xml
*/
@WorkerThread
public Drawable getDrawableIconForName(String drawableName) {
return loadDrawable(drawableName);
}


public Drawable getDefaultIconForPackage(PackageManager packageManager, ComponentName componentName, boolean maskFallback) {
/**
* This method will first try to look up the icon in the AppFilterMap.
* If no icon is found in the AppFilter, a masked icon will be generated for this app.
*
* @param context
* @param componentName
* @param maskFallback
* @return
*/
@Nullable
@WorkerThread
public Drawable getDefaultIconForPackage(Context context, ComponentName componentName, boolean maskFallback) {

Intent intent = new Intent();
intent.setComponent(componentName);
List<ResolveInfo> activites = packageManager.queryIntentActivities(intent, PackageManager.GET_META_DATA);
List<ResolveInfo> activites = context.getPackageManager().queryIntentActivities(intent, PackageManager.GET_META_DATA);

if (activites.size() > 0) {
return getDefaultIconForPackage(activites.get(0), maskFallback);
Expand Down Expand Up @@ -339,7 +356,7 @@ private void onLoadDrawableMap(XmlPullParser parser) {

} else if (parser.getName().equals("item")) {

String name = parser.getAttributeValue(null, DRAWABLE);
String name = parser.getAttributeValue(null, Constants.DRAWABLE);

onAddIconToCategory(currentTitle, name);
}
Expand Down Expand Up @@ -393,7 +410,7 @@ private void onLoadAppFilter(XmlPullParser parser, boolean initMasking) {
onLoadMask(parser);
}

if (parser.getName().equals(IconMasking.ITEM)) {
if (parser.getName().equals(Constants.ITEM)) {
onLoadAppFilter(parser);
}
}
Expand All @@ -413,9 +430,9 @@ private void onLoadAppFilter(XmlPullParser parser) {
String drawableName = null;

for (int i = 0; i < parser.getAttributeCount(); i++) {
if (parser.getAttributeName(i).equals(COMPONENT)) {
if (parser.getAttributeName(i).equals(Constants.COMPONENT)) {
componentName = parser.getAttributeValue(i);
} else if (parser.getAttributeName(i).equals(DRAWABLE)) {
} else if (parser.getAttributeName(i).equals(Constants.DRAWABLE)) {
drawableName = parser.getAttributeValue(i);
}
}
Expand All @@ -426,11 +443,11 @@ private void onLoadAppFilter(XmlPullParser parser) {

@WorkerThread
private void onLoadMask(XmlPullParser parser) {
if (parser.getName().equals(IconMasking.BACKGROUND)) {
if (parser.getName().equals(Constants.BACKGROUND)) {


for (int i = 0; i < parser.getAttributeCount(); i++) {
if (parser.getAttributeName(i).startsWith(IconMasking.BACKGROUND_IMG)) {
if (parser.getAttributeName(i).startsWith(Constants.BACKGROUND_IMG)) {
String drawableName = parser.getAttributeValue(i);
Bitmap iconback = loadDrawable(drawableName).getBitmap();
if (iconback != null) {
Expand All @@ -444,8 +461,8 @@ private void onLoadMask(XmlPullParser parser) {

}
}
} else if (parser.getName().equals(IconMasking.MASK)) {
if (parser.getAttributeCount() > 0 && parser.getAttributeName(0).equals(IconMasking.IMG_1_VALUE)) {
} else if (parser.getName().equals(Constants.MASK)) {
if (parser.getAttributeCount() > 0 && parser.getAttributeName(0).equals(Constants.IMG_1_VALUE)) {
String drawableName = parser.getAttributeValue(0);

if (mIconMasking == null) {
Expand All @@ -454,8 +471,8 @@ private void onLoadMask(XmlPullParser parser) {
mIconMasking.setMaskBitmap(loadDrawable(drawableName).getBitmap());

}
} else if (parser.getName().equals(IconMasking.FRONT)) {
if (parser.getAttributeCount() > 0 && parser.getAttributeName(0).equals(IconMasking.IMG_1_VALUE)) {
} else if (parser.getName().equals(Constants.FRONT)) {
if (parser.getAttributeCount() > 0 && parser.getAttributeName(0).equals(Constants.IMG_1_VALUE)) {
String drawableName = parser.getAttributeValue(0);

if (mIconMasking == null) {
Expand All @@ -464,9 +481,9 @@ private void onLoadMask(XmlPullParser parser) {

mIconMasking.setFrontBitmap(loadDrawable(drawableName).getBitmap());
}
} else if (parser.getName().equals(IconMasking.SCALE)) {
} else if (parser.getName().equals(Constants.SCALE)) {
// mFactor
if (parser.getAttributeCount() > 0 && parser.getAttributeName(0).equals(IconMasking.FACTOR)) {
if (parser.getAttributeCount() > 0 && parser.getAttributeName(0).equals(Constants.FACTOR)) {

if (mIconMasking == null) {
mIconMasking = new IconMasking();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.sofaking.iconpack;

import android.app.Application;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
Expand All @@ -16,8 +15,6 @@
import java.util.List;

/**
* Created by nadavfima on 18/05/2017.
* <p>
* The @{@link IconPackManager} holds the objects for the installed icon packs.
* You should only have one of these in your app.
*/
Expand All @@ -26,6 +23,9 @@ public class IconPackManager {
private HashMap<String, IconPack> mInstalledIconPacks;
private boolean mInstalledPacksLoaded;

/**
* You should only have one of these in your app.
*/
public IconPackManager() {

// init the hasmap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,25 @@
import java.io.InputStream;


public class XmlParserGenerator {
public class XmlPullParserGenerator {

private static final String DEF_XML = "xml";
private static final String EXT_XML = "." + DEF_XML;
private static final String UTF_8 = "UTF-8";


public static XmlPullParser getXmlPullParser(Resources res, String packageName, String file) throws XMLNotFoundException, XmlPullParserException {
public static XmlPullParser getXmlPullParser(Resources resources, String packageName, String file) throws XMLNotFoundException, XmlPullParserException {

XmlPullParser xpp = null;

// try to get identifier of the XML file
int xmlId = res.getIdentifier(file, DEF_XML, packageName);

int xmlId = resources.getIdentifier(file, DEF_XML, packageName);

if (xmlId > 0) {
// if found - getXml()
xpp = res.getXml(xmlId);
xpp = resources.getXml(xmlId);
} else {
// no resource found, try to open it from assests folder
// no resource found, try to open it from assets folder
try {
InputStream appfilterstream = res.getAssets().open(file + EXT_XML);
InputStream appfilterstream = resources.getAssets().open(file + EXT_XML);

XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
Expand Down
5 changes: 5 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ or Gradle:
compile 'com.sofakingforever.libraries:iconpack:0.0.3@aar'
```

Still on the Todo List
--------
- Icon Selection Activity
- IconPack Selection Activity

License
-------

Expand Down

0 comments on commit 8b65765

Please sign in to comment.