MainActivity.java
17 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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
package com.example.test;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.location.Address;
import android.location.Geocoder;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import java.io.InputStream;
import java.util.ArrayList;
import java.io.IOException;
import java.util.Calendar;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
public class MainActivity extends AppCompatActivity {
public static String start = "";
public static String from = "";
private Spinner spinner;
ArrayList<String> arrayArea;
ArrayAdapter<String> arrayAdapter;
MainActivity mThis;
GetAreaCode mArea;
Button btn_clothes;
String code;
private static final int GPS_ENABLE_REQUEST_CODE = 2000;
// 날짜 받아오는 함수 초기화
Spinner sMonth;
Spinner sDay;
Spinner sHour;
Spinner fMonth;
Spinner fDay;
Spinner fHour;
ArrayAdapter<String> ArrayAdapter2;
ArrayAdapter<String> ArrayAdapter3;
ArrayAdapter<String> ArrayAdapter4;
ImageView Angel;
Bitmap bitmap_angel;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Initialize();
}
public void Initialize() {
mThis = this;
Angel = (ImageView)findViewById(R.id.angel);
AssetManager as = getResources().getAssets();
InputStream is = null;
try{
is = as.open("angel.png");
bitmap_angel = BitmapFactory.decodeStream(is);
Angel.setImageBitmap(bitmap_angel);
is.close();
}catch(Exception e){
e.printStackTrace();
}
SelectDate();
SaveTop();
}
public void SaveTop() {
mArea = new GetAreaCode(this);
LinkedList area = new LinkedList();
area = mArea.GetTopCode();
arrayAdapter = new ArrayAdapter<>(getApplicationContext(),
android.R.layout.simple_spinner_dropdown_item, area);
spinner = (Spinner)findViewById(R.id.TopList);
spinner.setAdapter(arrayAdapter);
LinkedList finalArea = area;
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
SaveMdl(mArea.SearchTop(finalArea.get(i)));
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
}
public void SaveMdl(String Top) {
arrayArea = new ArrayList<>();
mArea = new GetAreaCode(this);
LinkedList area = new LinkedList();
area = mArea.GetMdlCode(Top);
arrayAdapter = new ArrayAdapter<>(getApplicationContext(),
android.R.layout.simple_spinner_dropdown_item, area);
spinner = (Spinner)findViewById(R.id.MdlList);
spinner.setAdapter(arrayAdapter);
LinkedList finalArea = area;
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
System.out.println(mArea.SearchMdl(finalArea.get(i), Top));
SaveLeaf(mArea.SearchMdl(finalArea.get(i), Top));
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
}
public void SaveLeaf(String Mdl) {
arrayArea = new ArrayList<>();
mArea = new GetAreaCode(this);
final RadioGroup rg = (RadioGroup)findViewById(R.id.radioGender);
LinkedList area = new LinkedList();
area = mArea.GetLeafCode(Mdl);
arrayAdapter = new ArrayAdapter<>(getApplicationContext(),
android.R.layout.simple_spinner_dropdown_item, area);
spinner = (Spinner)findViewById(R.id.LeafList);
spinner.setAdapter(arrayAdapter);
LinkedList finalArea = area;
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
code = mArea.SearchLeaf(finalArea.get(i), Mdl);
View.OnClickListener listener = new View.OnClickListener()
{
@Override
public void onClick(View v) {
start = "";
String month = sMonth.getSelectedItem().toString();
start += String.format("%2s",month.substring(0,month.length()-1)).replace(" ","0");
String day = sDay.getSelectedItem().toString();
start += String.format("%2s",day.substring(0,day.length()-1)).replace(" ","0");
String hour = sHour.getSelectedItem().toString();
start += String.format("%2s",hour.substring(0,hour.length()-1)).replace(" ","0");
from = "";
String month2 = fMonth.getSelectedItem().toString();
from += String.format("%2s",month2.substring(0,month2.length()-1)).replace(" ","0");
String day2 = fDay.getSelectedItem().toString();
from += String.format("%2s",day2.substring(0,day2.length()-1)).replace(" ","0");
String hour2 = fHour.getSelectedItem().toString();
from += String.format("%2s",hour2.substring(0,hour2.length()-1)).replace(" ","0");
String leaf = spinner.getSelectedItem().toString();
int gender = rg.getCheckedRadioButtonId();
RadioButton rb = (RadioButton)findViewById(gender);
Intent intent = new Intent(MainActivity.this, WeatherActivity.class);
intent.putExtra("code", code); //code에 있는 값 이동
intent.putExtra("start", start); //start에 있는 값 이동
intent.putExtra("from", from); //from에 있는 값 이동
intent.putExtra("leaf", leaf); //leaf에 있는 값 이동
intent.putExtra("gender", rb.getText().toString());
startActivity(intent); // 이동
}
};
Button btn_weather = (Button) findViewById(R.id.btn_weather);
btn_weather.setOnClickListener(listener);
btn_clothes = findViewById(R.id.btn_clothes);
btn_clothes.setOnClickListener(new View.OnClickListener() { //선언
@Override
public void onClick(View v) {
//MainActivity 에서 ClothesActivity 로 이동
start = "";
String month = sMonth.getSelectedItem().toString();
start += String.format("%2s",month.substring(0,month.length()-1)).replace(" ","0");
String day = sDay.getSelectedItem().toString();
start += String.format("%2s",day.substring(0,day.length()-1)).replace(" ","0");
String hour = sHour.getSelectedItem().toString();
start += String.format("%2s",hour.substring(0,hour.length()-1)).replace(" ","0");
from = "";
String month2 = fMonth.getSelectedItem().toString();
from += String.format("%2s",month2.substring(0,month2.length()-1)).replace(" ","0");
String day2 = fDay.getSelectedItem().toString();
from += String.format("%2s",day2.substring(0,day2.length()-1)).replace(" ","0");
String hour2 = fHour.getSelectedItem().toString();
from += String.format("%2s",hour2.substring(0,hour2.length()-1)).replace(" ","0");
String leaf = spinner.getSelectedItem().toString();
int gender = rg.getCheckedRadioButtonId();
RadioButton rb = (RadioButton)findViewById(gender);
Intent intent = new Intent(MainActivity.this, ClothesActivity.class);
intent.putExtra("code", code); //code에 있는 값 이동
intent.putExtra("start", start); //start에 있는 값 이동
intent.putExtra("from", from); //from에 있는 값 이동
intent.putExtra("leaf", leaf); //leaf에 있는 값 이동
intent.putExtra("code", code);//code에 있는 값 이동
intent.putExtra("gender", rb.getText().toString()); //gender에 있는 값 이동
startActivity(intent);//액티비티 이동
}
});
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
}
public void SelectDate(){
Calendar cal = Calendar.getInstance();
int month = cal.get(Calendar.MONTH) + 1;
int day = cal.get(Calendar.DAY_OF_MONTH);
int hour = cal.get(Calendar.HOUR_OF_DAY);
// *** 초기 위젯에 현재 시각 박기
LinkedList LMonth = new LinkedList();
LinkedList LDay = new LinkedList();
LinkedList LHour = new LinkedList();
LMonth.add(String.valueOf(month) + "월");
int day1 = day;
int day2 = day + 1;
int day3 = day + 2;
int day4 = day + 3;
switch(month){
case 1: case 3: case 5: case 7: case 8: case 10: case 12:
if (day4 > 31){
LMonth.add(String.valueOf(month + 1) + "월");
if (day1 > 31){
day1 -= 31;
day2 -= 31;
day3 -= 31;
day4 -= 31;
break;
} else if (day2 > 31){
day2 -= 31;
day3 -= 31;
day4 -= 31;
break;
} else if (day3 > 31){
day3 -= 31;
day4 -= 31;
break;
} else if (day4 > 31) {
day4 -= 31;
}
} else{
break;
}
case 2:
if (day4 > 28){
LMonth.add(String.valueOf(month + 1) + "월");
if (day1 > 28){
day1 -= 28;
day2 -= 28;
day3 -= 28;
day4 -= 28;
break;
} else if (day2 > 28){
day2 -= 28;
day3 -= 28;
day4 -= 28;
break;
} else if (day3 > 28){
day3 -= 28;
day4 -= 28;
break;
} else if (day4 > 28) {
day4 -= 28;
}
} else{
break;
}
case 4: case 6: case 9: case 11:
if (day4 > 30){
LMonth.add(String.valueOf(month + 1) + "월");
if (day1 > 30){
day1 -= 30;
day2 -= 30;
day3 -= 30;
day4 -= 30;
break;
} else if (day2 > 30){
day2 -= 30;
day3 -= 30;
day4 -= 30;
break;
} else if (day3 > 30){
day3 -= 30;
day4 -= 30;
break;
} else if (day4 > 30) {
day4 -= 30;
}
} else {
break;
}
}
LDay.add(String.valueOf(day1) + "일");
LDay.add(String.valueOf(day2) + "일");
LDay.add(String.valueOf(day3) + "일");
LDay.add(String.valueOf(day4) + "일");
for (int i = 1; i <= 24; i++){
LHour.add(String.valueOf(i)+"시");
}
// 월 select
ArrayAdapter2 = new ArrayAdapter<>(getApplicationContext(),
android.R.layout.simple_spinner_dropdown_item, LMonth);
sMonth = (Spinner)findViewById(R.id.start_month);
sMonth.setAdapter(ArrayAdapter2);
sMonth.setSelection(getIndex(sMonth, String.valueOf(month) + "월"));
LinkedList finalmonth = LMonth;
sMonth.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
fMonth = (Spinner)findViewById(R.id.from_month);
fMonth.setAdapter(ArrayAdapter2);
fMonth.setSelection(getIndex(fMonth, String.valueOf(month) + "월"));
LinkedList frommonth = LMonth;
fMonth.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
// 일 select
ArrayAdapter3 = new ArrayAdapter<>(getApplicationContext(),
android.R.layout.simple_spinner_dropdown_item, LDay);
sDay = (Spinner)findViewById(R.id.start_day);
sDay.setAdapter(ArrayAdapter3);
sDay.setSelection(getIndex(sDay, String.valueOf(day) + "일"));
LinkedList finalday = LDay;
sDay.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
fDay = (Spinner)findViewById(R.id.from_day);
fDay.setAdapter(ArrayAdapter3);
fDay.setSelection(getIndex(fDay, String.valueOf(day) + "일"));
LinkedList fromday = LDay;
fDay.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
// 시간 select
ArrayAdapter4 = new ArrayAdapter<>(getApplicationContext(),
android.R.layout.simple_spinner_dropdown_item, LHour);
sHour = (Spinner)findViewById(R.id.start_hour);
sHour.setAdapter(ArrayAdapter4);
sHour.setSelection(getIndex(sHour, String.valueOf(hour) + "시"));
LinkedList finalhour = LHour;
sHour.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
fHour = (Spinner)findViewById(R.id.from_hour);
fHour.setAdapter(ArrayAdapter4);
fHour.setSelection(getIndex(fHour, String.valueOf(hour) + "시"));
LinkedList fromhour = LHour;
fHour.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
}
private int getIndex(Spinner spinner, String item){
for (int i = 0; i < spinner.getCount(); i++){
if (spinner.getItemAtPosition(i).toString().equalsIgnoreCase(item)){
return i;
}
}
return 0;
}
}