Commit 6d661f0e7b67af2f31692781ea27194c91c9fd7f

Authored by junsang
1 parent a7ab6b18f0

print pm 2.5 in seoul by android app

Showing 11 changed files with 69 additions and 5 deletions

.idea/gradle.xml View file @ 6d661f0
... ... @@ -11,6 +11,7 @@
11 11 <set>
12 12 <option value="$PROJECT_DIR$" />
13 13 <option value="$PROJECT_DIR$/app" />
  14 + <option value="$PROJECT_DIR$/jsoup-1.8.3" />
14 15 </set>
15 16 </option>
16 17 </GradleProjectSettings>
.idea/modules.xml View file @ 6d661f0
... ... @@ -4,6 +4,7 @@
4 4 <modules>
5 5 <module fileurl="file://$PROJECT_DIR$/Simsimi.iml" filepath="$PROJECT_DIR$/Simsimi.iml" />
6 6 <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
  7 + <module fileurl="file://$PROJECT_DIR$/jsoup-1.8.3/jsoup-1.8.3.iml" filepath="$PROJECT_DIR$/jsoup-1.8.3/jsoup-1.8.3.iml" />
7 8 </modules>
8 9 </component>
9 10 </project>
... ... @@ -97,6 +97,7 @@
97 97 <orderEntry type="library" exported="" name="design-23.1.0" level="project" />
98 98 <orderEntry type="library" exported="" name="appcompat-v7-23.1.0" level="project" />
99 99 <orderEntry type="library" exported="" name="support-annotations-23.1.0" level="project" />
  100 + <orderEntry type="module" module-name="jsoup-1.8.3" exported="" />
100 101 </component>
101 102 </module>
app/build.gradle View file @ 6d661f0
... ... @@ -20,9 +20,10 @@
20 20 }
21 21  
22 22 dependencies {
23   - compile fileTree(dir: 'libs', include: ['*.jar'])
  23 + compile fileTree(include: ['*.jar'], dir: 'libs')
24 24 testCompile 'junit:junit:4.12'
25 25 compile 'com.android.support:appcompat-v7:23.1.0'
26 26 compile 'com.android.support:design:23.1.0'
  27 + compile project(':jsoup-1.8.3')
27 28 }
app/src/main/java/com/example/junsang/simsimi/MainActivity.java View file @ 6d661f0
... ... @@ -9,13 +9,20 @@
9 9  
10 10 import org.json.JSONArray;
11 11 import org.json.JSONException;
  12 +//import org.w3c.dom.Document;
12 13  
  14 +import org.jsoup.Jsoup;
  15 +import org.jsoup.nodes.Document;
  16 +import org.jsoup.nodes.Element;
  17 +import org.jsoup.select.Elements;
  18 +
13 19 import java.io.BufferedReader;
14 20 import java.io.IOException;
15 21 import java.io.InputStream;
16 22 import java.io.InputStreamReader;
17 23 import java.net.HttpURLConnection;
18 24 import java.net.URL;
  25 +import java.util.Iterator;
19 26  
20 27  
21 28 public class MainActivity extends ActionBarActivity {
... ... @@ -24,6 +31,14 @@
24 31 String results;
25 32 TextView pm_tv;
26 33  
  34 + //
  35 + public String parse_pm(String str){
  36 + String parse_1 = str.split("<td id=\'cur_pm25\' class=\'tdcur\' style=\'font-weight:bold;font-size:11px;\' align=center>")[1];
  37 + String parse_2 = parse_1.split("</td>")[0];
  38 +
  39 + return parse_2;
  40 + }
  41 +
27 42 @Override
28 43 protected void onCreate(Bundle savedInstanceState) {
29 44 super.onCreate(savedInstanceState);
... ... @@ -74,7 +89,22 @@
74 89 e.printStackTrace();
75 90 }
76 91  
77   - pm_tv.setText("결과값");
  92 + jsonStr = parse_pm(result);
  93 + /*
  94 + Document doc = Jsoup.parse(result);
  95 + Elements rows = doc.select("td.line-content ");
  96 +
  97 +
  98 + for (Element row : rows) {
  99 + Iterator<Element> iterElem = row.getElementsByTag("div").iterator();
  100 + StringBuilder builder = new StringBuilder();
  101 + System.out.println(builder);
  102 + builder.append(iterElem.next());
  103 + jsonStr= jsonStr+builder.toString();
  104 + }*/
  105 + // String testStr = (?:"<td id='cur_pm25' class='tdcur' style='font-weight:bold;font-size:11px;' align=center>") result;
  106 +
  107 + pm_tv.setText("지금 서울의 초미세먼지 농도는 "+jsonStr+"㎍/㎥야~");
78 108 }
79 109 }
80 110  
app/src/main/res/layout/activity_main.xml View file @ 6d661f0
... ... @@ -10,12 +10,13 @@
10 10 android:layout_height="match_parent"
11 11 android:orientation="vertical">
12 12  
13   - <LinearLayout
  13 + <RelativeLayout
14 14 android:orientation="horizontal"
15 15 android:layout_width="match_parent"
16 16 android:layout_height="match_parent">
17 17  
18 18 <ImageView
  19 + android:layout_marginTop="200dp"
19 20 android:layout_height="160dp"
20 21 android:layout_width="160dp"
21 22 android:background="@drawable/image1"/>
... ... @@ -32,7 +33,7 @@
32 33  
33 34  
34 35  
35   - </LinearLayout>
  36 + </RelativeLayout>
36 37  
37 38 </ScrollView>
38 39  
app/src/main/res/layout/content_main.xml View file @ 6d661f0
... ... @@ -16,6 +16,7 @@
16 16 android:orientation="vertical">
17 17  
18 18 <ImageView
  19 + android:layout_marginTop="100dp"
19 20 android:layout_height="160dp"
20 21 android:layout_width="160dp"
21 22 android:background="@drawable/image1"/>
jsoup-1.8.3/build.gradle View file @ 6d661f0
  1 +configurations.create("default")
  2 +artifacts.add("default", file('jsoup-1.8.3.jar'))
jsoup-1.8.3/jsoup-1.8.3.iml View file @ 6d661f0
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<module external.linked.project.id=":jsoup-1.8.3" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="Simsimi" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
  3 + <component name="FacetManager">
  4 + <facet type="android-gradle" name="Android-Gradle">
  5 + <configuration>
  6 + <option name="GRADLE_PROJECT_PATH" value=":jsoup-1.8.3" />
  7 + </configuration>
  8 + </facet>
  9 + <facet type="java-gradle" name="Java-Gradle">
  10 + <configuration>
  11 + <option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
  12 + <option name="BUILDABLE" value="false" />
  13 + </configuration>
  14 + </facet>
  15 + </component>
  16 + <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="true">
  17 + <exclude-output />
  18 + <content url="file://$MODULE_DIR$">
  19 + <excludeFolder url="file://$MODULE_DIR$/.gradle" />
  20 + <excludeFolder url="file://$MODULE_DIR$/build" />
  21 + </content>
  22 + <orderEntry type="inheritedJdk" />
  23 + <orderEntry type="sourceFolder" forTests="false" />
  24 + <orderEntry type="library" exported="" name="jsoup-1.8.3.jsoup-1.8.3" level="project" />
  25 + </component>
  26 +</module>
jsoup-1.8.3/jsoup-1.8.3.jar View file @ 6d661f0

No preview for this file type

settings.gradle View file @ 6d661f0
1   -include ':app'
  1 +include ':app', ':jsoup-1.8.3'