add qr and nfc scan to placeNewspage
This commit is contained in:
@@ -169,6 +169,12 @@ namespace CampusAppWP8.Model.GeoDb
|
||||
public List<PlaceModel> FilterByPid(List<string> pidList)
|
||||
{
|
||||
List<PlaceModel> fitlerList = new List<PlaceModel>();
|
||||
|
||||
if (pidList == null || pidList.Count < 1)
|
||||
{
|
||||
return fitlerList;
|
||||
}
|
||||
|
||||
foreach (PlaceModel place in this.Places)
|
||||
{
|
||||
if (pidList.Contains(place.PlaceId))
|
||||
|
||||
@@ -48,6 +48,8 @@ namespace CampusAppWP8.Pages.Dev
|
||||
/// <summary>true if this object is in autofocus. </summary>
|
||||
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<CameraOperationCompletedEventArgs>(this.Cam_Initialized);
|
||||
this.cam.AutoFocusCompleted += new EventHandler<CameraOperationCompletedEventArgs>(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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
/// <summary>Place news.</summary>
|
||||
/// <remarks>Stubbfel, 09.09.2013.</remarks>
|
||||
@@ -49,6 +52,11 @@ namespace CampusAppWP8.Pages.PlaceNews
|
||||
/// <summary>List of search pids.</summary>
|
||||
private List<string> searchPidList;
|
||||
|
||||
private bool qrScan = false;
|
||||
|
||||
/// <summary>The device.</summary>
|
||||
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<SpsModel>(Constants.IsolatedStorage_AllPlaces);
|
||||
this.SetupResultBox();
|
||||
if (this.places == null)
|
||||
{
|
||||
this.places = new PlacesFile();
|
||||
this.places.Model = App.LoadFromIsolatedStorage<SpsModel>(Constants.IsolatedStorage_AllPlaces);
|
||||
}
|
||||
|
||||
if (qrScan)
|
||||
{
|
||||
qrScan = false;
|
||||
string qrResult = App.LoadFromIsolatedStorage<string>("PlaceNewsQCCode");
|
||||
App.SaveToIsolatedStorage<string>("PlaceNewsQCCode", null);
|
||||
this.searchPidList = new List<string>() { 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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// send get request to pis andd pss for PlaceNews service
|
||||
/// </summary>
|
||||
/// <param name="pidList">list of place id</param>
|
||||
private void SendGetPisPssForPlacenews(List<string> pidList) {
|
||||
List<string> infoNames = new List<string>() { Constants.PisInformationName_Name };
|
||||
List<string> serviceNames = new List<string>() { 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);
|
||||
}
|
||||
/// <summary>
|
||||
/// Method send get for PlaceInformation of certain places
|
||||
/// </summary>
|
||||
/// <param name="pidList">list of place id</param>
|
||||
/// <param name="infoNames">list of informations name</param>
|
||||
/// <param name="force">if its true then force api load</param>
|
||||
private void SendGetPlaceInformation(List<string> pidList, List<string> 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))
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method send get for PlaceSetvice of certain places
|
||||
/// </summary>
|
||||
/// <param name="pidList">list of place id</param>
|
||||
/// <param name="serviceNames">list of service name</param>
|
||||
/// <param name="force">if its true then force api load</param>
|
||||
private void SendGetPlaceService(List<string> pidList, List<string> 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();
|
||||
}
|
||||
|
||||
/// <summary>Sets up the result box.</summary>
|
||||
@@ -294,6 +350,11 @@ namespace CampusAppWP8.Pages.PlaceNews
|
||||
/// <param name="e"> Event information.</param>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>Event handler. Called by ApplicationBarMenuItem_Click for 1 events.</summary>
|
||||
@@ -302,6 +363,7 @@ namespace CampusAppWP8.Pages.PlaceNews
|
||||
/// <param name="e"> Event information.</param>
|
||||
private void ApplicationBarMenuItem_Click_1(object sender, EventArgs e)
|
||||
{
|
||||
this.device.SubscribeForMessage("NDEF", this.NDEFHandler);
|
||||
}
|
||||
|
||||
/// <summary>Checked setup result box.</summary>
|
||||
@@ -346,6 +408,37 @@ namespace CampusAppWP8.Pages.PlaceNews
|
||||
txt.Text = place.GetInformationsValue(Constants.PisInformationName_Name);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>Handler, called when the ndef.</summary>
|
||||
/// <remarks>Stubbfel, 22.08.2013.</remarks>
|
||||
/// <param name="sender"> The sender.</param>
|
||||
/// <param name="message">The message.</param>
|
||||
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<string>() { pid };
|
||||
this.SendGetPisPssForPlacenews(this.searchPidList);
|
||||
// this.Dispatcher.BeginInvoke(new Action(() => MessageBox.Show(ndef.GetContent())));
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -654,6 +654,15 @@ namespace CampusAppWP8.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sucht eine lokalisierte Zeichenfolge, die QRResultKey ähnelt.
|
||||
/// </summary>
|
||||
public static string ParamQRResultKey {
|
||||
get {
|
||||
return ResourceManager.GetString("ParamQRResultKey", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sucht eine lokalisierte Zeichenfolge, die Url ähnelt.
|
||||
/// </summary>
|
||||
|
||||
@@ -513,4 +513,7 @@
|
||||
<data name="PathEvent_EventPage" xml:space="preserve">
|
||||
<value>/Pages/Events/EventPage.xaml</value>
|
||||
</data>
|
||||
<data name="ParamQRResultKey" xml:space="preserve">
|
||||
<value>QRResultKey</value>
|
||||
</data>
|
||||
</root>
|
||||
Reference in New Issue
Block a user