コード例 #1
0
        /// <summary>
        /// On pre show
        /// </summary>
        protected void PreShow()
        {
            if (mRootView == null)
            {
                throw new IllegalStateException("setContentView was not called with a view to display.");
            }

            OnShow();

            if (mBackground == null)
            {
                mWindow.SetBackgroundDrawable(new BitmapDrawable());
            }
            else
            {
                mWindow.SetBackgroundDrawable(mBackground);
            }

            mWindow.Width     = WindowManagerLayoutParams.WrapContent;
            mWindow.Height    = WindowManagerLayoutParams.WrapContent;
            mWindow.Touchable = true;

            //TODO: make sure this doesn't crash somehow.
            //mWindow.setFocusable(true);
            mWindow.OutsideTouchable = true;

            mWindow.ContentView = mRootView;
        }
コード例 #2
0
        protected void PreShow()
        {
            if (root == null)
            {
                throw new Exception("setContentView was not called with a view to display.");
            }

            OnShow();

            if (background == null)
            {
                window.SetBackgroundDrawable(new BitmapDrawable());
            }
            else
            {
                window.SetBackgroundDrawable(background);
            }

            // if using PopupWindow#setBackgroundDrawable this is the only values of the width and hight that make it work
            // otherwise you need to set the background of the root viewgroup
            // and set the popupwindow background to an empty BitmapDrawable

            window.Width            = WindowManagerLayoutParams.WrapContent;
            window.Height           = WindowManagerLayoutParams.WrapContent;
            window.Touchable        = true;
            window.Focusable        = true;
            window.OutsideTouchable = true;

            window.ContentView = root;
        }
コード例 #3
0
        public void ShowToolTip(View anchor)
        {
            tipWindow.Height           = ViewGroup.LayoutParams.WrapContent;
            tipWindow.Width            = ViewGroup.LayoutParams.WrapContent;
            tipWindow.OutsideTouchable = false;
            tipWindow.Focusable        = false;
            tipWindow.SetBackgroundDrawable(new BitmapDrawable());

            tipWindow.ContentView = contentView;

            tipWindow.AnimationStyle = Resource.Style.animationPopUp;

            var screenPos = new int[2];

            anchor.GetLocationOnScreen(screenPos);
            var anchorRect = new Rect(screenPos [0], screenPos [1], screenPos [0] + anchor.Width, screenPos [1] + anchor.Height);

            contentView.Measure(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent);

            var contentViewheight = contentView.MeasuredHeight;
            var contentViewwidth  = contentView.MeasuredWidth;

            var positionX = anchorRect.CenterX() - contentViewwidth / 2;
            var positionY = anchorRect.Bottom - anchorRect.Height() / 2;

            tipWindow.ShowAtLocation(anchor, GravityFlags.NoGravity, positionX, positionY);
        }
コード例 #4
0
        private void ComponentsAdapter_PortionClicked(object sender, Events.PortionClickedEventArgs e)
        {
            if (popupWindow != null)
            {
                return;
            }

            FrameLayout mainView = new FrameLayout(this.Context);

            ListView popupView = new ListView(this.Context);

            PortionsListViewAdapter adapter = new PortionsListViewAdapter(e.View.ComponentId);

            adapter.PortionSelected += Adapter_PortionSelected;
            popupView.Adapter        = adapter;

            mainView.AddView(popupView);

            popupWindow        = new PopupWindow(mainView);
            popupWindow.Width  = 100;
            popupWindow.Height = 200;

            Resources res = this.Context.Resources;

#pragma warning disable CS0618 // Type or member is obsolete
            Drawable shape = res.GetDrawable(Resource.Drawable.VariationsListBorder);
#pragma warning restore CS0618 // Type or member is obsolete
            popupWindow.SetBackgroundDrawable(shape);

            popupWindow.ShowAsDropDown(e.View, 10, 0);
        }
コード例 #5
0
        private void DiscountButton_Click(object sender, EventArgs e)
        {
            if (popupWindow != null)
            {
                return;
            }

            FrameLayout mainView = new FrameLayout(this.Context);

            ListView popupView = new ListView(this.Context);

            DiscountPopupListViewAdapter adapter = new DiscountPopupListViewAdapter();

            adapter.DiscountSelected += Adapter_DiscountSelected;
            popupView.Adapter         = adapter;

            mainView.AddView(popupView);

            popupWindow        = new PopupWindow(mainView);
            popupWindow.Width  = 470;
            popupWindow.Height = 270;

            Resources res = this.Context.Resources;

#pragma warning disable CS0618 // Type or member is obsolete
            Drawable shape = res.GetDrawable(Resource.Drawable.VariationsListBorder);
#pragma warning restore CS0618 // Type or member is obsolete
            popupWindow.SetBackgroundDrawable(shape);

            popupWindow.ShowAsDropDown(discountText, 0, 0);
        }
コード例 #6
0
ファイル: Popup.Android.cs プロジェクト: propellingbits/Uno
        protected override void OnIsLightDismissEnabledChanged(bool oldIsLightDismissEnabled, bool newIsLightDismissEnabled)
        {
            base.OnIsLightDismissEnabledChanged(oldIsLightDismissEnabled, newIsLightDismissEnabled);
            if (newIsLightDismissEnabled)
            {
                _popupWindow.OutsideTouchable = true;

                _popupWindow.SetBackgroundDrawable(new ColorDrawable(Colors.Transparent));
            }
            else
            {
                _popupWindow.OutsideTouchable = false;

                _popupWindow.SetBackgroundDrawable(null);
            }
        }
コード例 #7
0
        public void ShowCourse(View v)
        {
            if (courseList != null && courseList.Any())
            {
                if (popCourse == null)
                {
                    View                popViwe3  = LayoutInflater.Inflate(Resource.Layout.popup_select1, null);
                    ListView            listview3 = popViwe3.FindViewById <ListView>(Resource.Id.lv);
                    CourseSelectAdapter adaptera  = new CourseSelectAdapter(CurrActivity, courseList);
                    adaptera.SetSelectedValue(searchCourse);
                    listview3.Adapter = adaptera;

                    popCourse                  = new PopupWindow(popViwe3, ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);
                    popCourse.Touchable        = true;
                    popCourse.Focusable        = true;
                    popCourse.OutsideTouchable = true;;
                    popCourse.SetBackgroundDrawable(new BitmapDrawable());

                    popCourse.DismissEvent += (sender, e) =>
                    {
                        tv_course.SetTextColor(new Color(ContextCompat.GetColor(CurrActivity, Resource.Color.textColorPrimary)));
                        var arrowDown = AppUtils.GetDrawable(CurrActivity, Resource.Drawable.arrow_down);
                        arrowDown.SetBounds(0, 0, arrowDown.MinimumWidth, arrowDown.MinimumHeight);
                        tv_course.SetCompoundDrawables(null, null, arrowDown, null);
                    };

                    listview3.ItemClick += (sender, e) =>
                    {
                        searchCourse   = this.courseList[e.Position];
                        tv_course.Text = searchCourse;

                        popCourse.Dismiss();

                        adaptera.SetSelectedValue(searchCourse);
                        adaptera.NotifyDataSetChanged();

                        BindData();
                    };
                }
                if (!popCourse.IsShowing)
                {
                    tv_course.SetTextColor(new Color(ContextCompat.GetColor(CurrActivity, Resource.Color.textColorHigh)));
                    var arrowDownOn = AppUtils.GetDrawable(CurrActivity, Resource.Drawable.arrow_down_on);
                    arrowDownOn.SetBounds(0, 0, arrowDownOn.MinimumWidth, arrowDownOn.MinimumHeight);
                    tv_course.SetCompoundDrawables(null, null, arrowDownOn, null);

                    if ((int)(Build.VERSION.SdkInt) >= 24)
                    {
                        int[] a = new int[2];
                        v.GetLocationInWindow(a);
                        popCourse.ShowAtLocation(Window.DecorView, GravityFlags.NoGravity, 0, a[1] + v.Height + AppUtils.dip2px(CurrActivity, 11));
                    }
                    else
                    {
                        popCourse.ShowAsDropDown(v, 0, AppUtils.dip2px(CurrActivity, 11));
                    }
                }
            }
        }
コード例 #8
0
 private void InitFloatingWindow()
 {
     mWindow           = new PopupWindow(mContext);
     mWindow.Focusable = false;
     mWindow.SetBackgroundDrawable(null);
     mWindow.OutsideTouchable = true;
     mAnimStyle = Android.Resource.Style.Animation;
 }
コード例 #9
0
        partial void OnIsLightDismissEnabledChangedNative(bool oldIsLightDismissEnabled, bool newIsLightDismissEnabled)
        {
            if (newIsLightDismissEnabled)
            {
                _popupWindow.OutsideTouchable = true;

                _popupWindow.SetBackgroundDrawable(new ColorDrawable(Colors.Transparent));
            }
            else
            {
                _popupWindow.OutsideTouchable = false;

                _popupWindow.SetBackgroundDrawable(null);
            }

            UpdatePopupPanelDismissibleBackground(newIsLightDismissEnabled);
        }
コード例 #10
0
ファイル: AddressBook.cs プロジェクト: elmariachi4/Xamarin
        PopupWindow CreateActionsPopup(Contact contactActions, AdapterView.ItemClickEventArgs e)
        {
            PopupWindow popup = new PopupWindow(Activity.CurrentFocus);

            popup.ContentView = popupView;
            popup.Focusable   = true;
            popup.Update();
            popup.OutsideTouchable = true;
            popup.SetBackgroundDrawable(new ColorDrawable(Color.LightGray));
            popup.AnimationStyle = Resource.Style.Animation_AppCompat_Dialog;
            popup.Width          = ViewGroup.LayoutParams.WrapContent;
            popup.Height         = ViewGroup.LayoutParams.WrapContent;
            ListView actionsListView = popupView.FindViewById <ListView>(Resource.Id.actionsListView);

            actionsListView.Adapter    = new AddressBookListAdapter(Activity, RequestContactData(contactActions));
            actionsListView.ItemClick += (sender, eArgs) =>
            {
                List <string> a = RequestContactData(contactActions);
                if (a[eArgs.Position].StartsWith("Call"))
                {
                    popup.Dismiss();
                    var callIntent = new Intent(Intent.ActionCall,
                                                Android.Net.Uri.Parse(string.Format("tel:{0}",
                                                                                    a[eArgs.Position].Substring(5).Trim(' ', '+', '-')))); //definitely not the best optimization concept, but still works
                    StartActivity(callIntent);
                }
                else
                {
                    PopupWindow mailPopup = new PopupWindow(Activity.CurrentFocus); //creating nested popup, if user choses sending email
                    mailPopup.ContentView = emailView;
                    mailPopup.Focusable   = true;
                    mailPopup.Update();
                    mailPopup.OutsideTouchable = true;
                    mailPopup.SetBackgroundDrawable(new ColorDrawable(Color.LightGray));
                    mailPopup.AnimationStyle = Resource.Style.Animation_AppCompat_Dialog;
                    mailPopup.Width          = ViewGroup.LayoutParams.WrapContent;
                    mailPopup.Height         = ViewGroup.LayoutParams.WrapContent;
                    EditText editTitle   = emailView.FindViewById <EditText>(Resource.Id.editMailTitle);
                    EditText editMessage = emailView.FindViewById <EditText>(Resource.Id.editMailMessage);
                    editTitle.Text   = string.Format("Hello, {0}", contactActions.Name); //template for title
                    editMessage.Text = string.Format("Dear {0}, ", contactActions.Name); // and message of email
                    Button buttonSend = emailView.FindViewById <Button>(Resource.Id.buttonSend);
                    buttonSend.Click += (_sender, _e) =>
                    {
                        var email = new Intent(Intent.ActionSend);
                        email.PutExtra(Intent.ExtraEmail, a[eArgs.Position]);
                        email.PutExtra(Intent.ExtraSubject, string.Format("Hello, {0}, ", contactActions.Name));
                        email.PutExtra(Intent.ExtraText, string.Format("Dear {0}, ", contactActions.Name));
                        email.SetType("message/rfc822");
                        StartActivity(email); //starting the mail app with given data
                    };
                    emailView.FindViewById <TextView>(Resource.Id.textViewMailHeader).Text = string.Format("Email to {0}", contactActions.Name);
                    mailPopup.ShowAtLocation(view, GravityFlags.Center, 0, 0);
                }
            };
            return(popup);
        }
コード例 #11
0
        public AbstractKeyBoard(Context context)
        {
            mContext = context;

            mPopopWindow = new PopupWindow(ViewGroup.LayoutParams.MatchParent,
                                           ViewGroup.LayoutParams.WrapContent);
            mPopopWindow.Focusable        = true;
            mPopopWindow.OutsideTouchable = false;
            mPopopWindow.SetBackgroundDrawable(new BitmapDrawable());
        }
コード例 #12
0
        void PreShow()
        {
            _window.SetBackgroundDrawable(Background ?? new BitmapDrawable());

            _window.Width            = ViewGroup.LayoutParams.WrapContent;
            _window.Height           = ViewGroup.LayoutParams.WrapContent;
            _window.Touchable        = true;
            _window.Focusable        = true;
            _window.OutsideTouchable = true;
            _window.ContentView      = _rootView;
        }
コード例 #13
0
        internal void CallFilterDialog(View anchor, Activity context)
        {
            FilterDialog d = tableModel.GetFilterView(context, anchor);

            PopupWindow w = d.GetView();

            w.ShowAsDropDown(anchor);
            w.OutsideTouchable = true;
            w.Touchable        = true;
            w.SetBackgroundDrawable(new BitmapDrawable());
        }
コード例 #14
0
 private void InitPopupWindow(int animationStyle)
 {
     popupWindow                  = new PopupWindow(context);
     popupWindow.Width            = WindowManagerLayoutParams.WrapContent;
     popupWindow.Height           = WindowManagerLayoutParams.WrapContent;
     popupWindow.Touchable        = true;
     popupWindow.Focusable        = true;
     popupWindow.OutsideTouchable = true;
     popupWindow.SetBackgroundDrawable(new ColorDrawable(Color.Transparent));
     popupWindow.AnimationStyle = animationStyle;
     popupWindow.SetTouchInterceptor(new TouchListener(popupWindow));
 }
コード例 #15
0
        void ListView_OnItemLongClick(object sender, AdapterView.ItemLongClickEventArgs e)
        {
            LocalBox clickedItem = foundLocalBoxes [e.Position];

            LayoutInflater inflater = (LayoutInflater)Activity.GetSystemService(Context.LayoutInflaterService);
            View           popupView;

            popupView = inflater.Inflate(Resource.Layout.custom_popup_root, null);

            PopupWindow popupWindow = new PopupWindow(popupView, e.View.Width, e.View.Height);

            //Hide popup window when clicking outside its view
            popupWindow.Focusable = true;
            popupWindow.Update();
            popupWindow.SetBackgroundDrawable(new BitmapDrawable());

            popupWindow.ShowAsDropDown(e.View, 0, -e.View.Height);

            ImageButton buttonDelete = (ImageButton)popupView.FindViewById(Resource.Id.button_popup_root_delete);

            buttonDelete.Click += delegate {
                popupWindow.Dismiss();

                var alertDialogConfirmDelete = new Android.App.AlertDialog.Builder(Activity);
                alertDialogConfirmDelete.SetTitle("Waarschuwing");
                alertDialogConfirmDelete.SetMessage("Weet u zeker dat u deze Pleiobox wilt verwijderen? \nDeze actie is niet terug te draaien.");

                alertDialogConfirmDelete.SetPositiveButton("Verwijderen", async delegate {
                    try{
                        DataLayer.Instance.DeleteLocalBox(clickedItem.Id);
                        ResetUIToBeginState(true);
                        UpdateLocalBoxes();

                        List <LocalBox> registeredLocalBoxes = await DataLayer.Instance.GetLocalBoxes();
                        if (registeredLocalBoxes.Count == 0)
                        {
                            HomeActivity homeActivity = (HomeActivity)Activity;
                            homeActivity.ShowLoginDialog();
                        }
                        //Reset logo
                        //imageViewLogo.SetImageResource (Resource.Drawable.beeldmerk_belastingdienst);
                    }catch (Exception ex) {
                        Insights.Report(ex);
                        Toast.MakeText(Android.App.Application.Context, "Het verwijderen van de Pleiobox is mislukt", ToastLength.Short).Show();
                    }
                });
                alertDialogConfirmDelete.SetNegativeButton("Annuleren", delegate {
                    alertDialogConfirmDelete.Dispose();
                });
                alertDialogConfirmDelete.Create().Show();
            };
        }
コード例 #16
0
        private void ShowPedestrianInfoPopupWindow(PedestrianRequestModel request)
        {
            View pedestrianView = _viewCache.GetView(request.RequestAuthor);// _viewCache.GetCachedView(request.RequestAuthor);

            if (pedestrianView != null && !_pedestrianInfoPopups.ContainsKey(request))
            {
                PopupWindow pedestrianInfoPopup = new PopupWindow(_context.LayoutInflater.Inflate(Resource.Layout.PedestrianPopupDetailsLayout, null), 100, 100);
                _pedestrianInfoPopups.Add(request, pedestrianInfoPopup);
                pedestrianInfoPopup.SetBackgroundDrawable(_context.Resources.GetDrawable(Resource.Drawable.PedestrianInfoPopup));
                HookModelToDetailsPopupWindow(pedestrianInfoPopup, request);
                pedestrianInfoPopup.ShowAsDropDown(pedestrianView, -32, 0);
                pedestrianInfoPopup.Update();
            }
        }
コード例 #17
0
ファイル: MenuView.cs プロジェクト: XamarinGuru/MyFlexiPark
        protected override void OnCreate(Bundle bundle)
        {
            OverridePendingTransition(Resource.Animation.slide_in_right, Resource.Animation.slide_out_left);
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.MenuView);
            ViewModel.View = this;
            layoutInflater = (LayoutInflater)BaseContext.GetSystemService(LayoutInflaterService);
            popupView      = layoutInflater.Inflate(Resource.Layout.ParkMeView, null);

            popupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.MatchParent,
                                          ViewGroup.LayoutParams.MatchParent);

            popupWindow.AnimationStyle = Resource.Style.DialogAnimation;

            popupWindow.OutsideTouchable = true;
            popupWindow.Focusable        = true;

            popupWindow.SetBackgroundDrawable(new ColorDrawable(Color.Transparent));

            ParkMeNow = popupView.FindViewById <FlexyPark.UI.Droid.Controls.TextRegular>(Resource.Id.ParkMeNow);

            ParkMeLater = popupView.FindViewById <FlexyPark.UI.Droid.Controls.TextRegular>(Resource.Id.ParkMeLater);

            LinearLayout linearLayout = popupView.FindViewById <LinearLayout>(Resource.Id.llfullscreen);

            linearLayout.Click += (sender, args) => { popupWindow.Dismiss(); };

            SetButtonEffectsByViews(new List <View>()
            {
                ParkMeNow,
                ParkMeLater
            });

            ParkMeNow.Text   = Mvx.Resolve <ICacheService>().TextSource.GetText("NowText");
            ParkMeLater.Text = Mvx.Resolve <ICacheService>().TextSource.GetText("LaterText");


            ParkMeNow.Click   += (sender, args) => { ViewModel.ParkMeNow(); };
            ParkMeLater.Click += (sender, args) => { ViewModel.ParkMeLater(); };

            SetButtonEffects(new List <int>()
            {
                Resource.Id.llParkMe,
                Resource.Id.llMyOwnParking,
                Resource.Id.llCredits,
                Resource.Id.llReservations,
                Resource.Id.ivSetting,
            });
        }
コード例 #18
0
        public PopupWindow CreateDbPopup(string action)
        {
            popUp                  = new PopupWindow(Activity.CurrentFocus);
            popUp.ContentView      = popupView;
            popUp.Width            = ViewGroup.LayoutParams.MatchParent;
            popUp.Height           = ViewGroup.LayoutParams.WrapContent;
            popUp.OutsideTouchable = true;
            popUp.SetBackgroundDrawable(new ColorDrawable(Color.LightGray));
            popUp.Focusable = true;
            popUp.Update();
            //----------------------------
            actionButton    = popupView.FindViewById <Button>(Resource.Id.dbActionButton);
            editName        = popupView.FindViewById <EditText>(Resource.Id.dbAddEditName);
            editDescription = popupView.FindViewById <TextInputEditText>(Resource.Id.dbAddEditDescr);
            isActive        = popupView.FindViewById <Switch>(Resource.Id.dbAddIsActiveSwitch);

            actionButton.Click += delegate
            {
                actionButton.Enabled = false;
                if (editName.Text.Trim(' ') != "" || editDescription.Text.Trim(' ') != "")
                {
                    SomeEntity se = new SomeEntity()
                    {
                        Name        = editName.Text,
                        Description = editDescription.Text,
                        IsActive    = isActive.Checked,
                        Updated     = DateTime.Now
                    };
                    if (action == "ADD")
                    {
                        dbConnection.Insert(se);
                    }
                    else
                    {
                        se.Id = tempID;
                        dbConnection.Update(se);
                    }
                    popUp.Dismiss();
                    FillListFromDb();
                }
                else
                {
                    Toast.MakeText(Context, "Fill the fields!", ToastLength.Short).Show();
                }
                actionButton.Enabled = true;
            };
            actionButton.Text = action;
            return(popUp);
        }
コード例 #19
0
ファイル: Popup.cs プロジェクト: daviddw/Kinsky
        public void Show()
        {
            PopupManager.Add(this);
            PopupContent contents = GetContent();

            iPopup = new PopupWindow(contents.Content);
            iPopup.SetBackgroundDrawable(new BitmapDrawable());
            iPopup.Width            = contents.Width;
            iPopup.Height           = contents.Height;
            iPopup.Touchable        = true;
            iPopup.Focusable        = true;
            iPopup.OutsideTouchable = true;
            iPopup.DismissEvent    += DismissEventHandler;
            iPopup.ShowAtLocation(iAnchor, (int)Android.Views.GravityFlags.NoGravity, contents.X, contents.Y);
        }
コード例 #20
0
        private void OnPopupInfoButtonClicked(object tag)
        {
            Popup popup = (Popup)tag;
            // Create a popupviewer and show it in a PopupWindow
            var         popupViewer = new UI.Controls.PopupViewer(ApplicationContext);
            PopupWindow window      = new PopupWindow(ApplicationContext)
            {
                ContentView = popupViewer,
            };

            window.SetBackgroundDrawable(new Android.Graphics.Drawables.ColorDrawable(Android.Graphics.Color.White));
            window.OutsideTouchable = true;
            window.Touchable        = true;
            popupViewer.SetPadding(20, 20, 20, 20);
            popupViewer.PopupManager = new PopupManager(popup);
            window.ShowAtLocation(mapView, Android.Views.GravityFlags.Bottom, 0, 0);
        }
コード例 #21
0
        void PreShow()
        {
            if (_rootView == null)
            {
                throw new NullReferenceException("SetContentView was not called with a view to display.");
            }

            _window.SetBackgroundDrawable(Background ?? new BitmapDrawable());

            // ReSharper disable AccessToStaticMemberViaDerivedType
            _window.Width  = WindowManagerLayoutParams.WrapContent;
            _window.Height = WindowManagerLayoutParams.WrapContent;
            // ReSharper restore AccessToStaticMemberViaDerivedType
            _window.Touchable        = true;
            _window.Focusable        = true;
            _window.OutsideTouchable = true;
            _window.ContentView      = _rootView;
        }
コード例 #22
0
        public void ShowPopup(string content, string title)
        {
            View popupView = LayoutInflater.Inflate(Resource.Layout.MarkdownExtendedCardView, null);

            PopupWindow popupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);

            // If the PopupWindow should be focusable
            popupWindow.Focusable = (true);
            popupWindow.SetBackgroundDrawable(new Android.Graphics.Drawables.ColorDrawable(Android.Graphics.Color.Transparent));

            var fullMarkdownTextView = popupView.FindViewById <MarkdownView>(Resource.Id.FullMarkdownView);

            fullMarkdownTextView.LoadMarkdown(content, "file:///android_asset/github-markdown.css");

            // Using location, the PopupWindow will be displayed right under anchorView
            popupWindow.ShowAtLocation(Window.DecorView, GravityFlags.NoGravity,
                                       0, 0);
        }
コード例 #23
0
        public static PopupWindow PopupWindowWithText(Context context, int contentViewLayoutId, int tooltipTextViewId, string tooltipTextString)
        {
            Ensure.Argument.IsNotNull(context, nameof(context));
            Ensure.Argument.IsNotNull(tooltipTextViewId, nameof(tooltipTextViewId));
            Ensure.Argument.IsNotZero(tooltipTextViewId, nameof(tooltipTextViewId));
            Ensure.Argument.IsNotNullOrEmpty(tooltipTextString, nameof(tooltipTextString));

            var popupWindow            = new PopupWindow(context);
            var popupWindowContentView = LayoutInflater.From(context).Inflate(contentViewLayoutId, null, false);
            var tooltipTextView        = popupWindowContentView.FindViewById <TextView>(tooltipTextViewId);

            if (tooltipTextView == null)
            {
                throw new AndroidRuntimeException("The tooltipTextViewId must be present and must be a TextView");
            }

            tooltipTextView.Text    = tooltipTextString;
            popupWindow.ContentView = popupWindowContentView;
            popupWindow.SetBackgroundDrawable(null);
            return(popupWindow);
        }
