public TodoListXaml ()
		{
			InitializeComponent ();

			var tbi = new ToolbarItem ("+", null, () => {
				var todoItem = new TodoItem();
				var todoPage = new TodoItemXaml();
				todoPage.BindingContext = todoItem;
				Navigation.PushAsync(todoPage);
			}, 0, 0);
			if (Device.OS == TargetPlatform.Android) { // BUG: Android doesn't support the icon being null
				tbi = new ToolbarItem ("+", "plus", () => {
					var todoItem = new TodoItem();
					var todoPage = new TodoItemXaml();
					todoPage.BindingContext = todoItem;
					Navigation.PushAsync(todoPage);
				}, 0, 0);
			}

			ToolbarItems.Add (tbi);

//			if (Device.OS == TargetPlatform.iOS) {
//				var tbi2 = new ToolbarItem ("?", null, () => {
//					var todos = App.Database.GetItemsNotDone();
//					var tospeak = "";
//					foreach (var t in todos)
//						tospeak += t.Name + " ";
//					if (tospeak == "") tospeak = "there are no tasks to do";
//					App.Speech.Speak(tospeak);
//				}, 0, 0);
//				ToolbarItems.Add (tbi2);
//			}
		}
		public TodoListPage ()
		{
			Title = AppResources.ApplicationTitle; // "Todo";

			listView = new ListView { RowHeight = 40 };
			listView.ItemTemplate = new DataTemplate (typeof (TodoItemCell));

			listView.ItemSelected += (sender, e) => {
				var todoItem = (TodoItem)e.SelectedItem;

				// use C# localization
				var todoPage = new TodoItemPage();

				// use XAML localization
//				var todoPage = new TodoItemXaml();


				todoPage.BindingContext = todoItem;
				Navigation.PushAsync(todoPage);
			};

			var layout = new StackLayout();
			if (Device.OS == TargetPlatform.WinPhone) { // WinPhone doesn't have the title showing
				layout.Children.Add(new Label{Text="Todo", Font=Font.SystemFontOfSize(NamedSize.Large, FontAttributes.Bold)});
			}
			layout.Children.Add(listView);
			layout.VerticalOptions = LayoutOptions.FillAndExpand;
			Content = layout;


			var tbiAdd = new ToolbarItem("Add", "plus.png", () =>
				{
					var todoItem = new TodoItem();
					var todoPage = new TodoItemPage();
					todoPage.BindingContext = todoItem;
					Navigation.PushAsync(todoPage);
				}, 0, 0);


			ToolbarItems.Add (tbiAdd);


			var tbiSpeak = new ToolbarItem ("Speak", "chat.png", () => {
				var todos = App.Database.GetItemsNotDone();
				var tospeak = "";
				foreach (var t in todos)
					tospeak += t.Name + " ";
				if (tospeak == "") tospeak = "there are no tasks to do";

				if (todos.Any ()) {
					var s = L10n.Localize ("SpeakTaskCount", "Number of tasks to do");
					tospeak = String.Format (s, todos.Count ()) + tospeak;
				}

				DependencyService.Get<ITextToSpeech>().Speak(tospeak);
			}, 0, 0);
			ToolbarItems.Add (tbiSpeak);


		}
Exemplo n.º 3
0
		public static async Task SaveTodoAsync (TodoItem item)
		{
			if (item.ID == null | item.ID == string.Empty) {
				await client.GetTable<TodoItem> ().InsertAsync (item);
			} else {
				await client.GetTable<TodoItem> ().UpdateAsync (item);
			}
		}
      public void doneEditing(TodoItem todo) 
      {
		   editedTodo = null;
		   todo.title = todo.title.Trim();

   		if(todo.title=="") 
         {
			   removeTodo(todo);
		   }
	   }
        public TodoItemListX()
        {
            InitializeComponent();

            #region toolbar
            ToolbarItem tbi = null;
            if (Device.OS == TargetPlatform.iOS)
            {
                tbi = new ToolbarItem("+", null, () =>
                {
                    var todoItem = new TodoItem();
                    var todoPage = new TodoItemPageX();
                    todoPage.BindingContext = todoItem;
                    Navigation.PushAsync(todoPage);
                }, 0, 0);
            }
            if (Device.OS == TargetPlatform.Android)
            { // BUG: Android doesn't support the icon being null
                tbi = new ToolbarItem("+", "plus", () =>
                {
                    var todoItem = new TodoItem();
                    var todoPage = new TodoItemPageX();
                    todoPage.BindingContext = todoItem;
                    Navigation.PushAsync(todoPage);
                }, 0, 0);
            }
            if (Device.OS == TargetPlatform.WinPhone || Device.OS == TargetPlatform.Windows)
            {
                tbi = new ToolbarItem("Add", "add.png", () =>
                {
                    var todoItem = new TodoItem();
                    var todoPage = new TodoItemPageX();
                    todoPage.BindingContext = todoItem;
                    Navigation.PushAsync(todoPage);
                }, 0, 0);
            }

            ToolbarItems.Add(tbi);

            if (Device.OS == TargetPlatform.iOS)
            {
                var tbi2 = new ToolbarItem("?", null, () =>
                {
                    var todos = App.Database.GetItemsNotDone();
                    var tospeak = "";
                    foreach (var t in todos)
                        tospeak += t.Name + " ";
                    if (tospeak == "") tospeak = "there are no tasks to do";

                    DependencyService.Get<ITextToSpeech>().Speak(tospeak);
                }, 0, 0);
                ToolbarItems.Add(tbi2);
            }
            #endregion
        }
		public int SaveItem (TodoItem item) 
		{
			lock (locker) {
				if (item.ID != 0) {
					database.Update(item);
					return item.ID;
				} else {
					return database.Insert(item);
				}
			}
		}
