/
FormsAppCompatActivity.cs
120 lines (99 loc) · 3.53 KB
/
FormsAppCompatActivity.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#if !FORMS_APPLICATION_ACTIVITY && !PRE_APPLICATION_CLASS
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.OS;
using Java.Interop;
using Xamarin.Forms.Controls;
using Xamarin.Forms.Controls.Issues;
using Xamarin.Forms.Platform.Android;
using Xamarin.Forms.Platform.Android.AppLinks;
using System.Linq;
using Xamarin.Forms.Internals;
namespace Xamarin.Forms.ControlGallery.Android
{
// This is the AppCompat version of Activity1
[Activity(Label = "Control Gallery", Icon = "@drawable/icon", Theme = "@style/MyTheme",
MainLauncher = true, HardwareAccelerated = true,
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.UiMode)]
[IntentFilter(new[] { Intent.ActionView },
Categories = new[]
{
Intent.ActionView,
Intent.CategoryDefault,
Intent.CategoryBrowsable
},
DataScheme = "http", DataHost = App.AppName, DataPathPrefix = "/gallery/"
)
]
public partial class Activity1 : FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
Profile.Start();
ToolbarResource = Resource.Layout.Toolbar;
TabLayoutResource = Resource.Layout.Tabbar;
// Uncomment the next line to run this as a full screen app (no status bar)
//Window.AddFlags(WindowManagerFlags.Fullscreen | WindowManagerFlags.TurnScreenOn);
base.OnCreate(bundle);
#if TEST_EXPERIMENTAL_RENDERERS
#else
Forms.SetFlags("UseLegacyRenderers", "SwipeView_Experimental", "MediaElement_Experimental", "AppTheme_Experimental");
#endif
Forms.Init(this, bundle);
FormsMaps.Init(this, bundle);
FormsMaterial.Init(this, bundle);
AndroidAppLinks.Init(this);
Forms.ViewInitialized += (sender, e) => {
// if (!string.IsNullOrWhiteSpace(e.View.StyleId)) {
// e.NativeView.ContentDescription = e.View.StyleId;
// }
};
// uncomment to verify turning off title bar works. This is not intended to be dynamic really.
//Forms.SetTitleBarVisibility (AndroidTitleBarVisibility.Never);
if (RestartAppTest.App != null)
{
_app = (App)RestartAppTest.App;
RestartAppTest.Reinit = true;
}
else
{
_app = new App();
}
// When the native control gallery loads up, it'll let us know so we can add the nested native controls
MessagingCenter.Subscribe<NestedNativeControlGalleryPage>(this, NestedNativeControlGalleryPage.ReadyForNativeControlsMessage, AddNativeControls);
// When the native binding gallery loads up, it'll let us know so we can set up the native bindings
MessagingCenter.Subscribe<NativeBindingGalleryPage>(this, NativeBindingGalleryPage.ReadyForNativeBindingsMessage, AddNativeBindings);
// Listen for the message from the status bar color toggle test
MessagingCenter.Subscribe<AndroidStatusBarColor>(this, AndroidStatusBarColor.Message, color => SetStatusBarColor(global::Android.Graphics.Color.Red));
SetUpForceRestartTest();
// Make the activity accessible to platform unit tests
DependencyResolver.ResolveUsing((t) => {
if (t == typeof(Context))
{
return this;
}
return null;
});
LoadApplication(_app);
#if !TEST_EXPERIMENTAL_RENDERERS
if ((int)Build.VERSION.SdkInt >= 21)
{
// Show a purple status bar if we're looking at legacy renderers
Window.SetStatusBarColor(Color.MediumPurple.ToAndroid());
}
#endif
}
protected override void OnResume()
{
base.OnResume();
Profile.Stop();
}
[Export("IsPreAppCompat")]
public bool IsPreAppCompat()
{
return false;
}
}
}
#endif