Showing
4 changed files
with
98 additions
and
5 deletions
| ... | @@ -32,6 +32,7 @@ dependencies { | ... | @@ -32,6 +32,7 @@ dependencies { |
| 32 | implementation 'androidx.appcompat:appcompat:1.3.0' | 32 | implementation 'androidx.appcompat:appcompat:1.3.0' |
| 33 | implementation 'com.google.android.material:material:1.4.0' | 33 | implementation 'com.google.android.material:material:1.4.0' |
| 34 | implementation 'androidx.constraintlayout:constraintlayout:2.0.4' | 34 | implementation 'androidx.constraintlayout:constraintlayout:2.0.4' |
| 35 | + implementation 'org.jsoup:jsoup:1.13.1' | ||
| 35 | testImplementation 'junit:junit:4.13.2' | 36 | testImplementation 'junit:junit:4.13.2' |
| 36 | androidTestImplementation 'androidx.test.ext:junit:1.1.3' | 37 | androidTestImplementation 'androidx.test.ext:junit:1.1.3' |
| 37 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' | 38 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' | ... | ... |
| 1 | <?xml version="1.0" encoding="utf-8"?> | 1 | <?xml version="1.0" encoding="utf-8"?> |
| 2 | <manifest xmlns:android="http://schemas.android.com/apk/res/android" | 2 | <manifest xmlns:android="http://schemas.android.com/apk/res/android" |
| 3 | package="com.example.holidaycounter"> | 3 | package="com.example.holidaycounter"> |
| 4 | - | 4 | + <uses-permission android:name="android.permission.INTERNET"/> |
| 5 | <application | 5 | <application |
| 6 | android:allowBackup="true" | 6 | android:allowBackup="true" |
| 7 | android:icon="@mipmap/ic_launcher" | 7 | android:icon="@mipmap/ic_launcher" |
| 8 | android:label="@string/app_name" | 8 | android:label="@string/app_name" |
| 9 | android:roundIcon="@mipmap/ic_launcher_round" | 9 | android:roundIcon="@mipmap/ic_launcher_round" |
| 10 | android:supportsRtl="true" | 10 | android:supportsRtl="true" |
| 11 | + android:usesCleartextTraffic="true" | ||
| 11 | android:theme="@style/Theme.HolidayCounter"> | 12 | android:theme="@style/Theme.HolidayCounter"> |
| 12 | <activity | 13 | <activity |
| 13 | android:name=".MainActivity" | 14 | android:name=".MainActivity" | ... | ... |
| ... | @@ -3,12 +3,64 @@ package com.example.holidaycounter; | ... | @@ -3,12 +3,64 @@ package com.example.holidaycounter; |
| 3 | import androidx.appcompat.app.AppCompatActivity; | 3 | import androidx.appcompat.app.AppCompatActivity; |
| 4 | 4 | ||
| 5 | import android.os.Bundle; | 5 | import android.os.Bundle; |
| 6 | +import android.os.Handler; | ||
| 7 | +import android.os.Message; | ||
| 8 | +import android.widget.TextView; | ||
| 9 | + | ||
| 10 | +import org.jsoup.Jsoup; | ||
| 11 | +import org.jsoup.nodes.Document; | ||
| 12 | +import org.jsoup.nodes.Element; | ||
| 13 | + | ||
| 14 | +import java.io.IOException; | ||
| 6 | 15 | ||
| 7 | public class MainActivity extends AppCompatActivity { | 16 | public class MainActivity extends AppCompatActivity { |
| 17 | + TextView todayDate; | ||
| 18 | + TextView dateName; | ||
| 19 | + TextView locDate; | ||
| 20 | + TextView leftDate; | ||
| 21 | + String url = "http://52.200.90.192:8080/app"; | ||
| 22 | + String msg; | ||
| 23 | + final Bundle bundle = new Bundle(); | ||
| 24 | + | ||
| 25 | + | ||
| 26 | + Handler handler = new Handler() { | ||
| 27 | + @Override | ||
| 28 | + public void handleMessage(Message msg) { | ||
| 29 | + Bundle bundle = msg.getData(); | ||
| 30 | + String[] data = bundle.getString("message").split(","); | ||
| 31 | + todayDate.setText(data[0]); | ||
| 32 | + dateName.setText(data[1]); | ||
| 33 | + locDate.setText(Integer.parseInt(data[2].substring(4, 6)) + "월 " + Integer.parseInt(data[2].substring(6)) + "일"); | ||
| 34 | + leftDate.setText("D-" + data[3]); | ||
| 35 | + } | ||
| 36 | + }; | ||
| 8 | 37 | ||
| 9 | @Override | 38 | @Override |
| 10 | protected void onCreate(Bundle savedInstanceState) { | 39 | protected void onCreate(Bundle savedInstanceState) { |
| 40 | + | ||
| 11 | super.onCreate(savedInstanceState); | 41 | super.onCreate(savedInstanceState); |
| 12 | setContentView(R.layout.activity_main); | 42 | setContentView(R.layout.activity_main); |
| 43 | + | ||
| 44 | + todayDate = findViewById(R.id.todayDate); | ||
| 45 | + dateName = findViewById(R.id.dateName); | ||
| 46 | + locDate = findViewById(R.id.locDate); | ||
| 47 | + leftDate = findViewById(R.id.leftDate); | ||
| 48 | + new Thread() { | ||
| 49 | + public void run() { | ||
| 50 | + Document doc = null; | ||
| 51 | + try { | ||
| 52 | + doc = Jsoup.connect(url).get(); | ||
| 53 | + Element elements = doc.select("body").first(); | ||
| 54 | + msg = elements.text(); | ||
| 55 | + bundle.putString("message", msg); | ||
| 56 | + Message msg = handler.obtainMessage(); | ||
| 57 | + msg.setData(bundle); | ||
| 58 | + handler.sendMessage(msg); | ||
| 59 | + } catch (IOException e) { | ||
| 60 | + e.printStackTrace(); | ||
| 61 | + } | ||
| 62 | + } | ||
| 63 | + }.start(); | ||
| 13 | } | 64 | } |
| 65 | + | ||
| 14 | } | 66 | } |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -7,12 +7,51 @@ | ... | @@ -7,12 +7,51 @@ |
| 7 | tools:context=".MainActivity"> | 7 | tools:context=".MainActivity"> |
| 8 | 8 | ||
| 9 | <TextView | 9 | <TextView |
| 10 | - android:layout_width="wrap_content" | 10 | + android:id="@+id/leftDate" |
| 11 | - android:layout_height="wrap_content" | 11 | + android:layout_width="380dp" |
| 12 | - android:text="Hello World!" | 12 | + android:layout_height="217dp" |
| 13 | + android:text="D-0" | ||
| 14 | + android:textAlignment="center" | ||
| 15 | + android:textSize="200sp" | ||
| 13 | app:layout_constraintBottom_toBottomOf="parent" | 16 | app:layout_constraintBottom_toBottomOf="parent" |
| 17 | + app:layout_constraintHorizontal_bias="0.466" | ||
| 14 | app:layout_constraintLeft_toLeftOf="parent" | 18 | app:layout_constraintLeft_toLeftOf="parent" |
| 15 | app:layout_constraintRight_toRightOf="parent" | 19 | app:layout_constraintRight_toRightOf="parent" |
| 16 | - app:layout_constraintTop_toTopOf="parent" /> | 20 | + app:layout_constraintTop_toTopOf="parent" |
| 21 | + app:layout_constraintVertical_bias="0.278" /> | ||
| 22 | + | ||
| 23 | + <TextView | ||
| 24 | + android:id="@+id/dateName" | ||
| 25 | + android:layout_width="364dp" | ||
| 26 | + android:layout_height="42dp" | ||
| 27 | + android:layout_marginTop="4dp" | ||
| 28 | + android:text="NONE" | ||
| 29 | + android:textAlignment="center" | ||
| 30 | + android:textSize="32sp" | ||
| 31 | + app:layout_constraintEnd_toEndOf="parent" | ||
| 32 | + app:layout_constraintHorizontal_bias="0.498" | ||
| 33 | + app:layout_constraintStart_toStartOf="parent" | ||
| 34 | + app:layout_constraintTop_toBottomOf="@+id/leftDate" /> | ||
| 35 | + | ||
| 36 | + <TextView | ||
| 37 | + android:id="@+id/locDate" | ||
| 38 | + android:layout_width="210dp" | ||
| 39 | + android:layout_height="28dp" | ||
| 40 | + android:text="0월 0일" | ||
| 41 | + android:textAlignment="center" | ||
| 42 | + android:textSize="18sp" | ||
| 43 | + app:layout_constraintEnd_toEndOf="parent" | ||
| 44 | + app:layout_constraintStart_toStartOf="parent" | ||
| 45 | + app:layout_constraintTop_toBottomOf="@+id/dateName" /> | ||
| 46 | + | ||
| 47 | + <TextView | ||
| 48 | + android:id="@+id/todayDate" | ||
| 49 | + android:layout_width="78dp" | ||
| 50 | + android:layout_height="19dp" | ||
| 51 | + android:layout_marginEnd="2dp" | ||
| 52 | + android:text="0000-00-00" | ||
| 53 | + android:textAlignment="viewEnd" | ||
| 54 | + app:layout_constraintBottom_toBottomOf="parent" | ||
| 55 | + app:layout_constraintEnd_toEndOf="parent" /> | ||
| 17 | 56 | ||
| 18 | </androidx.constraintlayout.widget.ConstraintLayout> | 57 | </androidx.constraintlayout.widget.ConstraintLayout> |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment