@Override public void initialize(CordovaInterface cordova, CordovaWebView webView) { cordovaInterface = cordova; super.initialize(cordova, webView); appName = getApplicationName(this.cordova.getActivity().getApplicationContext()); handle = new PhoneAccountHandle(new ComponentName(this.cordova.getActivity().getApplicationContext(),MyConnectionService.class),appName); tm = (TelecomManager)this.cordova.getActivity().getApplicationContext().getSystemService(this.cordova.getActivity().getApplicationContext().TELECOM_SERVICE); phoneAccount = new PhoneAccount.Builder(handle, appName) .setCapabilities(PhoneAccount.CAPABILITY_CALL_PROVIDER) .build(); callbackContextMap.put("answer",new ArrayList<CallbackContext>()); callbackContextMap.put("reject",new ArrayList<CallbackContext>()); callbackContextMap.put("hangup",new ArrayList<CallbackContext>()); callbackContextMap.put("sendCall",new ArrayList<CallbackContext>()); callbackContextMap.put("receiveCall",new ArrayList<CallbackContext>()); }
/** * Executes the request. * * @param action The action to execute. * @param cordova The cordova interface. * @param webView The cordova web view. */ static void execute(String action, CordovaInterface cordova, CordovaWebView webView) { BackgroundExt ext = new BackgroundExt(cordova, webView); if (action.equalsIgnoreCase("optimizations")) { ext.disableWebViewOptimizations(); } if (action.equalsIgnoreCase("background")) { ext.moveToBackground(); } if (action.equalsIgnoreCase("foreground")) { ext.moveToForeground(); } if (action.equalsIgnoreCase("tasklist")) { ext.excludeFromTaskList(); } }
/** * Sets the context of the Command. This can then be used to do things like * get file paths associated with the Activity. * * @param cordova The context of the main Activity. * @param webView The CordovaWebView Cordova is running in. */ public void initialize(CordovaInterface cordova, CordovaWebView webView) { super.initialize(cordova, webView); this.sockMan = (ConnectivityManager) cordova.getActivity().getSystemService(Context.CONNECTIVITY_SERVICE); this.connectionCallbackContext = null; // We need to listen to connectivity events to update navigator.connection IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); if (this.receiver == null) { this.receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { // (The null check is for the ARM Emulator, please use Intel Emulator for better results) if(NetworkManager.this.webView != null) updateConnectionInfo(sockMan.getActiveNetworkInfo()); } }; webView.getContext().registerReceiver(this.receiver, intentFilter); } }
/** * Sets the context of the Command. This can then be used to do things like * get file paths associated with the Activity. * * @param cordova The context of the main Activity. * @param webView The CordovaWebView Cordova is running in. */ @Override public void initialize(final CordovaInterface cordova, CordovaWebView webView) { LOG.v(TAG, "StatusBar: initialization"); super.initialize(cordova, webView); this.cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { // Clear flag FLAG_FORCE_NOT_FULLSCREEN which is set initially // by the Cordova. Window window = cordova.getActivity().getWindow(); window.clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); // Read 'StatusBarBackgroundColor' from config.xml, default is #000000. setStatusBarBackgroundColor(preferences.getString("StatusBarBackgroundColor", "#000000")); // Read 'StatusBarStyle' from config.xml, default is 'lightcontent'. setStatusBarStyle(preferences.getString("StatusBarStyle", "lightcontent")); } }); }
@Override public void initialize(final CordovaInterface cordova, final CordovaWebView webView) { super.initialize(cordova, webView); parseCordovaConfigXml(); loadPluginInternalPreferences(); Log.d("CHCP", "Currently running release version " + pluginInternalPrefs.getCurrentReleaseVersionName()); // clean up file system cleanupFileSystemFromOldReleases(); handler = new Handler(); fileStructure = new PluginFilesStructure(cordova.getActivity(), pluginInternalPrefs.getCurrentReleaseVersionName()); appConfigStorage = new ApplicationConfigStorage(); defaultCallbackStoredResults = new ArrayList<PluginResult>(); }
/** * Call this after constructing to initialize the plugin. * Final because we want to be able to change args without breaking plugins. */ public final void privateInitialize(String serviceName, CordovaInterface cordova, CordovaWebView webView, CordovaPreferences preferences) { assert this.cordova == null; this.serviceName = serviceName; this.cordova = cordova; this.webView = webView; this.preferences = preferences; initialize(cordova, webView); pluginInitialize(); }
@Override public void init(CordovaWebView parentWebView, CordovaInterface cordova, CordovaWebViewEngine.Client client, CordovaResourceApi resourceApi, PluginManager pluginManager, NativeToJsMessageQueue nativeToJsMessageQueue) { if (this.cordova != null) { throw new IllegalStateException(); } // Needed when prefs are not passed by the constructor if (preferences == null) { preferences = parentWebView.getPreferences(); } this.parentWebView = parentWebView; this.cordova = cordova; this.client = client; this.resourceApi = resourceApi; this.pluginManager = pluginManager; this.nativeToJsMessageQueue = nativeToJsMessageQueue; webView.init(this, cordova); initWebViewSettings(); nativeToJsMessageQueue.addBridgeMode(new NativeToJsMessageQueue.OnlineEventsBridgeMode(new NativeToJsMessageQueue.OnlineEventsBridgeMode.OnlineEventsBridgeModeDelegate() { @Override public void setNetworkAvailable(boolean value) { webView.setNetworkAvailable(value); } @Override public void runOnUiThread(Runnable r) { SystemWebViewEngine.this.cordova.getActivity().runOnUiThread(r); } })); if(Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2) nativeToJsMessageQueue.addBridgeMode(new NativeToJsMessageQueue.EvalBridgeMode(this, cordova)); bridge = new CordovaBridge(pluginManager, nativeToJsMessageQueue); exposeJsInterface(webView, bridge); }
@Override public void initialize(final CordovaInterface cordova, final CordovaWebView webView) { super.initialize(cordova, webView); // parse config only if main plugin is installed isChcpPluginInstalled = isHotCodePushPluginIsInstalled(); if (isChcpPluginInstalled) { parseCordovaConfigXml(); } }
private void emitWindowEvent(final String event, final JSONObject data) { final CordovaWebView view = this.webView; this.cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { view.loadUrl(String.format("javascript:cordova.fireWindowEvent('%s', %s);", event, data.toString())); } }); }
@Test public void testViaLoadUrl() throws Throwable { final CordovaWebView webInterface = mActivity.getWebInterface(); assertEquals(START_URL, mActivity.onPageFinishedUrl.take()); mActivityRule.runOnUiThread(new Runnable() { public void run() { webInterface.loadUrl("file:///android_asset/www/backbuttonmultipage/sample2.html"); } }); assertEquals("file:///android_asset/www/backbuttonmultipage/sample2.html", mActivity.onPageFinishedUrl.take()); mActivityRule.runOnUiThread(new Runnable() { public void run() { webInterface.loadUrl("file:///android_asset/www/backbuttonmultipage/sample3.html"); } }); assertEquals("file:///android_asset/www/backbuttonmultipage/sample3.html", mActivity.onPageFinishedUrl.take()); mActivityRule.runOnUiThread(new Runnable() { public void run() { assertTrue(webInterface.backHistory()); } }); assertEquals("file:///android_asset/www/backbuttonmultipage/sample2.html", mActivity.onPageFinishedUrl.take()); mActivityRule.runOnUiThread(new Runnable() { public void run() { assertTrue(webInterface.backHistory()); } }); assertEquals(START_URL, mActivity.onPageFinishedUrl.take()); mActivityRule.runOnUiThread(new Runnable() { public void run() { assertFalse(webInterface.backHistory()); } }); }
@Override public void initialize(CordovaInterface cordova, CordovaWebView webView) { super.initialize(cordova, webView); _cordova = cordova; _cordovaActivity = cordova.getActivity(); _sharedPreferences = PreferenceManager.getDefaultSharedPreferences(_cordovaActivity); _permissionsController = new PermissionsController(_cordovaActivity, _cordova); _permissionsController.handleOnInitialize(); removeActionPreferences(); Log.d(TAG, "Initialized"); }
@Test public void checkBackgroundIntentCheck() { StandardActivity activity = (StandardActivity) mActivityRule.getActivity(); final SystemWebView webView = (SystemWebView) activity.getWindow().getCurrentFocus(); CordovaWebView webInterface = webView.getCordovaWebView(); CordovaPreferences prefs = webInterface.getPreferences(); assertFalse(prefs.getInteger("backgroundcolor", Color.BLACK) == Color.GREEN); }
@Override public void initialize(CordovaInterface cordova, CordovaWebView webView) { super.initialize(cordova, webView); activity = cordova.getActivity(); //如果是首次启动,并且点击的通知消息,则处理消息 if (openNotificationId != 0) { notificationOpened(openNotificationId, openNotificationExtras); } }
@Override public void init(CordovaWebView parentWebView, CordovaInterface cordova, Client client, CordovaResourceApi resourceApi, PluginManager pluginManager, NativeToJsMessageQueue nativeToJsMessageQueue) { if (this.cordova != null) { throw new IllegalStateException(); } // Needed when prefs are not passed by the constructor if (preferences == null) { preferences = parentWebView.getPreferences(); } this.parentWebView = parentWebView; this.cordova = cordova; this.client = client; this.resourceApi = resourceApi; this.pluginManager = pluginManager; this.nativeToJsMessageQueue = nativeToJsMessageQueue; webView.init(this, cordova); initWebViewSettings(); nativeToJsMessageQueue.addBridgeMode(new NativeToJsMessageQueue.OnlineEventsBridgeMode(new NativeToJsMessageQueue.OnlineEventsBridgeMode.OnlineEventsBridgeModeDelegate() { @Override public void setNetworkAvailable(boolean value) { webView.setNetworkAvailable(value); } @Override public void runOnUiThread(Runnable r) { X5WebViewEngine.this.cordova.getActivity().runOnUiThread(r); } })); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2) nativeToJsMessageQueue.addBridgeMode(new NativeToJsMessageQueue.EvalBridgeMode(this, cordova)); bridge = new CordovaBridge(pluginManager, nativeToJsMessageQueue); exposeJsInterface(webView, bridge); }
private void fireEvent(final String event) { final CordovaWebView view = this.webView; this.cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { view.loadUrl("javascript:cordova.fireDocumentEvent('" + event + "');"); } }); }
private void fireEvent(final String event, final JSONObject data) { final CordovaWebView view = this.webView; this.cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { view.loadUrl(String.format("javascript:cordova.fireDocumentEvent('%s', %s);", event, data.toString())); } }); }
@Test public void testViaHref() throws Throwable { final CordovaWebView webInterface = mActivity.getWebInterface(); assertEquals(START_URL, mActivity.onPageFinishedUrl.take()); mActivityRule.runOnUiThread(new Runnable() { public void run() { webInterface.sendJavascript("window.location = 'sample2.html';"); } }); assertEquals("file:///android_asset/www/backbuttonmultipage/sample2.html", mActivity.onPageFinishedUrl.take()); mActivityRule.runOnUiThread(new Runnable() { public void run() { webInterface.sendJavascript("window.location = 'sample3.html';"); } }); assertEquals("file:///android_asset/www/backbuttonmultipage/sample3.html", mActivity.onPageFinishedUrl.take()); mActivityRule.runOnUiThread(new Runnable() { public void run() { assertTrue(webInterface.backHistory()); } }); assertEquals("file:///android_asset/www/backbuttonmultipage/sample2.html", mActivity.onPageFinishedUrl.take()); mActivityRule.runOnUiThread(new Runnable() { public void run() { assertTrue(webInterface.backHistory()); } }); assertEquals(START_URL, mActivity.onPageFinishedUrl.take()); mActivityRule.runOnUiThread(new Runnable() { public void run() { assertFalse(webInterface.backHistory()); } }); }
@Override public void initialize(CordovaInterface cordova, CordovaWebView webView) { super.initialize(cordova, webView); this.filesystems = new ArrayList<Filesystem>(); this.pendingRequests = new PendingRequests(); String tempRoot = null; String persistentRoot = null; Activity activity = cordova.getActivity(); String packageName = activity.getPackageName(); String location = preferences.getString("androidpersistentfilelocation", "internal"); tempRoot = activity.getCacheDir().getAbsolutePath(); if ("internal".equalsIgnoreCase(location)) { persistentRoot = activity.getFilesDir().getAbsolutePath() + "/files/"; this.configured = true; } else if ("compatibility".equalsIgnoreCase(location)) { /* * Fall-back to compatibility mode -- this is the logic implemented in * earlier versions of this plugin, and should be maintained here so * that apps which were originally deployed with older versions of the * plugin can continue to provide access to files stored under those * versions. */ if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { persistentRoot = Environment.getExternalStorageDirectory().getAbsolutePath(); tempRoot = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/" + packageName + "/cache/"; } else { persistentRoot = "/data/data/" + packageName; } this.configured = true; } if (this.configured) { // Create the directories if they don't exist. File tmpRootFile = new File(tempRoot); File persistentRootFile = new File(persistentRoot); tmpRootFile.mkdirs(); persistentRootFile.mkdirs(); // Register initial filesystems // Note: The temporary and persistent filesystems need to be the first two // registered, so that they will match window.TEMPORARY and window.PERSISTENT, // per spec. this.registerFilesystem(new LocalFilesystem("temporary", webView.getContext(), webView.getResourceApi(), tmpRootFile)); this.registerFilesystem(new LocalFilesystem("persistent", webView.getContext(), webView.getResourceApi(), persistentRootFile)); this.registerFilesystem(new ContentFilesystem(webView.getContext(), webView.getResourceApi())); this.registerFilesystem(new AssetFilesystem(webView.getContext().getAssets(), webView.getResourceApi())); registerExtraFileSystems(getExtraFileSystemsPreference(activity), getAvailableFileSystems(activity)); // Initialize static plugin reference for deprecated getEntry method if (filePlugin == null) { FileUtils.filePlugin = this; } } else { LOG.e(LOG_TAG, "File plugin configuration error: Please set AndroidPersistentFileLocation in config.xml to one of \"internal\" (for new applications) or \"compatibility\" (for compatibility with previous versions)"); activity.finish(); } }
@Override public CordovaWebView getCordovaWebView() { return parentWebView; }
public CallbackContext(String callbackId, CordovaWebView webView) { this.callbackId = callbackId; this.webView = webView; }
/**--------------------------------------------------------------- */ public void initialize(CordovaInterface cordova, CordovaWebView webView) { cordovaWebView = webView; super.initialize(cordova, webView); }
public InAppChromeClient(CordovaWebView webView) { super(); this.webView = webView; }
@Override public void initialize(CordovaInterface cordova, CordovaWebView webView) { context = this.cordova.getActivity().getApplicationContext(); super.initialize(cordova, webView); }