MainActivity.java
2.8 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
package com.example.holidaycounter;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import android.app.Activity;
import android.graphics.Point;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Display;
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;
TextView title;
String url = "http://www.holiday-counter.tk:8080/app";
String msg;
final Bundle bundle = new Bundle();
int standardSize_X, standardSize_Y;
float density;
public void getStandardSize() {
Point ScreenSize = getScreenSize(this);
density = getResources().getDisplayMetrics().density;
standardSize_X = (int) (ScreenSize.x / density);
standardSize_Y = (int) (ScreenSize.y / density);
}
public Point getScreenSize(Activity activity) {
Display display = activity.getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
return size;
}
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(data[2].substring(0, 4) + "년 " + data[2].substring(4, 6) + "월 " + data[2].substring(6) + "일");
leftDate.setText("D-" + data[3]);
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar actionBar = getSupportActionBar();
actionBar.hide();
todayDate = findViewById(R.id.todayDate);
dateName = findViewById(R.id.dateName);
locDate = findViewById(R.id.locDate);
leftDate = findViewById(R.id.leftDate);
title = findViewById(R.id.title);
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();
}
}