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