Exemple #1
0
        private View CreateScoreDistributionView(
            IReadOnlyList <AniListScoreDistribution> animeScoreDistributions,
            IReadOnlyList <AniListScoreDistribution> mangaScoreDistributions)
        {
            var chartHeight = Resources.GetDimensionPixelSize(Resource.Dimension.Details_ChartHeight);
            var textColor   = GetThemedColor(Resource.Attribute.Background_Text);
            var margin      = Resources.GetDimensionPixelSize(Resource.Dimension.Details_MarginSmall);

            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 = "Score Distribution";
            detailContainer.Orientation = Orientation.Horizontal;
            detailContainer.SetPadding(margin, 0, margin, 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 scoreDistChart = new BarChart(this)
            {
                LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, chartHeight),
            };

            var data = new BarData()
            {
                BarWidth = 4.5F
            };

            var animeEntries = Enumerable.Range(1, 10).Select(x => new BarEntry(x * 10, animeScoreDistributions.Any(y => y.Score == (x * 10)) ? animeScoreDistributions.First(y => y.Score == (x * 10)).Amount : 0, (x * 10).ToString())).ToList();
            var animeDataSet = new BarDataSet(animeEntries, "Anime")
            {
                Color = colorList[4]
            };

            data.AddDataSet(animeDataSet);

            var mangaEntries = Enumerable.Range(1, 10).Select(x => new BarEntry(x * 10, mangaScoreDistributions.Any(y => y.Score == (x * 10)) ? mangaScoreDistributions.First(y => y.Score == (x * 10)).Amount : 0, (x * 10).ToString())).ToList();
            var mangaDataSet = new BarDataSet(mangaEntries, "Manga")
            {
                Color = colorList[5]
            };

            data.AddDataSet(mangaDataSet);

            data.SetValueFormatter(new ChartUtils.IntegerValueFormatter());

            scoreDistChart.Data = data;
            scoreDistChart.SetTouchEnabled(false);
            scoreDistChart.SetScaleEnabled(false);
            scoreDistChart.GroupBars(5F, .6F, .2F);
            scoreDistChart.AxisLeft.Enabled    = false;
            scoreDistChart.AxisRight.Enabled   = false;
            scoreDistChart.Description.Enabled = false;
            scoreDistChart.XAxis.SetDrawGridLines(false);
            scoreDistChart.XAxis.SetDrawAxisLine(false);
            scoreDistChart.XAxis.Position    = XAxis.XAxisPosition.BottomInside;
            scoreDistChart.XAxis.Granularity = 1;
            scoreDistChart.XAxis.LabelCount  = 10;
            scoreDistChart.XAxis.TextColor   = animeDataSet.ValueTextColor = mangaDataSet.ValueTextColor = scoreDistChart.Legend.TextColor = textColor;

            detailContainer.AddView(scoreDistChart);

            return(detailView);
        }