예제 #1
0
        public override int GetItemViewType(int position)
        {
            ModifiableChoice item = GetItem(position);

            if (item.Choice.Separator)
            {
                return(TYPE_SEPARATOR);
            }
            else if (_choicePromptType == GeckoSession.romptDelegateClassChoice.ChoiceTypeMenu)
            {
                return(item.ModifiableSelected ? TYPE_MENU_CHECK : TYPE_MENU_ITEM);
            }
            else if (item.Choice.Items != null)
            {
                return(TYPE_GROUP);
            }
            else if (_choicePromptType == GeckoSession.romptDelegateClassChoice.ChoiceTypeSingle)
            {
                return(TYPE_SINGLE);
            }
            else if (_choicePromptType == GeckoSession.romptDelegateClassChoice.ChoiceTypeMultiple)
            {
                return(TYPE_MULTIPLE);
            }
            else
            {
                throw new UnsupportedOperationException();
            }
        }
예제 #2
0
        public override bool IsEnabled(int position)
        {
            ModifiableChoice item = GetItem(position);

            return(!item.Choice.Separator && !item.Choice.Disabled &&
                   ((_choicePromptType != GeckoSession.romptDelegateClassChoice.ChoiceTypeSingle &&
                     _choicePromptType != GeckoSession.romptDelegateClassChoice.ChoiceTypeMultiple) ||
                    item.Choice.Items == null));
        }
예제 #3
0
        private void AddChoiceItems(int type, ModifiableChoiceArrayAdapter <ModifiableChoice> list,
                                    GeckoSession.romptDelegateClassChoice[] items, string indent)
        {
            if (type == GeckoSession.romptDelegateClassChoice.ChoiceTypeMenu)
            {
                foreach (GeckoSession.romptDelegateClassChoice item in items)
                {
                    list.Add(new ModifiableChoice(item));
                }
                return;
            }

            foreach (GeckoSession.romptDelegateClassChoice item in items)
            {
                ModifiableChoice modItem = new ModifiableChoice(item);

                GeckoSession.romptDelegateClassChoice[] children = item.Items?.ToArray();

                if (indent != null && children == null)
                {
                    modItem.ModifiableLabel = indent + modItem.ModifiableLabel;
                }
                list.Add(modItem);

                if (children != null)
                {
                    string newIndent;
                    if (type == GeckoSession.romptDelegateClassChoice.ChoiceTypeSingle || type == GeckoSession.romptDelegateClassChoice.ChoiceTypeMultiple)
                    {
                        newIndent = (indent != null) ? indent + '\t' : "\t";
                    }
                    else
                    {
                        newIndent = null;
                    }
                    AddChoiceItems(type, list, children, newIndent);
                }
            }
        }
예제 #4
0
        public virtual void OnChoicePrompt(GeckoSession session, string title, string msg, int type, GeckoSession.romptDelegateClassChoice[] choices, GeckoSession.PromptDelegateClassChoiceCallback prompt)
        {
            //This code is highly inspired of https://github.com/mozilla-mobile/focus-android/blob/f5b22ff78fca22765b8b873b4f70693943ae559a/app/src/main/java/org/mozilla/focus/gecko/GeckoViewPrompt.java#L265

            var currentActivity = BlazorWebViewService.GetCurrentActivity();

            if (currentActivity == null)
            {
                prompt.Dismiss();
                return;
            }

            var builder = new Android.App.AlertDialog.Builder(currentActivity);

            AddStandardLayout(builder, title, msg);

            Android.Widget.ListView list = new Android.Widget.ListView(builder.Context);
            if (type == GeckoSession.romptDelegateClassChoice.ChoiceTypeMultiple)
            {
                list.ChoiceMode = ChoiceMode.Multiple;
            }

            ModifiableChoiceArrayAdapter <ModifiableChoice> adapter = new ModifiableChoiceArrayAdapter <ModifiableChoice>(builder.Context, Android.Resource.Layout.SimpleListItem1, type, builder, list);

            AddChoiceItems(type, adapter, choices, /* indent */ null);

            list.SetAdapter(adapter);
            builder.SetView(list);

            AlertDialog dialog;

            if (type == GeckoSession.romptDelegateClassChoice.ChoiceTypeSingle || type == GeckoSession.romptDelegateClassChoice.ChoiceTypeMenu)
            {
                dialog = CreateStandardDialog(builder, prompt);

                list.ItemClick += (sender, e) =>
                {
                    ModifiableChoice item = adapter.GetItem(e.Position);
                    if (type == GeckoSession.romptDelegateClassChoice.ChoiceTypeMenu)
                    {
                        GeckoSession.romptDelegateClassChoice[] children = item.Choice.Items?.ToArray();
                        if (children != null)
                        {
                            // Show sub-menu.
                            dialog.SetOnDismissListener(null);
                            dialog.Dismiss();
                            OnChoicePrompt(session, item.ModifiableLabel, /* msg */ null,
                                           type, children, prompt);
                            return;
                        }
                    }
                    prompt.Confirm(item.Choice);
                    dialog.Dismiss();
                };
            }
            else if (type == GeckoSession.romptDelegateClassChoice.ChoiceTypeMultiple)
            {
                list.ItemClick += (sender, e) =>
                {
                    ModifiableChoice item = adapter.GetItem(e.Position);
                    item.ModifiableSelected = ((CheckedTextView)e.View).Checked;
                };
                builder
                .SetNegativeButton(Android.Resource.String.Cancel, /* listener */ (IDialogInterfaceOnClickListener)null)
                .SetPositiveButton(Android.Resource.String.Ok, (sender, e) =>
                {
                    int len             = adapter.Count;
                    List <string> items = new List <string>(len);
                    for (int i = 0; i < len; i++)
                    {
                        ModifiableChoice item = adapter.GetItem(i);
                        if (item.ModifiableSelected)
                        {
                            items.Add(item.Choice.Id);
                        }
                    }
                    prompt.Confirm(items.ToArray());
                });
                dialog = CreateStandardDialog(builder, prompt);
            }
            else
            {
                throw new UnsupportedOperationException();
            }
            dialog.Show();

            //TODO: Don't forget to Dispose dialogbuilder
        }
예제 #5
0
        public override Android.Views.View GetView(int position, Android.Views.View view, ViewGroup parent)
        {
            var context = BlazorWebViewService.GetCurrentActivity();

            int itemType = GetItemViewType(position);
            int layoutId;

            if (itemType == TYPE_SEPARATOR)
            {
                if (mSeparator == null)
                {
                    mSeparator = new Android.Views.View(context);
                    mSeparator.LayoutParameters = new Android.Widget.ListView.LayoutParams(ViewGroup.LayoutParams.MatchParent, 2, itemType);
                    TypedArray attr = context.ObtainStyledAttributes(
                        new int[] { Android.Resource.Attribute.ListDivider });
                    mSeparator.SetBackgroundResource(attr.GetResourceId(0, 0));
                    attr.Recycle();
                }
                return(mSeparator);
            }
            else if (itemType == TYPE_MENU_ITEM)
            {
                layoutId = Android.Resource.Layout.SimpleListItem1;
            }
            else if (itemType == TYPE_MENU_CHECK)
            {
                layoutId = Android.Resource.Layout.SimpleListItemChecked;
            }
            else if (itemType == TYPE_GROUP)
            {
                layoutId = Android.Resource.Layout.PreferenceCategory;
            }
            else if (itemType == TYPE_SINGLE)
            {
                layoutId = Android.Resource.Layout.SimpleListItemSingleChoice;
            }
            else if (itemType == TYPE_MULTIPLE)
            {
                layoutId = Android.Resource.Layout.SimpleListItemMultipleChoice;
            }
            else
            {
                throw new UnsupportedOperationException();
            }

            if (view == null)
            {
                if (mInflater == null)
                {
                    mInflater = LayoutInflater.From(_builder.Context);
                }
                view = mInflater.Inflate(layoutId, parent, false);
            }

            ModifiableChoice item = GetItem(position);
            TextView         text = (TextView)view;

            text.Enabled = !item.Choice.Disabled;
            text.Text    = item.ModifiableLabel;
            if (view is CheckedTextView)
            {
                bool selected = item.ModifiableSelected;
                if (itemType == TYPE_MULTIPLE)
                {
                    _list.SetItemChecked(position, selected);
                }
                else
                {
                    ((CheckedTextView)view).Checked = selected;
                }
            }
            return(view);
        }