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, Object... args) 

Source Link

Document

Error log message with printf formatting.

Usage

From source file:com.darktalker.cordova.screenshot.PermissionHelper.java

License:Apache License

/**
 * Requests "dangerous" permissions for the application at runtime. This is a helper method
 * alternative to cordovaInterface.requestPermissions() that does not require the project to be
 * built with cordova-android 5.0.0+//www  .j  a v  a2  s. com
 *
 * @param plugin        The plugin the permissions are being requested for
 * @param requestCode   A requestCode to be passed to the plugin's onRequestPermissionResult()
 *                      along with the result of the permissions request
 * @param permissions   The permissions to be requested
 */
public static void requestPermissions(CordovaPlugin plugin, int requestCode, String[] permissions) {
    try {
        Method requestPermission = CordovaInterface.class.getDeclaredMethod("requestPermissions",
                CordovaPlugin.class, int.class, String[].class);

        // If there is no exception, then this is cordova-android 5.0.0+
        requestPermission.invoke(plugin.cordova, plugin, requestCode, permissions);
    } catch (NoSuchMethodException noSuchMethodException) {
        // cordova-android version is less than 5.0.0, so permission is implicitly granted
        LOG.d(LOG_TAG, "No need to request permissions " + Arrays.toString(permissions));

        // Notify the plugin that all were granted by using more reflection
        deliverPermissionResult(plugin, requestCode, permissions);
    } catch (IllegalAccessException illegalAccessException) {
        // Should never be caught; this is a public method
        LOG.e(LOG_TAG, "IllegalAccessException when requesting permissions " + Arrays.toString(permissions),
                illegalAccessException);
    } catch (InvocationTargetException invocationTargetException) {
        // This method does not throw any exceptions, so this should never be caught
        LOG.e(LOG_TAG, "invocationTargetException when requesting permissions " + Arrays.toString(permissions),
                invocationTargetException);
    }
}

From source file:com.darktalker.cordova.screenshot.PermissionHelper.java

License:Apache License

/**
 * Checks at runtime to see if the application has been granted a permission. This is a helper
 * method alternative to cordovaInterface.hasPermission() that does not require the project to
 * be built with cordova-android 5.0.0+/* w  ww  .  j  a v a 2  s.c o  m*/
 *
 * @param plugin        The plugin the permission is being checked against
 * @param permission    The permission to be checked
 *
 * @return              True if the permission has already been granted and false otherwise
 */
public static boolean hasPermission(CordovaPlugin plugin, String permission) {
    try {
        Method hasPermission = CordovaInterface.class.getDeclaredMethod("hasPermission", String.class);

        // If there is no exception, then this is cordova-android 5.0.0+
        return (Boolean) hasPermission.invoke(plugin.cordova, permission);
    } catch (NoSuchMethodException noSuchMethodException) {
        // cordova-android version is less than 5.0.0, so permission is implicitly granted
        LOG.d(LOG_TAG, "No need to check for permission " + permission);
        return true;
    } catch (IllegalAccessException illegalAccessException) {
        // Should never be caught; this is a public method
        LOG.e(LOG_TAG, "IllegalAccessException when checking permission " + permission, illegalAccessException);
    } catch (InvocationTargetException invocationTargetException) {
        // This method does not throw any exceptions, so this should never be caught
        LOG.e(LOG_TAG, "invocationTargetException when checking permission " + permission,
                invocationTargetException);
    }
    return false;
}

From source file:com.darktalker.cordova.screenshot.PermissionHelper.java

License:Apache License

private static void deliverPermissionResult(CordovaPlugin plugin, int requestCode, String[] permissions) {
    // Generate the request results
    int[] requestResults = new int[permissions.length];
    Arrays.fill(requestResults, PackageManager.PERMISSION_GRANTED);

    try {/* w w  w .j av a 2 s.  c  o  m*/
        Method onRequestPermissionResult = CordovaPlugin.class.getDeclaredMethod("onRequestPermissionResult",
                int.class, String[].class, int[].class);

        onRequestPermissionResult.invoke(plugin, requestCode, permissions, requestResults);
    } catch (NoSuchMethodException noSuchMethodException) {
        // Should never be caught since the plugin must be written for cordova-android 5.0.0+ if it
        // made it to this point
        LOG.e(LOG_TAG, "NoSuchMethodException when delivering permissions results", noSuchMethodException);
    } catch (IllegalAccessException illegalAccessException) {
        // Should never be caught; this is a public method
        LOG.e(LOG_TAG, "IllegalAccessException when delivering permissions results", illegalAccessException);
    } catch (InvocationTargetException invocationTargetException) {
        // This method may throw a JSONException. We are just duplicating cordova-android's
        // exception handling behavior here; all it does is log the exception in CordovaActivity,
        // print the stacktrace, and ignore it
        LOG.e(LOG_TAG, "InvocationTargetException when delivering permissions results",
                invocationTargetException);
    }
}

