9 changed files with 125 additions and 151 deletions
@ -1,35 +0,0 @@ |
|||||
using Android.App; |
|
||||
using Android.Content; |
|
||||
using Android.Content.PM; |
|
||||
using Android.OS; |
|
||||
using Avalonia.Android; |
|
||||
|
|
||||
namespace ControlCatalog.Android |
|
||||
{ |
|
||||
[Activity(Theme = "@style/MyTheme.Splash", MainLauncher = true, NoHistory = true)] |
|
||||
public class SplashActivity : AvaloniaSplashActivity<App> |
|
||||
{ |
|
||||
protected override Avalonia.AppBuilder CustomizeAppBuilder(Avalonia.AppBuilder builder) |
|
||||
{ |
|
||||
return base.CustomizeAppBuilder(builder) |
|
||||
.AfterSetup(_ => |
|
||||
{ |
|
||||
Pages.EmbedSample.Implementation = new EmbedSampleAndroid(); |
|
||||
}); |
|
||||
} |
|
||||
|
|
||||
protected override void OnCreate(Bundle? savedInstanceState) |
|
||||
{ |
|
||||
base.OnCreate(savedInstanceState); |
|
||||
} |
|
||||
|
|
||||
protected override void OnResume() |
|
||||
{ |
|
||||
base.OnResume(); |
|
||||
|
|
||||
StartActivity(new Intent(Application.Context, typeof(MainActivity))); |
|
||||
|
|
||||
Finish(); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,12 +1,11 @@ |
|||||
using Android.App; |
using Android.App; |
||||
using Android.Content.PM; |
using Android.Content.PM; |
||||
using Avalonia; |
|
||||
using Avalonia.Android; |
using Avalonia.Android; |
||||
|
|
||||
namespace MobileSandbox.Android |
namespace MobileSandbox.Android |
||||
{ |
{ |
||||
[Activity(Label = "MobileSandbox.Android", Theme = "@style/MyTheme.NoActionBar", Icon = "@drawable/icon", LaunchMode = LaunchMode.SingleTop, ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize)] |
[Activity(Label = "MobileSandbox.Android", Theme = "@style/MyTheme.NoActionBar", Icon = "@drawable/icon", MainLauncher = true, ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize)] |
||||
public class MainActivity : AvaloniaMainActivity |
public class MainActivity : AvaloniaMainActivity<App> |
||||
{ |
{ |
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -1,17 +0,0 @@ |
|||||
using Android.App; |
|
||||
using Android.Content; |
|
||||
using Avalonia.Android; |
|
||||
|
|
||||
namespace MobileSandbox.Android |
|
||||
{ |
|
||||
[Activity(Theme = "@style/MyTheme.Splash", MainLauncher = true, NoHistory = true)] |
|
||||
public class SplashActivity : AvaloniaSplashActivity<App> |
|
||||
{ |
|
||||
protected override void OnResume() |
|
||||
{ |
|
||||
base.OnResume(); |
|
||||
|
|
||||
StartActivity(new Intent(Application.Context, typeof(MainActivity))); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,60 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace Avalonia.Android |
||||
|
{ |
||||
|
partial class AvaloniaMainActivity<TApp> where TApp : Application, new() |
||||
|
{ |
||||
|
protected virtual AppBuilder CustomizeAppBuilder(AppBuilder builder) => builder.UseAndroid(); |
||||
|
|
||||
|
private static AppBuilder? s_appBuilder; |
||||
|
internal static object ViewContent; |
||||
|
|
||||
|
public object Content |
||||
|
{ |
||||
|
get |
||||
|
{ |
||||
|
return ViewContent; |
||||
|
} |
||||
|
set |
||||
|
{ |
||||
|
ViewContent = value; |
||||
|
if (View != null) |
||||
|
View.Content = value; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
protected AppBuilder CreateAppBuilder() |
||||
|
{ |
||||
|
var builder = AppBuilder.Configure<TApp>(); |
||||
|
|
||||
|
return CustomizeAppBuilder(builder); |
||||
|
} |
||||
|
|
||||
|
private void InitializeApp() |
||||
|
{ |
||||
|
if (s_appBuilder == null) |
||||
|
{ |
||||
|
var builder = CreateAppBuilder(); |
||||
|
|
||||
|
builder.SetupWithLifetime(new SingleViewLifetime()); |
||||
|
|
||||
|
s_appBuilder = builder; |
||||
|
} |
||||
|
|
||||
|
View = new AvaloniaView(this); |
||||
|
if (ViewContent != null) |
||||
|
{ |
||||
|
View.Content = ViewContent; |
||||
|
} |
||||
|
|
||||
|
if (Avalonia.Application.Current.ApplicationLifetime is SingleViewLifetime lifetime) |
||||
|
{ |
||||
|
lifetime.View = View; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,40 +0,0 @@ |
|||||
using Android.OS; |
|
||||
using AndroidX.AppCompat.App; |
|
||||
|
|
||||
namespace Avalonia.Android |
|
||||
{ |
|
||||
public abstract class AvaloniaSplashActivity : AppCompatActivity |
|
||||
{ |
|
||||
protected abstract AppBuilder CreateAppBuilder(); |
|
||||
|
|
||||
private static AppBuilder s_appBuilder; |
|
||||
|
|
||||
protected override void OnCreate(Bundle? savedInstanceState) |
|
||||
{ |
|
||||
base.OnCreate(savedInstanceState); |
|
||||
|
|
||||
if (s_appBuilder == null) |
|
||||
{ |
|
||||
var builder = CreateAppBuilder(); |
|
||||
|
|
||||
var lifetime = new SingleViewLifetime(); |
|
||||
|
|
||||
builder.SetupWithLifetime(lifetime); |
|
||||
|
|
||||
s_appBuilder = builder; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
public abstract class AvaloniaSplashActivity<TApp> : AvaloniaSplashActivity where TApp : Application, new() |
|
||||
{ |
|
||||
protected virtual AppBuilder CustomizeAppBuilder(AppBuilder builder) => builder.UseAndroid(); |
|
||||
|
|
||||
protected override AppBuilder CreateAppBuilder() |
|
||||
{ |
|
||||
var builder = AppBuilder.Configure<TApp>(); |
|
||||
|
|
||||
return CustomizeAppBuilder(builder); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue