Skip to content

Commit 0e6b008

Browse files
committed
Merge pull request #18 from nativecode-dev/development
Development
2 parents 261f2c6 + 6f2917d commit 0e6b008

32 files changed

+3644
-3010
lines changed

src/Demo/Demo.Droid/Demo.Droid.csproj

+4
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@
7070
<HintPath>..\..\packages\Xamarin.Android.Support.v7.AppCompat.22.2.0.0\lib\MonoAndroid403\Xamarin.Android.Support.v7.AppCompat.dll</HintPath>
7171
<Private>True</Private>
7272
</Reference>
73+
<Reference Include="Xamarin.Android.Support.v7.CardView, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
74+
<HintPath>..\..\packages\Xamarin.Android.Support.v7.CardView.22.2.0.0\lib\MonoAndroid403\Xamarin.Android.Support.v7.CardView.dll</HintPath>
75+
<Private>True</Private>
76+
</Reference>
7377
<Reference Include="Xamarin.Forms.Core, Version=1.4.0.0, Culture=neutral, PublicKeyToken=null">
7478
<HintPath>..\..\packages\Xamarin.Forms.1.4.2.6359\lib\MonoAndroid10\Xamarin.Forms.Core.dll</HintPath>
7579
</Reference>

src/Demo/Demo.Droid/Resources/Resource.Designer.cs

+1,600-1,458
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Demo/Demo.Droid/packages.config

+1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
<package id="Xamarin.Android.Support.Design" version="22.2.0.0" targetFramework="MonoAndroid50" />
55
<package id="Xamarin.Android.Support.v4" version="22.2.0.0" targetFramework="MonoAndroid50" />
66
<package id="Xamarin.Android.Support.v7.AppCompat" version="22.2.0.0" targetFramework="MonoAndroid50" />
7+
<package id="Xamarin.Android.Support.v7.CardView" version="22.2.0.0" targetFramework="MonoAndroid50" />
78
<package id="Xamarin.Forms" version="1.4.2.6359" targetFramework="MonoAndroid23" />
89
</packages>

src/Demo/Demo/App.xaml.cs

+35-8
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,64 @@ public partial class App : Application
99
public App()
1010
{
1111
this.InitializeComponent();
12-
this.MainPage = CreateMainPage();
12+
ShowChooser();
1313
}
1414

1515
internal static MasterDetailPage MasterDetail { get; private set; }
1616

1717
internal static INavigation Navigation { get; private set; }
1818

19-
private static Page CreateMainPage()
19+
public static void ShowChooser()
20+
{
21+
Current.MainPage = new ChooserView();
22+
}
23+
24+
public static void ShowMasterDetailPatternOne()
2025
{
2126
var master = CreateMasterDetailPage(new MenuView(), new MainView());
22-
var navigation = CreateNavigationPage(master);
27+
Current.MainPage = CreateNavigationPage(master);
28+
}
2329

24-
return navigation;
30+
public static void ShowMasterDetailPatternTwo()
31+
{
32+
var master = CreateMasterDetailPage(new MenuView(), CreateNavigationPage(new MainView()));
33+
Current.MainPage = master;
2534
}
2635

2736
private static MasterDetailPage CreateMasterDetailPage(Page master, Page detail)
2837
{
29-
return MasterDetail = new MasterDetailPage { Detail = detail, Master = master, MasterBehavior = MasterBehavior.Popover, Title = "AppCompat Demo" };
38+
return MasterDetail = new MasterDetailPage { Detail = detail, Master = master, MasterBehavior = GetMasterBehavior(), Title = "AppCompat Demo" };
3039
}
3140

3241
private static NavigationPage CreateNavigationPage(Page page)
3342
{
3443
var navigation = new NavigationPage(page);
3544

36-
navigation.Popped += (sender, args) => MasterDetail.IsPresented = false;
37-
navigation.PoppedToRoot += (sender, args) => MasterDetail.IsPresented = false;
38-
navigation.Pushed += (sender, args) => MasterDetail.IsPresented = false;
45+
navigation.Popped += (sender, args) => HideMenu();
46+
navigation.PoppedToRoot += (sender, args) => HideMenu();
47+
navigation.Pushed += (sender, args) => HideMenu();
3948

4049
Navigation = navigation.Navigation;
4150

4251
return navigation;
4352
}
53+
54+
private static MasterBehavior GetMasterBehavior()
55+
{
56+
if (Device.Idiom == TargetIdiom.Phone)
57+
{
58+
return MasterBehavior.Popover;
59+
}
60+
61+
return MasterBehavior.SplitOnLandscape;
62+
}
63+
64+
private static void HideMenu()
65+
{
66+
if (MasterDetail.MasterBehavior == MasterBehavior.Popover)
67+
{
68+
MasterDetail.IsPresented = false;
69+
}
70+
}
4471
}
4572
}

