Clover Coverage Report - WhatYouEat Coverage Report
Coverage timestamp: sab gen 3 2015 15:14:15 EST
../../../img/srcFileCovDistChart9.png 25% of files have more coverage
358   745   74   22,38
82   544   0,21   16
16     4,62  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  NutritionCalculatorView       Line # 25 358 74 81,8% 0.81798244
 
No Tests
 
1    package co.harlequinmettle.healthfoodconcepts;
2   
3    import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
4   
5    import java.util.ArrayList;
6    import java.util.Arrays;
7    import java.util.HashMap;
8    import java.util.TreeMap;
9    import java.util.Map.Entry;
10   
11    import android.text.InputType;
12    import android.util.TypedValue;
13    import android.view.View;
14    import android.view.ViewTreeObserver;
15    import android.view.ViewTreeObserver.OnGlobalLayoutListener;
16    import android.widget.Button;
17    import android.widget.CheckBox;
18    import android.widget.CompoundButton;
19    import android.widget.EditText;
20    import android.widget.LinearLayout;
21    import android.widget.RadioButton;
22    import android.widget.RadioGroup;
23    import android.widget.TextView;
24   
 
25    public class NutritionCalculatorView extends LinearLayout {
26    static float[] myNutritionalState;
27    static float[] compareToGoal;
28    SubScroll myNutritionBuilder;
29    int scrollViewCount = 0;
30    LinearLayout foodQuantityInput;
31    EditText quantityInput;
32    int currentFood = 0;
33    ArrayList<Long> currentCalc = new ArrayList<Long>();
34    View.OnClickListener foodSuggestionListener = new View.OnClickListener() {
 
35  0 toggle public void onClick(View view) {
36  0 int id = view.getId();
37   
38    }
39    };
40    View.OnClickListener nutritionCalculaterListener = new View.OnClickListener() {
 
41  4 toggle public void onClick(View view) {
42  4 int id = view.getId();
43  4 switch (id) {
44  0 case CLEAR:
45   
46  0 break;
47  2 case CALCULATE:
48  2 compareThisDietToNutritionTargets();
49  2 displayNutritionState();
50  2 break;
51  2 case SUGGEST:
52  2 compareThisDietToNutritionTargets();
53  2 searchforNutritionalFoods();
54  2 break;
55  0 default:
56  0 break;
57   
58    }
59    // from each checked food get quantity and unit - convert to grams
60    // and calculate nutrient profile and display results
61   
62    }
63    };
64    View.OnClickListener saveQuantityListener = new View.OnClickListener() {
 
65  3 toggle public void onClick(View view) {
66  3 try {
67  3 float quantity = Float.valueOf(quantityInput.getText()
68    .toString());
69  3 WhatYouEat.myFoodQuantities.put(currentFood, quantity);
70    } catch (NumberFormatException nfe) {
71    }
72  3 ((Button) myNutritionBuilder.findViewById(currentFood)
73    .findViewById(currentFood + 2000000))
74    .setText(addFullUnitText(currentFood));
75  3 WhatYouEat.saveObject(WhatYouEat.myFoodQuantities, "QUANTITYMAP");
76  3 WhatYouEat.saveObject(WhatYouEat.myFoodUnits, "UNITYMAP");
77  3 WhatYouEat.saveObject(WhatYouEat.myFoodUnitIDs, "UNITIDMAP");
78    }
79    };
80   
81    RadioGroup.OnCheckedChangeListener unitChoiceListener = new RadioGroup.OnCheckedChangeListener() {
82   
 
83  3 toggle @Override
84    public void onCheckedChanged(RadioGroup group, int checkedId) {
85    // DO SOMETHING WHEN USER SELECTS UNITS FOR NUMERIC TEXT INPUT
86   
87  3 int foodID = checkedId / 10000;
88  3 int unitID = checkedId - foodID * 10000;
89   
90  3 WhatYouEat.myFoodUnits.put(foodID,
91    WhatYouEat.oddUnits[foodID][unitID]);
92   
93  3 WhatYouEat.myFoodUnitIDs.put(foodID, unitID);
94   
95    // WhatYouEat.myFoodQuantities.put(foodID, getnumberfrom
96    // textfield)
97  3 WhatYouEat.saveObject(WhatYouEat.myFoodQuantities, "QUANTITYMAP");
98  3 WhatYouEat.saveObject(WhatYouEat.myFoodUnits, "UNITYMAP");
99  3 WhatYouEat.saveObject(WhatYouEat.myFoodUnitIDs, "UNITIDMAP");
100   
101    }
102    };
103   
104    View.OnClickListener foodQuantityListener = new View.OnClickListener() {
 
105  6 toggle public void onClick(View view) {
106  6 int foodId = view.getId() - 2000000;
107  6 currentFood = foodId;
108   
109  6 removeOtherViews();
110   
111  6 SubScroll selectAmount = new SubScroll(WhatYouEat.ctx);
112  6 LinearLayout structure = selectAmount.basicLinearLayout();
113   
114    // option add linearlayout with stationary food title
115  6 structure.setId(10001000);
116  6 TextView title = SubScroll.textView();
117  6 title.setMinimumWidth(300);
118  6 title.setMaxWidth(SubScroll.MAX_BUTTON_WIDTH);
119  6 title.setTextSize(TypedValue.COMPLEX_UNIT_DIP, WhatYouEat.TEXT_MED);
120    // title.setTextSize(25);
121  6 title.setTextColor(0xffff00ff);
122  6 title.setBackgroundColor(0xff333366);
123  6 title.setText(WhatYouEat.foods[foodId]);
124    // selectAmount.instanceChild.addView(title);
125  6 structure.addView(title);
126  6 quantityInput = SubScroll.editText("please enter a number");
127  6 if (WhatYouEat.myFoodQuantities.containsKey(foodId)) {
128  0 quantityInput.setText(""
129    + WhatYouEat.myFoodQuantities.get(foodId));
130    }
131  6 quantityInput.setRawInputType(InputType.TYPE_CLASS_NUMBER
132    | InputType.TYPE_NUMBER_VARIATION_NORMAL);
133   
134    // selectAmount.instanceChild.addView(quantityInput);
135  6 structure.addView(quantityInput);
136    // insert text field and radio group of options
137  6 RadioGroup unitChoices = new RadioGroup(WhatYouEat.ctx);
138  6 unitChoices.setBackgroundColor(0xff222255);
139  6 unitChoices.setOnCheckedChangeListener(unitChoiceListener);
140  6 if (false) {
141  0 RadioButton grams = new RadioButton(WhatYouEat.ctx);
142  0 grams.setText("grams");
143  0 grams.setTextSize(TypedValue.COMPLEX_UNIT_DIP,
144    WhatYouEat.TEXT_MED);
145  0 grams.setId(1000000000);// 1 billion
146   
147  0 unitChoices.addView(grams);
148   
149  0 if (WhatYouEat.myFoodUnits.containsKey(foodId)
150    && WhatYouEat.myFoodUnits.get(foodId).equals("grams")) {
151  0 grams.setChecked(true);
152   
153  0 if (WhatYouEat.myFoodQuantities.containsKey(foodId)) {
154  0 quantityInput.setText(""
155    + WhatYouEat.myFoodQuantities.get(foodId));
156    } else {
157  0 quantityInput.setText("" + 10);
158    }
159    }
160    }
161  6 String[] servingUnits = WhatYouEat.oddUnits[foodId];
162  6 if (servingUnits == null) {
163   
164  0 WhatYouEat.oddUnits[foodId] = new String[1];
165  0 WhatYouEat.oddUnits[foodId][0] = "grams";
166  0 WhatYouEat.quantityFactor[foodId] = new float[1];
167  0 WhatYouEat.quantityFactor[foodId][0] = 100.0f;
168  0 servingUnits = WhatYouEat.oddUnits[foodId];
169  0 return;
170    }
171   
172  12 for (int i = 0; i < servingUnits.length; i++) {
173  6 RadioButton rb = new RadioButton(WhatYouEat.ctx);
174  6 rb.setId(foodId * 10000 + i);
175  6 rb.setText(servingUnits[i]);
176  6 rb.setTextSize(TypedValue.COMPLEX_UNIT_DIP, WhatYouEat.TEXT_MED);
177  6 unitChoices.addView(rb);
178  6 if (WhatYouEat.myFoodUnits.containsKey(foodId)
179    && WhatYouEat.myFoodUnits.get(foodId).equals(
180    servingUnits[i])) {
181  0 rb.setChecked(true);
182  0 if (WhatYouEat.myFoodQuantities.containsKey(foodId)) {
183  0 quantityInput.setText(""
184    + WhatYouEat.myFoodQuantities.get(foodId));
185    } else {
186  0 quantityInput.setText("" + 10);
187    }
188    }
189    // rb.setOnCheckedChangeListener(listener);
190    }
191  6 selectAmount.instanceChild.addView(unitChoices);
192  6 structure.addView(selectAmount);
193    // ///////////////////////////////////////
194  6 Button enterButton = SubScroll.simpleButton();
195  6 enterButton.setText("Save Food Quantity");
196  6 enterButton.setId(100100100);
197  6 enterButton.setOnClickListener(saveQuantityListener);
198   
199  6 structure.addView(enterButton);
200    // /////////////////////////////////////
201  6 WhatYouEat.appAccess.addView(structure);
202    // /////////////////////////////////////////////////
203  6 final ViewTreeObserver viewTreeObserver4 = WhatYouEat.application
204    .getViewTreeObserver();
205  6 if (viewTreeObserver4.isAlive()) {
206  6 viewTreeObserver4
207    .addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
 
208  6 toggle @Override
209    public void onGlobalLayout() {
210   
211  6 WhatYouEat.application.scrollBy((int) (350), 0);
212  6 viewTreeObserver4
213    .removeGlobalOnLayoutListener(this);
214    }
215    });
216    }
217    }
218    };
219   
220    CompoundButton.OnCheckedChangeListener foodInclusionListener = new CompoundButton.OnCheckedChangeListener() {
 
221  3 toggle @Override
222    public void onCheckedChanged(CompoundButton buttonView,
223    boolean isChecked) {
224  3 int id = buttonView.getId();
225  3 int foodId = id - 1000000;
226  3 View structure = myNutritionBuilder.instanceChild
227    .findViewById(foodId);
228  3 if (isChecked) {
229  3 ((Button) structure.findViewById(id + 1000000))
230    .setText(addFullUnitText(foodId));
231  3 currentCalc.add(new Long(foodId));
232    } else {
233  0 ((Button) structure.findViewById(id + 1000000))
234    .setText(WhatYouEat.foods[foodId]);
235  0 currentCalc.remove(new Long(foodId));
236    }
237   
238  3 WhatYouEat.allMyFoods.get(WhatYouEat.findGroupFromFoodID(foodId))
239    .put(foodId, false);
240  3 WhatYouEat.saveObject(WhatYouEat.allMyFoods, "MYFOODS");
241    }
242   
243    };
244    private static final int CALCULATE = 341301473;
245    private static final int CLEAR = 31349;
246    private static final int SUGGEST = 606387;
247   
 
