示例#1
0
 private void StartService()
 {
     if (permissionGranted)
     {
         //start Service
         if (UtilityClass.IsLocationEnabled(mContext))
         {
             StartServiceAndBind();
             stopService.Enabled = true;
             stopService.Click  += StopServiceListener;
         }
         else
         {
             /*
              * In case the user has his location service turned off we prompt the user
              * to start the service
              * */
             Android.Support.V7.App.AlertDialog dialog = UtilityClass.ShowAlertDialog(this, mContext.Resources.GetString(Resource.String.turn_on_location), "OK", "Cancel");
             Button btnPositive = dialog.GetButton((int)DialogButtonType.Positive);
             btnPositive.Click += (s, e) =>
             {
                 Intent myIntent = new Intent(Android.Provider.Settings.ActionLocationSourceSettings);
                 StartActivity(myIntent);
                 dialog.Dismiss();
             };
             Button btnNegative = dialog.GetButton((int)DialogButtonType.Negative);
             btnNegative.Click += (s, e) =>
             {
                 dialog.Dismiss();
             };
         }
     }
 }
        /// <summary>
        /// Shows a dialog.
        /// </summary>
        /// <param name="title">A dialog title.</param>
        /// <param name="value">A dialog value.</param>
        /// <param name="canCopy">Indicates that "Copy value" is activated.</param>
        /// <param name="valueToCopy">Value to copy by button.</param>
        internal void ShowInfoDialog(string title, string value, bool canCopy, string valueToCopy)
        {
            // dialog builder
            using (Android.Support.V7.App.AlertDialog.Builder dialogBuilder = new Android.Support.V7.App.AlertDialog.Builder(new ContextThemeWrapper(this, Resource.Style.AlertDialogTheme)))
            {
                // create button
                dialogBuilder.SetPositiveButton(Resources.GetString(Resource.String.ok_button), (EventHandler <DialogClickEventArgs>)null);
                if (canCopy)
                {
                    dialogBuilder.SetNeutralButton(Resources.GetString(Resource.String.copy_value_button), (EventHandler <DialogClickEventArgs>)null);
                    _infoDialogValueToCopy = valueToCopy;
                }
                // create dialog
                _infoDialog = dialogBuilder.Create();

                _infoDialog.Window.SetBackgroundDrawableResource(Android.Resource.Drawable.ScreenBackgroundDarkTransparent);
                // set dialog title
                _infoDialog.SetTitle(title);
                // set dialog message
                _infoDialog.SetMessage(value);
                // show on screen
                _infoDialog.Show();

                // get display size
                DisplayMetrics displayMetrics = new DisplayMetrics();
                WindowManager.DefaultDisplay.GetMetrics(displayMetrics);
                int height = (int)(displayMetrics.HeightPixels * 3 / 4);

                // if dialog content height is greater than 3/4 of screen height
                if (_infoDialog.Window.Attributes.Height > height)
                {
                    _infoDialog.Window.SetLayout(_infoDialog.Window.Attributes.Width, height);
                }

                TextView dialogTextView = _infoDialog.FindViewById <TextView>(Android.Resource.Id.Message);
                // allow to select dialog text
                dialogTextView.SetTextIsSelectable(true);
                // allow to click links
                dialogTextView.MovementMethod = LinkMovementMethod.Instance;
                dialogTextView.LinksClickable = true;
                // add links
                Utils.MyLinkify.AddLinks(dialogTextView, Patterns.EmailAddress, null);
                Utils.MyLinkify.AddLinks(dialogTextView, Patterns.WebUrl, null, new Utils.MyLinkify(), null);

                if (canCopy)
                {
                    _infoDialogNeutralButton         = _infoDialog.GetButton((int)DialogButtonType.Neutral);
                    _infoDialogNeutralButton.Click  += NeutralButton_Click;
                    _infoDialogPositiveButton        = _infoDialog.GetButton((int)DialogButtonType.Positive);
                    _infoDialogPositiveButton.Click += PositiveButton_Click;
                }
            }
        }
示例#3
0
        /// <summary>
        /// Change Password
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ResetPassword_Click(object sender, EventArgs e)
        {
            LayoutInflater inflater = LayoutInflater.From(this);
            View           view     = inflater.Inflate(Resource.Layout.dialog_reset_password, null);

            AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);
            alertBuilder.SetView(view);

            var newPassword   = view.FindViewById <EditText>(Resource.Id.dialog_reset_pass);
            var passwordRpt   = view.FindViewById <EditText>(Resource.Id.dialog_reset_pass_rpt);
            var passwordError = view.FindViewById <TextView>(Resource.Id.dialog_reset_pass_error);

            alertBuilder.SetTitle("Reset Password")
            .SetPositiveButton("Submit", delegate
            {
                try
                {
                    var user = auth.CurrentUser.UpdatePassword(newPassword.Text);

                    Toast.MakeText(this, "Done!", ToastLength.Long).Show();

                    //signout
                }
                catch (Exception ex)
                {
                    Toast.MakeText(this, "An error occured. Sorry.", ToastLength.Long).Show();
                }
            })
            .SetNegativeButton("Cancel", delegate
            {
                alertBuilder.Dispose();
            });

            AlertDialog alertDialog = alertBuilder.Create();

            alertDialog.Show();

            var submit = alertDialog.GetButton((int)DialogButtonType.Positive);

            submit.Click += delegate
            {
                if (!passwordRpt.Text.Equals(newPassword.Text))
                {
                    passwordError.Text = "Passwords must match";
                }
                else
                {
                    //update current user
                    var user = auth.CurrentUser;
                    if (user != null)
                    {
                        user.UpdatePassword(newPassword.Text);

                        Toast.MakeText(this, "Done!", ToastLength.Long).Show();
                    }
                    else
                    {
                        Toast.MakeText(this, "You are not logged in!", ToastLength.Long).Show();
                    }

                    alertDialog.Dismiss();
                }
            };
        }