Added navigation sample for Android

This commit is contained in:
Laurent Bugnion 2015-08-31 17:35:06 +02:00
Родитель ff853cf61d
Коммит 81cf21a3a4
23 изменённых файлов: 579 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,42 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NavigationDroid", "NavigationDroid\NavigationDroid.csproj", "{559F05DF-73E6-4D7A-A830-74F8BEE9780A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GalaSoft.MvvmLight (PCL)", "..\..\GalaSoft.MvvmLight\GalaSoft.MvvmLight (PCL)\GalaSoft.MvvmLight (PCL).csproj", "{6A912701-3BA1-4975-ADBF-160CAF66B640}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GalaSoft.MvvmLight.Extras (PCL)", "..\..\GalaSoft.MvvmLight\GalaSoft.MvvmLight.Extras (PCL)\GalaSoft.MvvmLight.Extras (PCL).csproj", "{39C71A69-4ACE-4B45-9A2C-C274FADA78EF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GalaSoft.MvvmLight.Platform (Android)", "..\..\GalaSoft.MvvmLight\GalaSoft.MvvmLight.Platform (Android)\GalaSoft.MvvmLight.Platform (Android).csproj", "{A5B7741D-E331-438C-B3BF-596B048DB622}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{559F05DF-73E6-4D7A-A830-74F8BEE9780A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{559F05DF-73E6-4D7A-A830-74F8BEE9780A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{559F05DF-73E6-4D7A-A830-74F8BEE9780A}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{559F05DF-73E6-4D7A-A830-74F8BEE9780A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{559F05DF-73E6-4D7A-A830-74F8BEE9780A}.Release|Any CPU.Build.0 = Release|Any CPU
{559F05DF-73E6-4D7A-A830-74F8BEE9780A}.Release|Any CPU.Deploy.0 = Release|Any CPU
{6A912701-3BA1-4975-ADBF-160CAF66B640}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6A912701-3BA1-4975-ADBF-160CAF66B640}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6A912701-3BA1-4975-ADBF-160CAF66B640}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6A912701-3BA1-4975-ADBF-160CAF66B640}.Release|Any CPU.Build.0 = Release|Any CPU
{39C71A69-4ACE-4B45-9A2C-C274FADA78EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{39C71A69-4ACE-4B45-9A2C-C274FADA78EF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{39C71A69-4ACE-4B45-9A2C-C274FADA78EF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{39C71A69-4ACE-4B45-9A2C-C274FADA78EF}.Release|Any CPU.Build.0 = Release|Any CPU
{A5B7741D-E331-438C-B3BF-596B048DB622}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A5B7741D-E331-438C-B3BF-596B048DB622}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A5B7741D-E331-438C-B3BF-596B048DB622}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A5B7741D-E331-438C-B3BF-596B048DB622}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

Просмотреть файл

@ -0,0 +1,19 @@
Any raw assets you want to be deployed with your application can be placed in
this directory (and child directories) and given a Build Action of "AndroidAsset".
These files will be deployed with you package and will be accessible using Android's
AssetManager, like this:
public class ReadAsset : Activity
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
InputStream input = Assets.Open ("my_asset.txt");
}
}
Additionally, some Android functions will automatically load asset files:
Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf");

Просмотреть файл

