From e1b6a2d279274819bdb06ad1499a51e4b210f44f Mon Sep 17 00:00:00 2001 From: stubbfel Date: Wed, 18 Sep 2013 16:21:46 +0200 Subject: [PATCH 1/3] add qr and nfc scan to placeNewspage --- .../CampusAppWP8/Model/GeoDb/SpsModel.cs | 6 + .../CampusAppWP8/Pages/Dev/QRScanner.xaml.cs | 18 ++- .../Pages/PlaceNews/PlaceNews.xaml.cs | 139 +++++++++++++++--- .../Resources/Constants.Designer.cs | 9 ++ .../CampusAppWP8/Resources/Constants.resx | 3 + 5 files changed, 150 insertions(+), 25 deletions(-) diff --git a/CampusAppWP8/CampusAppWP8/Model/GeoDb/SpsModel.cs b/CampusAppWP8/CampusAppWP8/Model/GeoDb/SpsModel.cs index b51fb54c..4982eeb3 100644 --- a/CampusAppWP8/CampusAppWP8/Model/GeoDb/SpsModel.cs +++ b/CampusAppWP8/CampusAppWP8/Model/GeoDb/SpsModel.cs @@ -169,6 +169,12 @@ namespace CampusAppWP8.Model.GeoDb public List FilterByPid(List pidList) { List fitlerList = new List(); + + if (pidList == null || pidList.Count < 1) + { + return fitlerList; + } + foreach (PlaceModel place in this.Places) { if (pidList.Contains(place.PlaceId)) diff --git a/CampusAppWP8/CampusAppWP8/Pages/Dev/QRScanner.xaml.cs b/CampusAppWP8/CampusAppWP8/Pages/Dev/QRScanner.xaml.cs index a502d9fc..76f8bd73 100644 --- a/CampusAppWP8/CampusAppWP8/Pages/Dev/QRScanner.xaml.cs +++ b/CampusAppWP8/CampusAppWP8/Pages/Dev/QRScanner.xaml.cs @@ -48,6 +48,8 @@ namespace CampusAppWP8.Pages.Dev /// true if this object is in autofocus. private bool isInAutofocus = false; + private string ResultAppStoreKey; + #endregion #region Constructor @@ -73,6 +75,10 @@ namespace CampusAppWP8.Pages.Dev { if (PhotoCamera.IsCameraTypeSupported(CameraType.Primary) == true) { + if (NavigationContext.QueryString.ContainsKey(Constants.ParamQRResultKey)) + { + this.ResultAppStoreKey = NavigationContext.QueryString[Constants.ParamQRResultKey]; + } this.cam = new PhotoCamera(CameraType.Primary); this.cam.Initialized += new EventHandler(this.Cam_Initialized); this.cam.AutoFocusCompleted += new EventHandler(this.Cam_AutoFocusCompl); @@ -85,7 +91,7 @@ namespace CampusAppWP8.Pages.Dev { this.Dispatcher.BeginInvoke(delegate { - this.scannText.Text = AppResources.PrimCamNotSupported; + MessageBox.Show(AppResources.PrimCamNotSupported); }); } } @@ -211,7 +217,15 @@ namespace CampusAppWP8.Pages.Dev { Dispatcher.BeginInvoke(delegate { - this.scannText.Text = result.Text; + if (this.ResultAppStoreKey != null) + { + App.SaveToIsolatedStorage(this.ResultAppStoreKey, result.Text); + NavigationService.GoBack(); + } + else + { + MessageBox.Show(result.Text); + } }); } } diff --git a/CampusAppWP8/CampusAppWP8/Pages/PlaceNews/PlaceNews.xaml.cs b/CampusAppWP8/CampusAppWP8/Pages/PlaceNews/PlaceNews.xaml.cs index f0e1e317..aa1574a9 100644 --- a/CampusAppWP8/CampusAppWP8/Pages/PlaceNews/PlaceNews.xaml.cs +++ b/CampusAppWP8/CampusAppWP8/Pages/PlaceNews/PlaceNews.xaml.cs @@ -22,6 +22,9 @@ namespace CampusAppWP8.Pages.PlaceNews using CampusAppWP8.Utility; using CampusAppWP8.Utility.Lui.MessageBoxes; using Microsoft.Phone.Controls; + using Windows.Networking.Proximity; + using CampusAppWP8.Utility.NDEF; + using System.Runtime.InteropServices.WindowsRuntime; /// Place news. /// Stubbfel, 09.09.2013. @@ -49,6 +52,11 @@ namespace CampusAppWP8.Pages.PlaceNews /// List of search pids. private List searchPidList; + private bool qrScan = false; + + /// The device. + private readonly ProximityDevice device = ProximityDevice.GetDefault(); + #endregion #region Constructor @@ -74,11 +82,27 @@ namespace CampusAppWP8.Pages.PlaceNews { base.OnNavigatedTo(e); - if (NavigationMode.Back == e.NavigationMode && this.places == null) + if (NavigationMode.Back == e.NavigationMode) { - this.places = new PlacesFile(); - this.places.Model = App.LoadFromIsolatedStorage(Constants.IsolatedStorage_AllPlaces); - this.SetupResultBox(); + if (this.places == null) + { + this.places = new PlacesFile(); + this.places.Model = App.LoadFromIsolatedStorage(Constants.IsolatedStorage_AllPlaces); + } + + if (qrScan) + { + qrScan = false; + string qrResult = App.LoadFromIsolatedStorage("PlaceNewsQCCode"); + App.SaveToIsolatedStorage("PlaceNewsQCCode", null); + this.searchPidList = new List() { qrResult.Split('\n')[0].Trim() }; + this.SendGetPisPssForPlacenews(this.searchPidList); + } + else + { + this.SetupResultBox(); + } + } else { @@ -120,22 +144,24 @@ namespace CampusAppWP8.Pages.PlaceNews this.places.OnFailedLoad += new PlacesFile.OnFailed(this.PlacesFileIsFail); this.places.LoadData(); } - + // init sps Api - if (this.spsApi == null || this.forceRequest) + if (this.spsApi == null) { this.spsApi = new SpsApi(); this.spsApi.OnLoaded += new SpsApi.OnIO(this.SpsApiIsReady); this.spsApi.OnFailedLoad += new SpsApi.OnFailed(this.ApiIsFail); this.spsApi.SetupCurrentPlaceRequest(Constants.SpsDomain_Buildings); - if (this.forceRequest) - { - this.spsApi.LoadData(); - } + + } + + if (this.forceRequest) + { + this.spsApi.LoadData(); } // init pis API - if (this.pisApi == null || this.forceRequest) + if (this.pisApi == null) { this.pisApi = new PisApi(); this.pisApi.OnLoaded += new PisApi.OnIO(this.PisApiIsReady); @@ -143,7 +169,7 @@ namespace CampusAppWP8.Pages.PlaceNews } // init pss Api - if (this.pssApi == null || this.forceRequest) + if (this.pssApi == null) { this.pssApi = new PssApi(); this.pssApi.OnLoaded += new PssApi.OnIO(this.PssApiIsReady); @@ -174,8 +200,8 @@ namespace CampusAppWP8.Pages.PlaceNews this.spsApi.OnLoaded += new SpsApi.OnIO(this.SpsApiIsReady); this.spsApi.OnFailedLoad += new SpsApi.OnFailed(this.ApiIsFail); this.spsApi.SetupCurrentPlaceRequest(Constants.SpsDomain_Buildings); - } - + } + this.spsApi.LoadData(); this.waitForApi++; } @@ -232,29 +258,59 @@ namespace CampusAppWP8.Pages.PlaceNews private void SpsApiIsReady() { this.waitForApi--; - this.places.Model.AddPlaces(this.spsApi.Model.Places.ToList()); - - this.searchPidList = this.spsApi.Model.CreatePidList(); + if (spsApi.Model.Places.Count > 0) + { + this.places.Model.AddPlaces(this.spsApi.Model.Places.ToList()); + this.searchPidList = this.spsApi.Model.CreatePidList(); + this.SendGetPisPssForPlacenews(this.searchPidList); + } + this.CheckedSetupResultBox(); + } + + /// + /// send get request to pis andd pss for PlaceNews service + /// + /// list of place id + private void SendGetPisPssForPlacenews(List pidList) { List infoNames = new List() { Constants.PisInformationName_Name }; List serviceNames = new List() { Constants.PssServiceName_PlaceNews }; // load from pis api - if (this.forceRequest || !this.places.Model.ContainsInformationNames(this.searchPidList, infoNames)) + this.SendGetPlaceInformation(this.searchPidList, infoNames, this.forceRequest); + + // load from pis api + this.SendGetPlaceService(this.searchPidList, serviceNames); + } + /// + /// Method send get for PlaceInformation of certain places + /// + /// list of place id + /// list of informations name + /// if its true then force api load + private void SendGetPlaceInformation(List pidList, List infoNames, bool force = false) + { + if (force || !this.places.Model.ContainsInformationNames(pidList, infoNames)) { this.pisApi.SetupInformationRequest(this.searchPidList, infoNames); this.pisApi.LoadData(); this.waitForApi++; } - - // load from pis api - if (this.forceRequest || !this.places.Model.ContainsServiceNames(this.searchPidList, serviceNames)) + } + + /// + /// Method send get for PlaceSetvice of certain places + /// + /// list of place id + /// list of service name + /// if its true then force api load + private void SendGetPlaceService(List pidList, List serviceNames, bool force = false) + { + if (this.forceRequest || !this.places.Model.ContainsServiceNames(pidList, serviceNames)) { this.pssApi.SetupServiceRequest(this.searchPidList, serviceNames); this.pssApi.LoadData(); this.waitForApi++; } - - this.CheckedSetupResultBox(); } /// Sets up the result box. @@ -294,6 +350,11 @@ namespace CampusAppWP8.Pages.PlaceNews /// Event information. private void ApplicationBarMenuItem_Click(object sender, EventArgs e) { + this.qrScan = true; + string urlString = "/Pages/Dev/QRScanner.xaml"; + urlString += "?" + Constants.ParamQRResultKey + "=" + "PlaceNewsQCCode"; + Uri url = new Uri(urlString as string, UriKind.Relative); + this.NavigationService.Navigate(url); } /// Event handler. Called by ApplicationBarMenuItem_Click for 1 events. @@ -302,6 +363,7 @@ namespace CampusAppWP8.Pages.PlaceNews /// Event information. private void ApplicationBarMenuItem_Click_1(object sender, EventArgs e) { + this.device.SubscribeForMessage("NDEF", this.NDEFHandler); } /// Checked setup result box. @@ -346,6 +408,37 @@ namespace CampusAppWP8.Pages.PlaceNews txt.Text = place.GetInformationsValue(Constants.PisInformationName_Name); } + + /// Handler, called when the ndef. + /// Stubbfel, 22.08.2013. + /// The sender. + /// The message. + private void NDEFHandler(ProximityDevice sender, ProximityMessage message) + { + this.device.StopSubscribingForMessage(message.SubscriptionId); + var ndefMessage = message.Data; + byte[] data = ndefMessage.ToArray(); + + NDEFMessage ndef = new NDEFMessage(data); + string nfcContent = ndef.GetContent(); + nfcContent = nfcContent.Trim('{'); + nfcContent = nfcContent.Trim('}'); + string[] items = nfcContent.Split(','); + string pid = "0"; + foreach (string item in items) + { + if (item.StartsWith("\"pid\":\"")) + { + pid = item; + pid = pid.TrimStart("\"pid\":\"".ToCharArray()); + pid = pid.TrimEnd('\"'); + break; + } + } + this.searchPidList = new List() { pid }; + this.SendGetPisPssForPlacenews(this.searchPidList); + // this.Dispatcher.BeginInvoke(new Action(() => MessageBox.Show(ndef.GetContent()))); + } #endregion } } \ No newline at end of file diff --git a/CampusAppWP8/CampusAppWP8/Resources/Constants.Designer.cs b/CampusAppWP8/CampusAppWP8/Resources/Constants.Designer.cs index 8bb7086c..0f3c3b91 100644 --- a/CampusAppWP8/CampusAppWP8/Resources/Constants.Designer.cs +++ b/CampusAppWP8/CampusAppWP8/Resources/Constants.Designer.cs @@ -654,6 +654,15 @@ namespace CampusAppWP8.Resources { } } + /// + /// Sucht eine lokalisierte Zeichenfolge, die QRResultKey ähnelt. + /// + public static string ParamQRResultKey { + get { + return ResourceManager.GetString("ParamQRResultKey", resourceCulture); + } + } + /// /// Sucht eine lokalisierte Zeichenfolge, die Url ähnelt. /// diff --git a/CampusAppWP8/CampusAppWP8/Resources/Constants.resx b/CampusAppWP8/CampusAppWP8/Resources/Constants.resx index 2e17a5d2..675e0e6b 100644 --- a/CampusAppWP8/CampusAppWP8/Resources/Constants.resx +++ b/CampusAppWP8/CampusAppWP8/Resources/Constants.resx @@ -513,4 +513,7 @@ /Pages/Events/EventPage.xaml + + QRResultKey + \ No newline at end of file From 04ff3ad80bd022b2435653c2ad00981f9904c51a Mon Sep 17 00:00:00 2001 From: stubbfel Date: Thu, 19 Sep 2013 10:55:07 +0200 Subject: [PATCH 2/3] add filter pid medhod to stringmanager --- .../Pages/PlaceNews/PlaceNews.xaml.cs | 33 +++++---- .../Resources/Constants.Designer.cs | 9 +++ .../CampusAppWP8/Resources/Constants.resx | 3 + .../CampusAppWPortalLib8/Settings.StyleCop | 2 + .../Utility/DefaultStringManager.cs | 71 ++++++++++++++++++- 5 files changed, 100 insertions(+), 18 deletions(-) diff --git a/CampusAppWP8/CampusAppWP8/Pages/PlaceNews/PlaceNews.xaml.cs b/CampusAppWP8/CampusAppWP8/Pages/PlaceNews/PlaceNews.xaml.cs index aa1574a9..ab6f784e 100644 --- a/CampusAppWP8/CampusAppWP8/Pages/PlaceNews/PlaceNews.xaml.cs +++ b/CampusAppWP8/CampusAppWP8/Pages/PlaceNews/PlaceNews.xaml.cs @@ -95,8 +95,13 @@ namespace CampusAppWP8.Pages.PlaceNews qrScan = false; string qrResult = App.LoadFromIsolatedStorage("PlaceNewsQCCode"); App.SaveToIsolatedStorage("PlaceNewsQCCode", null); - this.searchPidList = new List() { qrResult.Split('\n')[0].Trim() }; - this.SendGetPisPssForPlacenews(this.searchPidList); + + string searchPid = Wp8StringManager.FilterPlaceIdinQRResultString(qrResult); + if (searchPid != null) + { + this.searchPidList = new List() { searchPid }; + this.SendGetPisPssForPlacenews(this.searchPidList); + } } else { @@ -280,6 +285,9 @@ namespace CampusAppWP8.Pages.PlaceNews // load from pis api this.SendGetPlaceService(this.searchPidList, serviceNames); + + this.CheckedSetupResultBox(); + } /// /// Method send get for PlaceInformation of certain places @@ -351,7 +359,7 @@ namespace CampusAppWP8.Pages.PlaceNews private void ApplicationBarMenuItem_Click(object sender, EventArgs e) { this.qrScan = true; - string urlString = "/Pages/Dev/QRScanner.xaml"; + string urlString = Constants.PathQR_QRPage; urlString += "?" + Constants.ParamQRResultKey + "=" + "PlaceNewsQCCode"; Uri url = new Uri(urlString as string, UriKind.Relative); this.NavigationService.Navigate(url); @@ -363,6 +371,7 @@ namespace CampusAppWP8.Pages.PlaceNews /// Event information. private void ApplicationBarMenuItem_Click_1(object sender, EventArgs e) { + this.ProgressBar.Visibility = Visibility.Visible; this.device.SubscribeForMessage("NDEF", this.NDEFHandler); } @@ -421,22 +430,12 @@ namespace CampusAppWP8.Pages.PlaceNews NDEFMessage ndef = new NDEFMessage(data); string nfcContent = ndef.GetContent(); - nfcContent = nfcContent.Trim('{'); - nfcContent = nfcContent.Trim('}'); - string[] items = nfcContent.Split(','); - string pid = "0"; - foreach (string item in items) + string pid = Wp8StringManager.FilterPlaceIdinNFCResultString(nfcContent.Trim()); + if (pid != null) { - if (item.StartsWith("\"pid\":\"")) - { - pid = item; - pid = pid.TrimStart("\"pid\":\"".ToCharArray()); - pid = pid.TrimEnd('\"'); - break; - } + this.searchPidList = new List() { pid }; + this.SendGetPisPssForPlacenews(this.searchPidList); } - this.searchPidList = new List() { pid }; - this.SendGetPisPssForPlacenews(this.searchPidList); // this.Dispatcher.BeginInvoke(new Action(() => MessageBox.Show(ndef.GetContent()))); } #endregion diff --git a/CampusAppWP8/CampusAppWP8/Resources/Constants.Designer.cs b/CampusAppWP8/CampusAppWP8/Resources/Constants.Designer.cs index 0f3c3b91..50e0e97e 100644 --- a/CampusAppWP8/CampusAppWP8/Resources/Constants.Designer.cs +++ b/CampusAppWP8/CampusAppWP8/Resources/Constants.Designer.cs @@ -861,6 +861,15 @@ namespace CampusAppWP8.Resources { } } + /// + /// Sucht eine lokalisierte Zeichenfolge, die /Pages/Dev/QRScanner.xaml ähnelt. + /// + public static string PathQR_QRPage { + get { + return ResourceManager.GetString("PathQR_QRPage", resourceCulture); + } + } + /// /// Sucht eine lokalisierte Zeichenfolge, die /Pages/Setting/AppSettingPage.xaml ähnelt. /// diff --git a/CampusAppWP8/CampusAppWP8/Resources/Constants.resx b/CampusAppWP8/CampusAppWP8/Resources/Constants.resx index 675e0e6b..522f7cf8 100644 --- a/CampusAppWP8/CampusAppWP8/Resources/Constants.resx +++ b/CampusAppWP8/CampusAppWP8/Resources/Constants.resx @@ -516,4 +516,7 @@ QRResultKey + + /Pages/Dev/QRScanner.xaml + \ No newline at end of file diff --git a/CampusAppWP8/CampusAppWPortalLib8/Settings.StyleCop b/CampusAppWP8/CampusAppWPortalLib8/Settings.StyleCop index 7aff7afb..54487d17 100644 --- a/CampusAppWP8/CampusAppWPortalLib8/Settings.StyleCop +++ b/CampusAppWP8/CampusAppWPortalLib8/Settings.StyleCop @@ -1,7 +1,9 @@ + nfc param + qr str stubbfel telefon diff --git a/CampusAppWP8/CampusAppWPortalLib8/Utility/DefaultStringManager.cs b/CampusAppWP8/CampusAppWPortalLib8/Utility/DefaultStringManager.cs index faf0b1b3..a572c10f 100644 --- a/CampusAppWP8/CampusAppWPortalLib8/Utility/DefaultStringManager.cs +++ b/CampusAppWP8/CampusAppWPortalLib8/Utility/DefaultStringManager.cs @@ -6,7 +6,7 @@ // 06.06.2013 //---------------------------------------------------------------------- namespace CampusAppWPortalLib8.Utility -{ +{ using System; using System.Text.RegularExpressions; using CampusAppWPortalLib8.Resources; @@ -118,6 +118,75 @@ namespace CampusAppWPortalLib8.Utility return shortStr; } + + /// + /// Method gets the placeId of the result string for an qrCode string + /// + /// input qrCode string + /// the id if it was found it in the string otherwise null + public static string FilterPlaceIdinQRResultString(string qrCodeResult) + { + string[] lines = qrCodeResult.Split('\n'); + + string tmpLineTrim; + foreach (string line in lines) + { + tmpLineTrim = line.Trim(); + if (DefaultStringManager.IsDigitsOnly(tmpLineTrim)) + { + return tmpLineTrim; + } + } + + return null; + } + + /// + /// Method check if the string contains only digit + /// + /// input string + /// true if the string contains only digit, otherwise false + public static bool IsDigitsOnly(string str) + { + foreach (char c in str) + { + if (c < '0' || c > '9') + { + return false; + } + } + + return true; + } + + /// + /// Method gets the placeId of the result string for an nfc string + /// + /// input nfc string + /// the id if it was found it in the string otherwise null + public static string FilterPlaceIdinNFCResultString(string nfcResult) + { + string nfcResultTrim = nfcResult.Trim('{'); + nfcResultTrim = nfcResultTrim.Trim('}'); + string[] items = nfcResultTrim.Split(','); + string[] tmpStringPair; + + foreach (string item in items) + { + tmpStringPair = item.Trim().Split(':'); + + if (tmpStringPair.Length == 2) + { + string pairKey = tmpStringPair[0].Trim('\"').Trim(); + if (pairKey.Equals("pid")) + { + return tmpStringPair[1].Trim('\"').Trim(); + } + } + } + + return null; + } #endregion } } From 771e1fc7b5edcddfca23e9425fb5ffccc4153e1f Mon Sep 17 00:00:00 2001 From: stubbfel Date: Thu, 19 Sep 2013 12:34:53 +0200 Subject: [PATCH 3/3] add nfc and qr to map --- .../Pages/Campusmap/CampusMapPage.xaml | 6 +- .../Pages/Campusmap/CampusMapPage.xaml.cs | 162 +++++++++++++++++- .../Pages/PlaceNews/PlaceNews.xaml.cs | 1 + .../Resources/AppResources.Designer.cs | 36 ++++ .../CampusAppWP8/Resources/AppResources.resx | 12 ++ .../Resources/Constants.Designer.cs | 18 ++ .../CampusAppWP8/Resources/Constants.resx | 6 + CampusAppWP8/CampusAppWP8/Settings.StyleCop | 1 + .../Utility/DefaultStringManager.cs | 6 +- 9 files changed, 242 insertions(+), 6 deletions(-) diff --git a/CampusAppWP8/CampusAppWP8/Pages/Campusmap/CampusMapPage.xaml b/CampusAppWP8/CampusAppWP8/Pages/Campusmap/CampusMapPage.xaml index 2033c099..d9c8457e 100644 --- a/CampusAppWP8/CampusAppWP8/Pages/Campusmap/CampusMapPage.xaml +++ b/CampusAppWP8/CampusAppWP8/Pages/Campusmap/CampusMapPage.xaml @@ -69,8 +69,12 @@ - + + + + + \ No newline at end of file diff --git a/CampusAppWP8/CampusAppWP8/Pages/Campusmap/CampusMapPage.xaml.cs b/CampusAppWP8/CampusAppWP8/Pages/Campusmap/CampusMapPage.xaml.cs index 2b0dc3e4..74fadd03 100644 --- a/CampusAppWP8/CampusAppWP8/Pages/Campusmap/CampusMapPage.xaml.cs +++ b/CampusAppWP8/CampusAppWP8/Pages/Campusmap/CampusMapPage.xaml.cs @@ -11,15 +11,19 @@ namespace CampusAppWP8.Pages.Campusmap using System.Collections.Generic; using System.Device.Location; using System.Globalization; + using System.Runtime.InteropServices.WindowsRuntime; using System.Threading; using System.Windows; - using System.Windows.Navigation; + using System.Windows.Navigation; using CampusAppWP8.Model.Campusmap; using CampusAppWP8.Model.GeoDb; using CampusAppWP8.Resources; using CampusAppWP8.Utility; using CampusAppWP8.Utility.Lui.MessageBoxes; + using CampusAppWP8.Utility.NDEF; using Microsoft.Phone.Controls; + using Microsoft.Phone.Shell; + using Windows.Networking.Proximity; /// Class for the campusMap page. /// Stubbfel, 19.08.2013. @@ -27,6 +31,9 @@ namespace CampusAppWP8.Pages.Campusmap { #region Member + /// The device. + private readonly ProximityDevice device = ProximityDevice.GetDefault(); + /// Variable for the map model. private MapModel map; @@ -35,6 +42,11 @@ namespace CampusAppWP8.Pages.Campusmap /// private List informationsNames; + /// + /// Flag which indicates if an qrCode scan is running + /// + private bool qrcodeScan = false; + #endregion #region Constructor @@ -47,6 +59,19 @@ namespace CampusAppWP8.Pages.Campusmap this.map = new CBMainMapModel(); this.MapCanvas.DataContext = this.map; this.map.ShowMapInfos += new CBMainMapModel.MapInfos(this.ShowMapInfo); + + ApplicationBarMenuItem menuItem1 = ApplicationBar.MenuItems[0] as ApplicationBarMenuItem; + ApplicationBarMenuItem menuItem2 = ApplicationBar.MenuItems[1] as ApplicationBarMenuItem; + + if (menuItem1 != null) + { + menuItem1.Text = AppResources.CampusMapApp_ScanQR; + } + + if (menuItem2 != null) + { + menuItem2.Text = AppResources.CampusMapApp_ScanNfc; + } } #endregion @@ -61,7 +86,12 @@ namespace CampusAppWP8.Pages.Campusmap protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); - if (this.map.Spatial != null && e.NavigationMode == NavigationMode.New) + if (this.map.Spatial == null) + { + return; + } + + if (e.NavigationMode == NavigationMode.New) { MapCanvas.Children.Clear(); @@ -80,12 +110,63 @@ namespace CampusAppWP8.Pages.Campusmap this.ShowCurrentPositionDispatcher(scroll); } + else if (this.qrcodeScan && e.NavigationMode == NavigationMode.Back) + { + this.qrcodeScan = false; + string qrcodeResult = App.LoadFromIsolatedStorage(Constants.CampusMapApp_QRCodeSearchResultStorageKey); + App.SaveToIsolatedStorage(Constants.CampusMapApp_QRCodeSearchResultStorageKey, null); + + string searchPid = Wp8StringManager.FilterPlaceIdinQRResultString(qrcodeResult); + if (searchPid != null) + { + this.AddPinsByPids(new List() { searchPid }, MapPinModel.PinType.SearchPlace); + } + } } #endregion #region private + /// + /// Method adds pin to the map by given list of placeId + /// + /// list of placeId + /// type of pin + /// (optional) if its true, clear canvas before adding + private void AddPinsByPids(List pidList, MapPinModel.PinType pinType, bool clearCanvas = true) + { + // clear canvas + if (clearCanvas) + { + MapCanvas.Children.Clear(); + } + + // null and empty list assert + if (pidList == null || pidList.Count < 1) + { + return; + } + + List placeList = new List(); + PlaceModel tmpPlace; + + foreach (string pid in pidList) + { + tmpPlace = this.map.Spatial.GetPlaceById(pid); + if (tmpPlace != null) + { + placeList.Add(tmpPlace); + } + } + + // add pins to map + if (placeList.Count > 0) + { + this.AddPins(placeList, pinType); + } + } + /// Button click method. /// Stubbfel, 19.08.2013. /// caller object. @@ -95,6 +176,83 @@ namespace CampusAppWP8.Pages.Campusmap // this.AddPin(double.Parse(XPoint.Text), double.Parse(YPoint.Text)); } + /// + /// Method start a NFCScan + /// + /// sender of event + /// the event args + private void SearchPlaceByNFC_Click(object sender, EventArgs e) + { + MessageBoxes.ShowMainModelInfoMessageBox(AppResources.ScarNfc_Search); + this.ProgressBar.Visibility = Visibility.Visible; + this.device.SubscribeForMessage(Constants.NCFMessageType_NDEF, this.NDEFHandler); + } + + /// + /// Method start a QRCodeScan + /// + /// sender of event + /// the event args + private void SearchPlaceByQR_Click(object sender, EventArgs e) + { + this.qrcodeScan = true; + string urlString = Constants.PathQR_QRPage; + urlString += "?" + Constants.ParamQRResultKey + "=" + Constants.CampusMapApp_QRCodeSearchResultStorageKey; + Uri url = new Uri(urlString as string, UriKind.Relative); + this.NavigationService.Navigate(url); + } + + /// + /// Method handle the result of a NFCScan + /// + /// the sender device + /// the message of the device + private void NDEFHandler(ProximityDevice sender, ProximityMessage message) + { + // create ndefMessage + this.device.StopSubscribingForMessage(message.SubscriptionId); + var ndefMessage = message.Data; + byte[] data = ndefMessage.ToArray(); + NDEFMessage ndef = new NDEFMessage(data); + + // search for placeId + string nfcContent = ndef.GetContent(); + string searchPid = Wp8StringManager.FilterPlaceIdinNFCResultString(nfcContent.Trim()); + if (searchPid != null) + { + // add pins to map + if (this.Dispatcher != null) + { + this.Dispatcher.BeginInvoke(new Action(() => this.AddPinsByPids(new List() { searchPid }, MapPinModel.PinType.SearchPlace))); + } + else + { + this.AddPinsByPids(new List() { searchPid }, MapPinModel.PinType.SearchPlace); + } + } + else + { + // Errorcase + if (this.Dispatcher != null) + { + this.Dispatcher.BeginInvoke(new Action(() => MessageBoxes.ShowMainModelErrorMessageBox(AppResources.ScarNfc_Fail))); + } + else + { + MessageBoxes.ShowMainModelErrorMessageBox(AppResources.ScarNfc_Fail); + } + } + + if (this.Dispatcher != null) + { + this.Dispatcher.BeginInvoke(new Action(() => this.ProgressBar.Visibility = Visibility.Collapsed)); + } + else + { + this.ProgressBar.Visibility = Visibility.Collapsed; + } + } + /// Button click method. /// Stubbfel, 19.08.2013. /// caller object. diff --git a/CampusAppWP8/CampusAppWP8/Pages/PlaceNews/PlaceNews.xaml.cs b/CampusAppWP8/CampusAppWP8/Pages/PlaceNews/PlaceNews.xaml.cs index ab6f784e..6ad59c34 100644 --- a/CampusAppWP8/CampusAppWP8/Pages/PlaceNews/PlaceNews.xaml.cs +++ b/CampusAppWP8/CampusAppWP8/Pages/PlaceNews/PlaceNews.xaml.cs @@ -25,6 +25,7 @@ namespace CampusAppWP8.Pages.PlaceNews using Windows.Networking.Proximity; using CampusAppWP8.Utility.NDEF; using System.Runtime.InteropServices.WindowsRuntime; + using Microsoft.Phone.Shell; /// Place news. /// Stubbfel, 09.09.2013. diff --git a/CampusAppWP8/CampusAppWP8/Resources/AppResources.Designer.cs b/CampusAppWP8/CampusAppWP8/Resources/AppResources.Designer.cs index b4a616bb..f3c27a3a 100644 --- a/CampusAppWP8/CampusAppWP8/Resources/AppResources.Designer.cs +++ b/CampusAppWP8/CampusAppWP8/Resources/AppResources.Designer.cs @@ -141,6 +141,24 @@ namespace CampusAppWP8.Resources { } } + /// + /// Sucht eine lokalisierte Zeichenfolge, die Info via NFC ähnelt. + /// + public static string CampusMapApp_ScanNfc { + get { + return ResourceManager.GetString("CampusMapApp_ScanNfc", resourceCulture); + } + } + + /// + /// Sucht eine lokalisierte Zeichenfolge, die Info via QR-Code ähnelt. + /// + public static string CampusMapApp_ScanQR { + get { + return ResourceManager.GetString("CampusMapApp_ScanQR", resourceCulture); + } + } + /// /// Sucht eine lokalisierte Zeichenfolge, die Campusplan ähnelt. /// @@ -807,6 +825,24 @@ namespace CampusAppWP8.Resources { } } + /// + /// Sucht eine lokalisierte Zeichenfolge, die Kein gültigen NFC-Tag gefunden ähnelt. + /// + public static string ScarNfc_Fail { + get { + return ResourceManager.GetString("ScarNfc_Fail", resourceCulture); + } + } + + /// + /// Sucht eine lokalisierte Zeichenfolge, die Bitte halten Sie das Handy vor dem NFC-Tag ähnelt. + /// + public static string ScarNfc_Search { + get { + return ResourceManager.GetString("ScarNfc_Search", resourceCulture); + } + } + /// /// Sucht eine lokalisierte Zeichenfolge, die Appeinstellungen ähnelt. /// diff --git a/CampusAppWP8/CampusAppWP8/Resources/AppResources.resx b/CampusAppWP8/CampusAppWP8/Resources/AppResources.resx index 08e76485..8eea55e9 100644 --- a/CampusAppWP8/CampusAppWP8/Resources/AppResources.resx +++ b/CampusAppWP8/CampusAppWP8/Resources/AppResources.resx @@ -440,4 +440,16 @@ Auf Startseite + + Info via NFC + + + Info via QR-Code + + + Kein gültigen NFC-Tag gefunden + + + Bitte halten Sie das Handy vor dem NFC-Tag + \ No newline at end of file diff --git a/CampusAppWP8/CampusAppWP8/Resources/Constants.Designer.cs b/CampusAppWP8/CampusAppWP8/Resources/Constants.Designer.cs index 50e0e97e..06e95858 100644 --- a/CampusAppWP8/CampusAppWP8/Resources/Constants.Designer.cs +++ b/CampusAppWP8/CampusAppWP8/Resources/Constants.Designer.cs @@ -177,6 +177,15 @@ namespace CampusAppWP8.Resources { } } + /// + /// Sucht eine lokalisierte Zeichenfolge, die CampusMapAppQRCodeSearchResultStorageKey ähnelt. + /// + public static string CampusMapApp_QRCodeSearchResultStorageKey { + get { + return ResourceManager.GetString("CampusMapApp_QRCodeSearchResultStorageKey", resourceCulture); + } + } + /// /// Sucht eine lokalisierte Zeichenfolge, die +49 ähnelt. /// @@ -555,6 +564,15 @@ namespace CampusAppWP8.Resources { } } + /// + /// Sucht eine lokalisierte Zeichenfolge, die NDEF ähnelt. + /// + public static string NCFMessageType_NDEF { + get { + return ResourceManager.GetString("NCFMessageType_NDEF", resourceCulture); + } + } + /// /// Sucht eine lokalisierte Zeichenfolge, die Studiengang ähnelt. /// diff --git a/CampusAppWP8/CampusAppWP8/Resources/Constants.resx b/CampusAppWP8/CampusAppWP8/Resources/Constants.resx index 522f7cf8..97cd1179 100644 --- a/CampusAppWP8/CampusAppWP8/Resources/Constants.resx +++ b/CampusAppWP8/CampusAppWP8/Resources/Constants.resx @@ -519,4 +519,10 @@ /Pages/Dev/QRScanner.xaml + + CampusMapAppQRCodeSearchResultStorageKey + + + NDEF + \ No newline at end of file diff --git a/CampusAppWP8/CampusAppWP8/Settings.StyleCop b/CampusAppWP8/CampusAppWP8/Settings.StyleCop index a049e944..d16b0ee3 100644 --- a/CampusAppWP8/CampusAppWP8/Settings.StyleCop +++ b/CampusAppWP8/CampusAppWP8/Settings.StyleCop @@ -17,6 +17,7 @@ pis prev pss + qr Senftenberg sps Stubbfel diff --git a/CampusAppWP8/CampusAppWPortalLib8/Utility/DefaultStringManager.cs b/CampusAppWP8/CampusAppWPortalLib8/Utility/DefaultStringManager.cs index a572c10f..264fc2fa 100644 --- a/CampusAppWP8/CampusAppWPortalLib8/Utility/DefaultStringManager.cs +++ b/CampusAppWP8/CampusAppWPortalLib8/Utility/DefaultStringManager.cs @@ -122,11 +122,11 @@ namespace CampusAppWPortalLib8.Utility /// /// Method gets the placeId of the result string for an qrCode string /// - /// input qrCode string + /// input qrCode string /// the id if it was found it in the string otherwise null - public static string FilterPlaceIdinQRResultString(string qrCodeResult) + public static string FilterPlaceIdinQRResultString(string qrcodeResult) { - string[] lines = qrCodeResult.Split('\n'); + string[] lines = qrcodeResult.Split('\n'); string tmpLineTrim; foreach (string line in lines)