protected override void OnCreate(Bundle bundle) { new ActivityDesign(this).ApplyTheme(); base.OnCreate(bundle); SetContentView(Resource.Layout.plugin_list); PluginHost.TriggerRequests(this); ListView listView = FindViewById <ListView>(Android.Resource.Id.List); listView.ItemClick += (sender, args) => { Intent i = new Intent(this, typeof(PluginDetailsActivity)); i.PutExtra(Strings.ExtraPluginPackage, _items[args.Position].Package); StartActivity(i); }; FindViewById <Button>(Resource.Id.btnPluginsOnline).Click += delegate { Util.GotoUrl(this, "https://keepass2android.codeplex.com/wikipage?title=Available%20Plug-ins"); }; }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.plugin_list); PluginHost.TriggerRequests(this); ListView listView = FindViewById <ListView>(Android.Resource.Id.List); listView.ItemClick += (sender, args) => { Intent i = new Intent(this, typeof(PluginDetailsActivity)); i.PutExtra(Strings.ExtraPluginPackage, _items[args.Position].Package); StartActivity(i); }; }
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { base.OnActivityResult(requestCode, resultCode, data); if (requestCode == RequestCodePluginAccess) { if (new PluginDatabase(this).HasAcceptedScope(_pluginPackage, _requiredScope)) { //user granted access. Search for the requested credentials: StartQuery(); } else { //user didn't grant access SetResult(Result.Canceled); Finish(); } } if (requestCode == RequestCodeQuery) { if (resultCode == KeePass.ExitCloseAfterTaskComplete) { //double check we really have the permission if (!new PluginDatabase(this).HasAcceptedScope(_pluginPackage, _requiredScope)) { Kp2aLog.LogUnexpectedError(new Exception("Ohoh! Scope not available, shouldn't get here. Malicious app somewhere?")); SetResult(Result.Canceled); Finish(); return; } //return credentials to caller: Intent credentialData = new Intent(); PluginHost.AddEntryToIntent(credentialData, App.Kp2a.LastOpenedEntry); credentialData.PutExtra(Strings.ExtraQueryString, _requestedUrl); SetResult(Result.Ok, credentialData); Finish(); } else { SetResult(Result.Canceled); Finish(); } } }
private void AddPluginAction(string pluginPackage, string fieldId, string popupItemId, string displayText, int iconId, Bundle bundleExtra) { if (fieldId != null) { try { if (!_popupMenuItems.ContainsKey(fieldId)) { Kp2aLog.Log("Did not find field with key " + fieldId); return; } //create a new popup item for the plugin action: var newPopup = new PluginPopupMenuItem(this, pluginPackage, fieldId, popupItemId, displayText, iconId, bundleExtra); //see if we already have a popup item for this field with the same item id var popupsForField = _popupMenuItems[fieldId]; var popupItemPos = popupsForField.FindIndex(0, item => (item is PluginPopupMenuItem) && ((PluginPopupMenuItem)item).PopupItemId == popupItemId); //replace existing or add if (popupItemPos >= 0) { popupsForField[popupItemPos] = newPopup; } else { popupsForField.Add(newPopup); } } catch (Exception e) { Kp2aLog.LogUnexpectedError(e); } } else { //we need to add an option to the menu. //As it is not sure that OnCreateOptionsMenu was called yet, we cannot access _menu without a check: Intent i = new Intent(Strings.ActionEntryActionSelected); i.SetPackage(pluginPackage); i.PutExtra(Strings.ExtraActionData, bundleExtra); i.PutExtra(Strings.ExtraSender, PackageName); PluginHost.AddEntryToIntent(i, App.Kp2a.GetDb().LastOpenedEntry); var menuOption = new PluginMenuOption() { DisplayText = displayText, Icon = PackageManager.GetResourcesForApplication(pluginPackage).GetDrawable(iconId), Intent = i }; if (_menu != null) { AddMenuOption(menuOption); } else { lock (_pendingMenuOptions) { _pendingMenuOptions.Add(menuOption); } } } }
public void AddEntryToIntent(Intent intent) { PluginHost.AddEntryToIntent(intent, App.Kp2a.GetDb().LastOpenedEntry); }
protected override void OnCreate(Bundle bundle) { new ActivityDesign(this).ApplyTheme(); base.OnCreate(bundle); _pluginPackageName = Intent.GetStringExtra(Strings.ExtraPluginPackage); var pluginRes = PackageManager.GetResourcesForApplication(_pluginPackageName); var title = GetStringFromPlugin(pluginRes, _pluginPackageName, "kp2aplugin_title"); var author = GetStringFromPlugin(pluginRes, _pluginPackageName, "kp2aplugin_author"); var shortDesc = GetStringFromPlugin(pluginRes, _pluginPackageName, "kp2aplugin_shortdesc"); var version = PackageManager.GetPackageInfo(_pluginPackageName, 0).VersionName; SetContentView(Resource.Layout.plugin_details); if (title != null) { FindViewById <TextView>(Resource.Id.txtLabel).Text = title; } FindViewById <TextView>(Resource.Id.txtVersion).Text = version; SetTextOrHide(Resource.Id.txtAuthor, author); SetTextOrHide(Resource.Id.txtShortDesc, shortDesc); _checkbox = FindViewById <CheckBox>(Resource.Id.cb_enabled); _checkbox.CheckedChange += delegate { new PluginDatabase(this).SetEnabled(_pluginPackageName, _checkbox.Checked); }; Drawable d = PackageManager.GetApplicationIcon(_pluginPackageName); FindViewById <ImageView>(Resource.Id.imgIcon).SetImageDrawable(d); FindViewById <TextView>(Resource.Id.txtVersion).Text = version; //cannot be wrong to update the view when we received an update PluginHost.OnReceivedRequest += OnPluginHostOnOnReceivedRequest; if (Intent.Action == Strings.ActionEditPluginSettings) { //this action can be triggered by external apps so we don't know if anybody has ever triggered //the plugin to request access. Do this now, don't set the view right now PluginHost.TriggerRequest(this, _pluginPackageName, new PluginDatabase(this)); //show the buttons instead of the checkbox _checkbox.Visibility = ViewStates.Invisible; FindViewById(Resource.Id.accept_button).Visibility = ViewStates.Invisible; //show them only after access is requested FindViewById(Resource.Id.deny_button).Visibility = ViewStates.Visible; FindViewById(Resource.Id.accept_button).Click += delegate(object sender, EventArgs args) { new PluginDatabase(this).SetEnabled(_pluginPackageName, true); SetResult(Result.Ok); Finish(); }; FindViewById(Resource.Id.deny_button).Click += delegate(object sender, EventArgs args) { new PluginDatabase(this).SetEnabled(_pluginPackageName, false); SetResult(Result.Canceled); Finish(); }; //in case the plugin requested scopes previously, make sure we display them UpdateView(); } else { UpdateView(); _checkbox.Visibility = ViewStates.Visible; FindViewById(Resource.Id.accept_button).Visibility = ViewStates.Gone; FindViewById(Resource.Id.deny_button).Visibility = ViewStates.Gone; } }
private void OnPluginHostOnOnReceivedRequest(object sender, PluginHost.PluginHostEventArgs args) { if (args.Package == _pluginPackageName) { UpdateView(); } }
public IEnumerable <String> GetAllPluginPackages() { return(PluginHost.GetAllPlugins(_ctx)); }