LocalNotificationOptions.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /**
  2. * LocalNotificationOptions.java
  3. * Cordova LocalNotification Plugin
  4. *
  5. * Created by Sebastian Katzer (github.com/katzer) on 31/08/2013.
  6. * Copyright 2013 Sebastian Katzer. All rights reserved.
  7. * GPL v2 licensed
  8. */
  9. package de.appplant.cordova.plugin.localnotification;
  10. import java.util.Calendar;
  11. import java.util.Date;
  12. import org.apache.cordova.CordovaInterface;
  13. import org.json.JSONObject;
  14. import android.R;
  15. /**
  16. * Class that helps to store the options that can be specified per alarm.
  17. */
  18. public class LocalNotificationOptions {
  19. /*
  20. * Options that can be set when this plugin is invoked
  21. */
  22. private JSONObject options = new JSONObject();
  23. private String id = null;
  24. private long interval = 0;
  25. private long date = 0;
  26. /**
  27. * Parse options passed from javascript part of this plugin.
  28. */
  29. LocalNotificationOptions (JSONObject options) {
  30. String repeat = options.optString("repeat");
  31. this.options = options;
  32. date = options.optLong("date") * 1000;
  33. id = options.optString("id");
  34. if (repeat.equalsIgnoreCase("daily")) {
  35. interval = 86400000;
  36. } else if (repeat.equalsIgnoreCase("weekly")) {
  37. interval = 604800000;
  38. } else if (repeat.equalsIgnoreCase("monthly")) {
  39. interval = 2678400000L; // 31 days
  40. } else if (repeat.equalsIgnoreCase("yearly")) {
  41. interval = 31536000000L;
  42. }
  43. }
  44. /**
  45. * Gibt die Eigenschaften als JSONObjekt an.
  46. */
  47. public JSONObject getJSONObject() {
  48. return options;
  49. }
  50. /**
  51. * Gibt die Zeit in Sekunden an, wann die Notification aufpoppen soll.
  52. */
  53. public long getDate() {
  54. return date;
  55. }
  56. /**
  57. * Gibt die Zeit als Kalender an.
  58. */
  59. public Calendar getCalendar () {
  60. Calendar calendar = Calendar.getInstance();
  61. calendar.setTime(new Date(getDate()));
  62. return calendar;
  63. }
  64. /**
  65. * Gibt die Nachricht der Notification an.
  66. */
  67. public String getMessage () {
  68. return options.optString("message");
  69. }
  70. /**
  71. * Gibt den Titel der Notification an.
  72. */
  73. public String getTitle () {
  74. return options.optString("title");
  75. }
  76. /**
  77. * Gibt den Pfad zum Sound der Notification an.
  78. */
  79. public String getSound () {
  80. return options.optString("sound", null);
  81. }
  82. /**
  83. * Gibt den Pfad zum Icon der Notification an.
  84. */
  85. public int getIcon () {
  86. int icon = R.drawable.ic_menu_info_details;
  87. CordovaInterface cordova = LocalNotification.cordova;
  88. String packageName = cordova.getActivity().getPackageName();
  89. try {
  90. Class<?> klass = Class.forName(packageName + ".R$drawable");
  91. icon = (Integer) klass.getDeclaredField("icon").get(Integer.class);
  92. } catch (Exception e) {}
  93. return options.optInt("icon", icon);
  94. }
  95. /**
  96. * Gibt den Pfad zur Callback-Funktion der Notification an.
  97. */
  98. public String getForeground () {
  99. return options.optString("foreground", null);
  100. }
  101. /**
  102. * Gibt den Pfad zur Callback-Funktion der Notification an.
  103. */
  104. public String getBackground () {
  105. return options.optString("background", null);
  106. }
  107. /**
  108. * Gibt das Intervall an, in dem die Notification aufpoppen soll (daily, weekly, monthly, yearly)
  109. */
  110. public long getInterval () {
  111. return interval;
  112. }
  113. /**
  114. * Gibt die Badge-Nummer der Notification an.
  115. */
  116. public int getBadge () {
  117. return options.optInt("badge", 0);
  118. }
  119. /**
  120. * Gibt die Callback-ID des PluginResults an.
  121. */
  122. public String getId () {
  123. return id;
  124. }
  125. }