/* * onKeyDown */ @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (boundKeyCodes.contains(keyCode)) { if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { sendJavascriptEvent("volumedownbutton"); return true; } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { sendJavascriptEvent("volumeupbutton"); return true; } else { return super.onKeyDown(keyCode, event); } } else if (keyCode == KeyEvent.KEYCODE_BACK) { return !(this.startOfHistory()) || isButtonPlumbedToJs(KeyEvent.KEYCODE_BACK); } else if (keyCode == KeyEvent.KEYCODE_MENU) { // How did we get here? Is there a childView? View childView = this.getFocusedChild(); if (childView != null) { // Make sure we close the keyboard if it's present InputMethodManager imm = (InputMethodManager) cordova.getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(childView.getWindowToken(), 0); cordova.getActivity().openOptionsMenu(); return true; } else { return super.onKeyDown(keyCode, event); } } return super.onKeyDown(keyCode, event); }
@Override public void initialize(CordovaInterface cordova, CordovaWebView webView) { super.initialize(cordova, webView); WindowManager manager = ((WindowManager) cordova.getActivity().getApplicationContext().getSystemService(Context.WINDOW_SERVICE)); WindowManager.LayoutParams localLayoutParams = new WindowManager.LayoutParams(); localLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR; localLayoutParams.gravity = Gravity.TOP; localLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | // this is to enable the notification to recieve touch events WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | // Draws over status bar WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT; localLayoutParams.height = (int) (30 * cordova.getActivity().getResources().getDisplayMetrics().scaledDensity); localLayoutParams.format = PixelFormat.TRANSPARENT; CustomViewGroup view = new CustomViewGroup(cordova.getActivity().getApplicationContext()); manager.addView(view, localLayoutParams); }
public void openFileChooser( ValueCallback<Uri> paramValueCallback, String paramString1, String paramString2) { mUploadMessage = paramValueCallback; paramValueCallback = new Intent("android.intent.action.GET_CONTENT"); paramValueCallback.addCategory("android.intent.category.OPENABLE"); paramValueCallback.setType("*/*"); cordova .getActivity() .startActivityForResult(Intent.createChooser(paramValueCallback, "File Browser"), 5173); }
public boolean onJsPrompt( WebView paramWebView, final String paramString1, String paramString2, String paramString3, final JsPromptResult paramJsPromptResult) { paramWebView = appView.bridge.promptOnJsPrompt(paramString1, paramString2, paramString3); if (paramWebView != null) { paramJsPromptResult.confirm(paramWebView); } for (; ; ) { return true; paramWebView = new AlertDialog.Builder(cordova.getActivity()); paramWebView.setMessage(paramString2); paramString1 = new EditText(cordova.getActivity()); if (paramString3 != null) { paramString1.setText(paramString3); } paramWebView.setView(paramString1); paramWebView.setCancelable(false); paramWebView.setPositiveButton( 17039370, new DialogInterface.OnClickListener() { public void onClick( DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt) { paramAnonymousDialogInterface = paramString1.getText().toString(); paramJsPromptResult.confirm(paramAnonymousDialogInterface); } }); paramWebView.setNegativeButton( 17039360, new DialogInterface.OnClickListener() { public void onClick( DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt) { paramJsPromptResult.cancel(); } }); paramWebView.show(); } }
@Override public void initialize(final CordovaInterface cordova, CordovaWebView webView) { super.initialize(cordova, webView); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { final Activity activity = cordova.getActivity(); final Window window = activity.getWindow(); setTranslucentStatus(window); tintManager = new SystemBarTintManager(activity); } }
public boolean onJsConfirm( WebView paramWebView, String paramString1, String paramString2, final JsResult paramJsResult) { paramWebView = new AlertDialog.Builder(cordova.getActivity()); paramWebView.setMessage(paramString2); paramWebView.setTitle("Confirm"); paramWebView.setCancelable(true); paramWebView.setPositiveButton( 17039370, new DialogInterface.OnClickListener() { public void onClick( DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt) { paramJsResult.confirm(); } }); paramWebView.setNegativeButton( 17039360, new DialogInterface.OnClickListener() { public void onClick( DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt) { paramJsResult.cancel(); } }); paramWebView.setOnCancelListener( new DialogInterface.OnCancelListener() { public void onCancel(DialogInterface paramAnonymousDialogInterface) { paramJsResult.cancel(); } }); paramWebView.setOnKeyListener( new DialogInterface.OnKeyListener() { public boolean onKey( DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt, KeyEvent paramAnonymousKeyEvent) { if (paramAnonymousInt == 4) { paramJsResult.cancel(); return false; } return true; } }); paramWebView.show(); return true; }
/** * Load the specified URL in the Cordova webview or a new browser instance. * * <p>NOTE: If openExternal is false, only URLs listed in whitelist can be loaded. * * @param url The url to load. * @param openExternal Load url in browser instead of Cordova webview. * @param clearHistory Clear the history stack, so new page becomes top of history * @param params Parameters for new app */ public void showWebPage( String url, boolean openExternal, boolean clearHistory, HashMap<String, Object> params) { LOG.d(TAG, "showWebPage(%s, %b, %b, HashMap", url, openExternal, clearHistory); // If clearing history if (clearHistory) { this.clearHistory(); } // If loading into our webview if (!openExternal) { // Make sure url is in whitelist if (url.startsWith("file://") || internalWhitelist.isUrlWhiteListed(url)) { // TODO: What about params? // Load new URL loadUrlIntoView(url, true); return; } // Load in default viewer if not LOG.w( TAG, "showWebPage: Cannot load URL into webview since it is not in white list. Loading into browser instead. (URL=" + url + ")"); } try { // Omitting the MIME type for file: URLs causes "No Activity found to handle Intent". // Adding the MIME type to http: URLs causes them to not be handled by the downloader. Intent intent = new Intent(Intent.ACTION_VIEW); Uri uri = Uri.parse(url); if ("file".equals(uri.getScheme())) { intent.setDataAndType(uri, resourceApi.getMimeType(uri)); } else { intent.setData(uri); } cordova.getActivity().startActivity(intent); } catch (android.content.ActivityNotFoundException e) { LOG.e(TAG, "Error loading url " + url, e); } }
@Override public void initialize(final CordovaInterface cordova, final CordovaWebView webView) { super.initialize(cordova, webView); am = (AudioManager) cordova.getActivity().getSystemService(Context.AUDIO_SERVICE); reader = new AudioJackReader(am, true); IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_HEADSET_PLUG); cordova .getActivity() .registerReceiver( new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(Intent.ACTION_HEADSET_PLUG)) { boolean plugged = (intent.getIntExtra("state", 0) == 1); /* Mute the audio output if the reader is unplugged. */ reader.setMute(!plugged); mute = !plugged; } } }, filter); final StringBuffer buffer = new StringBuffer(); final StringBuffer atrBuffer = new StringBuffer(); reader.setSleepTimeout(30); reader.setOnPiccAtrAvailableListener( new AudioJackReader.OnPiccAtrAvailableListener() { @Override public void onPiccAtrAvailable(AudioJackReader audioJackReader, byte[] bytes) { Log.w(TAG, bytesToHex(bytes)); atrBuffer.append(bytesToHex(bytes)); } }); reader.setOnPiccResponseApduAvailableListener( new AudioJackReader.OnPiccResponseApduAvailableListener() { @Override public void onPiccResponseApduAvailable(AudioJackReader audioJackReader, byte[] bytes) { byte[] resultBytes = new byte[bytes.length - 2]; byte[] statusBytes = new byte[2]; System.arraycopy(bytes, 0, resultBytes, 0, bytes.length - 2); System.arraycopy(bytes, bytes.length - 2, statusBytes, 0, 2); Log.w(TAG, bytesToHex(statusBytes)); buffer.append(bytesToHex(resultBytes)); buffer.append(""); } }); reader.setOnStatusAvailableListener( new AudioJackReader.OnStatusAvailableListener() { @Override public void onStatusAvailable(AudioJackReader audioJackReader, final Status status) { timer.cancel(); cordova .getActivity() .runOnUiThread( new Runnable() { @Override public void run() { JSONArray resultArray = new JSONArray(); resultArray.put(Integer.toString(status.getBatteryLevel())); resultArray.put(Integer.toString(status.getSleepTimeout())); PluginResult dataResult = new PluginResult(PluginResult.Status.OK, resultArray); callbackContext.sendPluginResult(dataResult); } }); } }); reader.setOnDeviceIdAvailableListener( new AudioJackReader.OnDeviceIdAvailableListener() { @Override public void onDeviceIdAvailable(AudioJackReader audioJackReader, final byte[] bytes) { // reader.sleep(); timer.cancel(); cordova .getActivity() .runOnUiThread( new Runnable() { @Override public void run() { PluginResult dataResult = new PluginResult(PluginResult.Status.OK, bytesToHex(bytes)); callbackContext.sendPluginResult(dataResult); } }); } }); reader.setOnResultAvailableListener( new AudioJackReader.OnResultAvailableListener() { @Override public void onResultAvailable(AudioJackReader audioJackReader, Result result) { // reader.sleep(); timer.cancel(); final String stringResult = buffer.toString(); final String atrResult = atrBuffer.toString(); Log.i(TAG, "Result Available"); Log.i(TAG, stringResult); cordova .getActivity() .runOnUiThread( new Runnable() { @Override public void run() { if (timedOut) { PluginResult dataResult = new PluginResult(PluginResult.Status.OK, "TIMEDOUT"); callbackContext.sendPluginResult(dataResult); } else { JSONArray resultArray = new JSONArray(); resultArray.put(stringResult.replaceAll("\\s", "")); resultArray.put(atrResult.replaceAll("\\s", "")); PluginResult dataResult = new PluginResult(PluginResult.Status.OK, resultArray); callbackContext.sendPluginResult(dataResult); } } }); buffer.delete(0, buffer.length()); atrBuffer.delete(0, atrBuffer.length()); } }); }