Skip to content

Development #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 20, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Demo/Demo.Droid/Demo.Droid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@
<HintPath>..\..\packages\Xamarin.Android.Support.v7.AppCompat.22.2.0.0\lib\MonoAndroid403\Xamarin.Android.Support.v7.AppCompat.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Xamarin.Android.Support.v7.CardView, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Xamarin.Android.Support.v7.CardView.22.2.0.0\lib\MonoAndroid403\Xamarin.Android.Support.v7.CardView.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Xamarin.Forms.Core, Version=1.4.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\packages\Xamarin.Forms.1.4.2.6359\lib\MonoAndroid10\Xamarin.Forms.Core.dll</HintPath>
</Reference>
Expand Down
3,058 changes: 1,600 additions & 1,458 deletions src/Demo/Demo.Droid/Resources/Resource.Designer.cs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/Demo/Demo.Droid/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
<package id="Xamarin.Android.Support.Design" version="22.2.0.0" targetFramework="MonoAndroid50" />
<package id="Xamarin.Android.Support.v4" version="22.2.0.0" targetFramework="MonoAndroid50" />
<package id="Xamarin.Android.Support.v7.AppCompat" version="22.2.0.0" targetFramework="MonoAndroid50" />
<package id="Xamarin.Android.Support.v7.CardView" version="22.2.0.0" targetFramework="MonoAndroid50" />
<package id="Xamarin.Forms" version="1.4.2.6359" targetFramework="MonoAndroid23" />
</packages>
43 changes: 35 additions & 8 deletions src/Demo/Demo/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,64 @@ public partial class App : Application
public App()
{
this.InitializeComponent();
this.MainPage = CreateMainPage();
ShowChooser();
}

internal static MasterDetailPage MasterDetail { get; private set; }

internal static INavigation Navigation { get; private set; }

private static Page CreateMainPage()
public static void ShowChooser()
{
Current.MainPage = new ChooserView();
}

public static void ShowMasterDetailPatternOne()
{
var master = CreateMasterDetailPage(new MenuView(), new MainView());
var navigation = CreateNavigationPage(master);
Current.MainPage = CreateNavigationPage(master);
}

return navigation;
public static void ShowMasterDetailPatternTwo()
{
var master = CreateMasterDetailPage(new MenuView(), CreateNavigationPage(new MainView()));
Current.MainPage = master;
}

private static MasterDetailPage CreateMasterDetailPage(Page master, Page detail)
{
return MasterDetail = new MasterDetailPage { Detail = detail, Master = master, MasterBehavior = MasterBehavior.Popover, Title = "AppCompat Demo" };
return MasterDetail = new MasterDetailPage { Detail = detail, Master = master, MasterBehavior = GetMasterBehavior(), Title = "AppCompat Demo" };
}

private static NavigationPage CreateNavigationPage(Page page)
{
var navigation = new NavigationPage(page);

navigation.Popped += (sender, args) => MasterDetail.IsPresented = false;
navigation.PoppedToRoot += (sender, args) => MasterDetail.IsPresented = false;
navigation.Pushed += (sender, args) => MasterDetail.IsPresented = false;
navigation.Popped += (sender, args) => HideMenu();
navigation.PoppedToRoot += (sender, args) => HideMenu();
navigation.Pushed += (sender, args) => HideMenu();

Navigation = navigation.Navigation;

return navigation;
}

private static MasterBehavior GetMasterBehavior()
{
if (Device.Idiom == TargetIdiom.Phone)
{
return MasterBehavior.Popover;
}

return MasterBehavior.SplitOnLandscape;
}

private static void HideMenu()
{
if (MasterDetail.MasterBehavior == MasterBehavior.Popover)
{
MasterDetail.IsPresented = false;
}
}
}
}
10 changes: 10 additions & 0 deletions src/Demo/Demo/Demo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
</Compile>
<Compile Include="ViewModels\ChooserViewModel.cs" />
<Compile Include="ViewModels\LoremIpsumViewModel.cs" />
<Compile Include="Views\ChooserView.xaml.cs">
<DependentUpon>ChooserView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\LoremIpsumView.xaml.cs">
<DependentUpon>LoremIpsumView.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -108,6 +112,12 @@
<ItemGroup>
<EmbeddedResource Include="Resources\loremipsum.txt" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Views\ChooserView.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<Import Project="..\..\packages\Xamarin.Forms.1.4.2.6359\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets" Condition="Exists('..\..\packages\Xamarin.Forms.1.4.2.6359\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
Expand Down
19 changes: 19 additions & 0 deletions src/Demo/Demo/ViewModels/ChooserViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace Demo.ViewModels
{
using System.Windows.Input;

using Xamarin.Forms;

public class ChooserViewModel : ViewModel
{
public ChooserViewModel()
{
this.MasterDetailPatternOneCommand = new Command(App.ShowMasterDetailPatternOne);
this.MasterDetailPatternTwoCommand = new Command(App.ShowMasterDetailPatternTwo);
}

public ICommand MasterDetailPatternOneCommand { get; private set; }

public ICommand MasterDetailPatternTwoCommand { get; private set; }
}
}
2 changes: 1 addition & 1 deletion src/Demo/Demo/ViewModels/MenuViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class MenuViewModel : ViewModel
{
public MenuViewModel()
{
this.HomeCommand = new Command(async () => await App.Navigation.PopToRootAsync());
this.HomeCommand = new Command(App.ShowChooser);
this.HomeText = "Home";

this.LoremIpsumCommand = new Command(async () => await App.Navigation.PushAsync(new LoremIpsumView()));
Expand Down
11 changes: 11 additions & 0 deletions src/Demo/Demo/Views/ChooserView.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:controls="clr-namespace:NativeCode.Mobile.AppCompat.Controls;assembly=NativeCode.Mobile.AppCompat.Controls"
x:Class="Demo.Views.ChooserView">
<controls:NavigationLayout>
<controls:NavigationLayout.Children>
<controls:NavigationLayoutMenu Command="{Binding MasterDetailPatternOneCommand}" Text="Master Detail Pattern One" />
<controls:NavigationLayoutMenu Command="{Binding MasterDetailPatternTwoCommand}" Text="Master Detail Pattern Two" />
</controls:NavigationLayout.Children>
</controls:NavigationLayout>
</ContentPage>
15 changes: 15 additions & 0 deletions src/Demo/Demo/Views/ChooserView.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Demo.Views
{
using Demo.ViewModels;

using Xamarin.Forms;

public partial class ChooserView : ContentPage
{
public ChooserView()
{
this.InitializeComponent();
this.BindingContext = new ChooserViewModel();
}
}
}
44 changes: 31 additions & 13 deletions src/Demo/Demo/Views/MainView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,36 @@
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:controls="clr-namespace:NativeCode.Mobile.AppCompat.Controls;assembly=NativeCode.Mobile.AppCompat.Controls"
x:Class="Demo.Views.MainView" IsBusy="{Binding IsBusy}" Title="{Binding Title}">
<StackLayout Padding="20">
<Button Command="{Binding ShowSnackBar}" Text="Hit me!" />
<StackLayout Orientation="Horizontal">
<Label Text="Switch On/Off" />
<Switch />
<ScrollView>
<StackLayout Padding="20">
<controls:Card Padding="40" Radius="20">
<controls:Card.Content>
<StackLayout>
<Button Command="{Binding ShowSnackBar}" Text="Hit me!" />
<StackLayout Orientation="Horizontal">
<Label Text="Switch On/Off" />
<Switch />
</StackLayout>
<StackLayout Orientation="Horizontal">
<Label Text="Entry Field" />
<Entry HorizontalOptions="FillAndExpand" />
</StackLayout>
</StackLayout>
</controls:Card.Content>
</controls:Card>
<controls:Card>
<controls:Card.Content>
<StackLayout Orientation="Horizontal">
<controls:FloatingButton ButtonSize="Mini" Color="Green" Command="{Binding FloatingButtonCommand}" Icon="launcher" />
<controls:FloatingButton ButtonSize="Normal" Color="Green" Command="{Binding FloatingButtonCommand}" Icon="launcher" />
</StackLayout>
</controls:Card.Content>
</controls:Card>
<controls:Card Command="{Binding ShowSnackBar}">
<controls:Card.Content>
<Label Text="Clickable CardView" />
</controls:Card.Content>
</controls:Card>
</StackLayout>
<StackLayout Orientation="Horizontal">
<Label Text="Entry Field" />
<Entry HorizontalOptions="FillAndExpand" />
</StackLayout>
<RelativeLayout Padding="10" HorizontalOptions="Center" VerticalOptions="Center">
<controls:FloatingButton ButtonSize="Mini" Color="Green" Command="{Binding FloatingButtonCommand}" Icon="launcher" />
</RelativeLayout>
</StackLayout>
</ScrollView>
</ContentPage>
46 changes: 46 additions & 0 deletions src/NativeCode.Mobile.AppCompat.Controls/Card.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
namespace NativeCode.Mobile.AppCompat.Controls
{
using System.Windows.Input;

using Xamarin.Forms;

public class Card : ContentView, ICommandProvider
{
public static readonly BindableProperty CommandProperty = BindableProperty.Create<FloatingButton, ICommand>(x => x.Command, default(ICommand));

public static readonly BindableProperty CommandParameterProperty = BindableProperty.Create<FloatingButton, object>(
x => x.CommandParameter,
default(object));

public static readonly BindableProperty RadiusProperty = BindableProperty.Create<Card, double>(x => x.Radius, 20.0d);

public Card()
{
this.Padding = new Thickness(20);
}

/// <summary>
/// Gets or sets the command.
/// </summary>
public ICommand Command
{
get { return (ICommand)this.GetValue(CommandProperty); }
set { this.SetValue(CommandProperty, value); }
}

/// <summary>
/// Gets or sets the command parameter.
/// </summary>
public object CommandParameter
{
get { return this.GetValue(CommandParameterProperty); }
set { this.SetValue(CommandParameterProperty, value); }
}

public double Radius
{
get { return (double)this.GetValue(RadiusProperty); }
set { this.SetValue(RadiusProperty, value); }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Compile Include="Card.cs" />
<Compile Include="FloatingButton.cs" />
<Compile Include="FloatingButtonSize.cs" />
<Compile Include="ICommandProvider.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace NativeCode.Mobile.AppCompat.Renderers.Extensions
using System;
using System.Reflection;

using NativeCode.Mobile.AppCompat.Renderers.Helpers;
using NativeCode.Mobile.AppCompat.Helpers;

using Xamarin.Forms;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace NativeCode.Mobile.AppCompat.Renderers.Extensions
{
using System.Reflection;

using NativeCode.Mobile.AppCompat.Renderers.Helpers;
using NativeCode.Mobile.AppCompat.Helpers;

using Xamarin.Forms;

Expand Down
25 changes: 19 additions & 6 deletions src/NativeCode.Mobile.AppCompat.Renderers/FormsAppCompat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ namespace NativeCode.Mobile.AppCompat.Renderers
using System;
using System.Reflection;

using NativeCode.Mobile.AppCompat.Controls;
using NativeCode.Mobile.AppCompat.Helpers;
using NativeCode.Mobile.AppCompat.Renderers.Renderers;

using Xamarin.Forms;
Expand All @@ -24,32 +26,43 @@ public static class FormsAppCompat
static FormsAppCompat()
{
var type = Type.GetType(RegistrarType, true);
var property = type.GetProperty("Registered", BindingFlags.NonPublic | BindingFlags.Static);
var property = type.GetProperty("Registered", ReflectionHelper.NonPublicStatic);
RegistrarInstance = property.GetValue(null);
RegisterMethod = property.PropertyType.GetMethod("Register", BindingFlags.Instance | BindingFlags.Public);
RegisterMethod = property.PropertyType.GetMethod("Register", ReflectionHelper.InstancePublic);
}

/// <summary>
/// Enables registration of all renderers.
/// </summary>
public static void EnableAll()
{
EnableAppCompatReplacements();
EnableAndroidRenderers();
EnableAppCompatRenderers();
EnableMasterDetailRenderer();
}

/// <summary>
/// Enables registration of $AppCompat$ renderers.
/// Enables Android-specific renderers.
/// </summary>
public static void EnableAppCompatReplacements()
public static void EnableAndroidRenderers()
{
RegisterType(typeof(Card), typeof(CardRenderer));
RegisterType(typeof(FloatingButton), typeof(FloatingButtonRenderer));
RegisterType(typeof(NavigationLayout), typeof(NavigationLayoutRenderer));
}

/// <summary>
/// Enables compatibility renderers.
/// </summary>
public static void EnableAppCompatRenderers()
{
RegisterType(typeof(Button), typeof(AppCompatButtonRenderer));
RegisterType(typeof(Entry), typeof(AppCompatEntryRenderer));
RegisterType(typeof(Switch), typeof(AppCompatSwitchRenderer));
}

/// <summary>
/// Enables registration of the <see cref="AppCompatMasterDetailRenderer"/>.
/// Enables the <see cref="AppCompatMasterDetailRenderer"/>.
/// </summary>
public static void EnableMasterDetailRenderer()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
<HintPath>..\packages\Xamarin.Android.Support.v7.AppCompat.22.2.0.0\lib\MonoAndroid403\Xamarin.Android.Support.v7.AppCompat.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Xamarin.Android.Support.v7.CardView, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Xamarin.Android.Support.v7.CardView.22.2.0.0\lib\MonoAndroid403\Xamarin.Android.Support.v7.CardView.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Xamarin.Forms.Core, Version=1.4.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Xamarin.Forms.1.4.2.6359\lib\MonoAndroid10\Xamarin.Forms.Core.dll</HintPath>
<Private>True</Private>
Expand All @@ -79,13 +83,12 @@
<Compile Include="Extensions\CommandExtensions.cs" />
<Compile Include="Extensions\ElementExtensions.cs" />
<Compile Include="Extensions\EntryExtensions.cs" />
<Compile Include="Helpers\KeyboardHelper.cs" />
<Compile Include="Helpers\ReflectionHelper.cs" />
<Compile Include="Platforms\UserNotifier.cs" />
<Compile Include="Renderers\AppCompatButtonRenderer.cs" />
<Compile Include="Renderers\AppCompatEntryRenderer.cs" />
<Compile Include="Renderers\AppCompatMasterDetailRenderer.cs" />
<Compile Include="Renderers\AppCompatSwitchRenderer.cs" />
<Compile Include="Renderers\CardRenderer.cs" />
<Compile Include="Renderers\Controls\AppCompatEntryEditText.cs" />
<Compile Include="FormsAppCompat.cs" />
<Compile Include="Renderers\FloatingButtonRenderer.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ namespace NativeCode.Mobile.AppCompat.Renderers.Renderers
using Java.Lang;

using NativeCode.Mobile.AppCompat.Extensions;
using NativeCode.Mobile.AppCompat.Helpers;
using NativeCode.Mobile.AppCompat.Renderers.Extensions;
using NativeCode.Mobile.AppCompat.Renderers.Helpers;
using NativeCode.Mobile.AppCompat.Renderers.Renderers.Controls;

using Xamarin.Forms;
Expand Down
Loading