diff options
author | Jason Smith <jason.smith@xamarin.com> | 2016-04-24 12:25:26 -0400 |
---|---|---|
committer | Rui Marinho <me@ruimarinho.net> | 2016-04-24 12:25:26 -0400 |
commit | 5907152c50ee2c658b266f2804e6b383bb15a6f1 (patch) | |
tree | 9beb907623359723456c5c03b08922bebc4f41f3 /Xamarin.Forms.Platform.Android.AppLinks | |
parent | feac1ba3ed6df5e27b3fa2076bd15c190cbacd1c (diff) | |
download | xamarin-forms-5907152c50ee2c658b266f2804e6b383bb15a6f1.tar.gz xamarin-forms-5907152c50ee2c658b266f2804e6b383bb15a6f1.tar.bz2 xamarin-forms-5907152c50ee2c658b266f2804e6b383bb15a6f1.zip |
Evolve feature branch (#117)
* Initial import of evolve features
* [Android] Add Xamarin.Forms.Platform.Android.AppLinks project
* [iOS] Fix issues with c# 6 features on iOS AppLinks
* Added naive stanza to update-docs-windows.bat to produce Pages docs. Not tested. (#69)
* Update packages
* Add AppLinks android nuspec and fix linker issues
* Fix build
* Fix nusepc
* Fix nuspec
* Update android support nugets to 23.2.1
* Update Xamarin.UITest
* Add CardView
* [iOS] Fix app link for CoreSpotlight
* [Android] Update AppLinks android support libs
* Add Newtonsoft.Json dependency to nuspec
* Fix NRE when setting ControlTemplate to null
* Move to ModernHttpClient for download
* Try fix build
* Preserve android app links
* Fix margin issue
* General coding and simple fixes
Diffstat (limited to 'Xamarin.Forms.Platform.Android.AppLinks')
6 files changed, 272 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.Android.AppLinks/AndroidAppLinks.cs b/Xamarin.Forms.Platform.Android.AppLinks/AndroidAppLinks.cs new file mode 100644 index 00000000..b1639da7 --- /dev/null +++ b/Xamarin.Forms.Platform.Android.AppLinks/AndroidAppLinks.cs @@ -0,0 +1,115 @@ +using System; +using System.Threading.Tasks; +using Android.Content; +using Android.Gms.AppIndexing; +using Android.Gms.Common.Apis; +using Android.Runtime; +using IndexingAction = Android.Gms.AppIndexing.Action; +using Android.App; + +namespace Xamarin.Forms.Platform.Android.AppLinks +{ + [Preserve(AllMembers = true)] + public class AndroidAppLinks : IAppLinks, IDisposable + { + readonly GoogleApiClient _client; + + bool _disposed; + + public static bool IsInitialized { get; private set; } + + public static Context Context { get; private set; } + + public static void Init(Activity activity) + { + if (IsInitialized) + return; + IsInitialized = true; + + Context = activity; + } + + public AndroidAppLinks(Context context) + { + _client = new GoogleApiClient.Builder(context).AddApi(AppIndex.API).Build(); + _client.Connect(); + } + + public void DeregisterLink(IAppLinkEntry appLink) + { + RemoveFromIndexItemAsync(appLink.AppLinkUri.ToString()); + } + + public void DeregisterLink(Uri appLinkUri) + { + RemoveFromIndexItemAsync(appLinkUri.ToString()); + } + + public async void RegisterLink(IAppLinkEntry appLink) + { + await IndexItemAsync(appLink); + } + + public void Dispose() + { + Dispose(true); + } + + protected virtual void Dispose(bool isDisposing) + { + if (isDisposing && !_disposed) + { + _disposed = true; + _client.Disconnect(); + _client.Dispose(); + } + } + + static IndexingAction BuildIndexAction(IAppLinkEntry appLink) + { + Thing item = new Thing.Builder().SetName(appLink.Title).SetDescription(appLink.Description).SetUrl(global::Android.Net.Uri.Parse(appLink.AppLinkUri.AbsoluteUri)).Build(); + Thing thing = new IndexingAction.Builder(IndexingAction.TypeView).SetObject(item).SetActionStatus(IndexingAction.StatusTypeCompleted).Build(); + var indexAction = thing.JavaCast<IndexingAction>(); + return indexAction; + } + + async Task IndexItemAsync(IAppLinkEntry appLink) + { + IndexingAction indexAction = BuildIndexAction(appLink); + + if (_client.IsConnected && appLink.IsLinkActive) + { + Statuses resultStart = await AppIndex.AppIndexApi.StartAsync(_client, indexAction); + if (resultStart.IsSuccess) + { + var aL = appLink as AppLinkEntry; + if (aL != null) + { + aL.PropertyChanged += async (sender, e) => + { + if (e.PropertyName == AppLinkEntry.IsLinkActiveProperty.PropertyName) + { + if (appLink.IsLinkActive) + { + Statuses resultStartAgain = await AppIndex.AppIndexApi.StartAsync(_client, indexAction); + } + else + { + Statuses resultEnd = await AppIndex.AppIndexApi.EndAsync(_client, indexAction); + } + } + }; + } + } + } + } + + void RemoveFromIndexItemAsync(string identifier) + { + if (_client.IsConnected) + { + } + } + } +} + diff --git a/Xamarin.Forms.Platform.Android.AppLinks/Properties/AssemblyInfo.cs b/Xamarin.Forms.Platform.Android.AppLinks/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..330d609a --- /dev/null +++ b/Xamarin.Forms.Platform.Android.AppLinks/Properties/AssemblyInfo.cs @@ -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("Xamarin.Forms.Platform.Android.AppLinks")] +[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.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("")] + diff --git a/Xamarin.Forms.Platform.Android.AppLinks/Resources/AboutResources.txt b/Xamarin.Forms.Platform.Android.AppLinks/Resources/AboutResources.txt new file mode 100644 index 00000000..10f52d46 --- /dev/null +++ b/Xamarin.Forms.Platform.Android.AppLinks/Resources/AboutResources.txt @@ -0,0 +1,44 @@ +Images, layout descriptions, binary blobs and string dictionaries can be included +in your application as resource files. Various Android APIs are designed to +operate on the resource IDs instead of dealing with images, strings or binary blobs +directly. + +For example, a sample Android app that contains a user interface layout (main.axml), +an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png) +would keep its resources in the "Resources" directory of the application: + +Resources/ + drawable/ + icon.png + + layout/ + main.axml + + values/ + strings.xml + +In order to get the build system to recognize Android resources, set the build action to +"AndroidResource". The native Android APIs do not operate directly with filenames, but +instead operate on resource IDs. When you compile an Android application that uses resources, +the build system will package the resources for distribution and generate a class called "R" +(this is an Android convention) that contains the tokens for each one of the resources +included. For example, for the above Resources layout, this is what the R class would expose: + +public class R { + public class drawable { + public const int icon = 0x123; + } + + public class layout { + public const int main = 0x456; + } + + public class strings { + public const int first_string = 0xabc; + public const int second_string = 0xbcd; + } +} + +You would then use R.drawable.icon to reference the drawable/icon.png file, or R.layout.main +to reference the layout/main.axml file, or R.strings.first_string to reference the first +string in the dictionary file values/strings.xml. diff --git a/Xamarin.Forms.Platform.Android.AppLinks/Resources/values/Strings.xml b/Xamarin.Forms.Platform.Android.AppLinks/Resources/values/Strings.xml new file mode 100644 index 00000000..08334fa4 --- /dev/null +++ b/Xamarin.Forms.Platform.Android.AppLinks/Resources/values/Strings.xml @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <string name="library_name">Xamarin.Forms.Platform.Android.AppLinks</string> +</resources> diff --git a/Xamarin.Forms.Platform.Android.AppLinks/Xamarin.Forms.Platform.Android.AppLinks.csproj b/Xamarin.Forms.Platform.Android.AppLinks/Xamarin.Forms.Platform.Android.AppLinks.csproj new file mode 100644 index 00000000..08864b51 --- /dev/null +++ b/Xamarin.Forms.Platform.Android.AppLinks/Xamarin.Forms.Platform.Android.AppLinks.csproj @@ -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>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> + <ProjectGuid>{42DB052E-0909-45D2-8240-187F99F393FB}</ProjectGuid> + <OutputType>Library</OutputType> + <RootNamespace>Xamarin.Forms.Platform.Android.AppLinks</RootNamespace> + <MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix> + <MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix> + <AndroidResgenClass>Resource</AndroidResgenClass> + <AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile> + <AndroidUseLatestPlatformSdk>True</AndroidUseLatestPlatformSdk> + <AssemblyName>Xamarin.Forms.Platform.Android.AppLinks</AssemblyName> + <TargetFrameworkVersion>v6.0</TargetFrameworkVersion> + </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> + <AndroidLinkMode>None</AndroidLinkMode> + <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> + <AndroidUseSharedRuntime>false</AndroidUseSharedRuntime> + <ConsolePause>false</ConsolePause> + </PropertyGroup> + <ItemGroup> + <Reference Include="System" /> + <Reference Include="System.Xml" /> + <Reference Include="System.Core" /> + <Reference Include="Mono.Android" /> + <Reference Include="Xamarin.GooglePlayServices.Basement"> + <HintPath>..\packages\Xamarin.GooglePlayServices.Basement.29.0.0.1\lib\MonoAndroid41\Xamarin.GooglePlayServices.Basement.dll</HintPath> + </Reference> + <Reference Include="Xamarin.GooglePlayServices.Base"> + <HintPath>..\packages\Xamarin.GooglePlayServices.Base.29.0.0.1\lib\MonoAndroid41\Xamarin.GooglePlayServices.Base.dll</HintPath> + </Reference> + <Reference Include="Xamarin.GooglePlayServices.AppIndexing"> + <HintPath>..\packages\Xamarin.GooglePlayServices.AppIndexing.29.0.0.1\lib\MonoAndroid41\Xamarin.GooglePlayServices.AppIndexing.dll</HintPath> + </Reference> + <Reference Include="Xamarin.Android.Support.v4"> + <HintPath>..\packages\Xamarin.Android.Support.v4.23.3.0\lib\MonoAndroid403\Xamarin.Android.Support.v4.dll</HintPath> + </Reference> + </ItemGroup> + <ItemGroup> + <Compile Include="Resources\Resource.designer.cs" /> + <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="AndroidAppLinks.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="Resources\AboutResources.txt" /> + <None Include="packages.config" /> + </ItemGroup> + <ItemGroup> + <AndroidResource Include="Resources\values\Strings.xml" /> + </ItemGroup> + <Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" /> + <ItemGroup> + <ProjectReference Include="..\Xamarin.Forms.Core\Xamarin.Forms.Core.csproj"> + <Project>{57B8B73D-C3B5-4C42-869E-7B2F17D354AC}</Project> + <Name>Xamarin.Forms.Core</Name> + </ProjectReference> + </ItemGroup> +</Project>
\ No newline at end of file diff --git a/Xamarin.Forms.Platform.Android.AppLinks/packages.config b/Xamarin.Forms.Platform.Android.AppLinks/packages.config new file mode 100644 index 00000000..b488c682 --- /dev/null +++ b/Xamarin.Forms.Platform.Android.AppLinks/packages.config @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="utf-8"?> +<packages> + <package id="Xamarin.Android.Support.v4" version="23.3.0" targetFramework="MonoAndroid60" /> + <package id="Xamarin.GooglePlayServices.AppIndexing" version="29.0.0.1" targetFramework="MonoAndroid60" /> + <package id="Xamarin.GooglePlayServices.Base" version="29.0.0.1" targetFramework="MonoAndroid60" /> + <package id="Xamarin.GooglePlayServices.Basement" version="29.0.0.1" targetFramework="MonoAndroid60" /> +</packages>
\ No newline at end of file |