public LoggedIn() { /// ContextDemoList = new ListView(); var datad = new EmergencyContactDB(); var rawdata = datad.GetUserEmergencyContancts(App.userName); bool AddButtonEnable = true; if (rawdata == null) { AddButtonEnable = true; } else if (rawdata != null && rawdata.Count < 3) { AddButtonEnable = true; } else if (rawdata != null && rawdata.Count >= 3) { AddButtonEnable = false; } Label header = new Label { Text = "List Of Contacts", FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label)), HorizontalOptions = LayoutOptions.Center }; ToolbarItem addbutton = new ToolbarItem { IconImageSource = "Resources/drawable/PlusIcon.png", Priority = 0, Command = new Command(this.AddItemCalled), IsEnabled = AddButtonEnable //Text = "Add" }; ToolbarItem logoutbutton = new ToolbarItem { IconImageSource = "Resources/drawable/logoutIcon.png", Priority = 1, Command = new Command(this.LogOutClicked) //Text = "Add" }; var moreAction = new MenuItem { Text = "More" }; moreAction.SetBinding(MenuItem.CommandParameterProperty, new Binding(".")); moreAction.Clicked += async(sender, e) => { var mi = ((MenuItem)sender); Debug.WriteLine("More Context Action clicked: " + mi.CommandParameter); }; var deleteAction = new MenuItem { Text = "Delete", IsDestructive = true }; // red background deleteAction.SetBinding(MenuItem.CommandParameterProperty, new Binding(".")); deleteAction.Clicked += async(sender, e) => { var mi = ((MenuItem)sender); Debug.WriteLine("Delete Context Action clicked: " + mi.CommandParameter); }; //itemList.Add("A"); //itemList.Add("B"); //itemList.Add("C"); //itemList.Add("D"); //itemList.Add("E"); //itemList.Add("F"); //itemList.Add("G"); //ContextDemoList.ItemsSource = itemList; // Create the ListView. ListView listView = new ListView { ItemsSource = rawdata, ItemTemplate = new DataTemplate(() => { Label nameLabel = new Label { TextColor = Color.Black }; nameLabel.SetBinding(Label.TextProperty, "name"); Label relationLabel = new Label { TextColor = Color.Black }; relationLabel.SetBinding(Label.TextProperty, "relation"); return(new ViewCell { View = new StackLayout { Padding = new Thickness(0, 5), Orientation = StackOrientation.Horizontal, Children = { new StackLayout { VerticalOptions = LayoutOptions.Center, Spacing = 0, Children = { nameLabel, relationLabel } } }, }, }); }) }; listView.ItemSelected += (object sender, SelectedItemChangedEventArgs e) => { // DisplayAlert("ItemSelected", e.SelectedItem.ToString(), "Ok"); //var ContactDetailPage = new ContacDetails(); //ContactDetailPage.BindingContext = e.SelectedItem; //EmerygencyContact selected = new EmerygencyContact(); //this.Navigation.PushAsync(new ContacDetails(e.SelectedItem)); }; // add to the ViewCell's ContextActions property // Accomodate iPhone status bar. this.Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5); // Build the page. this.Content = new StackLayout { Children = { header, listView } }; this.ToolbarItems.Add(addbutton); this.ToolbarItems.Add(logoutbutton); InitializeComponent(); }
public override bool OnKeyDown([GeneratedEnum] Keycode keyCode, KeyEvent e) { if (keyCode == Keycode.VolumeDown) { volumeKeyPressedCount = volumeKeyPressedCount + 1; if (volumeKeyPressedCount == 3) { var datad = new Women_Safety_App.EmergencyContactDB(); var rawdata = new List <EmerygencyContact>(); rawdata = datad.GetUserEmergencyContancts(App.userName); if (rawdata.Count > 0) { var phonos = new List <string>(); var LocationTask = GetLocation(); foreach (EmerygencyContact element in rawdata) { phonos.Add(element.phone1); } try { var task = SendSms("I am in emergency. I need Help.", phonos.ToArray()); Task.WhenAll(LocationTask); //var result = AsyncContext.RunTask(MyAsyncMethod).Result; volumeKeyPressedCount = 0; } catch (FeatureNotSupportedException ex) { // Sms is not supported on this device. } catch (Exception ex) { // Other error has occurred. } } else { volumeKeyPressedCount = 0; Toast.MakeText(this, "No Contacts Added", ToastLength.Long); } } } if (keyCode == Keycode.VolumeUp) { volumeUpKeyPressedCount = volumeUpKeyPressedCount + 1; if (volumeUpKeyPressedCount == 3) { var datad = new Women_Safety_App.EmergencyContactDB(); var rawdata = new EmerygencyContact(); rawdata = datad.GetUserEmergencyContanctsForCall(App.userName); if (rawdata == null) { Toast.MakeText(this, "No Contacts Added", ToastLength.Long); } else { PlacePhoneCall(rawdata.phone1); } volumeUpKeyPressedCount = 0; } } //if (keyCode == Keycode.VolumeUp) //{ // Intent intent = new Intent(MediaStore.ActionImageCapture); // App_test._file = new File(App_test._dir, String.Format("myPhoto_{0}.jpg", Guid.NewGuid())); // intent.PutExtra(MediaStore.ExtraOutput, Uri.FromFile(App_test._file)); // StartActivityForResult(intent, 0); // Toast.MakeText(this, "OnKeyDown-VolumeUp", ToastLength.Short).Show(); // return true; //} return(base.OnKeyDown(keyCode, e)); }