Skip to content

Development #10

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 2 commits into from
Jun 19, 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
3 changes: 2 additions & 1 deletion src/Demo/Demo.Droid/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Android.OS;

using NativeCode.Mobile.AppCompat.FormsAppCompat;
using NativeCode.Mobile.AppCompat.Renderers;
using NativeCode.Mobile.AppCompat.Renderers.Renderers;

using Xamarin.Forms;
Expand All @@ -21,7 +22,7 @@ protected override void OnCreate(Bundle savedInstanceState)
base.OnCreate(savedInstanceState);

Forms.Init(this, savedInstanceState);
AppCompatRenderers.EnableAll();
FormsAppCompat.EnableAll();

this.LoadApplication(new App());
}
Expand Down
1,506 changes: 1,451 additions & 55 deletions src/Demo/Demo.Droid/Resources/Resource.Designer.cs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Demo/Demo/Views/MainView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<Label Text="Entry Field" />
<Entry HorizontalOptions="FillAndExpand" />
</StackLayout>
<RelativeLayout>
<RelativeLayout Padding="10" HorizontalOptions="Center" VerticalOptions="Center">
<controls:FloatingButton ButtonSize="Mini" Color="Green" Command="{Binding FloatingButtonCommand}" Icon="launcher" />
</RelativeLayout>
</StackLayout>
Expand Down
17 changes: 13 additions & 4 deletions src/Demo/Demo/Views/MenuView.xaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
<?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.MenuView" IsBusy="{Binding IsBusy}" Title="{Binding Title}">
<StackLayout>
<Button Command="{Binding HomeCommand}" Text="{Binding HomeText}" />
<Button Command="{Binding LoremIpsumCommand}" Text="{Binding LoremIpsumText}" />
</StackLayout>
<controls:NavigationLayout>
<controls:NavigationLayout.HeaderView>
<StackLayout>
<BoxView HeightRequest="150" BackgroundColor="Green" />
<Label Text="Header" />
</StackLayout>
</controls:NavigationLayout.HeaderView>
<controls:NavigationLayout.Children>
<controls:NavigationMenu Command="{Binding HomeCommand}" Text="{Binding HomeText}" />
<controls:NavigationMenu Command="{Binding LoremIpsumCommand}" Text="{Binding LoremIpsumText}" />
</controls:NavigationLayout.Children>
</controls:NavigationLayout>
</ContentPage>
2 changes: 1 addition & 1 deletion src/NativeCode.Mobile.AppCompat.Controls/FloatingButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/// <summary>
/// Provides a floating action button.
/// </summary>
public class FloatingButton : View
public class FloatingButton : View, ICommandProvider
{
public static readonly BindableProperty ButtonSizeProperty = BindableProperty.Create<FloatingButton, FloatingButtonSize>(
x => x.ButtonSize,
Expand Down
11 changes: 11 additions & 0 deletions src/NativeCode.Mobile.AppCompat.Controls/ICommandProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace NativeCode.Mobile.AppCompat.Controls
{
using System.Windows.Input;

public interface ICommandProvider
{
ICommand Command { get; }

object CommandParameter { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
<ItemGroup>
<Compile Include="FloatingButton.cs" />
<Compile Include="FloatingButtonSize.cs" />
<Compile Include="ICommandProvider.cs" />
<Compile Include="NavigationLayout.cs" />
<Compile Include="NavigationMenu.cs" />
<Compile Include="Platforms\IUserNotifier.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down
19 changes: 19 additions & 0 deletions src/NativeCode.Mobile.AppCompat.Controls/NavigationLayout.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace NativeCode.Mobile.AppCompat.Controls
{
using Xamarin.Forms;

public class NavigationLayout : Layout<NavigationMenu>
{
public static readonly BindableProperty HeaderViewProperty = BindableProperty.Create<NavigationLayout, View>(x => x.HeaderView, default(View));

public View HeaderView
{
get { return (View)this.GetValue(HeaderViewProperty); }
set { this.SetValue(HeaderViewProperty, value); }
}

protected override void LayoutChildren(double x, double y, double width, double height)
{
}
}
}
43 changes: 43 additions & 0 deletions src/NativeCode.Mobile.AppCompat.Controls/NavigationMenu.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
namespace NativeCode.Mobile.AppCompat.Controls
{
using System.Windows.Input;

using Xamarin.Forms;

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

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

public static readonly BindableProperty IconProperty = BindableProperty.Create<NavigationMenu, ImageSource>(x => x.Icon, default(ImageSource));

public static readonly BindableProperty TextProperty = BindableProperty.Create<NavigationMenu, string>(x => x.Text, default(string));

public ICommand Command
{
get { return (ICommand)this.GetValue(CommandProperty); }
set { this.SetValue(CommandProperty, value); }
}

public object CommandParameter
{
get { return this.GetValue(CommandParameterProperty); }
set { this.SetValue(CommandParameterProperty, value); }
}

public ImageSource Icon
{
get { return (ImageSource)this.GetValue(IconProperty); }
set { this.SetValue(IconProperty, value); }
}

public string Text
{
get { return (string)this.GetValue(TextProperty); }
set { this.SetValue(TextProperty, value); }
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace NativeCode.Mobile.AppCompat.Renderers.Extensions
{
using NativeCode.Mobile.AppCompat.Controls;

public static class CommandExtensions
{
public static void ExecuteCommand(this ICommandProvider provider)
{
var command = provider.Command;
var parameter = provider.CommandParameter;

if (command != null && command.CanExecute(parameter))
{
command.Execute(parameter);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
namespace NativeCode.Mobile.AppCompat.Renderers.Renderers
namespace NativeCode.Mobile.AppCompat.Renderers
{
using System;
using System.Reflection;

using NativeCode.Mobile.AppCompat.Renderers.Renderers;

using Xamarin.Forms;

/// <summary>
/// Allows registration of renderers.
/// Enables renderers for various aspects of the library.
/// </summary>
public static class AppCompatRenderers
public static class FormsAppCompat
{
private const string RegistrarType = "Xamarin.Forms.Registrar, Xamarin.Forms.Core";

Expand All @@ -17,9 +19,9 @@ public static class AppCompatRenderers
private static readonly MethodInfo RegisterMethod;

/// <summary>
/// Initializes static members of the <see cref="AppCompatRenderers"/> class.
/// Initializes static members of the <see cref="FormsAppCompat"/> class.
/// </summary>
static AppCompatRenderers()
static FormsAppCompat()
{
var type = Type.GetType(RegistrarType, true);
var property = type.GetProperty("Registered", BindingFlags.NonPublic | BindingFlags.Static);
Expand All @@ -32,16 +34,8 @@ static AppCompatRenderers()
/// </summary>
public static void EnableAll()
{
EnableMasterDetailRenderer();
EnableAppCompatReplacements();
}

/// <summary>
/// Enables registration of the <see cref="AppCompatMasterDetailRenderer"/>.
/// </summary>
public static void EnableMasterDetailRenderer()
{
RegisterType(typeof(MasterDetailPage), typeof(AppCompatMasterDetailRenderer));
EnableMasterDetailRenderer();
}

/// <summary>
Expand All @@ -54,6 +48,14 @@ public static void EnableAppCompatReplacements()
RegisterType(typeof(Switch), typeof(AppCompatSwitchRenderer));
}

/// <summary>
/// Enables registration of the <see cref="AppCompatMasterDetailRenderer"/>.
/// </summary>
public static void EnableMasterDetailRenderer()
{
RegisterType(typeof(MasterDetailPage), typeof(AppCompatMasterDetailRenderer));
}

private static void RegisterType(Type handler, Type target)
{
RegisterMethod.Invoke(RegistrarInstance, new object[] { handler, target });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Extensions\CommandExtensions.cs" />
<Compile Include="Extensions\ElementExtensions.cs" />
<Compile Include="Extensions\EntryExtensions.cs" />
<Compile Include="Helpers\KeyboardHelper.cs" />
Expand All @@ -86,8 +87,9 @@
<Compile Include="Renderers\AppCompatMasterDetailRenderer.cs" />
<Compile Include="Renderers\AppCompatSwitchRenderer.cs" />
<Compile Include="Renderers\Controls\AppCompatEntryEditText.cs" />
<Compile Include="FormsAppCompat.cs" />
<Compile Include="Renderers\FloatingButtonRenderer.cs" />
<Compile Include="Renderers\AppCompatRenderers.cs" />
<Compile Include="Renderers\NavigationLayoutRenderer.cs" />
<Compile Include="Resources\Resource.Designer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down Expand Up @@ -120,6 +122,21 @@
<SubType>Designer</SubType>
</AndroidResource>
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\values\dimensions.xml">
<SubType>Designer</SubType>
</AndroidResource>
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\layout-v21\fab_mini.xml">
<SubType>Designer</SubType>
</AndroidResource>
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\layout-v21\fab_normal.xml">
<SubType>Designer</SubType>
</AndroidResource>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.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
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
// in the base method.
if (this.Control == null)
{
var control = new AppCompatButton(this.Context.GetAppCompatThemedContext());
var context = this.Context.GetAppCompatThemedContext();
var control = new AppCompatButton(context);
this.SetNativeControl(control);

control.SetOnClickListener(ButtonClickListener.Instance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)

if (e.OldElement == null)
{
var control = new AppCompatEntryEditText(this.Context.GetAppCompatThemedContext());
var context = this.Context.GetAppCompatThemedContext();
var control = new AppCompatEntryEditText(context);
this.SetNativeControl(control);

this.Control.ImeOptions = ImeAction.Done;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ protected override void OnElementChanged(ElementChangedEventArgs<Switch> e)

if (this.Control == null)
{
var control = new SwitchCompat(this.Context.GetAppCompatThemedContext());
var context = this.Context.GetAppCompatThemedContext();
var control = new SwitchCompat(context);
control.SetOnCheckedChangeListener(this);
this.SetNativeControl(control);
}
Expand Down
Loading