add nfc and qr to map
This commit is contained in:
@@ -69,8 +69,12 @@
|
||||
</Grid>
|
||||
</Grid>
|
||||
<phone:PhoneApplicationPage.ApplicationBar>
|
||||
<shell:ApplicationBar IsVisible="True" IsMenuEnabled="False" Mode="Minimized" >
|
||||
<shell:ApplicationBar IsVisible="True" IsMenuEnabled="True" Mode="Minimized" >
|
||||
<lui:UpdateButtonAppBar Click="UpdateButtonAppBar_Click"/>
|
||||
<shell:ApplicationBar.MenuItems>
|
||||
<shell:ApplicationBarMenuItem Text="Scan QR-Code" Click="SearchPlaceByQR_Click" />
|
||||
<shell:ApplicationBarMenuItem Text="Scan NFC-Tag" Click="SearchPlaceByNFC_Click"/>
|
||||
</shell:ApplicationBar.MenuItems>
|
||||
</shell:ApplicationBar>
|
||||
</phone:PhoneApplicationPage.ApplicationBar>
|
||||
</phone:PhoneApplicationPage>
|
||||
@@ -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;
|
||||
|
||||
/// <summary>Class for the campusMap page.</summary>
|
||||
/// <remarks>Stubbfel, 19.08.2013.</remarks>
|
||||
@@ -27,6 +31,9 @@ namespace CampusAppWP8.Pages.Campusmap
|
||||
{
|
||||
#region Member
|
||||
|
||||
/// <summary>The device.</summary>
|
||||
private readonly ProximityDevice device = ProximityDevice.GetDefault();
|
||||
|
||||
/// <summary>Variable for the map model.</summary>
|
||||
private MapModel map;
|
||||
|
||||
@@ -35,6 +42,11 @@ namespace CampusAppWP8.Pages.Campusmap
|
||||
/// </summary>
|
||||
private List<string> informationsNames;
|
||||
|
||||
/// <summary>
|
||||
/// Flag which indicates if an qrCode scan is running
|
||||
/// </summary>
|
||||
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<string>(Constants.CampusMapApp_QRCodeSearchResultStorageKey);
|
||||
App.SaveToIsolatedStorage<string>(Constants.CampusMapApp_QRCodeSearchResultStorageKey, null);
|
||||
|
||||
string searchPid = Wp8StringManager.FilterPlaceIdinQRResultString(qrcodeResult);
|
||||
if (searchPid != null)
|
||||
{
|
||||
this.AddPinsByPids(new List<string>() { searchPid }, MapPinModel.PinType.SearchPlace);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region private
|
||||
|
||||
/// <summary>
|
||||
/// Method adds pin to the map by given list of placeId
|
||||
/// </summary>
|
||||
/// <param name="pidList">list of placeId</param>
|
||||
/// <param name="pinType">type of pin</param>
|
||||
/// <param name="clearCanvas">(optional) if its true, clear canvas before adding</param>
|
||||
private void AddPinsByPids(List<string> 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<PlaceModel> placeList = new List<PlaceModel>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Button click method.</summary>
|
||||
/// <remarks>Stubbfel, 19.08.2013.</remarks>
|
||||
/// <param name="sender">caller object.</param>
|
||||
@@ -95,6 +176,83 @@ namespace CampusAppWP8.Pages.Campusmap
|
||||
// this.AddPin(double.Parse(XPoint.Text), double.Parse(YPoint.Text));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method start a NFCScan
|
||||
/// </summary>
|
||||
/// <param name="sender">sender of event</param>
|
||||
/// <param name="e">the event args</param>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method start a QRCodeScan
|
||||
/// </summary>
|
||||
/// <param name="sender">sender of event</param>
|
||||
/// <param name="e">the event args</param>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method handle the result of a NFCScan
|
||||
/// </summary>
|
||||
/// <param name="sender">the sender device</param>
|
||||
/// <param name="message">the message of the device</param>
|
||||
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<string>() { searchPid }, MapPinModel.PinType.SearchPlace)));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.AddPinsByPids(new List<string>() { 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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Button click method.</summary>
|
||||
/// <remarks>Stubbfel, 19.08.2013.</remarks>
|
||||
/// <param name="sender">caller object.</param>
|
||||
|
||||
@@ -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;
|
||||
|
||||
/// <summary>Place news.</summary>
|
||||
/// <remarks>Stubbfel, 09.09.2013.</remarks>
|
||||
|
||||
@@ -141,6 +141,24 @@ namespace CampusAppWP8.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sucht eine lokalisierte Zeichenfolge, die Info via NFC ähnelt.
|
||||
/// </summary>
|
||||
public static string CampusMapApp_ScanNfc {
|
||||
get {
|
||||
return ResourceManager.GetString("CampusMapApp_ScanNfc", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sucht eine lokalisierte Zeichenfolge, die Info via QR-Code ähnelt.
|
||||
/// </summary>
|
||||
public static string CampusMapApp_ScanQR {
|
||||
get {
|
||||
return ResourceManager.GetString("CampusMapApp_ScanQR", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sucht eine lokalisierte Zeichenfolge, die Campusplan ähnelt.
|
||||
/// </summary>
|
||||
@@ -807,6 +825,24 @@ namespace CampusAppWP8.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sucht eine lokalisierte Zeichenfolge, die Kein gültigen NFC-Tag gefunden ähnelt.
|
||||
/// </summary>
|
||||
public static string ScarNfc_Fail {
|
||||
get {
|
||||
return ResourceManager.GetString("ScarNfc_Fail", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sucht eine lokalisierte Zeichenfolge, die Bitte halten Sie das Handy vor dem NFC-Tag ähnelt.
|
||||
/// </summary>
|
||||
public static string ScarNfc_Search {
|
||||
get {
|
||||
return ResourceManager.GetString("ScarNfc_Search", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sucht eine lokalisierte Zeichenfolge, die Appeinstellungen ähnelt.
|
||||
/// </summary>
|
||||
|
||||
@@ -440,4 +440,16 @@
|
||||
<data name="ContextMenu_PinToStart" xml:space="preserve">
|
||||
<value>Auf Startseite</value>
|
||||
</data>
|
||||
<data name="CampusMapApp_ScanNfc" xml:space="preserve">
|
||||
<value>Info via NFC</value>
|
||||
</data>
|
||||
<data name="CampusMapApp_ScanQR" xml:space="preserve">
|
||||
<value>Info via QR-Code</value>
|
||||
</data>
|
||||
<data name="ScarNfc_Fail" xml:space="preserve">
|
||||
<value>Kein gültigen NFC-Tag gefunden</value>
|
||||
</data>
|
||||
<data name="ScarNfc_Search" xml:space="preserve">
|
||||
<value>Bitte halten Sie das Handy vor dem NFC-Tag</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -177,6 +177,15 @@ namespace CampusAppWP8.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sucht eine lokalisierte Zeichenfolge, die CampusMapAppQRCodeSearchResultStorageKey ähnelt.
|
||||
/// </summary>
|
||||
public static string CampusMapApp_QRCodeSearchResultStorageKey {
|
||||
get {
|
||||
return ResourceManager.GetString("CampusMapApp_QRCodeSearchResultStorageKey", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sucht eine lokalisierte Zeichenfolge, die +49 ähnelt.
|
||||
/// </summary>
|
||||
@@ -555,6 +564,15 @@ namespace CampusAppWP8.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sucht eine lokalisierte Zeichenfolge, die NDEF ähnelt.
|
||||
/// </summary>
|
||||
public static string NCFMessageType_NDEF {
|
||||
get {
|
||||
return ResourceManager.GetString("NCFMessageType_NDEF", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sucht eine lokalisierte Zeichenfolge, die Studiengang ähnelt.
|
||||
/// </summary>
|
||||
|
||||
@@ -519,4 +519,10 @@
|
||||
<data name="PathQR_QRPage" xml:space="preserve">
|
||||
<value>/Pages/Dev/QRScanner.xaml</value>
|
||||
</data>
|
||||
<data name="CampusMapApp_QRCodeSearchResultStorageKey" xml:space="preserve">
|
||||
<value>CampusMapAppQRCodeSearchResultStorageKey</value>
|
||||
</data>
|
||||
<data name="NCFMessageType_NDEF" xml:space="preserve">
|
||||
<value>NDEF</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -17,6 +17,7 @@
|
||||
<Value>pis</Value>
|
||||
<Value>prev</Value>
|
||||
<Value>pss</Value>
|
||||
<Value>qr</Value>
|
||||
<Value>Senftenberg</Value>
|
||||
<Value>sps</Value>
|
||||
<Value>Stubbfel</Value>
|
||||
|
||||
@@ -122,11 +122,11 @@ namespace CampusAppWPortalLib8.Utility
|
||||
/// <summary>
|
||||
/// Method gets the placeId of the result string for an qrCode string
|
||||
/// </summary>
|
||||
/// <param name="qrCodeResult">input qrCode string</param>
|
||||
/// <param name="qrcodeResult">input qrCode string</param>
|
||||
/// <returns>the id if it was found it in the string otherwise null</returns>
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user