Exemplo n.º 7
0
		public static async Task SaveTodoAsync (TodoItem item)
		{
			System.Diagnostics.Debug.WriteLine (item.Name);
			if (item.ID == null || item.ID == string.Empty) {
				await Client.GetTable<TodoItem> ().InsertAsync (item);
				System.Diagnostics.Debug.WriteLine ("Insert");
			} else {
				await Client.GetTable<TodoItem> ().UpdateAsync (item);
				System.Diagnostics.Debug.WriteLine ("Update");
			}
		}
Exemplo n.º 8
0
        public TodoItem CreateItem(string text) {
            string id = Date.Now.GetTime().ToString();

            TodoItem item = new TodoItem();
            item.ID = id;
            item.Title = text;
            item.Completed = false;

            _items.Add(item);
            SaveItems();

            return item;
        }
		public TodoListPage ()
		{
			Title = "Todo";

			NavigationPage.SetHasNavigationBar (this, true);

			listView = new ListView {
			    RowHeight = 40
			};
			listView.ItemTemplate = new DataTemplate (typeof (TodoItemCell));

			listView.ItemSelected += (sender, e) => {
				var todoItem = (TodoItem)e.SelectedItem;
				var todoPage = new TodoItemPage();
				todoPage.BindingContext = todoItem;
				Navigation.PushAsync(todoPage);
			};

			var layout = new StackLayout();
			if (Device.OS == TargetPlatform.WinPhone) { // WinPhone doesn't have the title showing
				layout.Children.Add(new Label{Text="Todo", Font=Font.SystemFontOfSize(NamedSize.Large, FontAttributes.Bold)});
			}
			layout.Children.Add(listView);
			layout.VerticalOptions = LayoutOptions.FillAndExpand;
			Content = layout;


			var tbiAdd = new ToolbarItem ("+", "plus.png", () => {
				var todoItem = new TodoItem();
				var todoPage = new TodoItemPage();
				todoPage.BindingContext = todoItem;
				Navigation.PushAsync(todoPage);
			}, 0, 0);

			ToolbarItems.Add (tbiAdd);

			var tbiSpeak = new ToolbarItem ("?", "chat.png", () => {
				var todos = App.Database.GetItemsNotDone();
				var tospeak = "";
				foreach (var t in todos)
					tospeak += t.Name + " ";
				if (tospeak == "") tospeak = "there are no tasks to do";

				DependencyService.Get<ITextToSpeech>().Speak(tospeak);
			}, 0, 0);
			ToolbarItems.Add (tbiSpeak);

		}
      public TodoCtrl(Scope _scope, Location _location, todoStorage todoStorage, filterFilter filterFilter)
      {
	      this.Storage = todoStorage;
         this.filter = filterFilter;         
         this.location = _location;

         todos = Storage.get();      

	      newTodo = "";
	      editedTodo = null;

         _scope.Watch<object>(()=>todos, update, true);

	      if(location.Path == "") location.Path = "/";
	      	      
         _scope.Watch<string>(()=>location.Path, pathchanged);         
      }            
 public TodoItem GetItem(int id)
 {
     var t = new TodoItem();
     lock (locker) {
         connection = new SqliteConnection ("Data Source=" + path);
         connection.Open ();
         using (var command = connection.CreateCommand ()) {
             command.CommandText = "SELECT [ID], [Name], [Notes], [Done] from [TodoItem] WHERE [ID] = ?";
             command.Parameters.Add (new SqliteParameter (DbType.Int32) { Value = id });
             var r = command.ExecuteReader ();
             while (r.Read ()) {
                 t = FromReader (r);
                 break;
             }
         }
         connection.Close ();
     }
     return t;
 }
Exemplo n.º 12
0
        public TodoPage()
        {
            BindingContext = new TodoViewModel ();

            InitializeComponent ();

            todoListView.ItemSelected += (sender, e) => {
                if (todoListView.SelectedItem == null)
                    return;

                Navigation.PushAsync (new TodoDetailPage (todoListView.SelectedItem as TodoItem));

                todoListView.SelectedItem = null;
            };

            ToolbarItems.Add (new ToolbarItem ("Add", null, async () => {
                var viewModel = BindingContext as TodoViewModel;
                var todo = new TodoItem { Name = "New Todo", Description = "Edit Me", Done = false };
                viewModel.Todos.Add (todo);

                MobileService.SaveTodoAsync (todo);
            }));
        }
