diff options
Diffstat (limited to 'Xamarin.Forms.ControlGallery.Android')
10 files changed, 287 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 } diff --git a/Xamarin.Forms.ControlGallery.Android/CacheService.cs b/Xamarin.Forms.ControlGallery.Android/CacheService.cs new file mode 100644 index 00000000..1f371656 --- /dev/null +++ b/Xamarin.Forms.ControlGallery.Android/CacheService.cs @@ -0,0 +1,26 @@ +using System.IO; +using System.IO.IsolatedStorage; +using Xamarin.Forms.Controls; + +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)); + } + } + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.ControlGallery.Android/DisposeLabelRenderer.cs b/Xamarin.Forms.ControlGallery.Android/DisposeLabelRenderer.cs new file mode 100644 index 00000000..f0e8e424 --- /dev/null +++ b/Xamarin.Forms.ControlGallery.Android/DisposeLabelRenderer.cs @@ -0,0 +1,17 @@ +using Xamarin.Forms.Controls; +using Xamarin.Forms.Platform.Android; + +namespace Xamarin.Forms.ControlGallery.Android +{ + public class DisposeLabelRenderer : LabelRenderer + { + protected override void Dispose (bool disposing) + { + + if (disposing) { + ((DisposeLabel) Element).SendRendererDisposed (); + } + base.Dispose (disposing); + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.ControlGallery.Android/DisposePageRenderer.cs b/Xamarin.Forms.ControlGallery.Android/DisposePageRenderer.cs new file mode 100644 index 00000000..aa75bda4 --- /dev/null +++ b/Xamarin.Forms.ControlGallery.Android/DisposePageRenderer.cs @@ -0,0 +1,17 @@ +using Xamarin.Forms.Controls; +using Xamarin.Forms.Platform.Android; + +namespace Xamarin.Forms.ControlGallery.Android +{ + public class DisposePageRenderer : PageRenderer + { + protected override void Dispose (bool disposing) + { + if (disposing) { + ((DisposePage) Element).SendRendererDisposed (); + } + base.Dispose (disposing); + + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.ControlGallery.Android/FormsAppCompatActivity.cs b/Xamarin.Forms.ControlGallery.Android/FormsAppCompatActivity.cs new file mode 100644 index 00000000..afeea537 --- /dev/null +++ b/Xamarin.Forms.ControlGallery.Android/FormsAppCompatActivity.cs @@ -0,0 +1,74 @@ +#if !FORMS_APPLICATION_ACTIVITY && !PRE_APPLICATION_CLASS + +using System.Diagnostics; +using Android.App; +using Android.Content; +using Android.Content.PM; +using Android.OS; +using Xamarin.Forms.Controls; +using Xamarin.Forms.Controls.Issues; +using Xamarin.Forms.Platform.Android; +using Xamarin.Forms.Platform.Android.AppLinks; + +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)] + [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) + { + 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); + + _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)); + + LoadApplication(_app); + } + + } +} + +#endif
\ No newline at end of file diff --git a/Xamarin.Forms.ControlGallery.Android/FormsApplicationActivity.cs b/Xamarin.Forms.ControlGallery.Android/FormsApplicationActivity.cs new file mode 100644 index 00000000..7c999ce8 --- /dev/null +++ b/Xamarin.Forms.ControlGallery.Android/FormsApplicationActivity.cs @@ -0,0 +1,50 @@ +#if FORMS_APPLICATION_ACTIVITY + +using System.Diagnostics; +using Android.App; +using Android.Content.PM; +using Android.OS; +using Xamarin.Forms.Controls; +using Xamarin.Forms.Platform.Android; + +namespace Xamarin.Forms.ControlGallery.Android +{ + // This is the Pre-AppCompat version of Activity1 + +[Activity(Label = "Control Gallery", Icon = "@drawable/icon", MainLauncher = true, + HardwareAccelerated = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)] + public partial class Activity1 : FormsApplicationActivity + { + protected override void OnCreate(Bundle bundle) + { + base.OnCreate(bundle); + + if (!Debugger.IsAttached) + Insights.Initialize(App.InsightsApiKey, ApplicationContext); + + Forms.Init(this, bundle); + FormsMaps.Init(this, bundle); + 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 = _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); + + LoadApplication(app); + } + } +} + +#endif
\ No newline at end of file diff --git a/Xamarin.Forms.ControlGallery.Android/PreApplicationClassActivity.cs b/Xamarin.Forms.ControlGallery.Android/PreApplicationClassActivity.cs new file mode 100644 index 00000000..13f21640 --- /dev/null +++ b/Xamarin.Forms.ControlGallery.Android/PreApplicationClassActivity.cs @@ -0,0 +1,54 @@ +#if PRE_APPLICATION_CLASS + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +using Android.App; +using Android.Content; +using Android.Content.PM; +using Android.OS; +using Android.Runtime; +using Android.Views; +using Android.Widget; +using Xamarin.Forms.Controls; +using Xamarin.Forms.Platform.Android; + +namespace Xamarin.Forms.ControlGallery.Android +{ + [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); + }); + } + } +} + +#endif
\ No newline at end of file diff --git a/Xamarin.Forms.ControlGallery.Android/StringProvider.cs b/Xamarin.Forms.ControlGallery.Android/StringProvider.cs new file mode 100644 index 00000000..018ea7b3 --- /dev/null +++ b/Xamarin.Forms.ControlGallery.Android/StringProvider.cs @@ -0,0 +1,15 @@ +using Xamarin.Forms.Controls; + +namespace Xamarin.Forms.ControlGallery.Android +{ + public class StringProvider : IStringProvider + { + public string CoreGalleryTitle + { + get + { + return "Android CoreGallery"; + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.ControlGallery.Android/TestCloudService.cs b/Xamarin.Forms.ControlGallery.Android/TestCloudService.cs new file mode 100644 index 00000000..7a2fe050 --- /dev/null +++ b/Xamarin.Forms.ControlGallery.Android/TestCloudService.cs @@ -0,0 +1,24 @@ +using Xamarin.Forms.Controls; + +namespace Xamarin.Forms.ControlGallery.Android +{ + 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"); + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.ControlGallery.Android/Xamarin.Forms.ControlGallery.Android.csproj b/Xamarin.Forms.ControlGallery.Android/Xamarin.Forms.ControlGallery.Android.csproj index 473ae27f..ccf16fe7 100644 --- a/Xamarin.Forms.ControlGallery.Android/Xamarin.Forms.ControlGallery.Android.csproj +++ b/Xamarin.Forms.ControlGallery.Android/Xamarin.Forms.ControlGallery.Android.csproj @@ -175,11 +175,19 @@ <Compile Include="Activity1.cs" /> <Compile Include="BorderEffect.cs" /> <Compile Include="BrokenNativeControl.cs" /> + <Compile Include="CacheService.cs" /> + <Compile Include="FormsApplicationActivity.cs" /> + <Compile Include="DisposeLabelRenderer.cs" /> + <Compile Include="DisposePageRenderer.cs" /> + <Compile Include="FormsAppCompatActivity.cs" /> + <Compile Include="PreApplicationClassActivity.cs" /> <Compile Include="Properties\MapsKey.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Resources\Resource.Designer.cs" /> <Compile Include="CustomRenderers.cs" /> <Compile Include="ColorPicker.cs" /> + <Compile Include="StringProvider.cs" /> + <Compile Include="TestCloudService.cs" /> <Compile Include="_38989CustomRenderer.cs" /> <Compile Include="BrokenImageSourceHandler.cs" /> <Compile Include="_57114CustomRenderer.cs" /> |