Created
June 17, 2015 18:40
-
-
Save IanLeatherbury/fc5a5c43bceb9ea425d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void SetUpLabels() | |
{ | |
//find winning poll and make it green | |
var options = new Dictionary<string, int>(); | |
options.Add(thisPoll.Option1, thisPoll.Option1Count); | |
options.Add(thisPoll.Option2, thisPoll.Option2Count); | |
options.Add(thisPoll.Option3, thisPoll.Option3Count); | |
options.Add(thisPoll.Option4, thisPoll.Option4Count); | |
//find maximum value and return that poll option | |
var max = options.Aggregate((l, r) => l.Value > r.Value ? l : r).Key; | |
//text labels | |
var option1Label = FindViewById<TextView>(Resource.Id.option1); | |
option1Label.Text = "1: " + thisPoll.Option1; | |
var option2Label = FindViewById<TextView>(Resource.Id.option2); | |
option2Label.Text = "2: " + thisPoll.Option2; | |
var option3Label = FindViewById<TextView>(Resource.Id.option3); | |
option3Label.Text = "3: " + thisPoll.Option3; | |
var option4Label = FindViewById<TextView>(Resource.Id.option4); | |
option4Label.Text = "4: " + thisPoll.Option4; | |
//percent labels | |
var option1Percent = FindViewById<TextView>(Resource.Id.option1Percent); | |
int percent1 = (int)(((double)thisPoll.Option1Count) / ((double)thisPoll.Option1Count + thisPoll.Option2Count + | |
(double)thisPoll.Option3Count + (double)thisPoll.Option4Count) * 100); | |
option1Percent.Text = percent1.ToString() + "%"; | |
var option2Percent = FindViewById<TextView>(Resource.Id.option2Percent); | |
int percent2 = (int)(((double)thisPoll.Option2Count) / ((double)thisPoll.Option1Count + thisPoll.Option2Count + | |
(double)thisPoll.Option3Count + (double)thisPoll.Option4Count) * 100); | |
option2Percent.Text = percent2.ToString() + "%"; | |
var option3Percent = FindViewById<TextView>(Resource.Id.option3Percent); | |
int percent3 = (int)(((double)thisPoll.Option3Count) / ((double)thisPoll.Option1Count + thisPoll.Option2Count + | |
(double)thisPoll.Option3Count + (double)thisPoll.Option4Count) * 100); | |
option3Percent.Text = percent3.ToString() + "%"; | |
var option4Percent = FindViewById<TextView>(Resource.Id.option4Percent); | |
int percent4 = (int)(((double)thisPoll.Option4Count) / ((double)thisPoll.Option1Count + thisPoll.Option2Count + | |
(double)thisPoll.Option3Count + (double)thisPoll.Option4Count) * 100); | |
option4Percent.Text = percent4.ToString() + "%"; | |
//need to make this into a nifty array or something cleaner | |
if (max == thisPoll.Option1) | |
option1Percent.SetTextColor(MyColors.MaterialGreen); | |
if (max == thisPoll.Option2) | |
option2Percent.SetTextColor(MyColors.MaterialGreen); | |
if (max == thisPoll.Option3) | |
option3Percent.SetTextColor(MyColors.MaterialGreen); | |
if (max == thisPoll.Option4) | |
option4Percent.SetTextColor(MyColors.MaterialGreen); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment