[iOS Search Recipes] Two search recipes added.
This commit is contained in:
Родитель
9fbec48dd3
Коммит
98396455cc
|
@ -0,0 +1,43 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2012
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CoreSpotlightSearch", "CoreSpotlightSearch\CoreSpotlightSearch.csproj", "{9ECDE5C5-FFD6-495F-9DBE-3FCD773152F1}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CoreSpotlightSearch.iOS", "iOS\CoreSpotlightSearch.iOS.csproj", "{2F5E8483-B5D0-4F3B-9C1F-C7B3CCF88D4B}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
Debug|iPhoneSimulator = Debug|iPhoneSimulator
|
||||
Release|iPhone = Release|iPhone
|
||||
Release|iPhoneSimulator = Release|iPhoneSimulator
|
||||
Debug|iPhone = Debug|iPhone
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{2F5E8483-B5D0-4F3B-9C1F-C7B3CCF88D4B}.Debug|Any CPU.ActiveCfg = Debug|iPhoneSimulator
|
||||
{2F5E8483-B5D0-4F3B-9C1F-C7B3CCF88D4B}.Debug|Any CPU.Build.0 = Debug|iPhoneSimulator
|
||||
{2F5E8483-B5D0-4F3B-9C1F-C7B3CCF88D4B}.Debug|iPhone.ActiveCfg = Debug|iPhone
|
||||
{2F5E8483-B5D0-4F3B-9C1F-C7B3CCF88D4B}.Debug|iPhone.Build.0 = Debug|iPhone
|
||||
{2F5E8483-B5D0-4F3B-9C1F-C7B3CCF88D4B}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator
|
||||
{2F5E8483-B5D0-4F3B-9C1F-C7B3CCF88D4B}.Debug|iPhoneSimulator.Build.0 = Debug|iPhoneSimulator
|
||||
{2F5E8483-B5D0-4F3B-9C1F-C7B3CCF88D4B}.Release|Any CPU.ActiveCfg = Release|iPhone
|
||||
{2F5E8483-B5D0-4F3B-9C1F-C7B3CCF88D4B}.Release|Any CPU.Build.0 = Release|iPhone
|
||||
{2F5E8483-B5D0-4F3B-9C1F-C7B3CCF88D4B}.Release|iPhone.ActiveCfg = Release|iPhone
|
||||
{2F5E8483-B5D0-4F3B-9C1F-C7B3CCF88D4B}.Release|iPhone.Build.0 = Release|iPhone
|
||||
{2F5E8483-B5D0-4F3B-9C1F-C7B3CCF88D4B}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator
|
||||
{2F5E8483-B5D0-4F3B-9C1F-C7B3CCF88D4B}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator
|
||||
{9ECDE5C5-FFD6-495F-9DBE-3FCD773152F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9ECDE5C5-FFD6-495F-9DBE-3FCD773152F1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9ECDE5C5-FFD6-495F-9DBE-3FCD773152F1}.Debug|iPhone.ActiveCfg = Debug|Any CPU
|
||||
{9ECDE5C5-FFD6-495F-9DBE-3FCD773152F1}.Debug|iPhone.Build.0 = Debug|Any CPU
|
||||
{9ECDE5C5-FFD6-495F-9DBE-3FCD773152F1}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
|
||||
{9ECDE5C5-FFD6-495F-9DBE-3FCD773152F1}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
|
||||
{9ECDE5C5-FFD6-495F-9DBE-3FCD773152F1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9ECDE5C5-FFD6-495F-9DBE-3FCD773152F1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{9ECDE5C5-FFD6-495F-9DBE-3FCD773152F1}.Release|iPhone.ActiveCfg = Release|Any CPU
|
||||
{9ECDE5C5-FFD6-495F-9DBE-3FCD773152F1}.Release|iPhone.Build.0 = Release|Any CPU
|
||||
{9ECDE5C5-FFD6-495F-9DBE-3FCD773152F1}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
|
||||
{9ECDE5C5-FFD6-495F-9DBE-3FCD773152F1}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -0,0 +1,46 @@
|
|||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Xaml;
|
||||
|
||||
[assembly: XamlCompilation (XamlCompilationOptions.Compile)]
|
||||
namespace CoreSpotlightSearch
|
||||
{
|
||||
public class App : Application
|
||||
{
|
||||
public static TodoItemManager TodoManager { get; private set; }
|
||||
|
||||
public static ITextToSpeech Speech { get; set; }
|
||||
|
||||
public App ()
|
||||
{
|
||||
TodoManager = new TodoItemManager ();
|
||||
MainPage = new NavigationPage (new TodoListPage ());
|
||||
|
||||
MessagingCenter.Subscribe <CoreSpotlightSearch.App, string> (this, "ShowItem", async (sender, arg) => {
|
||||
var todoItems = TodoManager.All;
|
||||
var item = todoItems.FirstOrDefault (i => i.ID == arg);
|
||||
|
||||
await MainPage.Navigation.PopToRootAsync ();
|
||||
var todoItemPage = new TodoItemPage ();
|
||||
todoItemPage.BindingContext = item;
|
||||
await MainPage.Navigation.PushAsync (todoItemPage);
|
||||
});
|
||||
}
|
||||
|
||||
protected override void OnStart ()
|
||||
{
|
||||
// Handle when your app starts
|
||||
}
|
||||
|
||||
protected override void OnSleep ()
|
||||
{
|
||||
// Handle when your app sleeps
|
||||
}
|
||||
|
||||
protected override void OnResume ()
|
||||
{
|
||||
// Handle when your app resumes
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<ProjectGuid>{9ECDE5C5-FFD6-495F-9DBE-3FCD773152F1}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>CoreSpotlightSearch</RootNamespace>
|
||||
<AssemblyName>CoreSpotlightSearch</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<TargetFrameworkProfile>Profile78</TargetFrameworkProfile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="App.cs" />
|
||||
<Compile Include="Data\TodoItemManager.cs" />
|
||||
<Compile Include="Models\TodoItem.cs" />
|
||||
<Compile Include="Views\TodoItemPage.xaml.cs">
|
||||
<DependentUpon>TodoItemPage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\TodoListPage.xaml.cs">
|
||||
<DependentUpon>TodoListPage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="ITextToSpeech.cs" />
|
||||
<Compile Include="ISpotlightSearch.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
|
||||
<Import Project="..\packages\Xamarin.Forms.2.0.0.6487\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets" Condition="Exists('..\packages\Xamarin.Forms.2.0.0.6487\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets')" />
|
||||
<ItemGroup>
|
||||
<Folder Include="Data\" />
|
||||
<Folder Include="Models\" />
|
||||
<Folder Include="Views\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Views\TodoItemPage.xaml">
|
||||
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Views\TodoListPage.xaml">
|
||||
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Xamarin.Forms.Core">
|
||||
<HintPath>..\packages\Xamarin.Forms.2.0.0.6487\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Xamarin.Forms.Xaml">
|
||||
<HintPath>..\packages\Xamarin.Forms.2.0.0.6487\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.Xaml.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Xamarin.Forms.Platform">
|
||||
<HintPath>..\packages\Xamarin.Forms.2.0.0.6487\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.Platform.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -0,0 +1,78 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace CoreSpotlightSearch
|
||||
{
|
||||
public class TodoItemManager
|
||||
{
|
||||
List<TodoItem> todoItems;
|
||||
|
||||
public TodoItemManager ()
|
||||
{
|
||||
InitializeData ();
|
||||
}
|
||||
|
||||
public List<TodoItem> All {
|
||||
get { return todoItems; }
|
||||
}
|
||||
|
||||
public bool DoesItemExist (string id)
|
||||
{
|
||||
return todoItems.Any (item => item.ID == id);
|
||||
}
|
||||
|
||||
public TodoItem Find (string id)
|
||||
{
|
||||
return todoItems.FirstOrDefault (item => item.ID == id);
|
||||
}
|
||||
|
||||
public void Insert (TodoItem item)
|
||||
{
|
||||
todoItems.Add (item);
|
||||
}
|
||||
|
||||
public void Update (TodoItem item)
|
||||
{
|
||||
var todoItem = Find (item.ID);
|
||||
var index = todoItems.IndexOf (todoItem);
|
||||
todoItems.RemoveAt (index);
|
||||
todoItems.Insert (index, item);
|
||||
}
|
||||
|
||||
public void Delete (string id)
|
||||
{
|
||||
todoItems.Remove (Find (id));
|
||||
}
|
||||
|
||||
void InitializeData ()
|
||||
{
|
||||
todoItems = new List<TodoItem> ();
|
||||
|
||||
var todoItem1 = new TodoItem {
|
||||
ID = "6bb8a868-dba1-4f1a-93b7-24ebce87e243",
|
||||
Name = "Learn app development",
|
||||
Notes = "Attend Xamarin University",
|
||||
Done = true
|
||||
};
|
||||
|
||||
var todoItem2 = new TodoItem {
|
||||
ID = "b94afb54-a1cb-4313-8af3-b7511551b33b",
|
||||
Name = "Develop apps",
|
||||
Notes = "Use Xamarin Studio/Visual Studio",
|
||||
Done = false
|
||||
};
|
||||
|
||||
var todoItem3 = new TodoItem {
|
||||
ID = "ecfa6f80-3671-4911-aabe-63cc442c1ecf",
|
||||
Name = "Publish apps",
|
||||
Notes = "All app stores",
|
||||
Done = false,
|
||||
};
|
||||
|
||||
todoItems.Add (todoItem1);
|
||||
todoItems.Add (todoItem2);
|
||||
todoItems.Add (todoItem3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
namespace CoreSpotlightSearch
|
||||
{
|
||||
public interface ISpotlightSearch
|
||||
{
|
||||
void CreateSearchItem (TodoItem item);
|
||||
|
||||
void DeleteSearchItem (TodoItem item);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
namespace CoreSpotlightSearch
|
||||
{
|
||||
public interface ITextToSpeech
|
||||
{
|
||||
void Speak (string text);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
namespace CoreSpotlightSearch
|
||||
{
|
||||
public class TodoItem
|
||||
{
|
||||
public string ID { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Notes { get; set; }
|
||||
|
||||
public bool Done { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
// Information about this assembly is defined by the following attributes.
|
||||
// Change them to the values specific to your project.
|
||||
|
||||
[assembly: AssemblyTitle ("CoreSpotlightSearch")]
|
||||
[assembly: AssemblyDescription ("")]
|
||||
[assembly: AssemblyConfiguration ("")]
|
||||
[assembly: AssemblyCompany ("")]
|
||||
[assembly: AssemblyProduct ("")]
|
||||
[assembly: AssemblyCopyright ("Xamarin")]
|
||||
[assembly: AssemblyTrademark ("")]
|
||||
[assembly: AssemblyCulture ("")]
|
||||
|
||||
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
|
||||
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
|
||||
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
|
||||
|
||||
[assembly: AssemblyVersion ("1.0.*")]
|
||||
|
||||
// The following attributes are used to specify the signing key for the assembly,
|
||||
// if desired. See the Mono documentation for more information about signing.
|
||||
|
||||
//[assembly: AssemblyDelaySign(false)]
|
||||
//[assembly: AssemblyKeyFile("")]
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="CoreSpotlightSearch.TodoItemPage" Title="Todo Item">
|
||||
<ContentPage.Content>
|
||||
<StackLayout VerticalOptions="StartAndExpand">
|
||||
<Label Text="Name" />
|
||||
<Entry Text="{Binding Path=Name}" Placeholder="task name" />
|
||||
<Label Text="Notes" />
|
||||
<Entry Text="{Binding Path=Notes}" />
|
||||
<Label Text="Done" />
|
||||
<Switch IsToggled="{Binding Path=Done}" />
|
||||
<Button Text="Save" Clicked="OnSaveActivated" />
|
||||
<Button Text="Delete" Clicked="OnDeleteActivated" />
|
||||
<Button Text="Cancel" Clicked="OnCancelActivated" />
|
||||
<Button Text="Speak" Clicked="OnSpeakActivated" />
|
||||
</StackLayout>
|
||||
</ContentPage.Content>
|
||||
</ContentPage>
|
|
@ -0,0 +1,58 @@
|
|||
using System;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace CoreSpotlightSearch
|
||||
{
|
||||
public partial class TodoItemPage : ContentPage
|
||||
{
|
||||
ISpotlightSearch spotlightSearch;
|
||||
bool isNewItem;
|
||||
|
||||
public TodoItemPage (bool isNew = false)
|
||||
{
|
||||
InitializeComponent ();
|
||||
isNewItem = isNew;
|
||||
|
||||
if (Device.OS == TargetPlatform.iOS) {
|
||||
spotlightSearch = DependencyService.Get<ISpotlightSearch> ();
|
||||
}
|
||||
}
|
||||
|
||||
async void OnSaveActivated (object sender, EventArgs e)
|
||||
{
|
||||
var todoItem = (TodoItem)BindingContext;
|
||||
if (isNewItem) {
|
||||
App.TodoManager.Insert (todoItem);
|
||||
} else {
|
||||
App.TodoManager.Update (todoItem);
|
||||
}
|
||||
|
||||
if (Device.OS == TargetPlatform.iOS) {
|
||||
spotlightSearch.CreateSearchItem (todoItem);
|
||||
}
|
||||
await Navigation.PopAsync ();
|
||||
}
|
||||
|
||||
async void OnDeleteActivated (object sender, EventArgs e)
|
||||
{
|
||||
var todoItem = (TodoItem)BindingContext;
|
||||
App.TodoManager.Delete (todoItem.ID);
|
||||
|
||||
if (Device.OS == TargetPlatform.iOS) {
|
||||
spotlightSearch.DeleteSearchItem (todoItem);
|
||||
}
|
||||
await Navigation.PopAsync ();
|
||||
}
|
||||
|
||||
async void OnCancelActivated (object sender, EventArgs e)
|
||||
{
|
||||
await Navigation.PopAsync ();
|
||||
}
|
||||
|
||||
void OnSpeakActivated (object sender, EventArgs e)
|
||||
{
|
||||
var todoItem = (TodoItem)BindingContext;
|
||||
App.Speech.Speak (todoItem.Name + " " + todoItem.Notes);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="CoreSpotlightSearch.TodoListPage" Title="CoreSpotlightSearch">
|
||||
<ContentPage.ToolbarItems>
|
||||
<ToolbarItem Name="+" Activated="OnAddItemActivated" />
|
||||
</ContentPage.ToolbarItems>
|
||||
<ContentPage.Content>
|
||||
<ListView x:Name="listView" ItemSelected="OnItemSelected">
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<ViewCell>
|
||||
<StackLayout Padding="20,0,0,0" HorizontalOptions="StartAndExpand" Orientation="Horizontal">
|
||||
<Label Text="{Binding Name}" YAlign="Center" />
|
||||
<Image Source="check.png" IsVisible="{Binding Done}" />
|
||||
</StackLayout>
|
||||
</ViewCell>
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>
|
||||
</ContentPage.Content>
|
||||
</ContentPage>
|
|
@ -0,0 +1,43 @@
|
|||
using System;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace CoreSpotlightSearch
|
||||
{
|
||||
public partial class TodoListPage : ContentPage
|
||||
{
|
||||
public TodoListPage ()
|
||||
{
|
||||
InitializeComponent ();
|
||||
}
|
||||
|
||||
protected override void OnAppearing ()
|
||||
{
|
||||
base.OnAppearing ();
|
||||
listView.ItemsSource = App.TodoManager.All;
|
||||
}
|
||||
|
||||
protected override void OnDisappearing ()
|
||||
{
|
||||
base.OnDisappearing ();
|
||||
listView.ItemsSource = null;
|
||||
}
|
||||
|
||||
async void OnAddItemActivated (object sender, EventArgs e)
|
||||
{
|
||||
var todoItem = new TodoItem () {
|
||||
ID = Guid.NewGuid ().ToString ()
|
||||
};
|
||||
var todoPage = new TodoItemPage (true);
|
||||
todoPage.BindingContext = todoItem;
|
||||
await Navigation.PushAsync (todoPage);
|
||||
}
|
||||
|
||||
async void OnItemSelected (object sender, SelectedItemChangedEventArgs e)
|
||||
{
|
||||
var todoItem = e.SelectedItem as TodoItem;
|
||||
var todoPage = new TodoItemPage ();
|
||||
todoPage.BindingContext = todoItem;
|
||||
await Navigation.PushAsync (todoPage);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Xamarin.Forms" version="2.0.0.6487" targetFramework="portable-net45+win+wp80+MonoTouch10+MonoAndroid10+xamarinmac20+xamarinios10" />
|
||||
</packages>
|
|
@ -0,0 +1,3 @@
|
|||
This recipe shows how to use the iOS9 Core Spotlight framework to make Xamarin.Forms app content searchable through Spotlight search.
|
||||
|
||||
The full recipe can be found [here](http://developer.xamarin.com/recipes/cross-platform/xamarin-forms/core-spotlight-search/).
|
|
@ -0,0 +1,45 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using CoreSpotlight;
|
||||
using Foundation;
|
||||
using UIKit;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace CoreSpotlightSearch.iOS
|
||||
{
|
||||
[Register ("AppDelegate")]
|
||||
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
|
||||
{
|
||||
List<TodoItem> todoItems;
|
||||
|
||||
public SpotlightSearch SpotlightSearch { get; private set; }
|
||||
|
||||
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
|
||||
{
|
||||
global::Xamarin.Forms.Forms.Init ();
|
||||
|
||||
App.Speech = new Speech ();
|
||||
LoadApplication (new App ());
|
||||
todoItems = App.TodoManager.All;
|
||||
|
||||
if (UIDevice.CurrentDevice.CheckSystemVersion (9, 0)) {
|
||||
SpotlightSearch = new SpotlightSearch (todoItems);
|
||||
} else {
|
||||
throw new NotSupportedException ("CoreSpotlight not supported");
|
||||
}
|
||||
|
||||
return base.FinishedLaunching (app, options);
|
||||
}
|
||||
|
||||
public override bool ContinueUserActivity (UIApplication application, NSUserActivity userActivity, UIApplicationRestorationHandler completionHandler)
|
||||
{
|
||||
if (userActivity.ActivityType == CSSearchableItem.ActionType) {
|
||||
string id = userActivity.UserInfo.ObjectForKey (CSSearchableItem.ActivityIdentifier).ToString ();
|
||||
if (!string.IsNullOrEmpty (id)) {
|
||||
MessagingCenter.Send<CoreSpotlightSearch.App, string> (Xamarin.Forms.Application.Current as CoreSpotlightSearch.App, "ShowItem", id);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,124 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">iPhoneSimulator</Platform>
|
||||
<ProjectTypeGuids>{FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<ProjectGuid>{2F5E8483-B5D0-4F3B-9C1F-C7B3CCF88D4B}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>CoreSpotlightSearch.iOS</RootNamespace>
|
||||
<IPhoneResourcePrefix>Resources</IPhoneResourcePrefix>
|
||||
<AssemblyName>CoreSpotlightSearch.iOS</AssemblyName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\iPhoneSimulator\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG;ENABLE_TEST_CLOUD;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
<MtouchArch>i386</MtouchArch>
|
||||
<MtouchLink>None</MtouchLink>
|
||||
<MtouchUseRefCounting>true</MtouchUseRefCounting>
|
||||
<MtouchUseSGen>true</MtouchUseSGen>
|
||||
<MtouchFastDev>true</MtouchFastDev>
|
||||
<MtouchDebug>true</MtouchDebug>
|
||||
<CodesignKey>iPhone Developer</CodesignKey>
|
||||
<MtouchProfiling>true</MtouchProfiling>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' ">
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\iPhone\Release</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
<MtouchArch>ARMv7, ARM64</MtouchArch>
|
||||
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
|
||||
<MtouchFloat32>true</MtouchFloat32>
|
||||
<MtouchUseSGen>true</MtouchUseSGen>
|
||||
<CodesignKey>iPhone Developer</CodesignKey>
|
||||
<MtouchUseRefCounting>true</MtouchUseRefCounting>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhoneSimulator' ">
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\iPhoneSimulator\Release</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
<MtouchArch>i386</MtouchArch>
|
||||
<MtouchLink>None</MtouchLink>
|
||||
<MtouchUseRefCounting>true</MtouchUseRefCounting>
|
||||
<CodesignKey>iPhone Developer</CodesignKey>
|
||||
<MtouchUseSGen>true</MtouchUseSGen>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhone' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\iPhone\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG;ENABLE_TEST_CLOUD;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
<MtouchArch>ARMv7, ARM64</MtouchArch>
|
||||
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
|
||||
<MtouchFloat32>true</MtouchFloat32>
|
||||
<CodesignKey>iPhone Developer</CodesignKey>
|
||||
<DeviceSpecificBuild>true</DeviceSpecificBuild>
|
||||
<MtouchDebug>true</MtouchDebug>
|
||||
<MtouchUseSGen>true</MtouchUseSGen>
|
||||
<MtouchUseRefCounting>true</MtouchUseRefCounting>
|
||||
<MtouchProfiling>true</MtouchProfiling>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="Xamarin.iOS" />
|
||||
<Reference Include="Xamarin.Forms.Platform.iOS">
|
||||
<HintPath>..\packages\Xamarin.Forms.2.0.0.6487\lib\Xamarin.iOS10\Xamarin.Forms.Platform.iOS.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Xamarin.Forms.Core">
|
||||
<HintPath>..\packages\Xamarin.Forms.2.0.0.6487\lib\Xamarin.iOS10\Xamarin.Forms.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Xamarin.Forms.Xaml">
|
||||
<HintPath>..\packages\Xamarin.Forms.2.0.0.6487\lib\Xamarin.iOS10\Xamarin.Forms.Xaml.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Xamarin.Forms.Platform">
|
||||
<HintPath>..\packages\Xamarin.Forms.2.0.0.6487\lib\Xamarin.iOS10\Xamarin.Forms.Platform.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CoreSpotlightSearch\CoreSpotlightSearch.csproj">
|
||||
<Project>{9ECDE5C5-FFD6-495F-9DBE-3FCD773152F1}</Project>
|
||||
<Name>CoreSpotlightSearch</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ImageAsset Include="Resources\Images.xcassets\AppIcons.appiconset\Contents.json" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<InterfaceDefinition Include="Resources\LaunchScreen.xib" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Info.plist" />
|
||||
<None Include="Entitlements.plist" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Main.cs" />
|
||||
<Compile Include="AppDelegate.cs" />
|
||||
<Compile Include="Speech.cs" />
|
||||
<Compile Include="SpotlightSearch.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
|
||||
<Import Project="..\packages\Xamarin.Forms.2.0.0.6487\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets" Condition="Exists('..\packages\Xamarin.Forms.2.0.0.6487\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets')" />
|
||||
<ItemGroup>
|
||||
<BundleResource Include="Resources\check.png" />
|
||||
<BundleResource Include="Resources\check%402x.png" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
</dict>
|
||||
</plist>
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDisplayName</key>
|
||||
<string>CoreSpotlightSearch</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.companyname.corespotlightsearch</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.0</string>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>MinimumOSVersion</key>
|
||||
<string>9.0</string>
|
||||
<key>UIDeviceFamily</key>
|
||||
<array>
|
||||
<integer>1</integer>
|
||||
<integer>2</integer>
|
||||
</array>
|
||||
<key>UILaunchStoryboardName</key>
|
||||
<string>LaunchScreen</string>
|
||||
<key>UIRequiredDeviceCapabilities</key>
|
||||
<array>
|
||||
<string>armv7</string>
|
||||
</array>
|
||||
<key>UISupportedInterfaceOrientations</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
<key>UISupportedInterfaceOrientations~ipad</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
<string>UIInterfaceOrientationPortraitUpsideDown</string>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
<key>XSAppIconAssets</key>
|
||||
<string>Resources/Images.xcassets/AppIcons.appiconset</string>
|
||||
</dict>
|
||||
</plist>
|
|
@ -0,0 +1,16 @@
|
|||
using UIKit;
|
||||
|
||||
namespace CoreSpotlightSearch.iOS
|
||||
{
|
||||
public class Application
|
||||
{
|
||||
// This is the main entry point of the application.
|
||||
static void Main (string[] args)
|
||||
{
|
||||
// if you want to use a different Application Delegate class from "AppDelegate"
|
||||
// you can specify it here.
|
||||
UIApplication.Main (args, null, "AppDelegate");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,108 @@
|
|||
{
|
||||
"images": [
|
||||
{
|
||||
"size": "29x29",
|
||||
"scale": "1x",
|
||||
"idiom": "iphone"
|
||||
},
|
||||
{
|
||||
"size": "29x29",
|
||||
"scale": "2x",
|
||||
"idiom": "iphone"
|
||||
},
|
||||
{
|
||||
"size": "29x29",
|
||||
"scale": "3x",
|
||||
"idiom": "iphone"
|
||||
},
|
||||
{
|
||||
"size": "40x40",
|
||||
"scale": "2x",
|
||||
"idiom": "iphone"
|
||||
},
|
||||
{
|
||||
"size": "40x40",
|
||||
"scale": "3x",
|
||||
"idiom": "iphone"
|
||||
},
|
||||
{
|
||||
"size": "57x57",
|
||||
"scale": "1x",
|
||||
"idiom": "iphone"
|
||||
},
|
||||
{
|
||||
"size": "57x57",
|
||||
"scale": "2x",
|
||||
"idiom": "iphone"
|
||||
},
|
||||
{
|
||||
"size": "60x60",
|
||||
"scale": "2x",
|
||||
"idiom": "iphone"
|
||||
},
|
||||
{
|
||||
"size": "60x60",
|
||||
"scale": "3x",
|
||||
"idiom": "iphone"
|
||||
},
|
||||
{
|
||||
"size": "29x29",
|
||||
"scale": "1x",
|
||||
"idiom": "ipad"
|
||||
},
|
||||
{
|
||||
"size": "29x29",
|
||||
"scale": "2x",
|
||||
"idiom": "ipad"
|
||||
},
|
||||
{
|
||||
"size": "40x40",
|
||||
"scale": "1x",
|
||||
"idiom": "ipad"
|
||||
},
|
||||
{
|
||||
"size": "40x40",
|
||||
"scale": "2x",
|
||||
"idiom": "ipad"
|
||||
},
|
||||
{
|
||||
"size": "50x50",
|
||||
"scale": "1x",
|
||||
"idiom": "ipad"
|
||||
},
|
||||
{
|
||||
"size": "50x50",
|
||||
"scale": "2x",
|
||||
"idiom": "ipad"
|
||||
},
|
||||
{
|
||||
"size": "72x72",
|
||||
"scale": "1x",
|
||||
"idiom": "ipad"
|
||||
},
|
||||
{
|
||||
"size": "72x72",
|
||||
"scale": "2x",
|
||||
"idiom": "ipad"
|
||||
},
|
||||
{
|
||||
"size": "76x76",
|
||||
"scale": "1x",
|
||||
"idiom": "ipad"
|
||||
},
|
||||
{
|
||||
"size": "76x76",
|
||||
"scale": "2x",
|
||||
"idiom": "ipad"
|
||||
},
|
||||
{
|
||||
"size": "120x120",
|
||||
"scale": "1x",
|
||||
"idiom": "car"
|
||||
}
|
||||
],
|
||||
"info": {
|
||||
"version": 1,
|
||||
"author": "xcode"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6214" systemVersion="14A314h" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
|
||||
<dependencies>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6207"/>
|
||||
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
|
||||
<view contentMode="scaleToFill" id="iN0-l3-epB">
|
||||
<rect key="frame" x="0.0" y="0.0" width="480" height="480"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" Copyright (c) 2015 Xamarin" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="8ie-xW-0ye" misplaced="YES">
|
||||
<rect key="frame" x="20" y="439" width="441" height="21"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
||||
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="CoreSpotlightSearch.iOS" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="kId-c2-rCX" misplaced="YES">
|
||||
<rect key="frame" x="20" y="140" width="441" height="43"/>
|
||||
<fontDescription key="fontDescription" type="boldSystem" pointSize="36"/>
|
||||
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
|
||||
<constraints>
|
||||
<constraint firstItem="kId-c2-rCX" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="bottom" multiplier="1/3" constant="1" id="5cJ-9S-tgC"/>
|
||||
<constraint firstAttribute="centerX" secondItem="kId-c2-rCX" secondAttribute="centerX" id="Koa-jz-hwk"/>
|
||||
<constraint firstAttribute="bottom" secondItem="8ie-xW-0ye" secondAttribute="bottom" constant="20" id="Kzo-t9-V3l"/>
|
||||
<constraint firstItem="8ie-xW-0ye" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="20" symbolic="YES" id="MfP-vx-nX0"/>
|
||||
<constraint firstAttribute="centerX" secondItem="8ie-xW-0ye" secondAttribute="centerX" id="ZEH-qu-HZ9"/>
|
||||
<constraint firstItem="kId-c2-rCX" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="20" symbolic="YES" id="fvb-Df-36g"/>
|
||||
</constraints>
|
||||
<nil key="simulatedStatusBarMetrics"/>
|
||||
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
|
||||
<point key="canvasLocation" x="548" y="455"/>
|
||||
</view>
|
||||
</objects>
|
||||
<resources>
|
||||
<image name="check.png" width="16" height="18"/>
|
||||
</resources>
|
||||
</document>
|
Двоичные данные
cross-platform/xamarin-forms/iOS/CoreSpotlightSearch/iOS/Resources/check.png
Normal file
Двоичные данные
cross-platform/xamarin-forms/iOS/CoreSpotlightSearch/iOS/Resources/check.png
Normal file
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 292 B |
Двоичные данные
cross-platform/xamarin-forms/iOS/CoreSpotlightSearch/iOS/Resources/check@2x.png
Normal file
Двоичные данные
cross-platform/xamarin-forms/iOS/CoreSpotlightSearch/iOS/Resources/check@2x.png
Normal file
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 459 B |
|
@ -0,0 +1,29 @@
|
|||
using AVFoundation;
|
||||
|
||||
namespace CoreSpotlightSearch.iOS
|
||||
{
|
||||
public class Speech : ITextToSpeech
|
||||
{
|
||||
float volume = 0.5f;
|
||||
float pitch = 1.0f;
|
||||
|
||||
/// <summary>
|
||||
/// Speak example from:
|
||||
/// http://blog.xamarin.com/make-your-ios-7-app-speak/
|
||||
/// </summary>
|
||||
public void Speak (string text)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace (text)) {
|
||||
var speechSynthesizer = new AVSpeechSynthesizer ();
|
||||
var speechUtterance = new AVSpeechUtterance (text) {
|
||||
Rate = AVSpeechUtterance.MaximumSpeechRate / 2,
|
||||
Voice = AVSpeechSynthesisVoice.FromLanguage ("en-US"),
|
||||
Volume = volume,
|
||||
PitchMultiplier = pitch
|
||||
};
|
||||
|
||||
speechSynthesizer.SpeakUtterance (speechUtterance);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using CoreSpotlight;
|
||||
using CoreSpotlightSearch.iOS;
|
||||
using MobileCoreServices;
|
||||
using Xamarin.Forms;
|
||||
|
||||
[assembly:Dependency (typeof(SpotlightSearch))]
|
||||
namespace CoreSpotlightSearch.iOS
|
||||
{
|
||||
public class SpotlightSearch : ISpotlightSearch
|
||||
{
|
||||
List<TodoItem> todoItems;
|
||||
|
||||
public SpotlightSearch ()
|
||||
{
|
||||
}
|
||||
|
||||
public SpotlightSearch (List<TodoItem> items)
|
||||
{
|
||||
todoItems = items;
|
||||
|
||||
// Re-index the app's data
|
||||
ReIndexSearchItems (todoItems);
|
||||
}
|
||||
|
||||
public void CreateSearchItem (TodoItem item)
|
||||
{
|
||||
// Create attributes to describe item
|
||||
var attributes = new CSSearchableItemAttributeSet (UTType.Text);
|
||||
attributes.Title = item.Name;
|
||||
attributes.ContentDescription = item.Notes;
|
||||
|
||||
// Create item
|
||||
var searchableItem = new CSSearchableItem (item.ID, "com.companyname.corespotlightsearch", attributes);
|
||||
|
||||
// Index item
|
||||
CSSearchableIndex.DefaultSearchableIndex.Index (new CSSearchableItem[]{ searchableItem }, error => {
|
||||
if (error != null) {
|
||||
Debug.WriteLine (error);
|
||||
} else {
|
||||
Debug.WriteLine ("Successfully indexed item");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void DeleteSearchItem (TodoItem item)
|
||||
{
|
||||
CSSearchableIndex.DefaultSearchableIndex.Delete (new string[]{ item.ID }, error => {
|
||||
if (error != null) {
|
||||
Debug.WriteLine (error);
|
||||
} else {
|
||||
Debug.WriteLine ("Successfully deleted item");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void ReIndexSearchItems (List<TodoItem> items)
|
||||
{
|
||||
var searchableItems = new List<CSSearchableItem> ();
|
||||
foreach (var item in todoItems) {
|
||||
// Create attributes to describe item
|
||||
var attributes = new CSSearchableItemAttributeSet (UTType.Text);
|
||||
attributes.Title = item.Name;
|
||||
attributes.ContentDescription = item.Notes;
|
||||
|
||||
// Create item
|
||||
var searchableItem = new CSSearchableItem (item.ID, "com.companyname.corespotlightsearch", attributes);
|
||||
searchableItems.Add (searchableItem);
|
||||
}
|
||||
|
||||
// Index items
|
||||
CSSearchableIndex.DefaultSearchableIndex.Index (searchableItems.ToArray<CSSearchableItem> (), error => {
|
||||
if (error != null) {
|
||||
Debug.WriteLine (error);
|
||||
} else {
|
||||
Debug.WriteLine ("Successfully indexed items");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Xamarin.Forms" version="2.0.0.6487" targetFramework="xamarinios10" />
|
||||
</packages>
|
|
@ -0,0 +1,43 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2012
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NSUserActivitySearch", "NSUserActivitySearch\NSUserActivitySearch.csproj", "{4864CFE3-E78F-4ABA-AB11-950EF1A5B994}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NSUserActivitySearch.iOS", "iOS\NSUserActivitySearch.iOS.csproj", "{AD6C4F19-6352-4050-B460-61B594F199C2}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
Debug|iPhoneSimulator = Debug|iPhoneSimulator
|
||||
Release|iPhone = Release|iPhone
|
||||
Release|iPhoneSimulator = Release|iPhoneSimulator
|
||||
Debug|iPhone = Debug|iPhone
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{4864CFE3-E78F-4ABA-AB11-950EF1A5B994}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{4864CFE3-E78F-4ABA-AB11-950EF1A5B994}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4864CFE3-E78F-4ABA-AB11-950EF1A5B994}.Debug|iPhone.ActiveCfg = Debug|Any CPU
|
||||
{4864CFE3-E78F-4ABA-AB11-950EF1A5B994}.Debug|iPhone.Build.0 = Debug|Any CPU
|
||||
{4864CFE3-E78F-4ABA-AB11-950EF1A5B994}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
|
||||
{4864CFE3-E78F-4ABA-AB11-950EF1A5B994}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
|
||||
{4864CFE3-E78F-4ABA-AB11-950EF1A5B994}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4864CFE3-E78F-4ABA-AB11-950EF1A5B994}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{4864CFE3-E78F-4ABA-AB11-950EF1A5B994}.Release|iPhone.ActiveCfg = Release|Any CPU
|
||||
{4864CFE3-E78F-4ABA-AB11-950EF1A5B994}.Release|iPhone.Build.0 = Release|Any CPU
|
||||
{4864CFE3-E78F-4ABA-AB11-950EF1A5B994}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
|
||||
{4864CFE3-E78F-4ABA-AB11-950EF1A5B994}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
|
||||
{AD6C4F19-6352-4050-B460-61B594F199C2}.Debug|Any CPU.ActiveCfg = Debug|iPhoneSimulator
|
||||
{AD6C4F19-6352-4050-B460-61B594F199C2}.Debug|Any CPU.Build.0 = Debug|iPhoneSimulator
|
||||
{AD6C4F19-6352-4050-B460-61B594F199C2}.Debug|iPhone.ActiveCfg = Debug|iPhone
|
||||
{AD6C4F19-6352-4050-B460-61B594F199C2}.Debug|iPhone.Build.0 = Debug|iPhone
|
||||
{AD6C4F19-6352-4050-B460-61B594F199C2}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator
|
||||
{AD6C4F19-6352-4050-B460-61B594F199C2}.Debug|iPhoneSimulator.Build.0 = Debug|iPhoneSimulator
|
||||
{AD6C4F19-6352-4050-B460-61B594F199C2}.Release|Any CPU.ActiveCfg = Release|iPhone
|
||||
{AD6C4F19-6352-4050-B460-61B594F199C2}.Release|Any CPU.Build.0 = Release|iPhone
|
||||
{AD6C4F19-6352-4050-B460-61B594F199C2}.Release|iPhone.ActiveCfg = Release|iPhone
|
||||
{AD6C4F19-6352-4050-B460-61B594F199C2}.Release|iPhone.Build.0 = Release|iPhone
|
||||
{AD6C4F19-6352-4050-B460-61B594F199C2}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator
|
||||
{AD6C4F19-6352-4050-B460-61B594F199C2}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -0,0 +1,47 @@
|
|||
using System.Linq;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Xaml;
|
||||
|
||||
[assembly: XamlCompilation (XamlCompilationOptions.Compile)]
|
||||
namespace NSUserActivitySearch
|
||||
{
|
||||
public class App : Application
|
||||
{
|
||||
public static TodoItemManager TodoManager { get; private set; }
|
||||
|
||||
public static ITextToSpeech Speech { get; set; }
|
||||
|
||||
public App ()
|
||||
{
|
||||
TodoManager = new TodoItemManager ();
|
||||
MainPage = new NavigationPage (new TodoListPage ());
|
||||
|
||||
MessagingCenter.Subscribe <NSUserActivitySearch.App, string> (this, "ShowItem", async (sender, arg) => {
|
||||
var todoItems = TodoManager.All;
|
||||
var item = todoItems.FirstOrDefault (i => i.ID == arg);
|
||||
|
||||
if (item != null) {
|
||||
await MainPage.Navigation.PopToRootAsync ();
|
||||
var todoItemPage = new TodoItemPage ();
|
||||
todoItemPage.BindingContext = item;
|
||||
await MainPage.Navigation.PushAsync (todoItemPage);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected override void OnStart ()
|
||||
{
|
||||
// Handle when your app starts
|
||||
}
|
||||
|
||||
protected override void OnSleep ()
|
||||
{
|
||||
// Handle when your app sleeps
|
||||
}
|
||||
|
||||
protected override void OnResume ()
|
||||
{
|
||||
// Handle when your app resumes
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace NSUserActivitySearch
|
||||
{
|
||||
public class TodoItemManager
|
||||
{
|
||||
List<TodoItem> todoItems;
|
||||
|
||||
public TodoItemManager ()
|
||||
{
|
||||
InitializeData ();
|
||||
}
|
||||
|
||||
public List<TodoItem> All {
|
||||
get { return todoItems; }
|
||||
}
|
||||
|
||||
public bool DoesItemExist (string id)
|
||||
{
|
||||
return todoItems.Any (item => item.ID == id);
|
||||
}
|
||||
|
||||
public TodoItem Find (string id)
|
||||
{
|
||||
return todoItems.FirstOrDefault (item => item.ID == id);
|
||||
}
|
||||
|
||||
public void Insert (TodoItem item)
|
||||
{
|
||||
todoItems.Add (item);
|
||||
}
|
||||
|
||||
public void Update (TodoItem item)
|
||||
{
|
||||
var todoItem = Find (item.ID);
|
||||
var index = todoItems.IndexOf (todoItem);
|
||||
todoItems.RemoveAt (index);
|
||||
todoItems.Insert (index, item);
|
||||
}
|
||||
|
||||
public void Delete (string id)
|
||||
{
|
||||
todoItems.Remove (Find (id));
|
||||
}
|
||||
|
||||
void InitializeData ()
|
||||
{
|
||||
todoItems = new List<TodoItem> ();
|
||||
|
||||
var todoItem1 = new TodoItem {
|
||||
ID = "6bb8a868-dba1-4f1a-93b7-24ebce87e243",
|
||||
Name = "Learn app development",
|
||||
Notes = "Attend Xamarin University",
|
||||
Done = true
|
||||
};
|
||||
|
||||
var todoItem2 = new TodoItem {
|
||||
ID = "b94afb54-a1cb-4313-8af3-b7511551b33b",
|
||||
Name = "Develop apps",
|
||||
Notes = "Use Xamarin Studio/Visual Studio",
|
||||
Done = false
|
||||
};
|
||||
|
||||
var todoItem3 = new TodoItem {
|
||||
ID = "ecfa6f80-3671-4911-aabe-63cc442c1ecf",
|
||||
Name = "Publish apps",
|
||||
Notes = "All app stores",
|
||||
Done = false,
|
||||
};
|
||||
|
||||
todoItems.Add (todoItem1);
|
||||
todoItems.Add (todoItem2);
|
||||
todoItems.Add (todoItem3);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
namespace NSUserActivitySearch
|
||||
{
|
||||
public interface ITextToSpeech
|
||||
{
|
||||
void Speak (string text);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
namespace NSUserActivitySearch
|
||||
{
|
||||
public interface IUserActivity
|
||||
{
|
||||
void Start (TodoItem item);
|
||||
|
||||
void Stop ();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
namespace NSUserActivitySearch
|
||||
{
|
||||
public class TodoItem
|
||||
{
|
||||
public string ID { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Notes { get; set; }
|
||||
|
||||
public bool Done { get; set; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<ProjectGuid>{4864CFE3-E78F-4ABA-AB11-950EF1A5B994}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>NSUserActivitySearch</RootNamespace>
|
||||
<AssemblyName>NSUserActivitySearch</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<TargetFrameworkProfile>Profile78</TargetFrameworkProfile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="App.cs" />
|
||||
<Compile Include="Models\TodoItem.cs" />
|
||||
<Compile Include="Data\TodoItemManager.cs" />
|
||||
<Compile Include="ITextToSpeech.cs" />
|
||||
<Compile Include="Views\TodoListPage.xaml.cs">
|
||||
<DependentUpon>TodoListPage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\TodoItemPage.xaml.cs">
|
||||
<DependentUpon>TodoItemPage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="IUserActivity.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
|
||||
<Import Project="..\packages\Xamarin.Forms.2.0.0.6487\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets" Condition="Exists('..\packages\Xamarin.Forms.2.0.0.6487\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets')" />
|
||||
<ItemGroup>
|
||||
<Folder Include="Data\" />
|
||||
<Folder Include="Models\" />
|
||||
<Folder Include="Views\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Views\TodoListPage.xaml">
|
||||
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Views\TodoItemPage.xaml">
|
||||
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Xamarin.Forms.Core">
|
||||
<HintPath>..\packages\Xamarin.Forms.2.0.0.6487\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Xamarin.Forms.Xaml">
|
||||
<HintPath>..\packages\Xamarin.Forms.2.0.0.6487\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.Xaml.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Xamarin.Forms.Platform">
|
||||
<HintPath>..\packages\Xamarin.Forms.2.0.0.6487\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.Platform.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -0,0 +1,27 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
// Information about this assembly is defined by the following attributes.
|
||||
// Change them to the values specific to your project.
|
||||
|
||||
[assembly: AssemblyTitle ("NSUserActivitySearch")]
|
||||
[assembly: AssemblyDescription ("")]
|
||||
[assembly: AssemblyConfiguration ("")]
|
||||
[assembly: AssemblyCompany ("")]
|
||||
[assembly: AssemblyProduct ("")]
|
||||
[assembly: AssemblyCopyright ("Xamarin")]
|
||||
[assembly: AssemblyTrademark ("")]
|
||||
[assembly: AssemblyCulture ("")]
|
||||
|
||||
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
|
||||
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
|
||||
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
|
||||
|
||||
[assembly: AssemblyVersion ("1.0.*")]
|
||||
|
||||
// The following attributes are used to specify the signing key for the assembly,
|
||||
// if desired. See the Mono documentation for more information about signing.
|
||||
|
||||
//[assembly: AssemblyDelaySign(false)]
|
||||
//[assembly: AssemblyKeyFile("")]
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="NSUserActivitySearch.TodoItemPage" Title="Todo Item">
|
||||
<ContentPage.Content>
|
||||
<StackLayout VerticalOptions="StartAndExpand">
|
||||
<Label Text="Name" />
|
||||
<Entry Text="{Binding Path=Name}" Placeholder="task name" />
|
||||
<Label Text="Notes" />
|
||||
<Entry Text="{Binding Path=Notes}" />
|
||||
<Label Text="Done" />
|
||||
<Switch IsToggled="{Binding Path=Done}" />
|
||||
<Button Text="Save" Clicked="OnSaveActivated" />
|
||||
<Button Text="Delete" Clicked="OnDeleteActivated" />
|
||||
<Button Text="Cancel" Clicked="OnCancelActivated" />
|
||||
<Button Text="Speak" Clicked="OnSpeakActivated" />
|
||||
</StackLayout>
|
||||
</ContentPage.Content>
|
||||
</ContentPage>
|
|
@ -0,0 +1,70 @@
|
|||
using System;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace NSUserActivitySearch
|
||||
{
|
||||
public partial class TodoItemPage : ContentPage
|
||||
{
|
||||
IUserActivity userActivity;
|
||||
bool isNewItem;
|
||||
|
||||
public TodoItemPage (bool isNew = false)
|
||||
{
|
||||
InitializeComponent ();
|
||||
isNewItem = isNew;
|
||||
|
||||
if (Device.OS == TargetPlatform.iOS) {
|
||||
userActivity = DependencyService.Get<IUserActivity> ();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnAppearing ()
|
||||
{
|
||||
base.OnAppearing ();
|
||||
|
||||
if (Device.OS == TargetPlatform.iOS) {
|
||||
var todoItem = (TodoItem)BindingContext;
|
||||
userActivity.Start (todoItem);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnDisappearing ()
|
||||
{
|
||||
if (Device.OS == TargetPlatform.iOS) {
|
||||
userActivity.Stop ();
|
||||
}
|
||||
|
||||
base.OnDisappearing ();
|
||||
}
|
||||
|
||||
async void OnSaveActivated (object sender, EventArgs e)
|
||||
{
|
||||
var todoItem = (TodoItem)BindingContext;
|
||||
if (isNewItem) {
|
||||
App.TodoManager.Insert (todoItem);
|
||||
} else {
|
||||
App.TodoManager.Update (todoItem);
|
||||
}
|
||||
await Navigation.PopAsync ();
|
||||
}
|
||||
|
||||
async void OnDeleteActivated (object sender, EventArgs e)
|
||||
{
|
||||
var todoItem = (TodoItem)BindingContext;
|
||||
App.TodoManager.Delete (todoItem.ID);
|
||||
await Navigation.PopAsync ();
|
||||
}
|
||||
|
||||
async void OnCancelActivated (object sender, EventArgs e)
|
||||
{
|
||||
await Navigation.PopAsync ();
|
||||
}
|
||||
|
||||
void OnSpeakActivated (object sender, EventArgs e)
|
||||
{
|
||||
var todoItem = (TodoItem)BindingContext;
|
||||
App.Speech.Speak (todoItem.Name + " " + todoItem.Notes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="NSUserActivitySearch.TodoListPage" Title="NSUserActivitySearch">
|
||||
<ContentPage.ToolbarItems>
|
||||
<ToolbarItem Name="+" Activated="OnAddItemActivated" />
|
||||
</ContentPage.ToolbarItems>
|
||||
<ContentPage.Content>
|
||||
<ListView x:Name="listView" ItemSelected="OnItemSelected">
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<ViewCell>
|
||||
<StackLayout Padding="20,0,0,0" HorizontalOptions="StartAndExpand" Orientation="Horizontal">
|
||||
<Label Text="{Binding Name}" YAlign="Center" />
|
||||
<Image Source="check.png" IsVisible="{Binding Done}" />
|
||||
</StackLayout>
|
||||
</ViewCell>
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>
|
||||
</ContentPage.Content>
|
||||
</ContentPage>
|
|
@ -0,0 +1,44 @@
|
|||
using System;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace NSUserActivitySearch
|
||||
{
|
||||
public partial class TodoListPage : ContentPage
|
||||
{
|
||||
public TodoListPage ()
|
||||
{
|
||||
InitializeComponent ();
|
||||
}
|
||||
|
||||
protected override void OnAppearing ()
|
||||
{
|
||||
base.OnAppearing ();
|
||||
listView.ItemsSource = App.TodoManager.All;
|
||||
}
|
||||
|
||||
protected override void OnDisappearing ()
|
||||
{
|
||||
base.OnDisappearing ();
|
||||
listView.ItemsSource = null;
|
||||
}
|
||||
|
||||
async void OnAddItemActivated (object sender, EventArgs e)
|
||||
{
|
||||
var todoItem = new TodoItem () {
|
||||
ID = Guid.NewGuid ().ToString ()
|
||||
};
|
||||
var todoPage = new TodoItemPage (true);
|
||||
todoPage.BindingContext = todoItem;
|
||||
await Navigation.PushAsync (todoPage);
|
||||
}
|
||||
|
||||
async void OnItemSelected (object sender, SelectedItemChangedEventArgs e)
|
||||
{
|
||||
var todoItem = e.SelectedItem as TodoItem;
|
||||
var todoPage = new TodoItemPage ();
|
||||
todoPage.BindingContext = todoItem;
|
||||
await Navigation.PushAsync (todoPage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Xamarin.Forms" version="2.0.0.6487" targetFramework="portable-net45+win+wp80+MonoTouch10+MonoAndroid10+xamarinmac20+xamarinios10" />
|
||||
</packages>
|
|
@ -0,0 +1,3 @@
|
|||
This recipe shows how to use the iOS 9 `NSUserActivity` class to make Xamarin.Forms app content searchable through Spotlight search.
|
||||
|
||||
The full recipe can be found [here](http://developer.xamarin.com/recipes/cross-platform/xamarin-forms/nsuseractivity-search/).
|
|
@ -0,0 +1,39 @@
|
|||
using Foundation;
|
||||
using UIKit;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace NSUserActivitySearch.iOS
|
||||
{
|
||||
[Register ("AppDelegate")]
|
||||
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
|
||||
{
|
||||
public static AppDelegate Current { get; private set; }
|
||||
|
||||
public UIWindow window;
|
||||
|
||||
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
|
||||
{
|
||||
global::Xamarin.Forms.Forms.Init ();
|
||||
|
||||
Current = this;
|
||||
window = new UIWindow (UIScreen.MainScreen.Bounds);
|
||||
|
||||
App.Speech = new Speech ();
|
||||
LoadApplication (new App ());
|
||||
|
||||
return base.FinishedLaunching (app, options);
|
||||
}
|
||||
|
||||
public override bool ContinueUserActivity (UIApplication application, NSUserActivity userActivity, UIApplicationRestorationHandler completionHandler)
|
||||
{
|
||||
if (userActivity.ActivityType == ActivityTypes.View) {
|
||||
string id = userActivity.UserInfo.ObjectForKey (new NSString ("Id")).ToString ();
|
||||
if (!string.IsNullOrWhiteSpace (id)) {
|
||||
MessagingCenter.Send<NSUserActivitySearch.App, string> (Xamarin.Forms.Application.Current as NSUserActivitySearch.App, "ShowItem", id);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
</dict>
|
||||
</plist>
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDisplayName</key>
|
||||
<string>NSUserActivitySearch</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.companyname.nsuseractivitysearch</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.0</string>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>MinimumOSVersion</key>
|
||||
<string>9.0</string>
|
||||
<key>UIDeviceFamily</key>
|
||||
<array>
|
||||
<integer>1</integer>
|
||||
<integer>2</integer>
|
||||
</array>
|
||||
<key>UILaunchStoryboardName</key>
|
||||
<string>LaunchScreen</string>
|
||||
<key>UIRequiredDeviceCapabilities</key>
|
||||
<array>
|
||||
<string>armv7</string>
|
||||
</array>
|
||||
<key>UISupportedInterfaceOrientations</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
<key>UISupportedInterfaceOrientations~ipad</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
<string>UIInterfaceOrientationPortraitUpsideDown</string>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
<key>XSAppIconAssets</key>
|
||||
<string>Resources/Images.xcassets/AppIcons.appiconset</string>
|
||||
<key>NSUserActivityTypes</key>
|
||||
<array>
|
||||
<string>com.companyname.nsuseractivitysearch.activity.view</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
|
@ -0,0 +1,21 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using Foundation;
|
||||
using UIKit;
|
||||
|
||||
namespace NSUserActivitySearch.iOS
|
||||
{
|
||||
public class Application
|
||||
{
|
||||
// This is the main entry point of the application.
|
||||
static void Main (string[] args)
|
||||
{
|
||||
// if you want to use a different Application Delegate class from "AppDelegate"
|
||||
// you can specify it here.
|
||||
UIApplication.Main (args, null, "AppDelegate");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,125 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">iPhoneSimulator</Platform>
|
||||
<ProjectTypeGuids>{FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<ProjectGuid>{AD6C4F19-6352-4050-B460-61B594F199C2}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>NSUserActivitySearch.iOS</RootNamespace>
|
||||
<IPhoneResourcePrefix>Resources</IPhoneResourcePrefix>
|
||||
<AssemblyName>NSUserActivitySearch.iOS</AssemblyName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\iPhoneSimulator\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG;ENABLE_TEST_CLOUD;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
<MtouchArch>i386</MtouchArch>
|
||||
<MtouchLink>None</MtouchLink>
|
||||
<MtouchUseRefCounting>true</MtouchUseRefCounting>
|
||||
<MtouchUseSGen>true</MtouchUseSGen>
|
||||
<MtouchFastDev>true</MtouchFastDev>
|
||||
<MtouchDebug>true</MtouchDebug>
|
||||
<CodesignKey>iPhone Developer: david.britch@xamarin.com (EGJ7LLZP37)</CodesignKey>
|
||||
<MtouchProfiling>true</MtouchProfiling>
|
||||
<CodesignProvision>7d62b38e-5db1-4382-815e-1c207da3a2a8</CodesignProvision>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' ">
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\iPhone\Release</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
<MtouchArch>ARMv7, ARM64</MtouchArch>
|
||||
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
|
||||
<MtouchFloat32>true</MtouchFloat32>
|
||||
<MtouchUseSGen>true</MtouchUseSGen>
|
||||
<CodesignKey>iPhone Developer</CodesignKey>
|
||||
<MtouchUseRefCounting>true</MtouchUseRefCounting>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhoneSimulator' ">
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\iPhoneSimulator\Release</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
<MtouchArch>i386</MtouchArch>
|
||||
<MtouchLink>None</MtouchLink>
|
||||
<MtouchUseRefCounting>true</MtouchUseRefCounting>
|
||||
<CodesignKey>iPhone Developer</CodesignKey>
|
||||
<MtouchUseSGen>true</MtouchUseSGen>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhone' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\iPhone\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG;ENABLE_TEST_CLOUD;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
<MtouchArch>ARMv7, ARM64</MtouchArch>
|
||||
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
|
||||
<MtouchFloat32>true</MtouchFloat32>
|
||||
<CodesignKey>iPhone Developer</CodesignKey>
|
||||
<DeviceSpecificBuild>true</DeviceSpecificBuild>
|
||||
<MtouchDebug>true</MtouchDebug>
|
||||
<MtouchUseSGen>true</MtouchUseSGen>
|
||||
<MtouchUseRefCounting>true</MtouchUseRefCounting>
|
||||
<MtouchProfiling>true</MtouchProfiling>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="Xamarin.iOS" />
|
||||
<Reference Include="Xamarin.Forms.Platform.iOS">
|
||||
<HintPath>..\packages\Xamarin.Forms.2.0.0.6487\lib\Xamarin.iOS10\Xamarin.Forms.Platform.iOS.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Xamarin.Forms.Core">
|
||||
<HintPath>..\packages\Xamarin.Forms.2.0.0.6487\lib\Xamarin.iOS10\Xamarin.Forms.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Xamarin.Forms.Xaml">
|
||||
<HintPath>..\packages\Xamarin.Forms.2.0.0.6487\lib\Xamarin.iOS10\Xamarin.Forms.Xaml.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Xamarin.Forms.Platform">
|
||||
<HintPath>..\packages\Xamarin.Forms.2.0.0.6487\lib\Xamarin.iOS10\Xamarin.Forms.Platform.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\NSUserActivitySearch\NSUserActivitySearch.csproj">
|
||||
<Project>{4864CFE3-E78F-4ABA-AB11-950EF1A5B994}</Project>
|
||||
<Name>NSUserActivitySearch</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ImageAsset Include="Resources\Images.xcassets\AppIcons.appiconset\Contents.json" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<InterfaceDefinition Include="Resources\LaunchScreen.xib" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Info.plist" />
|
||||
<None Include="Entitlements.plist" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Main.cs" />
|
||||
<Compile Include="AppDelegate.cs" />
|
||||
<Compile Include="Speech.cs" />
|
||||
<Compile Include="UserActivity.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
|
||||
<Import Project="..\packages\Xamarin.Forms.2.0.0.6487\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets" Condition="Exists('..\packages\Xamarin.Forms.2.0.0.6487\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets')" />
|
||||
<ItemGroup>
|
||||
<BundleResource Include="Resources\check.png" />
|
||||
<BundleResource Include="Resources\check%402x.png" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -0,0 +1,108 @@
|
|||
{
|
||||
"images": [
|
||||
{
|
||||
"size": "29x29",
|
||||
"scale": "1x",
|
||||
"idiom": "iphone"
|
||||
},
|
||||
{
|
||||
"size": "29x29",
|
||||
"scale": "2x",
|
||||
"idiom": "iphone"
|
||||
},
|
||||
{
|
||||
"size": "29x29",
|
||||
"scale": "3x",
|
||||
"idiom": "iphone"
|
||||
},
|
||||
{
|
||||
"size": "40x40",
|
||||
"scale": "2x",
|
||||
"idiom": "iphone"
|
||||
},
|
||||
{
|
||||
"size": "40x40",
|
||||
"scale": "3x",
|
||||
"idiom": "iphone"
|
||||
},
|
||||
{
|
||||
"size": "57x57",
|
||||
"scale": "1x",
|
||||
"idiom": "iphone"
|
||||
},
|
||||
{
|
||||
"size": "57x57",
|
||||
"scale": "2x",
|
||||
"idiom": "iphone"
|
||||
},
|
||||
{
|
||||
"size": "60x60",
|
||||
"scale": "2x",
|
||||
"idiom": "iphone"
|
||||
},
|
||||
{
|
||||
"size": "60x60",
|
||||
"scale": "3x",
|
||||
"idiom": "iphone"
|
||||
},
|
||||
{
|
||||
"size": "29x29",
|
||||
"scale": "1x",
|
||||
"idiom": "ipad"
|
||||
},
|
||||
{
|
||||
"size": "29x29",
|
||||
"scale": "2x",
|
||||
"idiom": "ipad"
|
||||
},
|
||||
{
|
||||
"size": "40x40",
|
||||
"scale": "1x",
|
||||
"idiom": "ipad"
|
||||
},
|
||||
{
|
||||
"size": "40x40",
|
||||
"scale": "2x",
|
||||
"idiom": "ipad"
|
||||
},
|
||||
{
|
||||
"size": "50x50",
|
||||
"scale": "1x",
|
||||
"idiom": "ipad"
|
||||
},
|
||||
{
|
||||
"size": "50x50",
|
||||
"scale": "2x",
|
||||
"idiom": "ipad"
|
||||
},
|
||||
{
|
||||
"size": "72x72",
|
||||
"scale": "1x",
|
||||
"idiom": "ipad"
|
||||
},
|
||||
{
|
||||
"size": "72x72",
|
||||
"scale": "2x",
|
||||
"idiom": "ipad"
|
||||
},
|
||||
{
|
||||
"size": "76x76",
|
||||
"scale": "1x",
|
||||
"idiom": "ipad"
|
||||
},
|
||||
{
|
||||
"size": "76x76",
|
||||
"scale": "2x",
|
||||
"idiom": "ipad"
|
||||
},
|
||||
{
|
||||
"size": "120x120",
|
||||
"scale": "1x",
|
||||
"idiom": "car"
|
||||
}
|
||||
],
|
||||
"info": {
|
||||
"version": 1,
|
||||
"author": "xcode"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6214" systemVersion="14A314h" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
|
||||
<dependencies>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6207"/>
|
||||
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
|
||||
<view contentMode="scaleToFill" id="iN0-l3-epB">
|
||||
<rect key="frame" x="0.0" y="0.0" width="480" height="480"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" Copyright (c) 2015 Xamarin" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="8ie-xW-0ye" misplaced="YES">
|
||||
<rect key="frame" x="20" y="439" width="441" height="21"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
||||
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="NSUserActivitySearch.iOS" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="kId-c2-rCX" misplaced="YES">
|
||||
<rect key="frame" x="20" y="140" width="441" height="43"/>
|
||||
<fontDescription key="fontDescription" type="boldSystem" pointSize="36"/>
|
||||
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
|
||||
<constraints>
|
||||
<constraint firstItem="kId-c2-rCX" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="bottom" multiplier="1/3" constant="1" id="5cJ-9S-tgC"/>
|
||||
<constraint firstAttribute="centerX" secondItem="kId-c2-rCX" secondAttribute="centerX" id="Koa-jz-hwk"/>
|
||||
<constraint firstAttribute="bottom" secondItem="8ie-xW-0ye" secondAttribute="bottom" constant="20" id="Kzo-t9-V3l"/>
|
||||
<constraint firstItem="8ie-xW-0ye" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="20" symbolic="YES" id="MfP-vx-nX0"/>
|
||||
<constraint firstAttribute="centerX" secondItem="8ie-xW-0ye" secondAttribute="centerX" id="ZEH-qu-HZ9"/>
|
||||
<constraint firstItem="kId-c2-rCX" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="20" symbolic="YES" id="fvb-Df-36g"/>
|
||||
</constraints>
|
||||
<nil key="simulatedStatusBarMetrics"/>
|
||||
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
|
||||
<point key="canvasLocation" x="548" y="455"/>
|
||||
</view>
|
||||
</objects>
|
||||
</document>
|
Двоичные данные
cross-platform/xamarin-forms/iOS/NSUserActivitySearch/iOS/Resources/check.png
Normal file
Двоичные данные
cross-platform/xamarin-forms/iOS/NSUserActivitySearch/iOS/Resources/check.png
Normal file
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 292 B |
Двоичные данные
cross-platform/xamarin-forms/iOS/NSUserActivitySearch/iOS/Resources/check@2x.png
Normal file
Двоичные данные
cross-platform/xamarin-forms/iOS/NSUserActivitySearch/iOS/Resources/check@2x.png
Normal file
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 459 B |
|
@ -0,0 +1,29 @@
|
|||
using AVFoundation;
|
||||
|
||||
namespace NSUserActivitySearch.iOS
|
||||
{
|
||||
public class Speech : ITextToSpeech
|
||||
{
|
||||
float volume = 0.5f;
|
||||
float pitch = 1.0f;
|
||||
|
||||
/// <summary>
|
||||
/// Speak example from:
|
||||
/// http://blog.xamarin.com/make-your-ios-7-app-speak/
|
||||
/// </summary>
|
||||
public void Speak (string text)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace (text)) {
|
||||
var speechSynthesizer = new AVSpeechSynthesizer ();
|
||||
var speechUtterance = new AVSpeechUtterance (text) {
|
||||
Rate = AVSpeechUtterance.MaximumSpeechRate / 2,
|
||||
Voice = AVSpeechSynthesisVoice.FromLanguage ("en-US"),
|
||||
Volume = volume,
|
||||
PitchMultiplier = pitch
|
||||
};
|
||||
|
||||
speechSynthesizer.SpeakUtterance (speechUtterance);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
using CoreSpotlight;
|
||||
using Foundation;
|
||||
using NSUserActivitySearch.iOS;
|
||||
using Xamarin.Forms;
|
||||
|
||||
[assembly:Dependency (typeof(UserActivity))]
|
||||
namespace NSUserActivitySearch.iOS
|
||||
{
|
||||
public static class ActivityTypes
|
||||
{
|
||||
public const string View = "com.companyname.nsuseractivitysearch.activity.view";
|
||||
}
|
||||
|
||||
public class UserActivity : IUserActivity
|
||||
{
|
||||
|
||||
public void Start (TodoItem item)
|
||||
{
|
||||
var window = NSUserActivitySearch.iOS.AppDelegate.Current.window;
|
||||
window.UserActivity = CreateActivity (item);
|
||||
|
||||
// Force the UserInfo to be preserved for AppDelegate.ContinueUserActivity
|
||||
// https://forums.developer.apple.com/thread/9690
|
||||
window.UpdateUserActivityState (CreateActivity (item));
|
||||
}
|
||||
|
||||
public void Stop ()
|
||||
{
|
||||
var window = NSUserActivitySearch.iOS.AppDelegate.Current.window;
|
||||
window.UserActivity.ResignCurrent ();
|
||||
}
|
||||
|
||||
NSUserActivity CreateActivity (TodoItem item)
|
||||
{
|
||||
// Create app search activity
|
||||
var activity = new NSUserActivity (ActivityTypes.View);
|
||||
|
||||
// Populate activity
|
||||
activity.Title = item.Name;
|
||||
|
||||
// Add additional data
|
||||
var attributes = new CSSearchableItemAttributeSet ();
|
||||
attributes.DisplayName = item.Name;
|
||||
attributes.ContentDescription = item.Notes;
|
||||
|
||||
activity.ContentAttributeSet = attributes;
|
||||
activity.AddUserInfoEntries (NSDictionary.FromObjectAndKey (new NSString (item.ID), new NSString ("Id")));
|
||||
|
||||
// Add app search ability
|
||||
activity.EligibleForSearch = true;
|
||||
activity.BecomeCurrent (); // Don't forget to ResignCurrent() later
|
||||
|
||||
return activity;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Xamarin.Forms" version="2.0.0.6487" targetFramework="xamarinios10" />
|
||||
</packages>
|
Загрузка…
Ссылка в новой задаче