Exemplo n.º 1
0
		public SelectionPage(MultiCell cell, string title, string[] items, string key, int defaultValue)
		{
			this.cell = cell;
			this.items = items;
			this.key = key;
			this.defaultValue = defaultValue;

			Title = Catalog.GetString(title);

			NavigationPage.SetTitleIcon(this, "HomeIcon.png");
			NavigationPage.SetBackButtonTitle(this, string.Empty);

			section = new TableSection();

			var active = 0;

			if (cell.Values == null)
			{
				active = Settings.Current.GetValueOrDefault<int>(key, defaultValue);
			}
			else
			{
				active = Array.IndexOf(cell.Values, Settings.Current.GetValueOrDefault<string>(key, cell.Values[defaultValue]));
				active = active < 0 ? 0 : active;
			}

			cells = new CheckCell[items.Length];

			for(int i = 0; i < items.Length; i++)
			{
				cells[i] = new CheckCell
					{
						Text = items[i],
						TextColor = App.Colors.Text,
					};

				cells[i].Index = i;
				cells[i].Checkmark = i == active;
				cells[i].Tapped += HandleTapped;

				section.Add(cells[i]);
			}

			var tableRoot = new TableRoot() 
				{
					section,
				};

			var tableView = new TableView() 
				{
					BackgroundColor = App.Colors.Background,
					Intent = TableIntent.Settings,
					Root = tableRoot,
					HasUnevenRows = true,
				};

			Content = tableView;
		}
