-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpage_human_1.java
More file actions
378 lines (352 loc) · 15.2 KB
/
page_human_1.java
File metadata and controls
378 lines (352 loc) · 15.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
package com.ryzen.remedi;
import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
import android.media.MediaPlayer;
import android.os.AsyncTask;
import android.os.Vibrator;
import android.support.v4.view.GestureDetectorCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.View.OnTouchListener;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.ScrollView;
import android.widget.TextView;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class page_human_1 extends AppCompatActivity{
ImageView info_bg;
ImageView homeBtn;
ImageView backBtn;
Vibrator vibrator;
MediaPlayer popSound;
ScrollView sw;
TextView quoteText;
final String url = "http://api.forismatic.com/api/1.0/?method=getQuote&format=text&lang=en";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_page_human_1);
info_bg = (ImageView) findViewById(R.id.info_show);
popSound=MediaPlayer.create(page_human_1.this, R.raw.pop_sound);
homeBtn = (ImageView) findViewById(R.id.homeBtn);
backBtn = (ImageView) findViewById(R.id.backBtn);
// Quote Text
quoteText = (TextView) findViewById(R.id.quoteText);
final Typeface font = Typeface.createFromAsset(getAssets(), "fonts/antonio_reg.ttf");
quoteText.setTypeface(font);
// Executes Forismatic API
new getAPI().execute(url);
sw = (ScrollView) findViewById(R.id.page_human_scroll);
// Buttons changes color on click and hold
final ImageView coughBtn = (ImageView) findViewById(R.id.cough_btn);
coughBtn.setOnTouchListener(new View.OnTouchListener(){
@Override
public boolean onTouch(View view, MotionEvent event) {
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
showInfo();
coughBtn.setImageResource(R.drawable.human_symptom_blue_cough);
info_bg.setImageResource(R.drawable.human_symptom_info_cough);
break;
case MotionEvent.ACTION_UP:
hideInfo();
coughBtn.setImageResource(R.drawable.human_symptom_cough);
break;
}
return true;
}
});
final ImageView congestBtn = (ImageView) findViewById(R.id.congest_btn);
congestBtn.setOnTouchListener(new View.OnTouchListener(){
@Override
public boolean onTouch(View view, MotionEvent event) {
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
showInfo();
congestBtn.setImageResource(R.drawable.human_symptom_blue_congestion);
info_bg.setImageResource(R.drawable.human_symptom_info_congest);
break;
case MotionEvent.ACTION_UP:
hideInfo();
congestBtn.setImageResource(R.drawable.human_symptom_congestion);
break;
}
return true;
}
});
final ImageView backstrainBtn = (ImageView) findViewById(R.id.back_btn);
backstrainBtn.setOnTouchListener(new View.OnTouchListener(){
@Override
public boolean onTouch(View view, MotionEvent event) {
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
showInfo();
backstrainBtn.setImageResource(R.drawable.human_symptom_blue_backstrain);
info_bg.setImageResource(R.drawable.human_symptom_info_back);
break;
case MotionEvent.ACTION_UP:
hideInfo();
backstrainBtn.setImageResource(R.drawable.human_symptom_backstrain);
break;
}
return true;
}
});
final ImageView throatBtn = (ImageView) findViewById(R.id.throat_btn);
throatBtn.setOnTouchListener(new View.OnTouchListener(){
@Override
public boolean onTouch(View view, MotionEvent event) {
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
showInfo();
throatBtn.setImageResource(R.drawable.human_symptom_blue_sore);
info_bg.setImageResource(R.drawable.human_symptom_info_sore);
break;
case MotionEvent.ACTION_UP:
hideInfo();
throatBtn.setImageResource(R.drawable.human_symptom_sorethroat);
break;
}
return true;
}
});
final ImageView crampBtn = (ImageView) findViewById(R.id.cramp_btn);
crampBtn.setOnTouchListener(new View.OnTouchListener(){
@Override
public boolean onTouch(View view, MotionEvent event) {
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
showInfo();
crampBtn.setImageResource(R.drawable.human_symptom_blue_cramping);
info_bg.setImageResource(R.drawable.human_symptom_info_cramp);
break;
case MotionEvent.ACTION_UP:
hideInfo();
crampBtn.setImageResource(R.drawable.human_symptom_cramping);
break;
}
return true;
}
});
final ImageView dizzyBtn = (ImageView) findViewById(R.id.dizzy_btn);
dizzyBtn.setOnTouchListener(new View.OnTouchListener(){
@Override
public boolean onTouch(View view, MotionEvent event) {
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
showInfo();
dizzyBtn.setImageResource(R.drawable.human_symptom_blue_dizzy);
info_bg.setImageResource(R.drawable.human_symptom_info_dizzy);
break;
case MotionEvent.ACTION_UP:
hideInfo();
dizzyBtn.setImageResource(R.drawable.human_symptom_dizziness);
break;
}
return true;
}
});
final ImageView runnyBtn = (ImageView) findViewById(R.id.runny_btn);
runnyBtn.setOnTouchListener(new View.OnTouchListener(){
@Override
public boolean onTouch(View view, MotionEvent event) {
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
showInfo();
runnyBtn.setImageResource(R.drawable.human_symptom_blue_runny);
info_bg.setImageResource(R.drawable.human_symptom_info_runny);
break;
case MotionEvent.ACTION_UP:
hideInfo();
runnyBtn.setImageResource(R.drawable.human_symptom_runnynose);
break;
}
return true;
}
});
final ImageView feverBtn = (ImageView) findViewById(R.id.fever_btn);
feverBtn.setOnTouchListener(new View.OnTouchListener(){
@Override
public boolean onTouch(View view, MotionEvent event) {
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
showInfo();
feverBtn.setImageResource(R.drawable.human_symptom_blue_fever);
info_bg.setImageResource(R.drawable.human_symptom_info_fever);
break;
case MotionEvent.ACTION_UP:
hideInfo();
feverBtn.setImageResource(R.drawable.human_symptom_fever);
break;
}
return true;
}
});
final ImageView rashBtn = (ImageView) findViewById(R.id.rash_btn);
rashBtn.setOnTouchListener(new View.OnTouchListener(){
@Override
public boolean onTouch(View view, MotionEvent event) {
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
showInfo();
rashBtn.setImageResource(R.drawable.human_symptom_blue_rash);
info_bg.setImageResource(R.drawable.human_symptom_info_rash);
break;
case MotionEvent.ACTION_UP:
hideInfo();
rashBtn.setImageResource(R.drawable.human_symptom_rash);
break;
}
return true;
}
});
final ImageView fatigueBtn = (ImageView) findViewById(R.id.fatigue_btn);
fatigueBtn.setOnTouchListener(new View.OnTouchListener(){
@Override
public boolean onTouch(View view, MotionEvent event) {
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
showInfo();
fatigueBtn.setImageResource(R.drawable.human_symptom_blue_fatigue);
info_bg.setImageResource(R.drawable.human_symptom_info_fatigue);
break;
case MotionEvent.ACTION_UP:
hideInfo();
fatigueBtn.setImageResource(R.drawable.human_symptom_fatigue);
break;
}
return true;
}
});
final ImageView itchyBtn = (ImageView) findViewById(R.id.itchy_btn);
itchyBtn.setOnTouchListener(new View.OnTouchListener(){
@Override
public boolean onTouch(View view, MotionEvent event) {
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
showInfo();
itchyBtn.setImageResource(R.drawable.human_symptom_blue_itchy);
info_bg.setImageResource(R.drawable.human_symptom_info_itchy);
break;
case MotionEvent.ACTION_UP:
hideInfo();
itchyBtn.setImageResource(R.drawable.human_symptom_itchyeye);
break;
}
return true;
}
});
final ImageView nauseaBtn = (ImageView) findViewById(R.id.nausea_btn);
nauseaBtn.setOnTouchListener(new View.OnTouchListener(){
@Override
public boolean onTouch(View view, MotionEvent event) {
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
showInfo();
nauseaBtn.setImageResource(R.drawable.human_symptom_blue_nausea);
info_bg.setImageResource(R.drawable.human_symptom_info_nausea);
break;
case MotionEvent.ACTION_UP:
hideInfo();
nauseaBtn.setImageResource(R.drawable.human_symptom_nausea);
break;
}
return true;
}
});
final ImageView backBtn = (ImageView) findViewById(R.id.backBtn);
backBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
backBtn.setImageResource(R.drawable.back_btn_black);
Intent intent = new Intent(page_human_1.this, MainActivity.class);
startActivity(intent);
finish();
}
});
final ImageView homeBtn = (ImageView) findViewById(R.id.homeBtn);
homeBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
homeBtn.setImageResource(R.drawable.home_btn_black);
Intent intent = new Intent(page_human_1.this, MainActivity.class);
startActivity(intent);
finish();
}
});
}
// Method to show remedies for symptoms
public void showInfo(){
popSound.start();
sw.fullScroll(View.FOCUS_DOWN);
info_bg.setVisibility(View.VISIBLE);
homeBtn.setVisibility(View.INVISIBLE);
backBtn.setVisibility(View.INVISIBLE);
sw.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
}
// Method to hide remedies
public void hideInfo(){
info_bg.setVisibility(View.INVISIBLE);
homeBtn.setVisibility(View.VISIBLE);
backBtn.setVisibility(View.VISIBLE);
sw.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return false;
}
});
}
private final String USER_AGENT = "Mozilla/5.0";
// Class to connect to API
class getAPI extends AsyncTask<String, Void, String> {
private Exception exception;
@Override
protected String doInBackground(String... url) {
try{
URL obj = new URL(url[0]);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
//add request header
con.setRequestMethod("POST");
con.setRequestProperty("User-Agent", USER_AGENT);
con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
// Send post request
con.setDoOutput(true);
int responseCode = con.getResponseCode();
System.out.println("\nSending 'POST' request to URL : " + url);
System.out.println("Response Code : " + responseCode);
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
//print result
return response.toString();
}
catch(Exception e){
this.exception = e;
return null;
}
}
protected void onPostExecute(String response){
if (exception != null)
quoteText.setText(exception.toString());
else
quoteText.setText(response.toString());
}
}
}