示例#1
1
文件: OptionPage.cs 项目: Zepsen/App1
        private ScrollView GenerateOptionLayout()
        {
            var stack = new StackLayout { Orientation = StackOrientation.Vertical };

            var peak = new Entry { Keyboard = Keyboard.Numeric, Placeholder = "Peak" };
            peak.SetBinding(Entry.TextProperty, OptionViewModel.PeakCommandPropertyName);
            stack.Children.Add(peak);

            var distance = new Entry { Keyboard = Keyboard.Numeric, Placeholder = "Distance" };
            distance.SetBinding(Entry.TextProperty, OptionViewModel.DistanceCommandPropertyName);
            stack.Children.Add(distance);

            var dogAllowed = new Switch();
            dogAllowed.SetBinding(Switch.IsToggledProperty, OptionViewModel.DogAllowedCommandPropertyName);
            stack.Children.Add(dogAllowed);

            var goodForKids = new Switch();
            goodForKids.SetBinding(Switch.IsToggledProperty, OptionViewModel.GoodForKidsCommandPropertyName);
            stack.Children.Add(goodForKids);

            var seasonStart = new Picker { Title = "SeasonStart" };
            foreach (var season in options.Seasons)
            {
                seasonStart.Items.Add(season.Value);
            }
            seasonStart.SetBinding(Picker.SelectedIndexProperty, OptionViewModel.SeasonStartCommandPropertyName);
            stack.Children.Add(seasonStart);

            var seasonEnd = new Picker { Title = "SeasonEnd" };
            foreach (var season in options.Seasons)
            {
                seasonEnd.Items.Add(season.Value);
            }
            seasonEnd.SetBinding(Picker.SelectedIndexProperty, OptionViewModel.SeasonEndCommandPropertyName);
            stack.Children.Add(seasonEnd);

            var trailType = new Picker() { Title = "Trail Type" };
            stack.Children.Add(trailType);
            foreach (var type in options.TrailsTypes)
            {
                trailType.Items.Add(type.Value);
            }
            trailType.SetBinding(Picker.SelectedIndexProperty, OptionViewModel.TypeCommandPropertyName);

            var trailDurationType = new Picker() { Title = "Trail Duration Type" };
            foreach (var durType in options.TrailsDurationTypes)
            {
                trailDurationType.Items.Add(durType.Value);
            }
            trailDurationType.SetBinding(Picker.SelectedIndexProperty, OptionViewModel.DurationTypeCommandPropertyName);
            stack.Children.Add(trailDurationType);

            var button = GenericsContent.GenerateDefaultButton("Update");
            button.SetBinding(Button.CommandProperty, OptionViewModel.UpdateCommandPropertyName);
            stack.Children.Add(button);

            return new ScrollView { Content = stack };
        }
示例#2
0
        private void AddComponent(object sender, EventArgs e)
        {
            Entry entry = new Entry {
                Text = "None", FontSize = 10
            };

            entry.Unfocused += (object me, FocusEventArgs ea) => { SetSpellDifficulty(sender, e); };
            Picker picker = new Picker {
                ItemsSource = ComponentComplexity, SelectedIndex = 0, FontSize = 10
            };

            picker.SelectedIndex         = 0;
            picker.SelectedIndexChanged += new EventHandler(Complexity_SelectedIndexChanged);
            Label label = new Label {
                Text = "Destroy on Use", FontSize = 10
            };

            Xamarin.Forms.Switch destroy = new Xamarin.Forms.Switch();
            Button destroyButton         = new Button {
                Text = "Destroy Component " + numComponent++
            };

            destroyButton.Clicked += new EventHandler(DestroyButton_Clicked);
            Components.Children.Add(entry);
            Components.Children.Add(picker);
            Components.Children.Add(label);
            Components.Children.Add(destroy);
            Components.Children.Add(destroyButton);
            SetSpellDifficulty(sender, null);
        }
        public void OnWristToggled(object sender, ToggledEventArgs e)
        {
            Switch sw      = sender as Switch;
            bool   toggled = sw.IsToggled;

            try
            {
                if (Windesheart.PairedDevice == null)
                {
                    return;
                }
                if (!Windesheart.PairedDevice.IsConnected())
                {
                    return;
                }
                Windesheart.PairedDevice.SetActivateOnLiftWrist(toggled);
                DeviceSettings.WristRaiseDisplay = toggled;
            }
            catch (Exception)
            {
                //toggle back the switch
                SettingsPage.WristSwitch.IsToggled = !toggled;
                Debug.WriteLine("Something went wrong!");
            }
        }
 private void InitComponentiValutazioneAttivi()
 {
     componentiValutazioneAttivi = new Xamarin.Forms.Switch()
     {
         IsToggled = false
     };
     componentiValutazioneAttivi.Toggled += EventComponentiValutazioneAttiviToggled;
 }
 public LoginForm(Entry login, Entry password, Switch isRemind, Label error, Button btnLogin, View tweets, View form)
 {
     Login    = login;
     Password = password;
     IsRemind = isRemind;
     Error    = error;
     Tweets   = tweets;
     Form     = form;
 }
示例#6
0
 public LoginForm(Entry login, Entry password, Xamarin.Forms.Switch isRemind, View loginForm, View tweetForm, Label errorLabel, Button button)
 {
     this.Login            = login;
     this.Password         = password;
     this.IsRemind         = isRemind;
     this.VisibilitySwitch = new VisibilitySwitch(loginForm, tweetForm);
     this.Error            = new ErrorForm(errorLabel);
     button.Clicked       += Button_Clicked;
 }
		public TodoItemPage ()
		{
			this.SetBinding (ContentPage.TitleProperty, "Name");

			NavigationPage.SetHasNavigationBar (this, true);
			var nameLabel = new Label { Text = "Name" };
			var nameEntry = new Entry ();
			
			nameEntry.SetBinding (Entry.TextProperty, "Name");

			var notesLabel = new Label { Text = "Notes" };
			var notesEntry = new Entry ();
			notesEntry.SetBinding (Entry.TextProperty, "Notes");

			var doneLabel = new Label { Text = "Done" };
			var doneEntry = new Xamarin.Forms.Switch ();
			doneEntry.SetBinding (Xamarin.Forms.Switch.IsToggledProperty, "Done");

			var saveButton = new Button { Text = "Save" };
			saveButton.Clicked += (sender, e) => {
				var todoItem = (TodoItem)BindingContext;
				App.Database.SaveItem(todoItem);
				this.Navigation.PopAsync();
			};

			var deleteButton = new Button { Text = "Delete" };
			deleteButton.Clicked += (sender, e) => {
				var todoItem = (TodoItem)BindingContext;
				App.Database.DeleteItem(todoItem.ID);
                this.Navigation.PopAsync();
			};
							
			var cancelButton = new Button { Text = "Cancel" };
			cancelButton.Clicked += (sender, e) => {
				var todoItem = (TodoItem)BindingContext;
                this.Navigation.PopAsync();
			};


			var speakButton = new Button { Text = "Speak" };
			speakButton.Clicked += (sender, e) => {
				var todoItem = (TodoItem)BindingContext;
				DependencyService.Get<ITextToSpeech>().Speak(todoItem.Name + " " + todoItem.Notes);
			};

			Content = new StackLayout {
				VerticalOptions = LayoutOptions.StartAndExpand,
				Padding = new Thickness(20),
				Children = {
					nameLabel, nameEntry, 
					notesLabel, notesEntry,
					doneLabel, doneEntry,
					saveButton, deleteButton, cancelButton,
					speakButton
				}
			};
		}
示例#8
0
        public LoginForm(Entry login, Entry password, Xamarin.Forms.Switch isRemind, View loginForm, Label errorLabel, Button button)
        {
            this.twitterService = new TwitterService();

            this.login    = login;
            this.password = password;
            this.isRemind = isRemind;
            this.error    = new ErrorForm(errorLabel);
        }
示例#9
0
        protected override void OnBindingContextChanged()
        {
            base.OnBindingContextChanged();
            var pitanje = (Anketa)GetValue(PitanjeProperty);

            labelPitanje.Text = pitanje.Pitanje;
            autor.Text        = pitanje.IdKorisnikNavigation.ImeIPrezimeP;
            datum.Text        = "Datum zatvaranja: " + pitanje.DatumKraja.ToString("dd.MM.yyyy.");
            var converter = new SlikaLinkConverter();

            profilna.Source             = (ImageSource)converter.Convert(pitanje.IdKorisnikNavigation.IdSlika, null, null, null);
            RezultatiBtn.BindingContext = pitanje;

            if (pitanje.VisestrukiOdgovor == false)
            {
                picker.ItemsSource        = pitanje.OdgovorAnkete.ToList();
                picker.ItemDisplayBinding = new Binding("Odgovor");
                var odg = pitanje.OdgovorAnkete.Where(o => o.OdgovorKorisnikaNaAnketu.Select(od => od.IdKorisnik).Contains(App.Korisnik.Id)).FirstOrDefault();
                if (odg != null)
                {
                    picker.SelectedItem = odg;
                }
                picker.SelectedIndexChanged += (sender, args) => this.PromjenaOdgovora.Invoke(this, args);
                if (pitanje.DatumKraja < DateTime.Now)
                {
                    picker.IsEnabled = false;
                }
            }
            else
            {
                grid.Children.Remove(picker);
                foreach (var odg in pitanje.OdgovorAnkete)
                {
                    StackLayout horizontalLayout = new StackLayout();
                    horizontalLayout.Orientation = StackOrientation.Horizontal;
                    Label l = new Label {
                        Text = odg.Odgovor
                    };
                    Switch cell = new Switch();
                    cell.HorizontalOptions = LayoutOptions.End;
                    cell.ThumbColor        = Color.AliceBlue;
                    if (odg.OdgovorKorisnikaNaAnketu.Select(o => o.IdKorisnik).Contains(App.Korisnik.Id))
                    {
                        cell.IsToggled = true;
                    }
                    horizontalLayout.Children.Add(l);
                    horizontalLayout.Children.Add(cell);
                    cell.BindingContext = odg;
                    cell.Toggled       += (sender, args) => this.PromjenaOdgovora.Invoke(this, args);
                    switchers.Children.Add(horizontalLayout);
                    if (pitanje.DatumKraja < DateTime.Now)
                    {
                        cell.IsEnabled = false;
                    }
                }
            }
        }
示例#10
0
        public void populateStoredEventsGrid()
        {
            storedEventsGrid.Children.Clear();

            GlobalVariables.storedEvents.Sort((x, y) => x.getName().CompareTo(y.getName()));

            //add events to grid
            int   row = 0;
            int   storedEventsIndex = 0;
            Event currentEvent;

            while (storedEventsIndex < GlobalVariables.storedEvents.Count())
            {
                currentEvent = null;
                currentEvent = GlobalVariables.storedEvents[storedEventsIndex++];

                StackLayout stack = new StackLayout();
                stack.HorizontalOptions = Xamarin.Forms.LayoutOptions.Start;
                stack.VerticalOptions   = Xamarin.Forms.LayoutOptions.CenterAndExpand;

                Label eventLabel = new Label();
                eventLabel.Text = currentEvent.getName();
                eventLabel.HorizontalTextAlignment = TextAlignment.Center;
                eventLabel.HorizontalOptions       = Xamarin.Forms.LayoutOptions.Start;
                eventLabel.VerticalOptions         = Xamarin.Forms.LayoutOptions.EndAndExpand;
                eventLabel.FontSize  = 16;
                eventLabel.TextColor = Color.Black;

                Label dateLabel = new Label();
                dateLabel.Text = currentEvent.getDate().ToString("MMMM d, yyyy");
                dateLabel.HorizontalOptions = Xamarin.Forms.LayoutOptions.Start;
                dateLabel.VerticalOptions   = Xamarin.Forms.LayoutOptions.StartAndExpand;
                dateLabel.FontSize          = 13;
                dateLabel.TextColor         = Xamarin.Forms.Color.Black;

                stack.Children.Add(eventLabel);
                stack.Children.Add(dateLabel);

                Xamarin.Forms.Switch visibleSwitch = new Xamarin.Forms.Switch();
                visibleSwitch.HorizontalOptions = Xamarin.Forms.LayoutOptions.EndAndExpand;
                visibleSwitch.VerticalOptions   = Xamarin.Forms.LayoutOptions.Center;
                visibleSwitch.Toggled          += currentEvent.VisibleSwitch_Toggled;
                visibleSwitch.IsToggled         = currentEvent.isVisible();

                //add grid's back color
                BoxView backColor = new BoxView();
                backColor.HorizontalOptions = Xamarin.Forms.LayoutOptions.FillAndExpand;
                backColor.Color             = Color.LightSteelBlue;

                storedEventsGrid.Children.Add(backColor, 0, 3, row, row + 1);
                storedEventsGrid.Children.Add(stack, 0, 2, row, row + 1);
                storedEventsGrid.Children.Add(visibleSwitch, 2, row);

                row++;
            }
        }
