Esempio n. 1
0
        void LayoutSideBySide()
        {
            var flyoutView = _flyoutView;

            if (MauiContext == null || _navigationRoot == null || flyoutView == null)
            {
                return;
            }

            if (_sideBySideView == null)
            {
                _sideBySideView = new LinearLayoutCompat(Context)
                {
                    Orientation      = LinearLayoutCompat.Horizontal,
                    LayoutParameters = new DrawerLayout.LayoutParams(
                        DrawerLayout.LayoutParams.MatchParent,
                        DrawerLayout.LayoutParams.MatchParent)
                };
            }

            if (_navigationRoot.Parent != _sideBySideView)
            {
                _navigationRoot.RemoveFromParent();

                var layoutParameters =
                    new LinearLayoutCompat.LayoutParams(
                        LinearLayoutCompat.LayoutParams.MatchParent,
                        LinearLayoutCompat.LayoutParams.MatchParent,
                        1);

                _sideBySideView.AddView(_navigationRoot, layoutParameters);
                UpdateDetailsFragmentView();
            }

            if (flyoutView.Parent != _sideBySideView)
            {
                // When the Flyout is acting as a flyout Android will set the Visibilty to GONE when it's off screen
                // This makes sure it's visible
                flyoutView.Visibility = ViewStates.Visible;
                flyoutView.RemoveFromParent();
                var layoutParameters =
                    new LinearLayoutCompat.LayoutParams(
                        (int)FlyoutWidth,
                        LinearLayoutCompat.LayoutParams.MatchParent,
                        0);

                _sideBySideView.AddView(flyoutView, 0, layoutParameters);
            }

            if (_sideBySideView.Parent != PlatformView)
            {
                DrawerLayout.AddView(_sideBySideView);
            }

            if (VirtualView is IToolbarElement te && te.Toolbar?.Handler is ToolbarHandler th)
            {
                th.SetupWithDrawerLayout(null);
            }
        }
Esempio n. 2
0
        void LayoutAsFlyout()
        {
            var flyoutView = _flyoutView;

            if (MauiContext == null || _navigationRoot == null || flyoutView == null)
            {
                return;
            }

            _sideBySideView?.RemoveAllViews();
            _sideBySideView?.RemoveFromParent();

            if (_navigationRoot.Parent != PlatformView)
            {
                _navigationRoot.RemoveFromParent();

                var layoutParameters =
                    new LinearLayoutCompat.LayoutParams(
                        LinearLayoutCompat.LayoutParams.MatchParent,
                        LinearLayoutCompat.LayoutParams.MatchParent);

                DrawerLayout.AddView(_navigationRoot, 0, layoutParameters);
            }

            UpdateDetailsFragmentView();

            if (flyoutView.Parent != PlatformView)
            {
                flyoutView.RemoveFromParent();

                var layoutParameters =
                    new DrawerLayout.LayoutParams(
                        (int)FlyoutWidth,
                        DrawerLayout.LayoutParams.MatchParent,
                        (int)GravityFlags.Start);

                // Flyout has to get added after the content otherwise clicking anywhere
                // on the flyout will cause it to close and gesture
                // recognizers inside the flyout won't fire
                DrawerLayout.AddView(flyoutView, layoutParameters);
            }

            DrawerLayout.CloseDrawer(flyoutView);

            if (VirtualView is IToolbarElement te && te.Toolbar?.Handler is ToolbarHandler th)
            {
                th.SetupWithDrawerLayout(DrawerLayout);
            }
        }
        private void LoadDaySelectorButtons(int type = 1)
        {
            layoutButtons = FindViewById <LinearLayout>(Resource.Id.layout_buttons);
            layoutButtons.RemoveAllViews();
            var layoutButtonParams = new LinearLayoutCompat.LayoutParams(
                (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 40, Resources.DisplayMetrics),
                (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 40, Resources.DisplayMetrics))
            {
                Width     = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 40, Resources.DisplayMetrics),
                Height    = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 40, Resources.DisplayMetrics),
                MarginEnd = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 5, Resources.DisplayMetrics)
            };
            int      dayIndex = ReturnDayIndex();
            DateTime baseDate = DateTime.Today;

//            var today = baseDate;
//            var yesterday = baseDate.AddDays(-1);
            DateTime thisWeekStart = baseDate.AddDays(-dayIndex);
//            var thisWeekEnd = thisWeekStart.AddDays(7).AddSeconds(-1);
//            var lastWeekStart = thisWeekStart.AddDays(-7);
//            var lastWeekEnd = thisWeekStart.AddSeconds(-1);
            DateTime thisMonthStart = baseDate.AddDays(1 - baseDate.Day);

//            var thisMonthEnd = thisMonthStart.AddMonths(1).AddSeconds(-1);
//            var lastMonthStart = thisMonthStart.AddMonths(-1);
//            var lastMonthEnd = thisMonthStart.AddSeconds(-1);

            switch (type)
            {
            case 1:
                GetDataForChart(thisWeekStart, _dataType == "BloodPressure");
                break;

            case 2:
                GetDataForChart(thisMonthStart, _dataType == "BloodPressure");
                break;

            case 3:
                GetDataForChart(new DateTime(DateTime.Now.Year, 1, 1), _dataType == "BloodPressure");
                break;

            default:
                return;
            }

            if (type != 3)
            {
                string[] days                = { "L", "M", "M", "J", "V", "S", "D" };
                int      dayOfMonth          = DateTime.Now.Day;
                int      numberOfDaysInMonth = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month);
                int      size                = type == 1 && type != 3 ? days.Length : numberOfDaysInMonth;

                var activeButton = new AppCompatButton(this);
                for (var i = 0; i < size; i++)
                {
                    bool            isActive = type == 1 && type != 3 ? i == dayIndex : i + 1 == dayOfMonth;
                    AppCompatButton btn      = DaySelectorButton(isActive);
                    btn.Id               = i + 1;
                    btn.Text             = type == 1 && type != 3 ? i < days.Length ? days[i] : i.ToString() : (i + 1).ToString();
                    btn.LayoutParameters = layoutButtonParams;
                    if (type == 1 && type != 3 && i > dayIndex)
                    {
                        btn.Enabled = false;
                        btn.SetTextColor(Resources.GetColor(Resource.Color.colorSecondary, Theme));
                    }
                    else
                    if (i + 1 > dayOfMonth)
                    {
                        btn.Enabled = false;
                        btn.SetTextColor(Resources.GetColor(Resource.Color.colorSecondary, Theme));
                    }
                    if (isActive)
                    {
                        activeButton = btn;
                    }
                    layoutButtons.AddView(btn);
                }

                if (type == 2)
                {
                    _scrollViewButtons.PostDelayed(delegate { _scrollViewButtons.SmoothScrollTo(activeButton.Left - 5, 0); }, 30);
                }
            }
            else
            {
                Drawable img = Resources.GetDrawable(Resource.Drawable.calendar_date, Theme);
                img.SetBounds(0, 0, 50, 50);
                var btn = new AppCompatButton(this)
                {
                    Id   = 1,
                    Text = "Data"
                           //Background = buttonBackgroundA,
                           //LayoutParameters = layoutButtonParams
                };
                btn.SetTextColor(Color.White);
                btn.Background = buttonBackgroundDatePicker;
                btn.SetAllCaps(false);
                btn.SetCompoundDrawables(img, null, null, null);
                btn.SetPadding((int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 8, Resources.DisplayMetrics),
                               (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 8, Resources.DisplayMetrics),
                               (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 8, Resources.DisplayMetrics),
                               (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 8, Resources.DisplayMetrics));

                btn.Click += (sender, args) =>
                {
                    var frag = SharingDatePickerFragment.NewInstance(delegate(DateTime time)
                    {
                        //_tbDate.Text = time.ToShortDateString();
                        _tvDate.Text = time.ToShortDateString();
                        switch (_dataType)
                        {
                        case "BloodPressure":
                            verticalScrollLinearLayout.RemoveAllViewsInLayout();
                            horizontalScrollLinearLayout.RemoveAllViewsInLayout();
                            LoadDataInScrollLayouts(time);
                            break;

                        case "BloodGlucose":
                            verticalScrollLinearLayout.RemoveAllViewsInLayout();
                            LoadDataInScrollLayouts(time, false);
                            break;
                        }
                    });
                    frag.Show(SupportFragmentManager, SharingDatePickerFragment.TAG);
                };
                layoutButtons.AddView(btn);
            }
        }
        private CardView CreateCard(Drawable image, string value, string measureType, string hour, LinearLayoutCompat.LayoutParams layoutParams)
        {
            var cardView = new CardView(this)
            {
                LayoutParameters = layoutParams
            };

            cardView.SetCardBackgroundColor(Resources.GetColor(Resource.Color.colorPrimaryDark, Theme));

            var rlContent = new RelativeLayout(this);
            var tvHour    = new TextView(this)
            {
                Id = 4
            };
            var tvBloodPressure = new TextView(this)
            {
                Id = 2
            };
            var tvMmHg = new TextView(this)
            {
                Id = 3
            };
            var imIcon = new ImageView(this)
            {
                Id = 1
            };

            var rlParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent,
                                                           ViewGroup.LayoutParams.WrapContent);
            var tvHourParams = new RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.WrapContent,
                ViewGroup.LayoutParams.WrapContent)
            {
                TopMargin = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 10, Resources.DisplayMetrics)
            };

            tvHourParams.AddRule(LayoutRules.AlignParentRight);

            var tvBloodPressureParams = new RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.WrapContent,
                ViewGroup.LayoutParams.WrapContent)
            {
                MarginStart = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 10, Resources.DisplayMetrics)
            };

            tvBloodPressureParams.AddRule(LayoutRules.AlignParentTop);
            tvBloodPressureParams.AddRule(LayoutRules.RightOf, imIcon.Id);

            var tvMmHgParams = new RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.WrapContent,
                ViewGroup.LayoutParams.WrapContent)
            {
                MarginStart = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 3, Resources.DisplayMetrics),
                TopMargin   = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 10, Resources.DisplayMetrics)
            };

            tvMmHgParams.AddRule(LayoutRules.RightOf, tvBloodPressure.Id);

            var tvIconParams = new RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.WrapContent,
                ViewGroup.LayoutParams.WrapContent)
            {
                Width     = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 30, Resources.DisplayMetrics),
                Height    = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 30, Resources.DisplayMetrics),
                TopMargin = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 3, Resources.DisplayMetrics)
            };

            rlContent.SetPadding((int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 16, Resources.DisplayMetrics),
                                 (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 16, Resources.DisplayMetrics),
                                 (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 16, Resources.DisplayMetrics),
                                 (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 16, Resources.DisplayMetrics));
            rlContent.LayoutParameters = rlParams;

            tvHour.LayoutParameters = tvHourParams;
            tvHour.Text             = hour;
            tvHour.SetTextSize(ComplexUnitType.Sp, 16);
            tvHour.SetTextColor(Color.White);

            tvBloodPressure.LayoutParameters = tvBloodPressureParams;
            tvBloodPressure.Text             = value;
            tvBloodPressure.SetTextSize(ComplexUnitType.Sp, 28);
            tvBloodPressure.SetTextColor(Resources.GetColor(Resource.Color.accent, Theme));
            tvBloodPressure.SetTypeface(tvBloodPressure.Typeface, TypefaceStyle.Bold);

            tvMmHg.LayoutParameters = tvMmHgParams;
            tvMmHg.Text             = measureType;
            tvMmHg.SetTextSize(ComplexUnitType.Sp, 18);
            tvMmHg.SetTextColor(Resources.GetColor(Resource.Color.colorSecondary, Theme));

            imIcon.LayoutParameters = tvIconParams;

            imIcon.SetImageDrawable(image);
            imIcon.SetColorFilter(Color.White);

            rlContent.AddView(imIcon);
            rlContent.AddView(tvBloodPressure);
            rlContent.AddView(tvMmHg);
            rlContent.AddView(tvHour);
            cardView.AddView(rlContent);
            return(cardView);
        }
        private void LoadDataInScrollLayouts(DateTime date, bool pressure = true)
        {
            Drawable bloodPressureIconDrawable = Resources.GetDrawable(Resource.Drawable.heart, Theme);
            Drawable pulseRateIconDrawable     = Resources.GetDrawable(Resource.Drawable.heart_pulse, Theme);
            Drawable glucoseIconDrawable       = Resources.GetDrawable(Resource.Drawable.water, Theme);

            verticalScrollLinearLayout.RemoveAllViewsInLayout();
            horizontalScrollLinearLayout.RemoveAllViewsInLayout();
            horizontalScrollLinearLayout.Invalidate();
            verticalScrollLinearLayout.Invalidate();
            //for (int i = 0; i < horizontalScrollLinearLayout.ChildCount; i++)
            //{
            //    horizontalScrollLinearLayout.RemoveViewAt(i);
            //}

            var verticalScrollLayoutParams = new LinearLayoutCompat.LayoutParams(
                ViewGroup.LayoutParams.MatchParent,
                ViewGroup.LayoutParams.WrapContent)
            {
                MarginStart  = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 1, Resources.DisplayMetrics),
                MarginEnd    = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 1, Resources.DisplayMetrics),
                BottomMargin = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 20, Resources.DisplayMetrics)
            };

            var horizontalScrollLayoutParams = new LinearLayoutCompat.LayoutParams(
                ViewGroup.LayoutParams.MatchParent,
                ViewGroup.LayoutParams.WrapContent)
            {
                Width       = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 220, Resources.DisplayMetrics),
                MarginStart = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 1, Resources.DisplayMetrics),
                MarginEnd   = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 5, Resources.DisplayMetrics)
            };

            if (pressure)
            {
                try
                {
                    Task.Run(async() =>
                    {
                        string result = await WebServices.WebServices.Post($"{Constants.PublicServerAddress}/api/getDayRec", new JSONObject().Put("imei", _imei).Put("dataType", "bloodPressure").Put("date", date.ToString("yyyy-MM-dd")), Utils.GetDefaults("Token"));

                        if (!string.IsNullOrEmpty(result))
                        {
                            try
                            {
                                var array = new JSONArray(result);
                                for (var i = 0; i < array.Length(); i++)
                                {
                                    var obj  = new JSONObject(array.Get(i).ToString());
                                    var time = Convert.ToDateTime(obj.GetString("date"));
                                    RunOnUiThread(() =>
                                    {
                                        verticalScrollLinearLayout.AddView(CreateCard(bloodPressureIconDrawable, $"{obj.GetString("systolic")}/{obj.GetString("diastolic")}", "mmHg", time.ToShortTimeString(), verticalScrollLayoutParams));
                                        horizontalScrollLinearLayout.AddView(CreateCard(pulseRateIconDrawable, $"{obj.GetString("pulseRate")}", "bpm", time.ToShortTimeString(), horizontalScrollLayoutParams));
                                    });
                                }
                            }
                            catch (Exception ex)
                            {
                                Log.Error("result error", ex.Message);
                            }
                        }
                    });
                }
                catch (Exception ex)
                {
                    Log.Error("Task error", ex.Message);
                }
                //var size = new Random().Next(5, 20);
                //for (int i = 0; i < size; i++)
                //{
                //    verticalScrollLinearLayout.AddView(CreateCard(bloodPressureIconDrawable, $"{new Random().Next(100, 180)}/{new Random().Next(20, 80)}", "mmHg", $"{new Random().Next(10, 24)}:{new Random().Next(10, 59)}", verticalScrollLayoutParams));
                //    horizontalScrollLinearLayout.AddView(CreateCard(pulseRateIconDrawable, $"{new Random().Next(45, 140)}", "bpm", $"{new Random().Next(10, 24)}:{new Random().Next(10, 59)}", horizontalScrollLayoutParams));
                //}
            }
            else
            {
                horizontalScrollLinearLayout.Visibility = ViewStates.Gone;
                //var size = new Random().Next(5, 20);
                //for (var i = 0; i < size; i++)
                //{
                //    verticalScrollLinearLayout.AddView(CreateCard(glucoseIconDrawable, $"{new Random().Next(100, 180)}", "mg/dL", $"{new Random().Next(10, 24)}:{new Random().Next(10, 59)}", verticalScrollLayoutParams));
                //}
                try
                {
                    Task.Run(async() =>
                    {
                        string result = await WebServices.WebServices.Post($"{Constants.PublicServerAddress}/api/getDayRec", new JSONObject().Put("imei", _imei).Put("dataType", "bloodGlucose").Put("date", date.ToString("yyyy-MM-dd")), Utils.GetDefaults("Token"));

                        if (!string.IsNullOrEmpty(result))
                        {
                            try
                            {
                                var array = new JSONArray(result);
                                for (var i = 0; i < array.Length(); i++)
                                {
                                    var obj  = new JSONObject(array.Get(i).ToString());
                                    var time = Convert.ToDateTime(obj.GetString("date"));
                                    RunOnUiThread(() =>
                                    {
                                        verticalScrollLinearLayout.AddView(CreateCard(glucoseIconDrawable, $"{obj.GetInt("bloodGlucose")}", "mg/dL", time.ToShortTimeString(), verticalScrollLayoutParams));
                                    });
                                }
                            }
                            catch (Exception ex)
                            {
                                Log.Error("result error", ex.Message);
                            }
                        }
                    });
                }
                catch (Exception ex)
                {
                    Log.Error("Task error", ex.Message);
                }
            }
        }