-
Notifications
You must be signed in to change notification settings - Fork 13
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
Showing
1 changed file
with
120 additions
and
120 deletions.
There are no files selected for viewing
240 changes: 120 additions & 120 deletions
240
ShanedlerSamples/Library/Shanandlers/ButtonRenderer.Android.cs
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 |
---|---|---|
@@ -1,120 +1,120 @@ | ||
#if ANDROID && NET8_0_OR_GREATER | ||
using Android.Content; | ||
using Android.Content.Res; | ||
using Android.Graphics.Drawables; | ||
using Google.Android.Material.Button; | ||
using Microsoft.Maui.Controls.Platform; | ||
using AView = Android.Views.View; | ||
using Microsoft.Maui.Graphics; | ||
using Android.Views; | ||
using Microsoft.Maui.Platform; | ||
using Microsoft.Maui.Handlers; | ||
using Microsoft.Maui.Controls.Handlers.Compatibility; | ||
|
||
namespace PureWeen.Maui.Controls.Handlers.Compatibility | ||
{ | ||
#pragma warning disable RS0016 // Add public types and members to the declared API | ||
public class ButtonRenderer : ViewRenderer<Button, MauiMaterialButton>, | ||
IButtonHandler, IImageSourcePartSetter, AView.IOnClickListener, AView.IOnTouchListener | ||
|
||
{ | ||
public static IPropertyMapper<Button, IButtonHandler> Mapper | ||
= new PropertyMapper<Button, IButtonHandler>(ButtonHandler.Mapper); | ||
|
||
public static CommandMapper<Button, IButtonHandler> CommandMapper | ||
= new CommandMapper<Button, IButtonHandler>(ButtonHandler.CommandMapper); | ||
|
||
bool _isDisposed; | ||
|
||
public ButtonRenderer(Context context) : base(context/*, Mapper, CommandMapper*/) | ||
{ | ||
AutoPackage = false; | ||
} | ||
|
||
IButton IButtonHandler.VirtualView => Element!; | ||
|
||
MaterialButton IButtonHandler.PlatformView => Control!; | ||
|
||
ImageSourcePartLoader? _imageSourcePartLoader; | ||
public ImageSourcePartLoader ImageSourceLoader => | ||
_imageSourcePartLoader ??= new ImageSourcePartLoader(this); | ||
|
||
ImageSourcePartLoader IButtonHandler.ImageSourceLoader => ImageSourceLoader; | ||
|
||
|
||
static ColorStateList TransparentColorStateList = Colors.Transparent.ToDefaultColorStateList(); | ||
protected override MauiMaterialButton CreateNativeControl() | ||
{ | ||
return new MauiMaterialButton(Context!) | ||
{ | ||
IconGravity = MaterialButton.IconGravityTextStart, | ||
IconTintMode = Android.Graphics.PorterDuff.Mode.Add, | ||
IconTint = TransparentColorStateList, | ||
SoundEffectsEnabled = false | ||
}; | ||
} | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
if (_isDisposed) | ||
return; | ||
|
||
_isDisposed = true; | ||
|
||
if (disposing) | ||
{ | ||
if (Control != null) | ||
{ | ||
Control.SetOnClickListener(null); | ||
Control.SetOnTouchListener(null); | ||
} | ||
} | ||
|
||
base.Dispose(disposing); | ||
} | ||
|
||
public void SetImageSource(Drawable? obj) | ||
{ | ||
Control!.Icon = obj; | ||
} | ||
|
||
protected override void OnElementChanged(ElementChangedEventArgs<Button> e) | ||
{ | ||
base.OnElementChanged(e); | ||
|
||
if (e.NewElement != null) | ||
{ | ||
if (Control == null) | ||
{ | ||
var button = CreateNativeControl(); | ||
|
||
button.SetOnClickListener(this); | ||
button.SetOnTouchListener(this); | ||
|
||
SetNativeControl(button); | ||
} | ||
} | ||
} | ||
|
||
void IOnClickListener.OnClick(AView? v) => (Element as IButton)?.Clicked(); | ||
|
||
bool IOnTouchListener.OnTouch(AView? v, MotionEvent? e) | ||
{ | ||
var button = (Element as IButton); | ||
switch (e?.ActionMasked) | ||
{ | ||
case MotionEventActions.Down: | ||
button?.Pressed(); | ||
break; | ||
case MotionEventActions.Cancel: | ||
case MotionEventActions.Up: | ||
button?.Released(); | ||
break; | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
#pragma warning restore RS0016 // Add public types and members to the declared API | ||
} | ||
#endif | ||
//#if ANDROID && NET8_0_OR_GREATER | ||
//using Android.Content; | ||
//using Android.Content.Res; | ||
//using Android.Graphics.Drawables; | ||
//using Google.Android.Material.Button; | ||
//using Microsoft.Maui.Controls.Platform; | ||
//using AView = Android.Views.View; | ||
//using Microsoft.Maui.Graphics; | ||
//using Android.Views; | ||
//using Microsoft.Maui.Platform; | ||
//using Microsoft.Maui.Handlers; | ||
//using Microsoft.Maui.Controls.Handlers.Compatibility; | ||
|
||
//namespace PureWeen.Maui.Controls.Handlers.Compatibility | ||
//{ | ||
//#pragma warning disable RS0016 // Add public types and members to the declared API | ||
// public class ButtonRenderer : ViewRenderer<Button, MauiMaterialButton>, | ||
// IButtonHandler, AView.IOnClickListener, AView.IOnTouchListener | ||
|
||
// { | ||
// public static IPropertyMapper<Button, IButtonHandler> Mapper | ||
// = new PropertyMapper<Button, IButtonHandler>(ButtonHandler.Mapper); | ||
|
||
// public static CommandMapper<Button, IButtonHandler> CommandMapper | ||
// = new CommandMapper<Button, IButtonHandler>(ButtonHandler.CommandMapper); | ||
|
||
// bool _isDisposed; | ||
|
||
// public ButtonRenderer(Context context) : base(context/*, Mapper, CommandMapper*/) | ||
// { | ||
// AutoPackage = false; | ||
// } | ||
|
||
// IButton IButtonHandler.VirtualView => Element!; | ||
|
||
// MaterialButton IButtonHandler.PlatformView => Control!; | ||
|
||
// ImageSourcePartLoader? _imageSourcePartLoader; | ||
// public ImageSourcePartLoader ImageSourceLoader => | ||
// _imageSourcePartLoader ??= new ImageSourcePartLoader(this); | ||
|
||
// ImageSourcePartLoader IButtonHandler.ImageSourceLoader => ImageSourceLoader; | ||
|
||
|
||
// static ColorStateList TransparentColorStateList = Colors.Transparent.ToDefaultColorStateList(); | ||
// protected override MauiMaterialButton CreateNativeControl() | ||
// { | ||
// return new MauiMaterialButton(Context!) | ||
// { | ||
// IconGravity = MaterialButton.IconGravityTextStart, | ||
// IconTintMode = Android.Graphics.PorterDuff.Mode.Add, | ||
// IconTint = TransparentColorStateList, | ||
// SoundEffectsEnabled = false | ||
// }; | ||
// } | ||
|
||
// protected override void Dispose(bool disposing) | ||
// { | ||
// if (_isDisposed) | ||
// return; | ||
|
||
// _isDisposed = true; | ||
|
||
// if (disposing) | ||
// { | ||
// if (Control != null) | ||
// { | ||
// Control.SetOnClickListener(null); | ||
// Control.SetOnTouchListener(null); | ||
// } | ||
// } | ||
|
||
// base.Dispose(disposing); | ||
// } | ||
|
||
// public void SetImageSource(Drawable? obj) | ||
// { | ||
// Control!.Icon = obj; | ||
// } | ||
|
||
// protected override void OnElementChanged(ElementChangedEventArgs<Button> e) | ||
// { | ||
// base.OnElementChanged(e); | ||
|
||
// if (e.NewElement != null) | ||
// { | ||
// if (Control == null) | ||
// { | ||
// var button = CreateNativeControl(); | ||
|
||
// button.SetOnClickListener(this); | ||
// button.SetOnTouchListener(this); | ||
|
||
// SetNativeControl(button); | ||
// } | ||
// } | ||
// } | ||
|
||
// void IOnClickListener.OnClick(AView? v) => (Element as IButton)?.Clicked(); | ||
|
||
// bool IOnTouchListener.OnTouch(AView? v, MotionEvent? e) | ||
// { | ||
// var button = (Element as IButton); | ||
// switch (e?.ActionMasked) | ||
// { | ||
// case MotionEventActions.Down: | ||
// button?.Pressed(); | ||
// break; | ||
// case MotionEventActions.Cancel: | ||
// case MotionEventActions.Up: | ||
// button?.Released(); | ||
// break; | ||
// } | ||
|
||
// return false; | ||
// } | ||
// } | ||
//#pragma warning restore RS0016 // Add public types and members to the declared API | ||
//} | ||
//#endif |