Exemplo n.º 13
0
        public TodoListPage()
        {
            Title = "Todo";

            NavigationPage.SetHasNavigationBar(this, true);

            listView = new ListView {
                RowHeight = 40
            };
            listView.ItemTemplate = new DataTemplate(typeof(TodoItemCell));

            // These commented-out lines were used to test the ListView prior to integrating the database
//			listView.ItemSource = new string [] { "Buy pears", "Buy oranges", "Buy mangos", "Buy apples", "Buy bananas" };
//			listView.ItemSource = new TodoItem [] {
//				new TodoItem {Name = "Buy pears`"},
//				new TodoItem {Name = "Buy oranges`", Done=true},
//				new TodoItem {Name = "Buy mangos`"},
//				new TodoItem {Name = "Buy apples`", Done=true},
//				new TodoItem {Name = "Buy bananas`", Done=true}
//			};

            // HACK: workaround issue #894 for now
            if (Device.OS == TargetPlatform.iOS)
            {
                listView.ItemsSource = new string [1] {
                    ""
                }
            }
            ;

            listView.ItemSelected += (sender, e) => {
                var todoItem = (TodoItem)e.SelectedItem;
                var todoPage = new TodoItemPage();
                todoPage.BindingContext = todoItem;
                Navigation.PushAsync(todoPage);
            };

            Content = new StackLayout {
                VerticalOptions = LayoutOptions.FillAndExpand,
                Children        = { listView }
            };

            var tbi = new ToolbarItem("+", null, () => {
                var todoItem            = new TodoItem();
                var todoPage            = new TodoItemPage();
                todoPage.BindingContext = todoItem;
                Navigation.PushAsync(todoPage);
            }, 0, 0);

            if (Device.OS == TargetPlatform.Android)               // BUG: Android doesn't support the icon being null
            {
                tbi = new ToolbarItem("+", "plus", () => {
                    var todoItem            = new TodoItem();
                    var todoPage            = new TodoItemPage();
                    todoPage.BindingContext = todoItem;
                    Navigation.PushAsync(todoPage);
                }, 0, 0);
            }

            ToolbarItems.Add(tbi);

            if (Device.OS == TargetPlatform.iOS)
            {
                var tbi2 = new ToolbarItem("?", null, () => {
                    var todos   = App.Database.GetItemsNotDone();
                    var tospeak = "";
                    foreach (var t in todos)
                    {
                        tospeak += t.Name + " ";
                    }
                    if (tospeak == "")
                    {
                        tospeak = "there are no tasks to do";
                    }
                    App.Speech.Speak(tospeak);
                }, 0, 0);
                ToolbarItems.Add(tbi2);
            }
        }
		public TodoListPage ()
		{
			Title = "Todo";

			NavigationPage.SetHasNavigationBar (this, true);

			listView = new ListView {
			    RowHeight = 40
			};
			listView.ItemTemplate = new DataTemplate (typeof (TodoItemCell));

//			listView.ItemSource = new string [] { "Buy pears", "Buy oranges", "Buy mangos", "Buy apples", "Buy bananas" };
//			listView.ItemSource = new TodoItem [] { 
//				new TodoItem {Name = "Buy pears`"}, 
//				new TodoItem {Name = "Buy oranges`", Done=true},
//				new TodoItem {Name = "Buy mangos`"}, 
//				new TodoItem {Name = "Buy apples`", Done=true},
//				new TodoItem {Name = "Buy bananas`", Done=true}
//			};

			// HACK: workaround issue #894 for now
			if (Device.OS == TargetPlatform.iOS)
				listView.ItemsSource = new string [1] {""};

			listView.ItemSelected += (sender, e) => {
				var todoItem = (TodoItem)e.SelectedItem;
				var todoPage = new TodoItemPage();
				todoPage.BindingContext = todoItem;
				Navigation.PushAsync(todoPage);
			};

			Content = new StackLayout {
				VerticalOptions = LayoutOptions.FillAndExpand,
				Children = {listView}
			};

			var tbi = new ToolbarItem ("+", null, () => {
				var todoItem = new TodoItem();
				var todoPage = new TodoItemPage();
				todoPage.BindingContext = todoItem;
				Navigation.PushAsync(todoPage);
			}, 0, 0);
			if (Device.OS == TargetPlatform.Android) { // BUG: Android doesn't support the icon being null
				tbi = new ToolbarItem ("+", "plus", () => {
					var todoItem = new TodoItem();
					var todoPage = new TodoItemPage();
					todoPage.BindingContext = todoItem;
					Navigation.PushAsync(todoPage);
				}, 0, 0);
			}

			ToolbarItems.Add (tbi);

			if (Device.OS == TargetPlatform.iOS) {
				var tbi2 = new ToolbarItem ("?", null, () => {
					var todos = App.Database.GetItemsNotDone();
					var tospeak = "";
					foreach (var t in todos)
						tospeak += t.Name + " ";
					if (tospeak == "") tospeak = "there are no tasks to do";
					App.Speech.Speak(tospeak);
				}, 0, 0);
				ToolbarItems.Add (tbi2);
			}

		}
 public int SaveItem(TodoItem item)
 {
     return database.SaveItem(item);
 }
      public void editTodo(TodoItem todo) 
      {
		   editedTodo = todo;
	   }
 public RootTableSource(TodoItem[] items)
 {
     tableItems = items;
 }
Exemplo n.º 18
0
		public TodoListPage ()
		{
			Title = "Staff List";

			NavigationPage.SetHasNavigationBar (this, true);

			listView = new ListView {
				RowHeight = 40,
				ItemTemplate = new DataTemplate (typeof(TodoItemCell))
			};
					

			listView.ItemSelected += (sender, e) => {
				var todoItem = (TodoItem)e.SelectedItem;
				var todoPage = new TodoItemPage ();
				todoPage.BindingContext = todoItem;
				Navigation.PushAsync (todoPage);
			};

			var lv = new ListView();
			lv.BackgroundColor = Color.Yellow;

			var layout = new StackLayout ();
			if (Device.OS == TargetPlatform.WinPhone) { // WinPhone doesn't have the title showing
				layout.Children.Add (new Label {
					Text = "Staff List",
					FontSize = Device.GetNamedSize (NamedSize.Large, typeof(Label)),
					FontAttributes = FontAttributes.Bold
				});
			}
			layout.Children.Add (listView);
			layout.VerticalOptions = LayoutOptions.FillAndExpand;
			Content = layout;


			ToolbarItem tbi = null;
			if (Device.OS == TargetPlatform.iOS) {
				tbi = new ToolbarItem ("+", null, () => {
					var todoItem = new TodoItem ();
					var todoPage = new TodoItemPage ();
					todoPage.BindingContext = todoItem;
					Navigation.PushAsync (todoPage);
				}, 0, 0);
			}
			if (Device.OS == TargetPlatform.Android) { // BUG: Android doesn't support the icon being null
				tbi = new ToolbarItem ("+", "plus", () => {
					var todoItem = new TodoItem ();
					var todoPage = new TodoItemPage ();
					todoPage.BindingContext = todoItem;
					Navigation.PushAsync (todoPage);
				}, 0, 0);
			}

			if (Device.OS == TargetPlatform.WinPhone) {
				tbi = new ToolbarItem ("Add", "add.png", () => {
					var todoItem = new TodoItem ();
					var todoPage = new TodoItemPage ();
					todoPage.BindingContext = todoItem;
					Navigation.PushAsync (todoPage);
				}, 0, 0);
			}

			ToolbarItems.Add (tbi);

			if (Device.OS == TargetPlatform.iOS) {
				var tbi2 = new ToolbarItem ("?", null, () => {
					var todos = App.Database.GetItemsNotDone ();
					var tospeak = "";
					foreach (var t in todos)
						tospeak += t.Name + " ";
					if (tospeak == "")
						tospeak = "there are no tasks to do";

					DependencyService.Get<ITextToSpeech> ().Speak (tospeak);
				}, 0, 0);
				ToolbarItems.Add (tbi2);
			}
		}
        public TodoListPage()
        {
            Title = "Todo";

            listView = new ListView();
            listView.ItemTemplate = new DataTemplate(typeof(TodoItemCell));

            listView.ItemSelected += async(sender, e) => {
                if (e.SelectedItem == null)
                {
                    return;                     // ensures we ignore this handler when the selection is just being cleared
                }
                var todoItem = (TodoItem)e.SelectedItem;
                var todoPage = new TodoItemPage();
                todoPage.BindingContext = todoItem;
                await Navigation.PushAsync(todoPage);

                ((ListView)sender).SelectedItem = null;                 // clears the 'selected' background
            };

            // make floating (+) image at bottom of screen
            var tap = new TapGestureRecognizer(async(View obj) => {
                var todoItem            = new TodoItem();
                var todoPage            = new TodoItemPage();
                todoPage.BindingContext = todoItem;

                var b = newImage.Bounds;
                b.Y   = b.Y - 50;

                await newImage.LayoutTo(b, 250, Easing.SinIn);
                b.Y = b.Y + 50;
                await newImage.LayoutTo(b, 250, Easing.SinOut);

                await Navigation.PushAsync(todoPage);
            });

            newImage = new Image {
                Source       = "newitem.png",
                WidthRequest = 40,
                Opacity      = 0.8f
            };
            newImage.GestureRecognizers.Add(tap);

            layout = new RelativeLayout();
            layout.Children.Add(listView,
                                xConstraint: Constraint.Constant(0),
                                yConstraint: Constraint.Constant(0),
                                widthConstraint: Constraint.RelativeToParent((parent) => { return(parent.Width); }),
                                heightConstraint: Constraint.RelativeToParent((parent) => { return(parent.Height); }));
            layout.Children.Add(newImage,
                                xConstraint: Constraint.RelativeToParent((parent) =>
            {
                return((parent.Width / 2) - 20);                                // center of image (which is 40 wide)
            }),
                                yConstraint: Constraint.RelativeToParent((parent) =>
            {
                return(parent.Height - 60);
            }));
            Content = layout;


            #region toolbar
            var tbi = new ToolbarItem("+", "plus.png", () => {
                var todoItem            = new TodoItem();
                var todoPage            = new TodoItemPage();
                todoPage.BindingContext = todoItem;
                Navigation.PushAsync(todoPage);
            }, 0, 0);
            //tbi.Order = ToolbarItemOrder.Secondary;
            ToolbarItems.Add(tbi);

            var tbi2 = new ToolbarItem("?", "chat.png", () => {
                var todos   = App.Database.GetItemsNotDone();
                var tospeak = "";
                foreach (var t in todos)
                {
                    tospeak += t.Name + " ";
                }
                if (tospeak == "")
                {
                    tospeak = "there are no tasks to do";
                }

                DependencyService.Get <ITextToSpeech>().Speak("Hello from Xamarin Forms");
            }, 0, 0);
            // demonstrate toolbar/optionmenu
            tbi2.Order = ToolbarItemOrder.Secondary;
            ToolbarItems.Add(tbi2);

            #endregion
        }
Exemplo n.º 20
0
 public void UpdateItem(TodoItem item, string text, bool completed) {
     item.Title = text;
     item.Completed = completed;
     SaveItems();
 }
		public TodoListPage ()
		{
			Title = "Todo";

			NavigationPage.SetHasNavigationBar (this, true);

			listView = new ListView ();
			listView.ItemTemplate = new DataTemplate (typeof (TodoItemCell));

//			listView.ItemSource = new string [] { "Buy pears", "Buy oranges", "Buy mangos", "Buy apples", "Buy bananas" };
//			listView.ItemSource = new TodoItem [] { 
//				new TodoItem {Name = "Buy pears`"}, 
//				new TodoItem {Name = "Buy oranges`", Done=true},
//				new TodoItem {Name = "Buy mangos`"}, 
//				new TodoItem {Name = "Buy apples`", Done=true},
//				new TodoItem {Name = "Buy bananas`", Done=true}
//			};

			listView.ItemSelected += (sender, e) => {
				var todoItem = (TodoItem)e.SelectedItem;
				var todoPage = new TodoItemPage();
				todoPage.BindingContext = todoItem;
				Navigation.PushAsync(todoPage);
			};

			var tap = new TapGestureRecognizer ((View obj) => {
				var todoItem = new TodoItem();
				var todoPage = new TodoItemPage();
				todoPage.BindingContext = todoItem;
				Navigation.PushAsync(todoPage);
			});

			newImage = new Image ();
			newImage.Source = "new.png";
			newImage.WidthRequest = 40;
			newImage.GestureRecognizers.Add (tap);

			layout = new RelativeLayout ();
			layout.Children.Add (listView, 
				xConstraint: Constraint.Constant(0), 
				yConstraint: Constraint.Constant(0), 
				widthConstraint: Constraint.RelativeToParent ((parent) => {return parent.Width;}),
				heightConstraint: Constraint.RelativeToParent ((parent) => {return parent.Height;}));
			layout.Children.Add (newImage, 
				xConstraint: Constraint.RelativeToParent((parent) =>
					{
						return (parent.Width / 2) - 20; // center of image (which is 40 wide)
					}),
				yConstraint: Constraint.RelativeToParent((parent) =>
					{
						return parent.Height - 60;
					}));
			Content = layout;


			#region toolbar
			var tbi = new ToolbarItem ("+", null, () => {
				var todoItem = new TodoItem();
				var todoPage = new TodoItemPage();
				todoPage.BindingContext = todoItem;
				Navigation.PushAsync(todoPage);
			}, 0, 0);
			if (Device.OS == TargetPlatform.Android) { // BUG: Android doesn't support the icon being null
				tbi = new ToolbarItem ("+", "plus", () => {
					var todoItem = new TodoItem();
					var todoPage = new TodoItemPage();
					todoPage.BindingContext = todoItem;
					Navigation.PushAsync(todoPage);
				}, 0, 0);
			}

			ToolbarItems.Add (tbi);

			if (Device.OS == TargetPlatform.iOS) {
				var tbi2 = new ToolbarItem ("?", null, () => {
					var todos = App.Database.GetItemsNotDone();
					var tospeak = "";
					foreach (var t in todos)
						tospeak += t.Name + " ";
					if (tospeak == "") tospeak = "there are no tasks to do";
					App.Speech.Speak(tospeak);
				}, 0, 0);
				ToolbarItems.Add (tbi2);
			}
			#endregion
		}
Exemplo n.º 22
0
 public void TodoItemDefaultsToNone()
 {
     var todo = new TodoItem ();
     Assert.IsFalse (todo.Done);
 }
Exemplo n.º 23
0
		public void SaveItem (TodoItem item) 
		{
			lock (locker) {
				database.Save<TodoItem>(item); //upsert
			}
		}
	   public void removeTodo(TodoItem todo) 
      {		   
         todos.Splice(todos.IndexOf(todo), 1);     
	   }
Exemplo n.º 25
0
 public TodoItem[] get()
 {                  
    TodoItem[] items = Json.Parse<TodoItem[]>((string) Window.LocalStorage.GetItem(STORAGE_ID));
    if(items==null) items = new TodoItem[]{ };
    return items;
 }
Exemplo n.º 26
0
 public void put(TodoItem[] todos)
 {
    Window.LocalStorage.SetItem(STORAGE_ID, Json.Stringify(todos));
 }
