List of usage examples for org.apache.cordova LOG w
public static void w(String tag, String s)
From source file:com.ayogo.cordova.push.PushPlugin.java
License:Apache License
@Override protected void pluginInitialize() { LOG.v(TAG, "Initializing"); // Check device for Play Services APK. if (!checkPlayServices()) { LOG.w(TAG, "No valid Google Play Services APK found."); return;/*from w w w .ja va 2s. c o m*/ } mSenderID = this.preferences.getString("fcm_sender_id", null); onNewIntent(cordova.getActivity().getIntent()); }
From source file:com.ayogo.cordova.push.PushPlugin.java
License:Apache License
/** * Check the device to make sure it has the Google Play Services APK. * * If it doesn't, display a dialog that allows users to download the APK * from the Google Play Store or enable it in the device's system settings. *//*from w w w. java2s. c o m*/ private boolean checkPlayServices() { GoogleApiAvailability googleApi = GoogleApiAvailability.getInstance(); Activity act = this.cordova.getActivity(); int resultCode = googleApi.isGooglePlayServicesAvailable(act.getApplicationContext()); if (resultCode != ConnectionResult.SUCCESS) { if (googleApi.isUserResolvableError(resultCode)) { googleApi.getErrorDialog(act, resultCode, PLAY_SERVICES_RESOLUTION_REQUEST).show(); } else { LOG.w(TAG, "This device is not supported."); } return false; } return true; }
From source file:com.dtworkshop.inappcrossbrowser.InAppChromeClient.java
License:Apache License
/** * Tell the client to display a prompt dialog to the user. * If the client returns true, WebView will assume that the client will * handle the prompt dialog and call the appropriate JsPromptResult method. * * The prompt bridge provided for the InAppBrowser is capable of executing any * oustanding callback belonging to the InAppBrowser plugin. Care has been * taken that other callbacks cannot be triggered, and that no other code * execution is possible.//from w ww .jav a 2 s . c o m * * To trigger the bridge, the prompt default value should be of the form: * * gap-iab://<callbackId> * * where <callbackId> is the string id of the callback to trigger (something * like "InAppBrowser0123456789") * * If present, the prompt message is expected to be a JSON-encoded value to * pass to the callback. A JSON_EXCEPTION is returned if the JSON is invalid. * * @param view * @param url * @param message * @param defaultValue * @param result */ @Override public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result) { // See if the prompt string uses the 'gap-iab' protocol. If so, the remainder should be the id of a callback to execute. if (defaultValue != null && defaultValue.startsWith("gap")) { if (defaultValue.startsWith("gap-iab://")) { PluginResult scriptResult; String scriptCallbackId = defaultValue.substring(10); if (scriptCallbackId.startsWith("InAppBrowser")) { if (message == null || message.length() == 0) { scriptResult = new PluginResult(PluginResult.Status.OK, new JSONArray()); } else { try { scriptResult = new PluginResult(PluginResult.Status.OK, new JSONArray(message)); } catch (JSONException e) { scriptResult = new PluginResult(PluginResult.Status.JSON_EXCEPTION, e.getMessage()); } } this.webView.sendPluginResult(scriptResult, scriptCallbackId); result.confirm(""); return true; } } else { // Anything else with a gap: prefix should get this message LOG.w(LOG_TAG, "InAppBrowser does not support Cordova API calls: " + url + " " + defaultValue); result.cancel(); return true; } } return false; }
From source file:com.emeth.cordova.ble.central.Peripheral.java
License:Apache License
private void registerNotifyCallback(CallbackContext callbackContext, UUID serviceUUID, UUID characteristicUUID) { boolean success = false; if (gatt == null) { callbackContext.error("BluetoothGatt is null"); return;/*from w w w . j a v a2 s. c o m*/ } BluetoothGattService service = gatt.getService(serviceUUID); BluetoothGattCharacteristic characteristic = service.getCharacteristic(characteristicUUID); String key = generateHashKey(serviceUUID, characteristic); if (characteristic != null) { notificationCallbacks.put(key, callbackContext); if (gatt.setCharacteristicNotification(characteristic, true)) { // Why doesn't setCharacteristicNotification write the descriptor? BluetoothGattDescriptor descriptor = characteristic .getDescriptor(CLIENT_CHARACTERISTIC_CONFIGURATION_UUID); if (descriptor != null) { // prefer notify over indicate if ((characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_NOTIFY) != 0) { descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); } else if ((characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_INDICATE) != 0) { descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE); } else { LOG.w(TAG, "Characteristic " + characteristicUUID + " does not have NOTIFY or INDICATE property set"); } if (gatt.writeDescriptor(descriptor)) { success = true; } else { callbackContext.error( "Failed to set client characteristic notification for " + characteristicUUID); } } else { callbackContext.error("Set notification failed for " + characteristicUUID); } } else { callbackContext.error("Failed to register notification for " + characteristicUUID); } } else { callbackContext.error("Characteristic " + characteristicUUID + " not found"); } if (!success) { commandCompleted(); } }
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 {//from w w w . jav a 2 s .c o 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.initialxy.cordova.themeablebrowser.InAppChromeClient.java
License:Apache License
/** * Tell the client to display a prompt dialog to the user. * If the client returns true, WebView will assume that the client will * handle the prompt dialog and call the appropriate JsPromptResult method. * * The prompt bridge provided for the ThemeableBrowser is capable of executing any * oustanding callback belonging to the ThemeableBrowser plugin. Care has been * taken that other callbacks cannot be triggered, and that no other code * execution is possible./*from w ww . ja v a2 s. c o m*/ * * To trigger the bridge, the prompt default value should be of the form: * * gap-iab://<callbackId> * * where <callbackId> is the string id of the callback to trigger (something * like "ThemeableBrowser0123456789") * * If present, the prompt message is expected to be a JSON-encoded value to * pass to the callback. A JSON_EXCEPTION is returned if the JSON is invalid. * * @param view * @param url * @param message * @param defaultValue * @param result */ @Override public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result) { // See if the prompt string uses the 'gap-iab' protocol. If so, the remainder should be the id of a callback to execute. if (defaultValue != null && defaultValue.startsWith("gap")) { if (defaultValue.startsWith("gap-iab://")) { PluginResult scriptResult; String scriptCallbackId = defaultValue.substring(10); if (scriptCallbackId.startsWith("ThemeableBrowser")) { if (message == null || message.length() == 0) { scriptResult = new PluginResult(PluginResult.Status.OK, new JSONArray()); } else { try { scriptResult = new PluginResult(PluginResult.Status.OK, new JSONArray(message)); } catch (JSONException e) { scriptResult = new PluginResult(PluginResult.Status.JSON_EXCEPTION, e.getMessage()); } } this.webView.sendPluginResult(scriptResult, scriptCallbackId); result.confirm(""); return true; } } else { // Anything else with a gap: prefix should get this message LOG.w(LOG_TAG, "ThemeableBrowser does not support Cordova API calls: " + url + " " + defaultValue); result.cancel(); return true; } } return false; }
From source file:com.viniciusfagundes.cordova.plugin.navigationbar.NavigationBar.java
License:Open Source License
private void setNavigationBarBackgroundColor(final String colorPref) { if (Build.VERSION.SDK_INT >= 21) { 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 { // Using reflection makes sure any 5.0+ device will work without having to compile with SDK level 21 window.getClass().getDeclaredMethod("setNavigationBarColor", 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.setNavigationBarColor not found for SDK level " + Build.VERSION.SDK_INT); }/*from w w w . j a v a 2s.c om*/ } } }
From source file:com.zsxsoft.cordova.x5.X5WebViewClient.java
License:Apache License
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override// w ww .j a v a2 s. co 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); } }
From source file:de.appplant.cordova.plugin.notification.Options.java
License:Open Source License
/** * Action buttons for notification//from w w w . jav a 2s . co m */ public NotificationCompat.Action[] getActions() { // recupero l'array delle actions che mi arrivano dal javascript JSONArray actions = options.optJSONArray("actions"); // se non ne ho specificate, oppure trovo un array vuoto, esco subito if (actions == null || actions.length() < 1) return new NotificationCompat.Action[0]; // inizializzo l'array che torner NotificationCompat.Action[] notificationActions = new NotificationCompat.Action[actions.length()]; // ciclo le actions e creo le corrispondenti `NotificationCompat.Action` da mettere nell'array for (int i = 0; i < actions.length(); i++) { try { // recupero l'iesimo `JSONObject` JSONObject action = actions.optJSONObject(i); // se nullo vado avanti con l'iterazione successiva if (action == null) { LOG.w(TAG, "Null action found. Skipping!"); continue; } String actionLabel = action.optString("label", null); // String actionDeepLink = action.optString("uri", null); String actionId = action.optString("id", null); int actionRequestCode = NotificationActions.requestCodeForAction(actionId); if (actionLabel == null || actionRequestCode < 0) { LOG.w(TAG, "Invalid action found. Skipping!"); continue; } Class clickActivityClass = ClickActivity.class; if (clickActivityClass == null) { LOG.e(TAG, "Click activity not found. Very Bad... Breaking!"); break; } Intent actionIntent = new Intent(context, clickActivityClass) .putExtra(Options.EXTRA, options.toString()).putExtra(Options.ACTION, actionId) .setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); PendingIntent pendingIntent = PendingIntent.getActivity(context, new Random().nextInt(), actionIntent, PendingIntent.FLAG_UPDATE_CURRENT); notificationActions[i] = new NotificationCompat.Action.Builder(0, actionLabel, pendingIntent) .build(); } catch (Exception e) { LOG.e(TAG, "Eccezione in getActions()", e); } } return notificationActions; }
From source file:org.codaco.networkCanvas.plugin.NetworkCanvasClient.java
License:Apache License
private FileUtils getCdvFilePlugin(CordovaWebView webView) { PluginManager pluginManager = null;/*from w w w .j ava 2 s . co m*/ try { Method method = webView.getClass().getMethod("getPluginManager"); pluginManager = (PluginManager) method.invoke(webView); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { // try getField } if (pluginManager == null) { try { Field field = webView.getClass().getField("pluginManager"); pluginManager = (PluginManager) field.get(webView); } catch (IllegalAccessException | NoSuchFieldException e) { // Log warning below } } if (pluginManager != null) { return (FileUtils) pluginManager.getPlugin("File"); } LOG.w(LogTag, "Could not get FilePlugin; download interface will not be available"); return null; }