Example #1
0
        private async void OnResetPassword(object sender, EventArgs e)
        {
            string confirmCode = tbConfirmCode.TrimInput();

            if (confirmCode.Length < 6)
            {
                //  Enter cofirm code
                tbConfirmCode.RequestFocus();
                tbConfirmCode.SelectAll();

                //
                ShowMessage("Please enter a valid reset code");
                return;
            }

            string passwordNew     = tbPwd.Text;
            string passwordConfirm = tbPwdConfirm.Text;

            if (passwordNew.Length < 6)
            {
                tbPwd.RequestFocus();
                tbPwd.SelectAll();
                return;
            }

            if (passwordConfirm != passwordNew)
            {
                tbPwd.RequestFocus();
                tbPwd.SelectAll();
                return;
            }

            //  Validate code
            using (Busy())
            {
                var proxy    = ProxyFactory.GetProxyInstace();
                var response = await proxy.ExecuteAsync(API.Endpoints.AccountEndpoints.ResetPassword(confirmCode, resetBearerToken, passwordNew));

                if (response.Successful)
                {
                    SetResult(Result.Ok);
                    Finish();
                }
                else
                {
                    ShowMessage(response.GetErrorDescription());
                }
            }
        }
        private void AddAutocompleteToLayout(string [] autocomplete, int resource, string title)
        {
            var lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FillParent, LinearLayout.LayoutParams.WrapContent);

            lp.SetMargins(50, 5, 50, 5);
            _linearLayout.LayoutParameters = lp;
            _linearLayout.AddView(new TextView(_activity)
            {
                Text = title
            }, lp);
            var adapter = new ArrayAdapter(_activity, resource, autocomplete);

            _autoCompleteText.Adapter = adapter;
            if (_win != null)
            {
                _autoCompleteText.Text = _win;
                _autoCompleteText.SelectAll();
            }

            if (_note != null)
            {
                _noteText.Text = _note;
                _noteText.SelectAll();
            }
            _linearLayout.AddView(_autoCompleteText, lp);
        }
Example #3
0
        void EditItem(string cnno, int id)
        {
            using (var db = new SQLite.SQLiteConnection(pathToDatabase))
            {
                var list = db.Table <CNNoteDtls>().Where(x => x.cnno == cnno && x.ID == id).ToList <CNNoteDtls>();
                if (list.Count > 0)
                {
                    txtqty.Text   = list [0].qty.ToString();
                    txtprice.Text = list [0].price.ToString("n2");
                    int pos1 = 0;
                    if (list [0].description.Length > 40)
                    {
                        pos1 = dAdapterItem.GetPosition(list [0].icode + " | " + list [0].description.Substring(0, 40) + "...");
                    }
                    else
                    {
                        pos1 = dAdapterItem.GetPosition(list [0].icode + " | " + list [0].description);
                    }

                    spinItem.SetSelection(pos1);
                    spinItem.Enabled    = false;
                    butFindItem.Enabled = false;
                    IsEdit          = true;
                    IDdtls          = list [0].ID;
                    txtInvMode.Text = "EDIT";
                    txtqty.RequestFocus();
                    txtqty.SelectAll();
                }
            }
        }
        private async void NextOnClick(object sender, EventArgs eventArgs)
        {
            _progressBar.Indeterminate = true;
            _studentId.Enabled         = false;
            _next.Enabled = false;

            var pref = PreferenceManager.GetDefaultSharedPreferences(this);
            var edit = pref.Edit();

            edit.PutBoolean("submitted", true);
            edit.PutInt("intro", 2);
            edit.PutString("studentId", _studentId.Text);
            edit.Commit();

            var result = await Client.GetStudentInfo(_studentId.Text, _password.Text);

            _progressBar.Indeterminate = false;
            _studentId.Enabled         = true;
            _next.Enabled = true;
            _studentId.SelectAll();

            if (result?.Success ?? false)
            {
                StartActivity(new Intent(Application.Context, typeof(StudentInfo)));
                Finish();
            }
            else
            {
                var dlg = new AlertDialog.Builder(this);
                if (result != null)
                {
                    dlg.SetMessage(result.ErrorMessage);
                    dlg.SetTitle("Request Failed");
                    dlg.SetPositiveButton("Okay", (o, args) =>
                    {
                    });
                }
                else
                {
                    dlg.SetTitle("Request Timeout");
                    dlg.SetMessage("Please make sure you are connected to the network.");
                    dlg.SetPositiveButton("Retry", (o, args) =>
                    {
                        NextOnClick(sender, eventArgs);
                    });

                    dlg.SetCancelable(true);
                    dlg.SetNegativeButton("Cancel", (o, args) =>
                    {
                        edit = pref.Edit();
                        edit.PutBoolean("submitted", false);
                        edit.PutInt("intro", 1);
                        edit.Commit();
                    });
                }


                dlg.Show();
            }
        }
