Esempio n. 1
0
        private void ShowEmailTemplateModal()
        {
            var alert = new AlertDialog.Builder(Context);
            var view  = mLayoutInflater.Inflate(Resource.Layout.email_template, null);

            view.FindViewById <Button>(Resource.Id.cancelEmailTemplateButton).Click += (object sender, EventArgs e) =>
            {
                Toast.MakeText(Context, "Katkestatud", ToastLength.Short).Show();
                mEmailTemplateModal.Dismiss();
            };
            view.FindViewById <Button>(Resource.Id.saveEmailTemplateButton).Click += (object sender, EventArgs e) =>
            {
                Toast.MakeText(Context, "E-kirja mall salvestatud", ToastLength.Short).Show();
                mEmailSettings.MessageTemplate = mEmailTemplateModal.FindViewById <EditText>(Resource.Id.emailTemplateInput).Text;
                mEmailSettings.Subject         = mEmailTemplateModal.FindViewById <EditText>(Resource.Id.emailSubjectInput).Text;
                mEmailSettings.Recipient       = mEmailTemplateModal.FindViewById <EditText>(Resource.Id.emailRecipientInput).Text;
                SaveSettings(mEmailSettings);
                mEmailTemplateModal.Dismiss();
            };
            view.FindViewById <EditText>(Resource.Id.emailTemplateInput).Text  = mEmailSettings.MessageTemplate;
            view.FindViewById <EditText>(Resource.Id.emailSubjectInput).Text   = mEmailSettings.Subject;
            view.FindViewById <EditText>(Resource.Id.emailRecipientInput).Text = mEmailSettings.Recipient;
            alert.SetView(view);
            mEmailTemplateModal = alert.Create();
            mEmailTemplateModal.Show();
        }
Esempio n. 2
0
        static DateTime DateTimeFromDialog(AlertDialog alertDialog)
        {
            DateTime result;

            using (var dp = alertDialog.FindViewById <DatePicker>(DatePicker))
                using (var tp = alertDialog.FindViewById <TimePicker>(TimePicker))
                {
                    if (dp != null)
                    {
                        dp.ClearFocus();
                    }
                    if (tp != null)
                    {
                        tp.ClearFocus();
                    }

                    int year  = dp != null ? dp.DateTime.Year : 1;
                    int month = dp != null ? dp.DateTime.Month : 1;
                    int day   = dp != null ? dp.DateTime.Day : 1;
                    int hour  = tp != null?tp.CurrentHour.IntValue() : 0;

                    int min = tp != null?tp.CurrentMinute.IntValue() : 0;

                    result = new DateTime(year, month, day, hour, min, 0);
                }
            return(result);
        }
Esempio n. 3
0
        //public override AlertDialog Create()
        //{
        //    AlertDialog dialog = base.Create();

        //    dialog.SetCustomTitle(customTitle);
        //    dialog.SetView(customView);

        //    return dialog;
        //}

        public override AlertDialog Show()
        {
            AlertDialog dialog = base.Show();

            dialog.GetButton((int)DialogButtonType.Positive).SetBackgroundResource(Resource.Drawable.metro_abs_selectablelistitem_style);
            dialog.GetButton((int)DialogButtonType.Negative).SetBackgroundResource(Resource.Drawable.metro_abs_selectablelistitem_style);

            try
            {
                // Title divider
                int  id   = context.Resources.GetIdentifier("titleDivider", "id", "android");
                View view = dialog.FindViewById(id);
                view.SetBackgroundColor(context.Resources.GetColor(Resource.Color.storehouse_blue_dark));

                // Title divider top
                id   = context.Resources.GetIdentifier("titleDividerTop", "id", "android");
                view = dialog.FindViewById(id);
                view.SetBackgroundColor(context.Resources.GetColor(Resource.Color.storehouse_blue_dark));

                // Custom panel
                id   = context.Resources.GetIdentifier("customPanel", "id", "android");
                view = dialog.FindViewById(id);
                view.SetMinimumHeight(0);
            }
            catch (System.Exception e)
            {
                Console.WriteLine(e.Message);
            }

            return(dialog);
        }
Esempio n. 4
0
        private void BtnRGExamItem_Click(object sender, EventArgs e)
        {
            //人工评判
            var text   = ((Button)sender).Text;
            var result = GetDeductionRule(text);

            RGSelectExamItem = text;
            // View view = View.Inflate(this, Resource.Layout.Dialog_ArtificialEvaluation, null);
            TableLayout tableLayout         = (TableLayout)alertDialog.FindViewById(Resource.Id.DeductionRuleTable);
            TableLayout tableLayoutExamItem = (TableLayout)alertDialog.FindViewById(Resource.Id.ExamItemBtnTable);

            //清空所有的 扣分规则
            tableLayout.RemoveAllViews();
            foreach (var item in result)
            {
                TableRow tableRow          = (TableRow)LayoutInflater.From(this).Inflate(Resource.Layout.tableArtificialEvaluation, null);
                TextView tvDeductionReason = (TextView)tableRow.FindViewById(Resource.Id.tvDeductionReason);
                TextView tvDeductionScore  = (TextView)tableRow.FindViewById(Resource.Id.tvDeductionScore);
                Button   btnDeduction      = (Button)tableRow.FindViewById(Resource.Id.btnDeduction);
                tvDeductionReason.Text = item.RuleName;
                tvDeductionScore.Text  = item.DeductedScores.ToString();
                btnDeduction.Text      = "扣分";
                btnDeduction.Tag       = item.RuleCode + "," + item.SubRuleCode;
                btnDeduction.Click    += BtnDeduction_Click;
                tableLayout.AddView(tableRow);
            }
        }
Esempio n. 5
0
        private void InitializeObjects(IList <Measurement> measurements)
        {
            day = dialog.FindViewById <TextView>(Resource.Id.day);
            measurementsOfDay = dialog.FindViewById <ListView>(Resource.Id.measurementsList);

            day.Text = measurements.First().Date.ToShortDateString();
            measurementsOfDay.Adapter = new MeasurementsOfDayAdapter(context, measurements);
        }
Esempio n. 6
0
        private void ShowConfirmationModal(string reading, Mat image)
        {
            if (mConfirmationModal?.IsShowing == true)
            {
                return;
            }
            var alert = new AlertDialog.Builder(Context);
            var view  = mLayoutInflater.Inflate(Resource.Layout.confirmation, null);

            view.FindViewById <Button>(Resource.Id.cancelReadingButton).Click += (object sender, EventArgs e) =>
            {
                Toast.MakeText(Context, "Katkestatud", ToastLength.Short).Show();
                mReadings.Clear();
                mConfirmationModal.Dismiss();
                UpdateReadingsText();
            };
            if (mEmailSettings.NumberOfRequiredReadings > mReadings.Count + 1)
            {
                var button = view.FindViewById <Button>(Resource.Id.captureAnotherReadingButton);
                button.Visibility = ViewStates.Visible;
                button.Click     += (object sender, EventArgs e) =>
                {
                    var confirmedReading = mConfirmationModal.FindViewById <EditText>(Resource.Id.readingEditText).Text;
                    mReadings.Add(confirmedReading);
                    mConfirmationModal.Dismiss();
                    UpdateReadingsText();
                };
            }
            else
            {
                var button = view.FindViewById <Button>(Resource.Id.sendEmailButton);
                button.Visibility = ViewStates.Visible;
                button.Click     += (object sender, EventArgs e) =>
                {
                    var confirmedReading = mConfirmationModal.FindViewById <EditText>(Resource.Id.readingEditText).Text;
                    mReadings.Add(confirmedReading);
                    mConfirmationModal.Dismiss();
                    SendEmail();
                    UpdateReadingsText();
                };
            }
            view.FindViewById <EditText>(Resource.Id.readingEditText).Text = reading;
            using (var stream = image.ToMemoryStream())
            {
                view.FindViewById <ImageView>(Resource.Id.readingImage).SetImageBitmap(BitmapFactory.DecodeStream(stream));
            }
            alert.SetView(view);
            mConfirmationModal = alert.Create();
            mConfirmationModal.Show();
        }
Esempio n. 7
0
        private void InitializeObjects()
        {
            saveButton    = dialog.FindViewById <Button>(Resource.Id.saveButton);
            backButton    = dialog.FindViewById <Button>(Resource.Id.backButton);
            englishButton = dialog.FindViewById <RadioButton>(Resource.Id.englishRadio);
            germanButton  = dialog.FindViewById <RadioButton>(Resource.Id.germanRadio);

            this.backButton.Click += (sender, args) => dialog.Dismiss();
            this.saveButton.Click += (sender, args) => { activity.SaveLanguage(); dialog.Dismiss(); };

            if (LanguageService.CurrentLanguage == Enums.Language.English)
            {
                englishButton.Checked = true;
            }
            else
            {
                germanButton.Checked = true;
            }

            this.englishButton.Click += (sender, args) =>
            {
                if (englishButton.Checked)
                {
                    LanguageService.CurrentLanguage = Enums.Language.English;
                }
                else
                {
                    LanguageService.CurrentLanguage = Enums.Language.German;
                }
            };

            this.germanButton.Click += (sender, args) =>
            {
                if (germanButton.Checked)
                {
                    LanguageService.CurrentLanguage = Enums.Language.German;
                }
                else
                {
                    LanguageService.CurrentLanguage = Enums.Language.English;
                }
            };
        }
Esempio n. 8
0
 public global::Android.Views.View findViewByID(int id)
 {
     if (_useAppCompat)
     {
         return(_appcompatAlertDialog.FindViewById(id));
     }
     else
     {
         return(_legacyAlertDialog.FindViewById(id));
     }
 }
Esempio n. 9
0
        public override string DoDialogGetMessage()
        {
            string      result = "";
            AlertDialog dialog = Context.DialogProviderInternal.Dialogs.Peek();

            if (dialog != null)
            {
                using (var tv = dialog.FindViewById <Android.Widget.TextView>(Android.Resource.Id.Message))
                    result = tv.Text;
            }

            return(result);
        }
Esempio n. 10
0
        public override string DoDialogGetDateTime()
        {
            string      result = "";
            AlertDialog dialog = Context.DialogProviderInternal.Dialogs.Peek();

            if (dialog != null)
            {
                var dp = dialog.FindViewById <Android.Widget.DatePicker>(DialogProvider.DatePicker);
                var tp = dialog.FindViewById <Android.Widget.TimePicker>(DialogProvider.TimePicker);

                var dateTime = new DateTime(dp.DateTime.Year
                                            , dp.DateTime.Month
                                            , dp.DateTime.Day
                                            , tp.CurrentHour.IntValue()
                                            , tp.CurrentMinute.IntValue()
                                            , 0);

                result = dateTime.ToString(CultureInfo.InvariantCulture);
            }

            return(result);
        }
Esempio n. 11
0
        public override bool DoDialogSetDateTime(object hack, string value)
        {
            DateTime dateTime = DateTime.Parse(value);

            bool result = false;

            _context.InvokeOnMainThreadSync(() =>
            {
                AlertDialog dialog = Context.DialogProviderInternal.Dialogs.Peek();
                if (dialog != null)
                {
                    var dp = dialog.FindViewById <Android.Widget.DatePicker>(DialogProvider.DatePicker);
                    var tp = dialog.FindViewById <Android.Widget.TimePicker>(DialogProvider.TimePicker);

                    dp.UpdateDate(dateTime.Year, dateTime.Month, dateTime.Day);
                    tp.CurrentHour   = new Java.Lang.Integer(dateTime.Hour);
                    tp.CurrentMinute = new Java.Lang.Integer(dateTime.Minute);

                    result = true;
                }
            });

            return(result);
        }
Esempio n. 12
0
        private void InitializeObjects()
        {
            heartRate    = dialog.FindViewById <TextView>(Resource.Id.heartRate);
            rangeStatus  = dialog.FindViewById <TextView>(Resource.Id.rangeStatus);
            noteEditText = dialog.FindViewById <EditText>(Resource.Id.note);
            saveButton   = dialog.FindViewById <Button>(Resource.Id.saveButton);
            cancelButton = dialog.FindViewById <Button>(Resource.Id.cancelButton);

            stateGeneral         = dialog.FindViewById <ToggleButton>(Resource.Id.generalState);
            stateGeneral.Checked = true;
            stateBeforeExercise  = dialog.FindViewById <ToggleButton>(Resource.Id.beforeExerciseState);
            stateAfterExercise   = dialog.FindViewById <ToggleButton>(Resource.Id.afterExerciseState);
            stateRest            = dialog.FindViewById <ToggleButton>(Resource.Id.restState);

            stateGeneral.Click        += (sender, args) => SetState(State.General);
            stateBeforeExercise.Click += (sender, args) => SetState(State.BeforeExercise);
            stateAfterExercise.Click  += (sender, args) => SetState(State.AfterExercise);
            stateRest.Click           += (sender, args) => SetState(State.Rest);
            saveButton.Click          += SaveButtonOnClick;
            cancelButton.Click        += CancelButtonOnClick;
        }
Esempio n. 13
0
 private void InitializeLogin(AlertDialog dialog)
 {
     // Create your application here
     loginButton               = dialog.FindViewById <Button>(Resource.Id.dialog_login_loginbutton);
     loginCancelButton         = dialog.FindViewById <Button>(Resource.Id.dialog_login_cancelbutton);
     username                  = dialog.FindViewById <EditText>(Resource.Id.dialog_login_username);
     password                  = dialog.FindViewById <EditText>(Resource.Id.dialog_login_password);
     message                   = dialog.FindViewById <TextView>(Resource.Id.dialog_login_tvmessage);
     forgotpassword            = dialog.FindViewById <TextView>(Resource.Id.login_forgot_password);
     progressBar               = dialog.FindViewById <ProgressBar>(Resource.Id.progress_bar);
     loginButton.Click        += LoginButton_Click;
     loginCancelButton.Click  += LoginCancelButton_Click;
     forgotpassword.Click     += ForgotPassword_Click;
     progressBar.Indeterminate = true;
     progressBar.Visibility    = ViewStates.Gone;
 }
Esempio n. 14
0
        private void BtnAsk_Click(object sender, EventArgs e)
        {
            string confirmedGuess           = etGuessTypingPlace.Text;
            var    confirmedGuessEvaluation = GameManager.getInstance().GetPlayerGuessEvaluation(etGuessTypingPlace.Text);

            if (confirmedGuessEvaluation.Bulls == numberOfDigits)
            {
                GameManager.getInstance().EndGame(true);

                AlertDialog.Builder winDialogBuilder = new AlertDialog.Builder(this);
                winDialogBuilder.SetTitle("You won!");
                winDialogBuilder.SetMessage("You guessed computer's number before it guessed yours");
                winDialogBuilder.SetCancelable(false);
                winDialogBuilder.SetPositiveButton("Main Menu", (object sender, DialogClickEventArgs e) =>
                {
                    Finish();
                });
                AlertDialog winDialog = winDialogBuilder.Create();
                winDialog.Show();
            }
            else
            {
                HistoryItem confirmedGuessOnList = new HistoryItem(confirmedGuess, confirmedGuessEvaluation.Bulls.ToString(), confirmedGuessEvaluation.Cows.ToString());

                historyItemAdapter.AddHistoryItem(confirmedGuessOnList);


                etGuessTypingPlace.Text = "";

                AlertDialog.Builder guessResultDialogbuilder = new AlertDialog.Builder(this);

                guessResultDialogbuilder.SetTitle("Score");
                guessResultDialogbuilder.SetMessage($"    {confirmedGuessEvaluation.Bulls}🎯\n    {confirmedGuessEvaluation.Cows}🐮");
                guessResultDialogbuilder.SetCancelable(false);
                guessResultDialogbuilder.SetPositiveButton("Continue", ContinueToComputerScreen);

                AlertDialog guessResultDialog = guessResultDialogbuilder.Create();

                guessResultDialog.Show();

                TextView tvAlertMessage = guessResultDialog.FindViewById <TextView>(Android.Resource.Id.Message);

                tvAlertMessage.SetTextSize(Android.Util.ComplexUnitType.Dip, 20);
            }
        }
