/// <summary> /// Creates a new App. /// </summary> public App() { InitializeComponent(); // Services _navigationService = Container.Bind <IWindowsPhoneNavigationService, WindowsPhoneNavigationService>(); Container.Bind <ISettingsStorage, WindowsPhoneSettingsStorage>(); Container.Bind <IHttpClient, HttpClient>(); Container.Bind <IBrowserService, BrowserService>(); Container.Bind <IEmailService, EmailService>(); Container.Bind <IPhoneService, PhoneService>(); Container.Bind <ILocationService, LocationService>(); Container.Bind <ITileService, TileService>(); Container.Bind <IDeviceIdentifier, DeviceIdentifier>(); Container.Bind <IRatingService, RatingService>(); Container.Bind <IDataCache, WindowsPhoneDataCache>(); Container.Bind <ICredentialsStorage, WindowsPhoneCredentialsStorage>(); _pluginLoader = Container.Bind <IPluginLoader, PluginLoader>(); _logger = Container.Bind <Logger, GoogleAnalyticsLogger>(); // Common part of plugins & services initialization AppInitializer.Initialize(_pluginLoader, _navigationService); // View-ViewModels bindings for Main _navigationService.Bind <MainViewModel>("/Views/MainView.xaml"); _navigationService.Bind <SettingsViewModel>("/Views/SettingsView.xaml"); _navigationService.Bind <AboutViewModel>("/Views/AboutView.xaml"); // URI mapping LauncherEx.RegisterProtocol(PocketCampusProtocol, NavigateToCustomUri); // WP-specific part of plugin initialization _plugins = _pluginLoader.GetPlugins().Cast <IWindowsPhonePlugin>().ToArray(); foreach (var plugin in _plugins) { plugin.Initialize(_navigationService); } // Debug settings DebugSettings.UserIdleDetectionMode = IdleDetectionMode.Disabled; // Theme initialization ThemeManager.OverrideOptions = ThemeManagerOverrideOptions.ApplicationBarColors; ThemeManager.ToLightTheme(); ThemeManager.SetAccentColor((Color)Resources["AppAccentColor"]); }
/// <summary> /// Processes a positive scan result. /// </summary> private void ProcessResult(Result result) { if (_isDone) { // this is sometimes called once too many?? return; } string url = result.Text; if (url.StartsWith(CustomUrlPrefix)) { Messenger.Send(new EventLogRequest("QRCodeScanned", url.Replace(CustomUrlLogPrefix, ""))); LauncherEx.Launch(url); Close(); } else { WrongCodeMessage.Visibility = Visibility.Visible; } }
/// <summary> /// Converts an HTML node into an Inline. /// </summary> private static Inline ToInline(HtmlNode node) { switch (node.Name) { case "br": return(new LineBreak()); case "a": string text = node.InnerText; string url = node.GetAttributeValue("href", ""); if (string.IsNullOrWhiteSpace(text)) { text = url; } var link = new Hyperlink { Inlines = { new Run { Text = text, Foreground = new SolidColorBrush(Colors.Blue) } }, NavigateUri = new Uri(url, UriKind.Absolute), TargetName = "42" // can be anything, it just needs to be set }; link.Click += (_, __) => LauncherEx.Launch(url); return(new Span { Inlines = { new Run { Text = " " }, link, new Run { Text = " " }, } }); case "strong": case "b": var bold = new Bold(); foreach (var child in node.ChildNodes) { bold.Inlines.Add(ToInline(child)); } return(bold); case "em": case "i": var italic = new Italic(); foreach (var child in node.ChildNodes) { italic.Inlines.Add(ToInline(child)); } return(italic); case "ul": var unorderedList = new Span(); foreach (var child in node.ChildNodes) { var listElem = new Span(); listElem.Inlines.Add(new Run { Text = "● " }); listElem.Inlines.Add(ToInline(child)); unorderedList.Inlines.Add(listElem); unorderedList.Inlines.Add(new LineBreak()); } return(unorderedList); case "ol": var orderedList = new Span(); for (int n = 0; n < node.ChildNodes.Count; n++) { var listElem = new Span(); listElem.Inlines.Add(new Run { Text = n.ToString() + " " }); listElem.Inlines.Add(ToInline(node.ChildNodes[n])); orderedList.Inlines.Add(listElem); orderedList.Inlines.Add(new LineBreak()); } return(orderedList); case "h1": return(new Run { Text = node.InnerText + Environment.NewLine, FontWeight = FontWeights.Bold, FontSize = 32 }); case "h2": return(new Run { Text = node.InnerText + Environment.NewLine, FontWeight = FontWeights.SemiBold, FontSize = 24 }); case "h3": return(new Run { Text = node.InnerText + Environment.NewLine, FontWeight = FontWeights.SemiBold, FontSize = 19 }); case "h4": return(new Run { Text = node.InnerText + Environment.NewLine, FontWeight = FontWeights.Medium, FontSize = 17 }); case "h5": return(new Run { Text = node.InnerText + Environment.NewLine, FontWeight = FontWeights.Medium, FontSize = 16 }); case "div": case "p": case "blockquote": var container = new Span(); foreach (var child in node.ChildNodes) { container.Inlines.Add(ToInline(child)); } container.Inlines.Add(new LineBreak()); container.Inlines.Add(new LineBreak()); return(container); } return(new Run { Text = node.PreviousSibling == null?node.InnerText.TrimStart() : node.InnerText }); }
/// <summary> /// Navigates to the specified URL. /// </summary> public void NavigateTo(string url) { LauncherEx.Launch(url); }