1 |
|
package co.harlequinmettle.healthfoodconcepts; |
2 |
|
|
3 |
|
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; |
4 |
|
import static android.widget.LinearLayout.VERTICAL; |
5 |
|
import android.content.Context; |
6 |
|
import android.graphics.PorterDuff; |
7 |
|
import android.util.TypedValue; |
8 |
|
import android.view.View; |
9 |
|
import android.view.ViewGroup; |
10 |
|
import android.view.ViewTreeObserver.OnGlobalLayoutListener; |
11 |
|
import android.widget.Button; |
12 |
|
import android.widget.EditText; |
13 |
|
import android.widget.LinearLayout; |
14 |
|
import android.widget.RadioButton; |
15 |
|
import android.widget.ScrollView; |
16 |
|
import android.widget.TextView; |
17 |
|
|
18 |
|
|
|
|
| 97% |
Uncovered Elements: 2 (66) |
Complexity: 12 |
Complexity Density: 0,24 |
|
19 |
|
public class SubScroll extends ScrollView { |
20 |
|
static boolean fromKeywordSearch; |
21 |
|
static boolean fromFoodSuggestions; |
22 |
|
static final int BUTTON_COLORS[] = { |
23 |
|
0xff77aaaa, |
24 |
|
0xff444488, |
25 |
|
0xff229922, |
26 |
|
0xff0000ff, |
27 |
|
0xff5555cc, |
28 |
|
0xffaaaaaa, |
29 |
|
0xff3333cc, |
30 |
|
0XFFDDAA00, |
31 |
|
0xffee22aa, |
32 |
|
}; |
33 |
|
public static boolean [] scrollinflated = new boolean [25]; |
34 |
|
static final int FOOD_GROUP_LABEL_COLOR = 0xff44aaff; |
35 |
|
|
36 |
|
static final int RADIO_OPTIONS_1_COLOR = 0xff77BB55; |
37 |
|
static final int RADIO_OPTIONS_2_COLOR = 0xff9999cc; |
38 |
|
static final int RADIO_OPTIONS_3_COLOR = 0xff22cc77; |
39 |
|
static final int RADIO_OPTIONS_4_COLOR = 0xff22ccff; |
40 |
|
|
41 |
|
static final int MAX_BUTTON_WIDTH = 350; |
42 |
|
|
43 |
|
static final int FOOD_RESULTS_ID = 1000055001; |
44 |
|
static final int FOOD_NUTRIENT_ID = 1055055001; |
45 |
|
static final int STATVIEW_ID = 1010101111; |
46 |
|
static final int GROUP_CHOICE_MENU_ID = 123311111; |
47 |
|
static final int NUTRIENT_CHOICE_MENU_ID = 1221000011; |
48 |
|
static final int FOOD_CHOICE_MENU_ID = 1222244011; |
49 |
|
static final int KEYWORD_SEARCH_ID = 2111211112; |
50 |
|
static final int NUTRITION_CHOICES_ID = 211333332; |
51 |
|
static final int OPTIONS_MENU_ID = 2131313222; |
52 |
|
static final int ID_PER_100_GRAMS = 343422222; |
53 |
|
static final int ID_PER_100_KCALS = 43432211; |
54 |
|
static final int ID_PER_SERVING = 44444411; |
55 |
|
static final int NUTRIENT_SEARCH_ID = 551155; |
56 |
|
static final int FOOD_REMOVAL_ID = 5555555; |
57 |
|
static final int NUTRITION_CALCULATOR_ID = 525252525; |
58 |
|
|
59 |
|
static final int NAVIGATION = 0; |
60 |
|
static final int SEARCHWORDS = 1; |
61 |
|
static final int SEARCH_RESULTS = 2; |
62 |
|
static final int NUTRIENTS = 3; |
63 |
|
static final int FOODGROUP = 4; |
64 |
|
static final int HISTOGRAM = 5; |
65 |
|
static final int SETTINGS = 6; |
66 |
|
static final int GROUPPREFS = 7; |
67 |
|
static final int NUTRPREFS = 8; |
68 |
|
|
69 |
|
static final int GENERAL = 0x002055dd; |
70 |
|
static final int INTERESTING = 0x004FBB1a; |
71 |
|
static final int CARB = 0x00ababab; |
72 |
|
static final int MINERAL = 0x00FF00CC; |
73 |
|
static final int VITAMIN = 0x00CC00FF; |
74 |
|
static final int PROTEIN = 0x00bb2255; |
75 |
|
static final int FAT = 0x00EEEE55; |
76 |
|
|
77 |
|
static int lastFoodsId; |
78 |
|
static int index; |
79 |
|
static int foodPosition; |
80 |
|
static int nutritionInfoPosition; |
81 |
|
|
82 |
|
static int scrollCount = 0; |
83 |
|
|
84 |
|
Context context; |
85 |
|
LinearLayout instanceChild; |
86 |
|
static int currentFoodID, currentNutrientID; |
87 |
|
static int currentFoodGroup; |
88 |
|
static EditText ourInput; |
89 |
|
Button[] buttons; |
90 |
|
static KeywordScroller[] foodGroupScrolls; |
91 |
|
static boolean showingResults, showingNutrients, showingStats; |
92 |
|
|
93 |
|
static boolean optionMenuShowing = false; |
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0,2 |
|
94 |
88
|
SubScroll(Context c) {... |
95 |
88
|
super(c); |
96 |
88
|
this.context = c; |
97 |
88
|
instanceChild = basicLinearLayout(); |
98 |
|
|
99 |
|
|
100 |
88
|
this.instanceChild.setId(scrollCount++); |
101 |
|
|
102 |
88
|
this.addView(instanceChild); |
103 |
|
} |
104 |
|
|
|
|
| 75% |
Uncovered Elements: 2 (8) |
Complexity: 2 |
Complexity Density: 0,33 |
|
105 |
19
|
SubScroll(Context c,boolean addChild) {... |
106 |
19
|
super(c); |
107 |
19
|
this.context = c; |
108 |
19
|
instanceChild = basicLinearLayout(); |
109 |
|
|
110 |
|
|
111 |
19
|
this.instanceChild.setId(scrollCount++); |
112 |
|
|
113 |
19
|
if( addChild) |
114 |
0
|
this.addView(instanceChild); |
115 |
|
} |
116 |
|
|
117 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 3 |
Complexity Density: 0,3 |
|
118 |
5
|
public void addScrollingButtons(String[] buttonNames, int[] buttonIds,... |
119 |
|
View.OnClickListener listener, int BUTTON_CLR) { |
120 |
|
|
121 |
5
|
buttons = new Button[buttonNames.length]; |
122 |
|
|
123 |
207
|
for (int i = 0; i < buttonNames.length; i++) { |
124 |
202
|
buttons[i] = simpleButton(); |
125 |
202
|
buttons[i].setText(buttonNames[i]); |
126 |
202
|
buttons[i].setId(buttonIds[i]); |
127 |
|
|
128 |
202
|
buttons[i].setOnClickListener(listener); |
129 |
202
|
if(BUTTON_CLR!=0){ |
130 |
199
|
buttons[i].getBackground().setColorFilter(BUTTON_CLR, |
131 |
|
PorterDuff.Mode.MULTIPLY); |
132 |
|
} |
133 |
202
|
instanceChild.addView(buttons[i]); |
134 |
|
} |
135 |
|
|
136 |
|
|
137 |
5
|
this.getViewTreeObserver().addOnGlobalLayoutListener( |
138 |
|
new RandomScroller(this)); |
139 |
|
|
140 |
|
} |
141 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
142 |
9
|
public static void resetDisplayConditions() {... |
143 |
9
|
showingStats = false; |
144 |
9
|
lastFoodsId = 0; |
145 |
9
|
showingNutrients = false; |
146 |
9
|
showingResults = false; |
147 |
|
} |
148 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0,17 |
|
149 |
2476
|
public static Button simpleButton() {... |
150 |
2476
|
Button button = new Button(WhatYouEat.ctx); |
151 |
2476
|
button.setHeight(WRAP_CONTENT); |
152 |
2476
|
button.setMaxWidth(MAX_BUTTON_WIDTH); |
153 |
2476
|
button.setMaxLines(5); |
154 |
2476
|
button.setTextSize(TypedValue.COMPLEX_UNIT_DIP,WhatYouEat.TEXT_MED); |
155 |
2476
|
return button; |
156 |
|
} |
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0,17 |
|
157 |
30
|
public static RadioButton simpleRadioButton() {... |
158 |
30
|
RadioButton button = new RadioButton(WhatYouEat.ctx); |
159 |
30
|
button.setHeight(WRAP_CONTENT); |
160 |
30
|
button.setMaxWidth(MAX_BUTTON_WIDTH); |
161 |
30
|
button.setMaxLines(5); |
162 |
30
|
button.setTextSize(TypedValue.COMPLEX_UNIT_DIP,WhatYouEat.TEXT_SMALL); |
163 |
30
|
return button; |
164 |
|
} |
165 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0,17 |
|
166 |
121
|
public static TextView textView() {... |
167 |
121
|
TextView ta = new TextView(WhatYouEat.ctx); |
168 |
121
|
ta.setHeight(WRAP_CONTENT); |
169 |
121
|
ta.setMaxWidth(MAX_BUTTON_WIDTH); |
170 |
121
|
ta.setMaxLines(5); |
171 |
121
|
ta.setTextSize(TypedValue.COMPLEX_UNIT_DIP,WhatYouEat.TEXT_MED); |
172 |
121
|
return ta; |
173 |
|
} |
174 |
|
|
175 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0,2 |
|
176 |
194
|
public LinearLayout basicLinearLayout() {... |
177 |
194
|
LinearLayout basic = new LinearLayout(context); |
178 |
194
|
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams( |
179 |
|
WRAP_CONTENT, WRAP_CONTENT); |
180 |
194
|
basic.setLayoutParams(params); |
181 |
194
|
basic.setOrientation(VERTICAL); |
182 |
194
|
return basic; |
183 |
|
} |
184 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 3 |
Complexity Density: 0,75 |
|
185 |
|
public class RandomScroller implements OnGlobalLayoutListener { |
186 |
|
ScrollView scroll; |
187 |
|
boolean hasBeenSet = false; |
188 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
189 |
5
|
public RandomScroller(ScrollView scroll) {... |
190 |
5
|
this.scroll = scroll; |
191 |
|
} |
192 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0,67 |
|
193 |
358
|
public void onGlobalLayout() {... |
194 |
358
|
if (!hasBeenSet) { |
195 |
5
|
scroll.scrollTo(0, |
196 |
|
(int) (Math.random() * scroll.getHeight() * 6)); |
197 |
5
|
hasBeenSet = true; |
198 |
|
} |
199 |
|
} |
200 |
|
} |
201 |
|
|
202 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
203 |
85
|
static EditText editText(String hint) {... |
204 |
85
|
EditText editText = new EditText(WhatYouEat.ctx); |
205 |
|
|
206 |
85
|
editText.setHint(hint); |
207 |
85
|
return editText; |
208 |
|
} |
209 |
|
|
210 |
|
} |