Example usage for org.apache.cordova LOG e

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

Introduction

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

Prototype

public static void e(String tag, String s) 

Source Link

Document

Error log message.

Usage

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

License:Open Source License

/**
 * Sets the context of the Command. This can then be used to do things like get file paths associated with the
 * Activity./*from  w  w w .j ava2  s . c  o  m*/
 * 
 * @param cordova
 *            The context of the main Activity.
 * @param webView
 *            The associated CordovaWebView.
 */
@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
    super.initialize(cordova, webView);
    // Initialize only for Amazon devices 2nd Generation and later
    if (this.isAmazonDevice() && !isFirstGenKindleFireDevice()) {
        adm = new ADM(cordova.getActivity());
        activity = (CordovaActivity) cordova.getActivity();
        webview = this.webView;
        isForeground = true;
        ADMMessageHandler.saveConfigOptions(activity);
    } else {
        LOG.e(TAG, NON_AMAZON_DEVICE_ERROR);
    }
}

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

License:Open Source License

/**
 * @see Plugin#execute(String, JSONArray, String)
 *///from w  w w. ja  va 2s  .  c o  m
@Override
public boolean execute(final String request, final JSONArray args, CallbackContext callbackContext)
        throws JSONException {
    try {
        // check ADM readiness
        ADMReadiness ready = isPushPluginReady();
        if (ready == ADMReadiness.NON_AMAZON_DEVICE) {
            callbackContext.error(NON_AMAZON_DEVICE_ERROR);
            return false;
        } else if (ready == ADMReadiness.ADM_NOT_SUPPORTED) {
            callbackContext.error(ADM_NOT_SUPPORTED_ERROR);
            return false;
        } else if (callbackContext == null) {
            LOG.e(TAG, "CallbackConext is null. Notification to WebView is not possible. Can not proceed.");
            return false;
        }

        // Process the request here
        if (REGISTER.equals(request)) {

            if (args == null) {
                LOG.e(TAG, REGISTER_OPTIONS_NULL);
                callbackContext.error(REGISTER_OPTIONS_NULL);
                return false;
            }

            // parse args to get eventcallback name
            if (args.isNull(0)) {
                LOG.e(TAG, ECB_NOT_SPECIFIED);
                callbackContext.error(ECB_NOT_SPECIFIED);
                return false;
            }

            JSONObject jo = args.getJSONObject(0);
            if (jo.getString("ecb").isEmpty()) {
                LOG.e(TAG, ECB_NAME_NOT_SPECIFIED);
                callbackContext.error(ECB_NAME_NOT_SPECIFIED);
                return false;
            }
            callbackContext.success(REGISTRATION_SUCCESS_RESPONSE);
            notificationHandlerCallBack = jo.getString(ECB);
            String regId = adm.getRegistrationId();
            LOG.d(TAG, "regId = " + regId);
            if (regId == null) {
                adm.startRegister();
            } else {
                sendRegistrationIdWithEvent(REGISTER_EVENT, regId);
            }

            // see if there are any messages while app was in background and
            // launched via app icon
            LOG.d(TAG, "checking for offline message..");
            deliverPendingMessageAndCancelNotifiation();
            return true;

        } else if (UNREGISTER.equals(request)) {
            adm.startUnregister();
            callbackContext.success(UNREGISTRATION_SUCCESS_RESPONSE);
            return true;
        } else {
            LOG.e(TAG, "Invalid action : " + request);
            callbackContext.error("Invalid action : " + request);
            return false;
        }
    } catch (final Exception e) {
        callbackContext.error(e.getMessage());
    }

    return false;
}

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   ww w  .j  av a2s . 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.ScheduledNotificationManager.java

License:Apache License