From source file:com.example.imageZoom.ActivityPlugin.java

License:Apache License

public void startActivity(String className, String ImageURL) {
    try {/* w  w w .  j  a  va2 s.  c o  m*/
        Intent intent = new Intent().setClass(this.cordova.getActivity(), Class.forName(className));
        intent.putExtra("imageURL", ImageURL);
        LOG.d(TAG, "Starting activity %s", className);
        this.cordova.getActivity().startActivity(intent);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
        LOG.e(TAG, "Error starting activity %s", className);
    }
}

From source file:com.facilityhero.plugin.camera.FileHelper.java

License:Apache License

/**
 * Returns the real path of the given URI string.
 * If the given URI string represents a content:// URI, the real path is retrieved from the media store.
 *
 * @param uriString the URI string of the audio/image/video
 * @param cordova the current application context
 * @return the full path to the file//  w  w  w  . ja v a  2 s  . c om
 */
@SuppressWarnings("deprecation")
public static String getRealPath(String uriString, CordovaInterface cordova) {
    String realPath = null;

    if (uriString.startsWith("content://")) {
        String[] proj = { _DATA };
        Cursor cursor = cordova.getActivity().managedQuery(Uri.parse(uriString), proj, null, null, null);
        int column_index = cursor.getColumnIndexOrThrow(_DATA);
        cursor.moveToFirst();
        realPath = cursor.getString(column_index);
        if (realPath == null) {
            LOG.e(LOG_TAG, "Could get real path for URI string %s", uriString);
        }
    } else if (uriString.startsWith("file://")) {
        realPath = uriString.substring(7);
        if (realPath.startsWith("/android_asset/")) {
            LOG.e(LOG_TAG, "Cannot get real path for URI string %s because it is a file:///android_asset/ URI.",
                    uriString);
            realPath = null;
        }
    } else {
        realPath = uriString;
    }

    return realPath;
}

From source file:com.luoteng.folk.plugins.ActivityPlugin.java

License:Apache License

public void startActivity(String className, String startUrl, JSONObject extraPrefs) throws JSONException {
    try {//from  w w  w.  j  a v a 2  s. co m
        if (!startUrl.contains(":")) {
            startUrl = "file:///android_asset/www/" + startUrl;
        }
        Intent intent = new Intent(this.cordova.getActivity(), Class.forName(className));
        intent.putExtra("testStartUrl", startUrl);
        Iterator<String> iter = extraPrefs.keys();
        while (iter.hasNext()) {
            String key = iter.next();
            intent.putExtra(key, extraPrefs.getString(key));
        }
        LOG.d(TAG, "Starting activity %s", className);
        this.cordova.getActivity().startActivity(intent);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
        LOG.e(TAG, "Error starting activity %s", className);
    }
}

From source file:com.mirasense.scanditsdk.plugin.PermissionHelper.java

License:Apache License

private static void deliverPermissionResult(CordovaPlugin plugin, int requestCode, String[] permissions) {
    // Generate the request results
    int[] requestResults = new int[permissions.length];
    Arrays.fill(requestResults, PackageManager.PERMISSION_GRANTED);

    try {//from   www.jav a 2  s.c o m
        Method onRequestPermissionResult = CordovaPlugin.class.getDeclaredMethod("onRequestPermissionResult",
                int.class, String[].class, int[].class);

        onRequestPermissionResult.invoke(plugin, requestCode, permissions, requestResults);
    } catch (NoSuchMethodException noSuchMethodException) {
        // Should never be caught since the plugin must be written for cordova-android 5.0.0+
        // if it made it to this point
        LOG.e(LOG_TAG, "NoSuchMethodException when delivering permissions results", noSuchMethodException);
    } catch (IllegalAccessException illegalAccessException) {
        // Should never be caught; this is a public method
        LOG.e(LOG_TAG, "IllegalAccessException when delivering permissions results", illegalAccessException);
    } catch (InvocationTargetException invocationTargetException) {
        // This method may throw a JSONException. We are just duplicating cordova-android's
        // exception handling behavior here; all it does is log the exception in CordovaActivity,
        // print the stacktrace, and ignore it
        LOG.e(LOG_TAG, "InvocationTargetException when delivering permissions results",
                invocationTargetException);
    }
}

From source file:com.phonegap.plugins.ImageResizer.ImageResizePlugin.java

License:Open Source License

