Browse Source

[Android] Support `PerformContextMenuAction` (#15608)

* support PerformContextMenuAction

* update

* update to new api
pull/15686/head
ijklam 2 years ago
committed by GitHub
parent
commit
7a7bee4cb4
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 36
      src/Android/Avalonia.Android/Platform/SkiaPlatform/TopLevelImpl.cs

36
src/Android/Avalonia.Android/Platform/SkiaPlatform/TopLevelImpl.cs

@ -54,7 +54,7 @@ namespace Avalonia.Android.Platform.SkiaPlatform
{ {
throw new ArgumentException("AvaloniaView.Context must not be null"); throw new ArgumentException("AvaloniaView.Context must not be null");
} }
_view = new ViewImpl(avaloniaView.Context, this, placeOnTop); _view = new ViewImpl(avaloniaView.Context, this, placeOnTop);
_textInputMethod = new AndroidInputMethod<ViewImpl>(_view); _textInputMethod = new AndroidInputMethod<ViewImpl>(_view);
_keyboardHelper = new AndroidKeyboardEventsHelper<TopLevelImpl>(this); _keyboardHelper = new AndroidKeyboardEventsHelper<TopLevelImpl>(this);
@ -85,7 +85,7 @@ namespace Avalonia.Android.Platform.SkiaPlatform
public virtual Size ClientSize => _view.Size.ToSize(RenderScaling); public virtual Size ClientSize => _view.Size.ToSize(RenderScaling);
public Size? FrameSize => null; public Size? FrameSize => null;
public Action? Closed { get; set; } public Action? Closed { get; set; }
public Action<RawInputEventArgs>? Input { get; set; } public Action<RawInputEventArgs>? Input { get; set; }
@ -136,7 +136,7 @@ namespace Avalonia.Android.Platform.SkiaPlatform
{ {
InputRoot = inputRoot; InputRoot = inputRoot;
} }
public virtual void Show() public virtual void Show()
{ {
_view.Visibility = ViewStates.Visible; _view.Visibility = ViewStates.Visible;
@ -148,7 +148,7 @@ namespace Avalonia.Android.Platform.SkiaPlatform
{ {
Paint?.Invoke(new Rect(new Point(0, 0), ClientSize)); Paint?.Invoke(new Rect(new Point(0, 0), ClientSize));
} }
public virtual void Dispose() public virtual void Dispose()
{ {
_systemNavigationManager.Dispose(); _systemNavigationManager.Dispose();
@ -264,11 +264,11 @@ namespace Avalonia.Android.Platform.SkiaPlatform
} }
public IPopupImpl? CreatePopup() => null; public IPopupImpl? CreatePopup() => null;
public Action? LostFocus { get; set; } public Action? LostFocus { get; set; }
public Action<WindowTransparencyLevel>? TransparencyLevelChanged { get; set; } public Action<WindowTransparencyLevel>? TransparencyLevelChanged { get; set; }
public WindowTransparencyLevel TransparencyLevel public WindowTransparencyLevel TransparencyLevel
{ {
get => _transparencyLevel; get => _transparencyLevel;
private set private set
@ -681,5 +681,29 @@ namespace Avalonia.Android.Platform.SkiaPlatform
return extract; return extract;
} }
public override bool PerformContextMenuAction(int id)
{
if (InputMethod.Client is not { } client) return false;
switch (id)
{
case global::Android.Resource.Id.SelectAll:
client.ExecuteContextMenuAction(ContextMenuAction.SelectAll);
return true;
case global::Android.Resource.Id.Cut:
client.ExecuteContextMenuAction(ContextMenuAction.Cut);
return true;
case global::Android.Resource.Id.Copy:
client.ExecuteContextMenuAction(ContextMenuAction.Copy);
return true;
case global::Android.Resource.Id.Paste:
client.ExecuteContextMenuAction(ContextMenuAction.Paste);
return true;
default:
break;
}
return base.PerformContextMenuAction(id);
}
} }
} }

Loading…
Cancel
Save