示例#11
0
 public LoginForm(Entry login, Entry password, Xamarin.Forms.Switch isRemind, Label errorLabel, Button button, INavigation navigation)
 {
     this.twitterService = new TwitterService();
     this.navigation     = navigation;
     this.login          = login;
     this.password       = password;
     this.isRemind       = isRemind;
     this.error          = new ErrorForm(errorLabel);
     button.Clicked     += Button_Clicked;
 }
        public LoginForm(Entry login, Entry password, Xamarin.Forms.Switch isRemind, View loginForm, View tweetForm, Label errorLabel, Button button)
        {
            this.twitterService = new TwitterService();

            this.login            = login;
            this.password         = password;
            this.isRemind         = isRemind;
            this.visibilitySwitch = new VisibilitySwitch(loginForm, tweetForm);
            this.error            = new ErrorForm(errorLabel);
            button.Clicked       += Button_Clicked;
        }
示例#13
0
        public static Xamarin.Forms.Switch GetToggle(ComponentContainer child, StandAloneFormSessionInfo info)
        {
            Xamarin.Forms.Switch Switch = new Xamarin.Forms.Switch()
            {
                IsToggled = GetToggleData <bool>(child, info)
                            // Text = child.Text,m
                            //   Text = GetControlData<string>(child, info)
                            //TextColor = GetColor(silverLabel.Attributes.LabelColor),
            };

            return(Switch);
        }
示例#14
0
 void Handle_ItemToggled(object sender, ToggledEventArgs e)
 {
     Xamarin.Forms.Switch s = sender as Xamarin.Forms.Switch;
     Debug.WriteLine(s.BindingContext);
     if (companiesToggled.Contains((String)s.BindingContext))
     {
         companiesToggled.Remove((String)s.BindingContext);
     }
     else
     {
         companiesToggled.Add((String)s.BindingContext);
     }
 }
 public SwitchHandler(NativeComponentRenderer renderer, XF.Switch switchControl) : base(renderer, switchControl)
 {
     SwitchControl          = switchControl ?? throw new System.ArgumentNullException(nameof(switchControl));
     SwitchControl.Toggled += (s, e) =>
     {
         if (IsToggledChangedEventHandlerId != default)
         {
             renderer.Dispatcher.InvokeAsync(() => renderer.DispatchEventAsync(IsToggledChangedEventHandlerId, null, new ChangeEventArgs {
                 Value = SwitchControl.IsToggled
             }));
         }
     };
 }
示例#16
0
        void createPopup1()
        {
            var checkbox = new Switch();

            checkbox.On <Xamarin.Forms.PlatformConfiguration.Tizen>().SetStyle("small");
            checkbox.Toggled += (s, e) =>
            {
                Console.WriteLine($"checkbox toggled. checkbox.IsToggled:{checkbox.IsToggled}");
            };

            _popUp1              = new TwoButtonPopup();
            _popUp1.Title        = "Popup title";
            _popUp1.FirstButton  = _leftButton;
            _popUp1.SecondButton = _rightButton;
            _popUp1.Content      = new StackLayout
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Children          =
                {
                    new Label
                    {
                        Text = "Will be saved, and sound, only on the Gear.",
                    },
                    new StackLayout
                    {
                        Orientation = StackOrientation.Horizontal,
                        Padding     = new Thickness(0, 40, 0, 40),
                        Children    =
                        {
                            checkbox,
                            new Label
                            {
                                Text = "Do not repeat",
                            }
                        }
                    }
                }
            };

            _popUp1.BackButtonPressed += (s, e) =>
            {
                _popUp1?.Dismiss();
                _popUp1     = null;
                label1.Text = "Popup1 is dismissed";
            };

            _popUp1.FirstButton.Clicked  += (s, e) => Console.WriteLine("First(share) button clicked!");
            _popUp1.SecondButton.Clicked += (s, e) => Console.WriteLine("Second(delete) button clicked!");
        }
示例#17
0
        protected override void OnAppearing()
        {
            base.OnAppearing();

            Team equipe = KTContext.Db.Teams
                          .Where(e => e.Id == equipeId)
                          .Include(e => e.Members)
                          .ThenInclude(e => e.Specialist.Tactics)
                          .Include(e => e.Members)
                          .ThenInclude(e => e.ModelProfile.Tactics)
                          .Include(e => e.Faction.Tactics)
                          .ThenInclude(t => t.Phase)
                          .First();

            Title = equipe.Name + " (" + equipe.Cost + ")";
            options.ChoosedPhase = KTContext.Db.Phases.Where(p => p.Id != "7").Select(p => p.Id).ToList();
            var tactiques = equipe.GetAllTactics(options);

            phasesSwitch.ForEach(p => StackLayoutOptions.Children.Remove(p));
            phasesSwitch.Clear();
            foreach (Phase phase in KTContext.Db.Phases.Where(p => p.Id != "7").OrderBy(p => p.Id))
            {
                StackLayout stackLayout = new StackLayout();
                stackLayout.Orientation = StackOrientation.Horizontal;
                stackLayout.Children.Add(
                    new Label
                {
                    Text          = phase.Name,
                    LineBreakMode = LineBreakMode.NoWrap,
                    FontSize      = 16
                }
                    );

                Switch @switch = new Switch();
                @switch.BindingContext    = phase;
                @switch.Toggled          += PhaseSwitchToggled;
                @switch.HorizontalOptions = LayoutOptions.EndAndExpand;
                @switch.IsToggled         = true;
                stackLayout.Children.Add(@switch);

                StackLayoutOptions.Children.Add(stackLayout);
                phasesSwitch.Add(stackLayout);
            }


            TactiquesListView.ItemsSource = equipe.GetAllTactics(options);

            BindingContext = options;
        }
        public SwitchSetting(string key, string title)
            : base(key, title)
        {
            var layout = (View as StackLayout);
            layout.Orientation = StackOrientation.Horizontal;
            var toggle = new Switch();
            toggle.Toggled += (sender, e) => {
                Value = e.Value ? "on" : "off";
            };
            toggle.IsToggled = Value == "on";
            layout.Children.Add(toggle);

            Tapped += delegate {
                toggle.IsToggled = !toggle.IsToggled;
            };
        }
示例#19
0
        protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Switch> e)
        {
            base.OnElementChanged(e);
            if (e.OldElement != null || e.NewElement == null)
            {
                return;
            }

            view = (Xamarin.Forms.Switch)Element;
            if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.JellyBean)
            {
                if (Control != null)
                {
                    this.Control.CheckedChange += this.OnCheckedChange;
                    Control.SetTrackResource(Resource.Drawable.track);
                }
            }
        }
示例#20
0
        private void Filter_Toggled(object sender, ToggledEventArgs e)
        {
            if (sender is Xamarin.Forms.Switch)
            {
                //the Auto Binding not working for Switch element
                Xamarin.Forms.Switch sw = sender as Xamarin.Forms.Switch;

                CheckedTypeMenu tyItem = sw.BindingContext as CheckedTypeMenu;
                if (tyItem != null)
                {
                    tyItem.check = sw.IsToggled;
                }
            }


            //if (Gluten.IsToggled)                                              // linq  create a new Object
            //    list = fullList.Where(item => item.Mnu.Glutan ).ToList();

            list = new List <MenuCommande>();
            Debug.WriteLine("*** filter: ***  gluten: " + this.Gluten.IsToggled + "   Vegan " + this.Vegan.IsToggled);
            foreach (MenuCommande item in fullList)
            {
                //Debug.WriteLine("*** Gluten ***" + item.Mnu.Glutan + " Vegan " + item.Mnu.Vegan);
                if ((!this.Gluten.IsToggled || (this.Gluten.IsToggled == item.Mnu.Glutan)) &&
                    ((!this.Vegan.IsToggled || (this.Vegan.IsToggled == item.Mnu.Vegan))))
                {
                    list.Add(item);
                }
            }
            Debug.WriteLine("*** filter: ***  gluten: " + this.Gluten.IsToggled + "   Vegan " + this.Vegan.IsToggled);


            //list = fullList.Where(item => item.Mnu.Glutan == this.Gluten.IsToggled &&
            //                             item.Mnu.Vegan == this.Vegan.IsToggled).ToList();
            //https://stackoverflow.com/questions/37389027/use-linq-to-get-items-in-one-list-that-are-in-another-list
            //var result = peopleList1.Where(p => peopleList2.Any(p2 => p2.ID == p.ID));
            list = list.Where(item => typeList.Any(t => t.check && t.Type.Id == item.Mnu.TypeMenu.Id)).ToList();

            Debug.WriteLine("*** Filter_Toggled ***" + list.Count + " from " + fullList.Count);
            refreshDisplay();
        }
        public EmployeeView()
        {
            photo = new Image {
                WidthRequest = IMAGE_SIZE, HeightRequest = IMAGE_SIZE
            };
            photo.SetBinding(Image.SourceProperty, "DetailsPlaceholder.jpg");

            favoriteLabel  = new Label();
            favoriteSwitch = new Xamarin.Forms.Switch();

            var optionsView = new StackLayout
            {
                VerticalOptions = LayoutOptions.StartAndExpand,
                Orientation     = StackOrientation.Vertical,
                Children        = { favoriteLabel, favoriteSwitch }
            };

            var headerView = new StackLayout
            {
                Padding           = new Thickness(10, 20, 10, 0),
                HorizontalOptions = LayoutOptions.StartAndExpand,
                Orientation       = StackOrientation.Horizontal,
                Children          = { photo, optionsView }
            };

            var listView = new ListView {
                IsGroupingEnabled = true
            };

            listView.ItemSelected += OnItemSelected;
            listView.SetBinding(ItemsView <Cell> .ItemsSourceProperty, "PropertyGroups");
            listView.GroupHeaderTemplate = new DataTemplate(typeof(GroupHeaderTemplate));
            listView.ItemTemplate        = new DataTemplate(typeof(DetailsItemTemplate));

            Content = new StackLayout
            {
                VerticalOptions = LayoutOptions.StartAndExpand,
                Children        = { headerView, listView }
            };
        }
示例#22
0
        void PhaseSwitchToggled(object sender, EventArgs e)
        {
            Switch @switch = sender as Switch;
            Phase  phase   = @switch.BindingContext as Phase;

            if (@switch.IsToggled)
            {
                if (!options.ChoosedPhase.Contains(phase.Id))
                {
                    options.ChoosedPhase.Add(phase.Id);
                    UpdateTactiques();
                }
            }
            else
            {
                if (options.ChoosedPhase.Contains(phase.Id))
                {
                    options.ChoosedPhase.Remove(phase.Id);
                    UpdateTactiques();
                }
            }
        }
示例#23
0
        public static FrameworkElement Render(TypedElement element, RenderContext context)
        {
            ToggleInput input = (ToggleInput)element;

            if (context.Config.SupportsInteractivity)
            {
                var uiToggle = new CheckBox();
#if WPF
                // TODO: Finish switch
                uiToggle.Content = input.Title;
#endif
                uiToggle.SetState(input.Value == (input.ValueOn ?? "true"));
                uiToggle.Style = context.GetStyle($"Adaptive.Input.Toggle");
                uiToggle.SetContext(input);
                context.InputBindings.Add(input.Id, () =>
                {
                    return(uiToggle.GetState() == true ? input.ValueOn ?? "true" : input.ValueOff ?? "false");
                });
                return(uiToggle);
            }
            else
            {
                Container container = TypedElementConverter.CreateElement <Container>();
                container.Separation = input.Separation;

                TextBlock textBlock = TypedElementConverter.CreateElement <TextBlock>();
                textBlock.Text = XamlUtilities.GetFallbackText(input);
                container.Items.Add(textBlock);
                if (input.Value != null)
                {
                    textBlock       = TypedElementConverter.CreateElement <TextBlock>();
                    textBlock.Text  = (input.Value == (input.ValueOn ?? "true")) ? input.ValueOn ?? "selected" : input.ValueOff ?? "not selected";
                    textBlock.Color = TextColor.Accent;
                    textBlock.Wrap  = true;
                    container.Items.Add(textBlock);
                }
                return(context.Render(container));
            }
        }
		public VectorSpeechBubblePage ()
		{
			this.Title = "Vector Speech Bubble";
			this.BackgroundColor = ColorHelper.MyLightBlue.ToFormsColor();

			var bubble = new VectorSpeechBubble {
				Text = "Hello there. Do you have a minute to talk?",
				ArrowDirection = ArrowDirections.RightBottom,
				BorderColor = Color.White,
				BorderWidth = 4d,
				// Padding = new Thickness(8d,8d,8d,8d),	// TODO: Auto calculate padding based on the arrow direction and size.  This padding should be in addition to
				HasShadow = true,
				HorizontalOptions = LayoutOptions.Start,
				VerticalOptions = LayoutOptions.Start,
			};

			var arrowDirectionPicker = new Picker { 
				HorizontalOptions = LayoutOptions.End, 
				WidthRequest=150d,
			};
			foreach (var direction in System.Enum.GetNames(typeof(ArrowDirections))) {
				arrowDirectionPicker.Items.Add (direction);
			}
			arrowDirectionPicker.SelectedIndex = arrowDirectionPicker.Items.IndexOf (ArrowDirections.RightBottom.ToString());

			arrowDirectionPicker.SelectedIndexChanged += (object sender, System.EventArgs e) => {
				var selectedValue = arrowDirectionPicker.Items[arrowDirectionPicker.SelectedIndex];
				var direction = (ArrowDirections)System.Enum.Parse(typeof(ArrowDirections), selectedValue);
				bubble.ArrowDirection = direction;
			};

			var shadowSwitch = new Switch() { HorizontalOptions = LayoutOptions.End, WidthRequest=150d };

			var fillColorPicker = new ColorPicker () { HorizontalOptions = LayoutOptions.End, WidthRequest=150d };
			fillColorPicker.SelectedColor = Color.Silver;

			var gradientColorPicker = new ColorPicker () { HorizontalOptions = LayoutOptions.End, WidthRequest=150d };
			gradientColorPicker.SelectedColor = Color.Default;

			var borderColorPicker = new ColorPicker () { HorizontalOptions = LayoutOptions.End, WidthRequest=150d };
			borderColorPicker.SelectedColor = Color.Purple;

			var borderWidthSlider = new Slider (0d, 100d, 4d) { HorizontalOptions = LayoutOptions.End, WidthRequest=150d };
			var cornerRadiusSlider = new Slider (0d, 50d, 10d) { HorizontalOptions = LayoutOptions.End, WidthRequest=150d };

			var widthSlider = new Slider {
				Minimum = 0d,
				Maximum = Application.Current.MainPage.Width - 20d,
				Value = Application.Current.MainPage.Width,
				HorizontalOptions = LayoutOptions.End,
				WidthRequest = 150d,
			};
			var heightSlider = new Slider {
				Minimum = 0d,
				Maximum = 300d,
				Value = 50d,
				HorizontalOptions = LayoutOptions.End,
				WidthRequest = 150d,
			};

			var sliderLabelStyle = new Style (typeof(Label)) {
				Setters = {
					new Setter {Property=Label.FontProperty, Value= Font.SystemFontOfSize (NamedSize.Micro)},
					new Setter {Property=Label.YAlignProperty, Value=TextAlignment.Center},
				},
			};
			var borderWidthLabel = new Label { Style= sliderLabelStyle};
			var cornerRadiusLabel = new Label { Style= sliderLabelStyle};	// new Label { Font = Font.SystemFontOfSize (NamedSize.Micro), YAlign = TextAlignment.Center };
			var heightLabel = new Label { Style= sliderLabelStyle};			// new Label { Font = Font.SystemFontOfSize (NamedSize.Micro), YAlign = TextAlignment.Center };
			var widthLabel = new Label { Style= sliderLabelStyle};	// new Label { Font = Font.SystemFontOfSize (NamedSize.Micro), YAlign = TextAlignment.Center };

			this.Content = new ScrollView {
				Content = new StackLayout {
					Padding = new Thickness(4d,4d,4d,4d),
					Spacing = 4d,
					Children = {
						new StackLayout {
							Orientation = StackOrientation.Horizontal,
							Children = {
								new Label { Text = "Arrow Direction", HorizontalOptions = LayoutOptions.FillAndExpand, YAlign = TextAlignment.Center },
								arrowDirectionPicker,
							}
						},
						new StackLayout {
							Orientation = StackOrientation.Horizontal,
							Children = {
								new Label { Text = "Has Shadow", HorizontalOptions = LayoutOptions.FillAndExpand, YAlign = TextAlignment.Center },
								shadowSwitch,
							}
						},
						new StackLayout {
							Orientation = StackOrientation.Horizontal,
							Children = {
								new Label { Text = "Fill Color", HorizontalOptions = LayoutOptions.FillAndExpand, YAlign = TextAlignment.Center },
								fillColorPicker,
							}
						},
						new StackLayout {
							Orientation = StackOrientation.Horizontal,
							Children = {
								new Label { Text = "Gradient Color", HorizontalOptions = LayoutOptions.FillAndExpand, YAlign = TextAlignment.Center },
								gradientColorPicker,
							}
						},
						new StackLayout {
							Orientation = StackOrientation.Horizontal,
							Children = {
								new Label { Text = "Border Color", HorizontalOptions = LayoutOptions.FillAndExpand, YAlign = TextAlignment.Center },
								borderColorPicker,
							}
						},
						new StackLayout {
							Orientation = StackOrientation.Horizontal,
							Children = {
								new Label { Text = "Border Width", HorizontalOptions = LayoutOptions.FillAndExpand, YAlign = TextAlignment.Center },
								borderWidthLabel,
								borderWidthSlider,
							}
						},
						new StackLayout {
							Orientation = StackOrientation.Horizontal,
							Children = {
								new Label { Text = "Corner Radius", HorizontalOptions = LayoutOptions.FillAndExpand, YAlign = TextAlignment.Center },
								cornerRadiusLabel,
								cornerRadiusSlider,
							}
						},
						new StackLayout {
							Orientation = StackOrientation.Horizontal,
							Children = {
								new Label { Text = "Width", HorizontalOptions = LayoutOptions.FillAndExpand, YAlign = TextAlignment.Center },
								widthLabel,
								widthSlider,
							}
						},
						new StackLayout {
							Orientation = StackOrientation.Horizontal,
							Children = {
								new Label { Text = "Height", HorizontalOptions = LayoutOptions.FillAndExpand, YAlign = TextAlignment.Center },
								heightLabel,
								heightSlider,
							}
						},
						new BoxView { HeightRequest = 12d }, // For some additional spacing
						bubble,
					},
				}
			};

			bubble.SetBinding(VectorSpeechBubble.FillColorProperty, new Binding("SelectedColor", BindingMode.OneWay, source:fillColorPicker));
			bubble.SetBinding(VectorSpeechBubble.GradientFillColorProperty, new Binding("SelectedColor", BindingMode.OneWay, source:gradientColorPicker));
			bubble.SetBinding(VectorSpeechBubble.BorderColorProperty, new Binding("SelectedColor", BindingMode.OneWay, source:borderColorPicker));
			bubble.SetBinding(VectorSpeechBubble.BorderWidthProperty, new Binding("Value", BindingMode.TwoWay, source:borderWidthSlider));
			bubble.SetBinding(VectorSpeechBubble.CornerRadiusProperty, new Binding("Value", BindingMode.TwoWay, source:cornerRadiusSlider));
		
			bubble.SetBinding(VectorSpeechBubble.WidthRequestProperty, new Binding("Value", BindingMode.TwoWay, source:widthSlider));
			bubble.SetBinding(VectorSpeechBubble.HeightRequestProperty, new Binding("Value", BindingMode.TwoWay, source:heightSlider));
			bubble.SetBinding(VectorSpeechBubble.HasShadowProperty, new Binding("IsToggled", BindingMode.TwoWay, source:shadowSwitch));

			borderWidthLabel.SetBinding(Label.TextProperty, new Binding("Value", BindingMode.OneWay, source:borderWidthSlider, stringFormat:"{0:0.0}"));
			cornerRadiusLabel.SetBinding(Label.TextProperty, new Binding("Value", BindingMode.OneWay, source:cornerRadiusSlider, stringFormat:"{0:0.0}"));
			heightLabel.SetBinding(Label.TextProperty, new Binding("Value", BindingMode.OneWay, source:heightSlider));
			widthLabel.SetBinding(Label.TextProperty, new Binding("Value", BindingMode.OneWay, source:widthSlider));
		}
示例#25
0
        protected override void OnAppearing()
        {
            base.OnAppearing();

            idx        = ((Todo)this.BindingContext).Idx;
            projectIdx = ((Todo)BindingContext).ProjectIdx;
            dao        = new ProjectDao(projectIdx);

            Title = (idx == -1) ? "New Todo" : "Edit Todo";

            var nameLbl = new Label {
                Text = "Name"
            };
            var nameEntry = new Entry();

            nameEntry.SetBinding(Entry.TextProperty, "Name");

            var contentLbl = new Label {
                Text = "Content"
            };
            var contentEntry = new Editor();

            contentEntry.SetBinding(Editor.TextProperty, "Content");

            var deadlineLbl = new Label {
                Text = "Deadline"
            };
            var deadlinePicker = new DatePicker();

            deadlinePicker.SetBinding(DatePicker.DateProperty, "DeadLine");

            var essentialLbl = new Label {
                Text = "Essential"
            };
            var essentialEntry = new Xamarin.Forms.Switch();

            essentialEntry.SetBinding(Switch.IsToggledProperty, "IsEssential");

            var progressLbl = new Label {
                Text = "Progress"
            };

            progressEntry = new Xamarin.Forms.Picker()
            {
                Items =
                {
                    "Before Starting", "Proceeding", "END"
                }
            };
            if (idx != -1)
            {
                string tmp = ((Todo)BindingContext).Progress;

                progressEntry.SelectedIndex = (tmp == "B") ? 0 : (tmp == "P") ? 1 : 2;
            }

            var managerLbl = new Label {
                Text = "Manager"
            };

            getManagers();

            var saveButton = new Button {
                Text = "Save"
            };

            saveButton.Clicked += SaveButton_Clicked;

            var deleteButton = new Button {
                Text = "Delete"
            };

            deleteButton.Clicked += DeleteButton_Clicked;

            var cancelButton = new Button {
                Text = "Cancel"
            };

            cancelButton.Clicked += CancelButton_Clicked;

            var layout = new StackLayout
            {
                VerticalOptions = LayoutOptions.StartAndExpand,
//				Padding = new Thickness(20),
                Children =
                {
                    nameLbl,      nameEntry,
                    contentLbl,   contentEntry,
                    deadlineLbl,  deadlinePicker,
                    essentialLbl, essentialEntry,
                    progressLbl,  progressEntry,
                    managerLbl,   managerEntry,
                    saveButton,   cancelButton,
                }
            };

            if (idx != -1)
            {
                layout.Children.Add(deleteButton);
            }

            ScrollView scrollView = new ScrollView();

            scrollView.Content = layout;

            Content = scrollView;
        }
示例#26
0
        public DayPartGame()
        {
            Xamarin.Forms.Label titlelabel = new Xamarin.Forms.Label();
            titlelabel.Text = "День";
            titlelabel.HorizontalTextAlignment = TextAlignment.Center;
            titlelabel.TextColor             = Color.Red;
            titlelabel.FontSize              = 18;
            titlelabel.BackgroundColor       = Color.White;
            titlelabel.HeightRequest         = 25;
            titlelabel.WidthRequest          = 150;
            titlelabel.VerticalTextAlignment = TextAlignment.Center;

            Xamarin.Forms.Grid timergrid = new Grid()
            {
                VerticalOptions = LayoutOptions.Fill,

                RowDefinitions =
                {
                    new RowDefinition {
                        Height = 35
                    }
                },

                ColumnDefinitions =
                {
                    new ColumnDefinition {
                        Width = 50
                    },
                    new ColumnDefinition {
                        Width = 50
                    },
                    new ColumnDefinition {
                        Width = 100
                    },
                    new ColumnDefinition {
                        Width = 30
                    },
                    new ColumnDefinition {
                        Width = 30
                    },
                    new ColumnDefinition {
                        Width = 30
                    },
                    new ColumnDefinition {
                        Width = 30
                    }
                }
            };
            //  Device.StartTimer(TimeSpan interval, Func < bool > callback);
            timergrid.Children.Add(swichtimer = new Switch  {
                IsToggled         = true,
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.CenterAndExpand
            }, 0, 0);


            timergrid.Children.Add(switchlbl = new Label
            {
                VerticalTextAlignment = TextAlignment.Start,
                BackgroundColor       = Color.White,
                TextColor             = Color.Red,
                FontSize      = 14,
                Text          = "1 хв",
                HeightRequest = 35,
                WidthRequest  = 50
            }, 1, 0);

            timergrid.Children.Add(timerlbl = new Label
            {
                VerticalTextAlignment = TextAlignment.Start,
                BackgroundColor       = Color.White,
                TextColor             = Color.Red,
                FontSize      = 14,
                Text          = "",
                HeightRequest = 35,
                WidthRequest  = 50
            }, 2, 0);

            timergrid.Children.Add(goBtn = new Button {
                Text            = "G",
                TextColor       = Color.Black,
                BorderColor     = Color.Red,
                BorderRadius    = 20,
                BackgroundColor = Color.White,
                WidthRequest    = 25
            }, 3, 0);

            timergrid.Children.Add(stopBtn = new Button
            {
                Text            = "S",
                TextColor       = Color.Black,
                BorderColor     = Color.Red,
                BorderRadius    = 20,
                BackgroundColor = Color.White,
                WidthRequest    = 25
            }, 4, 0);

            timergrid.Children.Add(pauseBtn = new Button
            {
                Text            = "P",
                TextColor       = Color.Black,
                BorderColor     = Color.Red,
                BorderRadius    = 20,
                BackgroundColor = Color.White,
                WidthRequest    = 25
            }, 5, 0);

            timergrid.Children.Add(nullBtn = new Button
            {
                Text            = "N",
                TextColor       = Color.Black,
                BorderColor     = Color.Red,
                BorderRadius    = 20,
                BackgroundColor = Color.White,
                WidthRequest    = 25
            }, 6, 0);



            Xamarin.Forms.Grid grid = new Grid()
            {
                VerticalOptions = LayoutOptions.Fill,

                RowDefinitions =
                {
                    new RowDefinition {
                        Height = 35
                    },
                    new RowDefinition {
                        Height = 35
                    },
                    new RowDefinition {
                        Height = 35
                    },
                    new RowDefinition {
                        Height = 35
                    },
                    new RowDefinition {
                        Height = 35
                    },
                    new RowDefinition {
                        Height = 35
                    },
                    new RowDefinition {
                        Height = 35
                    },
                    new RowDefinition {
                        Height = 35
                    },
                    new RowDefinition {
                        Height = 35
                    },
                    new RowDefinition {
                        Height = 35
                    }
                },

                ColumnDefinitions =
                {
                    new ColumnDefinition {
                        Width = 20
                    },
                    new ColumnDefinition {
                        Width = 160
                    },
                    new ColumnDefinition {
                        Width = 100
                    },
                    new ColumnDefinition {
                        Width = 80
                    },
                }
            };


            for (int i = 0; i < 10; i++)
            {
                grid.Children.Add(new Xamarin.Forms.Label
                {
                    VerticalTextAlignment = TextAlignment.Center,
                    BackgroundColor       = Color.White,
                    TextColor             = Color.Red,
                    Text          = (i + 1).ToString(),
                    FontSize      = 14,
                    HeightRequest = 35,
                    WidthRequest  = 50
                }, 0, i);
            }



            for (int i = 0; i < 10; i++)
            {
                grid.Children.Add(new Entry
                {
                    HeightRequest           = 16,
                    WidthRequest            = 151,
                    TextColor               = Color.Red,
                    FontSize                = 14,
                    HorizontalTextAlignment = TextAlignment.Start,
                    Placeholder             = "Player_" + (i + 1).ToString(),
                    PlaceholderColor        = Color.Black
                }, 1, i);
            }

            for (int i = 0; i < 10; i++)
            {
                grid.Children.Add(new Xamarin.Forms.Label
                {
                    BackgroundColor = Color.White,
                    TextColor       = Color.Red,
                    HeightRequest   = 25,
                    WidthRequest    = 70,
                    Text            = i.ToString() + " фол"
                }, 2, i);
            }

            for (int i = 0; i < 10; i++)
            {
                grid.Children.Add(btn = new Button
                {
                    BorderColor     = Color.Red,
                    BorderRadius    = 3,
                    BackgroundColor = Color.White,
                    TextColor       = Color.Red,
                    Text            = "Action",
                    FontSize        = 14,
                    HeightRequest   = 35,
                    WidthRequest    = 50,
                }, 3, i);
            }

            swichtimer.Toggled += Swichtimer_Toggled;
            goBtn.Clicked      += GoBtn_Clicked;
            pauseBtn.Clicked   += PauseBtn_Clicked;
            stopBtn.Clicked    += StopBtn_Clicked;
            nullBtn.Clicked    += NullBtn_Clicked;

            StackLayout stackLayout = new StackLayout()
            {
                Children = { timergrid, titlelabel, grid }
            };

            stackLayout.Orientation = StackOrientation.Vertical;
            stackLayout.Spacing     = 8;
            stackLayout.Margin      = 10;
            this.Content            = stackLayout;
        }
示例#27
0
        public void populateMyEventsGrid()
        {
            myEventsGrid.Children.Clear();

            GlobalVariables.storedEvents.Sort((x, y) => x.getName().CompareTo(y.getName()));

            //add events to grid
            int   row           = 0;
            int   myEventsIndex = 0;
            Event currentEvent;

            while (myEventsIndex < GlobalVariables.myEvents.Count())
            {
                currentEvent = null;
                currentEvent = GlobalVariables.myEvents[myEventsIndex++];

                Button deleteButton = new Button();
                deleteButton.VerticalOptions   = LayoutOptions.Center;
                deleteButton.HorizontalOptions = LayoutOptions.Center;
                deleteButton.Opacity           = 0.4;
                deleteButton.HeightRequest     = 30;

                deleteButton.Clicked += currentEvent.DeleteButton_Clicked;
                deleteButton.Clicked += DeleteButton_Clicked;

                Image deleteButtonImage = new Image();
                deleteButtonImage.Source            = "DeleteButton.png";
                deleteButtonImage.Aspect            = Aspect.AspectFill;
                deleteButtonImage.HorizontalOptions = LayoutOptions.Center;
                deleteButtonImage.VerticalOptions   = LayoutOptions.Center;
                deleteButtonImage.HeightRequest     = 30;

                StackLayout stack = new StackLayout();
                stack.HorizontalOptions = LayoutOptions.FillAndExpand;
                stack.VerticalOptions   = LayoutOptions.FillAndExpand;

                Label eventLabel = new Label();
                eventLabel.Text = currentEvent.getName();
                eventLabel.HorizontalTextAlignment = TextAlignment.Start;
                eventLabel.HorizontalOptions       = Xamarin.Forms.LayoutOptions.Start;
                eventLabel.VerticalOptions         = Xamarin.Forms.LayoutOptions.EndAndExpand;
                eventLabel.FontSize  = 16;
                eventLabel.TextColor = Color.Black;

                Label dateLabel = new Label();
                dateLabel.Text = currentEvent.getDate().ToString("MMMM d, yyyy");
                dateLabel.HorizontalOptions = Xamarin.Forms.LayoutOptions.Start;
                dateLabel.VerticalOptions   = Xamarin.Forms.LayoutOptions.StartAndExpand;
                dateLabel.FontSize          = 13;
                dateLabel.TextColor         = Xamarin.Forms.Color.Black;

                stack.Children.Add(eventLabel);
                stack.Children.Add(dateLabel);

                Xamarin.Forms.Switch visibleSwitch = new Xamarin.Forms.Switch();
                visibleSwitch.HorizontalOptions = Xamarin.Forms.LayoutOptions.EndAndExpand;
                visibleSwitch.VerticalOptions   = Xamarin.Forms.LayoutOptions.Center;
                visibleSwitch.Toggled          += currentEvent.VisibleSwitch_Toggled;
                visibleSwitch.IsToggled         = currentEvent.isVisible();

                //add grid's back color
                BoxView backColor = new BoxView();
                backColor.HorizontalOptions = Xamarin.Forms.LayoutOptions.FillAndExpand;
                backColor.Color             = Color.LightSteelBlue;

                myEventsGrid.Children.Add(backColor, 0, 3, row, row + 1);
                myEventsGrid.Children.Add(deleteButtonImage, 0, row);
                myEventsGrid.Children.Add(deleteButton, 0, row);
                myEventsGrid.Children.Add(stack, 1, row);
                myEventsGrid.Children.Add(visibleSwitch, 2, row);

                row++;
            }
        }