Exemplo n.º 27
0
        public TodoListPage()
        {
            Title = "Todo";

            NavigationPage.SetHasNavigationBar(this, true);

            listView = new ListView {
                RowHeight = 40
            };
            listView.ItemTemplate = new DataTemplate(typeof(TodoItemCell));

            // HACK: workaround issue #894 for now
            if (Device.OS == TargetPlatform.iOS)
            {
                listView.ItemsSource = new string [1] {
                    ""
                }
            }
            ;

            listView.ItemSelected += (sender, e) => {
                var todoItem = (TodoItem)e.SelectedItem;
                var todoPage = new TodoItemPage();
                todoPage.BindingContext = todoItem;
                Navigation.PushAsync(todoPage);
            };

            var layout = new StackLayout();

            if (Device.OS == TargetPlatform.WinPhone)               // WinPhone doesn't have the title showing
            {
                layout.Children.Add(new Label {
                    Text = "Todo", Font = Font.BoldSystemFontOfSize(NamedSize.Large)
                });
            }
            layout.Children.Add(listView);
            layout.VerticalOptions = LayoutOptions.FillAndExpand;
            Content = layout;


            ToolbarItem tbi = null;

            if (Device.OS == TargetPlatform.iOS)
            {
                tbi = new ToolbarItem("+", null, () =>
                {
                    var todoItem            = new TodoItem();
                    var todoPage            = new TodoItemPage();
                    todoPage.BindingContext = todoItem;
                    Navigation.PushAsync(todoPage);
                }, 0, 0);
            }
            if (Device.OS == TargetPlatform.Android)               // BUG: Android doesn't support the icon being null
            {
                tbi = new ToolbarItem("+", "plus", () => {
                    var todoItem            = new TodoItem();
                    var todoPage            = new TodoItemPage();
                    todoPage.BindingContext = todoItem;
                    Navigation.PushAsync(todoPage);
                }, 0, 0);
            }
            if (Device.OS == TargetPlatform.WinPhone)
            {
                tbi = new ToolbarItem("Add", "add.png", () =>
                {
                    var todoItem            = new TodoItem();
                    var todoPage            = new TodoItemPage();
                    todoPage.BindingContext = todoItem;
                    Navigation.PushAsync(todoPage);
                }, 0, 0);
            }

            ToolbarItems.Add(tbi);

            if (Device.OS == TargetPlatform.iOS)
            {
                var tbi2 = new ToolbarItem("?", null, () => {
                    var todos   = App.Database.GetItemsNotDone();
                    var tospeak = "";
                    foreach (var t in todos)
                    {
                        tospeak += t.Name + " ";
                    }
                    if (tospeak == "")
                    {
                        tospeak = "there are no tasks to do";
                    }

                    DependencyService.Get <ITextToSpeech>().Speak(tospeak);
                }, 0, 0);
                ToolbarItems.Add(tbi2);
            }
        }
		public TodoListPage ()
		{
			Title = "Todo";

			listView = new ListView ();
			listView.ItemTemplate = new DataTemplate 
					(typeof (TodoItemCell));
			listView.ItemSelected += (sender, e) => {
				var todoItem = (TodoItem)e.SelectedItem;
				var todoPage = new TodoItemPage();
				todoPage.BindingContext = todoItem;

				((App)App.Current).ResumeAtTodoId = todoItem.ID;
				Debug.WriteLine("setting ResumeAtTodoId = " + todoItem.ID);

				Navigation.PushAsync(todoPage);
			};

			var layout = new StackLayout();
			if (Device.OS == TargetPlatform.WinPhone) { // WinPhone doesn't have the title showing
				layout.Children.Add(new Label{
					Text="Todo", 
					FontSize = Device.GetNamedSize (NamedSize.Large, typeof(Label))});
			}
			layout.Children.Add(listView);
			layout.VerticalOptions = LayoutOptions.FillAndExpand;
			Content = layout;

			#region toolbar
			ToolbarItem tbi = null;
			if (Device.OS == TargetPlatform.iOS)
			{
				tbi = new ToolbarItem("+", null, () =>
					{
						var todoItem = new TodoItem();
						var todoPage = new TodoItemPage();
						todoPage.BindingContext = todoItem;
						Navigation.PushAsync(todoPage);
					}, 0, 0);
			}
			if (Device.OS == TargetPlatform.Android) { // BUG: Android doesn't support the icon being null
				tbi = new ToolbarItem ("+", "plus", () => {
					var todoItem = new TodoItem();
					var todoPage = new TodoItemPage();
					todoPage.BindingContext = todoItem;
					Navigation.PushAsync(todoPage);
				}, 0, 0);
			}
			if (Device.OS == TargetPlatform.WinPhone)
			{
				tbi = new ToolbarItem("Add", "add.png", () =>
					{
						var todoItem = new TodoItem();
						var todoPage = new TodoItemPage();
						todoPage.BindingContext = todoItem;
						Navigation.PushAsync(todoPage);
					}, 0, 0);
			}

			ToolbarItems.Add (tbi);

			if (Device.OS == TargetPlatform.iOS) {
				var tbi2 = new ToolbarItem ("?", null, () => {
					var todos = App.Database.GetItemsNotDone();
					var tospeak = "";
					foreach (var t in todos)
						tospeak += t.Name + " ";
					if (tospeak == "") tospeak = "there are no tasks to do";

					DependencyService.Get<ITextToSpeech>().Speak(tospeak);
				}, 0, 0);
				ToolbarItems.Add (tbi2);
			}
			#endregion
		}
