protected override void OnCreate(Bundle savedInstanceState)
        {
            _design.ApplyTheme();
            base.OnCreate(savedInstanceState);

            Android.Util.Log.Debug("KP2A", "Creating GBA");

            AppTask = AppTask.GetTaskInOnCreate(savedInstanceState, Intent);

            // Likely the app has been killed exit the activity
            if (!App.Kp2a.GetDb().Loaded)
            {
                Finish();
                return;
            }

            _prefs = PreferenceManager.GetDefaultSharedPreferences(this);


            SetContentView(ContentResourceId);

            if (FindViewById(Resource.Id.fabCancelAddNew) != null)
            {
                FindViewById(Resource.Id.fabAddNew).Click += (sender, args) =>
                {
                    FindViewById(Resource.Id.fabCancelAddNew).Visibility = ViewStates.Visible;
                    FindViewById(Resource.Id.fabAddNewGroup).Visibility  = AddGroupEnabled ? ViewStates.Visible : ViewStates.Gone;
                    FindViewById(Resource.Id.fabAddNewEntry).Visibility  = AddEntryEnabled ? ViewStates.Visible : ViewStates.Gone;
                    FindViewById(Resource.Id.fabAddNew).Visibility       = ViewStates.Gone;
                };

                FindViewById(Resource.Id.fabCancelAddNew).Click += (sender, args) =>
                {
                    FindViewById(Resource.Id.fabCancelAddNew).Visibility = ViewStates.Gone;
                    FindViewById(Resource.Id.fabAddNewGroup).Visibility  = ViewStates.Gone;
                    FindViewById(Resource.Id.fabAddNewEntry).Visibility  = ViewStates.Gone;
                    FindViewById(Resource.Id.fabAddNew).Visibility       = ViewStates.Visible;
                };
            }


            if (FindViewById(Resource.Id.cancel_insert_element) != null)
            {
                FindViewById(Resource.Id.cancel_insert_element).Click += (sender, args) => StopMovingElements();
                FindViewById(Resource.Id.insert_element).Click        += (sender, args) => InsertElements();
                Util.MoveBottomBarButtons(Resource.Id.cancel_insert_element, Resource.Id.insert_element, Resource.Id.bottom_bar, this);
            }


            SetResult(KeePass.ExitNormal);
        }
Exemple #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            _design.ApplyTheme();
            base.OnCreate(savedInstanceState);

            //see comment to this in PasswordActivity.
            //Note that this activity is affected even though it's finished when the app is closed because it
            //seems that the "app launch intent" is re-delivered, so this might end up here.
            if ((_appTask == null) && (Intent.Flags.HasFlag(ActivityFlags.LaunchedFromHistory)))
            {
                _appTask = new NullTask();
            }
            else
            {
                _appTask = AppTask.GetTaskInOnCreate(savedInstanceState, Intent);
            }


            Kp2aLog.Log("KeePass.OnCreate");
        }
Exemple #3
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            _appTask = AppTask.GetTaskInOnCreate(bundle, Intent);
            SetContentView(Resource.Layout.search);
            SearchParameters sp = new SearchParameters();

            PopulateCheckBox(Resource.Id.cbSearchInTitle, sp.SearchInTitles);
            PopulateCheckBox(Resource.Id.cbSearchInUsername, sp.SearchInUserNames);
            PopulateCheckBox(Resource.Id.cbSearchInNotes, sp.SearchInNotes);
            PopulateCheckBox(Resource.Id.cbSearchInPassword, sp.SearchInPasswords);
            PopulateCheckBox(Resource.Id.cbSearchInTags, sp.SearchInTags);
            PopulateCheckBox(Resource.Id.cbSearchInGroupName, sp.SearchInGroupNames);
            PopulateCheckBox(Resource.Id.cbSearchInUrl, sp.SearchInUrls);
            PopulateCheckBox(Resource.Id.cbSearchInOtherStrings, sp.SearchInOther);
            PopulateCheckBox(Resource.Id.cbRegEx, sp.RegularExpression);

            StringComparison sc            = sp.ComparisonMode;
            bool             caseSensitive = ((sc != StringComparison.CurrentCultureIgnoreCase) &&
                                              (sc != StringComparison.InvariantCultureIgnoreCase) &&
                                              (sc != StringComparison.OrdinalIgnoreCase));

            PopulateCheckBox(Resource.Id.cbCaseSensitive, caseSensitive);
            PopulateCheckBox(Resource.Id.cbExcludeExpiredEntries, sp.ExcludeExpired);

            ImageButton btnSearch = (ImageButton)FindViewById(Resource.Id.search_button);

            btnSearch.Click += (sender, e) => PerformSearch();

            FindViewById <EditText>(Resource.Id.searchEditText).EditorAction += (sender, e) =>
            {
                if (e.ActionId == Android.Views.InputMethods.ImeAction.Search)
                {
                    PerformSearch();
                }
            };
        }
        protected override void OnCreate(Bundle bundle)
        {
            _design.ApplyTheme();
            base.OnCreate(bundle);


            SupportActionBar.SetDisplayHomeAsUpEnabled(true);
            SupportActionBar.SetHomeButtonEnabled(true);

            SetContentView(Resource.Layout.create_database);
            _appTask = AppTask.GetTaskInOnCreate(bundle, Intent);

            SetDefaultIoc();

            FindViewById(Resource.Id.keyfile_filename).Visibility = ViewStates.Gone;


            var keyfileCheckbox = FindViewById <CheckBox>(Resource.Id.use_keyfile);

            if (bundle != null)
            {
                _keyfileFilename = bundle.GetString(KeyfilefilenameBundleKey, null);
                if (_keyfileFilename != null)
                {
                    FindViewById <TextView>(Resource.Id.keyfile_filename).Text = FileSelectHelper.ConvertFilenameToIocPath(_keyfileFilename);
                    FindViewById(Resource.Id.keyfile_filename).Visibility      = ViewStates.Visible;
                    keyfileCheckbox.Checked = true;
                }

                if (bundle.GetString(Util.KeyFilename, null) != null)
                {
                    _ioc = new IOConnectionInfo
                    {
                        Path         = bundle.GetString(Util.KeyFilename),
                        UserName     = bundle.GetString(Util.KeyServerusername),
                        Password     = bundle.GetString(Util.KeyServerpassword),
                        CredSaveMode = (IOCredSaveMode)bundle.GetInt(Util.KeyServercredmode),
                    };
                }
            }

            UpdateIocView();

            keyfileCheckbox.CheckedChange += (sender, args) =>
            {
                if (keyfileCheckbox.Checked)
                {
                    if (_restoringInstanceState)
                    {
                        return;
                    }

                    Util.ShowBrowseDialog(this, RequestCodeKeyFile, false, true);
                }
                else
                {
                    FindViewById(Resource.Id.keyfile_filename).Visibility = ViewStates.Gone;
                    _keyfileFilename = null;
                }
            };


            FindViewById(Resource.Id.btn_change_location).Click += (sender, args) =>
            {
                Intent intent = new Intent(this, typeof(FileStorageSelectionActivity));
                StartActivityForResult(intent, RequestCodeDbFilename);
            };

            Button generatePassword = (Button)FindViewById(Resource.Id.generate_button);

            generatePassword.Click += (sender, e) =>
            {
                GeneratePasswordActivity.LaunchWithoutLockCheck(this);
            };

            FindViewById(Resource.Id.btn_create).Click += (sender, evt) =>
            {
                CreateDatabase(Intent.GetBooleanExtra("MakeCurrent", true));
            };

            ImageButton btnTogglePassword = (ImageButton)FindViewById(Resource.Id.toggle_password);

            btnTogglePassword.Click += (sender, e) =>
            {
                _showPassword = !_showPassword;
                MakePasswordMaskedOrVisible();
            };
            Android.Graphics.PorterDuff.Mode mMode = Android.Graphics.PorterDuff.Mode.SrcAtop;
            Android.Graphics.Color           color = new Android.Graphics.Color(224, 224, 224);
            btnTogglePassword.SetColorFilter(color, mMode);
        }
Exemple #5
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            if (LastNonConfigurationInstance != null)
            {
                //bug in Mono for Android or whatever: after config change the extra fields are wrong
                // -> reload:
                Reload();
                return;
            }

            _appTask = AppTask.GetTaskInOnCreate(savedInstanceState, Intent);

            SetContentView(Resource.Layout.entry_edit);
            _closeForReload = false;

            // Likely the app has been killed exit the activity
            if (!App.Kp2a.DatabaseIsUnlocked)
            {
                Finish();
                return;
            }


            if (Intent.GetBooleanExtra(IntentContinueWithEditing, false))
            {
                //property "State" will return the state
            }
            else
            {
                Database db = App.Kp2a.GetDb();

                App.Kp2a.EntryEditActivityState = new EntryEditActivityState();
                ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this);
                State.ShowPassword = !prefs.GetBoolean(GetString(Resource.String.maskpass_key), Resources.GetBoolean(Resource.Boolean.maskpass_default));

                Intent i         = Intent;
                String uuidBytes = i.GetStringExtra(KeyEntry);

                PwUuid entryId = PwUuid.Zero;
                if (uuidBytes != null)
                {
                    entryId = new PwUuid(MemUtil.HexStringToByteArray(uuidBytes));
                }

                State.ParentGroup = null;
                if (entryId.Equals(PwUuid.Zero))
                {
                    //creating new entry
                    String groupId = i.GetStringExtra(KeyParent);
                    State.ParentGroup = db.KpDatabase.RootGroup.FindGroup(new PwUuid(MemUtil.HexStringToByteArray(groupId)), true);

                    PwUuid  templateId    = new PwUuid(MemUtil.HexStringToByteArray(i.GetStringExtra(KeyTemplateUuid)));
                    PwEntry templateEntry = null;
                    if (!PwUuid.Zero.Equals(templateId))
                    {
                        templateEntry = db.Entries[templateId];
                    }

                    if (KpEntryTemplatedEdit.IsTemplate(templateEntry))
                    {
                        CreateNewFromKpEntryTemplate(db, templateEntry);
                    }
                    else if (templateEntry != null)
                    {
                        CreateNewFromStandardTemplate(templateEntry);
                    }
                    else
                    {
                        CreateNewWithoutTemplate(db);
                    }

                    _appTask.PrepareNewEntry(State.EntryInDatabase);
                    State.IsNew         = true;
                    State.EntryModified = true;
                }
                else
                {
                    Debug.Assert(entryId != null);

                    State.EntryInDatabase = db.Entries [entryId];
                    State.IsNew           = false;
                }

                State.Entry = State.EntryInDatabase.CloneDeep();
                if (KpEntryTemplatedEdit.IsTemplated(db, State.Entry))
                {
                    State.EditMode = new KpEntryTemplatedEdit(db, State.Entry);
                }
                else
                {
                    State.EditMode = new DefaultEdit();
                }
            }

            if (!State.EntryModified)
            {
                SetResult(KeePass.ExitNormal);
            }
            else
            {
                SetResult(KeePass.ExitRefreshTitle);
            }



            FillData();
            View scrollView = FindViewById(Resource.Id.entry_scroll);

            scrollView.ScrollBarStyle = ScrollbarStyles.InsideInset;

            ImageButton iconButton = (ImageButton)FindViewById(Resource.Id.icon_button);

            if (State.SelectedIcon)
            {
                App.Kp2a.GetDb().DrawableFactory.AssignDrawableTo(iconButton, this, App.Kp2a.GetDb().KpDatabase, (PwIcon)State.SelectedIconId, State.SelectedCustomIconId, false);
            }
            iconButton.Click += (sender, evt) => {
                UpdateEntryFromUi(State.Entry);
                IconPickerActivity.Launch(this);
            };


            // Generate password button
            FindViewById(Resource.Id.generate_button).Click += (sender, e) =>
            {
                UpdateEntryFromUi(State.Entry);
                GeneratePasswordActivity.Launch(this);
            };



            // Save button
            //SupportActionBar.SetCustomView(Resource.Layout.SaveButton);

            if (State.IsNew)
            {
                SupportActionBar.Title = GetString(Resource.String.add_entry);
            }
            else
            {
                SupportActionBar.Title = GetString(Resource.String.edit_entry);
            }

            SupportActionBar.SetDisplayHomeAsUpEnabled(true);
            SupportActionBar.SetHomeButtonEnabled(true);

            // Respect mask password setting
            MakePasswordVisibleOrHidden();

            ImageButton btnTogglePassword = (ImageButton)FindViewById(Resource.Id.toggle_password);

            btnTogglePassword.Click += (sender, e) =>
            {
                State.ShowPassword = !State.ShowPassword;
                MakePasswordVisibleOrHidden();
            };
            PorterDuff.Mode mMode = PorterDuff.Mode.SrcAtop;
            Color           color = new Color(189, 189, 189);

            btnTogglePassword.SetColorFilter(color, mMode);


            Button addButton = (Button)FindViewById(Resource.Id.add_advanced);

            addButton.Visibility = ViewStates.Visible;
            addButton.Click     += (sender, e) =>
            {
                LinearLayout container = (LinearLayout)FindViewById(Resource.Id.advanced_container);

                KeyValuePair <string, ProtectedString> pair = new KeyValuePair <string, ProtectedString>("", new ProtectedString(true, ""));
                View ees = CreateExtraStringView(pair);
                container.AddView(ees);

                State.EntryModified = true;

                /*TextView keyView = (TextView) ees.FindViewById(Resource.Id.title);
                 * keyView.RequestFocus();*/
                EditAdvancedString(ees.FindViewById(Resource.Id.edit_extra));
            };
            SetAddExtraStringEnabled();

            ((CheckBox)FindViewById(Resource.Id.entry_expires_checkbox)).CheckedChange += (sender, e) =>
            {
                State.Entry.Expires = e.IsChecked;
                if (e.IsChecked)
                {
                    if (State.Entry.ExpiryTime < DateTime.Now)
                    {
                        State.Entry.ExpiryTime = DateTime.Now;
                    }
                }
                UpdateExpires();
                State.EntryModified = true;
            };
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this);

            long usageCount = prefs.GetLong(GetString(Resource.String.UsageCount_key), 0);

            ISharedPreferencesEditor edit = prefs.Edit();

            edit.PutLong(GetString(Resource.String.UsageCount_key), usageCount + 1);
            edit.Commit();

            _showPassword =
                !prefs.GetBoolean(GetString(Resource.String.maskpass_key), Resources.GetBoolean(Resource.Boolean.maskpass_default));

            RequestWindowFeature(WindowFeatures.IndeterminateProgress);

            _activityDesign.ApplyTheme();
            base.OnCreate(savedInstanceState);



            SetEntryView();

            Database db = App.Kp2a.GetDb();

            // Likely the app has been killed exit the activity
            if (!db.Loaded || (App.Kp2a.QuickLocked))
            {
                Finish();
                return;
            }

            SetResult(KeePass.ExitNormal);

            Intent i    = Intent;
            PwUuid uuid = new PwUuid(MemUtil.HexStringToByteArray(i.GetStringExtra(KeyEntry)));

            _pos = i.GetIntExtra(KeyRefreshPos, -1);

            _appTask = AppTask.GetTaskInOnCreate(savedInstanceState, Intent);

            Entry = db.Entries[uuid];

            // Refresh Menu contents in case onCreateMenuOptions was called before Entry was set
            ActivityCompat.InvalidateOptionsMenu(this);

            // Update last access time.
            Entry.Touch(false);

            if (PwDefs.IsTanEntry(Entry) && prefs.GetBoolean(GetString(Resource.String.TanExpiresOnUse_key), Resources.GetBoolean(Resource.Boolean.TanExpiresOnUse_default)) && ((Entry.Expires == false) || Entry.ExpiryTime > DateTime.Now))
            {
                PwEntry backupEntry = Entry.CloneDeep();
                Entry.ExpiryTime = DateTime.Now;
                Entry.Expires    = true;
                Entry.Touch(true);
                RequiresRefresh();
                UpdateEntry  update = new UpdateEntry(this, App.Kp2a, backupEntry, Entry, null);
                ProgressTask pt     = new ProgressTask(App.Kp2a, this, update);
                pt.Run();
            }
            FillData();

            SetupEditButtons();

            App.Kp2a.GetDb().LastOpenedEntry = new PwEntryOutput(Entry, App.Kp2a.GetDb().KpDatabase);

            _pluginActionReceiver = new PluginActionReceiver(this);
            RegisterReceiver(_pluginActionReceiver, new IntentFilter(Strings.ActionAddEntryAction));
            _pluginFieldReceiver = new PluginFieldReceiver(this);
            RegisterReceiver(_pluginFieldReceiver, new IntentFilter(Strings.ActionSetEntryField));

            new Thread(NotifyPluginsOnOpen).Start();

            //the rest of the things to do depends on the current app task:
            _appTask.CompleteOnCreateEntryActivity(this);
        }