private Bitmap getIconFromUri(String path) {
    try {/* w w w. j  av a2 s .co m*/
        AssetManager amgr = context.getAssets();
        String tmp_uri = "www/" + path;
        InputStream input = amgr.open(tmp_uri);

        return BitmapFactory.decodeStream(input);
    } catch (IOException e) {
        LOG.e(NotificationPlugin.TAG, "cant load icon from " + "www/" + path);
        LOG.e(NotificationPlugin.TAG, e.getMessage());
        return null;
    }
}

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

License:Apache License

@Override
public void onReceive(Context context, Intent intent) {
    LOG.e(NotificationPlugin.TAG, "Trigger Reciever Triggered!");

    String tag = intent.getAction();

    LOG.e(NotificationPlugin.TAG, "Trigger Tag: " + tag);

    ScheduledNotificationManager mgr = new ScheduledNotificationManager(context);

    // Cancel and Remove the notification from the list of scheduled notifications
    ScheduledNotification notification = mgr.cancelNotification(tag);

    if (notification != null) {
        //Build and show the notification.
        mgr.showNotification(notification);
    } else {/*from  w  ww  . j av  a 2s .c  om*/
        LOG.e(NotificationPlugin.TAG, "Notification " + tag + " is null! ");
    }
}

From source file:com.cooee.cordova.plugins.camera.CameraLauncher.java

License:Apache License

public void onMediaScannerConnected() {
    try {/* w ww.j a  va 2 s .  c  o m*/
        this.conn.scanFile(this.scanMe.toString(), "image/*");
    } catch (java.lang.IllegalStateException e) {
        LOG.e(LOG_TAG, "Can't scan file in MediaScanner after taking picture");
    }

}

From source file:com.github.michaelins.lightstatusbar.LightStatusBar.java

License:Apache License

/**
 * Executes the request and returns PluginResult.
 *
 * @param action/*from www  .  j  a v  a  2s. c om*/
 *            The action to execute.
 * @param args
 *            JSONArry of arguments for the plugin.
 * @param callbackContext
 *            The callback id used when calling back into JavaScript.
 * @return True if the action was valid, false otherwise.
 */
@Override
public boolean execute(final String action, final CordovaArgs args, final CallbackContext callbackContext)
        throws JSONException {

    LOG.v(TAG, "Executing action: " + action);
    final Activity activity = this.cordova.getActivity();
    final Window window = activity.getWindow();

    if ("isSupported".equals(action)) {
        this.cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M || SystemBarTintManager.IsMiuiV6Plus()) {
                    callbackContext.success("true");
                } else {
                    callbackContext.success("false");
                }
            }
        });
        return true;
    }

    if ("setStatusBarColor".equals(action)) {
        this.cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                try {
                    webView.getView().setFitsSystemWindows(true);
                    if (SystemBarTintManager.IsMiuiV6Plus()) {
                        // MIUI6+ light status bar
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                            setTranslucentStatus(window, true);
                        }
                        SystemBarTintManager tintManager = new SystemBarTintManager(activity);
                        tintManager.setStatusBarTintEnabled(true);
                        tintManager.setStatusBarTintColor(Color.parseColor(args.getString(0)));
                        tintManager.setStatusBarDarkMode(true, activity);
                    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                        // 6.0+ light status bar
                        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
                        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                        int uiOptions = window.getDecorView().getSystemUiVisibility()
                                | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
                        window.getDecorView().setSystemUiVisibility(uiOptions);
                        setStatusBarBackgroundColor(args.getString(0));
                    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                        setStatusBarBackgroundColor(args.getString(0));
                    }
                } catch (JSONException ignore) {
                    LOG.e(TAG, "Invalid hexString argument, use f.i. '#777777'");
                }
            }
        });
        return true;
    }

    if ("enable".equals(action)) {
        this.cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
            }
        });
        return true;
    }

    if ("disable".equals(action)) {
        this.cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
            }
        });
        return true;
    }
    return false;
}

From source file:com.github.michaelins.lightstatusbar.LightStatusBar.java

License:Apache License

