Exemple #1
0
        public static ImageFragment NewInstance(string imagePath, float rotation)
        {
            Bundle args = new Bundle();
            args.PutString(EXTRA_IMAGE_PATH, imagePath);
            args.PutFloat(EXTRA_IMAGE_ROTATION, rotation);

            ImageFragment fragment = new ImageFragment();
            fragment.Arguments = args;
            fragment.SetStyle((int)DialogFragmentStyle.NoTitle, 0);

            return fragment;
        }
Exemple #2
0
        public static ImageFragment NewInstance(string imagePath, float rotation)
        {
            Bundle args = new Bundle();

            args.PutString(EXTRA_IMAGE_PATH, imagePath);
            args.PutFloat(EXTRA_IMAGE_ROTATION, rotation);

            ImageFragment fragment = new ImageFragment();

            fragment.Arguments = args;
            fragment.SetStyle((int)DialogFragmentStyle.NoTitle, 0);

            return(fragment);
        }
Exemple #3
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View v = inflater.Inflate(Resource.Layout.fragment_crime, container, false);

            if (Build.VERSION.SdkInt >= BuildVersionCodes.Honeycomb)
            {
                // Using ParentActivity and NavUtils causes OnCreate to be called again
                // in CrimeListFragment, causing the subtitle view to be reset
//				if (NavUtils.GetParentActivityName(Activity) != null) {
                Activity.ActionBar.SetDisplayHomeAsUpEnabled(true);
//				}
            }

            mTitleField = (EditText)v.FindViewById(Resource.Id.crime_title_edittext);
            mTitleField.SetText(mCrime.Title, TextView.BufferType.Normal);
            mTitleField.BeforeTextChanged += (object sender, Android.Text.TextChangedEventArgs e) => {
                // nothing for now
            };
            mTitleField.TextChanged       += (object sender, Android.Text.TextChangedEventArgs e) => {
                mCrime.Title = e.Text.ToString();
                mCallBacks.OnCrimeUpdated();
            };
            mTitleField.AfterTextChanged += (object sender, Android.Text.AfterTextChangedEventArgs e) => {
                // nothing for now
            };

            // One DateTime Button
            mDateButton        = (Button)v.FindViewById(Resource.Id.crime_date_button);
            mDateButton.Click += (sender, e) => {
                Android.App.AlertDialog.Builder builder = new Android.App.AlertDialog.Builder(Activity);
                builder.SetTitle(Resource.String.date_or_time_alert_title);
                builder.SetPositiveButton(Resource.String.date_or_time_alert_date, (object date, DialogClickEventArgs de) => {
                    Android.Support.V4.App.FragmentManager fm = Activity.SupportFragmentManager;
                    DatePickerFragment dialog = DatePickerFragment.NewInstance(mCrime.Date);
                    dialog.SetTargetFragment(this, REQUEST_DATE);
                    dialog.Show(fm, CrimeFragment.DIALOG_DATE);
                });
                builder.SetNegativeButton(Resource.String.date_or_time_alert_time, (object time, DialogClickEventArgs de) => {
                    Android.Support.V4.App.FragmentManager fm = Activity.SupportFragmentManager;
                    TimePickerFragment dialog = TimePickerFragment.NewInstance(mCrime.Date);
                    dialog.SetTargetFragment(this, REQUEST_TIME);
                    dialog.Show(fm, CrimeFragment.DIALOG_TIME);
                });
                builder.Show();
            };

            // Separate date and time buttons
//			mDateButton = (Button)v.FindViewById(Resource.Id.crime_date_button);
//			mDateButton.Click += (sender, e) => {
//				FragmentManager fm = Activity.SupportFragmentManager;
//				DatePickerFragment dialog = DatePickerFragment.NewInstance(mCrime.Date);
//				dialog.SetTargetFragment(this, REQUEST_DATE);
//				dialog.Show(fm, CrimeFragment.DIALOG_DATE);
//			};
//
//			mTimeButton = (Button)v.FindViewById(Resource.Id.crime_time_button);
//			mTimeButton.Click += (sender, e) => {
//				FragmentManager fm = Activity.SupportFragmentManager;
//				TimePickerFragment dialog = TimePickerFragment.NewInstance(mCrime.Date);
//				dialog.SetTargetFragment(this, REQUEST_TIME);
//				dialog.Show(fm, CrimeFragment.DIALOG_TIME);
//			};

            UpdateDateTime();

            mSolvedCheckBox                = (CheckBox)v.FindViewById(Resource.Id.crime_solved_checkbox);
            mSolvedCheckBox.Checked        = mCrime.Solved;
            mSolvedCheckBox.CheckedChange += (object sender, CompoundButton.CheckedChangeEventArgs e) => {
                mCrime.Solved = e.IsChecked;
                mCallBacks.OnCrimeUpdated();
            };

            mPhotoView        = v.FindViewById <ImageView>(Resource.Id.crime_imageView);
            mPhotoView.Click += (object sender, EventArgs e) => {
                Photo p = mCrime.Photo;
                if (p == null)
                {
                    return;
                }
                Android.Support.V4.App.FragmentManager fm = Activity.SupportFragmentManager;

                // BNR
//				string path = Activity.GetFileStreamPath(p.Filename).AbsolutePath;
                if (p.Filename != null)
                {
                    ImageFragment.NewInstance(p.Filename, p.GetRotation()).Show(fm, DIALOG_IMAGE);
                }
            };
            mPhotoView.LongClick += (object sender, View.LongClickEventArgs e) => {
                if (mCrime.Photo != null)
                {
                    AlertDialog.Builder ad = new AlertDialog.Builder(Activity);
                    ad.SetTitle(mCrime.Title);
                    ad.SetMessage("Do you really want to delete the photo evidence of this crime?");
                    ad.SetCancelable(true);
                    ad.SetPositiveButton("DELETE", delegate(object s, DialogClickEventArgs evt) {
                        if (File.Exists(mCrime.Photo.Filename))
                        {
                            File.Delete(mCrime.Photo.Filename);
                            mCrime.Photo = null;
                            mPhotoView.SetImageDrawable(null);
                        }
                    });
                    ad.SetNegativeButton("Cancel", (s, evt) => {});
                    ad.Show();
                }
            };


            // From Xamarin guide
            mPhotoButton = v.FindViewById <ImageButton>(Resource.Id.crime_imageButton);
            if (IsAppToTakePicture())
            {
                CreateDirectoryForPictures();

                mPhotoButton.Click += (object sender, EventArgs e) => {
                    // From xamarin guide
                    Intent intent = new Intent(MediaStore.ActionImageCapture);

                    PhotoApp._file = new Java.IO.File(PhotoApp._dir, String.Format("{0}.jpg", Guid.NewGuid()));

                    intent.PutExtra(MediaStore.ExtraOutput, Android.Net.Uri.FromFile(PhotoApp._file));

                    StartActivityForResult(intent, REQUEST_PHOTO);

                    // From BNR Book - trying Xamarin method above
//					Intent i = new Intent(Activity, typeof(CrimeCameraActivity));
//					StartActivityForResult(i, REQUEST_PHOTO);
                };
            }
            else
            {
                mPhotoButton.Enabled = false;
            }
            // If camera is not available, disable button - checked in the if statement above
            // just shows another method
//			PackageManager pm = Activity.PackageManager;
//			if (!pm.HasSystemFeature(PackageManager.FeatureCamera) && !pm.HasSystemFeature(PackageManager.FeatureCameraFront)) {
//				mPhotoButton.Enabled = false;
//			}

            Button reportButton = v.FindViewById <Button>(Resource.Id.crime_reportButton);

            reportButton.Click += (object sender, EventArgs e) => {
                Intent i = new Intent(Intent.ActionSend);
                i.SetType("text/plain");
                i.PutExtra(Intent.ExtraText, GetCrimeReport());
                i.PutExtra(Intent.ExtraSubject, GetString(Resource.String.crime_report_subject));
                i = Intent.CreateChooser(i, GetString(Resource.String.send_report));
                StartActivity(i);
            };

            mSuspectButton = v.FindViewById <Button>(Resource.Id.crime_suspectButton);
            mCallButton    = v.FindViewById <Button>(Resource.Id.crime_callButton);

            mSuspectButton.Click += (object sender, EventArgs e) => {
                Intent i = new Intent(Intent.ActionPick, ContactsContract.Contacts.ContentUri);
                StartActivityForResult(i, REQUEST_CONTACT);
            };

            if (mCrime.Suspect != null)
            {
                mSuspectButton.Text = GetString(Resource.String.crime_report_suspect, mCrime.Suspect);
            }

            if (mCrime.PhoneNumber != null)
            {
                mCallButton.Text    = GetString(Resource.String.crime_report_call) + " " + mCrime.PhoneNumber;
                mCallButton.Enabled = true;
            }
            else
            {
                mCallButton.Enabled = false;
            }

            mCallButton.Click += (object sender, EventArgs e) => {
                Intent i = new Intent(Intent.ActionDial, Android.Net.Uri.Parse("tel:" + mCrime.PhoneNumber));                //.Replace("(","").Replace(")","").Replace("-","")));
                StartActivity(i);
            };

            return(v);
        }