Example usage for org.apache.cordova LOG v

List of usage examples for org.apache.cordova LOG v

Introduction

In this page you can find the example usage for org.apache.cordova LOG v.

Prototype

public static void v(String tag, String s) 

Source Link

Document

Verbose log message.

Usage

From source file:com.amazon.cordova.plugin.PushPlugin.java

License:Open Source License

/**
 * Delivers pending/offline messages if any
 * // w  ww  .  j a v  a 2s. c o  m
 * @return returns true if there were any pending messages otherwise false.
 */
public boolean deliverPendingMessageAndCancelNotifiation() {
    boolean delivered = false;
    LOG.d(TAG, "deliverPendingMessages()");
    if (cachedExtrasAvailable()) {
        LOG.v(TAG, "sending cached extras");
        sendExtras(gCachedExtras);
        gCachedExtras = null;
        delivered = true;
    } else {
        delivered = deliverOfflineMessages();
    }
    // Clear the notification if any exists
    ADMMessageHandler.cancelNotification(activity);

    return delivered;
}

From source file:com.amazon.cordova.plugin.PushPlugin.java

License:Open Source License

/**
 * Sends events to JS using cordova nativeToJS bridge.
 * // w  w  w. ja v a2 s  .  co  m
 * @param JSONObject
 */
public static boolean sendJavascript(JSONObject json) {
    if (json == null) {
        LOG.i(TAG, "JSON object is empty. Nothing to send to JS.");
        return true;
    }

    if (notificationHandlerCallBack != null && webview != null) {
        String jsToSend = "javascript:" + notificationHandlerCallBack + "(" + json.toString() + ")";
        LOG.v(TAG, "sendJavascript: " + jsToSend);
        webview.sendJavascript(jsToSend);
        return true;
    }
    return false;
}

From source file:com.amazon.cordova.plugin.PushPlugin.java

License:Open Source License

public static void sendExtras(Bundle extras) {
    if (extras != null) {
        if (!sendJavascript(convertBundleToJson(extras))) {
            LOG.v(TAG, "sendExtras: could not send to JS. Caching extras to send at a later time.");
            gCachedExtras = extras;//from www. jav  a  2  s. c  o m
        }
    }
}

From source file:com.amazon.cordova.plugin.PushPlugin.java

License:Open Source License

private static JSONObject convertBundleToJson(Bundle extras) {
    if (extras == null) {
        return null;
    }/*from  w ww  .ja v  a  2 s.c  om*/

    try {
        JSONObject json;
        json = new JSONObject().put(EVENT, MESSAGE);

        JSONObject jsondata = new JSONObject();
        Iterator<String> it = extras.keySet().iterator();
        while (it.hasNext()) {
            String key = it.next();
            Object value = extras.get(key);

            // System data from Android
            if (key.equals(FOREGROUND)) {
                json.put(key, extras.getBoolean(FOREGROUND));
            } else if (key.equals(COLDSTART)) {
                json.put(key, extras.getBoolean(COLDSTART));
            } else {
                // we encourage put the message content into message value
                // when server send out notification
                if (key.equals(MESSAGE)) {
                    json.put(key, value);
                }

                if (value instanceof String) {
                    // Try to figure out if the value is another JSON object

                    String strValue = (String) value;
                    if (strValue.startsWith("{")) {
                        try {
                            JSONObject json2 = new JSONObject(strValue);
                            jsondata.put(key, json2);
                        } catch (Exception e) {
                            jsondata.put(key, value);
                        }
                        // Try to figure out if the value is another JSON
                        // array
                    } else if (strValue.startsWith("[")) {
                        try {
                            JSONArray json2 = new JSONArray(strValue);
                            jsondata.put(key, json2);
                        } catch (Exception e) {
                            jsondata.put(key, value);
                        }
                    } else {
                        jsondata.put(key, value);
                    }
                }
            } // while
        }
        json.put(PAYLOAD, jsondata);
        LOG.v(TAG, "extrasToJSON: " + json.toString());

        return json;
    } catch (JSONException e) {
        LOG.e(TAG, "extrasToJSON: JSON exception");
    }
    return null;
}

From source file:com.ayogo.cordova.notification.NotificationPlugin.java

License:Apache License

@Override
protected void pluginInitialize() {
    LOG.v(TAG, "Initializing");

    this.mgr = new ScheduledNotificationManager(cordova.getActivity().getApplicationContext());
}

From source file:com.ayogo.cordova.notification.NotificationPlugin.java

License:Apache License