Exemplo n.º 29
0
		public TodoListPage ()
		{
			Title = "Todo";

			NavigationPage.SetHasNavigationBar (this, true);

			listView = new ListView ();
			listView.ItemTemplate = new DataTemplate (typeof (TodoItemCell));

//			listView.ItemSource = new string [] { "Buy pears", "Buy oranges", "Buy mangos", "Buy apples", "Buy bananas" };
//			listView.ItemSource = new TodoItem [] { 
//				new TodoItem {Name = "Buy pears`"}, 
//				new TodoItem {Name = "Buy oranges`", Done=true},
//				new TodoItem {Name = "Buy mangos`"}, 
//				new TodoItem {Name = "Buy apples`", Done=true},
//				new TodoItem {Name = "Buy bananas`", Done=true}
//			};

			listView.ItemSelected += (sender, e) => {
				if (e.SelectedItem == null) {
					return; // ensures we ignore this handler when the selection is just being cleared
				}
				var todoItem = (TodoItem)e.SelectedItem;
				var todoPage = new TodoItemPage();
				todoPage.BindingContext = todoItem;
				Navigation.PushAsync(todoPage);
				((ListView)sender).SelectedItem = null; // clears the 'selected' background
			};

			// make floating (+) image at bottom of screen
			var tap = new TapGestureRecognizer (async (View obj) => {
				var todoItem = new TodoItem();
				var todoPage = new TodoItemPage();
				todoPage.BindingContext = todoItem;

				var b = newImage.Bounds;
				b.Y = b.Y - 50;

				await newImage.LayoutTo(b,250, Easing.SinIn);
				b.Y = b.Y + 50;
				await newImage.LayoutTo(b,250, Easing.SinOut);

				Navigation.PushAsync(todoPage);
			});
			newImage = new Image {
				Source = "newitem.png",
				WidthRequest = 40,
				Opacity = 0.8f
			};
			newImage.GestureRecognizers.Add (tap);

			layout = new RelativeLayout ();
			layout.Children.Add (listView, 
				xConstraint: Constraint.Constant(0), 
				yConstraint: Constraint.Constant(0), 
				widthConstraint: Constraint.RelativeToParent ((parent) => {return parent.Width;}),
				heightConstraint: Constraint.RelativeToParent ((parent) => {return parent.Height;}));
			layout.Children.Add (newImage, 
				xConstraint: Constraint.RelativeToParent((parent) =>
					{
						return (parent.Width / 2) - 20; // center of image (which is 40 wide)
					}),
				yConstraint: Constraint.RelativeToParent((parent) =>
					{
						return parent.Height - 60;
					}));
			Content = layout;


			#region toolbar
			var tbi = new ToolbarItem ("+", "plus.png", () => {
				var todoItem = new TodoItem();
				var todoPage = new TodoItemPage();
				todoPage.BindingContext = todoItem;
				Navigation.PushAsync(todoPage);
			}, 0, 0);

			ToolbarItems.Add (tbi);

			if (Device.OS == TargetPlatform.iOS) {
				var tbi2 = new ToolbarItem ("?", "chat.png", () => {
					var todos = App.Database.GetItemsNotDone();
					var tospeak = "";
					foreach (var t in todos)
						tospeak += t.Name + " ";
					if (tospeak == "") tospeak = "there are no tasks to do";
					App.Speech.Speak(tospeak);
				}, 0, 0);
				ToolbarItems.Add (tbi2);
			}
			#endregion
		}
 // this will be called before the view is displayed
 public void SetTask(RootViewController d, TodoItem task)
 {
     Delegate = d;
     currentTask = task;
 }
Exemplo n.º 31
0
 public Task <int> DeleteItemAsync(TodoItem item)
 {
     return(database.DeleteAsync(item));
 }
Exemplo n.º 32
0
        public TodoListPage()
        {
            Title = "Todo";

            NavigationPage.SetHasNavigationBar(this, true);

            listView = new ListView
            {
                RowHeight = 40
            };
            listView.ItemTemplate = new DataTemplate(typeof(TodoItemCell));

            // These commented-out lines were used to test the ListView prior to integrating the database
            //			listView.ItemSource = new string [] { "Buy pears", "Buy oranges", "Buy mangos", "Buy apples", "Buy bananas" };
            //			listView.ItemSource = new TodoItem [] { 
            //				new TodoItem {Name = "Buy pears`"}, 
            //				new TodoItem {Name = "Buy oranges`", Done=true},
            //				new TodoItem {Name = "Buy mangos`"}, 
            //				new TodoItem {Name = "Buy apples`", Done=true},
            //				new TodoItem {Name = "Buy bananas`", Done=true}
            //			};

            // HACK: workaround issue #894 for now
            if (Device.OS == TargetPlatform.iOS)
                listView.ItemsSource = new string[1] { "" };

            listView.ItemSelected += (sender, e) =>
            {
                var todoItem = (TodoItem)e.SelectedItem;
                var todoPage = new TodoItemPage();
                todoPage.BindingContext = todoItem;
                Navigation.PushAsync(todoPage);
            };

            var layout = new StackLayout();
            if (Device.OS == TargetPlatform.WinPhone)
            { // WinPhone doesn't have the title showing
                layout.Children.Add(new Label { Text = "Todo", Font = Font.BoldSystemFontOfSize(NamedSize.Large) });
            }
            layout.Children.Add(listView);
            layout.VerticalOptions = LayoutOptions.FillAndExpand;
            Content = layout;


            ToolbarItem tbi = null;
            if (Device.OS == TargetPlatform.iOS)
            {
                tbi = new ToolbarItem("+", null, () =>
                    {
                        var todoItem = new TodoItem();
                        var todoPage = new TodoItemPage();
                        todoPage.BindingContext = todoItem;
                        Navigation.PushAsync(todoPage);
                    }, 0, 0);
            }
            if (Device.OS == TargetPlatform.Android)
            { // BUG: Android doesn't support the icon being null
                tbi = new ToolbarItem("+", "plus", () =>
                {
                    var todoItem = new TodoItem();
                    var todoPage = new TodoItemPage();
                    todoPage.BindingContext = todoItem;
                    Navigation.PushAsync(todoPage);
                }, 0, 0);
            }
            if (Device.OS == TargetPlatform.WinPhone)
            {
                tbi = new ToolbarItem("Add", "add.png", () =>
                    {
                        var todoItem = new TodoItem();
                        var todoPage = new TodoItemPage();
                        todoPage.BindingContext = todoItem;
                        Navigation.PushAsync(todoPage);
                    }, 0, 0);
            }
                // WINRT
            if (Device.OS == TargetPlatform.Other)
            {
                tbi = new ToolbarItem("Add", "ms-appx:///add.png", () =>
                {
                    var todoItem = new TodoItem();
                    var todoPage = new TodoItemPage();
                    todoPage.BindingContext = todoItem;
                    Navigation.PushAsync(todoPage);
                }, 0, 0);
            }
            if (tbi != null)
                ToolbarItems.Add(tbi);

            if (Device.OS == TargetPlatform.iOS)
            {
                var tbi2 = new ToolbarItem("?", null, () =>
                {
                    var todos = App.Database.GetItemsNotDone();
                    var tospeak = "";
                    foreach (var t in todos)
                        tospeak += t.Name + " ";
                    if (tospeak == "") tospeak = "there are no tasks to do";

                    DependencyService.Get<ITextToSpeech>().Speak(tospeak);
                }, 0, 0);
                ToolbarItems.Add(tbi2);
            }

        }
 public int DeleteItem(TodoItem item)
 {
     return database.DeleteItem(item.Id);
 }
Exemplo n.º 34
0
		public TodoListPage ()
		{
			Title = "Todo";

			listView = new ListView {StyleId = "TodoList"};
			listView.ItemTemplate = new DataTemplate (typeof (TodoItemCell));

			listView.ItemSelected += async (sender, e) => {
				if (e.SelectedItem == null) {
					return; // ensures we ignore this handler when the selection is just being cleared
				}
				var todoItem = (TodoItem)e.SelectedItem;
				var todoPage = new TodoItemPage();
				todoPage.BindingContext = todoItem;
				await Navigation.PushAsync(todoPage);
				((ListView)sender).SelectedItem = null; // clears the 'selected' background
			};

			// make floating (+) image at bottom of screen
			var tap = new TapGestureRecognizer (async (View obj) => {
				var todoItem = new TodoItem();
				var todoPage = new TodoItemPage();
				todoPage.BindingContext = todoItem;

				var b = newImage.Bounds;
				b.Y = b.Y - 50;

				await newImage.LayoutTo(b,250, Easing.SinIn);
				b.Y = b.Y + 50;
				await newImage.LayoutTo(b,250, Easing.SinOut);

				await Navigation.PushAsync(todoPage);
			});
			newImage = new Image {
				Source = "newitem.png",
				WidthRequest = 40,
				Opacity = 0.8f,
				StyleId = "TodoAdd"
			};
			newImage.GestureRecognizers.Add (tap);

			layout = new RelativeLayout ();
			layout.Children.Add (listView, 
				xConstraint: Constraint.Constant(0), 
				yConstraint: Constraint.Constant(0), 
				widthConstraint: Constraint.RelativeToParent ((parent) => {return parent.Width;}),
				heightConstraint: Constraint.RelativeToParent ((parent) => {return parent.Height;}));
			layout.Children.Add (newImage, 
				xConstraint: Constraint.RelativeToParent((parent) =>
					{
						return (parent.Width / 2) - 20; // center of image (which is 40 wide)
					}),
				yConstraint: Constraint.RelativeToParent((parent) =>
					{
						return parent.Height - 60;
					}));
			Content = layout;


			#region toolbar
			var tbiAdd = new ToolbarItem ("+", "plus.png", () => {
				var todoItem = new TodoItem();
				var todoPage = new TodoItemPage();
				todoPage.BindingContext = todoItem;
				Navigation.PushAsync(todoPage);
			}, 0, 0);
			tbiAdd.StyleId = "ToolbarAdd";
			//tbiAdd.Order = ToolbarItemOrder.Secondary;
			ToolbarItems.Add (tbiAdd);

			var tbiSpeak = new ToolbarItem ("?", "chat.png", () => {
				var todos = App.Database.GetItemsNotDone();
				var tospeak = "";
				foreach (var t in todos)
					tospeak += t.Name + " ";
				if (tospeak == "") tospeak = "there are no tasks to do";

				DependencyService.Get<ITextToSpeech>().Speak("Hello from Xamarin Forms");

			}, 0, 0);
			tbiAdd.StyleId = "ToolbarSpeak";
			// demonstrate toolbar/optionmenu
			//tbiSpeak.Order = ToolbarItemOrder.Secondary;
			ToolbarItems.Add (tbiSpeak);

			#endregion
		}
Exemplo n.º 35
0
 public Task DeleteItemAsync(TodoItem item)
 {
     return(Data.DeleteAsync <TodoItem>(item.ID.ToString(), DefaultPartitions.AppDocuments));
 }