Clover Coverage Report - WhatYouEat Coverage Report
Coverage timestamp: sab gen 3 2015 15:14:15 EST
../../../img/srcFileCovDistChart10.png 0% of files have more coverage
98   189   22   24,5
30   150   0,22   4
4     5,5  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  NutritionSettings       Line # 16 98 22 93,9% 0.93939394
 
No Tests
 
1    package co.harlequinmettle.healthfoodconcepts;
2   
3    import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
4   
5    import java.util.Arrays;
6   
7    import android.text.InputType;
8    import android.view.View;
9    import android.widget.Button;
10    import android.widget.CheckBox;
11    import android.widget.CompoundButton;
12    import android.widget.EditText;
13    import android.widget.LinearLayout;
14    import android.widget.TextView;
15   
 
16    public class NutritionSettings extends LinearLayout {
17    SubScroll myNutrients;
18    LinearLayout panel;
19    EditText[] amounts = new EditText[130];
20    CheckBox[] onoff = new CheckBox[130];
21   
22    View.OnClickListener saveSettingsListener = new View.OnClickListener() {
 
23  5 toggle public void onClick(View view) {
24  5 int actionID = view.getId();
25    // find EditText and get numbers - save
26  5 switch (actionID) {
27  3 case SAVE:
28  3 WhatYouEat.myGoodNutrients = new boolean[130];
29  393 for (int i = 0; i < 130; i++) {
30    // if i not in my food groups dont add to scroll
31    // if(false)
32  390 WhatYouEat.myGoodNutrients[i] = true;
33  390 if (!WhatYouEat.MY_NUTRIENTS[i])
34  159 continue;
35  231 float amount = 1;
36  231 try{
37  231 String amnt = (amounts[i].getText().toString());
38  231 String[] timeA = amnt.split("\\*");
39  231 for(String q: timeA){
40  231 amount*=Float.valueOf(q);
41    }
42    }catch(NumberFormatException nfe){
43   
44    }
45  231 WhatYouEat.goodNutritionGoals[i] = amount;
46  231 WhatYouEat.myGoodNutrients[i] = onoff[i].isChecked();
47    }
48  3 WhatYouEat.saveObject(WhatYouEat.goodNutritionGoals, "GOODNUTRGOALS");
49  3 WhatYouEat.saveObject(WhatYouEat.myGoodNutrients, "GOODNUTR");
50  3 break;
51  2 case RESET:
52  2 WhatYouEat.goodNutritionGoals = WhatYouEat.DEFAULT_NUTR_GOALS.clone();
53  2 WhatYouEat.myGoodNutrients = WhatYouEat.DEFAULT_GOOD_NUTRIENTS.clone();
54  262 for (int i = 0; i < 130; i++) {
55    // if i not in my food groups dont add to scroll
56    // if(false)
57  260 if (!WhatYouEat.MY_NUTRIENTS[i])
58  106 continue;
59  154 if (WhatYouEat.myGoodNutrients[i]) {
60  132 if(onoff!=null){
61  132 onoff[i].setChecked(true);
62  132 onoff[i].setBackgroundColor(0xff00ff00);
63    }
64  132 if (amounts[i] != null)
65  132 amounts[i].setText(""
66    + WhatYouEat.goodNutritionGoals[i]);
67    } else {
68  22 if(onoff!=null){
69  22 onoff[i].setChecked(false);
70  22 onoff[i].setBackgroundColor(0xffff0000);
71    }
72  22 if (amounts[i] != null)
73  22 amounts[i].setText(""
74    + WhatYouEat.goodNutritionGoals[i]);
75    //amounts[i].setText("As low as possible");
76    }
77    }
78  2 break;
79  0 default:
80   
81  0 break;
82    }
83    }
84    };
85   
86    CompoundButton.OnCheckedChangeListener nutrientBenefitListener = new CompoundButton.OnCheckedChangeListener() {
 
87  78 toggle @Override
88    public void onCheckedChanged(CompoundButton buttonView,
89    boolean isChecked) {
90  78 int id = buttonView.getId();
91    // save wether or not this is a good nutrient
92   
93  78 if (isChecked) {
94  72 buttonView.setChecked(true);
95  72 buttonView.setBackgroundColor(0xff00ff00);
96  72 if (amounts[id] != null)
97  72 amounts[id].setText("" + WhatYouEat.goodNutritionGoals[id]);
98  72 WhatYouEat.myGoodNutrients[id] = true;
99    } else {
100   
101  6 buttonView.setChecked(false);
102  6 buttonView.setBackgroundColor(0xffff0000);
103  6 WhatYouEat.myGoodNutrients[id] = false;
104  6 if (amounts[id] != null)
105  6 amounts[id].setText("" + WhatYouEat.goodNutritionGoals[id]);
106    }
107    }
108    };
109    private static final int RESET = 43837;
110    private static final int SAVE = 8473;
111   
 
112  1 toggle public NutritionSettings() {
113  1 super(WhatYouEat.ctx);
114  1 this.setOrientation(VERTICAL);
115    // /////////////////////////////////////
116  1 myNutrients = new SubScroll(WhatYouEat.ctx);
117   
118  1 LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
119    WRAP_CONTENT, WRAP_CONTENT, 1.0f);
120  1 myNutrients.setLayoutParams(params);
121  1 panel = myNutrients.basicLinearLayout();
122  1 buildSettingView();
123    }
124   
 
