1 |
|
package co.harlequinmettle.healthfoodconcepts; |
2 |
|
|
3 |
|
import java.util.Map.Entry; |
4 |
|
import java.util.TreeMap; |
5 |
|
|
6 |
|
import android.content.Context; |
7 |
|
import android.graphics.PorterDuff; |
8 |
|
import android.view.View; |
9 |
|
import android.widget.Button; |
10 |
|
import android.widget.CheckBox; |
11 |
|
import android.widget.CompoundButton; |
12 |
|
import android.widget.LinearLayout; |
13 |
|
|
|
|
| 86,8% |
Uncovered Elements: 9 (68) |
Complexity: 10 |
Complexity Density: 0,18 |
|
14 |
|
public class MyFoodsScroller extends SubScroll { |
15 |
|
CheckBox[] ckbox; |
16 |
|
int groupID; |
17 |
|
|
18 |
|
|
19 |
|
View.OnClickListener nutritionInfoListener = new View.OnClickListener() { |
|
|
| 81,5% |
Uncovered Elements: 5 (27) |
Complexity: 5 |
Complexity Density: 0,22 |
|
20 |
3
|
public void onClick(View view) {... |
21 |
3
|
int id = view.getId(); |
22 |
3
|
Button b = (Button) view; |
23 |
3
|
currentFoodID = id; |
24 |
3
|
b.getBackground() |
25 |
|
.setColorFilter(0xff999999, PorterDuff.Mode.SRC_IN); |
26 |
3
|
if (showingNutrients) |
27 |
2
|
WhatYouEat.appAccess.removeView(WhatYouEat.appAccess |
28 |
|
.findViewById(FOOD_NUTRIENT_ID)); |
29 |
|
|
30 |
3
|
NutritionScroller nutr = new NutritionScroller(context, id); |
31 |
|
|
32 |
3
|
if (showingStats) { |
33 |
1
|
WhatYouEat.appAccess.removeView(WhatYouEat.appAccess |
34 |
|
.findViewById(STATVIEW_ID)); |
35 |
1
|
showingStats = false; |
36 |
|
} |
37 |
3
|
nutr.setId(FOOD_NUTRIENT_ID); |
38 |
3
|
index = groupID + 2; |
39 |
3
|
switch(WhatYouEat.myFoods_View){ |
40 |
|
|
41 |
0
|
case 10: |
42 |
|
|
43 |
0
|
WhatYouEat.appAccess.addView(nutr, index); |
44 |
0
|
break; |
45 |
3
|
case WhatYouEat.VIEW_VERTICAL: |
46 |
|
|
47 |
3
|
WhatYouEat.appAccess.addView(nutr, 2); |
48 |
3
|
break; |
49 |
0
|
default: |
50 |
0
|
break; |
51 |
|
} |
52 |
|
|
53 |
3
|
WhatYouEat.application.scrollBy((int) (MAX_BUTTON_WIDTH * 0.9), 0); |
54 |
3
|
showingNutrients = true; |
55 |
|
} |
56 |
|
}; |
57 |
|
|
58 |
|
CompoundButton.OnCheckedChangeListener foodPreferencesListener = new CompoundButton.OnCheckedChangeListener() { |
59 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
60 |
0
|
@Override... |
61 |
|
public void onCheckedChanged(CompoundButton buttonView, |
62 |
|
boolean isChecked) { |
63 |
|
|
64 |
0
|
int foodId = buttonView.getId(); |
65 |
|
|
66 |
0
|
WhatYouEat.allMyFoods.get(groupID).put(foodId, isChecked); |
67 |
|
|
68 |
0
|
WhatYouEat.saveObject(WhatYouEat.allMyFoods, "MYFOODS"); |
69 |
|
} |
70 |
|
}; |
71 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 2 |
Complexity Density: 0,14 |
|
72 |
19
|
MyFoodsScroller(Context c, int groupID, boolean addChild) {... |
73 |
19
|
super(c , addChild); |
74 |
19
|
this.groupID = groupID; |
75 |
19
|
TreeMap<Integer, Boolean> myGroupFoods = WhatYouEat.allMyFoods |
76 |
|
.get(groupID); |
77 |
19
|
if (myGroupFoods.size() > 0) { |
78 |
2
|
String[] myFoodNames = new String[myGroupFoods.size()]; |
79 |
2
|
int[] myFoodNumbers = new int[myGroupFoods.size()]; |
80 |
2
|
boolean[] myFoodBool = new boolean[myGroupFoods.size()]; |
81 |
2
|
int i = 0; |
82 |
2
|
for (Entry<Integer, Boolean> ent : myGroupFoods.entrySet()) { |
83 |
3
|
myFoodNames[i] = WhatYouEat.foods[ent.getKey()]; |
84 |
3
|
myFoodNumbers[i] = ent.getKey(); |
85 |
3
|
myFoodBool[i] = ent.getValue(); |
86 |
3
|
i++; |
87 |
|
} |
88 |
2
|
addScrollingButtons(myFoodNames, myFoodNumbers, myFoodBool, |
89 |
|
BUTTON_COLORS[GROUPPREFS]); |
90 |
|
|
91 |
|
} |
92 |
|
|
93 |
|
} |
94 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (18) |
Complexity: 2 |
Complexity Density: 0,12 |
|
95 |
2
|
public void addScrollingButtons(String[] buttonNames, int[] buttonIds,... |
96 |
|
boolean[] settings, int BUTTON_CLR) { |
97 |
|
|
98 |
|
|
99 |
2
|
buttons = new Button[buttonNames.length]; |
100 |
|
|
101 |
2
|
ckbox = new CheckBox[buttonNames.length]; |
102 |
|
|
103 |
5
|
for (int i = 0; i < buttonNames.length; i++) { |
104 |
3
|
LinearLayout layout = new LinearLayout(context); |
105 |
3
|
buttons[i] = simpleButton(); |
106 |
3
|
buttons[i].setText(buttonNames[i]); |
107 |
3
|
buttons[i].setId(buttonIds[i]); |
108 |
|
|
109 |
3
|
buttons[i].setOnClickListener(nutritionInfoListener); |
110 |
3
|
buttons[i].getBackground().setColorFilter(BUTTON_CLR, |
111 |
|
PorterDuff.Mode.MULTIPLY); |
112 |
|
|
113 |
3
|
ckbox[i] = new CheckBox(context); |
114 |
|
|
115 |
3
|
ckbox[i].setChecked(settings[i]); |
116 |
|
|
117 |
3
|
ckbox[i].setOnCheckedChangeListener(foodPreferencesListener); |
118 |
3
|
ckbox[i].setId(buttonIds[i]); |
119 |
3
|
layout.addView(ckbox[i]); |
120 |
3
|
layout.addView(buttons[i]); |
121 |
3
|
instanceChild.addView(layout); |
122 |
|
} |
123 |
|
|
124 |
|
} |
125 |
|
} |