public override void OnAttachedToWindow() { base.OnAttachedToWindow(); if (CurrentExpense != null && CurrentExpense.Id != 0) { expenseViewModel.LoadPhotoAsync(CurrentExpense).ContinueWith(_ => { activity.RunOnUiThread(() => { if (expenseViewModel.Photo != null) { if (expenseViewModel.Photo.Image != null) { imageBitmap = BitmapFactory.DecodeByteArray(expenseViewModel.Photo.Image, 0, expenseViewModel.Photo.Image.Length); imageBitmap = Extensions.ResizeBitmap(imageBitmap, Constants.MaxWidth, Constants.MaxHeight); } expensePhoto.SetImageBitmap(imageBitmap); expenseAddPhoto.Visibility = ViewStates.Gone; } else { expensePhoto.SetImageBitmap(null); expenseAddPhoto.Visibility = ViewStates.Visible; } }); }); expenseType.SetSelection(expenseTypes.ToList().IndexOf(CurrentExpense.Category)); expenseAmount.Text = CurrentExpense.Cost.ToString("0.00"); expenseDescription.Text = CurrentExpense.Description; deleteExpense.Visibility = CurrentExpense.Id != 0 ? ViewStates.Visible : ViewStates.Gone; } else { expenseViewModel.Photo = null; expensePhoto.SetImageBitmap(null); expenseAmount.Text = "0.00"; expenseDescription.Text = string.Empty; expenseType.SetSelection(0); expenseAddPhoto.Visibility = ViewStates.Visible; deleteExpense.Visibility = ViewStates.Gone; } }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Create your application here SetContentView(Resource.Layout.MapViewLayout); assignmentMapViewLayout = FindViewById <LinearLayout> (Resource.Id.mapViewAssignmentLayout); assignmentMapViewLayout.Click += (sender, e) => { var intent = new Intent(this, typeof(SummaryActivity)); var tabActivity = (AssignmentTabActivity)Parent; tabActivity.MapData = null; assignmentViewModel.SelectedAssignment = assignmentViewModel.ActiveAssignment; menuViewModel.MenuIndex = Constants.Navigation.IndexOf("Map"); StartActivity(intent); }; // mapView = FindViewById<MapView> (Resource.Id.googleMapsView); // // myLocation = new MyLocationOverlay (this, mapView); // // mapView.Overlays.Add (myLocation); // mapView.Clickable = true; // mapView.Enabled = true; // mapView.SetBuiltInZoomControls (true); //View containing the active assignment var view = new View(this); LayoutInflater inflator = (LayoutInflater)GetSystemService(Context.LayoutInflaterService); view = inflator.Inflate(Resource.Layout.AssignmentItemLayout, null); assignmentMapViewLayout.AddView(view); view.LayoutParameters = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FillParent, LinearLayout.LayoutParams.WrapContent); view.SetBackgroundDrawable(Resources.GetDrawable(Resource.Drawable.active_assignment_selector)); number = view.FindViewById <TextView> (Resource.Id.assignmentItemNumber); job = view.FindViewById <TextView> (Resource.Id.assignmentJob); name = view.FindViewById <TextView> (Resource.Id.assignmentName); phone = view.FindViewById <TextView> (Resource.Id.assignmentPhone); address = view.FindViewById <TextView> (Resource.Id.assignmentAddress); buttonLayout = view.FindViewById <LinearLayout> (Resource.Id.assignmentButtonLayout); timerLayout = view.FindViewById <LinearLayout> (Resource.Id.assignmentTimerLayout); activeSpinner = view.FindViewById <Spinner> (Resource.Id.assignmentStatus); spinnerImage = view.FindViewById <ImageView> (Resource.Id.assignmentStatusImage); timer = view.FindViewById <ToggleButton> (Resource.Id.assignmentTimer); timerText = view.FindViewById <TextView> (Resource.Id.assignmentTimerText); phoneButton = view.FindViewById <RelativeLayout> (Resource.Id.assignmentPhoneLayout); mapButton = view.FindViewById <RelativeLayout> (Resource.Id.assignmentAddressLayout); phoneButton.Click += (sender, e) => { Extensions.MakePhoneCall(this, phone.Text); }; mapButton.Click += (sender, e) => { var intent = new Intent(this, typeof(SummaryActivity)); var tabActivity = (AssignmentTabActivity)Parent; tabActivity.MapData = null; assignmentViewModel.SelectedAssignment = assignmentViewModel.ActiveAssignment; menuViewModel.MenuIndex = 0; StartActivity(intent); }; assignmentViewModel.LoadTimerEntryAsync().ContinueWith(_ => { RunOnUiThread(() => { if (assignmentViewModel.Recording) { timer.Checked = true; } else { timer.Checked = false; } }); }); timer.CheckedChange += (sender, e) => { if (e.IsChecked != assignmentViewModel.Recording) { if (assignmentViewModel.Recording) { assignmentViewModel.PauseAsync(); } else { assignmentViewModel.RecordAsync(); } } }; activeSpinner.ItemSelected += (sender, e) => { if (assignment != null) { var selected = assignmentViewModel.AvailableStatuses.ElementAtOrDefault(e.Position); if (selected != assignment.Status) { switch (selected) { case AssignmentStatus.Hold: assignment.Status = selected; assignmentViewModel.SaveAssignmentAsync(assignment).ContinueWith(_ => { RunOnUiThread(() => { SetAssignment(false); // mapView.Overlays.Clear (); // mapView.Overlays.Add (myLocation); UpdateLocations(); }); }); break; case AssignmentStatus.Complete: //go to confirmations var intent = new Intent(this, typeof(SummaryActivity)); menuViewModel.MenuIndex = Constants.Navigation.IndexOf(Constants.Confirmations); StartActivity(intent); break; default: break; } } } }; }
public void OnClick(View v) { switch (v.Id) { case Resource.Id.addExpenseDelete: if (CurrentExpense != null && CurrentExpense.Id != -1) { DeleteExpense(); } else { // Dismiss (); } break; case Resource.Id.addExpenseSave: SaveExpense(); break; case Resource.Id.addExpenseCancel: // Dismiss (); break; case Resource.Id.addExpenseAddPhoto: { var choices = new List <string> (); choices.Add(activity.Resources.GetString(Resource.String.Gallery)); if (mediaPicker.IsCameraAvailable) { choices.Add(activity.Resources.GetString(Resource.String.Camera)); } AlertDialog.Builder takePictureDialog = new AlertDialog.Builder(activity); takePictureDialog.SetTitle("Select:"); takePictureDialog.SetItems(choices.ToArray(), (innerSender, innerE) => { if (innerE.Which == 0) { //gallery mediaPicker.PickPhotoAsync().ContinueWith(t => { if (t.IsCanceled) { return; } activity.RunOnUiThread(() => { expenseAddPhoto.Visibility = ViewStates.Gone; imageBitmap = BitmapFactory.DecodeStream(t.Result.GetStream()); imageBitmap = Extensions.ResizeBitmap(imageBitmap, Constants.MaxWidth, Constants.MaxHeight); expensePhoto.SetImageBitmap(imageBitmap); expenseViewModel.Photo = new ExpensePhoto { ExpenseId = CurrentExpense.Id }; }); }); } else if (innerE.Which == 1) { //camera StoreCameraMediaOptions options = new StoreCameraMediaOptions(); options.Directory = "FieldService"; options.Name = "FieldService.jpg"; mediaPicker.TakePhotoAsync(options).ContinueWith(t => { if (t.IsCanceled) { return; } activity.RunOnUiThread(() => { expenseAddPhoto.Visibility = ViewStates.Gone; imageBitmap = BitmapFactory.DecodeStream(t.Result.GetStream()); imageBitmap = Extensions.ResizeBitmap(imageBitmap, Constants.MaxWidth, Constants.MaxHeight); expensePhoto.SetImageBitmap(imageBitmap); expenseViewModel.Photo = new ExpensePhoto { ExpenseId = CurrentExpense.Id }; }); }); } }); takePictureDialog.Show(); } break; default: break; } }