示例#28
0
        private void ReadQuiz()
        {
            string jsonString = returnJsonString();

            //COnvert the JSON String into a list of objects
            List <RootObject> result = (List <RootObject>)JsonConvert.DeserializeObject(jsonString, typeof(List <RootObject>));

            foreach (var question in result)
            {
                //Only get the results from the corresponding quiz
                if (question.id == ChooseQuiz.quizIdClicked)
                {
                    //This foreach populates only the quesion header
                    foreach (var item in question.questions)
                    {
                        Label questionId = new Label();
                        questionId.Text           = ("Question: " + item.id + " - " + item.text).ToString();
                        questionId.FontSize       = Device.GetNamedSize(NamedSize.Medium, typeof(Label));
                        questionId.FontAttributes = FontAttributes.Bold;

                        Label help = new Label();
                        help.Text = ("Hint: " + item.help);

                        ViewCellHeader = new ViewCell()
                        {
                            View = new StackLayout
                            {
                                Margin          = new Thickness(0, 10, 0, 0),
                                Orientation     = StackOrientation.Vertical,
                                VerticalOptions = LayoutOptions.Center,
                                Children        =
                                {
                                    new StackLayout
                                    {
                                        Orientation = StackOrientation.Vertical,
                                        Children    =
                                        {
                                            questionId,
                                            help
                                        }
                                    }
                                }
                            }
                        };


                        //This manages the date fields and textboxes
                        if (item.type == "date" || item.type == "Date" || item.type == "textbox")
                        {
                            //For single Line entries
                            Entry singleLineEntry = new Entry();

                            //Get existing data from saved file (if it exists)
                            singleLineEntry.Text = myAnswerManager.ProvideAnswerText(item.id);

                            ViewCell ViewCellAnswer = new ViewCell()
                            {
                                View = new StackLayout
                                {
                                    Orientation     = StackOrientation.Vertical,
                                    VerticalOptions = LayoutOptions.Center,
                                    Children        =
                                    {
                                        singleLineEntry
                                    }
                                }
                            };

                            //Update the Answers if the user leaves the UI element
                            singleLineEntry.Unfocused += (sender, e) =>
                            {
                                myAnswerManager.UpdateAnswerList(item.id, false, false, singleLineEntry.Text);
                            };

                            section.Add(ViewCellHeader);
                            section.Add(ViewCellAnswer);
                        }

                        //this manages the textareas
                        if (item.type == "textarea")
                        {
                            //For single Line entries
                            Editor multilineEditor = new Editor {
                                HeightRequest = 50
                            };

                            //Get existing data from saved file (if it exists)
                            multilineEditor.Text = myAnswerManager.ProvideAnswerText(item.id);

                            ViewCell ViewCellAnswer = new ViewCell()
                            {
                                View = new StackLayout
                                {
                                    Orientation = StackOrientation.Vertical,
                                    Children    =
                                    {
                                        multilineEditor
                                    }
                                }
                            };

                            //Update the Answers if the user leaves the UI element
                            multilineEditor.Unfocused += (sender, e) =>
                            {
                                myAnswerManager.UpdateAnswerList(item.id, false, false, multilineEditor.Text);
                            };

                            section.Add(ViewCellHeader);
                            section.Add(ViewCellAnswer);
                        }



                        if (item.type == "choice" || item.type == "options")
                        {
                            Picker pickerView = new Picker
                            {
                                Title           = "Pick one",
                                BackgroundColor = Xamarin.Forms.Color.LightGray,
                                VerticalOptions = LayoutOptions.Center
                            };

                            foreach (var pickerItem in item.options)
                            {
                                pickerView.Items.Add(pickerItem);
                            }

                            //Get existing data from saved file (if it exists)
                            String answerText = myAnswerManager.ProvideAnswerText(item.id);

                            if (answerText != "")
                            {
                                pickerView.SelectedIndex = Convert.ToInt32(answerText);
                            }

                            ViewCell ViewCellAnswer = new ViewCell()
                            {
                                View = new StackLayout
                                {
                                    Orientation = StackOrientation.Vertical,
                                    Children    =
                                    {
                                        pickerView
                                    }
                                }
                            };

                            //Update the Answers if the user leaves the UI element
                            pickerView.Unfocused += (sender, e) =>
                            {
                                myAnswerManager.UpdateAnswerList(item.id, false, false, pickerView.SelectedIndex.ToString());
                            };

                            section.Add(ViewCellHeader);
                            section.Add(ViewCellAnswer);
                        }

                        if (item.type == "slidingoption")
                        {
                            //Get existing data from saved file (if it exists)
                            String answerText     = myAnswerManager.ProvideAnswerText(item.id);
                            float  answerPosition = 1.0f;

                            if (answerText != "")
                            {
                                answerPosition = float.Parse(answerText);
                            }

                            sliderView = new Slider
                            {
                                Minimum         = 0.0f,
                                Maximum         = 2.0f,
                                Value           = answerPosition,
                                VerticalOptions = LayoutOptions.Center
                            };

                            OptionItems      = new List <string>();
                            OptionItemsImage = new List <string>();

                            foreach (var optionItem in item.options)
                            {
                                OptionItems.Add(optionItem);
                            }

                            foreach (var optionItem in item.optionVisuals)
                            {
                                OptionItemsImage.Add(optionItem);
                            }

                            sliderPositionText = new Label
                            {
                                Text = OptionItems[Convert.ToInt32(sliderView.Value)]
                            };

                            sliderPositionImage = new Label
                            {
                                Text = OptionItemsImage[Convert.ToInt32(sliderView.Value)]
                            };

                            //Update the Answers if the user changes theslider value
                            sliderView.ValueChanged += (sender, e) =>
                            {
                                //https://forums.xamarin.com/discussion/22473/can-you-limit-a-slider-to-only-allow-integer-values-hopefully-snapping-to-the-next-integer
                                var newStep = Math.Round(e.NewValue / 1.0);

                                sliderView.Value = newStep * 1.0;

                                sliderPositionText.Text  = OptionItems[Convert.ToInt32(sliderView.Value)];
                                sliderPositionImage.Text = OptionItemsImage[Convert.ToInt32(sliderView.Value)];

                                myAnswerManager.UpdateAnswerList(item.id, false, false, sliderView.Value.ToString());
                            };

                            ViewCell ViewCellAnswer = new ViewCell()
                            {
                                View = new StackLayout
                                {
                                    Orientation = StackOrientation.Vertical,
                                    Children    =
                                    {
                                        sliderView,
                                        sliderPositionText,
                                        sliderPositionImage
                                    }
                                }
                            };

                            section.Add(ViewCellHeader);
                            section.Add(ViewCellAnswer);
                        }

                        if (item.type == "scale")
                        {
                            //Get existing data from saved file (if it exists)
                            String answerText     = myAnswerManager.ProvideAnswerText(item.id);
                            double answerPosition = Convert.ToDouble(item.end * 0.5f);

                            if (answerText != "")
                            {
                                answerPosition = double.Parse(answerText);
                            }

                            Stepper stepperView = new Stepper
                            {
                                Minimum         = Convert.ToDouble(item.start),
                                Maximum         = Convert.ToDouble(item.end),
                                Value           = answerPosition,
                                VerticalOptions = LayoutOptions.Center,
                                Increment       = Convert.ToDouble(item.increment)

                                                  //Here I was also wanting to utilise the colouring of the slider
                                                  //but I could not seem to bring up the MinimumTrackTintColor and
                                                  //MaximumTrackTintColor methods. If I could have done this then I
                                                  //would have applied the gradients.
                            };

                            Label stepperValue = new Label
                            {
                                Text = stepperView.Value.ToString()
                            };

                            StepperChange myStepperChange = new StepperChange();

                            myStepperChange.setLabel(stepperValue);

                            //This is a hack here. I did it this way so that multiple steppers do not interfere with each other
                            stepperView.ValueChanged += (sender, e) =>
                            {
                                //See how I have pased on (sender, e)
                                myStepperChange.OnStepperValueChanged(sender, e);
                                myAnswerManager.UpdateAnswerList(item.id, false, false, stepperView.Value.ToString());
                            };

                            ViewCell ViewCellAnswer = new ViewCell()
                            {
                                View = new StackLayout
                                {
                                    Orientation = StackOrientation.Vertical,
                                    Children    =
                                    {
                                        stepperView,
                                        stepperValue
                                    }
                                }
                            };

                            section.Add(ViewCellHeader);
                            section.Add(ViewCellAnswer);
                        }


                        if (item.type == "multiplechoice")
                        {
                            //This approach was referenced from http://proquestcombo.safaribooksonline.com.ezproxy-b.deakin.edu.au/video/programming/mobile/9781771373371#

                            multipleChoiceAnswers = new List <MultipleChoiceAnswer>();

                            //Get existing data from saved file (if it exists) and load into a List
                            foreach (var optionItem in item.options)
                            {
                                multipleChoiceAnswers.Add(new MultipleChoiceAnswer(optionItem, myAnswerManager.ProvideAnswerMultipleChoice(item.id, optionItem)));
                            }

                            ListView listView = new ListView
                            {
                                ItemsSource = multipleChoiceAnswers,

                                ItemTemplate = new DataTemplate(() => {
                                    Label lblDescription = new Label();
                                    lblDescription.SetBinding(Label.TextProperty, "Description");

                                    Label lblIsChecked = new Label();
                                    lblIsChecked.SetBinding(Label.TextProperty, "IsCheckedString");

                                    Xamarin.Forms.Switch swIsChecked = new Xamarin.Forms.Switch();
                                    swIsChecked.SetBinding(Xamarin.Forms.Switch.IsToggledProperty, "isChecked");

                                    //Update the Answers if the user changes the UI element
                                    swIsChecked.Toggled += (sender, e) => // I got this line from https://stackoverflow.com/questions/32975894/xamarin-forms-switch-sends-toggled-event-when-value-is-updated
                                    {
                                        if (e != null)
                                        {
                                            var optionText = lblDescription.Text;

                                            foreach (var multianswer in multipleChoiceAnswers)
                                            {
                                                if (multianswer.Description == optionText)
                                                {
                                                    if (multianswer.isChecked == true)
                                                    {
                                                        multianswer.isChecked = false;
                                                        //Save the toggle
                                                        myAnswerManager.UpdateAnswerList(item.id, true, false, lblDescription.Text);
                                                    }
                                                    else
                                                    {
                                                        multianswer.isChecked = true;
                                                        //Save the toggle
                                                        myAnswerManager.UpdateAnswerList(item.id, true, true, lblDescription.Text);
                                                    }
                                                    lblIsChecked.Text = multianswer.IsCheckedString;
                                                }
                                            }
                                        }
                                    };

                                    return(new ViewCell
                                    {
                                        Height = 100,
                                        View = new StackLayout
                                        {
                                            Orientation = StackOrientation.Horizontal,
                                            HorizontalOptions = LayoutOptions.StartAndExpand,
                                            Children =
                                            {
                                                new StackLayout {
                                                    VerticalOptions = LayoutOptions.Center,
                                                    Spacing = 0,
                                                    Children =
                                                    {
                                                        swIsChecked
                                                    }
                                                },
                                                new StackLayout {
                                                    VerticalOptions = LayoutOptions.Center,
                                                    Spacing = 0,
                                                    Children =
                                                    {
                                                        lblDescription,
                                                        lblIsChecked
                                                    }
                                                }
                                            }
                                        }
                                    });
                                }


                                                                )
                            };


                            ViewCell ViewCellAnswer = new ViewCell()
                            {
                                View = new StackLayout
                                {
                                    Orientation = StackOrientation.Vertical,
                                    Children    =
                                    {
                                        listView
                                    }
                                }
                            };

                            section.Add(ViewCellHeader);
                            section.Add(ViewCellAnswer);
                        }
                    }
                }
            }
            tblQuizes.Root.Add(section);
        }
		public TodoItemPage ()
		{
			this.SetBinding (ContentPage.TitleProperty, "Name");

			NavigationPage.SetHasNavigationBar (this, true);
			var nameLabel = new Label (); // no Text! localized later
			var nameEntry = new Entry ();
			
			nameEntry.SetBinding (Entry.TextProperty, "Name");

			var notesLabel = new Label (); // no Text! localized later
			var notesEntry = new Entry ();
			notesEntry.SetBinding (Entry.TextProperty, "Notes");

			var doneLabel = new Label (); // no Text! localized later
			var doneEntry = new Switch ();
			doneEntry.SetBinding (Switch.IsToggledProperty, "Done");

			var saveButton = new Button (); // no Text! localized later
			saveButton.Clicked += (sender, e) => {
				var todoItem = (TodoItem)BindingContext;
				App.Database.SaveItem(todoItem);
				this.Navigation.PopAsync();
			};

			var deleteButton = new Button (); // no Text! localized later
			deleteButton.Clicked += (sender, e) => {
				var todoItem = (TodoItem)BindingContext;
				App.Database.DeleteItem(todoItem.ID);
                this.Navigation.PopAsync();
			};
							
			var cancelButton = new Button (); // no Text! localized later
			cancelButton.Clicked += (sender, e) => {
                this.Navigation.PopAsync();
			};

			var speakButton = new Button (); // no Text! localized later
			speakButton.Clicked += (sender, e) => {
				var todoItem = (TodoItem)BindingContext;
				DependencyService.Get<ITextToSpeech>().Speak(todoItem.Name + " " + todoItem.Notes);
			};


			// TODO: Forms Localized text using two different methods:

			// refer to the codebehind for AppResources.resx.designer
			nameLabel.Text = AppResources.NameLabel;
			notesLabel.Text = AppResources.NotesLabel;
			doneLabel.Text = AppResources.DoneLabel;

			// using ResourceManager
			saveButton.Text = AppResources.SaveButton;
			deleteButton.Text = L10n.Localize ("DeleteButton", "Delete");
			cancelButton.Text = L10n.Localize ("CancelButton", "Cancel");
			speakButton.Text = L10n.Localize ("SpeakButton", "Speak");

			// HACK: included as a 'test' for localizing the picker
			// currently not saved to database
			//var dueDateLabel = new Label { Text = "Due" };
			//var dueDatePicker = new DatePicker ();

			Content = new StackLayout {
				VerticalOptions = LayoutOptions.StartAndExpand,
				Padding = new Thickness(20),
				Children = {
					nameLabel, nameEntry, 
					notesLabel, notesEntry,
					doneLabel, doneEntry,
					//dueDateLabel, dueDatePicker,
					saveButton, deleteButton, cancelButton, speakButton
				}
			};
		}
示例#30
0
        public void render_tasks()
        {
            //Get day of week 1-Monday, 7-Sunday
            int dayindex = ((int)DateTime.Now.DayOfWeek == 0) ? 7 : (int)DateTime.Now.DayOfWeek;

            string[] daynames = new string[7] {
                "Monday",
                "Tuesday",
                "Wednesday",
                "Thursday",
                "Friday",
                "Saturday",
                "Sunday"
            };
            string daystring = daynames[dayindex - 1];

            moveto_newtask += () => App.Current.MainPage = new NavigationPage(new NewHabitPage());

            var donetoggle = new Xamarin.Forms.Switch();
            var spacer     = new BoxView();

            Label greet = new Label()
            {
                Text              = String.Format("Hello, {0}.", Settings.GetUsername),
                TextColor         = Color.FromHex("#3aaa6a"),
                FontSize          = 32,
                FontAttributes    = FontAttributes.Bold,
                HorizontalOptions = LayoutOptions.Start
            };

            Label showday = new Label()
            {
                Text              = String.Format("Today is {0}.", daystring),
                TextColor         = Color.FromHex("#00b0cc"),
                FontSize          = 24,
                VerticalOptions   = LayoutOptions.Start,
                HorizontalOptions = LayoutOptions.Start
            };

            Grid.SetColumnSpan(greet, 3);
            Grid.SetColumnSpan(showday, 3);
            grid.Children.Add(greet, 1, 1);
            grid.Children.Add(showday, 1, 2);

            int    rowcnt   = 3;
            string taskdays = "";
            var    taskname = new Label();

            //Draw tasks
            foreach (var i in GetTasks())
            {
                bool istoday = false;
                System.Diagnostics.Debug.WriteLine("===== " + daystring);
                if (i.monday && daystring == "Monday")
                {
                    istoday = true;
                }
                if (i.tuesday && daystring == "Tuesday")
                {
                    istoday = true;
                }
                if (i.wednesday && daystring == "Wednesday")
                {
                    istoday = true;
                }
                if (i.thursday && daystring == "Thursday")
                {
                    istoday = true;
                }
                if (i.friday && daystring == "Friday")
                {
                    istoday = true;
                }
                if (i.saturday && daystring == "Saturday")
                {
                    istoday = true;
                }
                if (i.sunday && daystring == "Sunday")
                {
                    istoday = true;
                }

                if (!istoday)
                {
                    continue;
                }
                taskdays = "";

                /*
                 * for (int k = 0; k < 7; k++) {
                 *  if (i.daysofweek[k])
                 *      taskdays += daynames[k][0];
                 *  System.Diagnostics.Debug.WriteLine(i.daysofweek[k]);
                 * }
                 */
                grid.RowDefinitions.Add(new RowDefinition()
                {
                    Height = GridLength.Auto
                });

                taskname = new Label
                {
                    Text              = i.title,
                    TextColor         = Color.Black,
                    FontSize          = 18,
                    Margin            = 10,
                    HorizontalOptions = LayoutOptions.Start,
                    VerticalOptions   = LayoutOptions.CenterAndExpand
                };

                grid.Children.Add(taskname, 1, rowcnt);

                grid.Children.Add(new Label
                {
                    Text              = taskdays,
                    TextColor         = Color.FromHex("#00b0cc"),
                    FontSize          = 18,
                    Margin            = 10,
                    HorizontalOptions = LayoutOptions.Start,
                    VerticalOptions   = LayoutOptions.CenterAndExpand
                }, 2, rowcnt);

                grid.Children.Add(new Label
                {
                    Text              = i.TimesDone + "/" + i.goal,
                    TextColor         = Color.FromHex("#00b0cc"),
                    FontSize          = 18,
                    Margin            = 10,
                    HorizontalOptions = LayoutOptions.Start,
                    VerticalOptions   = LayoutOptions.CenterAndExpand
                }, 3, rowcnt);

                donetoggle = new Xamarin.Forms.Switch
                {
                    Margin            = 10,
                    HorizontalOptions = LayoutOptions.StartAndExpand,
                    VerticalOptions   = LayoutOptions.StartAndExpand
                };

                donetoggle.Toggled += (sender, e) => {
                    i.TimesDone++;
                    SaveTask(i);
                    //render_tasks();
                    System.Diagnostics.Debug.WriteLine("===== " + i.TimesDone);
                };

                grid.Children.Add(donetoggle, 4, rowcnt);

                rowcnt++;
                var task_tap = new TapGestureRecognizer();
                task_tap.Tapped += async(s, e) =>
                {
                    bool answer = await DisplayAlert("Confirmation", "Delete task '" + i.title + "'?", "DELETE", "KEEP");

                    if (answer)
                    {
                        i.active = false;
                        SaveTask(i);
                    }

                    //render_tasks();
                    System.Diagnostics.Debug.WriteLine("===== Deleted task: " + i.title);
                };
                taskname.GestureRecognizers.Add(task_tap);
            }

            //New task button
            grid.RowDefinitions.Add(new RowDefinition()
            {
                Height = 15
            });
            grid.RowDefinitions.Add(new RowDefinition()
            {
                Height = GridLength.Auto
            });

            Button button = new Button
            {
                Text              = "New Task",
                Command           = GoToHabit,
                BackgroundColor   = Color.FromHex("#cc2a45"),
                TextColor         = Color.White,
                VerticalOptions   = LayoutOptions.End,
                HorizontalOptions = LayoutOptions.Start,
            };

            Grid.SetColumnSpan(button, 2);
            grid.Children.Add(button, 1, rowcnt + 1);

            //Add cheesy quote
            var quote = new Label
            {
                Text              = "\n\nThe way get started is to quit talking and begin doing. \n\n– Walt Disney\n",
                FontSize          = 14,
                FontAttributes    = FontAttributes.Italic,
                TextColor         = Color.Gray,
                VerticalOptions   = LayoutOptions.Start,
                HorizontalOptions = LayoutOptions.End
            };

            Grid.SetColumnSpan(quote, 2);
            grid.Children.Add(quote, 1, rowcnt + 2);
        }
        public void InitControls(TreeMapPrItem navigationObjects)
        {
            {
                var navTree = GetNavMenuTree (navigationObjects);

                navControl.InitControl (navTree);
                navControl.SetBinding (ContentView.IsEnabledProperty, new Binding ("ShowLoadingAnimationInverted"));
            }

            if (Device.OS == TargetPlatform.Android) {
                {
                    var goalGroup = new BindableRadioGroup () { Orientation = StackOrientation.Horizontal };
                    goalGroup.ItemsSource = new List<string> () { "нефть", "обводненность" };
                    goalGroup.SelectedIndex = 1;
                    goalGroup.SelectedIndex = 0;
                    goalGroup.CheckedChanged += ViewModel.OnSelectedGoalChanged;
                    cnvGoal.Content = goalGroup;
                }

                {
                    var rowCountGroup = new BindableRadioGroup () { Orientation = StackOrientation.Horizontal };
                    rowCountGroup.ItemsSource = new List<string> () { "50", "100", "300" };
                    rowCountGroup.SelectedIndex = 1;
                    rowCountGroup.SelectedIndex = 0;
                    rowCountGroup.CheckedChanged += ViewModel.OnSelectedCountChanged;
                    cnvRowCount.Content = rowCountGroup;
                }

            } else {
                {
                    var goalSegmentView = new SegmentedControlView ();
                    goalSegmentView.SegmentsItens = "нефть;обводненность";
                    goalSegmentView.TintColor = Color.FromHex ("#4487CA");
                    goalSegmentView.PropertyChanged += OnGoalChanged;
                    cnvGoal.Content = goalSegmentView;
                }

                {
                    var rowCountSegmentView = new SegmentedControlView ();
                    rowCountSegmentView.SegmentsItens = "50;100;300";
                    rowCountSegmentView.TintColor = Color.FromHex ("#4487CA");
                    rowCountSegmentView.PropertyChanged += OnRowCountChanged;
                    cnvRowCount.Content = rowCountSegmentView;
                }
            }

            {
                Switch swt;
                if (Device.OS == TargetPlatform.Android) {
                    swt = new Switch (){ HorizontalOptions = LayoutOptions.End };
                } else {
                    swt = new ExtendedSwitch (){ HorizontalOptions = LayoutOptions.End, TintColor = Color.FromHex ("#D64B30") };
                }
                swt.SetBinding (Switch.IsToggledProperty, new Binding ("IsRedColor"));
                swt.SetBinding (View.IsEnabledProperty, new Binding ("ShowLoadingAnimationInverted"));

                Grid.SetColumn (swt, 2);
                grdRed.Children.Add (swt);
            }

            {
                Switch swt;
                if (Device.OS == TargetPlatform.Android) {
                    swt = new Switch (){ HorizontalOptions = LayoutOptions.End };
                } else {
                    swt = new ExtendedSwitch (){ HorizontalOptions = LayoutOptions.End, TintColor = Color.FromHex ("#189A55") };
                }
                swt.SetBinding (Switch.IsToggledProperty, new Binding ("IsGreenColor"));
                swt.SetBinding (View.IsEnabledProperty, new Binding ("ShowLoadingAnimationInverted"));

                Grid.SetColumn (swt, 2);
                grdGreen.Children.Add (swt);
            }

            {
                Switch swt;
                if (Device.OS == TargetPlatform.Android) {
                    swt = new Switch (){ HorizontalOptions = LayoutOptions.End };
                } else {
                    swt = new ExtendedSwitch (){ HorizontalOptions = LayoutOptions.End, TintColor = Color.FromHex ("#D1AA12") };
                }
                swt.SetBinding (Switch.IsToggledProperty, new Binding ("IsYellowColor"));
                swt.SetBinding (View.IsEnabledProperty, new Binding ("ShowLoadingAnimationInverted"));

                Grid.SetColumn (swt, 2);
                grdYellow.Children.Add (swt);
            }
        }
示例#32
0
        public GestureTestPage()
        {
            #region Page

            //var pageListener = FormsGestures.Listener.For(this);

            //pageListener.LongPressing += (s, e) => System.Diagnostics.Debug.WriteLine("\tPAGE LONG PRESSING");
            //pageListener.LongPressed += (s, e) => System.Diagnostics.Debug.WriteLine("\tPAGE LONG PRESSED");


            #endregion


            #region Delta vs Total Switch
            var totalSwitch = new Xamarin.Forms.Switch();
            #endregion


            #region Xamarin.Forms.Button
            var button = new Button
            {
                BackgroundColor = Color.Pink,
                Text            = "Hello",
                BorderColor     = Color.Blue,
                BorderWidth     = 3,
            };
            button.Clicked += (sender, e) => System.Diagnostics.Debug.WriteLine("\tBUTTON CLICKED!!!!");


            var buttonListener = FormsGestures.Listener.For(button);

            buttonListener.Down += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tBUTTON DOWN [" + e.Center(e.WindowTouches).ToString(format) + "][" + e.ElementTouches[0].ToString(format) + "][" + e.ElementPosition.ToString(format) + "]"); // does not work with UIControl derived elements
            };
            buttonListener.Up += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tBUTTON UP [" + e.Center(e.WindowTouches).ToString(format) + "][" + e.ElementTouches[0].ToString(format) + "][" + e.ElementPosition.ToString(format) + "]");      // does not work with UIControl derived elements
            };
            buttonListener.Tapping += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tBUTTON TAPPING #[" + e.NumberOfTaps + "] [" + e.Center(e.WindowTouches).ToString(format) + "][" + e.ElementTouches[0].ToString(format) + "][" + e.ElementPosition.ToString(format) + "]");
            };
            buttonListener.Tapped += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tBUTTON TAPPED #[" + e.NumberOfTaps + "] [" + e.Center(e.WindowTouches).ToString(format) + "][" + e.ElementTouches[0].ToString(format) + "][" + e.ElementPosition.ToString(format) + "]");  // does not work with UIControl derived elements
            };
            buttonListener.DoubleTapped += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tBUTTON DOUBLE TAPPED [" + e.Center(e.WindowTouches).ToString(format) + "][" + e.ElementTouches[0].ToString(format) + "][" + e.ElementPosition.ToString(format) + "]"); // does not work with UIControl derived elements
            };
            buttonListener.LongPressing += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tBUTTON LONG PRESSING [" + e.Center(e.WindowTouches).ToString(format) + "][" + e.ElementTouches[0].ToString(format) + "][" + e.ElementPosition.ToString(format) + "]");
            };
            buttonListener.LongPressed += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tBUTTON LONG PRESSED [" + e.Center(e.WindowTouches).ToString(format) + "][" + e.ElementTouches[0].ToString(format) + "][" + e.ElementPosition.ToString(format) + "]");
            };

            buttonListener.RightClicked += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tBUTTON RIGHT CLICK[" + e.Center(e.WindowTouches).ToString(format) + "][" + e.ElementTouches[0].ToString(format) + "][" + e.ElementPosition.ToString(format) + "]");
            };

            buttonListener.Panning += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tBUTTON PANNING [" + e.Center(e.WindowTouches).ToString(format) + "][" + e.ElementTouches[0].ToString(format) + "][" + e.ElementPosition.ToString(format) + "]");
                if (totalSwitch.IsToggled)
                {
                    button.TranslationX = e.TotalDistance.X;
                    button.TranslationY = e.TotalDistance.Y;
                }
                else
                {
                    button.TranslationX += e.DeltaDistance.X;
                    button.TranslationY += e.DeltaDistance.Y;
                }
            };
            buttonListener.Panned += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tBUTTON PANNED TotalDistance=[" + e.TotalDistance.ToString(format) + "][" + e.Center(e.WindowTouches).ToString(format) + "][" + e.ElementPosition.ToString(format) + "]");
                if (totalSwitch.IsToggled)
                {
                    button.TranslationX = 0;
                    button.TranslationY = 0;
                }
            };
            buttonListener.Swiped += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tBUTTON SWIPED!!! Velocity=[" + e.VelocityX.ToString(format) + "," + e.VelocityY.ToString(format) + "][" + e.Center(e.WindowTouches).ToString(format) + "][" + e.ElementPosition.ToString(format) + "]");
            };

            buttonListener.Pinching += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tBUTTON PINCHING [" + e.Center(e.WindowTouches).ToString(format) + "][" + e.ElementTouches[0].ToString(format) + "][" + e.ElementPosition.ToString(format) + "]");
                if (totalSwitch.IsToggled)
                {
                    button.Scale = e.TotalScale;
                }
                else
                {
                    button.Scale *= e.DeltaScale;
                }
            };
            buttonListener.Pinched += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tBUTTON PINCHED TotalScale=[" + e.TotalScale.ToString(format) + "][" + e.Center(e.WindowTouches).ToString(format) + "][" + e.ElementPosition.ToString(format) + "]");
                if (totalSwitch.IsToggled)
                {
                    button.Scale = 1;
                }
            };
            buttonListener.Rotating += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tBUTTON ROTATING [" + e.Center(e.WindowTouches).ToString(format) + "][" + e.ElementTouches[0].ToString(format) + "][" + e.ElementPosition.ToString(format) + "]");
                if (totalSwitch.IsToggled)
                {
                    button.Rotation = e.TotalAngle;
                }
                else
                {
                    button.Rotation += e.DeltaAngle;
                }
            };
            buttonListener.Rotated += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tBUTTON ROTATED TotalAngle=[" + e.TotalAngle.ToString(format) + "][" + e.Center(e.WindowTouches).ToString(format) + "][" + e.ElementPosition.ToString(format) + "]");
                if (totalSwitch.IsToggled)
                {
                    button.Rotation = 0;
                }
            };
            #endregion


            #region Forms9Patch.Frame
            var frame = new Forms9Patch.Frame
            {
                BackgroundColor = Color.Orange,
                WidthRequest    = 70,
                HeightRequest   = 70,
                HasShadow       = true,
                OutlineColor    = Color.Green,
                OutlineRadius   = 0,
                OutlineWidth    = 1,
                Content         = new Forms9Patch.Label {
                    Text = "pizza", TextColor = Color.White, BackgroundColor = Color.Blue, HorizontalOptions = LayoutOptions.Start, VerticalOptions = LayoutOptions.Start
                }
            };
            var frameListener = FormsGestures.Listener.For(frame);

            frameListener.Down += (sender, e) =>
            {
                e.Handled = true;
                System.Diagnostics.Debug.WriteLine("\tFRAME DOWN [" + e.Center(e.WindowTouches).ToString(format) + "][" + e.ElementTouches[0].ToString(format) + "][" + e.ElementPosition.ToString(format) + "]");
            };
            frameListener.Up += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tFRAME UP [" + e.Center(e.WindowTouches).ToString(format) + "][" + e.ElementTouches[0].ToString(format) + "][" + e.ElementPosition.ToString(format) + "]");
            };
            frameListener.Tapping += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tFRAME TAPPING #[" + e.NumberOfTaps + "] [" + e.Center(e.WindowTouches).ToString(format) + "][" + e.ElementTouches[0].ToString(format) + "][" + e.ElementPosition.ToString(format) + "]");
            };
            frameListener.Tapped += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tFRAME TAPPED #[" + e.NumberOfTaps + "] [" + e.Center(e.WindowTouches).ToString(format) + "][" + e.ElementTouches[0].ToString(format) + "][" + e.ElementPosition.ToString(format) + "]");
            };
            frameListener.DoubleTapped += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tFRAME DOUBLE TAPPED [" + e.Center(e.WindowTouches).ToString(format) + "][" + e.ElementTouches[0].ToString(format) + "][" + e.ElementPosition.ToString(format) + "]");
            };
            frameListener.LongPressing += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tFRAME LONG PRESSING [" + e.Center(e.WindowTouches).ToString(format) + "][" + e.ElementTouches[0].ToString(format) + "][" + e.ElementPosition.ToString(format) + "]");
            };
            frameListener.LongPressed += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tFRAME LONG PRESSED [" + e.Center(e.WindowTouches).ToString(format) + "][" + e.ElementTouches[0].ToString(format) + "][" + e.ElementPosition.ToString(format) + "]");
            };

            frameListener.RightClicked += (sender, e) => System.Diagnostics.Debug.WriteLine("\tFRAME RIGHT CLICK[" + e.Center(e.WindowTouches).ToString(format) + "][" + e.ElementTouches[0].ToString(format) + "][" + e.ElementPosition.ToString(format) + "]");

            frameListener.Panning += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tFRAME PANNING [" + e.Center(e.WindowTouches).ToString(format) + "][" + e.ElementTouches[0].ToString(format) + "][" + e.ElementPosition.ToString(format) + "]");
                if (totalSwitch.IsToggled)
                {
                    frame.TranslationX = e.TotalDistance.X;
                    frame.TranslationY = e.TotalDistance.Y;
                }
                else
                {
                    frame.TranslationX += e.DeltaDistance.X;
                    frame.TranslationY += e.DeltaDistance.Y;
                }
            };
            frameListener.Panned += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tFRAME PANNED TotalDistance=[" + e.TotalDistance.ToString(format) + "][" + e.Center(e.WindowTouches).ToString(format) + "][" + e.ElementPosition.ToString(format) + "]");
                if (totalSwitch.IsToggled)
                {
                    frame.TranslationX = 0;
                    frame.TranslationY = 0;
                }
            };
            frameListener.Swiped += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tFRAME SWIPED!!! Velocity=[" + e.VelocityX.ToString(format) + "," + e.VelocityY.ToString(format) + "][" + e.Center(e.WindowTouches).ToString(format) + "][" + e.ElementPosition.ToString(format) + "]");
            };

            frameListener.Pinching += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tFRAME PINCHING [" + e.Center(e.WindowTouches).ToString(format) + "][" + e.ElementTouches[0].ToString(format) + "][" + e.DeltaScale + "][" + e.ElementPosition.ToString(format) + "]");
                if (totalSwitch.IsToggled)
                {
                    frame.Scale = e.TotalScale;
                }
                else
                {
                    frame.Scale *= e.DeltaScale;
                }
            };
            frameListener.Pinched += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tFRAME PINCHED TotalScale=[" + e.TotalScale.ToString(format) + "][" + e.Center(e.WindowTouches).ToString(format) + "][" + e.ElementPosition.ToString(format) + "]");
                if (totalSwitch.IsToggled)
                {
                    frame.Scale = 1;
                }
            };
            frameListener.Rotating += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tFRAME ROTATING [" + e.Center(e.WindowTouches).ToString(format) + "][" + e.ElementTouches[0].ToString(format) + "][" + e.DeltaAngle + "][" + e.ElementPosition.ToString(format) + "]");
                if (totalSwitch.IsToggled)
                {
                    frame.Rotation = e.TotalAngle;
                }
                else
                {
                    frame.Rotation += e.DeltaAngle;
                }
            };
            frameListener.Rotated += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tFRAME ROTATED TotalAngle[" + e.TotalAngle.ToString(format) + "][" + e.Center(e.WindowTouches).ToString(format) + "][" + e.ElementPosition.ToString(format) + "]");
                if (totalSwitch.IsToggled)
                {
                    frame.Rotation = 0;
                }
            };

            #endregion


            #region Xamarin.Forms.BoxView
            var box = new BoxView
            {
                BackgroundColor = Color.Green,
            };
            var boxListener = FormsGestures.Listener.For(box);

            //boxListener.Down += OnDown;
            boxListener.Down += (sender, e) =>
            {
                e.Handled = true;
                System.Diagnostics.Debug.WriteLine("\tBOX DOWN [" + e.Center(e.WindowTouches).ToString(format) + "][" + e.WindowTouches[0].ToString(format) + "][" + e.ElementPosition.ToString(format) + "]");
                ShowTouches(e, Color.Red);
            };
            boxListener.Up += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tBOX UP [" + e.Center(e.WindowTouches).ToString(format) + "][" + e.ElementTouches[0].ToString(format) + "][" + e.ElementPosition.ToString(format) + "]");
                ShowTouches(e, Color.Blue);
            };

            boxListener.Tapping += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tBOX TAPPING #[" + e.NumberOfTaps + "] [" + e.Center(e.WindowTouches).ToString(format) + "][" + e.ElementTouches[0].ToString(format) + "][" + e.ElementPosition.ToString(format) + "]");
                ShowTouches(e, Color.Yellow);
            };
            boxListener.Tapped += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tBOX TAPPED #[" + e.NumberOfTaps + "] [" + e.Center(e.WindowTouches).ToString(format) + "][" + e.ElementTouches[0].ToString(format) + "][" + e.ElementPosition.ToString(format) + "]");
                ShowTouches(e, Color.Green);
            };
            boxListener.DoubleTapped += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tBOX DOUBLE TAPPED [" + e.Center(e.WindowTouches).ToString(format) + "][" + e.ElementTouches[0].ToString(format) + "][" + e.ElementPosition.ToString(format) + "]");
                ShowTouches(e, Color.Orange);
            };
            boxListener.LongPressing += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tBOX LONG PRESSING [" + e.Center(e.WindowTouches).ToString(format) + "][" + e.ElementTouches[0].ToString(format) + "][" + e.ElementPosition.ToString(format) + "]");
                ShowTouches(e, Color.Magenta);
            };
            boxListener.LongPressed += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tBOX LONG PRESSED [" + e.Center(e.WindowTouches).ToString(format) + "][" + e.ElementTouches[0].ToString(format) + "][" + e.ElementPosition.ToString(format) + "]");
                ShowTouches(e, Color.Purple);
            };


            boxListener.RightClicked += (sender, e) => System.Diagnostics.Debug.WriteLine("\tBOX RIGHT CLICK[" + e.Center(e.WindowTouches).ToString(format) + "][" + e.ElementTouches[0].ToString(format) + "][" + e.ElementPosition.ToString(format) + "]");

            boxListener.Panning += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tBOX PANNING [" + e.Center(e.WindowTouches).ToString(format) + "][" + e.WindowTouches[0].ToString(format) + "][" + e.ElementPosition.ToString(format) + "]");
                if (totalSwitch.IsToggled)
                {
                    box.TranslationX = e.TotalDistance.X;
                    box.TranslationY = e.TotalDistance.Y;
                }
                else
                {
                    box.TranslationX += e.DeltaDistance.X;
                    box.TranslationY += e.DeltaDistance.Y;
                }
                ShowTouches(e, Color.Pink);
            };
            boxListener.Panned += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tBOX PANNED TotalDistance=[" + e.TotalDistance.ToString(format) + "][" + e.Center(e.WindowTouches).ToString(format) + "][" + e.ElementPosition.ToString(format) + "]");
                ShowTouches(e, Color.MistyRose);
                if (totalSwitch.IsToggled)
                {
                    box.TranslationX = 0;
                    box.TranslationY = 0;
                }
            };
            boxListener.Swiped += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tBOX SWIPED!!! Velocity=[" + e.VelocityX.ToString(format) + "," + e.VelocityY.ToString(format) + "][" + e.Center(e.WindowTouches).ToString(format) + "][" + e.ElementPosition.ToString(format) + "]");
                ShowTouches(e, Color.Cyan);
            };

            boxListener.Pinching += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tBOX PINCHING [" + e.Center(e.WindowTouches).ToString(format) + "][" + e.WindowTouches[0].ToString(format) + "][" + e.DeltaScale + "][" + e.ElementPosition.ToString(format) + "]");
                ShowTouches(e, Color.LightSeaGreen);
                if (totalSwitch.IsToggled)
                {
                    box.Scale = e.TotalScale;
                }
                else
                {
                    box.Scale *= e.DeltaScale;
                }
            };
            boxListener.Pinched += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tBOX PINCHED TotalScale=[" + e.TotalScale.ToString(format) + "][" + e.Center(e.WindowTouches).ToString(format) + "][" + e.ElementPosition.ToString(format) + "]");
                ShowTouches(e, Color.MintCream);
                if (totalSwitch.IsToggled)
                {
                    box.Scale = 1;
                }
            };
            boxListener.Rotating += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tBOX ROTATING [" + e.Center(e.WindowTouches).ToString(format) + "][" + e.WindowTouches[0].ToString(format) + "][" + e.DeltaAngle + "][" + e.ElementPosition.ToString(format) + "]");
                ShowTouches(e, Color.SandyBrown);
                if (totalSwitch.IsToggled)
                {
                    box.Rotation = e.TotalAngle;
                }
                else
                {
                    box.Rotation += e.DeltaAngle;
                }
            };
            boxListener.Rotated += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tBOX ROTATED TotalAngle[" + e.TotalAngle.ToString(format) + "][" + e.Center(e.WindowTouches).ToString(format) + "][" + e.ElementPosition.ToString(format) + "]");
                ShowTouches(e, Color.RosyBrown);
                if (totalSwitch.IsToggled)
                {
                    box.Rotation = 0;
                }
            };
            #endregion


            #region Looking for multiple taps
            var tapBox = new BoxView
            {
                BackgroundColor = Color.Blue,
            };
            var tapBoxListener = FormsGestures.Listener.For(tapBox);

            tapBoxListener.Tapping      += (sender, e) => System.Diagnostics.Debug.WriteLine("\tTAPBOX TAPPING #[" + e.NumberOfTaps + "]");
            tapBoxListener.Tapped       += (sender, e) => System.Diagnostics.Debug.WriteLine("\tTAPBOX TAPPED #[" + e.NumberOfTaps + "]");
            tapBoxListener.DoubleTapped += (sender, e) => System.Diagnostics.Debug.WriteLine("\tTAPBOX DOUBLE TAPPED #[" + e.NumberOfTaps + "]");

            #endregion


            #region RelativeLayout
            relativeLayout = new Xamarin.Forms.RelativeLayout
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand,
                Padding           = new Thickness(0),
                BackgroundColor   = Color.Transparent,
            };
            relativeLayout.Children.Clear();


            relativeLayout.Children.Add(button,
                                        xConstraint: Constraint.RelativeToParent((parent) => { return(parent.X + parent.Width * 3 / 4); }),
                                        yConstraint: Constraint.RelativeToParent((parent) => { return(parent.Y + parent.Height * 3 / 4); }),
                                        widthConstraint: Constraint.RelativeToParent((parent) => { return(parent.Width / 3); }),
                                        heightConstraint: Constraint.RelativeToParent((parent) => { return(parent.Width / 3); })
                                        );
            relativeLayout.Children.Add(box,
                                        xConstraint: Constraint.RelativeToParent((parent) => { return(parent.X + parent.Width / 4); }),
                                        yConstraint: Constraint.RelativeToParent((parent) => { return(parent.Y + parent.Height / 4); }),
                                        widthConstraint: Constraint.RelativeToParent((parent) => { return(parent.Width / 2); }),
                                        heightConstraint: Constraint.RelativeToParent((parent) => { return(parent.Width / 2); })
                                        );
            relativeLayout.Children.Add(tapBox,
                                        xConstraint: Constraint.RelativeToParent((parent) => { return(parent.X + parent.Width / 8); }),
                                        yConstraint: Constraint.RelativeToParent((parent) => { return(parent.Y + parent.Height / 8); }),
                                        widthConstraint: Constraint.RelativeToParent((parent) => { return(parent.Width / 16); }),
                                        heightConstraint: Constraint.RelativeToParent((parent) => { return(parent.Width / 16); })
                                        );
            relativeLayout.Children.Add(frame,
                                        xConstraint: Constraint.RelativeToParent((parent) => { return(parent.X + parent.Width * 1 / 4); }),
                                        yConstraint: Constraint.RelativeToParent((parent) => { return(parent.Y + parent.Height / 8); })
                                        );

            relativeLayout.Children.Add(totalSwitch,
                                        xConstraint: Constraint.RelativeToParent((parent) => { return(parent.X); }),
                                        yConstraint: Constraint.RelativeToParent((parent) => { return(parent.Y); })
                                        );
            #endregion


            #region AbsoluteLayout
            absoluteLayout = new Xamarin.Forms.AbsoluteLayout
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand,
                Padding           = new Thickness(5, 5, 5, 5),          // given tool bar don't need upper padding

                BackgroundColor = Color.White
            };
            absoluteLayout.Children.Add(relativeLayout,
                                        new Rectangle(0, 0, 1, 1), AbsoluteLayoutFlags.All
                                        );

            #endregion

            Content = absoluteLayout;

            totalSwitch.Toggled += (s, e) =>
            {
                box.TranslationX    = 0;
                box.TranslationY    = 0;
                box.Scale           = 1;
                box.Rotation        = 0;
                frame.TranslationX  = 0;
                frame.TranslationY  = 0;
                frame.Scale         = 1;
                frame.Rotation      = 0;
                button.TranslationX = 0;
                button.TranslationY = 0;
                button.Scale        = 1;
                button.Rotation     = 0;
            };
        }
        public BeerDetails(String beerId)
        {
            BeerId = beerId;

            var inventory = InventoryApi.GetInventoryByOwner(App.Authenticator.GetCurrentUser()).Result;

            var beerDetails = inventory.Where(x => x.Id == BeerId);

            var beer = InventoryApi.GetBeerById(BeerId).Result;

            Details = new ObservableCollection <InventoryDetails>(beerDetails);

            var locations = beerDetails.Select(x => x.Location).Distinct().ToList();

            locations.Add("New Location");

            var inventoryDetails = new StackLayout()
            {
                Orientation       = StackOrientation.Horizontal,
                HorizontalOptions = LayoutOptions.Center
            };

            DetailList = inventoryDetails;
            UpdateList();

            var addRemoveSwitch = new Xamarin.Forms.Switch
            {
                IsToggled = true
            };

            addRemoveSwitch.Toggled += AddRemoveSwitch_Toggled;

            var locationPicker = new Picker
            {
                VerticalOptions = LayoutOptions.Start,
                Title           = "Select a Location",
                ItemsSource     = locations
            };

            locationPicker.SelectedIndexChanged += LocationPicker_SelectedIndexChanged;

            submitButton = new Button
            {
                VerticalOptions = LayoutOptions.End,
                Text            = "Select a Location",
                IsEnabled       = false
            };

            submitButton.Clicked += SubmitButton_ClickedAsync;

            var amountEntry = new Entry
            {
                HorizontalOptions       = LayoutOptions.EndAndExpand,
                Keyboard                = Keyboard.Numeric,
                MinimumWidthRequest     = 100,
                WidthRequest            = 100,
                HorizontalTextAlignment = TextAlignment.Center,
                Text = "1"
            };

            amountEntry.TextChanged += AmountEntry_TextChanged;

            Content = new StackLayout
            {
                Children =
                {
                    new StackLayout
                    {
                        Orientation     = StackOrientation.Horizontal,
                        VerticalOptions = LayoutOptions.Start,
                        Margin          = 20,
                        Children        =
                        {
                            new Image
                            {
                                Source = beer.LabelUrl
                            },
                            new StackLayout
                            {
                                Margin          = new Thickness(10, 20),
                                VerticalOptions = LayoutOptions.Center,
                                Children        =
                                {
                                    new Label
                                    {
                                        Text = beer.Brewer
                                    },
                                    new Label
                                    {
                                        Text = beer.Name
                                    },
                                    new Label
                                    {
                                        Text = beer.ABV.ToString() + "%"
                                    }
                                }
                            },
                            new StackLayout
                            {
                                VerticalOptions = LayoutOptions.Center,
                                Children        =
                                {
                                    new Label
                                    {
                                        Text = "Style: " + beer.Type
                                    },
                                    new Label
                                    {
                                        Text = beer.Availablity
                                    },
                                    new Label
                                    {
                                        Text = beer.Glass
                                    }
                                }
                            }
                        }
                    },

                    new StackLayout
                    {
                        Margin          = new Thickness(20, 10),
                        VerticalOptions = LayoutOptions.CenterAndExpand,
                        Children        =
                        {
                            new Label
                            {
                                Text = beer.Description
                            }
                        }
                    },

                    new StackLayout
                    {
                        Margin          = 20,
                        Orientation     = StackOrientation.Vertical,
                        VerticalOptions = LayoutOptions.End,
                        Children        =
                        {
                            inventoryDetails,
                            locationPicker,
                            new StackLayout
                            {
                                VerticalOptions = LayoutOptions.CenterAndExpand,
                                Orientation     = StackOrientation.Horizontal,
                                Children        =
                                {
                                    new Label
                                    {
                                        VerticalOptions = LayoutOptions.Center,
                                        Text            = "Remove"
                                    },
                                    addRemoveSwitch,
                                    new Label
                                    {
                                        VerticalOptions = LayoutOptions.Center,
                                        Text            = "Add"
                                    },
                                    amountEntry
                                }
                            },
                            submitButton
                        }
                    }
                }
            };
        }
示例#34
0
        public TodoItemPage()
        {
            this.SetBinding(ContentPage.TitleProperty, "Name");

            NavigationPage.SetHasNavigationBar(this, true);
            var nameLabel = new Label {
                Text = "Name"
            };
            var nameEntry = new Entry();

            nameEntry.SetBinding(Entry.TextProperty, "Name");

            var notesLabel = new Label {
                Text = "Notes"
            };
            var notesEntry = new Entry();

            notesEntry.SetBinding(Entry.TextProperty, "Notes");

            var doneLabel = new Label {
                Text = "Done"
            };
            var doneEntry = new Xamarin.Forms.Switch();

            doneEntry.SetBinding(Xamarin.Forms.Switch.IsToggledProperty, "Done");

            var saveButton = new Button {
                Text = "Save"
            };

            saveButton.Clicked += (sender, e) => {
                var todoItem = (TodoItem)BindingContext;
                App.Database.SaveItem(todoItem);
                this.Navigation.PopAsync();
            };

            var deleteButton = new Button {
                Text = "Delete"
            };

            deleteButton.Clicked += (sender, e) => {
                var todoItem = (TodoItem)BindingContext;
                App.Database.DeleteItem(todoItem._id);
                this.Navigation.PopAsync();
            };

            var cancelButton = new Button {
                Text = "Cancel"
            };

            cancelButton.Clicked += (sender, e) => {
                var todoItem = (TodoItem)BindingContext;
                this.Navigation.PopAsync();
            };


            var speakButton = new Button {
                Text = "Speak"
            };

            speakButton.Clicked += (sender, e) => {
                var todoItem = (TodoItem)BindingContext;
                DependencyService.Get <ITextToSpeech>().Speak(todoItem.Name + " " + todoItem.Notes);
            };

            Content = new StackLayout {
                VerticalOptions = LayoutOptions.StartAndExpand,
                Padding         = new Thickness(20),
                Children        =
                {
                    nameLabel,  nameEntry,
                    notesLabel, notesEntry,
                    doneLabel,  doneEntry,
                    saveButton, deleteButton,cancelButton,
                    speakButton
                }
            };
        }
        public CustomPinsPage()
        {
            InitializeComponent();

            // Switch contols as toggle
            var switches = new Xamarin.Forms.Switch[] { switchPinColor, switchPinBundle, switchPinStream };

            foreach (var sw in switches)
            {
                sw.Toggled += (sender, e) =>
                {
                    if (!e.Value || _dirty)
                    {
                        return;
                    }

                    _dirty = true;
                    foreach (var s in switches)
                    {
                        if (!object.ReferenceEquals(s, sender))
                        {
                            s.IsToggled = false;
                        }
                    }
                    _dirty = false;

                    UpdatePinIcon();
                };
            }

            // Default colors
            foreach (var c in _colors)
            {
                buttonPinColor.Items.Add(c.Item1);
            }

            buttonPinColor.SelectedIndexChanged += (_, e) =>
            {
                buttonPinColor.BackgroundColor = _colors[buttonPinColor.SelectedIndex].Item2;
                UpdatePinIcon();
            };
            buttonPinColor.SelectedIndex = 0;

            // Bundle Images
            foreach (var bundle in _bundles)
            {
                buttonPinBundle.Items.Add(bundle);
            }

            buttonPinBundle.SelectedIndexChanged += (_, e) =>
            {
                UpdatePinIcon();
            };
            buttonPinBundle.SelectedIndex = 0;

            // Stream Images
            foreach (var stream in _streams)
            {
                buttonPinStream.Items.Add(stream);
            }

            buttonPinStream.SelectedIndexChanged += (_, e) =>
            {
                UpdatePinIcon();
            };
            buttonPinStream.SelectedIndex = 0;

            // Set to null
            buttonPinSetToNull.Clicked += (sender, e) =>
            {
                _pinTokyo.Icon = null;
                foreach (var sw in switches)
                {
                    sw.IsToggled = false;
                }
            };

            // Pin Draggable
            switchIsDraggable.Toggled += (sender, e) =>
            {
                _pinTokyo.IsDraggable = switchIsDraggable.IsToggled;
            };

            switchFlat.Toggled += (sender, e) =>
            {
                _pinTokyo.Flat = switchFlat.IsToggled;
            };

            // Pin Rotation
            sliderRotation.ValueChanged += (sender, e) =>
            {
                _pinTokyo.Rotation = (float)e.NewValue;

                if (_pinTokyo.Rotation >= 0 && _pinTokyo.Rotation <= 60)
                {
                    _pinTokyo.InfoWindowAnchor = new Point(0.5, 0.0);
                }

                if (_pinTokyo.Rotation > 60 && _pinTokyo.Rotation <= 120)
                {
                    _pinTokyo.InfoWindowAnchor = new Point(0.0, 0.5);
                }

                if (_pinTokyo.Rotation > 120 && _pinTokyo.Rotation <= 210)
                {
                    _pinTokyo.InfoWindowAnchor = new Point(0.5, 1.0);
                }

                if (_pinTokyo.Rotation > 210 && _pinTokyo.Rotation < 270)
                {
                    _pinTokyo.InfoWindowAnchor = new Point(1.0, 0.25);
                }

                if (_pinTokyo.Rotation > 270 && _pinTokyo.Rotation < 360)
                {
                    _pinTokyo.InfoWindowAnchor = new Point(0.5, 0.0);
                }
            };

            // Pin Transparency
            sliderTransparency.ValueChanged += (sender, e) =>
            {
                _pinTokyo.Transparency = (float)(e.NewValue / 10f);
            };
            _pinTokyo.Transparency = (float)(sliderTransparency.Value / 10f);

            // ZIndex
            buttonMoveToFront.Clicked += (sender, e) =>
            {
                map.SelectedPin  = null;
                _pinTokyo.ZIndex = _pinTokyo2.ZIndex + 1;
            };
            buttonMoveToBack.Clicked += (sender, e) =>
            {
                map.SelectedPin  = null;
                _pinTokyo.ZIndex = _pinTokyo2.ZIndex - 1;
            };

            // MapToolbarEnabled
            //map.UiSettings.MapToolbarEnabled = true;
            //switchMapToolbarEnabled.Toggled += (sender, e) =>
            //{
            //    map.UiSettings.MapToolbarEnabled = e.Value;
            //};
            //switchMapToolbarEnabled.IsToggled = map.UiSettings.MapToolbarEnabled;

            map.PinDragStart += (_, e) => labelDragStatus.Text = $"DragStart - {PrintPin(e.Pin)}";
            map.PinDragging  += (_, e) => labelDragStatus.Text = $"Dragging - {PrintPin(e.Pin)}";
            map.PinDragEnd   += (_, e) => labelDragStatus.Text = $"DragEnd - {PrintPin(e.Pin)}";

            switchIsDraggable.IsToggled = true;

            switchPinColor.IsToggled = true;

            _pinTokyo.IsDraggable = true;
            map.Pins.Add(_pinTokyo);
            map.Pins.Add(_pinTokyo2);
            map.SelectedPin = _pinTokyo;
            map.MoveToRegion(MapSpan.FromCenterAndRadius(_pinTokyo.Position, Distance.FromMeters(5000)), true);
        }
示例#36
0
        public SwitchHandler(NativeComponentRenderer renderer, XF.Switch switchControl) : base(renderer, switchControl)
        {
            SwitchControl = switchControl ?? throw new ArgumentNullException(nameof(switchControl));

            Initialize(renderer);
        }