MainActivity.java
1.99 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
package com.example.holidaycounter;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.TextView;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import java.io.IOException;
public class MainActivity extends AppCompatActivity {
TextView todayDate;
TextView dateName;
TextView locDate;
TextView leftDate;
String url = "http://52.200.90.192:8080/app";
String msg;
final Bundle bundle = new Bundle();
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
Bundle bundle = msg.getData();
String[] data = bundle.getString("message").split(",");
todayDate.setText(data[0]);
dateName.setText(data[1]);
locDate.setText(Integer.parseInt(data[2].substring(4, 6)) + "월 " + Integer.parseInt(data[2].substring(6)) + "일");
leftDate.setText("D-" + data[3]);
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
todayDate = findViewById(R.id.todayDate);
dateName = findViewById(R.id.dateName);
locDate = findViewById(R.id.locDate);
leftDate = findViewById(R.id.leftDate);
new Thread() {
public void run() {
Document doc = null;
try {
doc = Jsoup.connect(url).get();
Element elements = doc.select("body").first();
msg = elements.text();
bundle.putString("message", msg);
Message msg = handler.obtainMessage();
msg.setData(bundle);
handler.sendMessage(msg);
} catch (IOException e) {
e.printStackTrace();
}
}
}.start();
}
}