private void setStatusBarBackgroundColor(final String colorPref) {
    if (colorPref != null && !colorPref.isEmpty()) {
        final Window window = cordova.getActivity().getWindow();
        // Method and constants not available on all SDKs but we want to
        // be able to compile this code with any SDK
        window.clearFlags(0x04000000); // SDK 19:
        // WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.addFlags(0x80000000); // SDK 21:
        // WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        try {//w ww  .  j  ava 2s  . co  m
            // Using reflection makes sure any 5.0+ device will work
            // without having to compile with SDK level 21
            window.getClass().getDeclaredMethod("setStatusBarColor", int.class).invoke(window,
                    Color.parseColor(colorPref));
        } catch (IllegalArgumentException ignore) {
            LOG.e(TAG, "Invalid hexString argument, use f.i. '#999999'");
        } catch (Exception ignore) {
            // this should not happen, only in case Android removes this
            // method in a version > 21
            LOG.w(TAG, "Method window.setStatusBarColor not found for SDK level " + Build.VERSION.SDK_INT);
        }
    }
}

From source file:com.glasgowtiger.inappbrowser.InAppBrowser.java

License:Apache License

/**
 * Executes the request and returns PluginResult.
 *
 * @param action        The action to execute.
 * @param args          JSONArry of arguments for the plugin.
 * @param callbackId    The callback id used when calling back into JavaScript.
 * @return              A PluginResult object with a status and message.
 *//*from  w w  w .j a  v a2  s. com*/
