Skip to content

Commit

Permalink
Merge pull request #18 from muak/beta
Browse files Browse the repository at this point in the history
Release 1.0.0
  • Loading branch information
muak authored Jul 12, 2017
2 parents 810b0d4 + b726578 commit 43385ef
Show file tree
Hide file tree
Showing 53 changed files with 2,800 additions and 56 deletions.
108 changes: 108 additions & 0 deletions AiForms.Effects.Droid/AddDatePickerPlatformEffect.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
using System;
using Xamarin.Forms.Platform.Android;
using Android.App;
using System.Windows.Input;
using AiForms.Effects;
using AiForms.Effects.Droid;
using Xamarin.Forms;

[assembly: ExportEffect(typeof(AddDatePickerPlatformEffect), nameof(AddDatePicker))]
namespace AiForms.Effects.Droid
{
public class AddDatePickerPlatformEffect : PlatformEffect
{
Android.Views.View _view;
DatePickerDialog _dialog;
ICommand _command;

protected override void OnAttached()
{
_view = Control ?? Container;

_view.Click += _view_Click;

UpdateCommand();
}

protected override void OnDetached()
{
var renderer = Container as IVisualElementRenderer;
if (renderer?.Element != null) {
_view.Click -= _view_Click;
}
if (_dialog != null) {
_dialog.Dispose();
_dialog = null;
}
_view = null;
_command = null;
}

protected override void OnElementPropertyChanged(System.ComponentModel.PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(e);

if (e.PropertyName == AddDatePicker.CommandProperty.PropertyName) {
UpdateCommand();
}
}

void _view_Click(object sender, EventArgs e)
{
if (_dialog != null) {
_dialog.Dispose();
}

CreateDialog();

UpdateMinDate();
UpdateMaxDate();

_dialog.CancelEvent += OnCancelButtonClicked;

_dialog.Show();
}

void CreateDialog()
{
var date = AddDatePicker.GetDate(Element);

_dialog = new DatePickerDialog(Container.Context, (o, e) => {
AddDatePicker.SetDate(Element, e.Date);
_command?.Execute(e.Date);
_view.ClearFocus();
_dialog.CancelEvent -= OnCancelButtonClicked;

_dialog = null;
}, date.Year, date.Month - 1, date.Day);

_dialog.SetCanceledOnTouchOutside(true);
}

void OnCancelButtonClicked(object sender, EventArgs e)
{
_view.ClearFocus();
}


void UpdateMaxDate()
{
if (_dialog != null) {
//when not to specify 23:59:59,last day can't be selected.
_dialog.DatePicker.MaxDate = (long)AddDatePicker.GetMaxDate(Element).AddHours(23).AddMinutes(59).AddSeconds(59).ToUniversalTime().Subtract(DateTime.MinValue.AddYears(1969)).TotalMilliseconds;
}
}

void UpdateMinDate()
{
if (_dialog != null) {
_dialog.DatePicker.MinDate = (long)AddDatePicker.GetMinDate(Element).ToUniversalTime().Subtract(DateTime.MinValue.AddYears(1969)).TotalMilliseconds;
}
}

void UpdateCommand()
{
_command = AddDatePicker.GetCommand(Element);
}
}
}
107 changes: 107 additions & 0 deletions AiForms.Effects.Droid/AddTimePickerPlatformEffect.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
using System;
using Xamarin.Forms.Platform.Android;
using Android.App;
using AiForms.Effects;
using Xamarin.Forms;
using AiForms.Effects.Droid;
using Android.Text.Format;
using Android.Widget;
using System.Windows.Input;

[assembly: ExportEffect(typeof(AddTimePickerPlatformEffect), nameof(AddTimePicker))]
namespace AiForms.Effects.Droid
{
public class AddTimePickerPlatformEffect : PlatformEffect
{
Android.Views.View _view;
TimePickerDialog _dialog;
ICommand _command;
string _title;

protected override void OnAttached()
{
_view = Control ?? Container;

_view.Click += _view_Click;

UpdateTitle();
UpdateCommand();
}

protected override void OnDetached()
{
var renderer = Container as IVisualElementRenderer;
if (renderer?.Element != null) {
_view.Click -= _view_Click;
}
if (_dialog != null) {
_dialog.Dispose();
_dialog = null;
}
_view = null;
_command = null;
}

protected override void OnElementPropertyChanged(System.ComponentModel.PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(e);

if (e.PropertyName == AddTimePicker.TitleProperty.PropertyName) {
UpdateTitle();
}
else if (e.PropertyName == AddTimePicker.CommandProperty.PropertyName) {
UpdateCommand();
}
}

void _view_Click(object sender, EventArgs e)
{
CreateDialog();
}

void CreateDialog()
{
var time = AddTimePicker.GetTime(Element);
if (_dialog == null) {
bool is24HourFormat = DateFormat.Is24HourFormat(Container.Context);
_dialog = new TimePickerDialog(Container.Context, TimeSelected, time.Hours, time.Minutes, is24HourFormat);

var title = new TextView(Container.Context);

if (!string.IsNullOrEmpty(_title)) {
title.Gravity = Android.Views.GravityFlags.Center;
title.SetPadding(10, 10, 10, 10);
title.Text = _title;
_dialog.SetCustomTitle(title);
}

_dialog.SetCanceledOnTouchOutside(true);

_dialog.DismissEvent += (ss, ee) => {
title.Dispose();
_dialog.Dispose();
_dialog = null;
};

_dialog.Show();
}
}

void TimeSelected(object sender, TimePickerDialog.TimeSetEventArgs e)
{
var time = new TimeSpan(e.HourOfDay, e.Minute, 0);
AddTimePicker.SetTime(Element, time);
_command?.Execute(time);
}

void UpdateTitle()
{
_title = AddTimePicker.GetTitle(Element);
}

void UpdateCommand()
{
_command = AddTimePicker.GetCommand(Element);
}
}
}
11 changes: 11 additions & 0 deletions AiForms.Effects.Droid/AiForms.Effects.Droid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
<AndroidUseLatestPlatformSdk>true</AndroidUseLatestPlatformSdk>
<AndroidTlsProvider></AndroidTlsProvider>
<ReleaseVersion>0.0.5-pre</ReleaseVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -92,6 +93,16 @@
<Compile Include="AddNumberPickerPlatform.cs" />
<Compile Include="ToFlatButtonPlatformEffect.cs" />
<Compile Include="AddTextPlatformEffect.cs" />
<Compile Include="BorderPlatformEffect.cs" />
<Compile Include="AlterColorPlatformEffect.cs" />
<Compile Include="AlterColorSlider.cs" />
<Compile Include="AlterColorBase.cs" />
<Compile Include="AlterColorSwitch.cs" />
<Compile Include="AlterColorTextView.cs" />
<Compile Include="AlterColorStatusbar.cs" />
<Compile Include="AddTimePickerPlatformEffect.cs" />
<Compile Include="AddDatePickerPlatformEffect.cs" />
<Compile Include="PlaceholderPlatformEffect.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\AboutResources.txt" />
Expand Down
20 changes: 20 additions & 0 deletions AiForms.Effects.Droid/AlterColorBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using Xamarin.Forms.Platform.Android;

namespace AiForms.Effects.Droid
{
public abstract class AlterColorBase
{
IVisualElementRenderer _renderer;

public AlterColorBase(IVisualElementRenderer renderer)
{
_renderer = renderer;
}

protected bool IsDisposed()
{
return _renderer?.Element == null;
}
}
}
53 changes: 53 additions & 0 deletions AiForms.Effects.Droid/AlterColorPlatformEffect.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using Android.Widget;
using Android.Support.V7.Widget;
using AiForms.Effects.Droid;
using AiForms.Effects;

[assembly: ExportEffect(typeof(AlterColorPlatformEffect), nameof(AlterColor))]
namespace AiForms.Effects.Droid
{
public class AlterColorPlatformEffect : PlatformEffect
{
IAlterColorEffect _effect;

protected override void OnAttached()
{
var renderer = Container as IVisualElementRenderer;

if (Element is Slider) {
_effect = new AlterColorSlider(Control as SeekBar, Element, renderer);
}
else if (Element is Xamarin.Forms.Switch) {
_effect = new AlterColorSwitch(Control as SwitchCompat, Element, renderer);
}
else if (Element is Entry || Element is Editor) {
_effect = new AlterColorTextView(Control as TextView, Element, renderer);
}
else if (Element is Page) {
_effect = new AlterColorStatusbar(Element, renderer);
}
else {
return;
}

_effect?.Update();
}

protected override void OnDetached()
{
_effect?.OnDetached();
_effect = null;
}

protected override void OnElementPropertyChanged(System.ComponentModel.PropertyChangedEventArgs args)
{
base.OnElementPropertyChanged(args);
if (args.PropertyName == AlterColor.AccentProperty.PropertyName) {
_effect?.Update();
}
}
}
}
Loading

0 comments on commit 43385ef

Please sign in to comment.