박지환

Get data from nodejs server

......@@ -32,6 +32,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'org.jsoup:jsoup:1.13.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
......
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.holidaycounter">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:usesCleartextTraffic="true"
android:theme="@style/Theme.HolidayCounter">
<activity
android:name=".MainActivity"
......
......@@ -3,12 +3,64 @@ 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();
}
}
\ No newline at end of file
......
......@@ -7,12 +7,51 @@
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:id="@+id/leftDate"
android:layout_width="380dp"
android:layout_height="217dp"
android:text="D-0"
android:textAlignment="center"
android:textSize="200sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.466"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.278" />
<TextView
android:id="@+id/dateName"
android:layout_width="364dp"
android:layout_height="42dp"
android:layout_marginTop="4dp"
android:text="NONE"
android:textAlignment="center"
android:textSize="32sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/leftDate" />
<TextView
android:id="@+id/locDate"
android:layout_width="210dp"
android:layout_height="28dp"
android:text="0월 0일"
android:textAlignment="center"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/dateName" />
<TextView
android:id="@+id/todayDate"
android:layout_width="78dp"
android:layout_height="19dp"
android:layout_marginEnd="2dp"
android:text="0000-00-00"
android:textAlignment="viewEnd"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
......