Esempio n. 15
0
        private void InitializeObjects()
        {
            name           = dialog.FindViewById <EditText>(Resource.Id.name);
            gender         = dialog.FindViewById <Spinner>(Resource.Id.gender);
            birthdayText   = dialog.FindViewById <TextView>(Resource.Id.birthdayText);
            birthdayButton = dialog.FindViewById <Button>(Resource.Id.birthdayButton);
            saveButton     = dialog.FindViewById <Button>(Resource.Id.saveButton);
            exitButton     = dialog.FindViewById <Button>(Resource.Id.exitButton);

            saveButton.Click     += SaveButtonOnClick;
            exitButton.Click     += ExitButtonOnClick;
            birthdayButton.Click += ShowDatePickerDialog;
        }
        /// <summary>
        /// Shows the dialog that allows to save the barcode image to a file.
        /// </summary>
        private void ShowSaveDialog()
        {
            // if Android version is equal or higher than 6.0 (API 23)
            if (Android.OS.Build.VERSION.SdkInt >= BuildVersionCodes.M)
            {
                // check WriteExternalStorage permission
                if (_barcodeViewerActivity.CheckSelfPermission(Manifest.Permission.WriteExternalStorage) != Permission.Granted)
                {
                    RequestPermissions(new string[] { Manifest.Permission.WriteExternalStorage }, 0);
                }
            }

            // dialog creater
            using (AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(_barcodeViewerActivity))
            {
                dialogBuilder.SetView(LayoutInflater.From(_barcodeViewerActivity).Inflate(Resource.Layout.save_dialog_layout, null));
                // create buttons
                dialogBuilder.SetPositiveButton(Resource.String.save_button, SaveDialogButtonClicked);
                dialogBuilder.SetNegativeButton(Resource.String.cancel_button, SaveDialogButtonClicked);

                // create dialog
                _saveBarcodeImageDialog = dialogBuilder.Create();

                // set dialog title
                _saveBarcodeImageDialog.SetTitle(Resources.GetString(Resource.String.save_title));

                // show on screen
                _saveBarcodeImageDialog.Show();

                EditText filePathEditText = _saveBarcodeImageDialog.FindViewById <EditText>(Resource.Id.filepath_edit_text);
                filePathEditText.Text = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryPictures).AbsolutePath;
                EditText fileNameEditText = _saveBarcodeImageDialog.FindViewById <EditText>(Resource.Id.filename_edit_text);
                // set filename to the filename edit text
                fileNameEditText.Text = GetDefaultFilename(filePathEditText.Text);

                // get width and height
                EditText widthEditText = _saveBarcodeImageDialog.FindViewById <EditText>(Resource.Id.barcode_width_edit_text);
                widthEditText.Text = _barcodeWidth.ToString();
                EditText heightEditText = _saveBarcodeImageDialog.FindViewById <EditText>(Resource.Id.barcode_height_edit_text);
                heightEditText.Text = _barcodeHeight.ToString();

                // get colors
                EditText foregroundColorEdtiText = _saveBarcodeImageDialog.FindViewById <EditText>(Resource.Id.barcode_foreground_edit_text);
                foregroundColorEdtiText.TextChanged += ColorEdtiText_TextChanged;
                ColorEdtiText_TextChanged(foregroundColorEdtiText, null);
                EditText backgroundColorEdtiText = _saveBarcodeImageDialog.FindViewById <EditText>(Resource.Id.barcode_backround_edit_text);
                backgroundColorEdtiText.TextChanged += ColorEdtiText_TextChanged;
                ColorEdtiText_TextChanged(backgroundColorEdtiText, null);
            }
        }
Esempio n. 17
0
        private void InitializeResponsiblePerson(AlertDialog dialog)
        {
            fullname     = dialog.FindViewById <EditText>(Resource.Id.etf_fullname);
            designation  = dialog.FindViewById <EditText>(Resource.Id.etf_designation);
            mobileNumber = dialog.FindViewById <EditText>(Resource.Id.etf_mobileNumber);
            emailaddress = dialog.FindViewById <EditText>(Resource.Id.etf_emailaddress);
            responsiblePersonCancelButton = dialog.FindViewById <Button>(Resource.Id.dfirp_cancelbutton);
            responsiblePersonDoneButton   = dialog.FindViewById <Button>(Resource.Id.dfirp_donebutton);

            if (facility.ResposiblePerson != null)
            {
                fullname.Text     = facility.ResposiblePerson.FullName;
                designation.Text  = facility.ResposiblePerson.Designation;
                mobileNumber.Text = facility.ResposiblePerson.PhoneNumber;
                emailaddress.Text = facility.ResposiblePerson.EmailAddress;
            }

            responsiblePersonCancelButton.Click += ResponsiblePersonCancelButton_Click;
            responsiblePersonDoneButton.Click   += ResponsiblePersonDoneButton_Click;

            if (isEdit)
            {
                fullname.Enabled     = true;
                designation.Enabled  = true;
                mobileNumber.Enabled = true;
                emailaddress.Enabled = true;
                responsiblePersonDoneButton.Enabled = true;
            }
            else
            {
                fullname.Enabled     = false;
                designation.Enabled  = false;
                mobileNumber.Enabled = false;
                emailaddress.Enabled = false;
                responsiblePersonDoneButton.Enabled = false;
            }
        }
Esempio n. 18
0
        private void InitializeDeed(AlertDialog dialog)
        {
            erfNumber        = dialog.FindViewById <EditText>(Resource.Id.etf_erfnumber);
            titleDeedNumber  = dialog.FindViewById <EditText>(Resource.Id.etf_titledeednumber);
            extentm2         = dialog.FindViewById <EditText>(Resource.Id.etf_extentm2);
            ownerInformation = dialog.FindViewById <EditText>(Resource.Id.etf_ownerinformation);
            deedCancelButton = dialog.FindViewById <Button>(Resource.Id.dfid_cancelbutton);
            deedDoneButton   = dialog.FindViewById <Button>(Resource.Id.dfid_donebutton);

            if (facility.DeedsInfo != null)
            {
                erfNumber.Text        = facility.DeedsInfo.ErFNumber;
                titleDeedNumber.Text  = facility.DeedsInfo.TitleDeedNumber;
                extentm2.Text         = facility.DeedsInfo.Extent;
                ownerInformation.Text = facility.DeedsInfo.OwnerInfomation;
            }
            deedCancelButton.Click += DeedCancelButton_Click;
            deedDoneButton.Click   += DeedDoneButton_Click;

            if (isEdit)
            {
                erfNumber.Enabled        = true;
                titleDeedNumber.Enabled  = true;
                extentm2.Enabled         = true;
                ownerInformation.Enabled = true;
                deedDoneButton.Enabled   = true;
            }
            else
            {
                erfNumber.Enabled        = false;
                titleDeedNumber.Enabled  = false;
                extentm2.Enabled         = false;
                ownerInformation.Enabled = false;
                deedDoneButton.Enabled   = false;
            }
        }
Esempio n. 19
0
        public override Task <int?> ShowDialogAsync(
            object body,
            IEnumerable <object> buttons,
            string caption = null,
            int defaultAcceptButtonIndex      = -1,
            DialogController dialogController = null)
        {
            Context context = ResolveContext();

            AlertDialog.Builder builder = CreateAlertDialogBuilder(context, DialogStyle);

            if (dialogController != null && !dialogController.Cancellable)
            {
                builder.SetCancelable(false);
            }

            if (!string.IsNullOrWhiteSpace(caption))
            {
                var stringParserService = Dependency.Resolve <IStringParserService>();
                var parsedText          = stringParserService.Parse(caption);
                builder.SetTitle(parsedText);
            }

            var bodyView = body as View;

            if (bodyView != null)
            {
                builder.SetView(bodyView);
            }
            else
            {
                var sequence = body as ICharSequence;
                if (sequence != null)
                {
                    builder.SetMessage(sequence);
                }
                else
                {
                    string bodyText = body?.ToString();

                    if (!string.IsNullOrWhiteSpace(bodyText))
                    {
                        var stringParserService = Dependency.Resolve <IStringParserService>();
                        var parsedText          = stringParserService.Parse(bodyText);
                        ;                                               builder.SetMessage(parsedText);
                    }
                }
            }

            List <string> labels     = null;
            int           labelCount = 0;

            if (buttons != null)
            {
                labels = new List <string>();
                foreach (var button in buttons)
                {
                    string buttonText = button.ToString();
                    labels.Add(buttonText);
                }

                labelCount = labels.Count;
            }

            var resultSource = new TaskCompletionSource <int?>();

            if (labelCount >= 2)
            {
                builder.SetNegativeButton(labels[0],
                                          (dialog, whichButton) =>
                {
                    resultSource.TrySetResult(0);
                });

                for (int i = 1; i < labelCount - 1; i++)
                {
                    int iClosureCopy = i;
                    builder.SetNeutralButton(labels[i],
                                             (dialog, whichButton) =>
                    {
                        resultSource.TrySetResult(iClosureCopy);
                    });
                }

                builder.SetPositiveButton(labels[labelCount - 1],
                                          (dialog, whichButton) =>
                {
                    int selectedIndex = labelCount - 1;
                    resultSource.TrySetResult(selectedIndex);
                });
            }
            else
            {
                if (labelCount == 1)
                {
                    string buttonLabel = labels[0];

                    builder.SetPositiveButton(buttonLabel,
                                              (dialog, whichButton) =>
                    {
                        resultSource.TrySetResult(0);
                    });
                }
            }

            builder.NothingSelected += (sender, e) => resultSource.TrySetResult(-1);

            Android.App.Application.SynchronizationContext.Post((object state) =>
            {
                try
                {
                    Interlocked.Increment(ref openDialogCount);

                    AlertDialog alertDialog = builder.Show();

                    var dialogStyles = dialogController?.DialogStyles;

                    if (dialogStyles.HasValue)
                    {
                        var styles    = dialogStyles.Value;
                        var lp        = new WindowManagerLayoutParams();
                        Window window = alertDialog.Window;
                        lp.CopyFrom(window.Attributes);

                        var stretchHorizontal = (styles & DialogStyles.StretchHorizontal) == DialogStyles.StretchHorizontal;
                        var stretchVertical   = (styles & DialogStyles.StretchVertical) == DialogStyles.StretchVertical;
                        lp.Width          = stretchHorizontal ? ViewGroup.LayoutParams.MatchParent : lp.Width;
                        lp.Height         = stretchVertical ? ViewGroup.LayoutParams.MatchParent : lp.Height;                //ViewGroup.LayoutParams.WrapContent;
                        window.Attributes = lp;
                    }

                    //var backgroundImage = dialogController?.BackgroundImage;
                    //
                    //if (backgroundImage != null)
                    //{
                    //	//Window window = alertDialog.Window;
                    //	//window.SetBackgroundDrawable(backgroundImage);;
                    //}

                    alertDialog.CancelEvent += delegate
                    {
                        resultSource.TrySetResult(-1);
                    };

                    if (dialogController != null)
                    {
                        dialogController.CloseRequested += delegate
                        {
                            if (alertDialog.IsShowing)
                            {
                                alertDialog.Cancel();
                            }
                        };
                    }

                    /* Subscribing to the DismissEvent to set the result source
                     * is unnecessary as other events are always raised.
                     * The DismissEvent is, however, always raised and thus
                     * we place the bodyView removal code here. */
                    alertDialog.DismissEvent += (sender, args) =>
                    {
                        Interlocked.Decrement(ref openDialogCount);
                        builder.SetView(null);

                        try
                        {
                            (bodyView?.Parent as ViewGroup)?.RemoveView(bodyView);
                        }
                        catch (ObjectDisposedException)
                        {
                            /* View was already disposed in user code. */
                        }
                        catch (Exception ex)
                        {
                            var log = Dependency.Resolve <ILog>();
                            log.Debug("Exception raised when removing view from alert.", ex);
                        }
                    };

                    if (AlertDialogDividerColor.HasValue)
                    {
                        var resources     = context.Resources;
                        int id            = resources.GetIdentifier("titleDivider", "id", "android");
                        View titleDivider = alertDialog.FindViewById(id);
                        if (titleDivider != null)
                        {
                            var color = AlertDialogDividerColor.Value;
                            if (color == Color.Transparent)
                            {
                                titleDivider.Visibility = ViewStates.Gone;
                            }

                            titleDivider.SetBackgroundColor(color);
                        }
                    }

                    if (AlertDialogTitleColor.HasValue)
                    {
                        var resources = context.Resources;
                        int id        = resources.GetIdentifier("alertTitle", "id", "android");
                        var textView  = alertDialog.FindViewById <TextView>(id);
                        if (textView != null)
                        {
                            var color = AlertDialogTitleColor.Value;
                            textView.SetTextColor(color);
                        }
                    }

                    if (AlertDialogBackgroundColor.HasValue)
                    {
                        var v = bodyView ?? alertDialog.ListView;
                        v.SetBackgroundColor(AlertDialogBackgroundColor.Value);
                    }
                }
                catch (WindowManagerBadTokenException ex)
                {
                    /* See http://stackoverflow.com/questions/2634991/android-1-6-android-view-windowmanagerbadtokenexception-unable-to-add-window*/
                    resultSource.SetException(new Exception(
                                                  "Unable to use the Application.Context object to create a dialog. Please either set the Context property of this DialogService or register the current activity using Dependency.Register<Activity>(myActivity)", ex));
                }
            }, null);

            return(resultSource.Task);
        }
