-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3630d42
commit 71d7d56
Showing
21 changed files
with
674 additions
and
5 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
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
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
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,7 @@ | ||
namespace Microsoft.Maui.Controls | ||
{ | ||
public partial class CheckBox : ICheck | ||
{ | ||
|
||
} | ||
} |
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,8 @@ | ||
namespace Microsoft.Maui | ||
{ | ||
public interface ICheck : IView | ||
{ | ||
bool IsChecked { get; set; } | ||
Color Color { get; } | ||
} | ||
} |
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,57 @@ | ||
using Android.Widget; | ||
using AndroidX.AppCompat.Widget; | ||
|
||
namespace Microsoft.Maui.Handlers | ||
{ | ||
public partial class CheckBoxHandler : AbstractViewHandler<ICheck, AppCompatCheckBox> | ||
{ | ||
CheckedChangeListener ChangeListener { get; } = new CheckedChangeListener(); | ||
|
||
protected override AppCompatCheckBox CreateNativeView() | ||
{ | ||
var nativeCheckBox = new AppCompatCheckBox(Context) | ||
{ | ||
SoundEffectsEnabled = false | ||
}; | ||
|
||
nativeCheckBox.SetClipToOutline(true); | ||
|
||
return nativeCheckBox; | ||
} | ||
|
||
protected override void ConnectHandler(AppCompatCheckBox nativeView) | ||
{ | ||
ChangeListener.Handler = this; | ||
nativeView.SetOnCheckedChangeListener(ChangeListener); | ||
} | ||
|
||
protected override void DisconnectHandler(AppCompatCheckBox nativeView) | ||
{ | ||
ChangeListener.Handler = null; | ||
nativeView.SetOnCheckedChangeListener(null); | ||
} | ||
|
||
void OnCheckedChanged(bool isChecked) | ||
{ | ||
if (VirtualView != null) | ||
VirtualView.IsChecked = isChecked; | ||
} | ||
|
||
internal class CheckedChangeListener : Java.Lang.Object, CompoundButton.IOnCheckedChangeListener | ||
{ | ||
public CheckBoxHandler? Handler { get; set; } | ||
|
||
public CheckedChangeListener() | ||
{ | ||
} | ||
|
||
public void OnCheckedChanged(CompoundButton? nativeCheckBox, bool isChecked) | ||
{ | ||
if (Handler == null || nativeCheckBox == null) | ||
return; | ||
|
||
Handler.OnCheckedChanged(isChecked); | ||
} | ||
} | ||
} | ||
} |
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,9 @@ | ||
using System; | ||
|
||
namespace Microsoft.Maui.Handlers | ||
{ | ||
public partial class CheckBoxHandler : AbstractViewHandler<ICheck, object> | ||
{ | ||
protected override object CreateNativeView() => throw new NotImplementedException(); | ||
} | ||
} |
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,39 @@ | ||
namespace Microsoft.Maui.Handlers | ||
{ | ||
public partial class CheckBoxHandler | ||
{ | ||
public static PropertyMapper<ICheck, CheckBoxHandler> CheckBoxMapper = new PropertyMapper<ICheck, CheckBoxHandler>(ViewHandler.ViewMapper) | ||
{ | ||
#if MONOANDROID | ||
[nameof(ICheck.BackgroundColor)] = MapBackgroundColor, | ||
#endif | ||
[nameof(ICheck.IsChecked)] = MapIsChecked, | ||
[nameof(ICheck.Color)] = MapColor | ||
}; | ||
|
||
public CheckBoxHandler() : base(CheckBoxMapper) | ||
{ | ||
|
||
} | ||
|
||
public CheckBoxHandler(PropertyMapper mapper) : base(mapper ?? CheckBoxMapper) | ||
{ | ||
|
||
} | ||
#if MONOANDROID | ||
public static void MapBackgroundColor(CheckBoxHandler handler, ICheck check) | ||
{ | ||
handler.TypedNativeView?.UpdateBackgroundColor(check); | ||
} | ||
#endif | ||
public static void MapIsChecked(CheckBoxHandler handler, ICheck check) | ||
{ | ||
handler.TypedNativeView?.UpdateIsChecked(check); | ||
} | ||
|
||
public static void MapColor(CheckBoxHandler handler, ICheck check) | ||
{ | ||
handler.TypedNativeView?.UpdateColor(check); | ||
} | ||
} | ||
} |
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,74 @@ | ||
using System; | ||
|
||
namespace Microsoft.Maui.Handlers | ||
{ | ||
public partial class CheckBoxHandler : AbstractViewHandler<ICheck, NativeCheckBox> | ||
{ | ||
protected virtual float MinimumSize => 44f; | ||
|
||
protected override NativeCheckBox CreateNativeView() | ||
{ | ||
return new NativeCheckBox | ||
{ | ||
MinimumViewSize = MinimumSize | ||
}; | ||
} | ||
|
||
protected override void ConnectHandler(NativeCheckBox nativeView) | ||
{ | ||
base.ConnectHandler(nativeView); | ||
|
||
nativeView.CheckedChanged += OnCheckedChanged; | ||
} | ||
|
||
protected override void DisconnectHandler(NativeCheckBox nativeView) | ||
{ | ||
base.DisconnectHandler(nativeView); | ||
|
||
nativeView.CheckedChanged -= OnCheckedChanged; | ||
} | ||
|
||
public override Size GetDesiredSize(double widthConstraint, double heightConstraint) | ||
{ | ||
var size = base.GetDesiredSize(widthConstraint, heightConstraint); | ||
|
||
var set = false; | ||
|
||
var width = widthConstraint; | ||
var height = heightConstraint; | ||
|
||
if (size.Width == 0) | ||
{ | ||
if (widthConstraint <= 0 || double.IsInfinity(widthConstraint)) | ||
{ | ||
width = MinimumSize; | ||
set = true; | ||
} | ||
} | ||
|
||
if (size.Height == 0) | ||
{ | ||
if (heightConstraint <= 0 || double.IsInfinity(heightConstraint)) | ||
{ | ||
height = MinimumSize; | ||
set = true; | ||
} | ||
} | ||
|
||
if (set) | ||
{ | ||
size = new Size(width, height); | ||
} | ||
|
||
return size; | ||
} | ||
|
||
void OnCheckedChanged(object? sender, EventArgs e) | ||
{ | ||
if (sender is NativeCheckBox nativeView && VirtualView != null) | ||
{ | ||
VirtualView.IsChecked = nativeView.IsChecked; | ||
} | ||
} | ||
} | ||
} |
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,57 @@ | ||
using Android.Content.Res; | ||
using Android.Graphics; | ||
using AndroidX.AppCompat.Widget; | ||
using AndroidX.Core.Widget; | ||
using AAttribute = Android.Resource.Attribute; | ||
using AColor = Android.Graphics.Color; | ||
using XColor = Microsoft.Maui.Color; | ||
|
||
namespace Microsoft.Maui | ||
{ | ||
public static class CheckBoxExtensions | ||
{ | ||
static readonly int[][] CheckedStates = new int[][] | ||
{ | ||
new int[] { AAttribute.StateEnabled, AAttribute.StateChecked }, | ||
new int[] { AAttribute.StateEnabled, -AAttribute.StateChecked }, | ||
new int[] { -AAttribute.StateEnabled, AAttribute.StateChecked }, | ||
new int[] { -AAttribute.StateEnabled, -AAttribute.StatePressed }, | ||
}; | ||
|
||
public static void UpdateBackgroundColor(this AppCompatCheckBox nativeCheckBox, ICheck check) | ||
{ | ||
if (check.BackgroundColor == XColor.Default) | ||
nativeCheckBox.SetBackgroundColor(AColor.Transparent); | ||
else | ||
nativeCheckBox.SetBackgroundColor(check.BackgroundColor.ToNative()); | ||
} | ||
|
||
public static void UpdateIsChecked(this AppCompatCheckBox nativeCheckBox, ICheck check) | ||
{ | ||
nativeCheckBox.Checked = check.IsChecked; | ||
} | ||
|
||
public static void UpdateColor(this AppCompatCheckBox nativeCheckBox, ICheck check) | ||
{ | ||
// TODO: Delete when implementing the logic to set the system accent color. | ||
XColor accent = XColor.FromHex("#ff33b5e5"); | ||
|
||
var tintColor = check.Color == XColor.Default ? accent.ToNative() : check.Color.ToNative(); | ||
|
||
var tintList = new ColorStateList( | ||
CheckedStates, | ||
new int[] | ||
{ | ||
tintColor, | ||
tintColor, | ||
tintColor, | ||
tintColor | ||
}); | ||
|
||
var tintMode = PorterDuff.Mode.SrcIn; | ||
|
||
CompoundButtonCompat.SetButtonTintList(nativeCheckBox, tintList); | ||
CompoundButtonCompat.SetButtonTintMode(nativeCheckBox, tintMode); | ||
} | ||
} | ||
} |
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,15 @@ | ||
namespace Microsoft.Maui | ||
{ | ||
public static class CheckBoxExtensions | ||
{ | ||
public static void UpdateIsChecked(this object nothing, ICheck check) | ||
{ | ||
|
||
} | ||
|
||
public static void UpdateColor(this object nothing, ICheck check) | ||
{ | ||
|
||
} | ||
} | ||
} |
Oops, something went wrong.