Exemplo n.º 1
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
            }
        }
Exemplo n.º 2
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));
                        }
                    }
                }
            }
        }