@Override public void onPause(boolean multitasking) { super.onPause(multitasking); gForeground = false; final NotificationManager notificationManager = (NotificationManager) cordova.getActivity().getSystemService(Context.NOTIFICATION_SERVICE); // notificationManager.cancelAll(); }
/** Called when the app navigates or refreshes. */ public void onReset() { Iterator<PluginEntry> it = this.entries.values().iterator(); while (it.hasNext()) { CordovaPlugin plugin = it.next().plugin; if (plugin != null) { plugin.onReset(); } } }
@Override public void onDestroy() { super.onDestroy(); gForeground = false; gECB = null; gWebView = null; }
@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); }
@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); } }
private void execHelper( final String service, final String action, final String callbackId, final String rawArgs) { CordovaPlugin plugin = getPlugin(service); if (plugin == null) { Log.d(TAG, "exec() call to unknown plugin: " + service); PluginResult cr = new PluginResult(PluginResult.Status.CLASS_NOT_FOUND_EXCEPTION); app.sendPluginResult(cr, callbackId); return; } CallbackContext callbackContext = new CallbackContext(callbackId, app); try { long pluginStartTime = System.currentTimeMillis(); boolean wasValidAction = plugin.execute(action, rawArgs, callbackContext); long duration = System.currentTimeMillis() - pluginStartTime; if (duration > SLOW_EXEC_WARNING_THRESHOLD) { Log.w( TAG, "THREAD WARNING: exec() call to " + service + "." + action + " blocked the main thread for " + duration + "ms. Plugin should use CordovaInterface.getThreadPool()."); } if (!wasValidAction) { PluginResult cr = new PluginResult(PluginResult.Status.INVALID_ACTION); callbackContext.sendPluginResult(cr); } } catch (JSONException e) { PluginResult cr = new PluginResult(PluginResult.Status.JSON_EXCEPTION); callbackContext.sendPluginResult(cr); } catch (Exception e) { Log.e(TAG, "Uncaught exception from plugin", e); callbackContext.error(e.getMessage()); } }
/** * Handle the user's action from the permissioning workflow. In this workflow a user may be asked * for access to his profile, email, offline access etc. * * <p>There are three situations we cover: * * <p>1. The user clicks sign in. We are not yet connected to the google services api. (common * case) * * <p>2. The user clicks sign in and we are already connected to the google services api. This * case is less common, and it's a bit confusing why we'd already be connected to the google * services api before the user clicks sign in. This case happens when the user sees multiple * pages in the permission workflow. The user will see multiple pages in the workflow when we * connect to the google services api (successfully), but on connection google tells us that we * should prompt the user for even more permissions that the first page of the workflow didn't ask * for via a UserRecoverableAuthException. For example, a user may first be prompted for basic * profile access. Then when we connect to the google services api it may suggest that we also * need to prompt the user for offline access. In this case we don't bother reconnecting to the * google services api again. Instead, we skip straight to resolving to the token. * * <p>3. The user clicks cancel. * * @param requestCode The request code originally supplied to startActivityForResult(), * @param resultCode The integer result code returned by the child activity through its * setResult(). * @param intent Information returned by the child activity */ @Override public void onActivityResult(int requestCode, final int resultCode, final Intent intent) { super.onActivityResult(requestCode, resultCode, intent); if (mGoogleApiClient == null) { buildGoogleApiClient(); } if (!mGoogleApiClient.isConnected() && resultCode == Activity.RESULT_OK) { mGoogleApiClient.connect(); } else if (resultCode == Activity.RESULT_OK) { this.resolveToken(email, result); } else { this.savedCallbackContext.error("user cancelled"); } }
public void onActivityResult(int requestCode, int resultCode, Intent intent) { Log.v(TAG, "onActivityResult: " + requestCode + " " + resultCode); super.onActivityResult(requestCode, resultCode, intent); if (ACTIVITY_CODE_PLAY_MEDIA == requestCode) { if (Activity.RESULT_OK == resultCode) { this.callbackContext.success(); } else if (Activity.RESULT_CANCELED == resultCode) { String errMsg = "Error"; if (intent != null && intent.hasExtra("message")) { errMsg = intent.getStringExtra("message"); } this.callbackContext.error(errMsg); } } }
@Override public void onResume(boolean multitasking) { super.onResume(multitasking); gForeground = true; checkPlayServices(); }
@Override public void initialize(CordovaInterface cordova, CordovaWebView webView) { super.initialize(cordova, webView); gForeground = true; checkPlayServices(); }
@Override public void initialize(CordovaInterface cordova, CordovaWebView webView) { super.initialize(cordova, webView); logger = new Logger(cordova, webView); }
@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()); } }); }
@Override public void initialize(CordovaInterface cordova, CordovaWebView webView) { super.initialize(cordova, webView); // your init code here }