Beispiel #1
0
        private void AddMenuOption(PluginMenuOption menuOption)
        {
            var menuItem = _menu.Add(menuOption.DisplayText);

            menuItem.SetIcon(menuOption.Icon);
            menuItem.SetIntent(menuOption.Intent);
        }
Beispiel #2
0
        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);
                    }
                }
            }
        }