Esempio n. 20
0
        private void InitializeLocation(AlertDialog dialog)
        {
            int listViewMinimumHeight = 25;

            streetAddress        = dialog.FindViewById <EditText>(Resource.Id.etf_streetAddress);
            suburb               = dialog.FindViewById <EditText>(Resource.Id.etf_suburb);
            region               = dialog.FindViewById <EditText>(Resource.Id.etf_region);
            province             = dialog.FindViewById <Spinner>(Resource.Id.sf_province);
            localmunicipality    = dialog.FindViewById <Spinner>(Resource.Id.sf_localmunicipality);
            locationCancelButton = dialog.FindViewById <Button>(Resource.Id.dfil_cancelbutton);
            locationDoneButton   = dialog.FindViewById <Button>(Resource.Id.dfil_donebutton);
            gpsLocationButton    = dialog.FindViewById <FloatingActionButton>(Resource.Id.gpscaddlocation_button);
            bpLocationButton     = dialog.FindViewById <FloatingActionButton>(Resource.Id.bpaddlocation_button);
            refashAccuracy       = dialog.FindViewById <FloatingActionButton>(Resource.Id.refreshaccuracy_button);
            tvfLatitude          = dialog.FindViewById <TextView>(Resource.Id.tvf_latitude);
            tvfLongitude         = dialog.FindViewById <TextView>(Resource.Id.tvf_longitude);
            boundaryPolygonsText = dialog.FindViewById <TextView>(Resource.Id.boundaryPolygonsText);
            accuracyMessage      = dialog.FindViewById <TextView>(Resource.Id.accuracy_message);
            bpListView           = dialog.FindViewById <ListView>(Resource.Id.bplistView1);
            itemList             = new List <string>();
            bpListView.SetMinimumHeight(listViewMinimumHeight);
            refashAccuracy.Click += RefashAccuracy_Click;
            if (facility.Location != null)
            {
                streetAddress.Text = facility.Location.StreetAddress;
                suburb.Text        = facility.Location.Suburb;
                region.Text        = facility.Location.Region;
                province.SetSelection(GetIndex(province, facility.Location.Province));
                localmunicipality.SetSelection(GetIndex(localmunicipality, facility.Location.LocalMunicipality));
                listViewMinimumHeight = listViewMinimumHeight * facility.Location.BoundryPolygon.Count();
                if (facility.Location.GPSCoordinates != null)
                {
                    tvfLatitude.Text  = "Lat: " + facility.Location.GPSCoordinates.Latitude;
                    tvfLongitude.Text = " Long: " + facility.Location.GPSCoordinates.Longitude;
                }


                if (facility.Location.BoundryPolygon != null)
                {
                    bpListView.SetMinimumHeight(listViewMinimumHeight);
                    _BoundryPolygons = new List <BoundryPolygon>();
                    foreach (var BoundaryPolygon in facility.Location.BoundryPolygon)
                    {
                        _BoundryPolygons.Add(BoundaryPolygon);
                        itemList.Add("Lat: " + BoundaryPolygon.Latitude.ToString() + " Long: " + BoundaryPolygon.Longitude.ToString());
                    }

                    arrayAdapter              = new ArrayAdapter <string>(Activity, Resource.Layout.list_item, itemList);
                    bpListView.Adapter        = arrayAdapter;
                    bpListView.ItemLongClick += Adapter_ItemSwipe;
                }
                boundaryPolygonsText.Text = String.Format("Boundary Polygons {0}", itemList.Count);
            }


            locationCancelButton.Click += LocationCancelButton_Click;
            locationDoneButton.Click   += LocationDoneButton_Click;
            bpLocationButton.Click     += BPLocationButton_Click;
            gpsLocationButton.Click    += GPSLocationButton_Click;

            Android.Content.Res.ColorStateList csl  = new Android.Content.Res.ColorStateList(new int[][] { new int[0] }, new int[] { Android.Graphics.Color.ParseColor("#008000") }); bpLocationButton.BackgroundTintList = csl;
            Android.Content.Res.ColorStateList cslf = new Android.Content.Res.ColorStateList(new int[][] { new int[0] }, new int[] { Android.Graphics.Color.ParseColor("#008000") }); gpsLocationButton.BackgroundTintList = cslf;

            if (isEdit)
            {
                streetAddress.Enabled      = true;
                suburb.Enabled             = true;
                region.Enabled             = true;
                province.Enabled           = true;
                localmunicipality.Enabled  = true;
                locationDoneButton.Enabled = true;
                gpsLocationButton.Enabled  = true;
                bpLocationButton.Enabled   = true;
            }
            else
            {
                streetAddress.Enabled      = false;
                suburb.Enabled             = false;
                region.Enabled             = false;
                province.Enabled           = false;
                localmunicipality.Enabled  = false;
                locationDoneButton.Enabled = false;
                gpsLocationButton.Enabled  = false;
                bpLocationButton.Enabled   = false;
            }

            GPSTracker GPSTracker = new GPSTracker();

            Android.Locations.Location location = GPSTracker.GPSCoordinate();
            if (location != null)
            {
                accuracyMessage.Text = String.Format("Accurate to {0} Meters", location.Accuracy.ToString());
            }
        }
        /// <summary>
        /// Save dialog button is clicked.
        /// </summary>
        private void SaveDialogButtonClicked(object sender, DialogClickEventArgs args)
        {
            // get colors edit text views
            EditText foregroundColorEdtiText = _saveBarcodeImageDialog.FindViewById <EditText>(Resource.Id.barcode_foreground_edit_text);
            EditText backgroundColorEdtiText = _saveBarcodeImageDialog.FindViewById <EditText>(Resource.Id.barcode_backround_edit_text);

            backgroundColorEdtiText.TextChanged -= ColorEdtiText_TextChanged;
            foregroundColorEdtiText.TextChanged -= ColorEdtiText_TextChanged;

            // if "Save" button clicked
            if (args.Which == (int)DialogButtonType.Positive)
            {
                // get file path
                EditText filePathEditText = _saveBarcodeImageDialog.FindViewById <EditText>(Resource.Id.filepath_edit_text);
                EditText fileNameEditText = _saveBarcodeImageDialog.FindViewById <EditText>(Resource.Id.filename_edit_text);

                if (string.IsNullOrWhiteSpace(fileNameEditText.Text))
                {
                    Toast.MakeText(_barcodeViewerActivity, Resource.String.filename_empty_message, ToastLength.Long).Show();
                    return;
                }
                if (string.IsNullOrWhiteSpace(filePathEditText.Text))
                {
                    Toast.MakeText(_barcodeViewerActivity, Resource.String.filepath_empty_message, ToastLength.Long).Show();
                    return;
                }

                // get width and height
                EditText widthEditText  = _saveBarcodeImageDialog.FindViewById <EditText>(Resource.Id.barcode_width_edit_text);
                EditText heightEditText = _saveBarcodeImageDialog.FindViewById <EditText>(Resource.Id.barcode_height_edit_text);

                // save showing settings
                WriterSettings previousSettings = _barcodeWriter.Settings.Clone();

                // set colors to the writer
                _barcodeWriter.Settings.ForeColor = ((ColorDrawable)foregroundColorEdtiText.Background).Color;
                _barcodeWriter.Settings.BackColor = ((ColorDrawable)backgroundColorEdtiText.Background).Color;
                // get path to the file
                string fullPathWithExtention = System.IO.Path.Combine(filePathEditText.Text, fileNameEditText.Text) + ".png";

                try
                {
                    int width  = Int32.Parse(widthEditText.Text);
                    int height = Int32.Parse(heightEditText.Text);
                    // create a file
                    using (FileStream outStream = new FileStream(fullPathWithExtention, FileMode.Create, FileAccess.Write))
                    {
                        // if barcode type is EAN or UPCA or UPCE type
                        if (Utils.IsEanOrUpcaOrUpceBarcode(_barcodeWriter.Settings.Barcode))
                        {
                            _barcodeWriter.Settings.Height = height;
                            _barcodeWriter.Settings.SetWidth(width);
                            _barcodeWriter.Settings.ValuePaint.TextSize = Resources.GetDimensionPixelSize(Resource.Dimension.barcode_value_viewer_text_size);
                            // draw the barcode
                            // create the barcode image
                            using (Bitmap barcodeImage = _barcodeWriter.GetBarcodeAsBitmap())
                            {
                                // save the barcode image to the file
                                barcodeImage.Compress(Bitmap.CompressFormat.Png, 100, outStream);
                            }
                        }
                        else
                        {
                            // create the barcode image
                            using (Bitmap barcodeImage = _barcodeWriter.GetBarcodeAsBitmap(width, height, UnitOfMeasure.Pixels))
                            {
                                // save the barcode image to the file
                                barcodeImage.Compress(Bitmap.CompressFormat.Png, 100, outStream);
                            }
                        }
                    }

                    // notify user that the barcode image is successfully saved to the file
                    string message = string.Format(Resources.GetString(Resource.String.barcode_saved_message), fullPathWithExtention);
                    Toast.MakeText(_barcodeViewerActivity, message, ToastLength.Long).Show();
                }
                catch (Exception e)
                {
                    Toast.MakeText(_barcodeViewerActivity, e.Message, ToastLength.Long).Show();
                    if (File.Exists(fullPathWithExtention))
                    {
                        File.Delete(fullPathWithExtention);
                    }
                }

                // return showing settings
                _barcodeWriter.Settings = previousSettings;
            }
        }
        public void ShowInRegionPersonDetail(InRegionPerson item)
        {
            if (_CurDialog == null || !_CurDialog.IsShowing)
            {
                _CurDialog = CreateDialog();
            }
            _CurDialogCreateTime = DateTime.Now;
            var txtName = _CurDialog.FindViewById <TextView>(Resource.Id.txtName);

            txtName.Text = item.UserName;
            var txtCardID = _CurDialog.FindViewById <TextView>(Resource.Id.txtCardID);

            txtCardID.Text = item.CardID;
            var txtDept = _CurDialog.FindViewById <TextView>(Resource.Id.txtDept);

            txtDept.Text = item.Department;
            var txtDoor = _CurDialog.FindViewById <TextView>(Resource.Id.txtDoor);

            txtDoor.Text = item.DoorName;
            var txtTime = _CurDialog.FindViewById <TextView>(Resource.Id.txtTime);

            txtTime.Text = item.EnterDateTime.ToString("yyyy-MM-dd HH:mm:ss");
            var picAlarm = _CurDialog.FindViewById <ImageView>(Resource.Id.picAlarm);

            picAlarm.Visibility = Android.Views.ViewStates.Gone;
            if (!_DicPerson.ContainsKey(item.UserID))
            {
                GetPersonDetail(item.UserID);                                       //如果不存在此用户信息,则先获取一次
            }
            if (_DicPerson.ContainsKey(item.UserID))
            {
                var person   = _DicPerson[item.UserID];
                var txtPhone = _CurDialog.FindViewById <TextView>(Resource.Id.txtPhone);
                txtPhone.Text = person.Phone;
                var picPhoto = _CurDialog.FindViewById <ImageView>(Resource.Id.picPhoto);
                picPhoto.SetImageBitmap(null);
                if (person.Photo != null && person.Photo.Length > 0)
                {
                    var bmp = BitmapFactory.DecodeByteArray(person.Photo, 0, person.Photo.Length);
                    picPhoto.SetImageBitmap(bmp);
                }
            }
        }