@ -0,0 +1,49 @@
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using GalaSoft.MvvmLight.Ioc;
using GalaSoft.MvvmLight.Views;
using Microsoft.Practices.ServiceLocation;
namespace NavigationDroid
{
[Activity(Label = "NavigationDroid", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : ActivityBase
{
public const string Page2Key = "Page2";
public const string Page3Key = "Page3";
private static bool _initialized;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
if (!_initialized)
{
_initialized = true;
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
var nav = new NavigationService();
nav.Configure(Page2Key, typeof(Page2Activity));
nav.Configure(Page3Key, typeof(Page3Activity));
SimpleIoc.Default.Register<INavigationService>(() => nav);
}
var button = FindViewById<Button>(Resource.Id.MyButton);
button.Click += (s, e) =>
{
var nav = ServiceLocator.Current.GetInstance<INavigationService>();
nav.NavigateTo(Page2Key);
};
}
}
}

Просмотреть файл

@ -0,0 +1,118 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{559F05DF-73E6-4D7A-A830-74F8BEE9780A}</ProjectGuid>
<ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>NavigationDroid</RootNamespace>
<AssemblyName>NavigationDroid</AssemblyName>
<FileAlignment>512</FileAlignment>
<AndroidApplication>true</AndroidApplication>
<AndroidResgenFile>Resources\Resource.Designer.cs</AndroidResgenFile>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<AndroidUseLatestPlatformSdk>
</AndroidUseLatestPlatformSdk>
<DevInstrumentationEnabled>True</DevInstrumentationEnabled>
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
<TargetFrameworkVersion>v4.4</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AndroidUseSharedRuntime>True</AndroidUseSharedRuntime>
<AndroidLinkMode>None</AndroidLinkMode>
<AndroidLinkSkip />
<EmbedAssembliesIntoApk>True</EmbedAssembliesIntoApk>
<BundleAssemblies>False</BundleAssemblies>
<AndroidCreatePackagePerAbi>False</AndroidCreatePackagePerAbi>
<AndroidSupportedAbis>armeabi,armeabi-v7a,x86</AndroidSupportedAbis>
<AndroidStoreUncompressedFileExtensions />
<MandroidI18n />
<JavaMaximumHeapSize />
<JavaOptions />
<MonoDroidExtraArgs />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AndroidUseSharedRuntime>False</AndroidUseSharedRuntime>
<AndroidLinkMode>SdkOnly</AndroidLinkMode>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Practices.ServiceLocation">
<HintPath>..\packages\CommonServiceLocator.1.3\lib\portable-net4+sl5+netcore45+wpa81+wp8\Microsoft.Practices.ServiceLocation.dll</HintPath>
</Reference>
<Reference Include="Mono.Android" />
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="MainActivity.cs" />
<Compile Include="Page2Activity.cs" />
<Compile Include="Page3Activity.cs" />
<Compile Include="Resources\Resource.Designer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="Resources\AboutResources.txt" />
<None Include="Assets\AboutAssets.txt" />
<AndroidResource Include="Resources\layout\Page2.axml">
<SubType>Designer</SubType>
</AndroidResource>
<AndroidResource Include="Resources\layout\Page3.axml">
<SubType>AndroidResource</SubType>
</AndroidResource>
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\layout\Main.axml" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\values\Strings.xml" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\drawable\Icon.png" />
</ItemGroup>
<ItemGroup>
<Content Include="Properties\AndroidManifest.xml" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\GalaSoft.MvvmLight\GalaSoft.MvvmLight %28PCL%29\GalaSoft.MvvmLight %28PCL%29.csproj">
<Project>{6a912701-3ba1-4975-adbf-160caf66b640}</Project>
<Name>GalaSoft.MvvmLight %28PCL%29</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\GalaSoft.MvvmLight\GalaSoft.MvvmLight.Extras %28PCL%29\GalaSoft.MvvmLight.Extras %28PCL%29.csproj">
<Project>{39c71a69-4ace-4b45-9a2c-c274fada78ef}</Project>
<Name>GalaSoft.MvvmLight.Extras %28PCL%29</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\GalaSoft.MvvmLight\GalaSoft.MvvmLight.Platform %28Android%29\GalaSoft.MvvmLight.Platform %28Android%29.csproj">
<Project>{a5b7741d-e331-438c-b3bf-596b048db622}</Project>
<Name>GalaSoft.MvvmLight.Platform %28Android%29</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

Просмотреть файл

@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using GalaSoft.MvvmLight.Views;
using Microsoft.Practices.ServiceLocation;
namespace NavigationDroid
{
[Activity(Label = "Page2")]
public class Page2Activity : ActivityBase
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Page2);
var button = FindViewById<Button>(Resource.Id.NavigateButton);
button.Click += (s, e) =>
{
var nav = ServiceLocator.Current.GetInstance<INavigationService>();
nav.NavigateTo(
MainActivity.Page3Key,
"Hello Xamarin " + DateTime.Now.ToString("HH:mm:ss"));
};
}
protected override void OnResume()
{
base.OnResume();
var nav = ServiceLocator.Current.GetInstance<INavigationService>();
Console.WriteLine("Current page key: " + nav.CurrentPageKey);
}
}
}

Просмотреть файл

@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using GalaSoft.MvvmLight.Views;
using Microsoft.Practices.ServiceLocation;
namespace NavigationDroid
{
[Activity(Label = "Page3")]
public class Page3Activity : ActivityBase
{
public NavigationService Nav
{
get
{
return (NavigationService)ServiceLocator.Current
.GetInstance<INavigationService>();
}
}
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Page3);
var button = FindViewById<Button>(Resource.Id.GoBackButton);
button.Click += (s, e) => Nav.GoBack();
var label = FindViewById<TextView>(Resource.Id.DisplayText);
var param = Nav.GetAndRemoveParameter<string>(Intent);
label.Text = param;
}
}
}

