summaryrefslogtreecommitdiffstats
path: root/src/com/cyngn/theme/util/Utils.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/cyngn/theme/util/Utils.java')
-rw-r--r--src/com/cyngn/theme/util/Utils.java31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/com/cyngn/theme/util/Utils.java b/src/com/cyngn/theme/util/Utils.java
index 720a542..68c4211 100644
--- a/src/com/cyngn/theme/util/Utils.java
+++ b/src/com/cyngn/theme/util/Utils.java
@@ -36,6 +36,7 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.lang.reflect.Field;
import java.util.List;
import java.util.Map;
@@ -515,4 +516,34 @@ public class Utils {
&& homeInfo.packageName.equals(component.getPackageName())
&& homeInfo.name.equals(component.getClassName());
}
+
+ /**
+ * Returns the resource-IDs for all attributes specified in the given
+ * <declare-styleable>-resource tag as an int array.
+ * stackoverflow.com/questions/13816596/accessing-declare-styleable-resources-programatically
+ *
+ * @param name
+ * @return
+ */
+ public static final int[] getResourceDeclareStyleableIntArray(String pkgName, String name) {
+ try {
+ //use reflection to access the resource class
+ Field[] fields2 =
+ Class.forName(pkgName + ".R$styleable").getFields();
+
+ //browse all fields
+ for (Field f : fields2) {
+ //pick matching field
+ if (f.getName().equals(name)) {
+ //return as int array
+ int[] ret = (int[])f.get(null);
+ return ret;
+ }
+ }
+ }
+ catch (Throwable t) {
+ }
+
+ return null;
+ }
}