Example #5
0
        public async void setAdapter(string location)
        {
            var locations = await SecondProject.Core.DataService.GetLocation("https://www.metaweather.com/api/location/search/?query=" + location);

            var locationsArr = locations as SecondProject.Core.Location[];

            if (locationsArr.Length == 0)
            {
                Toast.MakeText(Application.Context, "Error, location not found", ToastLength.Long).Show();
                textView.SelectAll();
                return;
            }

            string query = "https://www.metaweather.com/api/location/" + locationsArr[0].Woeid;

            var result = await SecondProject.Core.DataService.GetDataService(query);

            weather = result as SecondProject.Core.WeatherInfo;


            var ListAdapter = new BasicWeatherAdapter(this, weather);

            parentView         = FindViewById <GridView>(Resource.Id.parentView);
            parentView.Adapter = ListAdapter;

            parentView.ItemClick += ParentView_ItemClick;
        }
Example #6
0
//        void EditTextTouchUp(object sender, View.TouchEventArgs e)
//        {
//            //          if (MotionEventActions.Up == e.Event.Action ) {  disallow text edit ?
//            switch (e.Event.Action & MotionEventActions.Mask)
//            {
//                case MotionEventActions.Up:
//                    if (TransDetAdapter.lastFocusedControl != null)
//                        TransDetAdapter.lastFocusedControl.SetBackgroundResource(Resource.Drawable.my_edit_text_background_normal);
//                    TransDetAdapter.lastFocusedControl = (EditText)sender;
//                    TransDetAdapter.lastFocusedControl.SetBackgroundResource(Resource.Drawable.my_edit_text_background_focused);
//                    TransDetAdapter.lastFocusedControl.RequestFocus();
//
//                    EditText yourEditText = (EditText)sender;
//                    Android.Views.InputMethods.InputMethodManager imm = (Android.Views.InputMethods.InputMethodManager)context.GetSystemService(Android.Content.Context.InputMethodService);
//                    imm.ShowSoftInput(yourEditText, Android.Views.InputMethods.ShowFlags.Implicit);
//                    break;
//            }
//        }
        #region IOnTouchListener implementation

        public bool OnTouch(View v, MotionEvent e)
        {
            switch (e.Action & MotionEventActions.Mask)
            {
            case MotionEventActions.Up:
                if (TransDetAdapter.lastFocusedControl != null)
                {
                    TransDetAdapter.lastFocusedControl.SetBackgroundResource(Resource.Drawable.my_edit_text_background_normal);
                }
                TransDetAdapter.lastFocusedControl = (EditText)v;
                TransDetAdapter.lastFocusedControl.SetBackgroundResource(Resource.Drawable.my_edit_text_background_focused);
                TransDetAdapter.lastFocusedControl.RequestFocus();

                EditText yourEditText = (EditText)v;
                Android.Views.InputMethods.InputMethodManager imm = (Android.Views.InputMethods.InputMethodManager)context.GetSystemService(Android.Content.Context.InputMethodService);
                imm.ShowSoftInput(yourEditText, Android.Views.InputMethods.ShowFlags.Forced);
                if (lastFocusedControl != null)
                {
                    lastFocusedControl.PostDelayed(new Action(() => { lastFocusedControl.SelectAll(); }), 100);
                }
                break;
            }

            //_gestureDetector.OnTouchEvent(e);
            return(true);
        }
        private static void FocusOnNumber(EditText addressTextField, EditText numberTextField, Func <Address> currentAddress)
        {
            if (addressTextField.Text == null)
            {
                return;
            }

            var currentAddressValue = currentAddress();
            var streetNumber        = currentAddressValue != null
                ? currentAddressValue.StreetNumber
                : string.Empty;

            int dummy;

            if (!int.TryParse(streetNumber, out dummy))
            {
                return;
            }

            numberTextField.Text = streetNumber;
            numberTextField.SelectAll();

            // remove the street number from the other textfield
            addressTextField.Text = addressTextField.Text.Replace(streetNumber, string.Empty).Trim();
        }
        private void BtnLogin_Click(object sender, System.EventArgs e)
        {
            var res = new ReturnedSaveFuncInfo();

            res.AddReturnedValue(CheckValidation());
            if (res.HasError)
            {
                Toast.MakeText(this, res.ErrorMessage, ToastLength.Short).Show();
                return;
            }

            var user = UserBussines.Get(txtUserName.Text.Trim());

            if (user == null)
            {
                Toast.MakeText(this, $"کاربر با نام کاربری {txtUserName.Text} یافت نشد", ToastLength.Long).Show();
                txtUserName.SelectAll();
                return;
            }

            var ue        = new UTF8Encoding();
            var bytes     = ue.GetBytes(txtPassword.Text.Trim());
            var md5       = new MD5CryptoServiceProvider();
            var hashBytes = md5.ComputeHash(bytes);
            var password  = System.Text.RegularExpressions.Regex.Replace(BitConverter.ToString(hashBytes), "-", "")
                            .ToLower();

            if (password != user.Password)
            {
                Toast.MakeText(this, "رمز عبور اشتباه است", ToastLength.Long).Show();
                txtPassword.SelectAll();
                return;
            }

            if (user.IsBlock)
            {
                Toast.MakeText(this, "دسترسی شما به برنامه، از طریق پنل مدیریت محدود شده است", ToastLength.Long).Show();
                txtPassword.SelectAll();
                return;
            }

            CurrentUser.User       = user;
            CurrentUser.LastVorrod = DateTime.Now;

            StartActivity(typeof(MainActivity));
        }
Example #9
0
 public void SelectAll()
 {
     if (editText == null)
     {
         return;
     }
     editText.SelectAll();
 }
Example #10
0
        private void OnItemClick(object sender, AdapterView.ItemClickEventArgs e)
        {
            ShowButtonConnectState(true);
            currentItemID = (int)e.Id;
            _password.RequestFocus();
            _password.SelectAll();

            ShowVirtualKeyboard();
        }
Example #11
0
        private void OnEnterSelectAll(object sender, View.FocusChangeEventArgs e)
        {
            EditText eb = (EditText)sender;

            if (e.HasFocus)
            {
                eb.SelectAll();
            }
        }
Example #12
0
        public void AddPlayer()
        {
            if (playersInfo.Count < MaxPlayerCount)
            {
                EditText            et = (EditText)LayoutInflater.Inflate(Resource.Layout.edittext_dialog, null, false);
                AlertDialog.Builder ad = new AlertDialog.Builder(this);
                et.Text = GetFreeName();
                ad.SetTitle("Player's name");
                ad.SetView(et);
                var dialog = ad.Create();
                et.KeyPress += (sender, e) =>
                {
                    if (e.Event.Action == KeyEventActions.Down && e.KeyCode == Keycode.Enter)
                    {
                        string name = et.Text;
                        HideKeyboard(et);
                        dialog.Dismiss();

                        ad = new AlertDialog.Builder(this);
                        ad.SetTitle("Player's type");
                        dialog = ad.Create();
                        ad.SetItems(System.Enum.GetValues(typeof(PlayerType)).Cast <PlayerType>().Select(_ => _.ToString()).ToArray(), (sender2, e2) => {
                            playersInfo.Add(new PlayerInfo(et.Text, (PlayerType)e2.Which));
                            ((AlertDialog)sender2).Dismiss();
                            adapter.NotifyDataSetChanged();
                        });
                        ad.Show();
                    }
                    else
                    {
                        e.Handled = false;
                    }
                };
                dialog.Show();
                //dialog.DismissEvent += (a, b) => { HideKeyboard(et); };
                et.SelectAll();
                ShowKeyboard(et);
            }

            void ShowKeyboard(View pView)
            {
                pView.RequestFocus();

                InputMethodManager inputMethodManager = GetSystemService(InputMethodService) as InputMethodManager;

                inputMethodManager.ShowSoftInput(pView, ShowFlags.Forced);
                inputMethodManager.ToggleSoftInput(ShowFlags.Forced, HideSoftInputFlags.ImplicitOnly);
            }

            void HideKeyboard(View pView)
            {
                InputMethodManager inputMethodManager = GetSystemService(InputMethodService) as InputMethodManager;

                inputMethodManager.HideSoftInputFromWindow(pView.WindowToken, HideSoftInputFlags.None);
            }
        }
        public void TriggerEdit()
        {
            CanTrigger    = false;
            PreviousValue = Text;

            EditText.Visibility = Visibility.Visible;
            EditText.FontSize   = FontSize;
            Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.ApplicationIdle, new Action(() => { EditText.Focus(); }));
            EditText.SelectAll();
        }
Example #14
0
 private void JobEdit_FocusChange(object sender, View.FocusChangeEventArgs e)
 {
     if (e.HasFocus)
     {//gain focus
         JobEdit.SelectAll();
     }
     else
     {//lose focus
         ValidateJob();
     }
 }
        private async void OnActivate(object sender, EventArgs e)
        {
            string activationCode = tbConfirmText.TrimInput();

            using (var dlg = this.ShowProgress(null, "Activating account..."))
            {
                var proxy  = ProxyFactory.GetProxyInstace();
                var result = await proxy.ExecuteAsync(API.Endpoints.AccountEndpoints.ActivateAccount(activationCode, activationTicket));

                if (result.Successful)
                {
                    //  Auto login
                    if (autoLogin)
                    {
                        dlg.Dialog.SetMessage("Setting up your account...");

                        var loginResult = await proxy.LoginAsync(userInfo.Username, userPassword);

                        if (result.Successful)
                        {
                            NavigationHelper.NavigateUserHome(this, intent => intent.SetFlags(ActivityFlags.SingleTop | ActivityFlags.ClearTask));
                            Toast.MakeText(this, "Welcome!", ToastLength.Short).Show();

                            //  Set result to ok
                            SetResult(Result.Ok);
                        }
                        else
                        {
                            Toast.MakeText(this, loginResult.Message, ToastLength.Short).Show();
                        }
                    }

                    Finish();
                }
                else
                {
                    string message = string.Empty;
                    if (result.HasStatus(System.Net.HttpStatusCode.Forbidden))
                    {
                        message = Android.Resources.ERR_MSG_INVALID_ACTIVATION_CODE;
                        tbConfirmText.RequestFocus();
                        tbConfirmText.SelectAll();
                    }
                    else
                    {
                        message = result.GetErrorDescription();
                    }

                    //  Toast message
                    Toast.MakeText(this, message, ToastLength.Short).Show();
                }
            }
        }
 protected override Dialog CreateDialog(Context context)
 {
     var setting = Cell as TextSetting;
     var builder = new AlertDialog.Builder(context);
     builder.SetTitle(setting.Title);
     var input = new EditText(context);
     input.Text = setting.Value;
     input.SelectAll();
     builder.SetView(input);
     builder.SetPositiveButton("Ok", new TextApplier(input, setting));
     var dialog = builder.Create();
     dialog.Window.SetSoftInputMode(SoftInput.StateVisible);
     return dialog;
 }
Example #17
0
        void SubmitGuess()
        {
            if (string.IsNullOrWhiteSpace(_textGuess.Text))
            {
                return;
            }

            int val;

            if (int.TryParse(_textGuess.Text.Trim(), out val))
            {
                _channel.Guess(val);
            }

            _textGuess.SelectAll();
        }
Example #18
0
        private void SetListeners()
        {
            answerBtn.SoundEffectsEnabled = false;
            answerBtn.Click += AnswerBtn_Click;

            answerEdit.EditorAction += AnswerEdit_EditorAction;
            answerEdit.Click        += delegate
            {
                answerEdit.Text = "";
                answerEdit.SelectAll();
                if (counter == 1)
                {
                    totalTimeStopWatch.Start();
                }
            };
        }
        public new Dialog Build(Activity activity, PromptConfig config)
        {
            var txt = new EditText(activity)
            {
                Id   = Int32.MaxValue,
                Hint = config.Placeholder
            };

            if (config.Text != null)
            {
                txt.Text         = config.Text;
                txt.FocusChange += (o, e) => { if (e.HasFocus)
                                               {
                                                   txt.SelectAll();
                                               }
                };                                                                 // modify
            }

            if (config.MaxLength != null)
            {
                txt.SetFilters(new[] { new InputFilterLengthFilter(config.MaxLength.Value) });
            }

            SetInputType(txt, config.InputType);

            var builder = new AlertDialog.Builder(activity, config.AndroidStyleId ?? 0)
                          .SetCancelable(false)
                          .SetMessage(config.Message)
                          .SetTitle(config.Title)
                          .SetView(txt)
                          .SetPositiveButton(config.OkText, (s, a) =>
                                             config.OnAction(new PromptResult(true, txt.Text))
                                             );

            if (config.IsCancellable)
            {
                builder.SetNegativeButton(config.CancelText, (s, a) =>
                                          config.OnAction(new PromptResult(false, txt.Text))
                                          );
            }
            var dialog = builder.Create();

            this.HookTextChanged(dialog, txt, config);

            return(dialog);
        }
Example #20
0
        private void initText(string text)
        {
            Matcher matcher = Java.Util.Regex.Pattern.Compile("\\[(.*?)\\]").Matcher(text);
            int counter = 0, start=0, end=0;
            text = text.Replace("[", "");
            text = text.Replace("]", "");
            SpannableString spanString = new SpannableString(text);

            while (matcher.Find())
            {
                string tag = matcher.Group(1);

                start = matcher.Start() - counter;
                counter++;
                counter++;
                end = matcher.End() - counter;

                spanString.SetSpan(new ForegroundColorSpan(Color.ParseColor("#0000FF")),
                    start,
                    end,
                    0);

                MyClickableSpan clickableSpan = new MyClickableSpan();
                clickableSpan.Click += v =>
                {
                    Log.WriteLine(LogPriority.Debug, "click", "click: " + tag);
                    if (tag.Equals(_event)) _curEd = CurrentEdit.Event;
                    else _curEd = CurrentEdit.Test;

                    _editor.Text = tag;
                    _editor.Visibility = ViewStates.Visible;
                    _editor.SelectAll();
                    InputMethodManager mgr = (InputMethodManager)GetSystemService(InputMethodService);
                    mgr.ShowSoftInput(_editor, ShowFlags.Implicit);
                    _editor.Visibility = ViewStates.Visible;
                };
                spanString.SetSpan(clickableSpan, start, end, SpanTypes.ExclusiveExclusive);

            };

            _assumeTextView.TextFormatted = spanString;
            _assumeTextView.MovementMethod = new LinkMovementMethod();
        }
Example #21
0
        private void DisplayText_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            EscapeName             = EditText.Text;
            DisplayText.Visibility = Visibility.Collapsed;
            EditText.Visibility    = Visibility.Visible;
            EditText.SelectAll();

            /*https://stackoverflow.com/questions/13955340/keyboard-focus-does-not-work-on-text-box-in-wpf
             * WPF can have multiple Focus Scopes,
             * so multiple elements can have Logical Focus (IsFocused = true),
             * however only one element can have Keyboard Focus
             * */
            Dispatcher.BeginInvoke(DispatcherPriority.Input,
                                   new Action(delegate()
            {
                EditText.Focus();            // Set Logical Focus
                Keyboard.Focus(EditText);    // Set Keyboard Focus
            }));
        }
Example #22
0
        /*----------------------------------------------------------------------------
        *       %%Function: SetFocus
        *       %%Qualified: DroidUpc.MainActivity.SetFocus
        *
        *   set focus to the given editbox
        *  ----------------------------------------------------------------------------*/
        void SetFocus(EditText eb, bool fWantKeyboard)
        {
            RunOnUiThread(
                () =>
            {
                eb.RequestFocus();
                eb.SelectAll();

                InputMethodManager imm =
                    (InputMethodManager)GetSystemService(global::Android.Content.Context.InputMethodService);

                if (fWantKeyboard)
                {
                    imm.ShowSoftInput(eb, ShowFlags.Implicit);
                }
                else
                {
                    imm.HideSoftInputFromWindow(eb.WindowToken, 0);
                }
            });
        }
Example #23
0
        public override Dialog OnCreateDialog(Android.OS.Bundle savedInstanceState)
        {
            contextWeak.TryGetTarget(out Context context);

            var alertBuilder = new Android.Support.V7.App.AlertDialog.Builder(context);

            alertBuilder.SetTitle(title);

            if (message != null)
            {
                alertBuilder.SetMessage(message);
            }

            textInput = new EditText(context);
            textInput.AddTextChangedListener(this);
            alertBuilder.SetView(textInput);

            if (hint != null)
            {
                textInput.Text = hint;
                textInput.SelectAll();
            }

            alertBuilder.SetCancelable(false);

            alertBuilder.SetNegativeButton(cancelButton ?? "Cancel", delegate
            {
                Tcs.TrySetResult(null);
            });

            alertBuilder.SetPositiveButton(actionButton ?? "Ok", (EventHandler <DialogClickEventArgs>)null);

            var alert = alertBuilder.Create();

            alert.SetOnShowListener(this);

            return(alert);
        }
Example #24
0
        public override void OnCreateOptionsMenu(IMenu menu, MenuInflater inflater)
        {
            base.OnCreateOptionsMenu(menu, inflater);
            inflater.Inflate(Resource.Menu.fragment_photo_gallery, menu);
            // Using SearchView
            if (Build.VERSION.SdkInt >= BuildVersionCodes.Honeycomb)
            {
                IMenuItem  searchItem = menu.FindItem(Resource.Id.menu_item_search);
                SearchView searchView = (SearchView)searchItem.ActionView;

                // Get the data from our searchable.xml as a SearchableInfo
                SearchManager  searchManager = (SearchManager)Activity.GetSystemService(Context.SearchService);
                ComponentName  name          = Activity.ComponentName;
                SearchableInfo searchInfo    = searchManager.GetSearchableInfo(name);
                searchView.SetSearchableInfo(searchInfo);
                searchView.SubmitButtonEnabled = true;

                searchView.QueryTextFocusChange += (object sender, View.FocusChangeEventArgs e) => {
                    if (e.HasFocus && lastQuery != null && lastQuery != String.Empty)
                    {
                        searchView.SetQuery(lastQuery, false);
                        currentPage = 1;
                        int      id       = searchView.Context.Resources.GetIdentifier("android:id/search_src_text", null, null);
                        EditText editText = searchView.FindViewById <EditText>(id);
                        editText.SelectAll();
                    }
                };
                searchView.Close += async(object sender, SearchView.CloseEventArgs e) => {
                    e.Handled = false;
                    PreferenceManager.GetDefaultSharedPreferences(Activity).Edit().PutString(FlickrFetchr.PREF_SEARCH_QUERY, null).Commit();
                    query       = null;
                    currentPage = 1;
                    await UpdateItems();
                };
            }
        }
Example #25
0
        public virtual Task <string> Input(string title, string defaultText, string yes, bool password, CancellationToken cancellation)
        {
            var context = _contextFactory();

            if (context == null)
            {
                return(Task.FromResult(""));
            }

            var syncContext = SynchronizationContext.Current;
            var tcs         = new TaskCompletionSource <string>();
            var input       = new EditText(context)
            {
                Text = defaultText
            };

            input.SetSingleLine();

            if (password)
            {
                input.SetFilters(new[] { new InputFilterLengthFilter(20) });
                input.InputType            = InputTypes.ClassText | InputTypes.TextVariationPassword;
                input.TransformationMethod = PasswordTransformationMethod.Instance;
            }
            else
            {
                input.SetFilters(new[] { new InputFilterLengthFilter(140) });
            }

            var dialog = new AlertDialog.Builder(context)
                         .SetTitle(title)
                         .SetView(input)
                         .SetPositiveButton(yes, new ClickListener((e, i) =>
            {
                e.Dismiss();
                tcs.TrySetResult(input.Text);
            }))
                         .SetOnCancelListener(new ClickListener((e, i) =>
            {
                e.Dismiss();
                tcs.TrySetResult(null);
            }))
                         .Create();

            input.EditorAction += (sender, e) =>
            {
                if (e.Event == null || e.Event.KeyCode == Keycode.Enter)
                {
                    var text = input.Text;
                    dialog.Dismiss();
                    tcs.TrySetResult(text);
                }
            };

            input.FocusChange += (sender, e) =>
            {
                if (e.HasFocus)
                {
                    input.SelectAll();
                    dialog.Window.SetSoftInputMode(SoftInput.StateAlwaysVisible);
                }
            };

            dialog.Show();
            cancellation.Register(() =>
            {
                syncContext.Post(_ => dialog.Dismiss(), null);
                tcs.TrySetResult(null);
            });
            return(tcs.Task);
        }
Example #26
0
 private void ShowKeyboard(EditText userInput, AlertDialog dialog)
 {
     userInput.RequestFocus();
     userInput.SelectAll();
     dialog.Window.SetSoftInputMode(SoftInput.StateAlwaysVisible);
 }
        private void BookmarkButton_Click(object sender, EventArgs e)
        {
            int  lineNum      = mContext.lines.IndexOf(line);
            long bookmarkPos  = mContext.GetPosition(mContext.lines, lineNum + 1, wordIndex, true);
            int  bookmarksPos = Bookmark.SearchClosest(bookmarkPos, mContext.mBookmarks);

            if (mContext.mBookmarks.Count > bookmarksPos && mContext.mBookmarks[bookmarksPos].mPosition == bookmarkPos)
            {
                mContext.mBookmarks.RemoveAt(bookmarksPos);
                if (!Bookmark.SaveToFile(mContext.mBookmarks, mContext.curFilePath + ".bookmarks"))
                {
                    Toast.MakeText(mContext, "Bookmarks could not be stored. File location is not writable.", ToastLength.Long).Show();
                }

                int foundBookmarksPos = Bookmark.SearchClosest(bookmarkPos, mContext.mFoundBookmarks);
                if (mContext.mFoundBookmarks.Count > foundBookmarksPos && mContext.mFoundBookmarks[foundBookmarksPos].mPosition == bookmarkPos)
                {
                    mContext.mFoundBookmarks.RemoveAt(foundBookmarksPos);
                }

                mContext.linesAdapter.NotifyItemChanged(lineNum + 1);
                show(mContext.linesLayoutManager.FindViewByPosition(lineNum + 1), line, wordIndex, showX, false);
            }
            else
            {
                AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
                builder.SetTitle("New bookmark");
                EditText inputBookmark = new EditText(mContext);
                inputBookmark.InputType = InputTypes.TextFlagCapSentences;
                inputBookmark.Text      = Dict.PinyinToTones(Dict.GetPinyin(entry));
                inputBookmark.SelectAll();
                builder.SetView(inputBookmark);
                builder.SetCancelable(true);
                builder.SetPositiveButton("OK", delegate
                {
                    try
                    {
                        int lineNum1           = mContext.lines.IndexOf(line);
                        long bookmarkPos1      = mContext.GetPosition(mContext.lines, lineNum1 + 1, wordIndex, true);
                        int bookmarksPos1      = Bookmark.SearchClosest(bookmarkPos1, mContext.mBookmarks);
                        int foundBookmarksPos1 = Bookmark.SearchClosest(bookmarkPos1, mContext.mFoundBookmarks);

                        Bookmark newBookmark = new Bookmark(bookmarkPos1, inputBookmark.Text.ToString());
                        newBookmark.SetAnnotatedPosition(lineNum1, wordIndex);
                        mContext.mFoundBookmarks.Insert(foundBookmarksPos1, newBookmark);
                        mContext.mBookmarks.Insert(bookmarksPos1, newBookmark);

                        if (!Bookmark.SaveToFile(mContext.mBookmarks, mContext.curFilePath + ".bookmarks"))
                        {
                            Toast.MakeText(mContext, "Bookmarks could not be stored. File location is not writable.", ToastLength.Long).Show();
                        }

                        mContext.linesAdapter.NotifyItemChanged(lineNum1 + 1);
                        show(mContext.linesLayoutManager.FindViewByPosition(lineNum1 + 1), line, wordIndex, showX, false);
                    }
                    catch (FormatException)
                    {
                        Toast.MakeText(mContext, "", ToastLength.Long).Show();
                    }
                });
                builder.SetNegativeButton("Cancel", delegate
                {
                });
                AlertDialog dialog = builder.Create();
                dialog.Window.SetSoftInputMode(SoftInput.StateVisible);

                dialog.Show();
            }
        }