Просмотреть файл

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="NavigationDroid.NavigationDroid" android:versionCode="1" android:versionName="1.0">
<uses-sdk />
<application android:label="NavigationDroid" android:icon="@drawable/Icon"></application>
</manifest>

Просмотреть файл

@ -0,0 +1,30 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Android.App;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("NavigationDroid")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("NavigationDroid")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

Просмотреть файл

@ -0,0 +1,50 @@
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.xml),
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-hdpi/
icon.png
drawable-ldpi/
icon.png
drawable-mdpi/
icon.png
layout/
main.xml
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
"Resource" that contains the tokens for each one of the resources included. For example,
for the above Resources layout, this is what the Resource class would expose:
public class Resource {
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 Resource.layout.main
to reference the layout/main.xml file, or Resource.strings.first_string to reference the first
string in the dictionary file values/strings.xml.

129
Samples/Navigation/NavigationDroid/Resources/Resource.Designer.cs сгенерированный Normal file
Просмотреть файл

@ -0,0 +1,129 @@
#pragma warning disable 1591
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.0
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
[assembly: global::Android.Runtime.ResourceDesignerAttribute("NavigationDroid.Resource", IsApplication=true)]
namespace NavigationDroid
{
[System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "1.0.0.0")]
public partial class Resource
{
static Resource()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
public static void UpdateIdValues()
{
global::GalaSoft.MvvmLight.Resource.String.ApplicationName = global::NavigationDroid.Resource.String.ApplicationName;
global::GalaSoft.MvvmLight.Resource.String.Hello = global::NavigationDroid.Resource.String.Hello;
}
public partial class Attribute
{
static Attribute()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
private Attribute()
{
}
}
public partial class Drawable
{
// aapt resource value: 0x7f020000
public const int Icon = 2130837504;
static Drawable()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
private Drawable()
{
}
}
public partial class Id
{
// aapt resource value: 0x7f050003
public const int DisplayText = 2131034115;
// aapt resource value: 0x7f050002
public const int GoBackButton = 2131034114;
// aapt resource value: 0x7f050000
public const int MyButton = 2131034112;
// aapt resource value: 0x7f050001
public const int NavigateButton = 2131034113;
static Id()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
private Id()
{
}
}
public partial class Layout
{
// aapt resource value: 0x7f030000
public const int Main = 2130903040;
// aapt resource value: 0x7f030001
public const int Page2 = 2130903041;
// aapt resource value: 0x7f030002
public const int Page3 = 2130903042;
static Layout()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
private Layout()
{
}
}
public partial class String
{
// aapt resource value: 0x7f040001
public const int ApplicationName = 2130968577;
// aapt resource value: 0x7f040000
public const int Hello = 2130968576;
static String()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
private String()
{
}
}
}
}
#pragma warning restore 1591

Двоичные данные
Samples/Navigation/NavigationDroid/Resources/drawable/Icon.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 4.0 KiB

Просмотреть файл

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="@+id/MyButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Navigate to Page 2" />
</LinearLayout>

Просмотреть файл

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:minWidth="25px"
android:minHeight="25px">
<Button
android:text="Navigate to Page 3 with parameter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/NavigateButton" />
</LinearLayout>

Просмотреть файл

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:text="Go back to Page 2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/GoBackButton" />
<TextView
android:text="Nothing yet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/DisplayText"
android:gravity="center"
android:textSize="24dp" />
</LinearLayout>

Просмотреть файл

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="Hello">Hello World, Click Me!</string>
<string name="ApplicationName">NavigationDroid</string>
</resources>

Просмотреть файл

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="CommonServiceLocator" version="1.3" targetFramework="MonoAndroid44" />
<package id="MvvmLightLibs" version="5.1.1.0" targetFramework="MonoAndroid44" />
</packages>

Двоичный файл не отображается.

Двоичный файл не отображается.

Двоичный файл не отображается.

Двоичный файл не отображается.

Двоичный файл не отображается.

Двоичный файл не отображается.

Просмотреть файл

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<repositories>
<repository path="..\..\..\GalaSoft.MvvmLight\GalaSoft.MvvmLight.Extras (PCL)\packages.config" />
<repository path="..\NavigationDroid\packages.config" />
<repository path="..\NavigationIos\packages.config" />
<repository path="..\NavigationIosStoryboard\packages.config" />
</repositories>