248  2 toggle NutritionCalculatorView() {
249  2 super(WhatYouEat.ctx);//
250   
251  2 this.setOrientation(VERTICAL);
252    // /////////////////////////////////////
253   
254  2 myNutritionBuilder = new SubScroll(WhatYouEat.ctx);
255   
256  2 LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
257    WRAP_CONTENT, WRAP_CONTENT, 1.0f);
258  2 myNutritionBuilder.setLayoutParams(params);
259  2 foodQuantityInput = myNutritionBuilder.basicLinearLayout();
260  2 buildCalculator();
261   
262    }
263   
264    // /////////////////////////////////////////
 
265  2 toggle public void searchforNutritionalFoods() {
266   
267    // static float[] myNutritionalState;
268    // static float[] compareToGoal; //atan of ratio 1.57
269    // static HashMap<Integer, Float> myFoodQuantities = new
270    // static HashMap<Integer, String> myFoodUnits = new HashMap<Integer,
271    // static boolean[] myGoodNutrients;
272    // static float[] goodNutritionGoals;
273   
274    // static String[][] oddUnits = new String[FOOD_COUNT][];//
275    // static float[][] metricConversion = new float[FOOD_COUNT][];//
276    // static float[][] quantityFactor = new float[FOOD_COUNT][];//
277  2 ArrayList<Integer> h = new ArrayList<Integer>();
278  2 ArrayList<Integer> l = new ArrayList<Integer>();
279  262 for (int i = 0; i <130; i++) {
280   
281  260 if (!WhatYouEat.MY_NUTRIENTS[i] )
282  98 continue;
283  162 if (WhatYouEat.myGoodNutrients[i] && WhatYouEat.goodNutritionGoals[i] > 0) {
284  90 h.add(i);
285    } else {
286  72 l.add(i);
287    }
288    }
289    {
290   
291  2 long time = System.currentTimeMillis();
292  2 TreeMap<Float, Integer> foodRanking = new TreeMap<Float, Integer>();
293  2 int[] foodsToSearch = WhatYouEat.getFoodSearchIds();
294   
295  2 float[] rankHigh = new float[WhatYouEat.FOOD_COUNT];
296  2 float[] rankLow = new float[WhatYouEat.FOOD_COUNT];
297  2 if (false)
298  0 for (int i = 0; i < WhatYouEat.FOOD_COUNT; i++) {
299  0 rankHigh[i] = -100;
300  0 rankLow[i] = 100;
301    }
302  2 for (int i : foodsToSearch) {
303  12570 rankHigh[i] = 1;
304  12570 rankLow[i] = 1;
305    }
306  2 float null_rank_constant = 0;
307  2 float measuredFactor = 0.0f;
308   
309  2 for (int nutrientID : h) {
310   
311  90 float[] nstat = WhatYouEat.highlightFactors.get(nutrientID);
312  90 float min = nstat[0];
313  90 float mean = nstat[1];
314  90 float max = nstat[2];
315    // OPTIONS FOR SEARCHING 1 FOOD GROUP/ MYFOODS/ MYFOODGROUPS
316  90 for (int i : foodsToSearch) {
317   
318  565650 float dataPoint = WhatYouEat.db[nutrientID][i];
319   
320  565650 if (dataPoint < 0) {
321  188402 rankHigh[i] += null_rank_constant;
322  188402 continue;
323    }
324   
325  377248 switch (WhatYouEat.Nutrient_Measure) {
326  0 case WhatYouEat.USING_KCAL:
327  0 dataPoint = WhatYouEat.getPer100KcalDataPoint(i,
328    dataPoint);
329   
330  0 break;
331  0 case WhatYouEat.USING_SERVING:
332  0 dataPoint = WhatYouEat.getPerServingDataPoint(i,
333    dataPoint);
334  0 if (dataPoint < 0) {
335   
336  0 dataPoint = WhatYouEat.db[nutrientID][i];
337    }
338  0 break;
339  377248 case WhatYouEat.USING_GRAMS:
340   
341  377248 break;
342    // ADD CASE ID_PER_SERVING:
343  0 default:
344   
345  0 break;
346    }
347   
348  377248 float relativeData = dataPoint / max;
349   
350  377248 relativeData = (float) (Math.atan(relativeData));
351    // ranks[i] -=
352    // WhatYouEat.getRelativeAbundance(nutrientID,dataPoint);
353   
354   
355   
356  377248 rankHigh[i] += (measuredFactor + relativeData)
357    * (Math.PI/2- compareToGoal[nutrientID]);
358    // the higher rank in obtaining goals the lower rank
359    // rankHigh[i] *= (2.5 - compareToGoal[nutrientID]);
360   
361   
362  377248 rankHigh[i] -= (Math.random() / 100000000000.0);
363    }
364    }
365   
366  2 for (int nutrientID : l) {
367   
368  72 float[] nstat = WhatYouEat.highlightFactors.get(nutrientID);
369  72 float min = nstat[0];
370  72 float mean = nstat[1];
371  72 float max = nstat[2];
372   
373  72 for (int i : foodsToSearch) {
374   
375  452520 float dataPoint = WhatYouEat.db[nutrientID][i];
376  452520 if (dataPoint < 0) {
377  241346 rankLow[i] += null_rank_constant;
378  241346 continue;
379   
380    }
381   
382  211174 switch (WhatYouEat.Nutrient_Measure) {
383  0 case WhatYouEat.USING_KCAL:
384  0 dataPoint = WhatYouEat.getPer100KcalDataPoint(i,
385    dataPoint);
386   
387  0 break;
388  0 case WhatYouEat.USING_SERVING:
389  0 dataPoint = WhatYouEat.getPerServingDataPoint(i,
390    dataPoint);
391  0 if (dataPoint < 0) {
392  0 dataPoint = WhatYouEat.db[nutrientID][i];
393    }
394  0 break;
395  211174 case WhatYouEat.USING_GRAMS:
396   
397  211174 break;
398    // ADD CASE ID_PER_SERVING:
399  0 default:
400   
401  0 break;
402    }
403  211174 float relativeData = dataPoint / max;
404   
405  211174 relativeData = (float) (Math.atan(relativeData));
406    // ranks[i] -=
407    // WhatYouEat.getRelativeAbundance(nutrientID,dataPoint);
408   
409  211174 rankLow[i] += (measuredFactor + relativeData)
410    * ( compareToGoal[nutrientID]);
411   
412  211174 rankLow[i] -= (Math.random() / 100000000000.0);
413    }
414    }
415  2 int ctr = 0;
416  2 for (int i : foodsToSearch) {
417  12570 float highRank = -(rankHigh[i]);
418  12570 float lowRank = (rankLow[i]);
419    // order of tree set is from lowest to highest
420    // high ranking use negative
421  12570 foodRanking.put(lowRank + highRank, i);
422    }
423  2 int counter = 0;
424  2 int MAX = foodRanking.size() - 1;
425  2 if (MAX > 300)
426  2 MAX = 300;
427  2 if (MAX < 1)
428  0 MAX = 2;
429  2 String[] priorityResults = new String[MAX];
430  2 int[] pResIDs = new int[MAX];
431  2 for (int rank : foodRanking.values()) {
432   
433  600 priorityResults[counter] = WhatYouEat.foods[rank];
434  600 pResIDs[counter] = rank;
435   
436  600 if (counter++ == MAX - 1)
437  2 break;
438    }
439   
440  2 System.out.println("---::>DONE SEARCH: "
441    + (System.currentTimeMillis() - time));
442  2 WhatYouEat.searchResults = priorityResults;
443  2 WhatYouEat.foodCodeResults = pResIDs;
444    // WhatYouEat.appAccess.removeViewAt(2);
445  2 removeOtherViews();
446  2 FoodDescriptionsScroller fds = new FoodDescriptionsScroller(
447    WhatYouEat.ctx, true);
448  2 fds.setId(100010011);
449  2 WhatYouEat.appAccess.addView(fds);
450   
451    }// END OF SEARCH
452    }
453   
 
