void page_BackKeyPress(object sender, CancelEventArgs e) { if (OverrideBackButton) { try { CordovaBrowser.InvokeScript("eval", new string[] { "cordova.fireDocumentEvent('backbutton', {}, true);" }); e.Cancel = true; } catch (Exception ex) { Console.WriteLine("Exception while invoking backbutton into cordova view: " + ex.Message); } } else { try { PageDidChange = false; Uri uriBefore = this.Browser.Source; // calling js history.back with result in a page change if history was valid. CordovaBrowser.InvokeScript("eval", new string[] { "(function(){window.history.back();})()" }); Uri uriAfter = this.Browser.Source; e.Cancel = PageDidChange || (uriBefore != uriAfter); } catch (Exception) { e.Cancel = false; // exit the app ... ? } } }
void page_BackKeyPress(object sender, CancelEventArgs e) { if (OverrideBackButton) { try { CordovaBrowser.InvokeScript("CordovaCommandResult", new string[] { "backbutton" }); e.Cancel = true; } catch (Exception ex) { Console.WriteLine("Exception while invoking backbutton into cordova view: " + ex.Message); } } else { try { PageDidChange = false; // calling js history.back with result in a page change if history was valid. CordovaBrowser.InvokeScript("eval", new string[] { "(function(){window.history.back();})()" }); e.Cancel = PageDidChange; } catch (Exception) { e.Cancel = false; // exit the app ... ? } } }
void CordovaBrowser_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e) { string[] autoloadPlugs = this.configHandler.AutoloadPlugins; foreach (string plugName in autoloadPlugs) { // nativeExecution.ProcessCommand(commandCallParams); } string nativeReady = "(function(){ cordova.require('cordova/channel').onNativeReady.fire()})();"; try { CordovaBrowser.InvokeScript("execScript", new string[] { nativeReady }); } catch (Exception /*ex*/) { Debug.WriteLine("Error calling js to fire nativeReady event. Did you include cordova-x.x.x.js in your html script tag?"); } if (this.CordovaBrowser.Opacity < 1) { this.CordovaBrowser.Opacity = 1; RotateIn.Begin(); } }
void page_BackKeyPress(object sender, CancelEventArgs e) { if (OverrideBackButton) { try { CordovaBrowser.InvokeScript("CordovaCommandResult", new string[] { "backbutton" }); e.Cancel = true; } catch (Exception ex) { Console.WriteLine("Exception while invoking backbutton into cordova view: " + ex.Message); } } else { if (history.Count > 1) { history.Pop(); Uri next = history.Peek(); IsBackButtonPressed = true; CordovaBrowser.Navigate(next); e.Cancel = true; } } }
void CordovaBrowser_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e) { if (IsExiting) { // Special case, we navigate to about:blank when we are about to exit. IsolatedStorageSettings.ApplicationSettings.Save(); Application.Current.Terminate(); return; } Debug.WriteLine("CordovaBrowser_LoadCompleted"); string version = "?"; System.Windows.Resources.StreamResourceInfo streamInfo = Application.GetResourceStream(new Uri("VERSION", UriKind.Relative)); if (streamInfo != null) { using (StreamReader sr = new StreamReader(streamInfo.Stream)) { version = sr.ReadLine(); } } Debug.WriteLine("Apache Cordova native platform version " + version + " is starting"); string[] autoloadPlugs = this.configHandler.AutoloadPlugins; foreach (string plugName in autoloadPlugs) { nativeExecution.AutoLoadCommand(plugName); } // send js code to fire ready event string nativeReady = "(function(){ cordova.require('cordova/channel').onNativeReady.fire()})();"; try { CordovaBrowser.InvokeScript("eval", new string[] { nativeReady }); } catch (Exception /*ex*/) { Debug.WriteLine("Error calling js to fire nativeReady event. Did you include cordova.js in your html script tag?"); } // attach js code to dispatch exitApp string appExitHandler = "(function(){navigator.app = navigator.app || {}; navigator.app.exitApp= function(){cordova.exec(null,null,'CoreEvents','__exitApp',[]); }})();"; try { CordovaBrowser.InvokeScript("eval", new string[] { appExitHandler }); } catch (Exception /*ex*/) { Debug.WriteLine("Error calling js to add appExit funtion."); } if (this.CordovaBrowser.Opacity < 1) { FadeIn.Begin(); } }
/* * This method does the work of routing commands * NotifyEventArgs.Value contains a string passed from JS * If the command already exists in our map, we will just attempt to call the method(action) specified, and pass the args along * Otherwise, we create a new instance of the command, add it to the map, and call it ... * This method may also receive JS error messages caught by window.onerror, in any case where the commandStr does not appear to be a valid command * it is simply output to the debugger output, and the method returns. * **/ void CordovaBrowser_ScriptNotify(object sender, NotifyEventArgs e) { string commandStr = e.Value; string commandName = commandStr.Split('/').FirstOrDefault(); if (browserDecorators.ContainsKey(commandName)) { browserDecorators[commandName].HandleCommand(commandStr); return; } CordovaCommandCall commandCallParams = CordovaCommandCall.Parse(commandStr); if (commandCallParams == null) { // ERROR Debug.WriteLine("ScriptNotify :: " + commandStr); } else if (commandCallParams.Service == "CoreEvents") { switch (commandCallParams.Action.ToLower()) { case "overridebackbutton": string arg0 = JsonHelper.Deserialize <string[]>(commandCallParams.Args)[0]; this.OverrideBackButton = (arg0 != null && arg0.Length > 0 && arg0.ToLower() == "true"); break; case "__exitapp": Debug.WriteLine("Received exitApp command from javascript, app will now exit."); CordovaBrowser.InvokeScript("eval", new string[] { "cordova.fireDocumentEvent('pause');" }); CordovaBrowser.InvokeScript("eval", new string[] { "setTimeout(function(){ cordova.fireDocumentEvent('exit'); cordova.exec(null,null,'CoreEvents','__finalexit',[]); },0);" }); break; case "__finalexit": IsExiting = true; // hide the browser to prevent white flashes, since about:blank seems to always be white CordovaBrowser.Opacity = 0d; CordovaBrowser.Navigate(new Uri("about:blank", UriKind.Absolute)); break; } } else { if (configHandler.IsPluginAllowed(commandCallParams.Service)) { commandCallParams.Namespace = configHandler.GetNamespaceForCommand(commandCallParams.Service); nativeExecution.ProcessCommand(commandCallParams); } else { Debug.WriteLine("Error::Plugin not allowed in config.xml. " + commandCallParams.Service); } } }
void AppActivated(object sender, Microsoft.Phone.Shell.ActivatedEventArgs e) { Debug.WriteLine("INFO: AppActivated"); try { CordovaBrowser.InvokeScript("CordovaCommandResult", new string[] { "resume" }); } catch (Exception) { Debug.WriteLine("ERROR: Resume event error"); } }
void AppActivated(object sender, Microsoft.Phone.Shell.ActivatedEventArgs e) { Debug.WriteLine("INFO: AppActivated"); try { CordovaBrowser.InvokeScript("eval", new string[] { "cordova.fireDocumentEvent('resume');" }); } catch (Exception) { Debug.WriteLine("ERROR: Resume event error"); } }
private void service_Resuming(object sender, object e) { Debug.WriteLine("INFO: AppActivated"); try { CordovaBrowser.InvokeScript("eval", new string[] { "cordova.fireDocumentEvent('resume');" }); } catch (Exception) { Debug.WriteLine("ERROR: Resume event error"); } }
void AppDeactivated(object sender, DeactivatedEventArgs e) { Debug.WriteLine("INFO: AppDeactivated because " + e.Reason); try { CordovaBrowser.InvokeScript("eval", new string[] { "cordova.fireDocumentEvent('pause');" }); } catch (Exception) { Debug.WriteLine("ERROR: Pause event error"); } }
void AppDeactivated(object sender, DeactivatedEventArgs e) { Debug.WriteLine("INFO: AppDeactivated"); try { CordovaBrowser.InvokeScript("CordovaCommandResult", new string[] { "pause" }); } catch (Exception) { Debug.WriteLine("ERROR: Pause event error"); } }
private void service_Suspending(object sender, Windows.ApplicationModel.SuspendingEventArgs e) { Debug.WriteLine("INFO: AppDeactivated"); try { CordovaBrowser.InvokeScript("eval", new string[] { "cordova.fireDocumentEvent('pause');" }); } catch (Exception) { Debug.WriteLine("ERROR: Pause event error"); } }
void CordovaBrowser_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e) { if (IsExiting) { // Special case, we navigate to about:blank when we are about to exit. IsolatedStorageSettings.ApplicationSettings.Save(); Application.Current.Terminate(); return; } Debug.WriteLine("CordovaBrowser_LoadCompleted"); string[] autoloadPlugs = this.configHandler.AutoloadPlugins; foreach (string plugName in autoloadPlugs) { //nativeExecution.ProcessCommand(commandCallParams); } // send js code to fire ready event string nativeReady = "(function(){ cordova.require('cordova/channel').onNativeReady.fire(); angular.bootstrap(document,['opvko']); alert('ready')})();"; try { CordovaBrowser.InvokeScript("execScript", new string[] { nativeReady }); } catch (Exception /*ex*/) { Debug.WriteLine("Error calling js to fire nativeReady event. Did you include cordova.js in your html script tag?"); } // attach js code to dispatch exitApp string appExitHandler = "(function(){navigator.app = navigator.app || {}; navigator.app.exitApp= function(){cordova.exec(null,null,'CoreEvents','__exitApp',[]); }})();"; try { CordovaBrowser.InvokeScript("execScript", new string[] { appExitHandler }); } catch (Exception /*ex*/) { Debug.WriteLine("Error calling js to add appExit funtion."); } if (this.CordovaBrowser.Opacity < 1) { FadeIn.Begin(); } }
void page_BackKeyPress(object sender, CancelEventArgs e) { if (OverrideBackButton) { try { //--this is a hack so that we can exit the app if necessary Object val = CordovaBrowser.InvokeScript("eval", "do_hardware_back_button()"); if (val.Equals("1")) { e.Cancel = true; } //-- //-- old cordova code // CordovaBrowser.InvokeScript("CordovaCommandResult", new string[] { "backbutton" }); // e.Cancel = true; //-- } catch (Exception ex) { Console.WriteLine("Exception while invoking backbutton into cordova view: " + ex.Message); } } else { try { PageDidChange = false; Uri uriBefore = this.Browser.Source; // calling js history.back with result in a page change if history was valid. CordovaBrowser.InvokeScript("eval", new string[] { "(function(){window.history.back();})()" }); Uri uriAfter = this.Browser.Source; e.Cancel = PageDidChange || (uriBefore != uriAfter); } catch (Exception) { e.Cancel = false; // exit the app ... ? } } }
void GapBrowser_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e) { string nativeReady = "(function(){ cordova.require('cordova/channel').onNativeReady.fire()})();"; try { CordovaBrowser.InvokeScript("execScript", new string[] { nativeReady }); } catch (Exception /*ex*/) { Debug.WriteLine("Error calling js to fire nativeReady event. Did you include cordova-x.x.x.js in your html script tag?"); } if (this.CordovaBrowser.Opacity < 1) { this.CordovaBrowser.Opacity = 1; RotateIn.Begin(); } }
private void GapBrowser_LoadCompleted(object sender, NavigationEventArgs e) { string nativeReady = "(function(){ cordova.require('cordova/channel').onNativeReady.fire()})();"; try { var unloadFunc = "(function(){ function navigating(){ window.external.notify('%%' + location.href);} window.onbeforeunload=navigating;return location.href;})();"; var host = CordovaBrowser.InvokeScript("eval", new string[] { unloadFunc }); CordovaBrowser.AllowedScriptNotifyUris = new[] { new Uri(host) }; CordovaBrowser.InvokeScript("execScript", new string[] { nativeReady }); } catch (Exception /*ex*/) { Debug.WriteLine("Error calling js to fire nativeReady event. Did you include cordova-x.x.x.js in your html script tag?"); } if (this.CordovaBrowser.Opacity < 1) { this.CordovaBrowser.Opacity = 1; } }