@Override
public boolean execute(String action, final JSONArray args, final CallbackContext callback) {

    if (action.equals("requestPermission")) {
        callback.sendPluginResult(new PluginResult(PluginResult.Status.OK, "granted"));
        return true;
    }/*from  w  w w.j  a  va 2  s. c  o  m*/

    if (action.equals("showNotification")) {
        cordova.getThreadPool().execute(new Runnable() {
            public void run() {
                try {
                    String title = args.getString(0);
                    JSONObject options = args.getJSONObject(1);

                    if (options.optString("tag", null) == null) {
                        options.put("tag", callback.getCallbackId());
                    }

                    LOG.v(TAG, "Schedule Notification: " + title);

                    mgr.scheduleNotification(title, options);

                    callback.sendPluginResult(new PluginResult(PluginResult.Status.OK));
                } catch (JSONException ex) {
                    callback.sendPluginResult(
                            new PluginResult(PluginResult.Status.ERROR, "Missing or invalid title or options"));
                }
            }
        });
        return true;
    }

    if (action.equals("closeNotification")) {
        cordova.getThreadPool().execute(new Runnable() {
            public void run() {
                try {
                    String tag = args.getString(0);

                    LOG.v(TAG, "cancel Notification: " + tag);

                    mgr.cancelNotification(tag);

                    callback.sendPluginResult(new PluginResult(PluginResult.Status.OK));
                } catch (JSONException ex) {
                    callback.sendPluginResult(
                            new PluginResult(PluginResult.Status.ERROR, "Missing or invalid title or options"));
                }
            }
        });
        return true;
    }

    if (action.equals("getNotifications")) {
        cordova.getThreadPool().execute(new Runnable() {
            public void run() {
                LOG.v(TAG, "Get Notifications");

                JSONArray notifications = mgr.getNotifications();

                // Android doesn't require permission to send push notifications
                callback.sendPluginResult(new PluginResult(PluginResult.Status.OK, notifications));
            }
        });
        return true;
    }

    LOG.i(TAG, "Tried to call " + action + " with " + args.toString());

    callback.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION));
    return false;
}

From source file:com.ayogo.cordova.notification.RestoreReceiver.java

License:Apache License

@Override
public void onReceive(Context context, Intent intent) {
    LOG.v(NotificationPlugin.TAG, "Restore Reciever Triggered!");
    ScheduledNotificationManager mgr = new ScheduledNotificationManager(context);
    mgr.rescheduleNotifications();/* w w w. j a va  2 s. c  o  m*/
}

From source file:com.ayogo.cordova.notification.ScheduledNotificationManager.java

License:Apache License

public ScheduledNotification scheduleNotification(String title, JSONObject options) {
    LOG.v(NotificationPlugin.TAG, "scheduleNotification: " + title);

    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    ScheduledNotification notification = new ScheduledNotification(title, options);

    long alarmTime = notification.at;

    if (alarmTime != 0) { //0 = uninitialized.

        saveNotification(notification);//www  . j  a  va 2s .  c  o  m

        LOG.v(NotificationPlugin.TAG, "create Intent: " + notification.tag);

        Intent intent = new Intent(context, TriggerReceiver.class);
        intent.setAction(notification.tag);

        PendingIntent pi = PendingIntent.getBroadcast(context, INTENT_REQUEST_CODE, intent,
                PendingIntent.FLAG_CANCEL_CURRENT);

        LOG.v(NotificationPlugin.TAG, "schedule alarm for: " + alarmTime);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            alarmManager.setExact(AlarmManager.RTC_WAKEUP, alarmTime, pi);
        } else {
            alarmManager.set(AlarmManager.RTC_WAKEUP, alarmTime, pi);
        }
    } else {
        // No "at", trigger the notification right now.
        showNotification(notification);
    }

    return notification;
}

From source file:com.ayogo.cordova.notification.ScheduledNotificationManager.java

License:Apache License

public void rescheduleNotifications() {
    LOG.v(NotificationPlugin.TAG, "rescheduleNotifications");

    JSONArray notifications = getNotifications();
    long now = System.currentTimeMillis();

    for (int i = 0; i < notifications.length(); i++) {
        try {//from www  .  ja  v  a  2 s .  c  o  m
            JSONObject opts = notifications.getJSONObject(i);
            long at = opts.optLong("at", 0);

            if (at > now) {
                LOG.v(NotificationPlugin.TAG, "notification is in the future");
                //Reschedule the notification
                scheduleNotification(opts.optString("title", null), opts);
            } else {
                LOG.v(NotificationPlugin.TAG, "notification is in the past");
                cancelNotification(opts.getString("tag"));
            }
        } catch (JSONException e) {
        }
    }
}

From source file:com.ayogo.cordova.notification.ScheduledNotificationManager.java

License:Apache License

public JSONArray getNotifications() {
    LOG.v(NotificationPlugin.TAG, "getNotifications");

    SharedPreferences prefs = getPrefs();
    Map<String, ?> notes = prefs.getAll();

    JSONArray notifications = new JSONArray();

    for (String key : notes.keySet()) {
        try {/*from w w w  . jav a2  s . c om*/
            JSONObject value = new JSONObject(notes.get(key).toString());
            notifications.put(value);
        } catch (JSONException e) {
        }
    }

    LOG.v(NotificationPlugin.TAG, notifications.toString());

    return notifications;
}