Commit 24a28399 by Sebastián Katzer

Icon can be specified by name through interface.

parent faeee22a
...@@ -15,8 +15,6 @@ import java.util.Date; ...@@ -15,8 +15,6 @@ import java.util.Date;
import org.apache.cordova.CordovaInterface; import org.apache.cordova.CordovaInterface;
import org.json.JSONObject; import org.json.JSONObject;
import android.R;
/** /**
* Class that helps to store the options that can be specified per alarm. * Class that helps to store the options that can be specified per alarm.
*/ */
...@@ -101,15 +99,20 @@ public class LocalNotificationOptions { ...@@ -101,15 +99,20 @@ public class LocalNotificationOptions {
* Gibt den Pfad zum Icon der Notification an. * Gibt den Pfad zum Icon der Notification an.
*/ */
public int getIcon () { public int getIcon () {
int icon = R.drawable.ic_menu_info_details; int icon = 0;
CordovaInterface cordova = LocalNotification.cordova; CordovaInterface cordova = LocalNotification.cordova;
String packageName = cordova.getActivity().getPackageName(); String packageName = cordova.getActivity().getPackageName();
String iconName = options.optString("icon", "icon");
try { icon = getIconValue(packageName, iconName);
Class<?> klass = Class.forName(packageName + ".R$drawable");
icon = (Integer) klass.getDeclaredField("icon").get(Integer.class); if (icon == 0) {
} catch (Exception e) {} icon = getIconValue("android", iconName);
}
if (icon == 0) {
icon = android.R.drawable.ic_menu_info_details;
}
return options.optInt("icon", icon); return options.optInt("icon", icon);
} }
...@@ -148,4 +151,22 @@ public class LocalNotificationOptions { ...@@ -148,4 +151,22 @@ public class LocalNotificationOptions {
public String getId () { public String getId () {
return id; return id;
} }
/**
* Gibt den Zahlwert des Icons an.
*
* @param {String} className
* @param {String} iconName
*/
private int getIconValue (String className, String iconName) {
int icon = 0;
try {
Class<?> klass = Class.forName(className + ".R$drawable");
icon = (Integer) klass.getDeclaredField(iconName).get(Integer.class);
} catch (Exception e) {}
return icon;
}
} }
\ No newline at end of file
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