Browse Source
* move android app initialization to custom application class * fix tests * update api suppression * address commentspull/18869/head
committed by
GitHub
16 changed files with 139 additions and 59 deletions
@ -0,0 +1,30 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Android.App; |
|||
using Android.Runtime; |
|||
using Avalonia; |
|||
using Avalonia.Android; |
|||
|
|||
namespace ControlCatalog.Android |
|||
{ |
|||
[Application] |
|||
public class Application : AvaloniaAndroidApplication<App> |
|||
{ |
|||
protected Application(nint javaReference, JniHandleOwnership transfer) : base(javaReference, transfer) |
|||
{ |
|||
} |
|||
|
|||
|
|||
protected override AppBuilder CustomizeAppBuilder(AppBuilder builder) |
|||
{ |
|||
return base.CustomizeAppBuilder(builder) |
|||
.AfterSetup(_ => |
|||
{ |
|||
Pages.EmbedSample.Implementation = new EmbedSampleAndroid(); |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
using Android.App; |
|||
using Android.Runtime; |
|||
using Avalonia.Android; |
|||
|
|||
namespace SafeAreaDemo.Android |
|||
{ |
|||
[Application] |
|||
public class Application : AvaloniaAndroidApplication<App> |
|||
{ |
|||
protected Application(nint javaReference, JniHandleOwnership transfer) : base(javaReference, transfer) |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
@ -1,5 +1,5 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto"> |
|||
<uses-permission android:name="android.permission.INTERNET" /> |
|||
<application android:label="SafeAreaDemo" android:icon="@drawable/Icon" /> |
|||
<application android:name=".Application" android:label="SafeAreaDemo" android:icon="@drawable/Icon" /> |
|||
</manifest> |
|||
|
|||
@ -1,5 +1,5 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto"> |
|||
<application android:label="SingleProjectSandbox.Android"></application> |
|||
<application android:name=".Application" android:label="SingleProjectSandbox.Android"></application> |
|||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> |
|||
</manifest> |
|||
|
|||
@ -0,0 +1,14 @@ |
|||
using Android.App; |
|||
using Android.Runtime; |
|||
using Avalonia.Android; |
|||
|
|||
namespace SingleProjectSandbox.Android |
|||
{ |
|||
[Application] |
|||
public class Application : AvaloniaAndroidApplication<App> |
|||
{ |
|||
protected Application(nint javaReference, JniHandleOwnership transfer) : base(javaReference, transfer) |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
@ -1,15 +1,10 @@ |
|||
using Android.App; |
|||
using Android.Content.PM; |
|||
using Avalonia; |
|||
using Avalonia.Android; |
|||
|
|||
namespace SingleProjectSandbox; |
|||
|
|||
[Activity(Label = "SingleProjectSandbox.Android", Theme = "@style/Theme.AppCompat.NoActionBar", MainLauncher = true, ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize)] |
|||
public class MainActivity : AvaloniaMainActivity<App> |
|||
{ |
|||
protected override AppBuilder CreateAppBuilder() |
|||
public class MainActivity : AvaloniaMainActivity |
|||
{ |
|||
return App.BuildAvaloniaApp().UseAndroid(); |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,45 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Android.Runtime; |
|||
|
|||
namespace Avalonia.Android |
|||
{ |
|||
internal interface IAndroidApplication |
|||
{ |
|||
SingleViewLifetime? Lifetime { get; set; } |
|||
} |
|||
|
|||
public class AvaloniaAndroidApplication<TApp> : global::Android.App.Application, IAndroidApplication |
|||
where TApp : Application, new() |
|||
{ |
|||
SingleViewLifetime? IAndroidApplication.Lifetime { get; set; } |
|||
|
|||
protected AvaloniaAndroidApplication(nint javaReference, JniHandleOwnership transfer) : base(javaReference, transfer) |
|||
{ |
|||
} |
|||
|
|||
public override void OnCreate() |
|||
{ |
|||
base.OnCreate(); |
|||
InitializeAppLifetime(); |
|||
} |
|||
|
|||
private void InitializeAppLifetime() |
|||
{ |
|||
var builder = CreateAppBuilder(); |
|||
builder = CustomizeAppBuilder(builder); |
|||
|
|||
var lifetime = new SingleViewLifetime(); |
|||
|
|||
((IAndroidApplication)this).Lifetime = lifetime; |
|||
|
|||
builder.SetupWithLifetime(lifetime); |
|||
} |
|||
|
|||
protected virtual AppBuilder CreateAppBuilder() => AppBuilder.Configure<TApp>().UseAndroid(); |
|||
protected virtual AppBuilder CustomizeAppBuilder(AppBuilder builder) => builder; |
|||
} |
|||
} |
|||
@ -1,7 +0,0 @@ |
|||
namespace Avalonia.Android; |
|||
|
|||
public class AvaloniaMainActivity<TApp> : AvaloniaMainActivity |
|||
where TApp : Application, new() |
|||
{ |
|||
protected override AppBuilder CreateAppBuilder() => AppBuilder.Configure<TApp>().UseAndroid(); |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
using Android.App; |
|||
using Android.Runtime; |
|||
using Avalonia.Android; |
|||
|
|||
namespace BuildTests.Android |
|||
{ |
|||
[Application] |
|||
public class Application : AvaloniaAndroidApplication<App> |
|||
{ |
|||
protected Application(nint javaReference, JniHandleOwnership transfer) : base(javaReference, transfer) |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
@ -1,5 +1,6 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto"> |
|||
<uses-permission android:name="android.permission.INTERNET" /> |
|||
<application android:label="BuildTests" /> |
|||
<application android:name=".Application" |
|||
android:label="BuildTests" /> |
|||
</manifest> |
|||
|
|||
Loading…
Reference in new issue