src/Demo/Demo/Demo.csproj

+10
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@
4545
<Compile Include="App.xaml.cs">
4646
<DependentUpon>App.xaml</DependentUpon>
4747
</Compile>
48+
<Compile Include="ViewModels\ChooserViewModel.cs" />
4849
<Compile Include="ViewModels\LoremIpsumViewModel.cs" />
50+
<Compile Include="Views\ChooserView.xaml.cs">
51+
<DependentUpon>ChooserView.xaml</DependentUpon>
52+
</Compile>
4953
<Compile Include="Views\LoremIpsumView.xaml.cs">
5054
<DependentUpon>LoremIpsumView.xaml</DependentUpon>
5155
</Compile>
@@ -108,6 +112,12 @@
108112
<ItemGroup>
109113
<EmbeddedResource Include="Resources\loremipsum.txt" />
110114
</ItemGroup>
115+
<ItemGroup>
116+
<EmbeddedResource Include="Views\ChooserView.xaml">
117+
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
118+
<SubType>Designer</SubType>
119+
</EmbeddedResource>
120+
</ItemGroup>
111121
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
112122
<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')" />
113123
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace Demo.ViewModels
2+
{
3+
using System.Windows.Input;
4+
5+
using Xamarin.Forms;
6+
7+
public class ChooserViewModel : ViewModel
8+
{
9+
public ChooserViewModel()
10+
{
11+
this.MasterDetailPatternOneCommand = new Command(App.ShowMasterDetailPatternOne);
12+
this.MasterDetailPatternTwoCommand = new Command(App.ShowMasterDetailPatternTwo);
13+
}
14+
15+
public ICommand MasterDetailPatternOneCommand { get; private set; }
16+
17+
public ICommand MasterDetailPatternTwoCommand { get; private set; }
18+
}
19+
}

