diff options
Diffstat (limited to 'Xamarin.Forms.ControlGallery.Android/Activity1.cs')
-rw-r--r-- | Xamarin.Forms.ControlGallery.Android/Activity1.cs | 312 |
1 files changed, 2 insertions, 310 deletions
diff --git a/Xamarin.Forms.ControlGallery.Android/Activity1.cs b/Xamarin.Forms.ControlGallery.Android/Activity1.cs index 930697d2..eb32a4b2 100644 --- a/Xamarin.Forms.ControlGallery.Android/Activity1.cs +++ b/Xamarin.Forms.ControlGallery.Android/Activity1.cs @@ -1,8 +1,6 @@ using System; using System.Diagnostics; using System.Globalization; -using System.IO; -using System.IO.IsolatedStorage; using Android.App; using Android.Content.PM; using Android.OS; @@ -28,313 +26,10 @@ using AColor = Android.Graphics.Color; namespace Xamarin.Forms.ControlGallery.Android { - public class CacheService : ICacheService - { - public void ClearImageCache () - { - DeleteFilesInDirectory ("ImageLoaderCache"); - } - - static void DeleteFilesInDirectory (string directory) - { - using (IsolatedStorageFile isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication ()) { - if (isolatedStorage.DirectoryExists (directory)) { - var files = isolatedStorage.GetFileNames (Path.Combine (directory, "*")); - foreach (string file in files) { - isolatedStorage.DeleteFile (Path.Combine (directory, file)); - } - } - } - } - } - - public class DisposePageRenderer : PageRenderer - { - protected override void Dispose (bool disposing) - { - if (disposing) { - ((DisposePage) Element).SendRendererDisposed (); - } - base.Dispose (disposing); - - } - } - - public class DisposeLabelRenderer : LabelRenderer - { - protected override void Dispose (bool disposing) - { - - if (disposing) { - ((DisposeLabel) Element).SendRendererDisposed (); - } - base.Dispose (disposing); - } - } - - public class StringProvider : IStringProvider - { - public string CoreGalleryTitle - { - get - { - return "Android CoreGallery"; - } - } - } - - public class TestCloudService : ITestCloudService - { - public bool IsOnTestCloud () - { - var isInTestCloud = System.Environment.GetEnvironmentVariable ("XAMARIN_TEST_CLOUD"); - - return isInTestCloud != null && isInTestCloud.Equals ("1"); - } - - public string GetTestCloudDeviceName () - { - return System.Environment.GetEnvironmentVariable ("XTC_DEVICE_NAME"); - } - - public string GetTestCloudDevice () - { - return System.Environment.GetEnvironmentVariable ("XTC_DEVICE"); - } - } - -#if PRE_APPLICATION_CLASS - [Activity (Label = "Control Gallery", - Icon = "@drawable/icon", - MainLauncher = true, - HardwareAccelerated = true, - ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)] - public class Activity1 : AndroidActivity - { - - - protected override void OnCreate (Bundle bundle) - { - base.OnCreate (bundle); - - Forms.Init (this, bundle); - FormsMaps.Init (this, bundle); - - SetPage (FormsApp.GetFormsApp ()); - - MessagingCenter.Subscribe<RootPagesGallery, Type> (this, Messages.ChangeRoot, (sender, pageType) => { - var page = ((Page)Activator.CreateInstance (pageType)); - SetPage (page); - }); - - MessagingCenter.Subscribe<RootPagesGallery, Type> (this, Messages.ChangeRoot, (sender, pageType) => { - var page = ((Page)Activator.CreateInstance (pageType)); - SetPage (page); - }); - - MessagingCenter.Subscribe<HomeButton> (this, Messages.GoHome, (sender) => { - var screen = FormsApp.GetFormsApp (); - SetPage (screen); - }); - } - - public override void OnConfigurationChanged (global::Android.Content.Res.Configuration newConfig) - { - // we're good - base.OnConfigurationChanged (newConfig); - } - - protected override void OnDestroy () - { - base.OnDestroy (); - } - } - -#elif FORMS_APPLICATION_ACTIVITY - [Activity(Label = "Control Gallery", - Icon = "@drawable/icon", - // Theme="@style/TestStyle", - MainLauncher = true, - HardwareAccelerated = true, - ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)] - - public class Activity1 : FormsApplicationActivity + public partial class Activity1 { App _app; - protected override void OnCreate(Bundle bundle) - { - //ToolbarResource = Resource.Layout.Toolbar; - //TabLayoutResource = Resource.Layout.Tabbar; - - base.OnCreate(bundle); - - if (!Debugger.IsAttached) - Insights.Initialize(App.Config["InsightsApiKey"], this.ApplicationContext); - - Forms.Init(this, bundle); - FormsMaps.Init(this, bundle); - Xamarin.Forms.Forms.ViewInitialized += (object sender, Xamarin.Forms.ViewInitializedEventArgs 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); - - var app = _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); - - LoadApplication (app); - } - - private void AddNativeControls (NestedNativeControlGalleryPage page) - { - if (page.NativeControlsAdded) { - return; - } - - StackLayout sl = page.Layout; - - // Create and add a native TextView - var textView = new TextView (this) { Text = "I am a native TextView", TextSize = 14 }; - sl?.Children.Add (textView); - - // Create and add a native Button - var button = new global::Android.Widget.Button (this) { Text = "Click to change TextView font size" }; - float originalSize = textView.TextSize; - button.Click += (sender, args) => { textView.TextSize = textView.TextSize == originalSize ? 24 : 14; }; - - sl?.Children.Add (button.ToView ()); - - // Create a control which we know doesn't behave correctly with regard to measurement - var difficultControl0 = new BrokenNativeControl (this) { - Text = "This native control doesn't play nice with sizing, which is why it's all squished to one side." - }; - var difficultControl1 = new BrokenNativeControl (this) { - Text = "Same control, but with a custom GetDesiredSize delegate to accomodate it's sizing problems." - }; - - // Add a misbehaving control - sl?.Children.Add (difficultControl0); - - // Add a misbehaving control with a custom delegate for GetDesiredSize - sl?.Children.Add (difficultControl1, SizeBrokenControl); - - page.NativeControlsAdded = true; - } - - private static SizeRequest? SizeBrokenControl (NativeViewWrapperRenderer renderer, - int widthConstraint, int heightConstraint) - { - global::Android.Views.View nativeView = renderer.Control; - - if ((widthConstraint == 0 && heightConstraint == 0) || nativeView == null) { - return null; - } - - int width = global::Android.Views.View.MeasureSpec.GetSize (widthConstraint); - int widthSpec = global::Android.Views.View.MeasureSpec.MakeMeasureSpec (width * 2, - global::Android.Views.View.MeasureSpec.GetMode (widthConstraint)); - nativeView.Measure (widthSpec, heightConstraint); - var size = new Size (nativeView.MeasuredWidth, nativeView.MeasuredHeight); - return new SizeRequest (size); - } - - public override void OnConfigurationChanged(global::Android.Content.Res.Configuration newConfig) - { - // we're good - base.OnConfigurationChanged(newConfig); - } - - protected override void OnDestroy() - { - base.OnDestroy(); - } - - [Export("NavigateToTest")] - public bool NavigateToTest(string test) - { - return _app.NavigateToTestPage(test); - } - } -#else - - [Activity (Label = "Control Gallery", - Icon = "@drawable/icon", - Theme = "@style/MyTheme", - MainLauncher = true, - HardwareAccelerated = true, - ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)] - [IntentFilter (new[] { Intent.ActionView }, - Categories = new[] - { - Intent.ActionView, - Intent.CategoryDefault, - Intent.CategoryBrowsable - }, - DataScheme = "http", - DataHost = App.AppName, - DataPathPrefix = "/gallery/" - ) - ] - public class Activity1 : FormsAppCompatActivity - { - App _app; - - protected override void OnCreate (Bundle bundle) - { - 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 (!Debugger.IsAttached) - Insights.Initialize (App.InsightsApiKey, ApplicationContext); - - Forms.Init (this, bundle); - FormsMaps.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); - - var app = new App(); - _app = 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(AColor.Red)); - - LoadApplication(app); - } - - public override void OnConfigurationChanged (global::Android.Content.Res.Configuration newConfig) - { - // we're good - base.OnConfigurationChanged (newConfig); - } - - protected override void OnDestroy () - { - base.OnDestroy (); - } - void AddNativeControls (NestedNativeControlGalleryPage page) { if (page.NativeControlsAdded) { @@ -350,9 +45,7 @@ namespace Xamarin.Forms.ControlGallery.Android // Create and add a native Button var button = new global::Android.Widget.Button (this) { Text = "Click to change TextView font size" }; float originalSize = textView.TextSize; - button.Click += (sender, args) => { - textView.TextSize = textView.TextSize == originalSize ? 24 : 14; - }; + button.Click += (sender, args) => { textView.TextSize = textView.TextSize == originalSize ? 24 : 14; }; sl?.Children.Add (button.ToView ()); @@ -454,6 +147,5 @@ namespace Xamarin.Forms.ControlGallery.Android _app.Reset(); } } -#endif } |