-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from muak/beta
Release 1.0.0
- Loading branch information
Showing
53 changed files
with
2,800 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.