public boolean execute(String action, CordovaArgs args, final CallbackContext callbackContext)
        throws JSONException {
    if (action.equals("open")) {
        this.callbackContext = callbackContext;
        final String url = args.getString(0);
        String t = args.optString(1);
        if (t == null || t.equals("") || t.equals(NULL)) {
            t = SELF;
        }
        final String target = t;
        final HashMap<String, Boolean> features = parseFeature(args.optString(2));

        Log.d(LOG_TAG, "target = " + target);

        this.cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                String result = "";
                // SELF
                if (SELF.equals(target)) {
                    Log.d(LOG_TAG, "in self");
                    /* This code exists for compatibility between 3.x and 4.x versions of Cordova.
                     * Previously the Config class had a static method, isUrlWhitelisted(). That
                     * responsibility has been moved to the plugins, with an aggregating method in
                     * PluginManager.
                     */
                    Boolean shouldAllowNavigation = null;
                    if (url.startsWith("javascript:")) {
                        shouldAllowNavigation = true;
                    }
                    if (shouldAllowNavigation == null) {
                        try {
                            Method iuw = Config.class.getMethod("isUrlWhiteListed", String.class);
                            shouldAllowNavigation = (Boolean) iuw.invoke(null, url);
                        } catch (NoSuchMethodException e) {
                        } catch (IllegalAccessException e) {
                        } catch (InvocationTargetException e) {
                        }
                    }
                    if (shouldAllowNavigation == null) {
                        try {
                            Method gpm = webView.getClass().getMethod("getPluginManager");
                            PluginManager pm = (PluginManager) gpm.invoke(webView);
                            Method san = pm.getClass().getMethod("shouldAllowNavigation", String.class);
                            shouldAllowNavigation = (Boolean) san.invoke(pm, url);
                        } catch (NoSuchMethodException e) {
                        } catch (IllegalAccessException e) {
                        } catch (InvocationTargetException e) {
                        }
                    }
                    // load in webview
                    if (Boolean.TRUE.equals(shouldAllowNavigation)) {
                        Log.d(LOG_TAG, "loading in webview");
                        webView.loadUrl(url);
                    }
                    //Load the dialer
                    else if (url.startsWith(WebView.SCHEME_TEL)) {
                        try {
                            Log.d(LOG_TAG, "loading in dialer");
                            Intent intent = new Intent(Intent.ACTION_DIAL);
                            intent.setData(Uri.parse(url));
                            cordova.getActivity().startActivity(intent);
                        } catch (android.content.ActivityNotFoundException e) {
                            LOG.e(LOG_TAG, "Error dialing " + url + ": " + e.toString());
                        }
                    }
                    // load in InAppBrowser
                    else {
                        Log.d(LOG_TAG, "loading in InAppBrowser");
                        result = showWebPage(url, features);
                    }
                }
                // SYSTEM
                else if (SYSTEM.equals(target)) {
                    Log.d(LOG_TAG, "in system");
                    result = openExternal(url);
                }
                // BLANK - or anything else
                else {
                    Log.d(LOG_TAG, "in blank");
                    result = showWebPage(url, features);
                }

                PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, result);
                pluginResult.setKeepCallback(true);
                callbackContext.sendPluginResult(pluginResult);
            }
        });
    } else if (action.equals("close")) {
        closeDialog();
    } else if (action.equals("injectScriptCode")) {
        String jsWrapper = null;
        if (args.getBoolean(1)) {
            jsWrapper = String.format("prompt(JSON.stringify([eval(%%s)]), 'gap-iab://%s')",
                    callbackContext.getCallbackId());
        }
        injectDeferredObject(args.getString(0), jsWrapper);
    } else if (action.equals("injectScriptFile")) {
        String jsWrapper;
        if (args.getBoolean(1)) {
            jsWrapper = String.format(
                    "(function(d) { var c = d.createElement('script'); c.src = %%s; c.onload = function() { prompt('', 'gap-iab://%s'); }; d.body.appendChild(c); })(document)",
                    callbackContext.getCallbackId());
        } else {
            jsWrapper = "(function(d) { var c = d.createElement('script'); c.src = %s; d.body.appendChild(c); })(document)";
        }
        injectDeferredObject(args.getString(0), jsWrapper);
    } else if (action.equals("injectStyleCode")) {
        String jsWrapper;
        if (args.getBoolean(1)) {
            jsWrapper = String.format(
                    "(function(d) { var c = d.createElement('style'); c.innerHTML = %%s; d.body.appendChild(c); prompt('', 'gap-iab://%s');})(document)",
                    callbackContext.getCallbackId());
        } else {
            jsWrapper = "(function(d) { var c = d.createElement('style'); c.innerHTML = %s; d.body.appendChild(c); })(document)";
        }
        injectDeferredObject(args.getString(0), jsWrapper);
    } else if (action.equals("injectStyleFile")) {
        String jsWrapper;
        if (args.getBoolean(1)) {
            jsWrapper = String.format(
                    "(function(d) { var c = d.createElement('link'); c.rel='stylesheet'; c.type='text/css'; c.href = %%s; d.head.appendChild(c); prompt('', 'gap-iab://%s');})(document)",
                    callbackContext.getCallbackId());
        } else {
            jsWrapper = "(function(d) { var c = d.createElement('link'); c.rel='stylesheet'; c.type='text/css'; c.href = %s; d.head.appendChild(c); })(document)";
        }
        injectDeferredObject(args.getString(0), jsWrapper);
    } else if (action.equals("show")) {
        this.cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                dialog.show();
            }
        });
        PluginResult pluginResult = new PluginResult(PluginResult.Status.OK);
        pluginResult.setKeepCallback(true);
        this.callbackContext.sendPluginResult(pluginResult);
    } else {
        return false;
    }
    return true;
}

From source file:com.gotojmp.cordova.NativeAd.NativeAd.java

License:Apache License

public void onClick(int id, String pos) {
    try {/*from w  w w .j a  va 2  s  .c o m*/
        JSONObject res = new JSONObject();
        res.put("id", id);
        res.put("pos", pos);
        PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, res);
        pluginResult.setKeepCallback(true);
        this.onClickCallbackContext.sendPluginResult(pluginResult);
    } catch (JSONException ex) {
        LOG.e(LOG_TAG, "JSON error.");
    }
}