454  10 toggle public void removeOtherViews(){
455   
456  10 WhatYouEat.appAccess.removeView(WhatYouEat.appAccess
457    .findViewById(10001000));
458  10 WhatYouEat.appAccess.removeView(WhatYouEat.appAccess
459    .findViewById(101010101));
460  10 WhatYouEat.appAccess.removeView(WhatYouEat.appAccess
461    .findViewById(100010011));
462  10 WhatYouEat.appAccess.removeView(WhatYouEat.appAccess
463    .findViewById(SubScroll.FOOD_NUTRIENT_ID));
464  10 WhatYouEat.appAccess.removeView(WhatYouEat.appAccess
465    .findViewById(SubScroll.STATVIEW_ID));
466   
467    }
468    // ////////////////////////////////////////////////////////////////////////////////
 
469  4 toggle protected void compareThisDietToNutritionTargets() {
470   
471    // IF(GOOD NUTRIENT)->
472    // IF GOAL > 0 DO PERCENTAGE TO GOAL
473    // IF SUM < 95%GOAL COLOR RED
474    // IF SUM >=95%GOAL && <= 105% COLOR LIGHTGREEN
475    // IF SUM > 105%GOAL COLOR GREEN
476    // IF(BAD NUTRIETN) - > DO OPPOSITE
477  4 myNutritionalState = new float[130];
478  4 compareToGoal = new float[130];
479    // static ArrayList<TreeMap<Integer, Boolean>> allMyFoods = new
480    // ArrayList<TreeMap<Integer, Boolean>>();
481  4 for (long f_d : currentCalc) {
482  12 int foodID = (int) (f_d);
483    //
484    // if (WhatYouEat.allMyFoods.get(
485    // WhatYouEat.findGroupFromFoodID(ent.getKey())).get(ent.getKey()))
486    // {
487  1572 for (int i = 0; i < 130; i++) {
488    // if i not in my food groups dont add to scroll
489    // if(false)
490  1560 if (!WhatYouEat.MY_NUTRIENTS[i])
491  588 continue;
492  972 float nutritionPer100g = WhatYouEat.db[i][foodID];
493  972 if (nutritionPer100g < 0
494    || WhatYouEat.myFoodQuantities.get(foodID) == null)
495  804 continue;
496  168 float servingSize = WhatYouEat.myFoodQuantities.get(foodID);// user
497    // chosen
498    // quantity
499    // int smallestServingUnit =
500    // WhatYouEat.optimalServingId[foodID];
501  168 int currentUnitID = WhatYouEat.myFoodUnitIDs.get(foodID);
502  168 float gramsPerServing = 100;
503  168 float servingQuantity = 1;
504  168 gramsPerServing = WhatYouEat.metricConversion[foodID][currentUnitID];
505  168 servingQuantity = WhatYouEat.quantityFactor[foodID][currentUnitID];
506   
507  168 if (servingQuantity <= 0)
508  0 servingQuantity = 1;
509  168 float conversionFactor = servingSize * gramsPerServing
510    / servingQuantity;// COMPUTE THIS
511    // FOR EACH FOOD IF ENT.GETVALUE()
512  168 myNutritionalState[i] += nutritionPer100g * conversionFactor
513    / 100.0f;
514   
515    }
516    }
517    // state compared to goal default zero
518    //QUESTION HOW DO DEFAULTS EFFECT CALCULATIONS
519    //what if goal is zero ie not set
520  524 for (int i = 0; i < 130; i++) {
521    // if i not in my food groups dont add to scroll
522    // if(false)
523  520 if (!WhatYouEat.MY_NUTRIENTS[i] || myNutritionalState[i] < 0)
524  196 continue;
525   
526  324 float actualNutrition = myNutritionalState[i];
527  324 actualNutrition = (float) (((long) (1000 * actualNutrition)) / 1000);
528  324 float nutritionGoal = WhatYouEat.goodNutritionGoals[i];
529   
530  324 if (nutritionGoal > 0) {
531  196 float ratio = actualNutrition / nutritionGoal;
532  196 compareToGoal[i] = (float) Math.atan(ratio);
533    }
534    }
535   
536  524 for(int i = 0;i<compareToGoal.length;i++){
537  520 System.out.println("calculate: "+i+" "+compareToGoal[i]);
538    }
539    }// /////////////////
540   
 
541  2 toggle public void displayNutritionState() {
542    // COMPARE RESULTS TO GOALS; DISPLAY
543  2 removeOtherViews();
544   
545  2 SubScroll compareNutrients = new SubScroll(WhatYouEat.ctx);
546   
547  2 LinearLayout framed = compareNutrients.basicLinearLayout();
548  2 framed.setId(101010101);
549  2 WhatYouEat.appAccess.addView(framed);
550   
551  2 TextView title = SubScroll.textView();
552  2 title.setBackgroundColor(0xff223377);
553  2 title.setText("Current Diet Relative to Goals");
554  2 framed.addView(title);
555  2 framed.addView(compareNutrients);
556  2 Button doSomething = SubScroll.simpleButton();
557  2 doSomething.setText("do something");
558  2 doSomething.setOnClickListener(null);
559  2 framed.addView(doSomething);
560  262 for (int i = 0; i < 130; i++) {
561    // if i not in my food groups dont add to scroll
562    // if(false)
563  260 if (!WhatYouEat.MY_NUTRIENTS[i] || myNutritionalState[i] < 0)
564  98 continue;
565   
566  162 Button nutrB = SubScroll.simpleButton();
567  162 nutrB.setId(i);
568  162 nutrB.setOnClickListener(foodSuggestionListener);
569   
570  162 float actualNutrition = myNutritionalState[i];
571  162 actualNutrition = (float) (((long) (1000 * actualNutrition)) / 1000);
572  162 float nutritionGoal = WhatYouEat.goodNutritionGoals[i];
573   
574  162 String buttonTitle = "Intake of " + actualNutrition + " "
575    + WhatYouEat.units[i] + " of [" + WhatYouEat.nutrients[i]
576    + "] ";
577   
578  162 if (nutritionGoal <= 0) {
579  64 nutrB.setTextColor(0xffaaaaaa);
580  64 buttonTitle += " ;goal: not set";
581  64 if (WhatYouEat.myGoodNutrients[i]) {
582  48 nutrB.setBackgroundColor(0xaa227744);
583   
584    } else {
585   
586  16 nutrB.setBackgroundColor(0xaa772244);
587    }
588    } else {
589  98 nutrB.setTextColor(0xffffffff);
590  98 float ratio = actualNutrition / nutritionGoal;
591   
592    //compareToGoal[i] = ratio;
593  98 compareToGoal[i] = (float) Math.atan(ratio);
594  98 buttonTitle += " is " + (long) (100 * ratio) + "% of goal: "
595    + WhatYouEat.goodNutritionGoals[i] + " "
596    + WhatYouEat.units[i];
597  98 int color = colorToGoal(ratio, WhatYouEat.myGoodNutrients[i]);
598   
599  98 nutrB.setBackgroundColor(color);
600    }
601   
602   
603  162 nutrB.setText(buttonTitle);
604  162 compareNutrients.instanceChild.addView(nutrB);
605    }
606    // /////////////////////////////////////////////////
607  2 final ViewTreeObserver viewTreeObserver4 = WhatYouEat.application
608    .getViewTreeObserver();
609  2 if (viewTreeObserver4.isAlive()) {
610  2 viewTreeObserver4
611    .addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
 
612  2 toggle @Override
613    public void onGlobalLayout() {
614   
615  2 WhatYouEat.application.scrollBy((int) (350), 0);
616  2 viewTreeObserver4
617    .removeGlobalOnLayoutListener(this);
618    }
619    });
620    }
621  262 for(int i = 0;i<compareToGoal.length;i++){
622  260 System.out.println("display: "+i+" "+compareToGoal[i]);
623    }
624    }
625   
 
