Example usage for org.apache.cordova LOG i

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

Introduction

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

Prototype

public static void i(String tag, String s) 

Source Link

Document

Info log message.

Usage

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

License:Open Source License

/**
 * Sends events to JS using cordova nativeToJS bridge.
 * //www .  j  a  v  a2s . c  o  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.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 www.  j a  v  a 2s . 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.push.PushPlugin.java

License:Apache License

@Override
public boolean execute(String action, JSONArray args, final CallbackContext callback) {
    if (action.equals("registerPush") || action.equals("getPushRegistration")) {
        cordova.getThreadPool().execute(new Runnable() {
            public void run() {
                try {
                    String deviceToken = FirebaseInstanceId.getInstance().getToken(mSenderID,
                            FirebaseMessaging.INSTANCE_ID_SCOPE);

                    callback.sendPluginResult(
                            new PluginResult(PluginResult.Status.OK, wrapRegistrationData(deviceToken)));
                } catch (IOException ex) {
                    callback.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, "AbortError"));
                }// ww  w .ja  v a2  s  .  c o  m
            }
        });
        return true;
    }

    if (action.equals("unregisterPush")) {
        cordova.getThreadPool().execute(new Runnable() {
            public void run() {
                try {
                    FirebaseInstanceId.getInstance().deleteToken(mSenderID,
                            FirebaseMessaging.INSTANCE_ID_SCOPE);

                    callback.sendPluginResult(new PluginResult(PluginResult.Status.OK));
                } catch (IOException ex) {
                    callback.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, "AbortError"));
                }
            }
        });
        return true;
    }

    if (action.equals("hasPermission")) {
        // Android doesn't require permission to send push notifications
        callback.sendPluginResult(new PluginResult(PluginResult.Status.OK, "granted"));
        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.cf.code.lx.MainActivity.java

License:Apache License

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // enable Cordova apps to be started in the background
    Bundle extras = getIntent().getExtras();
    if (extras != null && extras.getBoolean("cdvStartInBackground", false)) {
        moveTaskToBack(true);/*from w  ww  .j a v  a2  s  . c om*/
    }

    // Set by <content src="index.html" /> in config.xml
    loadUrl(launchUrl);
    //MultiImageSelector.create().start(this, 1);
    LOG.i("congfeng", MultiImageSelector.create() + "");
}

From source file:com.nolgong.pedometer.Pedometer.java

License:Apache License

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    LOG.i(TAG, "execute()");
    this.callbackContext = callbackContext;
    if (action.equals("isStepCountingAvailable")) {
        this.isStepCountingAvailable();
    } else if (action.equals("startPedometerUpdates")) {

        if (!this.activityRunning) {
            this.startPedometerUpdates();
        }/*from   w  w  w  .ja  va2  s .c  om*/
    } else if (action.equals("stopPedometerUpdates")) {
        if (this.activityRunning) {
            this.stopPedometerUpdates();
        }
    } else {
        return false;
    }
    PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT, "");
    result.setKeepCallback(true);
    callbackContext.sendPluginResult(result);
    return true;
}

From source file:com.nolgong.pedometer.Pedometer.java

License:Apache License

@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
    LOG.i(TAG, "initialize() " + sensorManager);
    super.initialize(cordova, webView);
    sensorManager = (SensorManager) cordova.getActivity().getSystemService(Context.SENSOR_SERVICE);
    this.numberOfSteps = 0;
}

From source file:com.nolgong.pedometer.Pedometer.java

License:Apache License

public void isStepCountingAvailable() {
    this.activityRunning = true;
    countSensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
    if (countSensor != null) {
        LOG.i(TAG, "isStepCountingAvailable() " + countSensor);
        sensorManager.registerListener(this, countSensor, SensorManager.SENSOR_DELAY_UI);
        PluginResult result = new PluginResult(PluginResult.Status.OK);
        result.setKeepCallback(true);//ww w . j  a v  a2  s  .  c o  m
        callbackContext.sendPluginResult(result);
    } else {
        LOG.i(TAG, "isStepCountingAvailable() fail");
        PluginResult err = new PluginResult(PluginResult.Status.ERROR);
        err.setKeepCallback(true);
        callbackContext.sendPluginResult(err);
    }
}

From source file:com.nolgong.pedometer.Pedometer.java

License:Apache License

public void startPedometerUpdates() {
    LOG.i(TAG, "startPedometerUpdates() " + this.activityRunning);
    if (this.activityRunning) {
        return;/* w  ww.  j a v a  2 s. com*/
    }
    this.activityRunning = true;
    countSensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
    if (countSensor != null) {
        LOG.i(TAG, "StepCountingAvailable " + countSensor);
        sensorManager.registerListener(this, countSensor, SensorManager.SENSOR_DELAY_UI);
        this.activityRunning = true;
    } else {
        LOG.i(TAG, "StepCountingAvailable fail");
        this.activityRunning = false;
        JSONObject errorObj = new JSONObject();
        try {
            errorObj.put("message", "Step Counter could not be started.");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        PluginResult err = new PluginResult(PluginResult.Status.ERROR, errorObj);
        err.setKeepCallback(true);
        callbackContext.sendPluginResult(err);
        return;
    }
}

From source file:com.nolgong.pedometer.Pedometer.java

License:Apache License

@Override
public void onSensorChanged(SensorEvent event) {
    //        LOG.i(TAG, "onSensorChanged()");
    if (this.activityRunning) {
        if (this.accuracy >= SensorManager.SENSOR_STATUS_ACCURACY_HIGH) {
            long temptime = System.currentTimeMillis();
            if (temptime - this.timestamp > 2000) {
                LOG.i(TAG, "onSensorChanged() count : " + event.values[0]);
                this.numberOfSteps = event.values[0];
                // this.timestamp = System.currentTimeMillis();
                this.timestamp = temptime;
                PluginResult result = new PluginResult(PluginResult.Status.OK, this.getStepCountJSON());
                result.setKeepCallback(true);
                callbackContext.sendPluginResult(result);
            }/*w w  w.  java  2 s . c  om*/
        }
    }
}

From source file:com.nolgong.pedometer.Pedometer.java

License:Apache License

@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
    if (this.activityRunning) {
        LOG.i(TAG, "onAccuracyChanged() " + accuracy);
        this.accuracy = accuracy;
    }//from   www.  j ava2s. c o m
}