125  1 toggle private void buildSettingView() {
126  131 for (int i = 0; i < 130; i++) {
127    // if i not in my food groups dont add to scroll
128    // if(false)
129  130 if (!WhatYouEat.MY_NUTRIENTS[i])
130  53 continue;
131   
132  77 LinearLayout horizontalL = new LinearLayout(WhatYouEat.ctx);
133   
134  77 horizontalL.setId(i);// access layout to access button to
135    // change title
136    // //////////////////////////////////////////////////////
137  77 CheckBox selected = new CheckBox(WhatYouEat.ctx);
138  77 onoff[i] = selected;
139  77 selected.setWidth(250);
140  77 selected.setText(WhatYouEat.nutrients[i]);
141  77 selected.setId(i);
142    // listener to change buttontitle and quantity and unit
143  77 selected.setOnCheckedChangeListener(nutrientBenefitListener);
144  77 horizontalL.addView(selected);
145  77 EditText goal = SubScroll.editText("Enter Nutritient Goal");
146  77 amounts[i] = goal;
147   
148  77 goal.setRawInputType(InputType.TYPE_CLASS_NUMBER
149    | InputType.TYPE_NUMBER_VARIATION_NORMAL);
150  77 if (WhatYouEat.myGoodNutrients[i]) {
151  66 selected.setChecked(true);
152  66 selected.setBackgroundColor(0xff00ff00);
153  66 goal.setText("" + WhatYouEat.goodNutritionGoals[i]);
154    } else {
155   
156  11 selected.setChecked(false);
157  11 selected.setBackgroundColor(0xffff0000);
158   
159  11 goal.setText("" + WhatYouEat.goodNutritionGoals[i]);
160    }
161  77 horizontalL.addView(goal);
162   
163  77 TextView units = SubScroll.textView();
164  77 units.setText("" + WhatYouEat.units[i]);
165   
166  77 horizontalL.addView(units);
167  77 myNutrients.instanceChild.addView(horizontalL);
168    }
169   
170  1 this.addView(myNutrients);
171  1 LinearLayout hz = new LinearLayout(WhatYouEat.ctx);
172   
173  1 Button clr = SubScroll.simpleButton();
174  1 clr.setText("Reset Defaults");
175  1 clr.setId(RESET);
176  1 clr.setOnClickListener(saveSettingsListener);
177   
178  1 Button save = SubScroll.simpleButton();
179  1 save.setText("Save These Settings");
180  1 save.setId(SAVE);
181  1 save.setOnClickListener(saveSettingsListener);
182   
183  1 hz.addView(clr);
184  1 hz.addView(save);
185   
186  1 this.addView(hz);
187    }
188   
189    }