626  98 toggle public static int colorToGoal(float ratioToGoal, boolean goodNutrient) {
627  98 int color = 0x00ff0000;
628  98 if (goodNutrient)
629  90 color = 0x0000ff00;
630  98 int alpha = 30 + ((int) (200 * Math.atan(ratioToGoal)));
631  98 if (alpha > 255)
632  9 alpha = 255;
633  98 return alpha << 24 | color;
634   
635    }
636   
 
637  2 toggle private void buildCalculator() {
638    // layout to add grouptitle/food scroller and button at bottom
639  2 boolean alternatecolor = true;
640  52 for (int i = 0; i < 25; i++) {
641    // if i not in my food groups dont add to scroll
642    // if(false)
643  50 if (!WhatYouEat.MY_FOOD_GROUPS[i])
644  14 continue;
645   
646    // title button with kws.inflatorlistener id i
647  36 TextView groupTitle = SubScroll.textView();
648  36 if (alternatecolor) {
649  19 groupTitle.setBackgroundColor(0xff55cccc);
650  19 alternatecolor = false;
651    } else {
652   
653  17 groupTitle.setBackgroundColor(0xff5555dd);
654  17 alternatecolor = true;
655    }
656  36 groupTitle.setTextColor(0xff000000);
657  36 groupTitle.setText(WhatYouEat.foodGroups[i]);
658  36 myNutritionBuilder.instanceChild.addView(groupTitle);
659    // allMyFoods = new ArrayList<TreeMap<Integer, Boolean>>();
660  36 for (Entry<Integer, Boolean> ent : WhatYouEat.allMyFoods.get(i)
661    .entrySet()) {
662  3 LinearLayout horizontalL = new LinearLayout(WhatYouEat.ctx);
663   
664  3 int foodID = ent.getKey();
665  3 horizontalL.setId(foodID);// access layout to access button to
666    // change title
667    // //////////////////////////////////////////////////////
668  3 CheckBox selected = new CheckBox(WhatYouEat.ctx);
669  3 String foodQ = "";
670   
671  3 if (WhatYouEat.allMyFoods.get(
672    WhatYouEat.findGroupFromFoodID(foodID)).get(foodID)) {
673  0 selected.setChecked(true);
674  0 foodQ += addFullUnitText(foodID);
675    } else {
676  3 foodQ += WhatYouEat.foods[foodID];
677    }
678  3 selected.setId(1000000 + foodID);
679    // listener to change buttontitle and quantity and unit
680  3 selected.setOnCheckedChangeListener(foodInclusionListener);
681  3 horizontalL.addView(selected);
682    // ////////////////////////////////////////////////////
683  3 Button foodButton = SubScroll.simpleButton();// new
684    // Button(WhatYouEat.ctx);
685  3 foodButton.setText(foodQ);
686  3 foodButton.setId(2000000 + foodID);
687  3 foodButton.setOnClickListener(foodQuantityListener);
688    // set color
689  3 horizontalL.addView(foodButton);
690    // /////////////////////////////////////////////////
691   
692    // /////////////////////////////////////////
693  3 myNutritionBuilder.instanceChild.addView(horizontalL);
694    }
695    // for each food in this group
696    // build horizontal layout
697    // add checkbox true if true
698    // add food title (textfield?)
699    // add two spinners : on with quanitty on with unit
700    // add to
701   
702    }
703   
704  2 this.addView(myNutritionBuilder);
705    // ////////////////////////////////////////////
706   
707  2 LinearLayout hz = new LinearLayout(WhatYouEat.ctx);
708   
709  2 Button search = SubScroll.simpleButton();
710  2 search.setText("Calculate");
711  2 search.setId(CALCULATE);
712  2 search.setOnClickListener(nutritionCalculaterListener);
713  2 if(false){
714  0 Button clr = SubScroll.simpleButton();
715  0 clr.setText("Clear");
716  0 clr.setId(CLEAR);
717  0 clr.setOnClickListener(nutritionCalculaterListener);
718  0 hz.addView(clr);
719    }
720  2 Button sug = SubScroll.simpleButton();
721  2 sug.setText("Complement");
722  2 sug.setId(SUGGEST);
723  2 sug.setOnClickListener(nutritionCalculaterListener);
724   
725  2 hz.addView(search);
726  2 hz.addView(sug);
727   
728  2 this.addView(hz);
729   
730    }
731   
 
732  6 toggle public String addFullUnitText(int foodID) {
733  6 String qfd = "";
734  6 if (WhatYouEat.myFoodQuantities.containsKey(foodID)
735    && WhatYouEat.myFoodUnits.containsKey(foodID)) {
736  3 qfd += " " + WhatYouEat.myFoodQuantities.get(foodID);
737  3 qfd += " [" + WhatYouEat.myFoodUnits.get(foodID) + "] of ";
738  3 qfd += WhatYouEat.foods[foodID];
739    } else {
740  3 qfd += "[0]" + WhatYouEat.foods[foodID];
741    }
742  6 return qfd;
743    }
744   
745    }