Пример #1
0
        private View CreateAiringScoreProgressionView(
            List <MediaTrend> trends)
        {
            var detailView      = LayoutInflater.Inflate(Resource.Layout.View_AniListObjectDetail, null);
            var detailContainer = detailView.FindViewById <LinearLayout>(Resource.Id.AniListObjectDetail_InnerContainer);

            detailView.FindViewById <TextView>(Resource.Id.AniListObjectDetail_Name).Text = "Airing Score Progression";

            var chartHeight  = Resources.GetDimensionPixelSize(Resource.Dimension.Details_ChartHeight);
            var textColor    = GetThemedColor(Resource.Attribute.Background_Text);
            var legendMargin = Resources.GetDimensionPixelSize(Resource.Dimension.Details_MarginSmall);


            detailContainer.SetPadding(legendMargin, 0, legendMargin, 0);

            var typedColorArray = Resources.ObtainTypedArray(Resource.Array.Chart_Colors);
            var colorList       = new List <int>();

            for (var i = 0; i < typedColorArray.Length(); i++)
            {
                colorList.Add(typedColorArray.GetColor(i, 0));
            }

            var scoresChart = new LineChart(this)
            {
                LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, chartHeight),
            };

            var data = new LineData();

            var scorePoints  = trends.Select(x => new Entry(x.Episode.Value, x.AverageScore ?? 0)).ToList();
            var scoreDataSet = new LineDataSet(scorePoints, "Score")
            {
                Color          = colorList[0],
                ValueFormatter = new ChartUtils.IntegerValueFormatter(),
            };

            scoreDataSet.ValueTextSize = 12;
            scoreDataSet.SetDrawCircleHole(false);
            scoreDataSet.SetCircleColor(colorList[0]);
            scoreDataSet.SetMode(LineDataSet.Mode.Linear);
            scoreDataSet.ValueTextColor = textColor;
            scoreDataSet.SetDrawValues(true);

            data.AddDataSet(scoreDataSet);

            scoresChart.Data = data;
            scoresChart.FitScreen();
            scoresChart.SetTouchEnabled(false);
            scoresChart.Description.Enabled  = false;
            scoresChart.XAxis.Position       = XAxis.XAxisPosition.Bottom;
            scoresChart.XAxis.ValueFormatter = new ChartUtils.AxisValueCeilingFormatter(1);
            scoresChart.XAxis.Granularity    = 1;
            scoresChart.XAxis.AxisMaximum    = trends.Max(x => x.Episode.Value);
            scoresChart.XAxis.AxisMinimum    = trends.Min(x => x.Episode.Value);
            scoresChart.XAxis.SetLabelCount(trends.Count, true);

            scoresChart.AxisLeft.AxisMinimum = 0;
            scoresChart.AxisLeft.AxisMaximum = 100;
            scoresChart.Legend.Enabled       = false;
            scoresChart.SetDrawGridBackground(false);
            scoresChart.XAxis.SetDrawGridLines(false);
            scoresChart.AxisLeft.Enabled  = false;
            scoresChart.AxisRight.Enabled = false;

            scoresChart.ExtraLeftOffset = scoresChart.ExtraRightOffset = 15;
            scoresChart.XAxis.TextColor = scoresChart.AxisLeft.TextColor = scoresChart.Legend.TextColor = textColor;

            detailContainer.AddView(scoresChart);

            return(detailView);
        }
Пример #2
0
        private View CreateRecentActivityView(
            List <MediaTrend> trends)
        {
            var detailView      = LayoutInflater.Inflate(Resource.Layout.View_AniListObjectDetail, null);
            var detailContainer = detailView.FindViewById <LinearLayout>(Resource.Id.AniListObjectDetail_InnerContainer);

            detailView.FindViewById <TextView>(Resource.Id.AniListObjectDetail_Name).Text =
                "Recent Activity";

            var chartHeight  = Resources.GetDimensionPixelSize(Resource.Dimension.Details_ChartHeight);
            var textColor    = GetThemedColor(Resource.Attribute.Background_Text);
            var legendMargin = Resources.GetDimensionPixelSize(Resource.Dimension.Details_MarginSmall);

            detailContainer.SetPadding(legendMargin, 0, legendMargin, 0);

            var typedColorArray = Resources.ObtainTypedArray(Resource.Array.Chart_Colors);
            var colorList       = new List <int>();

            for (var i = 0; i < typedColorArray.Length(); i++)
            {
                colorList.Add(typedColorArray.GetColor(i, 0));
            }

            var activityChart = new LineChart(this)
            {
                LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, chartHeight),
            };

            var data = new LineData();

            var activityPoints  = trends.Select(x => new Entry(x.Date, x.Trending)).ToList();
            var activityDataSet = new LineDataSet(activityPoints, "Trending")
            {
                Color          = colorList[0],
                ValueFormatter = new ChartUtils.NumberValueFormatter(),
            };

            var activityRange = trends.Max(x => x.Trending) - trends.Min(x => x.Trending);

            activityDataSet.ValueTextSize = 12;
            activityDataSet.SetDrawCircleHole(false);
            activityDataSet.SetCircleColor(colorList[0]);
            activityDataSet.SetMode(LineDataSet.Mode.Linear);
            activityDataSet.ValueTextColor = textColor;
            activityDataSet.SetDrawValues(true);

            data.AddDataSet(activityDataSet);

            activityChart.Data = data;
            activityChart.FitScreen();
            activityChart.SetTouchEnabled(false);
            activityChart.Description.Enabled      = false;
            activityChart.XAxis.Position           = XAxis.XAxisPosition.Bottom;
            activityChart.XAxis.ValueFormatter     = new ChartUtils.DateValueFormatter("MMM d");
            activityChart.XAxis.LabelRotationAngle = 60;
            activityChart.XAxis.Granularity        = 1;
            activityChart.XAxis.AxisMaximum        = trends.Max(x => x.Date);
            activityChart.XAxis.AxisMinimum        = trends.Min(x => x.Date);
            activityChart.XAxis.SetLabelCount(trends.Count, true);

            activityChart.AxisLeft.AxisMinimum = Math.Max(trends.Min(x => x.Trending) - activityRange / 2, 0);
            activityChart.AxisLeft.AxisMaximum = trends.Max(x => x.Trending) + activityRange / 2;
            activityChart.Legend.Enabled       = false;
            activityChart.SetDrawGridBackground(false);
            activityChart.XAxis.SetDrawGridLines(false);
            activityChart.AxisLeft.Enabled  = false;
            activityChart.AxisRight.Enabled = false;

            activityChart.XAxis.TextColor = activityChart.AxisLeft.TextColor = activityChart.Legend.TextColor = textColor;
            activityChart.ExtraLeftOffset = activityChart.ExtraRightOffset = 15;

            detailContainer.AddView(activityChart);

            return(detailView);
        }