private boolean resizeImage(JSONObject params, String format, Bitmap bmp, String filePath,
        CallbackContext callbackContext) throws JSONException, IOException, URISyntaxException {
    double widthFactor;
    double heightFactor;

    // Pixels or Factor resize
    String resizeType = params.getString("resizeType");

    // Get width and height parameters
    double width = params.getDouble("width");
    double height = params.getDouble("height");

    if (resizeType.equals(RESIZE_TYPE_MIN_PIXEL)) {
        widthFactor = width / ((double) bmp.getWidth());
        heightFactor = height / ((double) bmp.getHeight());
        if (widthFactor > heightFactor && widthFactor <= 1.0) {
            heightFactor = widthFactor;/*from   w  ww  .java2s.c om*/
        } else if (heightFactor <= 1.0) {
            widthFactor = heightFactor;
        } else {
            widthFactor = 1.0;
            heightFactor = 1.0;
        }
    } else if (resizeType.equals(RESIZE_TYPE_MAX_PIXEL)) {
        widthFactor = width / ((double) bmp.getWidth());
        heightFactor = height / ((double) bmp.getHeight());
        if (widthFactor == 0.0) {
            widthFactor = heightFactor;
        } else if (heightFactor == 0.0) {
            heightFactor = widthFactor;
        } else if (widthFactor > heightFactor) {
            widthFactor = heightFactor; // scale to fit height
        } else {
            heightFactor = widthFactor; // scale to fit width
        }
    } else {
        // default resizeType.equals(RESIZE_TYPE_FACTOR)
        widthFactor = width;
        heightFactor = height;
    }

    if (params.getBoolean("pixelDensity")) {
        DisplayMetrics metrics = cordova.getActivity().getResources().getDisplayMetrics();
        if (metrics.density > 1) {
            if (widthFactor * metrics.density < 1.0 && heightFactor * metrics.density < 1.0) {
                widthFactor *= metrics.density;
                heightFactor *= metrics.density;
            } else {
                widthFactor = 1.0;
                heightFactor = 1.0;
            }
        }
    }

    Bitmap resized;
    if (widthFactor == 1 && heightFactor == 1) {
        // no need to resize
        resized = bmp;
    } else {
        LOG.e(LOG_TAG, "resize image %s", filePath);
        resized = getResizedBitmap(bmp, (float) widthFactor, (float) heightFactor, filePath);
    }

    if (params.getBoolean("storeImage")) {
        return storeImage(params, format, resized, callbackContext);
    } else {
        int quality = params.getInt("quality");
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        if (format.equals(FORMAT_PNG)) {
            resized.compress(Bitmap.CompressFormat.PNG, quality, baos);
        } else {
            resized.compress(Bitmap.CompressFormat.JPEG, quality, baos);
        }
        byte[] b = baos.toByteArray();
        String returnString = Base64.encodeToString(b, Base64.DEFAULT);
        // return object
        JSONObject res = new JSONObject();
        res.put("imageData", returnString);
        res.put("width", resized.getWidth());
        res.put("height", resized.getHeight());
        recyleBitmap(resized);
        callbackContext.success(res);
    }
    return true;
}

From source file:com.srikanth.phonegap.ActivityPlugin.java

License:Apache License

public void startActivity(String className) {
    try {/*from www. j  ava  2 s.  c om*/
        Intent intent = new Intent().setClass(this.cordova.getActivity(), Class.forName(className));
        LOG.d(TAG, "Starting activity %s", className);
        this.cordova.getActivity().startActivity(intent);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
        LOG.e(TAG, "Error starting activity %s", className);
    }
}

From source file:com.zsxsoft.cordova.x5.X5WebViewClient.java

License:Apache License

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override//www  .ja  v  a  2 s . c o  m
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
    try {
        // Check the against the whitelist and lock out access to the WebView directory
        // Changing this will cause problems for your application
        if (!parentEngine.pluginManager.shouldAllowRequest(url)) {
            LOG.w(TAG, "URL blocked by whitelist: " + url);
            // Results in a 404.
            return new WebResourceResponse("text/plain", "UTF-8", null);
        }

        CordovaResourceApi resourceApi = parentEngine.resourceApi;
        Uri origUri = Uri.parse(url);
        // Allow plugins to intercept WebView requests.
        Uri remappedUri = resourceApi.remapUri(origUri);

        if (!origUri.equals(remappedUri) || needsSpecialsInAssetUrlFix(origUri)
                || needsKitKatContentUrlFix(origUri)) {
            CordovaResourceApi.OpenForReadResult result = resourceApi.openForRead(remappedUri, true);
            return new WebResourceResponse(result.mimeType, "UTF-8", result.inputStream);
        }
        // If we don't need to special-case the request, let the browser load it.
        return null;
    } catch (IOException e) {
        if (!(e instanceof FileNotFoundException)) {
            LOG.e(TAG, "Error occurred while loading a file (returning a 404).", e);
        }
        // Results in a 404.
        return new WebResourceResponse("text/plain", "UTF-8", null);
    }
}