summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls/App.cs
diff options
context:
space:
mode:
authorE.Z. Hart <hartez@gmail.com>2016-03-29 14:08:26 -0600
committerE.Z. Hart <hartez@gmail.com>2016-03-29 14:08:26 -0600
commit81cb1d36479ec7d889fade1d53bef34357a73fb9 (patch)
tree061db1acff6446c4a7fce242c4231bb6e19e5a8a /Xamarin.Forms.Controls/App.cs
parent57b0f3ab3080928d2ddd2da58fc84ef7023c3651 (diff)
downloadxamarin-forms-81cb1d36479ec7d889fade1d53bef34357a73fb9.tar.gz
xamarin-forms-81cb1d36479ec7d889fade1d53bef34357a73fb9.tar.bz2
xamarin-forms-81cb1d36479ec7d889fade1d53bef34357a73fb9.zip
Make ControlGallery App.cs conform to code style
Diffstat (limited to 'Xamarin.Forms.Controls/App.cs')
-rw-r--r--Xamarin.Forms.Controls/App.cs330
1 files changed, 54 insertions, 276 deletions
diff --git a/Xamarin.Forms.Controls/App.cs b/Xamarin.Forms.Controls/App.cs
index 975faf8c..2556bc8c 100644
--- a/Xamarin.Forms.Controls/App.cs
+++ b/Xamarin.Forms.Controls/App.cs
@@ -1,85 +1,54 @@
using System;
-using System.Collections;
using System.Collections.Generic;
-using System.Diagnostics;
-using System.Globalization;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
namespace Xamarin.Forms.Controls
{
- public class AppLifeCycle : Application
+ public class App : Application
{
- protected override void OnStart ()
- {
- base.OnStart ();
- }
+ public const string AppName = "XamarinFormsControls";
+ static string s_insightsKey;
+
+ // ReSharper disable once InconsistentNaming
+ public static int IOSVersion = -1;
- protected override void OnSleep ()
- {
- base.OnSleep ();
- }
+ public static List<string> AppearingMessages = new List<string>();
- protected override void OnResume ()
- {
- base.OnResume ();
- }
+ static Dictionary<string, string> s_config;
+ readonly ITestCloudService _testCloudService;
- public AppLifeCycle ()
+ public App()
{
- MainPage = new ContentPage {
- Content = new Label {
- Text = "Testing Lifecycle events"
- }
+ _testCloudService = DependencyService.Get<ITestCloudService>();
+ InitInsights();
+ // MainPage = new MainPageLifeCycleTests ();
+ MainPage = new MasterDetailPage
+ {
+ Master = new ContentPage { Title = "Master", BackgroundColor = Color.Red },
+ Detail = CoreGallery.GetMainPage()
};
}
- }
-
- public class SimpleApp : Application
- {
- Label label;
- public SimpleApp ()
+ public static Dictionary<string, string> Config
{
- label = new Label { VerticalOptions = LayoutOptions.CenterAndExpand };
+ get
+ {
+ if (s_config == null)
+ LoadConfig();
- if (Current.Properties.ContainsKey ("LabelText")) {
- label.Text = (string) Current.Properties["LabelText"] + " Restored!";
- Debug.WriteLine ("Initialized");
- } else {
- Current.Properties["LabelText"] = "Wowza";
- label.Text = (string) Current.Properties["LabelText"] + " Set!";
- Debug.WriteLine ("Saved");
+ return s_config;
}
-
- MainPage = new ContentPage {
- Content = new StackLayout {
- Children = {
- label
- }
- }
- };
-
- SerializeProperties ();
- }
-
- async void SerializeProperties ()
- {
- await Current.SavePropertiesAsync ();
}
- }
- public class App : Application
- {
- static string s_insightsKey;
public static string InsightsApiKey
{
get
{
if (s_insightsKey == null)
{
- var key = Config["InsightsApiKey"];
+ string key = Config["InsightsApiKey"];
s_insightsKey = string.IsNullOrEmpty(key) ? Insights.DebugModeKey : key;
}
@@ -87,249 +56,58 @@ namespace Xamarin.Forms.Controls
}
}
- public const string AppName = "XamarinFormsControls";
- public const string AppVersion = "1.4.3";
- public static int IOSVersion = -1;
- readonly ITestCloudService _testCloudService;
- // make sure serialized data is available here
-
- //protected override void OnStart ()
- //{
- // // called right after property store is populated
- // MainPage.BackgroundColor = Color.Green;
- // Current.Properties["TimesStarted"] = ((int)Current.Properties["TimesStarted"]) + 1;
- // ((MainPageLifeCycleTests)MainPage).UpdateLabels ();
- //}
-
- //protected override void OnResume ()
- //{
- // MainPage.BackgroundColor = Color.White;
- // Current.Properties["TimesResumed"] = ((int)Current.Properties["TimesResumed"]) + 1;
- // ((MainPageLifeCycleTests)MainPage).UpdateLabels ();
- //}
-
- //protected override void OnSleep ()
- //{
- // MainPage.BackgroundColor = Color.Red;
- // Current.Properties["TimesSlept"] = ((int)Current.Properties["TimesSlept"]) + 1;
- // ((MainPageLifeCycleTests)MainPage).UpdateLabels ();
- //}
- public static List<string> AppearingMessages = new List<string>();
-
public static ContentPage MenuPage { get; set; }
-
-
- public App ()
+ public void SetMainPage(Page rootPage)
{
- _testCloudService = DependencyService.Get<ITestCloudService> ();
- InitInsights ();
- // MainPage = new MainPageLifeCycleTests ();
- MainPage = new MasterDetailPage () {
- Master = new ContentPage { Title = "Master", BackgroundColor = Color.Red },
- Detail = CoreGallery.GetMainPage ()
- };
+ MainPage = rootPage;
}
- public void SetMainPage (Page rootPage)
+ static Assembly GetAssembly(out string assemblystring)
{
- MainPage = rootPage;
+ assemblystring = typeof (App).AssemblyQualifiedName.Split(',')[1].Trim();
+ var assemblyname = new AssemblyName(assemblystring);
+ return Assembly.Load(assemblyname);
}
- void InitInsights ()
+ void InitInsights()
{
- if (Insights.IsInitialized) {
+ if (Insights.IsInitialized)
+ {
Insights.ForceDataTransmission = true;
- if (_testCloudService != null && _testCloudService.IsOnTestCloud ())
- Insights.Identify (_testCloudService.GetTestCloudDevice (), "Name", _testCloudService.GetTestCloudDeviceName ());
+ if (_testCloudService != null && _testCloudService.IsOnTestCloud())
+ Insights.Identify(_testCloudService.GetTestCloudDevice(), "Name", _testCloudService.GetTestCloudDeviceName());
else
- Insights.Identify ("DemoUser", "Name", "Demo User");
- }
- }
-
- public static Assembly GetAssembly (out string assemblystring)
- {
- assemblystring = typeof(App).AssemblyQualifiedName.Split (',')[1].Trim ();
- var assemblyname = new AssemblyName (assemblystring);
- return Assembly.Load (assemblyname);
- }
-
- public static async Task<string> LoadResource (string filename)
- {
- string assemblystring;
- Assembly assembly = GetAssembly (out assemblystring);
-
- Stream stream = assembly.GetManifestResourceStream ($"{assemblystring}.{filename}");
- string text;
- using (var reader = new StreamReader (stream)) {
- text = await reader.ReadToEndAsync ();
+ Insights.Identify("DemoUser", "Name", "Demo User");
}
- return text;
}
- public static void LoadConfig ()
+ static void LoadConfig()
{
- s_config = new Dictionary<string, string> ();
-
- string keyData = LoadResource ("controlgallery.config").Result;
- string[] entries = keyData.Split ("\n\r".ToCharArray (), StringSplitOptions.RemoveEmptyEntries);
- foreach (string entry in entries) {
- string[] parts = entry.Split (':');
- if (parts.Length < 2) {
- continue;
- }
+ s_config = new Dictionary<string, string>();
- s_config.Add (parts[0].Trim (), parts[1].Trim ());
- }
- }
-
- static Dictionary<string, string> s_config;
-
- public static Dictionary<string, string> Config
- {
- get
+ string keyData = LoadResource("controlgallery.config").Result;
+ string[] entries = keyData.Split("\n\r".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
+ foreach (string entry in entries)
{
- if (s_config == null) {
- LoadConfig ();
- }
-
- return s_config;
- }
- }
- }
-
- // Not quite sure how to turn this into a test case, effectively replace the normal Application with this to repro issues reported.
- // Full repro requires assignment to MainPage, hence the issue
- public class NavReproApp : Application
- {
- NavigationPage navPage1 = new NavigationPage ();
-
- public NavReproApp ()
- {
-
- var btn = new Button () { Text = "Start" };
-
- btn.Clicked += Btn_Clicked;
-
- navPage1.PushAsync (new ContentPage () { Content = btn });
-
- MainPage = navPage1;
-
- }
-
- async void Btn_Clicked (object sender, EventArgs e)
- {
- await navPage1.PushAsync (new ContentPage () { Content = new Label () { Text = "Page 2" } });
- await navPage1.PushAsync (new ContentPage () { Content = new Label () { Text = "Page 3" } });
-
-
- var navPage2 = new NavigationPage ();
-
- var btn = new Button () { Text = "Start Next" };
- btn.Clicked += Btn_Clicked1;
-
- await navPage2.PushAsync (new ContentPage () { Content = btn });
-
- MainPage = navPage2;
-
-
- }
-
- async void Btn_Clicked1 (object sender, EventArgs e)
- {
- MainPage = navPage1;
- await navPage1.PopAsync ();
-
-
- await navPage1.PushAsync (new ContentPage () { Content = new Label () { Text = "Page 3a" } });
- }
-
- protected override void OnStart ()
- {
- // Handle when your app starts
- }
-
- protected override void OnSleep ()
- {
- // Handle when your app sleeps
- }
-
- protected override void OnResume ()
- {
- // Handle when your app resumes
- }
- }
-
- public class MainPageLifeCycleTests : ContentPage
- {
- int numTimesStarted;
- int numTimesSlept;
- int numTimesResumed;
-
- StackLayout numTimesStartedLayout;
- StackLayout numTimesSleptLayout;
- StackLayout numTimesResumedLayout;
-
- public MainPageLifeCycleTests ()
- {
- object timesStarted;
- if (!Application.Current.Properties.TryGetValue ("TimesStarted", out timesStarted)) {
- Application.Current.Properties["TimesStarted"] = 0;
- }
- var numTimesStarted = (int)Application.Current.Properties["TimesStarted"];
-
-
- object timesSlept;
- if (!Application.Current.Properties.TryGetValue ("TimesSlept", out timesSlept)) {
- Application.Current.Properties["TimesSlept"] = 0;
- }
- var numTimesSlept = (int)Application.Current.Properties["TimesSlept"];
-
+ string[] parts = entry.Split(':');
+ if (parts.Length < 2)
+ continue;
- object timesResumed;
- if (!Application.Current.Properties.TryGetValue ("TimesResumed", out timesResumed)) {
- Application.Current.Properties["TimesResumed"] = 0;
+ s_config.Add(parts[0].Trim(), parts[1].Trim());
}
- var numTimesResumed = (int)Application.Current.Properties["TimesResumed"];
-
- numTimesStartedLayout = BuildLabelLayout ("TimesStarted", numTimesStarted);
- numTimesSleptLayout = BuildLabelLayout ("TimesSlept", numTimesSlept);
- numTimesResumedLayout = BuildLabelLayout ("TimesResumed", numTimesResumed);
-
- var layout = new StackLayout {
- Children = {
- numTimesStartedLayout,
- numTimesSleptLayout,
- numTimesResumedLayout
- }
- };
-
- Content = layout;
}
- StackLayout BuildLabelLayout (string title, int property)
+ static async Task<string> LoadResource(string filename)
{
- var labelTitle = new Label {
- Text = title
- };
-
- var valueLabel = new Label {
- Text = property.ToString ()
- };
-
- return new StackLayout {
- Children = {
- labelTitle,
- valueLabel
- }
- };
- }
+ string assemblystring;
+ Assembly assembly = GetAssembly(out assemblystring);
- public void UpdateLabels ()
- {
- ((Label)numTimesStartedLayout.Children[1]).Text = ((int)Application.Current.Properties["TimesStarted"]).ToString ();
- ((Label)numTimesSleptLayout.Children[1]).Text = ((int)Application.Current.Properties["TimesSlept"]).ToString ();
- ((Label)numTimesResumedLayout.Children[1]).Text = ((int)Application.Current.Properties["TimesResumed"]).ToString ();
+ Stream stream = assembly.GetManifestResourceStream($"{assemblystring}.{filename}");
+ string text;
+ using (var reader = new StreamReader(stream))
+ text = await reader.ReadToEndAsync();
+ return text;
}
}
-}
+} \ No newline at end of file