19 changed files with 271 additions and 254 deletions
@ -0,0 +1,50 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
|
|||
using Android.App; |
|||
using Android.Content; |
|||
using Android.OS; |
|||
using Android.Runtime; |
|||
using Android.Views; |
|||
using Android.Widget; |
|||
|
|||
namespace Avalonia.Android |
|||
{ |
|||
public abstract class AvaloniaActivity : Activity |
|||
{ |
|||
AvaloniaView _view; |
|||
object _content; |
|||
|
|||
protected override void OnCreate(Bundle savedInstanceState) |
|||
{ |
|||
RequestWindowFeature(WindowFeatures.NoTitle); |
|||
_view = new AvaloniaView(this); |
|||
if(_content != null) |
|||
_view.Content = _content; |
|||
SetContentView(_view); |
|||
TakeKeyEvents(true); |
|||
base.OnCreate(savedInstanceState); |
|||
} |
|||
|
|||
public object Content |
|||
{ |
|||
get |
|||
{ |
|||
return _content; |
|||
} |
|||
set |
|||
{ |
|||
_content = value; |
|||
if (_view != null) |
|||
_view.Content = value; |
|||
} |
|||
} |
|||
|
|||
public override bool DispatchKeyEvent(KeyEvent e) |
|||
{ |
|||
return _view.DispatchKeyEvent(e); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,59 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
|
|||
using Android.App; |
|||
using Android.Content; |
|||
using Android.OS; |
|||
using Android.Runtime; |
|||
using Android.Views; |
|||
using Android.Widget; |
|||
using Avalonia.Android.Platform.SkiaPlatform; |
|||
using Avalonia.Controls.Embedding; |
|||
using Avalonia.Platform; |
|||
|
|||
namespace Avalonia.Android |
|||
{ |
|||
public class AvaloniaView : FrameLayout |
|||
{ |
|||
private readonly EmbeddableControlRoot _root; |
|||
private readonly ViewImpl _view; |
|||
|
|||
public AvaloniaView(Context context) : base(context) |
|||
{ |
|||
_view = new ViewImpl(context); |
|||
AddView(_view); |
|||
_root = new EmbeddableControlRoot(_view); |
|||
_root.Prepare(); |
|||
} |
|||
|
|||
public object Content |
|||
{ |
|||
get { return _root.Content; } |
|||
set { _root.Content = value; } |
|||
} |
|||
|
|||
public override bool DispatchKeyEvent(KeyEvent e) |
|||
{ |
|||
return _view.DispatchKeyEvent(e); |
|||
} |
|||
|
|||
class ViewImpl : TopLevelImpl, IEmbeddableWindowImpl |
|||
{ |
|||
public event Action LostFocus; |
|||
|
|||
public ViewImpl(Context context) : base(context) |
|||
{ |
|||
Focusable = true; |
|||
FocusChange += ViewImpl_FocusChange; |
|||
} |
|||
|
|||
private void ViewImpl_FocusChange(object sender, FocusChangeEventArgs e) |
|||
{ |
|||
if(!e.HasFocus) |
|||
LostFocus?.Invoke(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,44 +0,0 @@ |
|||
using Android.Views; |
|||
using Avalonia.Android.Platform.Specific; |
|||
using Avalonia.Controls; |
|||
using Avalonia.Input; |
|||
using Avalonia.Platform; |
|||
|
|||
namespace Avalonia.Android.Platform.SkiaPlatform |
|||
{ |
|||
public class MainWindowImpl : |
|||
WindowImpl |
|||
, IWindowImpl |
|||
{ |
|||
public MainWindowImpl() |
|||
{ |
|||
} |
|||
|
|||
public new WindowState WindowState |
|||
{ |
|||
get { return WindowState.Normal; } |
|||
set { } |
|||
} |
|||
|
|||
protected override void Init() |
|||
{ |
|||
base.Init(); |
|||
|
|||
HandleEvents = true; |
|||
_keyboardHelper.ActivateAutoShowKeybord(); |
|||
} |
|||
|
|||
void ITopLevelImpl.Show() |
|||
{ |
|||
(Parent as ViewGroup)?.RemoveAllViews(); |
|||
AvaloniaLocator.Current.GetService<IAndroidActivity>().ContentView = this; |
|||
//this.Visibility = ViewStates.Visible;
|
|||
} |
|||
|
|||
void ITopLevelImpl.SetInputRoot(IInputRoot inputRoot) |
|||
{ |
|||
base.SetInputRoot(inputRoot); |
|||
_keyboardHelper.UpdateKeyboardState(inputRoot); |
|||
} |
|||
} |
|||
} |
|||
@ -1,60 +0,0 @@ |
|||
using System; |
|||
using Android.App; |
|||
using Android.OS; |
|||
using Android.Views; |
|||
using Android.Widget; |
|||
|
|||
namespace Avalonia.Android.Platform.Specific |
|||
{ |
|||
public class AvaloniaActivity : Activity, IAndroidActivity |
|||
{ |
|||
private IAndroidView _contentView; |
|||
|
|||
public AvaloniaActivity(Type applicationType) |
|||
{ |
|||
AndroidPlatform.Instance.Init(applicationType); |
|||
} |
|||
|
|||
public Activity Activity => this; |
|||
|
|||
public IAndroidView ContentView |
|||
{ |
|||
get |
|||
{ |
|||
return this._contentView; |
|||
} |
|||
|
|||
set |
|||
{ |
|||
this._contentView = value; |
|||
var fl = new FrameLayout(this); |
|||
fl.AddView(this._contentView.View); |
|||
//this.SetContentView(value.View);
|
|||
this.SetContentView(fl); |
|||
} |
|||
} |
|||
|
|||
protected override void OnCreate(Bundle savedInstanceState) |
|||
{ |
|||
AvaloniaLocator.CurrentMutable.Bind<IAndroidActivity>().ToConstant(this); |
|||
RequestWindowFeature(WindowFeatures.NoTitle); |
|||
base.OnCreate(savedInstanceState); |
|||
} |
|||
|
|||
public override void SetContentView(View view) |
|||
{ |
|||
base.SetContentView(view); |
|||
TakeKeyEvents(true); |
|||
} |
|||
|
|||
public override bool DispatchKeyEvent(KeyEvent e) |
|||
{ |
|||
if (_contentView != null) |
|||
{ |
|||
_contentView.View.DispatchKeyEvent(e); |
|||
} |
|||
|
|||
return base.DispatchKeyEvent(e); |
|||
} |
|||
} |
|||
} |
|||
@ -1,12 +0,0 @@ |
|||
using Android.App; |
|||
using Android.Views; |
|||
|
|||
namespace Avalonia.Android.Platform.Specific |
|||
{ |
|||
public interface IAndroidActivity |
|||
{ |
|||
Activity Activity { get; } |
|||
|
|||
IAndroidView ContentView { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,71 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Runtime.InteropServices; |
|||
using System.Text; |
|||
|
|||
using Android.App; |
|||
using Android.Content; |
|||
using Android.OS; |
|||
using Android.Runtime; |
|||
using Android.Views; |
|||
using Android.Widget; |
|||
|
|||
namespace Avalonia.Skia.Android |
|||
{ |
|||
static class NativeMethods |
|||
{ |
|||
[DllImport("android")] |
|||
internal static extern IntPtr ANativeWindow_fromSurface(IntPtr jniEnv, IntPtr handle); |
|||
|
|||
[DllImport("android")] |
|||
internal static extern void ANativeWindow_release(IntPtr window); |
|||
[DllImport("android")] |
|||
internal static extern void ANativeWindow_unlockAndPost(IntPtr window); |
|||
|
|||
[DllImport("android")] |
|||
internal static extern int ANativeWindow_lock(IntPtr window, out ANativeWindow_Buffer outBuffer, ref ARect inOutDirtyBounds); |
|||
public enum AndroidPixelFormat |
|||
{ |
|||
WINDOW_FORMAT_RGBA_8888 = 1, |
|||
WINDOW_FORMAT_RGBX_8888 = 2, |
|||
WINDOW_FORMAT_RGB_565 = 4, |
|||
} |
|||
|
|||
internal struct ARect |
|||
{ |
|||
public int left; |
|||
public int top; |
|||
public int right; |
|||
public int bottom; |
|||
} |
|||
|
|||
|
|||
internal struct ANativeWindow_Buffer |
|||
{ |
|||
// The number of pixels that are show horizontally.
|
|||
public int width; |
|||
|
|||
// The number of pixels that are shown vertically.
|
|||
public int height; |
|||
|
|||
// The number of *pixels* that a line in the buffer takes in
|
|||
// memory. This may be >= width.
|
|||
public int stride; |
|||
|
|||
// The format of the buffer. One of WINDOW_FORMAT_*
|
|||
public AndroidPixelFormat format; |
|||
|
|||
// The actual bits.
|
|||
public IntPtr bits; |
|||
|
|||
// Do not touch.
|
|||
uint reserved1; |
|||
uint reserved2; |
|||
uint reserved3; |
|||
uint reserved4; |
|||
uint reserved5; |
|||
uint reserved6; |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue