Exemple #1
0
        protected void CreateDialog()
        {
            _ListView?.Dispose();
            _Adapter?.Dispose();
            _ListView = new AListView(AndroidContext)
            {
                Focusable = false,
                DescendantFocusability = DescendantFocusability.AfterDescendants,
                ChoiceMode             = _PickerCell.SelectionMode switch
                {
                    SelectMode.Single => ChoiceMode.Single,
                    _ => ChoiceMode.Multiple,
                }
            };
            _ListView.SetDrawSelectorOnTop(true);
            _Adapter = new PickerAdapter(AndroidContext, this, _PickerCell, _ListView);

            _ListView.OnItemClickListener = _Adapter;
            _ListView.Adapter             = _Adapter;

            _TitleLabel = new TextView(AndroidContext)
            {
                Text    = _PickerCell.Prompt.Title,
                Gravity = GravityFlags.Center
            };
            _TitleLabel.SetBackgroundColor(_Adapter.BackgroundColor);
            _TitleLabel.SetTextColor(_Adapter.TitleTextColor);
            _TitleLabel.SetTextSize(ComplexUnitType.Sp, _Adapter.FontSize);


            if (_Dialog is not null)
            {
                return;
            }
            using (var builder = new AlertDialog.Builder(AndroidContext))
            {
                // builder.SetTitle(_PickerCell.PopupTitle);
                builder.SetCustomTitle(_TitleLabel);
                builder.SetView(_ListView);

                builder.SetNegativeButton(_PickerCell.Prompt.Cancel, CancelEventHandler);
                builder.SetPositiveButton(_PickerCell.Prompt.Accept, AcceptEventHandler);

                _Dialog = builder.Create();
            }

            if (_Dialog is null)
            {
                return;
            }
            _Dialog.SetCanceledOnTouchOutside(true);
            _Dialog.SetOnDismissListener(this);
            _Dialog.SetOnShowListener(this);
            _Dialog.Show();

            // Pending
            //var buttonTextColor = _PickerCell.AccentColor.IsDefault ? Xamarin.Forms.Color.Accent.ToAndroid() : _PickerCell.AccentColor.ToAndroid();
            //_dialog.GetButton((int)DialogButtonType.Positive).SetTextColor(buttonTextColor);
            //_dialog.GetButton((int)DialogButtonType.Negative).SetTextColor(buttonTextColor);
        }
Exemple #2
0
        internal PickerInnerView(Context context, PickerAdapter adapter) : base(context)
        {
            LayoutParameters = new LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);

            var padding = (int)context.ToPixels(8);

            SetPadding(padding, padding, padding, padding);

            SetBackgroundColor(adapter.BackgroundColor);


            _Title = new TextView(context)
            {
                Id = GenerateViewId()
            };
            _Title.SetBackgroundColor(adapter.BackgroundColor);
            _Title.SetTextColor(adapter.TextColor);
            _Title.SetTextSize(ComplexUnitType.Sp, (float)adapter.FontSize);


            _Description = new TextView(context)
            {
                Id = GenerateViewId()
            };
            _Description.SetBackgroundColor(adapter.BackgroundColor);
            _Description.SetTextColor(adapter.DetailColor);
            _Description.SetTextSize(ComplexUnitType.Sp, (float)adapter.DetailFontSize);


            _CheckBox = new SimpleCheck(context, adapter.AccentColor)
            {
                Focusable = false,
            };
            _CheckBox.SetBackgroundColor(adapter.BackgroundColor);
            _CheckBox.SetHighlightColor(adapter.AccentColor);


            _Container = new LinearLayout(context)
            {
                Orientation = Orientation.Vertical
            };
            _Container.SetBackgroundColor(adapter.BackgroundColor);


            using (var param = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent))
            {
                _Container.AddView(_Title, param);
                _Container.AddView(_Description, param);
            }


            using (var param = new LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent))
            {
                param.AddRule(LayoutRules.AlignParentStart);
                param.AddRule(LayoutRules.CenterVertical);
                AddView(_Container, param);
            }


            using (var param = new LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.MatchParent)
            {
                Width = (int)context.ToPixels(30),
                Height = (int)context.ToPixels(30)
            })
            {
                param.AddRule(LayoutRules.AlignParentEnd);
                param.AddRule(LayoutRules.CenterVertical);
                AddView(_CheckBox, param);
            }
        }