Exemplo n.º 2
0
		public SettingsPage()
		{
			Title = Catalog.GetString("Settings");
			BackgroundColor = App.Colors.Background;

			// Save for later use
			// Do this, because color could change while handling with settings :)
			textColor = App.Colors.Text;
			backgroundColor = App.Colors.Background;

			NavigationPage.SetTitleIcon(this, "HomeIcon.png");
			NavigationPage.SetBackButtonTitle(this, string.Empty);

			var cellTheme = new MultiCell {
				Text = Catalog.GetString("Theme"),
//				Detail = Catalog.GetString("Theme of display"),
				Items = new string[] { 
					Catalog.GetString("Light"), 
					Catalog.GetString("Dark"),
				},
				Key = Settings.DisplayThemeKey,
				DefaultValue = (int)0,
			};

			var sectionTheme = new TableSection(Catalog.GetString("Appearance")) 
				{
					cellTheme,
				};

			var cellTextAlignment = new MultiCell {
				Text = Catalog.GetString("Alignment"),
//				Detail = Catalog.GetString("Alignment of text"),
				Items = new string[] { 
					Catalog.GetString("Left"), 
					Catalog.GetString("Center"),
					Catalog.GetString("Right"),
				},
				Key = Settings.TextAlignmentKey,
				DefaultValue = (int)Settings.DefaultTextAlignment,
			};

			var cellTextSize = new EntryCell 
				{
					Label = Catalog.GetString("Size"),
					LabelColor = App.Colors.Text,
					Keyboard = Keyboard.Numeric,
					Text = Settings.Current.GetValueOrDefault<int>(Settings.TextSizeKey, Settings.DefaultFontSize).ToString(),
					XAlign = TextAlignment.End,
				};

			cellTextSize.Completed += (object sender, EventArgs e) =>
				{
					int value;

					if (int.TryParse(((EntryCell)sender).Text, out value))
					{
						Settings.Current.AddOrUpdateValue<int>(Settings.TextSizeKey, value);
					}
				};
			cellTextSize.PropertyChanged += (object sender, System.ComponentModel.PropertyChangedEventArgs e) => {
				if (e.PropertyName == "Text")
				{
					int value;

					if (int.TryParse(((EntryCell)sender).Text, out value))
					{
						Settings.Current.AddOrUpdateValue<int>(Settings.TextSizeKey, value);
					}
				}
			};

			var sectionText = new TableSection(Catalog.GetString("Text")) 
				{
					cellTextAlignment,
					cellTextSize,
				};

			var cellImageAlignment = new MultiCell {
				Text = Catalog.GetString("Alignment"),
//				Detail = Catalog.GetString("Alignment of images"),
				Items = new string[] { 
					Catalog.GetString("Left"), 
					Catalog.GetString("Center"),
					Catalog.GetString("Right"),
				},
				Key = Settings.ImageAlignmentKey,
				DefaultValue = (int)Settings.DefaultImageAlignment,
			};

			var cellImageResize = new MultiCell {
				Text = Catalog.GetString("Resizing"),
//				Detail = Catalog.GetString("Resizing of images"),
				Items = new string[] { 
					Catalog.GetString("Don't resize"), 
					Catalog.GetString("Shrink only"),
					Catalog.GetString("Resize to screen width"),
					Catalog.GetString("Resize to max. half height"),
				},
				ShortItems = new string[] { 
					Catalog.GetString("Don't resize"), 
					Catalog.GetString("Shrink only"),
					Catalog.GetString("Screen width"),
					Catalog.GetString("Max. half height"),
				},
				Key = Settings.ImageResizeKey,
				DefaultValue = (int)Settings.DefaultImageResize,
			};

			var sectionImages = new TableSection(Catalog.GetString("Images")) 
				{
					cellImageAlignment,
					cellImageResize,
				};

			var cellFeedbackSound = new SwitchCell 
				{
					Text = Catalog.GetString("Sound"),
					On = Settings.Current.GetValueOrDefault<bool>(Settings.FeedbackSoundKey, false),
				};

			cellFeedbackSound.OnChanged += (object sender, ToggledEventArgs e) => Settings.Current.AddOrUpdateValue<bool>(Settings.FeedbackSoundKey, e.Value);

			var cellFeedbackVibration = new SwitchCell 
				{
					Text = Catalog.GetString("Vibration"),
					On = Settings.Current.GetValueOrDefault<bool>(Settings.FeedbackVibrationKey, false),
				};

			cellFeedbackVibration.OnChanged += (object sender, ToggledEventArgs e) => Settings.Current.AddOrUpdateValue<bool>(Settings.FeedbackVibrationKey, e.Value);

			var sectionFeedback = new TableSection(Catalog.GetString("Feedback")) 
				{
					cellFeedbackSound,
					cellFeedbackVibration,
				};

			var cellUnitDegrees = new MultiCell {
				Text = Catalog.GetString("Degrees"),
				//				Detail = Catalog.GetString("Resizing of images"),
				Items = new string[] { 
					Catalog.GetString("Decimal degrees (9.07538°)"), 
					Catalog.GetString("Decimal minutes (9° 04.523')"),
					Catalog.GetString("Decimal seconds (9° 04' 31.38\")"),
				},
				ShortItems = new string[] { 
					Catalog.GetString("Decimal degrees"), 
					Catalog.GetString("Decimal minutes"),
					Catalog.GetString("Decimal seconds"),
				},
				Key = Settings.FormatCoordinatesKey,
				DefaultValue = (int)Settings.DefaultFormatCoordinates,
			};

			var cellUnitAltitude = new MultiCell {
				Text = Catalog.GetString("Altitude"),
				//				Detail = Catalog.GetString("Resizing of images"),
				Items = new string[] { 
					Catalog.GetString("Meter"), 
					Catalog.GetString("Feet"),
				},
				Key = Settings.UnitAltitudeKey,
				DefaultValue = (int)Settings.DefaultUnitAltitude,
			};

			var cellUnitLength = new MultiCell {
				Text = Catalog.GetString("Length"),
				//				Detail = Catalog.GetString("Resizing of images"),
				Items = new string[] { 
					Catalog.GetString("Meter"), 
					Catalog.GetString("Feet"),
				},
				Key = Settings.UnitLengthKey,
				DefaultValue = (int)Settings.DefaultUnitLength,
			};

			var sectionUnits = new TableSection(Catalog.GetString("Units")) 
				{
					cellUnitDegrees,
					cellUnitAltitude,
					cellUnitLength,
				};

			var languages = new string[] {
				string.Empty,
				"en",
				"fi",
				"fr",
				"de"
			};

			var cellLanguage = new MultiCell {
				Text = Catalog.GetString("Language"),
				//				Detail = Catalog.GetString("Resizing of images"),
				Items = new string[] { 
					Catalog.GetString("Default"), 
					Catalog.GetString("English"), 
					Catalog.GetString("Finnish"),
					Catalog.GetString("French"),
					Catalog.GetString("German"),
				},
				Values = languages,
				Key = Settings.LanguageKey,
				DefaultValue = Array.IndexOf(languages, Settings.LanguageKey) < 0 ? 0 : Array.IndexOf(languages, Settings.LanguageKey),
			};

			var sectionLanguage = new TableSection(Catalog.GetString("Language")) 
				{
					cellLanguage,
				};

			#if __ANDROID__

			cellPath = new TextCell {
				Text = Catalog.GetString("Path for cartridges"),
				TextColor = App.Colors.Text,
				Detail = Settings.Current.GetValueOrDefault<string>(Settings.CartridgePathKey, null),
				DetailColor = Color.Gray,
			};

			cellPath.Command = new Command((sender) =>
				App.Navigation.Navigation.PushAsync(new FolderSelectionPage(Settings.Current.GetValueOrDefault<string>(Settings.CartridgePathKey, null), () =>
						{
							cellPath.Detail = Settings.Current.GetValueOrDefault<string>(Settings.CartridgePathKey, null);
					}, textColor, backgroundColor)));

			var sectionPath = new TableSection(Catalog.GetString("Path")) 
				{
					cellPath,
				};

			#endif

			var tableRoot = new TableRoot(Catalog.GetString("Settings")) 
				{
					sectionTheme,
					sectionText,
					sectionImages,
					sectionFeedback,
					sectionUnits,
					sectionLanguage,
					#if __ANDROID__
					sectionPath,
					#endif
				};

			var tableView = new TableView() 
				{
					BackgroundColor = App.Colors.Background,
					Intent = TableIntent.Settings,
					Root = tableRoot,
					HasUnevenRows = true,
				};

			Content = tableView;
		}