1 |
|
package co.harlequinmettle.healthfoodconcepts; |
2 |
|
|
3 |
|
import java.util.Map.Entry; |
4 |
|
|
5 |
|
import android.content.Context; |
6 |
|
import android.graphics.PorterDuff; |
7 |
|
import android.view.View; |
8 |
|
import android.widget.Button; |
9 |
|
import android.widget.CheckBox; |
10 |
|
import android.widget.CompoundButton; |
11 |
|
import android.widget.LinearLayout; |
12 |
|
import android.widget.TextView; |
13 |
|
|
|
|
| 88,4% |
Uncovered Elements: 17 (147) |
Complexity: 35 |
Complexity Density: 0,36 |
|
14 |
|
public class PreferencesScroller extends SubScroll { |
15 |
|
CheckBox[] ckbox; |
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
View.OnClickListener foodGroupListener = new View.OnClickListener() { |
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
20 |
3
|
public void onClick(View view) {... |
21 |
3
|
int id = view.getId(); |
22 |
3
|
Button b = (Button) view; |
23 |
|
|
24 |
|
} |
25 |
|
}; |
26 |
|
CompoundButton.OnCheckedChangeListener foodGroupPreferencesListener = new CompoundButton.OnCheckedChangeListener() { |
27 |
|
|
|
|
| 83,3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0,5 |
|
28 |
2
|
@Override... |
29 |
|
public void onCheckedChanged(CompoundButton buttonView, |
30 |
|
boolean isChecked) { |
31 |
|
|
32 |
2
|
WhatYouEat.MY_FOOD_GROUPS[buttonView.getId()] = isChecked; |
33 |
2
|
WhatYouEat.saveObject(WhatYouEat.MY_FOOD_GROUPS, "MYFOODGROUPS"); |
34 |
2
|
if (WhatYouEat.USE_MY_FOOD_GROUPS == WhatYouEat.Foods_Search) |
35 |
2
|
WhatYouEat.setFoodsIds(); |
36 |
|
} |
37 |
|
}; |
38 |
|
CompoundButton.OnCheckedChangeListener nutrientsPreferencesListener = new CompoundButton.OnCheckedChangeListener() { |
39 |
|
|
|
|
| 80% |
Uncovered Elements: 2 (10) |
Complexity: 2 |
Complexity Density: 0,25 |
|
40 |
4
|
@Override... |
41 |
|
public void onCheckedChanged(CompoundButton buttonView, |
42 |
|
boolean isChecked) { |
43 |
4
|
int bID = buttonView.getId(); |
44 |
4
|
if (isChecked) { |
45 |
0
|
WhatYouEat.nutritionStats.put(bID, |
46 |
|
new StatTool(WhatYouEat.getFoodSearchIds(), bID)); |
47 |
|
} |
48 |
4
|
WhatYouEat.MY_NUTRIENTS[bID] = isChecked; |
49 |
4
|
int[] foodIds = WhatYouEat.getFoodSearchIds(); |
50 |
4
|
float[] basically = StatTool.simpleStats(foodIds, bID); |
51 |
|
|
52 |
4
|
WhatYouEat.highlightFactors.put(bID, basically); |
53 |
|
|
54 |
4
|
WhatYouEat.saveObject(WhatYouEat.MY_NUTRIENTS, "MYNUTRIENTS"); |
55 |
|
|
56 |
|
} |
57 |
|
}; |
58 |
|
|
|
|
| 80% |
Uncovered Elements: 13 (65) |
Complexity: 12 |
Complexity Density: 0,26 |
|
59 |
5
|
PreferencesScroller(Context c, int type) {... |
60 |
5
|
super(c); |
61 |
|
|
62 |
|
|
63 |
5
|
if (type == 0) { |
64 |
2
|
int[] ids = new int[25]; |
65 |
52
|
for (int i = 0; i < 25; i++) |
66 |
50
|
ids[i] = i; |
67 |
|
|
68 |
2
|
addScrollingButtons(WhatYouEat.foodGroups, ids, |
69 |
|
WhatYouEat.MY_FOOD_GROUPS, foodGroupListener, |
70 |
|
FOOD_GROUP_LABEL_COLOR, type); |
71 |
|
|
72 |
|
} |
73 |
|
|
74 |
5
|
if (type == 1) { |
75 |
|
|
76 |
2
|
int[] ids = new int[130]; |
77 |
262
|
for (int i = 0; i < 130; i++) |
78 |
260
|
ids[i] = i; |
79 |
|
|
80 |
2
|
addScrollingButtons(WhatYouEat.nutrients, ids, |
81 |
|
WhatYouEat.MY_NUTRIENTS, foodGroupListener, |
82 |
|
BUTTON_COLORS[GROUPPREFS], type); |
83 |
|
|
84 |
|
} |
85 |
5
|
if (type == 2) { |
86 |
1
|
boolean alternatecolor = true; |
87 |
26
|
for (int i = 0; i < 25; i++) { |
88 |
|
|
89 |
|
|
90 |
25
|
if (!WhatYouEat.MY_FOOD_GROUPS[i]) |
91 |
6
|
continue; |
92 |
|
|
93 |
|
|
94 |
19
|
MyFoodsScroller mfs = new MyFoodsScroller(context, i, false); |
95 |
19
|
mfs.setId(i); |
96 |
|
|
97 |
|
|
98 |
19
|
LinearLayout title = basicLinearLayout(); |
99 |
|
|
100 |
19
|
TextView groupTitle = new TextView(context); |
101 |
19
|
if (false) |
102 |
0
|
if (i % 2 == 0) { |
103 |
0
|
groupTitle.setBackgroundColor(0xff9999dd); |
104 |
|
} else { |
105 |
0
|
groupTitle.setBackgroundColor(0xffdd9999); |
106 |
|
} |
107 |
19
|
if(alternatecolor){ |
108 |
10
|
groupTitle |
109 |
|
.setBackgroundColor(0xff55cccc ); |
110 |
10
|
alternatecolor = false; |
111 |
|
}else{ |
112 |
|
|
113 |
9
|
groupTitle |
114 |
|
.setBackgroundColor( 0xff5555dd); |
115 |
9
|
alternatecolor = true; |
116 |
|
} |
117 |
19
|
groupTitle.setTextSize(22); |
118 |
19
|
groupTitle.setTextColor(0xff000000); |
119 |
19
|
groupTitle.setText(WhatYouEat.foodGroups[i]); |
120 |
19
|
groupTitle.setWidth(370); |
121 |
19
|
groupTitle.setHeight(46); |
122 |
|
|
123 |
19
|
switch (WhatYouEat.myFoods_View) { |
124 |
|
|
125 |
0
|
case 100000000: |
126 |
0
|
mfs.addView(mfs.instanceChild); |
127 |
0
|
title.addView(groupTitle); |
128 |
|
|
129 |
0
|
title.addView(mfs); |
130 |
|
|
131 |
0
|
WhatYouEat.appAccess.addView(title); |
132 |
0
|
break; |
133 |
19
|
case WhatYouEat.VIEW_VERTICAL: |
134 |
19
|
instanceChild.addView(groupTitle); |
135 |
19
|
instanceChild.addView(mfs.instanceChild); |
136 |
|
|
137 |
19
|
break; |
138 |
|
|
139 |
0
|
default: |
140 |
|
|
141 |
0
|
break; |
142 |
|
} |
143 |
|
|
144 |
|
|
145 |
|
} |
146 |
|
|
147 |
|
} |
148 |
|
|
149 |
|
} |
150 |
|
|
|
|
| 98,3% |
Uncovered Elements: 1 (59) |
Complexity: 18 |
Complexity Density: 0,49 |
|
151 |
4
|
public void addScrollingButtons(String[] buttonNames, int[] buttonIds,... |
152 |
|
boolean[] settings, View.OnClickListener listener, int BUTTON_CLR, |
153 |
|
int type) { |
154 |
|
|
155 |
|
|
156 |
4
|
buttons = new Button[buttonNames.length]; |
157 |
|
|
158 |
4
|
ckbox = new CheckBox[buttonNames.length]; |
159 |
|
|
160 |
314
|
for (int i = 0; i < buttonNames.length; i++) { |
161 |
310
|
LinearLayout layout = new LinearLayout(context); |
162 |
310
|
buttons[i] = simpleButton(); |
163 |
310
|
buttons[i].setText(buttonNames[i]); |
164 |
310
|
buttons[i].setId(buttonIds[i]); |
165 |
|
|
166 |
310
|
buttons[i].setOnClickListener(listener); |
167 |
310
|
if (type == 0) { |
168 |
50
|
buttons[i].getBackground().setColorFilter(BUTTON_CLR, |
169 |
|
PorterDuff.Mode.MULTIPLY); |
170 |
260
|
} else if (type == 1) { |
171 |
|
|
172 |
260
|
int bgColor = GENERAL; |
173 |
260
|
if (i >= 8 && i <= 14) { |
174 |
14
|
bgColor = INTERESTING; |
175 |
|
} |
176 |
260
|
if (i >= 15 && i <= 24) { |
177 |
20
|
bgColor = CARB; |
178 |
|
|
179 |
|
} |
180 |
260
|
if (i >= 25 && i <= 35) { |
181 |
22
|
bgColor = MINERAL; |
182 |
|
|
183 |
|
} |
184 |
260
|
if (i >= 36 && i <= 65) { |
185 |
60
|
bgColor = VITAMIN; |
186 |
|
|
187 |
|
} |
188 |
260
|
if (i >= 66 && i <= 84) { |
189 |
38
|
bgColor = PROTEIN; |
190 |
|
|
191 |
|
} |
192 |
260
|
if (i >= 85 && i <= 129) { |
193 |
90
|
bgColor = FAT; |
194 |
|
|
195 |
|
} |
196 |
260
|
int alpha = 150; |
197 |
260
|
int colorCombo = bgColor | (alpha << 24); |
198 |
|
|
199 |
260
|
buttons[i].getBackground().setColorFilter(colorCombo, |
200 |
|
PorterDuff.Mode.SRC_IN); |
201 |
|
|
202 |
|
} |
203 |
310
|
ckbox[i] = new CheckBox(context); |
204 |
|
|
205 |
310
|
ckbox[i].setChecked(settings[i]); |
206 |
310
|
if (type == 0) |
207 |
50
|
ckbox[i].setOnCheckedChangeListener(foodGroupPreferencesListener); |
208 |
310
|
if (type == 1) |
209 |
260
|
ckbox[i].setOnCheckedChangeListener(nutrientsPreferencesListener); |
210 |
|
|
211 |
310
|
ckbox[i].setId(buttonIds[i]); |
212 |
310
|
layout.addView(ckbox[i]); |
213 |
310
|
layout.addView(buttons[i]); |
214 |
310
|
instanceChild.addView(layout); |
215 |
|
} |
216 |
|
|
217 |
|
} |
218 |
|
|
219 |
|
} |