add ndefdraft
This commit is contained in:
@@ -116,9 +116,13 @@
|
||||
<Compile Include="Model\Utility\DegreeListPickerItemListModel.cs" />
|
||||
<Compile Include="Model\Utility\CleanUrlParamModel.cs" />
|
||||
<Compile Include="Model\Utility\CampusListPickerItemListModel.cs" />
|
||||
<Compile Include="Model\Utility\NDEF\NDEFRecord.cs" />
|
||||
<Compile Include="Model\Utility\RoleListPickerItemListModel.cs" />
|
||||
<Compile Include="Model\Utility\SemesterListPickerItemListModel.cs" />
|
||||
<Compile Include="Model\Utility\ListPickerItemListModel.cs" />
|
||||
<Compile Include="Pages\Dev\NFC.xaml.cs">
|
||||
<DependentUpon>NFC.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Pages\Setting\AppSettingPage.xaml.cs">
|
||||
<DependentUpon>AppSettingPage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
@@ -279,6 +283,10 @@
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Pages\Dev\NFC.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Pages\Lecture\LecturePage.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
@@ -428,7 +436,9 @@
|
||||
<Content Include="Assets\Tiles\kachel_large.png" />
|
||||
<Content Include="Assets\Tiles\kachel_medium.png" />
|
||||
<Content Include="Assets\Tiles\kachel_small.png" />
|
||||
<Content Include="File\Campusmap\Offlinemap.xml" />
|
||||
<Content Include="File\Campusmap\Offlinemap.xml">
|
||||
<SubType>Designer</SubType>
|
||||
</Content>
|
||||
<Content Include="README_FIRST.txt" />
|
||||
<Content Include="Toolkit.Content\ApplicationBar.Add.png" />
|
||||
<Content Include="Toolkit.Content\ApplicationBar.Cancel.png" />
|
||||
|
||||
92
CampusAppWP8/CampusAppWP8/Model/Utility/NDEF/NDEFRecord.cs
Normal file
92
CampusAppWP8/CampusAppWP8/Model/Utility/NDEF/NDEFRecord.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CampusAppWP8.Model.Utility.NDEF
|
||||
{
|
||||
public class NDEFRecord
|
||||
{
|
||||
private const byte typeSize = 0x01;
|
||||
public enum NDEFFlags
|
||||
{
|
||||
UNSET = 0x00,
|
||||
MBSET = 0x80,
|
||||
MESET = 0x40,
|
||||
CFSET = 0x20,
|
||||
SRSET = 0x10,
|
||||
ILSET = 0x08
|
||||
}
|
||||
|
||||
public enum TNFVAL
|
||||
{
|
||||
EMPTY = 0x00,
|
||||
WKT = 0x01,
|
||||
MEDIATYPE = 0x02,
|
||||
URI = 0x03,
|
||||
NFCE = 0x04,
|
||||
UNKOWN = 0x05,
|
||||
UNCHANGED = 0x06,
|
||||
RESERVED = 0x07
|
||||
}
|
||||
|
||||
public enum TYPEVAL
|
||||
{
|
||||
EMPTY = 0x00,
|
||||
URL = 0x55,
|
||||
TEXT = 0x54,
|
||||
}
|
||||
|
||||
public NDEFRecord()
|
||||
{
|
||||
|
||||
}
|
||||
public NDEFRecord(byte[] array)
|
||||
{
|
||||
this.Payload = Encoding.UTF8.GetString(array, 4, array.Length - 4);
|
||||
}
|
||||
public NDEFFlags MB { get; set; }
|
||||
public NDEFFlags ME { get; set; }
|
||||
public NDEFFlags CF { get; set; }
|
||||
public NDEFFlags SR { get; set; }
|
||||
public NDEFFlags IL { get; set; }
|
||||
public TNFVAL TNF { get; set; }
|
||||
public TYPEVAL Type { get; set; }
|
||||
public byte FormatFlags
|
||||
{
|
||||
get
|
||||
{
|
||||
return (byte)((byte)this.TNF | ((byte)this.MB) | ((byte)this.ME) | ((byte)this.CF) | ((byte)this.SR) | ((byte)this.IL));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public byte Record = 0xD1;
|
||||
|
||||
public string Payload = "nokia.com";
|
||||
|
||||
public byte[] toByteArray()
|
||||
{
|
||||
MemoryStream m = new MemoryStream();
|
||||
byte[] payloadAr = Encoding.UTF8.GetBytes(Payload);
|
||||
byte[] array = new byte[payloadAr.Length + 4];
|
||||
|
||||
array[0] = this.FormatFlags;
|
||||
array[1] = NDEFRecord.typeSize;
|
||||
array[2] = (byte)(Payload.Length);
|
||||
array[3] = (byte)this.Type;
|
||||
|
||||
int i = 4;
|
||||
foreach (byte b in payloadAr)
|
||||
{
|
||||
array[i] = b;
|
||||
i++;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
35
CampusAppWP8/CampusAppWP8/Pages/Dev/NFC.xaml
Normal file
35
CampusAppWP8/CampusAppWP8/Pages/Dev/NFC.xaml
Normal file
@@ -0,0 +1,35 @@
|
||||
<phone:PhoneApplicationPage
|
||||
x:Class="CampusAppWP8.Pages.Dev.NFC"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
|
||||
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
FontFamily="{StaticResource PhoneFontFamilyNormal}"
|
||||
FontSize="{StaticResource PhoneFontSizeNormal}"
|
||||
Foreground="{StaticResource PhoneForegroundBrush}"
|
||||
SupportedOrientations="Portrait" Orientation="Portrait"
|
||||
mc:Ignorable="d"
|
||||
shell:SystemTray.IsVisible="True">
|
||||
|
||||
<!--LayoutRoot ist das Stammraster, in dem alle anderen Seiteninhalte platziert werden-->
|
||||
<Grid x:Name="LayoutRoot" Background="Transparent">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!--TitlePanel enthält den Namen der Anwendung und den Seitentitel-->
|
||||
<StackPanel Grid.Row="0" Margin="12,17,0,28">
|
||||
<TextBlock Text="Campusapp" Style="{StaticResource PhoneTextNormalStyle}"/>
|
||||
<TextBlock Text="NFC" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
|
||||
</StackPanel>
|
||||
|
||||
<!--ContentPanel - zusätzliche Inhalte hier platzieren-->
|
||||
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
|
||||
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
</phone:PhoneApplicationPage>
|
||||
90
CampusAppWP8/CampusAppWP8/Pages/Dev/NFC.xaml.cs
Normal file
90
CampusAppWP8/CampusAppWP8/Pages/Dev/NFC.xaml.cs
Normal file
@@ -0,0 +1,90 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Navigation;
|
||||
using Microsoft.Phone.Controls;
|
||||
using Microsoft.Phone.Shell;
|
||||
using Windows.Networking.Proximity;
|
||||
using System.Runtime.InteropServices.WindowsRuntime;
|
||||
using CampusAppWP8.Model.Utility.NDEF;
|
||||
|
||||
|
||||
namespace CampusAppWP8.Pages.Dev
|
||||
{
|
||||
public partial class NFC : PhoneApplicationPage
|
||||
{
|
||||
|
||||
private readonly ProximityDevice device = ProximityDevice.GetDefault();
|
||||
private long lastMsgId;
|
||||
public NFC()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Override the OnNavigatedTo method
|
||||
/// </summary>
|
||||
/// <param name="e">Arguments of navigation</param>
|
||||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
{
|
||||
base.OnNavigatedTo(e);
|
||||
|
||||
if (this.device != null)
|
||||
{
|
||||
MessageBox.Show("NFC present");
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Your phone has no NFC or NFC is disabled");
|
||||
}
|
||||
this.lastMsgId = this.device.SubscribeForMessage("WriteableTag", WriteableTagDetected);
|
||||
}
|
||||
|
||||
protected override void OnNavigatedFrom(NavigationEventArgs e)
|
||||
{
|
||||
base.OnNavigatedTo(e);
|
||||
|
||||
this.device.StopSubscribingForMessage(this.lastMsgId);
|
||||
}
|
||||
|
||||
|
||||
private void WriteableTagDetected(ProximityDevice sender, ProximityMessage message)
|
||||
{
|
||||
Deployment.Current.Dispatcher.BeginInvoke(() =>
|
||||
{
|
||||
MessageBox.Show("message");
|
||||
});
|
||||
|
||||
this.device.StopSubscribingForMessage(message.SubscriptionId);
|
||||
|
||||
NDEFRecord ndef = new NDEFRecord();
|
||||
ndef.TNF = NDEFRecord.TNFVAL.URI;
|
||||
ndef.MB = NDEFRecord.NDEFFlags.MBSET;
|
||||
ndef.ME = NDEFRecord.NDEFFlags.MESET;
|
||||
ndef.SR = NDEFRecord.NDEFFlags.SRSET;
|
||||
ndef.Type = NDEFRecord.TYPEVAL.TEXT;
|
||||
ndef.toByteArray();
|
||||
ndef.Payload = "test";
|
||||
device.PublishBinaryMessage("NDEF:WriteTag", ndef.toByteArray().AsBuffer(), publishHandler);
|
||||
}
|
||||
|
||||
private void publishHandler(ProximityDevice sender, long messageId)
|
||||
{
|
||||
device.StopPublishingMessage(messageId);
|
||||
|
||||
device.SubscribeForMessage("NDEF", NDEFHandler);
|
||||
}
|
||||
|
||||
|
||||
private void NDEFHandler(ProximityDevice sender, ProximityMessage message)
|
||||
{
|
||||
|
||||
var NDefMessage = message.Data;
|
||||
byte[] testa = NDefMessage.ToArray();
|
||||
NDEFRecord test = new NDEFRecord(testa);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -142,6 +142,7 @@
|
||||
<shell:ApplicationBar.MenuItems>
|
||||
<shell:ApplicationBarMenuItem Text="Setting" Click="ApplicationBarMenuItem_Click"/>
|
||||
<shell:ApplicationBarMenuItem Text="Setting2" Click="ApplicationBarMenuItem2_Click"/>
|
||||
<shell:ApplicationBarMenuItem Text="Setting3" Click="ApplicationBarMenuItem3_Click"/>
|
||||
</shell:ApplicationBar.MenuItems>
|
||||
</shell:ApplicationBar>
|
||||
</phone:PhoneApplicationPage.ApplicationBar>
|
||||
|
||||
@@ -31,6 +31,7 @@ namespace CampusAppWP8.Pages
|
||||
this.InitializeComponent();
|
||||
ApplicationBarMenuItem menuItem1 = ApplicationBar.MenuItems[0] as ApplicationBarMenuItem;
|
||||
ApplicationBarMenuItem menuItem2 = ApplicationBar.MenuItems[1] as ApplicationBarMenuItem;
|
||||
ApplicationBarMenuItem menuItem3 = ApplicationBar.MenuItems[2] as ApplicationBarMenuItem;
|
||||
if (menuItem1 != null)
|
||||
{
|
||||
menuItem1.Text = AppResources.Setting_UserProfilAppBarTitle;
|
||||
@@ -41,6 +42,11 @@ namespace CampusAppWP8.Pages
|
||||
menuItem2.Text = AppResources.Setting_ApplAppBarTitle;
|
||||
}
|
||||
|
||||
if (menuItem3 != null)
|
||||
{
|
||||
menuItem3.Text = "Nfc";
|
||||
}
|
||||
|
||||
if (!Settings.AppSetting.InitApp)
|
||||
{
|
||||
this.ShowOptIns();
|
||||
@@ -126,6 +132,17 @@ namespace CampusAppWP8.Pages
|
||||
NavigationService.Navigate(url);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method Navigate to <see cref="Setting/UserProfil"/>
|
||||
/// </summary>
|
||||
/// <param name="sender">Caller of the function</param>
|
||||
/// <param name="e">some EventArgs</param>
|
||||
private void ApplicationBarMenuItem3_Click(object sender, EventArgs e)
|
||||
{
|
||||
Uri url = new Uri("/Pages/Dev/NFC.xaml", UriKind.Relative);
|
||||
NavigationService.Navigate(url);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method change the Opacity of the ApplicationBar
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user