Exemple #7
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.open_db_selection);

            var toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.mytoolbar);

            SetSupportActionBar(toolbar);

            SupportActionBar.Title = GetString(Resource.String.select_database);


            //only load the AppTask if this is the "first" OnCreate (not because of kill/resume, i.e. savedInstanceState==null)
            // and if the activity is not launched from history (i.e. recent tasks) because this would mean that
            // the Activity was closed already (user cancelling the task or task complete) but is restarted due recent tasks.
            // Don't re-start the task (especially bad if tak was complete already)
            if (Intent.Flags.HasFlag(ActivityFlags.LaunchedFromHistory))
            {
                AppTask = new NullTask();
            }
            else
            {
                AppTask = AppTask.GetTaskInOnCreate(savedInstanceState, Intent);
            }

            _adapter = new OpenDatabaseAdapter(this);
            var gridView = FindViewById <GridView>(Resource.Id.gridview);

            gridView.Adapter = _adapter;

            if (!string.IsNullOrEmpty(Intent.GetStringExtra(Util.KeyFilename)))
            {
                //forward to password activity
                Intent           i   = new Intent(this, typeof(PasswordActivity));
                IOConnectionInfo ioc = new IOConnectionInfo();
                Util.SetIoConnectionFromIntent(ioc, Intent);
                Util.PutIoConnectionToIntent(ioc, i);
                i.PutExtra(PasswordActivity.KeyKeyfile, i.GetStringExtra(PasswordActivity.KeyKeyfile));
                i.PutExtra(PasswordActivity.KeyPassword, i.GetStringExtra(PasswordActivity.KeyPassword));
                LaunchingOther = true;
                StartActivityForResult(i, ReqCodeOpenNewDb);
            }
            else
            {
                if (Intent.Action == Intent.ActionView)
                {
                    GetIocFromViewIntent(Intent);
                }
                else if (Intent.Action == Intent.ActionSend)
                {
                    AppTask = new SearchUrlTask {
                        UrlToSearchFor = Intent.GetStringExtra(Intent.ExtraText)
                    };
                }
            }

            _intentReceiver = new MyBroadcastReceiver(this);
            IntentFilter filter = new IntentFilter();

            filter.AddAction(Intents.DatabaseLocked);
            RegisterReceiver(_intentReceiver, filter);
        }
Exemple #8
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            _design.ApplyTheme();
            base.OnCreate(savedInstanceState);


            Kp2aLog.Log("FileSelect.OnCreate");
            Kp2aLog.Log("FileSelect:apptask=" + Intent.GetStringExtra("KP2A_APPTASK"));

            if (Intent.Action == Intent.ActionSend)
            {
                AppTask = new SearchUrlTask {
                    UrlToSearchFor = Intent.GetStringExtra(Intent.ExtraText)
                };
            }
            else
            {
                //see PasswordActivity for an explanation
                if (Intent.Flags.HasFlag(ActivityFlags.LaunchedFromHistory))
                {
                    AppTask = new NullTask();
                }
                else
                {
                    AppTask = AppTask.GetTaskInOnCreate(savedInstanceState, Intent);
                }
            }


            _dbHelper = App.Kp2a.FileDbHelper;
            SetContentView(Resource.Layout.file_selection);


            if (ShowRecentFiles())
            {
                _recentMode = true;


                FindViewById(Resource.Id.recent_files).Visibility = ViewStates.Visible;
                Android.Util.Log.Debug("KP2A", "Recent files visible");
            }
            else
            {
                FindViewById(Resource.Id.recent_files).Visibility = ViewStates.Invisible;
                Android.Util.Log.Debug("KP2A", "Recent files invisible");
#if NoNet
                ImageView imgView = FindViewById(Resource.Id.splashlogo) as ImageView;
                if (imgView != null)
                {
                    imgView.SetImageDrawable(Resources.GetDrawable(Resource.Drawable.splashlogo_offline));
                }
#endif
            }

            Button openFileButton = (Button)FindViewById(Resource.Id.start_open_file);

            EventHandler openFileButtonClick = (sender, e) =>
            {
                Intent intent = new Intent(this, typeof(SelectStorageLocationActivity));
                intent.PutExtra(FileStorageSelectionActivity.AllowThirdPartyAppGet, true);
                intent.PutExtra(FileStorageSelectionActivity.AllowThirdPartyAppSend, false);
                intent.PutExtra(SelectStorageLocationActivity.ExtraKeyWritableRequirements, (int)SelectStorageLocationActivity.WritableRequirements.WriteDesired);
                intent.PutExtra(FileStorageSetupDefs.ExtraIsForSave, false);
                StartActivityForResult(intent, RequestCodeSelectIoc);
            };
            openFileButton.Click += openFileButtonClick;

            //CREATE NEW
            Button       createNewButton      = (Button)FindViewById(Resource.Id.start_create);
            EventHandler createNewButtonClick = (sender, e) =>
            {
                //ShowFilenameDialog(false, true, true, Android.OS.Environment.ExternalStorageDirectory + GetString(Resource.String.default_file_path), "", Intents.RequestCodeFileBrowseForCreate)
                Intent i = new Intent(this, typeof(CreateDatabaseActivity));
                this.AppTask.ToIntent(i);
                StartActivityForResult(i, 0);
            };
            createNewButton.Click += createNewButtonClick;

            /*//CREATE + IMPORT
             *          Button createImportButton = (Button)FindViewById(Resource.Id.start_create_import);
             *          createImportButton.Click += (object sender, EventArgs e) =>
             *          {
             *                  openButton.Visibility = ViewStates.Gone;
             *                  createButton.Visibility = ViewStates.Visible;
             *                  enterFilenameDetails.Text = GetString(Resource.String.enter_filename_details_create_import);
             *                  enterFilenameDetails.Visibility = enterFilenameDetails.Text == "" ? ViewStates.Gone : ViewStates.Visible;
             *                  // Set the initial value of the filename
             *                  EditText filename = (EditText)FindViewById(Resource.Id.file_filename);
             *                  filename.Text = Android.OS.Environment.ExternalStorageDirectory + GetString(Resource.String.default_file_path);
             *
             *          };*/

            FindViewById <Switch>(Resource.Id.local_backups_switch).CheckedChange += (sender, args) => { FillData(); };

            FillData();

            if (savedInstanceState != null)
            {
                AppTask     = AppTask.CreateFromBundle(savedInstanceState);
                _recentMode = savedInstanceState.GetBoolean(BundleKeyRecentMode, _recentMode);
            }
        }
Exemple #9
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            _design.ApplyTheme();
            base.OnCreate(savedInstanceState);

            Android.Util.Log.Debug("KP2A", "Creating GBA");

            AppTask = AppTask.GetTaskInOnCreate(savedInstanceState, Intent);

            // Likely the app has been killed exit the activity
            if (!App.Kp2a.GetDb().Loaded)
            {
                Finish();
                return;
            }

            _prefs = PreferenceManager.GetDefaultSharedPreferences(this);


            SetContentView(ContentResourceId);

            if (FindViewById(Resource.Id.enable_autofill) != null)
            {
                FindViewById(Resource.Id.enable_autofill).Click += (sender, args) =>
                {
                    var intent = new Intent(Settings.ActionRequestSetAutofillService);
                    intent.SetData(Android.Net.Uri.Parse("package:" + PackageName));
                    try
                    {
                        StartActivity(intent);
                    }
                    catch (ActivityNotFoundException e)
                    {
                        //this exception was reported by many Huawei users
                        Kp2aLog.LogUnexpectedError(e);
                        new AlertDialog.Builder(this)
                        .SetTitle(Resource.String.autofill_enable)
                        .SetMessage(Resource.String.autofill_enable_failed)
                        .SetPositiveButton(Resource.String.ok, (o, eventArgs) => { })
                        .Show();
                        const string autofillservicewasenabled = "AutofillServiceWasEnabled";
                        _prefs.Edit().PutBoolean(autofillservicewasenabled, true).Commit();
                        UpdateBottomBarElementVisibility(Resource.Id.autofill_infotext, false);
                    }
                };
            }


            if (FindViewById(Resource.Id.info_dont_show_autofill_again) != null)
            {
                FindViewById(Resource.Id.info_dont_show_autofill_again).Click += (sender, args) =>
                {
                    _prefs.Edit().PutBoolean(autofillservicewasenabled_prefskey, true).Commit();
                    UpdateAutofillInfo();
                };
            }

            if (FindViewById(Resource.Id.fabCancelAddNew) != null)
            {
                FindViewById(Resource.Id.fabAddNew).Click += (sender, args) =>
                {
                    FindViewById(Resource.Id.fabCancelAddNew).Visibility = ViewStates.Visible;
                    FindViewById(Resource.Id.fabAddNewGroup).Visibility  = AddGroupEnabled ? ViewStates.Visible : ViewStates.Gone;
                    FindViewById(Resource.Id.fabAddNewEntry).Visibility  = AddEntryEnabled ? ViewStates.Visible : ViewStates.Gone;
                    FindViewById(Resource.Id.fabAddNew).Visibility       = ViewStates.Gone;
                };

                FindViewById(Resource.Id.fabCancelAddNew).Click += (sender, args) =>
                {
                    FindViewById(Resource.Id.fabCancelAddNew).Visibility = ViewStates.Gone;
                    FindViewById(Resource.Id.fabAddNewGroup).Visibility  = ViewStates.Gone;
                    FindViewById(Resource.Id.fabAddNewEntry).Visibility  = ViewStates.Gone;
                    FindViewById(Resource.Id.fabAddNew).Visibility       = ViewStates.Visible;
                };
            }


            if (FindViewById(Resource.Id.cancel_insert_element) != null)
            {
                FindViewById(Resource.Id.cancel_insert_element).Click += (sender, args) => StopMovingElements();
                FindViewById(Resource.Id.insert_element).Click        += (sender, args) => InsertElements();
                Util.MoveBottomBarButtons(Resource.Id.cancel_insert_element, Resource.Id.insert_element, Resource.Id.bottom_bar, this);
            }

            if (FindViewById(Resource.Id.show_autofill_info) != null)
            {
                FindViewById(Resource.Id.show_autofill_info).Click += (sender, args) => Util.GotoUrl(this, "https://philippc.github.io/keepass2android/OreoAutoFill.html");
                Util.MoveBottomBarButtons(Resource.Id.show_autofill_info, Resource.Id.enable_autofill, Resource.Id.autofill_buttons, this);
            }

            if (FindViewById(Resource.Id.configure_notification_channels) != null)
            {
                FindViewById(Resource.Id.configure_notification_channels).Click += (sender, args) =>
                {
                    Intent intent = new Intent(Settings.ActionChannelNotificationSettings);
                    intent.PutExtra(Settings.ExtraChannelId, App.NotificationChannelIdQuicklocked);
                    intent.PutExtra(Settings.ExtraAppPackage, PackageName);
                    try
                    {
                        StartActivity(intent);
                    }
                    catch (Exception e)
                    {
                        new AlertDialog.Builder(this)
                        .SetTitle("Unexpected error")
                        .SetMessage(
                            "Opening the settings failed. Please report this to [email protected] including information about your device vendor and OS. Please try to configure the notifications by long pressing a KP2A notification. Details: " + e.ToString())
                        .Show();
                    }
                    UpdateAndroid8NotificationInfo(true);
                };
                FindViewById(Resource.Id.ignore_notification_channel).Click += (sender, args) =>
                {
                    UpdateAndroid8NotificationInfo(true);
                };
            }



            SetResult(KeePass.ExitNormal);
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            _design.ApplyTheme();
            base.OnCreate(savedInstanceState);

            Android.Util.Log.Debug("KP2A", "Creating GBA");

            AppTask = AppTask.GetTaskInOnCreate(savedInstanceState, Intent);

            // Likely the app has been killed exit the activity
            if (!App.Kp2a.GetDb().Loaded)
            {
                Finish();
                return;
            }

            _prefs = PreferenceManager.GetDefaultSharedPreferences(this);


            SetContentView(ContentResourceId);

            if (FindViewById(Resource.Id.enable_autofill) != null)
            {
                FindViewById(Resource.Id.enable_autofill).Click += (sender, args) =>
                {
                    var intent = new Intent(Settings.ActionRequestSetAutofillService);
                    intent.SetData(Android.Net.Uri.Parse("package:" + PackageName));
                    try
                    {
                        StartActivity(intent);
                    }
                    catch (ActivityNotFoundException e)
                    {
                        //this exception was reported by many Huawei users
                        Kp2aLog.LogUnexpectedError(e);
                        new AlertDialog.Builder(this)
                        .SetTitle(Resource.String.autofill_enable)
                        .SetMessage(Resource.String.autofill_enable_failed)
                        .SetPositiveButton(Resource.String.ok, (o, eventArgs) => { })
                        .Show();
                        const string autofillservicewasenabled = "AutofillServiceWasEnabled";
                        _prefs.Edit().PutBoolean(autofillservicewasenabled, true).Commit();
                        UpdateBottomBarElementVisibility(Resource.Id.autofill_infotext, false);
                    }
                };
            }

            if (FindViewById(Resource.Id.fabCancelAddNew) != null)
            {
                FindViewById(Resource.Id.fabAddNew).Click += (sender, args) =>
                {
                    FindViewById(Resource.Id.fabCancelAddNew).Visibility = ViewStates.Visible;
                    FindViewById(Resource.Id.fabAddNewGroup).Visibility  = AddGroupEnabled ? ViewStates.Visible : ViewStates.Gone;
                    FindViewById(Resource.Id.fabAddNewEntry).Visibility  = AddEntryEnabled ? ViewStates.Visible : ViewStates.Gone;
                    FindViewById(Resource.Id.fabAddNew).Visibility       = ViewStates.Gone;
                };

                FindViewById(Resource.Id.fabCancelAddNew).Click += (sender, args) =>
                {
                    FindViewById(Resource.Id.fabCancelAddNew).Visibility = ViewStates.Gone;
                    FindViewById(Resource.Id.fabAddNewGroup).Visibility  = ViewStates.Gone;
                    FindViewById(Resource.Id.fabAddNewEntry).Visibility  = ViewStates.Gone;
                    FindViewById(Resource.Id.fabAddNew).Visibility       = ViewStates.Visible;
                };
            }


            if (FindViewById(Resource.Id.cancel_insert_element) != null)
            {
                FindViewById(Resource.Id.cancel_insert_element).Click += (sender, args) => StopMovingElements();
                FindViewById(Resource.Id.insert_element).Click        += (sender, args) => InsertElements();
                Util.MoveBottomBarButtons(Resource.Id.cancel_insert_element, Resource.Id.insert_element, Resource.Id.bottom_bar, this);
            }

            if (FindViewById(Resource.Id.show_autofill_info) != null)
            {
                FindViewById(Resource.Id.show_autofill_info).Click += (sender, args) => Util.GotoUrl(this, "https://philippc.github.io/keepass2android/OreoAutoFill.html");
                Util.MoveBottomBarButtons(Resource.Id.show_autofill_info, Resource.Id.enable_autofill, Resource.Id.autofill_buttons, this);
            }

            if (FindViewById(Resource.Id.configure_notification_channels) != null)
            {
                FindViewById(Resource.Id.configure_notification_channels).Click += (sender, args) =>
                {
                    Intent intent = new Intent(Settings.ActionChannelNotificationSettings);
                    intent.PutExtra(Settings.ExtraChannelId, App.NotificationChannelIdQuicklocked);
                    intent.PutExtra(Settings.ExtraAppPackage, PackageName);
                    try
                    {
                        StartActivity(intent);
                    }
                    catch (Exception e)
                    {
                        new AlertDialog.Builder(this)
                        .SetTitle("Unexpected error")
                        .SetMessage(
                            "Opening the settings failed. Please report this to [email protected] including information about your device vendor and OS. Please try to configure the notifications by long pressing a KP2A notification. Details: " + e.ToString())
                        .Show();
                    }
                    UpdateAndroid8NotificationInfo(true);
                };
                FindViewById(Resource.Id.ignore_notification_channel).Click += (sender, args) =>
                {
                    UpdateAndroid8NotificationInfo(true);
                };
            }



            string lastInfoText;

            if (IsTimeForInfotext(out lastInfoText))
            {
                FingerprintUnlockMode um;
                Enum.TryParse(_prefs.GetString(Database.GetFingerprintModePrefKey(App.Kp2a.GetDb().Ioc), ""), out um);
                bool isFingerprintEnabled = (um == FingerprintUnlockMode.FullUnlock);

                string masterKeyKey = "MasterKey" + isFingerprintEnabled;
                string emergencyKey = "Emergency";
                string backupKey    = "Backup";

                List <string> applicableInfoTextKeys = new List <string> {
                    masterKeyKey
                };

                if (App.Kp2a.GetFileStorage(App.Kp2a.GetDb().Ioc).UserShouldBackup)
                {
                    applicableInfoTextKeys.Add(backupKey);
                }
                if (App.Kp2a.GetDb().Entries.Count > 15)
                {
                    applicableInfoTextKeys.Add(emergencyKey);
                }

                List <string> enabledInfoTextKeys = new List <string>();
                foreach (string key in applicableInfoTextKeys)
                {
                    if (!InfoTextWasDisabled(key))
                    {
                        enabledInfoTextKeys.Add(key);
                    }
                }

                if (enabledInfoTextKeys.Any())
                {
                    string infoTextKey = "", infoHead = "", infoMain = "", infoNote = "";

                    if (enabledInfoTextKeys.Count > 1)
                    {
                        foreach (string key in enabledInfoTextKeys)
                        {
                            if (key == lastInfoText)
                            {
                                enabledInfoTextKeys.Remove(key);
                                break;
                            }
                        }
                        infoTextKey = enabledInfoTextKeys[new Random().Next(enabledInfoTextKeys.Count)];
                    }

                    if (infoTextKey == masterKeyKey)
                    {
                        infoHead = GetString(Resource.String.masterkey_infotext_head);
                        infoMain = GetString(Resource.String.masterkey_infotext_main);
                        if (isFingerprintEnabled)
                        {
                            infoNote = GetString(Resource.String.masterkey_infotext_fingerprint_note);
                        }
                    }
                    else if (infoTextKey == emergencyKey)
                    {
                        infoHead = GetString(Resource.String.emergency_infotext_head);
                        infoMain = GetString(Resource.String.emergency_infotext_main);
                    }
                    else if (infoTextKey == backupKey)
                    {
                        infoHead = GetString(Resource.String.backup_infotext_head);
                        infoMain = GetString(Resource.String.backup_infotext_main);
                        infoNote = GetString(Resource.String.backup_infotext_note, GetString(Resource.String.menu_app_settings), GetString(Resource.String.menu_db_settings), GetString(Resource.String.export_prefs));
                    }



                    FindViewById <TextView>(Resource.Id.info_head).Text = infoHead;
                    FindViewById <TextView>(Resource.Id.info_main).Text = infoMain;
                    var additionalInfoText = FindViewById <TextView>(Resource.Id.info_additional);
                    additionalInfoText.Text       = infoNote;
                    additionalInfoText.Visibility = string.IsNullOrEmpty(infoNote) ? ViewStates.Gone : ViewStates.Visible;

                    if (infoTextKey != "")
                    {
                        RegisterInfoTextDisplay(infoTextKey);
                        FindViewById(Resource.Id.info_ok).Click += (sender, args) =>
                        {
                            UpdateBottomBarElementVisibility(Resource.Id.infotext, false);
                        };
                        FindViewById(Resource.Id.info_dont_show_again).Click += (sender, args) =>
                        {
                            UpdateBottomBarElementVisibility(Resource.Id.infotext, false);
                            DisableInfoTextDisplay(infoTextKey);
                        };

                        UpdateBottomBarElementVisibility(Resource.Id.infotext, true);
                    }
                }
            }



            SetResult(KeePass.ExitNormal);
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            _design.ApplyTheme();
            base.OnCreate(savedInstanceState);

            Android.Util.Log.Debug("KP2A", "Creating GBA");

            AppTask = AppTask.GetTaskInOnCreate(savedInstanceState, Intent);

            // Likely the app has been killed exit the activity
            if (!App.Kp2a.GetDb().Loaded)
            {
                Finish();
                return;
            }

            _prefs = PreferenceManager.GetDefaultSharedPreferences(this);


            SetContentView(ContentResourceId);

            if (FindViewById(Resource.Id.enable_autofill) != null)
            {
                FindViewById(Resource.Id.enable_autofill).Click += (sender, args) =>
                {
                    var intent = new Intent(Settings.ActionRequestSetAutofillService);
                    intent.SetData(Android.Net.Uri.Parse("package:" + PackageName));
                    StartActivity(intent);
                };
            }

            if (FindViewById(Resource.Id.fabCancelAddNew) != null)
            {
                FindViewById(Resource.Id.fabAddNew).Click += (sender, args) =>
                {
                    FindViewById(Resource.Id.fabCancelAddNew).Visibility = ViewStates.Visible;
                    FindViewById(Resource.Id.fabAddNewGroup).Visibility  = AddGroupEnabled ? ViewStates.Visible : ViewStates.Gone;
                    FindViewById(Resource.Id.fabAddNewEntry).Visibility  = AddEntryEnabled ? ViewStates.Visible : ViewStates.Gone;
                    FindViewById(Resource.Id.fabAddNew).Visibility       = ViewStates.Gone;
                };

                FindViewById(Resource.Id.fabCancelAddNew).Click += (sender, args) =>
                {
                    FindViewById(Resource.Id.fabCancelAddNew).Visibility = ViewStates.Gone;
                    FindViewById(Resource.Id.fabAddNewGroup).Visibility  = ViewStates.Gone;
                    FindViewById(Resource.Id.fabAddNewEntry).Visibility  = ViewStates.Gone;
                    FindViewById(Resource.Id.fabAddNew).Visibility       = ViewStates.Visible;
                };
            }


            if (FindViewById(Resource.Id.cancel_insert_element) != null)
            {
                FindViewById(Resource.Id.cancel_insert_element).Click += (sender, args) => StopMovingElements();
                FindViewById(Resource.Id.insert_element).Click        += (sender, args) => InsertElements();
                Util.MoveBottomBarButtons(Resource.Id.cancel_insert_element, Resource.Id.insert_element, Resource.Id.bottom_bar, this);
            }

            if (FindViewById(Resource.Id.show_autofill_info) != null)
            {
                FindViewById(Resource.Id.show_autofill_info).Click += (sender, args) => Util.GotoUrl(this, "https://philippc.github.io/keepass2android/OreoAutoFill.html");
                Util.MoveBottomBarButtons(Resource.Id.show_autofill_info, Resource.Id.enable_autofill, Resource.Id.autofill_buttons, this);
            }



            SetResult(KeePass.ExitNormal);
        }