コード例 #24
0
        private void InitPopupWindow()
        {
            LayoutInflater inflater = LayoutInflater.From(Activity);
            //var popView = inflater.inflate(R.layout.popupwindow_content, null);
            var popView = inflater.Inflate(Resource.Layout.GuardianPopupWindowLayout, null);

            var ll_bindGuardian  = popView.FindViewById <LinearLayout> (Resource.Id.ll_bindGuardian);
            var ll_applyGuardian = popView.FindViewById <LinearLayout> (Resource.Id.ll_ApplyGuardian);

            //guardianPopupWindow = new PopupWindow (popView,Android.Widget.LinearLayout.LayoutParams.WrapContent,Android.Widget.LinearLayout.LayoutParams.WrapContent);
            guardianPopupWindow = new PopupWindow(popView, 600, 290);
            var m = Resources.DisplayMetrics.Density;

            guardianPopupWindow.OutsideTouchable = true;
            guardianPopupWindow.Focusable        = true;
            guardianPopupWindow.SetBackgroundDrawable(new ColorDrawable());

            guardianPopupWindow.AnimationStyle = Resource.Style.AnimationPreview;

            guardianPopupWindow.ShowAsDropDown(ll_actionBar, -30, 1, GravityFlags.Right | GravityFlags.Top);

            guardianPopupWindow.DismissEvent += (sender, e) =>
            {
                BackgroundAlpha(1f);
            };

            ll_bindGuardian.Click += (sender, e) =>
            {
                //绑定监护人
                guardianPopupWindow.Dismiss();
                Activity.StartActivity(typeof(BindGuardianActivity));
            };
            ll_applyGuardian.Click += (sender, e) =>
            {
                //监护人申请
                guardianPopupWindow.Dismiss();
                Activity.StartActivity(typeof(GuardianApplyActivity));
            };
        }
コード例 #25
0
        public void ShowAsDropDown(View anchor, int x, int y, int selectedFilterId = -1)
        {
            if (popup == null)
            {
                var view = host.LayoutInflater.Inflate(Resource.Layout.contentpage_searchfilter_popup, null);
                tvFilterAll             = view.FindViewById <TextView>(Resource.Id.tvFilterAll);
                tvFilterLegislation     = view.FindViewById <TextView>(Resource.Id.tvFilterLegislation);
                tvFilterCommentary      = view.FindViewById <TextView>(Resource.Id.tvFilterCommentary);
                tvFilterFormsPrecedents = view.FindViewById <TextView>(Resource.Id.tvFilterFormsPrecedents);

                tvFilterAll.Click             += OnFilterItemClicked;
                tvFilterLegislation.Click     += OnFilterItemClicked;
                tvFilterCommentary.Click      += OnFilterItemClicked;
                tvFilterFormsPrecedents.Click += OnFilterItemClicked;

                popup = new PopupWindow(
                    view,
                    ViewGroup.LayoutParams.WrapContent,
                    ViewGroup.LayoutParams.WrapContent,
                    true);
                popup.SetBackgroundDrawable(new ColorDrawable(Color.Rgb(255, 255, 255)));
                popup.OutsideTouchable = true;
            }

            if (selectedFilterId >= 0)
            {
                SetFilter(selectedFilterId);
            }

            if (popup.IsShowing)
            {
                return;
            }

            popup.ShowAsDropDown(anchor, x, y);
        }
コード例 #26
0
        public WordPopup(AnnotationActivity activity)
        {
            mContext = activity;
            mWindow  = new PopupWindow(mContext);
            if (Build.VERSION.SdkInt >= BuildVersionCodes.Honeycomb)
            {
                mWindow.SoftInputMode = SoftInput.AdjustNothing;
            }
            mWindowManager = activity.GetSystemService(Context.WindowService).JavaCast <IWindowManager>();
            history        = new List <int>();

            LayoutInflater inflater = (LayoutInflater)mContext.GetSystemService(Context.LayoutInflaterService);

            mRootView               = inflater.Inflate(Resource.Layout.Popup, null);
            mBubble                 = (LinearLayout)mRootView.FindViewById(Resource.Id.bubble);
            mScroll                 = (ScrollView)mRootView.FindViewById(Resource.Id.scroller);
            mArrowDown              = (ImageView)mRootView.FindViewById(Resource.Id.arrow_down);
            mArrowUp                = (ImageView)mRootView.FindViewById(Resource.Id.arrow_up);
            mChars                  = (TextView)mRootView.FindViewById(Resource.Id.charsText);
            mChars.LinksClickable   = true;
            mChars.MovementMethod   = LinkMovementMethod.Instance;
            mContent                = (TextView)mRootView.FindViewById(Resource.Id.content);
            mContent.LinksClickable = true;
            mContent.MovementMethod = LinkMovementMethod.Instance;
            mBookmark               = (TextView)mRootView.FindViewById(Resource.Id.bookmarkTitle);

            this.Configure(mContext);

            mWindow.SetBackgroundDrawable(new BitmapDrawable());
            mWindow.Width            = ViewGroup.LayoutParams.WrapContent;
            mWindow.Height           = ViewGroup.LayoutParams.WrapContent;
            mWindow.Touchable        = true;
            mWindow.Focusable        = false;
            mWindow.OutsideTouchable = false;
            mWindow.ContentView      = mRootView;

            Button copyButton = (Button)mRootView.FindViewById(Resource.Id.charsCopy);

            copyButton.Touch += Button_Touch;
            copyButton.Click += CopyButton_Click;

            splitButton        = (Button)mRootView.FindViewById(Resource.Id.button_split);
            splitButton.Touch += Button_Touch;
            splitButton.Click += SplitButton_Click;

            Button starButton = (Button)mRootView.FindViewById(Resource.Id.button_star);

            starButton.Touch += Button_Touch;
            starButton.Click += StarButton_Click;

            bookmarkButton        = (Button)mRootView.FindViewById(Resource.Id.button_bookmark);
            bookmarkButton.Touch += Button_Touch;
            bookmarkButton.Click += BookmarkButton_Click;

            Button shareButton = (Button)mRootView.FindViewById(Resource.Id.button_share);

            shareButton.Touch += Button_Touch;
            shareButton.Click += ShareButton_Click;

            LinearLayout popupButtons = (LinearLayout)mRootView.FindViewById(Resource.Id.popupButtons);

            Dictionaries.DictInfo[] dicts = Dictionaries.DictList;
            PackageManager          pm    = mContext.PackageManager;

            foreach (Dictionaries.DictInfo dict in dicts)
            {
                bool installed = Dictionaries.IsPackageInstalled(pm, dict.packageName);
                if (installed)
                {
                    Button dictBtn = new Button(mContext);
                    dictBtn.Text     = dict.id;
                    dictBtn.TextSize = 20;
                    dictBtn.SetTextColor(Color.ParseColor("#99333333"));
                    //dictBtn.Tag = dict;
                    dictBtn.SetPadding((int)(10 * scale), (int)(2 * scale), 0, (int)(2 * scale));
                    dictBtn.SetBackgroundColor(Color.Transparent);
                    dictBtn.SetMinimumWidth(0);
                    dictBtn.SetMinWidth(0);
                    dictBtn.SetMinimumHeight(0);
                    dictBtn.SetMinHeight(0);
                    dictBtn.SetSingleLine(true);
                    dictBtn.Touch += Button_Touch;
                    popupButtons.AddView(dictBtn);
                    dictBtn.Click += DictBtn_Click;
                }
            }
        }
コード例 #27
0
        public void OnClick(View v)
        {
            if (v.Id == Resource.Id.tv_year)
            {
                #region Quarter
                if (quarterList != null && quarterList.Any())
                {
                    if (popYear == null)
                    {
                        View                 popViwe1  = layoutInflater.Inflate(Resource.Layout.popup_select1, null);
                        ListView             listview1 = popViwe1.FindViewById <ListView>(Resource.Id.lv);
                        QuarterSelectAdapter adaptera  = new QuarterSelectAdapter(CurrActivity, quarterList);
                        adaptera.SetSelectedValue(searchQuarter.QuarterName);
                        listview1.Adapter = adaptera;

                        popYear                  = new PopupWindow(popViwe1, ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);
                        popYear.Touchable        = true;
                        popYear.Focusable        = true;
                        popYear.OutsideTouchable = false;
                        popYear.SetBackgroundDrawable(new BitmapDrawable());

                        popYear.DismissEvent += (sender, e) =>
                        {
                            tv_year.SetTextColor(new Color(ContextCompat.GetColor(CurrActivity, Resource.Color.textColorPrimary)));
                            var arrowDown = AppUtils.GetDrawable(CurrActivity, Resource.Drawable.arrow_down);
                            arrowDown.SetBounds(0, 0, arrowDown.MinimumWidth, arrowDown.MinimumHeight);
                            tv_year.SetCompoundDrawables(null, null, arrowDown, null);
                        };
                        //每一行的点击事件
                        listview1.ItemClick += (sender, e) =>
                        {
                            searchQuarter = this.quarterList[e.Position];
                            tv_year.Text  = searchQuarter.QuarterName;

                            popYear.Dismiss();

                            adaptera.SetSelectedValue(searchQuarter.QuarterName);
                            adaptera.NotifyDataSetChanged();

                            BindData();
                        };
                    }
                    if (!popYear.IsShowing)
                    {
                        tv_year.SetTextColor(new Color(ContextCompat.GetColor(CurrActivity, Resource.Color.textColorHigh)));
                        var arrowDownOn = AppUtils.GetDrawable(CurrActivity, Resource.Drawable.arrow_down_on);
                        arrowDownOn.SetBounds(0, 0, arrowDownOn.MinimumWidth, arrowDownOn.MinimumHeight);
                        tv_year.SetCompoundDrawables(null, null, arrowDownOn, null);

                        if ((int)(Build.VERSION.SdkInt) >= 24)
                        {
                            int[] a = new int[2];
                            v.GetLocationInWindow(a);
                            popYear.ShowAtLocation(this.Activity.Window.DecorView, GravityFlags.NoGravity, 0, a[1] + v.Height + AppUtils.dip2px(CurrActivity, 11));
                        }
                        else
                        {
                            popYear.ShowAsDropDown(v, 0, AppUtils.dip2px(CurrActivity, 11));
                        }
                    }
                }
                #endregion
            }
            else if (v.Id == Resource.Id.tv_district)
            {
                #region Distirct
                if (districtList != null && districtList.Any())
                {
                    if (popDistrict == null)
                    {
                        View     popViwe3              = layoutInflater.Inflate(Resource.Layout.popup_select1, null);
                        ListView listview3             = popViwe3.FindViewById <ListView>(Resource.Id.lv);
                        DistrictSelectAdapter adaptera = new DistrictSelectAdapter(CurrActivity, districtList);
                        adaptera.SetSelectedValue(searchDistrict);
                        listview3.Adapter = adaptera;

                        popDistrict                  = new PopupWindow(popViwe3, ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);
                        popDistrict.Touchable        = true;
                        popDistrict.Focusable        = true;
                        popDistrict.OutsideTouchable = true;;
                        popDistrict.SetBackgroundDrawable(new BitmapDrawable());

                        popDistrict.DismissEvent += (sender, e) =>
                        {
                            tv_district.SetTextColor(new Color(ContextCompat.GetColor(CurrActivity, Resource.Color.textColorPrimary)));
                            var arrowDown = AppUtils.GetDrawable(CurrActivity, Resource.Drawable.arrow_down);
                            arrowDown.SetBounds(0, 0, arrowDown.MinimumWidth, arrowDown.MinimumHeight);
                            tv_district.SetCompoundDrawables(null, null, arrowDown, null);
                        };
                        //每一行的点击事件
                        listview3.ItemClick += (sender, e) =>
                        {
                            searchDistrict   = this.districtList[e.Position];
                            tv_district.Text = searchDistrict;

                            popDistrict.Dismiss();

                            adaptera.SetSelectedValue(searchDistrict);
                            adaptera.NotifyDataSetChanged();

                            BindData();
                        };
                    }
                    if (!popDistrict.IsShowing)
                    {
                        tv_district.SetTextColor(new Color(ContextCompat.GetColor(CurrActivity, Resource.Color.textColorHigh)));
                        var arrowDownOn = AppUtils.GetDrawable(CurrActivity, Resource.Drawable.arrow_down_on);
                        arrowDownOn.SetBounds(0, 0, arrowDownOn.MinimumWidth, arrowDownOn.MinimumHeight);
                        tv_district.SetCompoundDrawables(null, null, arrowDownOn, null);

                        if ((int)(Build.VERSION.SdkInt) >= 24)
                        {
                            int[] a = new int[2];
                            v.GetLocationInWindow(a);
                            popDistrict.ShowAtLocation(this.Activity.Window.DecorView, GravityFlags.NoGravity, 0, a[1] + v.Height + AppUtils.dip2px(CurrActivity, 11));
                        }
                        else
                        {
                            popDistrict.ShowAsDropDown(v, 0, AppUtils.dip2px(CurrActivity, 11));
                        }
                    }
                }
                #endregion
            }
            else if (v.Id == Resource.Id.tv_category)
            {
                #region Category
                if (categoryList != null && categoryList.Any())
                {
                    if (popCategory == null)
                    {
                        View                popViwe3  = layoutInflater.Inflate(Resource.Layout.popup_select1, null);
                        ListView            listview3 = popViwe3.FindViewById <ListView>(Resource.Id.lv);
                        CourseSelectAdapter adaptera  = new CourseSelectAdapter(CurrActivity, categoryList);
                        adaptera.SetSelectedValue(searchCagetory);
                        listview3.Adapter = adaptera;

                        popCategory                  = new PopupWindow(popViwe3, ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);
                        popCategory.Touchable        = true;
                        popCategory.Focusable        = true;
                        popCategory.OutsideTouchable = true;;
                        popCategory.SetBackgroundDrawable(new BitmapDrawable());

                        popCategory.DismissEvent += (sender, e) =>
                        {
                            tv_cagetory.SetTextColor(new Color(ContextCompat.GetColor(CurrActivity, Resource.Color.textColorPrimary)));
                            var arrowDown = AppUtils.GetDrawable(CurrActivity, Resource.Drawable.arrow_down);
                            arrowDown.SetBounds(0, 0, arrowDown.MinimumWidth, arrowDown.MinimumHeight);
                            tv_cagetory.SetCompoundDrawables(null, null, arrowDown, null);
                        };

                        listview3.ItemClick += (sender, e) =>
                        {
                            searchCagetory   = this.categoryList[e.Position];
                            tv_cagetory.Text = searchCagetory;

                            popCategory.Dismiss();

                            adaptera.SetSelectedValue(searchCagetory);
                            adaptera.NotifyDataSetChanged();

                            BindData();
                        };
                    }
                    if (!popCategory.IsShowing)
                    {
                        tv_cagetory.SetTextColor(new Color(ContextCompat.GetColor(CurrActivity, Resource.Color.textColorHigh)));
                        var arrowDownOn = AppUtils.GetDrawable(CurrActivity, Resource.Drawable.arrow_down_on);
                        arrowDownOn.SetBounds(0, 0, arrowDownOn.MinimumWidth, arrowDownOn.MinimumHeight);
                        tv_cagetory.SetCompoundDrawables(null, null, arrowDownOn, null);

                        if ((int)(Build.VERSION.SdkInt) >= 24)
                        {
                            int[] a = new int[2];
                            v.GetLocationInWindow(a);
                            popCategory.ShowAtLocation(this.Activity.Window.DecorView, GravityFlags.NoGravity, 0, a[1] + v.Height + AppUtils.dip2px(CurrActivity, 11));
                        }
                        else
                        {
                            popCategory.ShowAsDropDown(v, 0, AppUtils.dip2px(CurrActivity, 11));
                        }
                    }
                }
                #endregion
            }
        }
コード例 #28
0
        public void ShowGrade(View v)
        {
            if (gradeList != null && gradeList.Any())
            {
                if (popGrade == null)
                {
                    View   popViwe2 = LayoutInflater.Inflate(Resource.Layout.popup_grade, null);
                    Button btnOk    = popViwe2.FindViewById <Button>(Resource.Id.btn_ok);

                    var screenWidth  = Resources.DisplayMetrics.WidthPixels;
                    var wrapperWidth = screenWidth - AppUtils.dip2px(CurrActivity, 24);
                    var itemWidth    = (int)Math.Round((wrapperWidth / 4) * 0.8);
                    var marginRight  = (wrapperWidth - itemWidth * 4) / 3;

                    var tvAll = popViwe2.FindViewById <TextView>(Resource.Id.tv_all);
                    ViewGroup.LayoutParams tvallParams = tvAll.LayoutParameters;
                    tvallParams.Width      = itemWidth;
                    tvAll.LayoutParameters = tvallParams;
                    if (searchGradeList.Count == gradeList.Count)
                    {
                        tvAll.Background = AppUtils.GetDrawable(CurrActivity, Resource.Drawable.textview_bg_on);
                        tvAll.SetTextColor(new Color(ContextCompat.GetColor(CurrActivity, Resource.Color.textColorHigh)));
                    }
                    else
                    {
                        tvAll.Background = AppUtils.GetDrawable(CurrActivity, Resource.Drawable.textview_bg);
                        tvAll.SetTextColor(new Color(ContextCompat.GetColor(CurrActivity, Resource.Color.textColorSecond)));
                    }

                    GridLayout gridlayout_1 = popViwe2.FindViewById <GridLayout>(Resource.Id.gridlayout_1);
                    for (var i = 0; i < gradeList.Count; i++)
                    {
                        TextView tvGrade   = new TextView(CurrActivity);
                        var      itemGrade = gradeList[i];
                        GridLayout.LayoutParams gradeParams = new GridLayout.LayoutParams();
                        gradeParams.Width = itemWidth;

                        if (i % 4 != 3)
                        {
                            gradeParams.RightMargin = marginRight;
                        }
                        gradeParams.TopMargin    = AppUtils.dip2px(CurrActivity, 5);
                        gradeParams.BottomMargin = AppUtils.dip2px(CurrActivity, 5);
                        tvGrade.LayoutParameters = gradeParams;
                        tvGrade.Text             = itemGrade;
                        tvGrade.TextSize         = 14;
                        tvGrade.Gravity          = GravityFlags.Center;
                        tvGrade.SetPadding(0, AppUtils.dip2px(CurrActivity, 5), 0, AppUtils.dip2px(CurrActivity, 5));
                        if (searchGradeList.Contains(itemGrade))
                        {
                            tvGrade.Background = AppUtils.GetDrawable(CurrActivity, Resource.Drawable.textview_bg_on);
                            tvGrade.SetTextColor(new Color(ContextCompat.GetColor(CurrActivity, Resource.Color.textColorHigh)));
                        }
                        else
                        {
                            tvGrade.Background = AppUtils.GetDrawable(CurrActivity, Resource.Drawable.textview_bg);
                            tvGrade.SetTextColor(new Color(ContextCompat.GetColor(CurrActivity, Resource.Color.textColorSecond)));
                        }

                        gridlayout_1.AddView(tvGrade);

                        #region tvGrade.Click
                        tvGrade.Click += (sender, e) =>
                        {
                            if (!searchGradeList.Contains(itemGrade))
                            {
                                searchGradeList.Add(itemGrade);

                                tvGrade.SetTextColor(new Color(ContextCompat.GetColor(CurrActivity, Resource.Color.textColorHigh)));
                                tvGrade.Background = AppUtils.GetDrawable(CurrActivity, Resource.Drawable.textview_bg_on);
                            }
                            else
                            {
                                searchGradeList.Remove(itemGrade);

                                tvGrade.SetTextColor(new Color(ContextCompat.GetColor(CurrActivity, Resource.Color.textColorSecond)));
                                tvGrade.Background = AppUtils.GetDrawable(CurrActivity, Resource.Drawable.textview_bg);

                                tvAll.SetTextColor(new Color(ContextCompat.GetColor(CurrActivity, Resource.Color.textColorSecond)));
                                tvAll.Background = AppUtils.GetDrawable(CurrActivity, Resource.Drawable.textview_bg);
                            }

                            //控制全部年级按钮颜色
                            if (gradeList.Count == searchGradeList.Count)
                            {
                                tvAll.SetTextColor(new Color(ContextCompat.GetColor(CurrActivity, Resource.Color.textColorHigh)));
                                tvAll.Background = AppUtils.GetDrawable(CurrActivity, Resource.Drawable.textview_bg_on);
                            }
                            //控制确定按钮是否可用
                            if (searchGradeList.Count == 0)
                            {
                                btnOk.Enabled = false;
                                btnOk.SetBackgroundResource(Resource.Drawable.button_bg_disabled);
                            }
                            else
                            {
                                btnOk.Enabled = true;
                                btnOk.SetBackgroundResource(Resource.Drawable.button_bg);
                            }
                        };

                        #endregion
                    }
                    #region tvAll.Click
                    tvAll.Click += (sender, e) =>
                    {
                        if (tvAll.CurrentTextColor == ContextCompat.GetColor(CurrActivity, Resource.Color.textColorHigh))
                        {
                            tvAll.SetTextColor(new Color(ContextCompat.GetColor(CurrActivity, Resource.Color.textColorSecond)));
                            tvAll.Background = AppUtils.GetDrawable(CurrActivity, Resource.Drawable.textview_bg);

                            for (var i = 0; i < gridlayout_1.ChildCount; i++)
                            {
                                var tv = (TextView)gridlayout_1.GetChildAt(i);
                                tv.SetTextColor(new Color(ContextCompat.GetColor(CurrActivity, Resource.Color.textColorSecond)));
                                tv.Background = AppUtils.GetDrawable(CurrActivity, Resource.Drawable.textview_bg);
                            }
                            searchGradeList = new List <string>();
                        }
                        else
                        {
                            tvAll.SetTextColor(new Color(ContextCompat.GetColor(CurrActivity, Resource.Color.textColorHigh)));
                            tvAll.Background = AppUtils.GetDrawable(CurrActivity, Resource.Drawable.textview_bg_on);

                            for (var i = 0; i < gridlayout_1.ChildCount; i++)
                            {
                                var tv = (TextView)gridlayout_1.GetChildAt(i);
                                tv.SetTextColor(new Color(ContextCompat.GetColor(CurrActivity, Resource.Color.textColorHigh)));
                                tv.Background = AppUtils.GetDrawable(CurrActivity, Resource.Drawable.textview_bg_on);
                            }
                            searchGradeList = new List <string>(gradeList.ToArray());
                        }

                        //控制确定按钮是否可用
                        if (searchGradeList.Count == 0)
                        {
                            btnOk.Enabled = false;
                            btnOk.SetBackgroundResource(Resource.Drawable.button_bg_disabled);
                        }
                        else
                        {
                            btnOk.Enabled = true;
                            btnOk.SetBackgroundResource(Resource.Drawable.button_bg);
                        }
                    };
                    #endregion

                    #region btnOK.Click
                    btnOk.Click += (sender, e) =>
                    {
                        popGrade.Dismiss();
                        var selectedgrade = "全部年级";
                        if (searchGradeList.Count != gradeList.Count)
                        {
                            selectedgrade = string.Join(",", searchGradeList.ToArray());
                        }

                        tv_grade.Text = selectedgrade;

                        BindData();
                    };
                    #endregion

                    popGrade                  = new PopupWindow(popViwe2, ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);
                    popGrade.Touchable        = true;
                    popGrade.Focusable        = true;
                    popGrade.OutsideTouchable = true;;
                    popGrade.SetBackgroundDrawable(new BitmapDrawable());

                    popGrade.DismissEvent += (sender, e) =>
                    {
                        tv_grade.SetTextColor(new Color(ContextCompat.GetColor(CurrActivity, Resource.Color.textColorPrimary)));
                        var arrowDown = AppUtils.GetDrawable(CurrActivity, Resource.Drawable.arrow_down);
                        arrowDown.SetBounds(0, 0, arrowDown.MinimumWidth, arrowDown.MinimumHeight);
                        tv_grade.SetCompoundDrawables(null, null, arrowDown, null);
                    };
                }
                if (!popGrade.IsShowing)
                {
                    tv_grade.SetTextColor(new Color(ContextCompat.GetColor(CurrActivity, Resource.Color.textColorHigh)));
                    var arrowDownOn = AppUtils.GetDrawable(CurrActivity, Resource.Drawable.arrow_down_on);
                    arrowDownOn.SetBounds(0, 0, arrowDownOn.MinimumWidth, arrowDownOn.MinimumHeight);
                    tv_grade.SetCompoundDrawables(null, null, arrowDownOn, null);


                    if ((int)(Build.VERSION.SdkInt) >= 24)
                    {
                        int[] a = new int[2];
                        v.GetLocationInWindow(a);
                        popGrade.ShowAtLocation(Window.DecorView, GravityFlags.NoGravity, 0, a[1] + v.Height + AppUtils.dip2px(CurrActivity, 11));
                    }
                    else
                    {
                        popGrade.ShowAsDropDown(v, 0, AppUtils.dip2px(CurrActivity, 11));
                    }
                }
            }
        }
コード例 #29
0
        /// <summary>
        /// 页面点击事件处理
        /// </summary>
        /// <param name="v">V.</param>
        public void OnClick(View v)
        {
            if (v.Id == Resource.Id.tv_btn1)
            {
                if (quarterList != null && quarterList.Any())
                {
                    if (popWin1 == null)
                    {
                        View                 popViwe1  = layoutInflater.Inflate(Resource.Layout.popup_select1, null);
                        ListView             listview1 = popViwe1.FindViewById <ListView>(Resource.Id.lv);
                        QuarterSelectAdapter adaptera  = new QuarterSelectAdapter(CurrActivity, quarterList);
                        adaptera.SetSelectedValue(searchQuarter.QuarterName);
                        listview1.Adapter = adaptera;

                        popWin1                  = new PopupWindow(popViwe1, ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);
                        popWin1.Touchable        = true;
                        popWin1.Focusable        = true;
                        popWin1.OutsideTouchable = false;
                        popWin1.SetBackgroundDrawable(new BitmapDrawable());

                        popWin1.DismissEvent += (sender, e) =>
                        {
                            tv_btn1.SetTextColor(new Color(ContextCompat.GetColor(CurrActivity, Resource.Color.textColorPrimary)));
                            var arrowDown = AppUtils.GetDrawable(CurrActivity, Resource.Drawable.arrow_down);
                            arrowDown.SetBounds(0, 0, arrowDown.MinimumWidth, arrowDown.MinimumHeight);
                            tv_btn1.SetCompoundDrawables(null, null, arrowDown, null);
                        };

                        listview1.ItemClick += (sender, e) =>
                        {
                            searchQuarter = this.quarterList[e.Position];
                            tv_btn1.Text  = searchQuarter.QuarterName;

                            popWin1.Dismiss();

                            adaptera.SetSelectedValue(searchQuarter.QuarterName);
                            adaptera.NotifyDataSetChanged();

                            //Toast.MakeText(CurrActivity, searchQuarter.QuarterName, ToastLength.Short).Show();
                            GetRenewInfoInGroup();
                        };
                    }
                    if (!popWin1.IsShowing)
                    {
                        tv_btn1.SetTextColor(new Color(ContextCompat.GetColor(CurrActivity, Resource.Color.textColorHigh)));
                        var arrowDownOn = AppUtils.GetDrawable(CurrActivity, Resource.Drawable.arrow_down_on);
                        arrowDownOn.SetBounds(0, 0, arrowDownOn.MinimumWidth, arrowDownOn.MinimumHeight);
                        tv_btn1.SetCompoundDrawables(null, null, arrowDownOn, null);

                        if ((int)(Build.VERSION.SdkInt) >= 24)
                        {
                            int[] a = new int[2];
                            v.GetLocationInWindow(a);
                            popWin1.ShowAtLocation(this.Activity.Window.DecorView, GravityFlags.NoGravity, 0, a[1] + v.Height + AppUtils.dip2px(CurrActivity, 11));
                        }
                        else
                        {
                            popWin1.ShowAsDropDown(v, 0, AppUtils.dip2px(CurrActivity, 11));
                        }
                    }
                }
            }
            else if (v.Id == Resource.Id.tv_btn2)
            {
                if (gradeList != null && gradeList.Any())
                {
                    if (popWin2 == null)
                    {
                        View   popViwe2 = layoutInflater.Inflate(Resource.Layout.popup_grade, null);
                        Button btnOk    = popViwe2.FindViewById <Button>(Resource.Id.btn_ok);

                        var screenWidth  = Resources.DisplayMetrics.WidthPixels;
                        var wrapperWidth = screenWidth - AppUtils.dip2px(CurrActivity, 24);
                        var itemWidth    = (int)Math.Round((wrapperWidth / 4) * 0.8);
                        var marginRight  = (wrapperWidth - itemWidth * 4) / 3;

                        var tvAll = popViwe2.FindViewById <TextView>(Resource.Id.tv_all);
                        ViewGroup.LayoutParams tvallParams = tvAll.LayoutParameters;
                        tvallParams.Width      = itemWidth;
                        tvAll.LayoutParameters = tvallParams;

                        GridLayout gridlayout_1 = popViwe2.FindViewById <GridLayout>(Resource.Id.gridlayout_1);
                        for (var i = 0; i < gradeList.Count; i++)
                        {
                            TextView tvGrade   = new TextView(CurrActivity);
                            var      itemGrade = gradeList[i];
                            GridLayout.LayoutParams gradeParams = new GridLayout.LayoutParams();
                            gradeParams.Width = itemWidth;
                            //parasBox.Height =
                            if (i % 4 != 3)
                            {
                                gradeParams.RightMargin = marginRight;
                            }
                            gradeParams.TopMargin    = AppUtils.dip2px(CurrActivity, 5);
                            gradeParams.BottomMargin = AppUtils.dip2px(CurrActivity, 5);
                            tvGrade.LayoutParameters = gradeParams;
                            tvGrade.Text             = itemGrade;
                            tvGrade.TextSize         = 14;
                            tvGrade.Gravity          = GravityFlags.Center;
                            tvGrade.Background       = AppUtils.GetDrawable(CurrActivity, Resource.Drawable.textview_bg_on);
                            tvGrade.SetPadding(0, AppUtils.dip2px(CurrActivity, 5), 0, AppUtils.dip2px(CurrActivity, 5));
                            tvGrade.SetTextColor(new Color(ContextCompat.GetColor(CurrActivity, Resource.Color.textColorHigh)));

                            gridlayout_1.AddView(tvGrade);

                            #region tvGrade.Click
                            tvGrade.Click += (sender, e) =>
                            {
                                if (!searchGradeList.Contains(itemGrade))
                                {
                                    searchGradeList.Add(itemGrade);

                                    tvGrade.SetTextColor(new Color(ContextCompat.GetColor(CurrActivity, Resource.Color.textColorHigh)));
                                    tvGrade.Background = AppUtils.GetDrawable(CurrActivity, Resource.Drawable.textview_bg_on);
                                }
                                else
                                {
                                    searchGradeList.Remove(itemGrade);

                                    tvGrade.SetTextColor(new Color(ContextCompat.GetColor(CurrActivity, Resource.Color.textColorSecond)));
                                    tvGrade.Background = AppUtils.GetDrawable(CurrActivity, Resource.Drawable.textview_bg);

                                    tvAll.SetTextColor(new Color(ContextCompat.GetColor(CurrActivity, Resource.Color.textColorSecond)));
                                    tvAll.Background = AppUtils.GetDrawable(CurrActivity, Resource.Drawable.textview_bg);
                                }

                                //控制全部年级按钮颜色
                                if (gradeList.Count == searchGradeList.Count)
                                {
                                    tvAll.SetTextColor(new Color(ContextCompat.GetColor(CurrActivity, Resource.Color.textColorHigh)));
                                    tvAll.Background = AppUtils.GetDrawable(CurrActivity, Resource.Drawable.textview_bg_on);
                                }
                                //控制确定按钮是否可用
                                if (searchGradeList.Count == 0)
                                {
                                    btnOk.Enabled = false;
                                    btnOk.SetBackgroundResource(Resource.Drawable.button_bg_disabled);
                                }
                                else
                                {
                                    btnOk.Enabled = true;
                                    btnOk.SetBackgroundResource(Resource.Drawable.button_bg);
                                }
                            };
                        }
                        #endregion

                        #region tvAll.Click
                        tvAll.Click += (sender, e) =>
                        {
                            if (tvAll.CurrentTextColor == ContextCompat.GetColor(CurrActivity, Resource.Color.textColorHigh))
                            {
                                tvAll.SetTextColor(new Color(ContextCompat.GetColor(CurrActivity, Resource.Color.textColorSecond)));
                                tvAll.Background = AppUtils.GetDrawable(CurrActivity, Resource.Drawable.textview_bg);

                                for (var i = 0; i < gridlayout_1.ChildCount; i++)
                                {
                                    var tv = (TextView)gridlayout_1.GetChildAt(i);
                                    tv.SetTextColor(new Color(ContextCompat.GetColor(CurrActivity, Resource.Color.textColorSecond)));
                                    tv.Background = AppUtils.GetDrawable(CurrActivity, Resource.Drawable.textview_bg);
                                }
                                searchGradeList = new List <string>();
                            }
                            else
                            {
                                tvAll.SetTextColor(new Color(ContextCompat.GetColor(CurrActivity, Resource.Color.textColorHigh)));
                                tvAll.Background = AppUtils.GetDrawable(CurrActivity, Resource.Drawable.textview_bg_on);

                                for (var i = 0; i < gridlayout_1.ChildCount; i++)
                                {
                                    var tv = (TextView)gridlayout_1.GetChildAt(i);
                                    tv.SetTextColor(new Color(ContextCompat.GetColor(CurrActivity, Resource.Color.textColorHigh)));
                                    tv.Background = AppUtils.GetDrawable(CurrActivity, Resource.Drawable.textview_bg_on);
                                }
                                searchGradeList = new List <string>(gradeList.ToArray());
                            }

                            //控制确定按钮是否可用
                            if (searchGradeList.Count == 0)
                            {
                                btnOk.Enabled = false;
                                btnOk.SetBackgroundResource(Resource.Drawable.button_bg_disabled);
                            }
                            else
                            {
                                btnOk.Enabled = true;
                                btnOk.SetBackgroundResource(Resource.Drawable.button_bg);
                            }
                        };
                        #endregion

                        #region btnOK.Click
                        btnOk.Click += (sender, e) =>
                        {
                            popWin2.Dismiss();
                            var selectedgrade = "全部年级";
                            if (searchGradeList.Count != gradeList.Count)
                            {
                                selectedgrade = string.Join(",", searchGradeList.ToArray());
                            }

                            tv_btn2.Text = selectedgrade;

                            GetRenewInfoInGroup();
                        };
                        #endregion

                        popWin2                  = new PopupWindow(popViwe2, ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);
                        popWin2.Touchable        = true;
                        popWin2.Focusable        = true;
                        popWin2.OutsideTouchable = true;;
                        popWin2.SetBackgroundDrawable(new BitmapDrawable());

                        popWin2.DismissEvent += (sender, e) =>
                        {
                            tv_btn2.SetTextColor(new Color(ContextCompat.GetColor(CurrActivity, Resource.Color.textColorPrimary)));
                            var arrowDown = AppUtils.GetDrawable(CurrActivity, Resource.Drawable.arrow_down);
                            arrowDown.SetBounds(0, 0, arrowDown.MinimumWidth, arrowDown.MinimumHeight);
                            tv_btn2.SetCompoundDrawables(null, null, arrowDown, null);
                        };
                    }
                    if (!popWin2.IsShowing)
                    {
                        tv_btn2.SetTextColor(new Color(ContextCompat.GetColor(CurrActivity, Resource.Color.textColorHigh)));
                        var arrowDownOn = AppUtils.GetDrawable(CurrActivity, Resource.Drawable.arrow_down_on);
                        arrowDownOn.SetBounds(0, 0, arrowDownOn.MinimumWidth, arrowDownOn.MinimumHeight);
                        tv_btn2.SetCompoundDrawables(null, null, arrowDownOn, null);


                        if ((int)(Build.VERSION.SdkInt) >= 24)
                        {
                            int[] a = new int[2];
                            v.GetLocationInWindow(a);
                            popWin2.ShowAtLocation(this.Activity.Window.DecorView, GravityFlags.NoGravity, 0, a[1] + v.Height + AppUtils.dip2px(CurrActivity, 11));
                        }
                        else
                        {
                            popWin2.ShowAsDropDown(v, 0, AppUtils.dip2px(CurrActivity, 11));
                        }
                    }
                }
            }
            else if (v.Id == Resource.Id.tv_btn3)
            {
                if (districtList != null && districtList.Any())
                {
                    if (popWin3 == null)
                    {
                        View     popViwe3              = layoutInflater.Inflate(Resource.Layout.popup_select1, null);
                        ListView listview3             = popViwe3.FindViewById <ListView>(Resource.Id.lv);
                        DistrictSelectAdapter adaptera = new DistrictSelectAdapter(CurrActivity, districtList);
                        adaptera.SetSelectedValue(searchDistrict);
                        listview3.Adapter = adaptera;

                        popWin3                  = new PopupWindow(popViwe3, ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);
                        popWin3.Touchable        = true;
                        popWin3.Focusable        = true;
                        popWin3.OutsideTouchable = true;;
                        popWin3.SetBackgroundDrawable(new BitmapDrawable());

                        popWin3.DismissEvent += (sender, e) =>
                        {
                            tv_btn3.SetTextColor(new Color(ContextCompat.GetColor(CurrActivity, Resource.Color.textColorPrimary)));
                            var arrowDown = AppUtils.GetDrawable(CurrActivity, Resource.Drawable.arrow_down);
                            arrowDown.SetBounds(0, 0, arrowDown.MinimumWidth, arrowDown.MinimumHeight);
                            tv_btn3.SetCompoundDrawables(null, null, arrowDown, null);
                        };

                        listview3.ItemClick += (sender, e) =>
                        {
                            searchDistrict = this.districtList[e.Position];
                            tv_btn3.Text   = searchDistrict;

                            popWin3.Dismiss();

                            adaptera.SetSelectedValue(searchDistrict);
                            adaptera.NotifyDataSetChanged();

                            //Toast.MakeText(CurrActivity, searchDistrict, ToastLength.Short).Show();
                            GetRenewInfoInGroup();
                        };
                    }
                    if (!popWin3.IsShowing)
                    {
                        tv_btn3.SetTextColor(new Color(ContextCompat.GetColor(CurrActivity, Resource.Color.textColorHigh)));
                        var arrowDownOn = AppUtils.GetDrawable(CurrActivity, Resource.Drawable.arrow_down_on);
                        arrowDownOn.SetBounds(0, 0, arrowDownOn.MinimumWidth, arrowDownOn.MinimumHeight);
                        tv_btn3.SetCompoundDrawables(null, null, arrowDownOn, null);

                        if ((int)(Build.VERSION.SdkInt) >= 24)
                        {
                            int[] a = new int[2];
                            v.GetLocationInWindow(a);
                            popWin3.ShowAtLocation(this.Activity.Window.DecorView, GravityFlags.NoGravity, 0, a[1] + v.Height + AppUtils.dip2px(CurrActivity, 11));
                        }
                        else
                        {
                            popWin3.ShowAsDropDown(v, 0, AppUtils.dip2px(CurrActivity, 11));
                        }
                    }
                }
            }
        }
コード例 #30
0
ファイル: PopupMenu.cs プロジェクト: dalyl/MicroBluer
        /// <summary>
        /// 显示popupWindow弹出框
        /// </summary>
        public static void ShowPopupWindows(Context context, View spinnerview, List <PopupMenuItem> mArrayList, PopupMenuSetting setting)
        {
            if (popupWindow != null)
            {
                if (popupWindow.IsShowing)
                {
                    popupWindow.Dismiss();
                    popupWindow = null;
                }
            }
            //一个自定义的布局,作为显示的内容
            View popupWindowView = LayoutInflater.From(context).Inflate(Resource.Layout.PopupMenuLayout, null);

            /// <summary>
            /// 在初始化contentView的时候,强制绘制contentView,并且马上初始化contentView的尺寸。
            /// 另外一个点需要注意:popwindow_layout.xml的根Layout必须为LinearLayout;如果为RelativeLayout的话,会导致程序崩溃。
            /// </summary>
            popupWindowView.Measure((int)MeasureSpecMode.Unspecified, (int)MeasureSpecMode.Unspecified);
            //用于获取单个列表项的高度【用于计算大于n个列表项的时候,列表的总高度值n * listitemView.getMeasuredHeight()】
            View listitemView = LayoutInflater.From(context).Inflate(Resource.Layout.PopupMenuItem, null);

            listitemView.Measure((int)MeasureSpecMode.Unspecified, (int)MeasureSpecMode.Unspecified);

            //列表
            RecyclerView mListView = (RecyclerView)popupWindowView.FindViewById(Resource.Id.menu_list);
            //设置布局管理器
            LinearLayoutManager linerLayoutManager = new LinearLayoutManager(context);

            mListView.SetLayoutManager(linerLayoutManager);

            PopupWindowMenuListAdapter mPopupMenuAdapter = new PopupWindowMenuListAdapter(context, mArrayList);

            mListView.SetAdapter(mPopupMenuAdapter);
            mPopupMenuAdapter.SetOnItemClickLitener(new AnonymousItemClickLitener(position => mArrayList[position].Click()));

            //实例化PopupWindow【宽度为自身宽度,高度为自身高度】
            //popupWindow = new PopupWindow(popupWindowView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            //设置当大于6个列表项的时候,设置列表总高度值为6个列表项的高度值
            if (mArrayList.Count <= 6)
            {
                popupWindow = new PopupWindow(popupWindowView, ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent);
                //popupWindow = new PopupWindow(popupWindowView, spinnerview.getMeasuredWidth(), ViewGroup.LayoutParams.WRAP_CONTENT);//spinnerview.getMeasuredWidth()用于设置跟依附的控件的宽度相等
            }
            else
            {
                popupWindow = new PopupWindow(popupWindowView, ViewGroup.LayoutParams.WrapContent, listitemView.MeasuredHeight * 6);
                //popupWindow = new PopupWindow(popupWindowView, spinnerview.getMeasuredWidth(), listitemView.getMeasuredHeight() * 6);//spinnerview.getMeasuredWidth()用于设置跟依附的控件的宽度相等
            }

            popupWindow.Touchable = true; //设置可以触摸
            popupWindow.Focusable = true; //代表可以允许获取焦点的,如果有输入框的话,可以聚焦

            //监听popWindow的隐藏时执行的操作--这个不错
            popupWindow.SetOnDismissListener(new AnonymousOnDismissListener());

            //下面两个参数是实现点击点击外面隐藏popupwindow的
            //这里设置显示PopuWindow之后在外面点击是否有效。如果为false的话,那么点击PopuWindow外面并不会关闭PopuWindow。当然这里很明显只能在Touchable下才能使用。不设置此项则下面的捕获window外touch事件就无法触发。
            popupWindow.OutsideTouchable = true;

            // 如果不设置PopupWindow的背景,无论是点击外部区域还是Back键都无法dismiss弹框
            // 我觉得这里是API的一个bug
            //方式一

            ColorDrawable dw = new ColorDrawable(new Color(0x00000000)); //设置背景为透明

            popupWindow.SetBackgroundDrawable(dw);

            //int xPos = - popupWindow.getWidth() / 2 + view.getWidth() / 2;//X轴的偏移值:xoff表示x轴的偏移,正值表示向右,负值表示向左;
            int xPos = 0; //X轴的偏移值:xoff表示x轴的偏移,正值表示向左,负值表示向右;
            int yPos = 0; //Y轴的偏移值相对某个控件的位置,有偏移;yoff表示相对y轴的偏移,正值是向下,负值是向上;

            //=======展现在控件的下方
            //相对于当前view进行位置设置
            popupWindow.ShowAsDropDown(spinnerview, xPos, yPos);
        }