src/Demo/Demo/ViewModels/MenuViewModel.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class MenuViewModel : ViewModel
1212
{
1313
public MenuViewModel()
1414
{
15-
this.HomeCommand = new Command(async () => await App.Navigation.PopToRootAsync());
15+
this.HomeCommand = new Command(App.ShowChooser);
1616
this.HomeText = "Home";
1717

1818
this.LoremIpsumCommand = new Command(async () => await App.Navigation.PushAsync(new LoremIpsumView()));

src/Demo/Demo/Views/ChooserView.xaml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
3+
xmlns:controls="clr-namespace:NativeCode.Mobile.AppCompat.Controls;assembly=NativeCode.Mobile.AppCompat.Controls"
4+
x:Class="Demo.Views.ChooserView">
5+
<controls:NavigationLayout>
6+
<controls:NavigationLayout.Children>
7+
<controls:NavigationLayoutMenu Command="{Binding MasterDetailPatternOneCommand}" Text="Master Detail Pattern One" />
8+
<controls:NavigationLayoutMenu Command="{Binding MasterDetailPatternTwoCommand}" Text="Master Detail Pattern Two" />
9+
</controls:NavigationLayout.Children>
10+
</controls:NavigationLayout>
11+
</ContentPage>
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace Demo.Views
2+
{
3+
using Demo.ViewModels;
4+
5+
using Xamarin.Forms;
6+
7+
public partial class ChooserView : ContentPage
8+
{
9+
public ChooserView()
10+
{
11+
this.InitializeComponent();
12+
this.BindingContext = new ChooserViewModel();
13+
}
14+
}
15+
}

src/Demo/Demo/Views/MainView.xaml

+31-13
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,36 @@
33
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
44
xmlns:controls="clr-namespace:NativeCode.Mobile.AppCompat.Controls;assembly=NativeCode.Mobile.AppCompat.Controls"
55
x:Class="Demo.Views.MainView" IsBusy="{Binding IsBusy}" Title="{Binding Title}">
6-
<StackLayout Padding="20">
7-
<Button Command="{Binding ShowSnackBar}" Text="Hit me!" />
8-
<StackLayout Orientation="Horizontal">
9-
<Label Text="Switch On/Off" />
10-
<Switch />
6+
<ScrollView>
7+
<StackLayout Padding="20">
8+
<controls:Card Padding="40" Radius="20">
9+
<controls:Card.Content>
10+
<StackLayout>
11+
<Button Command="{Binding ShowSnackBar}" Text="Hit me!" />
12+
<StackLayout Orientation="Horizontal">
13+
<Label Text="Switch On/Off" />
14+
<Switch />
15+
</StackLayout>
16+
<StackLayout Orientation="Horizontal">
17+
<Label Text="Entry Field" />
18+
<Entry HorizontalOptions="FillAndExpand" />
19+
</StackLayout>
20+
</StackLayout>
21+
</controls:Card.Content>
22+
</controls:Card>
23+
<controls:Card>
24+
<controls:Card.Content>
25+
<StackLayout Orientation="Horizontal">
26+
<controls:FloatingButton ButtonSize="Mini" Color="Green" Command="{Binding FloatingButtonCommand}" Icon="launcher" />
27+
<controls:FloatingButton ButtonSize="Normal" Color="Green" Command="{Binding FloatingButtonCommand}" Icon="launcher" />
28+
</StackLayout>
29+
</controls:Card.Content>
30+
</controls:Card>
31+
<controls:Card Command="{Binding ShowSnackBar}">
32+
<controls:Card.Content>
33+
<Label Text="Clickable CardView" />
34+
</controls:Card.Content>
35+
</controls:Card>
1136
</StackLayout>
12-
<StackLayout Orientation="Horizontal">
13-
<Label Text="Entry Field" />
14-
<Entry HorizontalOptions="FillAndExpand" />
15-
</StackLayout>
16-
<RelativeLayout Padding="10" HorizontalOptions="Center" VerticalOptions="Center">
17-
<controls:FloatingButton ButtonSize="Mini" Color="Green" Command="{Binding FloatingButtonCommand}" Icon="launcher" />
18-
</RelativeLayout>
19-
</StackLayout>
37+
</ScrollView>
2038
</ContentPage>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
namespace NativeCode.Mobile.AppCompat.Controls
2+
{
3+
using System.Windows.Input;
4+
5+
using Xamarin.Forms;
6+
7+
public class Card : ContentView, ICommandProvider
8+
{
9+
public static readonly BindableProperty CommandProperty = BindableProperty.Create<FloatingButton, ICommand>(x => x.Command, default(ICommand));
10+
11+
public static readonly BindableProperty CommandParameterProperty = BindableProperty.Create<FloatingButton, object>(
12+
x => x.CommandParameter,
13+
default(object));
14+
15+
public static readonly BindableProperty RadiusProperty = BindableProperty.Create<Card, double>(x => x.Radius, 20.0d);
16+
17+
public Card()
18+
{
19+
this.Padding = new Thickness(20);
20+
}
21+
22+
/// <summary>
23+
/// Gets or sets the command.
24+
/// </summary>
25+
public ICommand Command
26+
{
27+
get { return (ICommand)this.GetValue(CommandProperty); }
28+
set { this.SetValue(CommandProperty, value); }
29+
}
30+
31+
/// <summary>
32+
/// Gets or sets the command parameter.
33+
/// </summary>
34+
public object CommandParameter
35+
{
36+
get { return this.GetValue(CommandParameterProperty); }
37+
set { this.SetValue(CommandParameterProperty, value); }
38+
}
39+
40+
public double Radius
41+
{
42+
get { return (double)this.GetValue(RadiusProperty); }
43+
set { this.SetValue(RadiusProperty, value); }
44+
}
45+
}
46+
}

src/NativeCode.Mobile.AppCompat.Controls/NativeCode.Mobile.AppCompat.Controls.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
<WarningLevel>4</WarningLevel>
3636
</PropertyGroup>
3737
<ItemGroup>
38+
<Compile Include="Card.cs" />
3839
<Compile Include="FloatingButton.cs" />
3940
<Compile Include="FloatingButtonSize.cs" />
4041
<Compile Include="ICommandProvider.cs" />

src/NativeCode.Mobile.AppCompat.Renderers/Extensions/ElementExtensions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ namespace NativeCode.Mobile.AppCompat.Renderers.Extensions
33
using System;
44
using System.Reflection;
55

6-
using NativeCode.Mobile.AppCompat.Renderers.Helpers;
6+
using NativeCode.Mobile.AppCompat.Helpers;
77

88
using Xamarin.Forms;
99

src/NativeCode.Mobile.AppCompat.Renderers/Extensions/EntryExtensions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ namespace NativeCode.Mobile.AppCompat.Renderers.Extensions
22
{
33
using System.Reflection;
44

5-
using NativeCode.Mobile.AppCompat.Renderers.Helpers;
5+
using NativeCode.Mobile.AppCompat.Helpers;
66

77
using Xamarin.Forms;
88

src/NativeCode.Mobile.AppCompat.Renderers/FormsAppCompat.cs

+19-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ namespace NativeCode.Mobile.AppCompat.Renderers
33
using System;
44
using System.Reflection;
55

6+
using NativeCode.Mobile.AppCompat.Controls;
7+
using NativeCode.Mobile.AppCompat.Helpers;
68
using NativeCode.Mobile.AppCompat.Renderers.Renderers;
79

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

3234
/// <summary>
3335
/// Enables registration of all renderers.
3436
/// </summary>
3537
public static void EnableAll()
3638
{
37-
EnableAppCompatReplacements();
39+
EnableAndroidRenderers();
40+
EnableAppCompatRenderers();
3841
EnableMasterDetailRenderer();
3942
}
4043

4144
/// <summary>
42-
/// Enables registration of $AppCompat$ renderers.
45+
/// Enables Android-specific renderers.
4346
/// </summary>
44-
public static void EnableAppCompatReplacements()
47+
public static void EnableAndroidRenderers()
48+
{
49+
RegisterType(typeof(Card), typeof(CardRenderer));
50+
RegisterType(typeof(FloatingButton), typeof(FloatingButtonRenderer));
51+
RegisterType(typeof(NavigationLayout), typeof(NavigationLayoutRenderer));
52+
}
53+
54+
/// <summary>
55+
/// Enables compatibility renderers.
56+
/// </summary>
57+
public static void EnableAppCompatRenderers()
4558
{
4659
RegisterType(typeof(Button), typeof(AppCompatButtonRenderer));
4760
RegisterType(typeof(Entry), typeof(AppCompatEntryRenderer));
4861
RegisterType(typeof(Switch), typeof(AppCompatSwitchRenderer));
4962
}
5063

5164
/// <summary>
52-
/// Enables registration of the <see cref="AppCompatMasterDetailRenderer"/>.
65+
/// Enables the <see cref="AppCompatMasterDetailRenderer"/>.
5366
/// </summary>
5467
public static void EnableMasterDetailRenderer()
5568
{

src/NativeCode.Mobile.AppCompat.Renderers/NativeCode.Mobile.AppCompat.Renderers.csproj

+5-2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@
5858
<HintPath>..\packages\Xamarin.Android.Support.v7.AppCompat.22.2.0.0\lib\MonoAndroid403\Xamarin.Android.Support.v7.AppCompat.dll</HintPath>
5959
<Private>True</Private>
6060
</Reference>
61+
<Reference Include="Xamarin.Android.Support.v7.CardView, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
62+
<HintPath>..\packages\Xamarin.Android.Support.v7.CardView.22.2.0.0\lib\MonoAndroid403\Xamarin.Android.Support.v7.CardView.dll</HintPath>
63+
<Private>True</Private>
64+
</Reference>
6165
<Reference Include="Xamarin.Forms.Core, Version=1.4.0.0, Culture=neutral, processorArchitecture=MSIL">
6266
<HintPath>..\packages\Xamarin.Forms.1.4.2.6359\lib\MonoAndroid10\Xamarin.Forms.Core.dll</HintPath>
6367
<Private>True</Private>
@@ -79,13 +83,12 @@
7983
<Compile Include="Extensions\CommandExtensions.cs" />
8084
<Compile Include="Extensions\ElementExtensions.cs" />
8185
<Compile Include="Extensions\EntryExtensions.cs" />
82-
<Compile Include="Helpers\KeyboardHelper.cs" />
83-
<Compile Include="Helpers\ReflectionHelper.cs" />
8486
<Compile Include="Platforms\UserNotifier.cs" />
8587
<Compile Include="Renderers\AppCompatButtonRenderer.cs" />
8688
<Compile Include="Renderers\AppCompatEntryRenderer.cs" />
8789
<Compile Include="Renderers\AppCompatMasterDetailRenderer.cs" />
8890
<Compile Include="Renderers\AppCompatSwitchRenderer.cs" />
91+
<Compile Include="Renderers\CardRenderer.cs" />
8992
<Compile Include="Renderers\Controls\AppCompatEntryEditText.cs" />
9093
<Compile Include="FormsAppCompat.cs" />
9194
<Compile Include="Renderers\FloatingButtonRenderer.cs" />

src/NativeCode.Mobile.AppCompat.Renderers/Renderers/AppCompatEntryRenderer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ namespace NativeCode.Mobile.AppCompat.Renderers.Renderers
1111
using Java.Lang;
1212

1313
using NativeCode.Mobile.AppCompat.Extensions;
14+
using NativeCode.Mobile.AppCompat.Helpers;
1415
using NativeCode.Mobile.AppCompat.Renderers.Extensions;
15-
using NativeCode.Mobile.AppCompat.Renderers.Helpers;
1616
using NativeCode.Mobile.AppCompat.Renderers.Renderers.Controls;
1717

1818
using Xamarin.Forms;

0 commit comments

Comments
 (0)