Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added app/.DS_Store
Binary file not shown.
Empty file modified app/.gitignore
100644 → 100755
Empty file.
146 changes: 146 additions & 0 deletions app/app.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
<option name="GRADLE_PROJECT_PATH" value=":app" />
</configuration>
</facet>
<facet type="android" name="Android">
<configuration>
<option name="SELECTED_BUILD_VARIANT" value="debug" />
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
<afterSyncTasks>
<task>generateDebugSources</task>
</afterSyncTasks>
<option name="ALLOW_USER_CONFIGURATION" value="false" />
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7">
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/test/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/build-info" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/builds" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/check-manifest" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-runtime-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-verifier" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-resources" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-support" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaPrecompile" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/prebuild" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/reload-dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/split-apk" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/splits-support" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/tmp" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 26 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="com.android.support:support-media-compat-26.1.0" level="project" />
<orderEntry type="library" scope="TEST" name="junit:junit:4.12@jar" level="project" />
<orderEntry type="library" name="android.arch.lifecycle:common:1.0.0@jar" level="project" />
<orderEntry type="library" scope="TEST" name="com.android.support.test.espresso:espresso-core-3.0.1" level="project" />
<orderEntry type="library" name="com.android.support:support-fragment-26.1.0" level="project" />
<orderEntry type="library" scope="TEST" name="javax.inject:javax.inject:1@jar" level="project" />
<orderEntry type="library" scope="TEST" name="com.squareup:javawriter:2.1.1@jar" level="project" />
<orderEntry type="library" name="com.android.support:support-vector-drawable-26.1.0" level="project" />
<orderEntry type="library" name="android.arch.lifecycle:runtime-1.0.0" level="project" />
<orderEntry type="library" name="com.android.support:appcompat-v7-26.1.0" level="project" />
<orderEntry type="library" name="com.android.support:support-annotations:26.1.0@jar" level="project" />
<orderEntry type="library" name="com.android.support.constraint:constraint-layout-solver:1.0.2@jar" level="project" />
<orderEntry type="library" name="com.android.support:support-core-utils-26.1.0" level="project" />
<orderEntry type="library" name="com.android.support.constraint:constraint-layout-1.0.2" level="project" />
<orderEntry type="library" name="com.android.support:support-core-ui-26.1.0" level="project" />
<orderEntry type="library" scope="TEST" name="com.android.support.test:runner-1.0.1" level="project" />
<orderEntry type="library" scope="TEST" name="com.android.support.test:rules-1.0.1" level="project" />
<orderEntry type="library" scope="TEST" name="com.google.code.findbugs:jsr305:2.0.1@jar" level="project" />
<orderEntry type="library" scope="TEST" name="com.android.support.test.espresso:espresso-idling-resource-3.0.1" level="project" />
<orderEntry type="library" scope="TEST" name="org.hamcrest:hamcrest-core:1.3@jar" level="project" />
<orderEntry type="library" name="com.android.support:support-compat-26.1.0" level="project" />
<orderEntry type="library" name="android.arch.core:common:1.0.0@jar" level="project" />
<orderEntry type="library" scope="TEST" name="org.hamcrest:hamcrest-library:1.3@jar" level="project" />
<orderEntry type="library" scope="TEST" name="org.hamcrest:hamcrest-integration:1.3@jar" level="project" />
<orderEntry type="library" name="com.android.support:support-v4-26.1.0" level="project" />
<orderEntry type="library" scope="TEST" name="net.sf.kxml:kxml2:2.3.0@jar" level="project" />
<orderEntry type="library" name="com.android.support:animated-vector-drawable-26.1.0" level="project" />
</component>
</module>
Empty file modified app/build.gradle
100644 → 100755
Empty file.
Empty file modified app/proguard-rules.pro
100644 → 100755
Empty file.
Binary file added app/src/.DS_Store
Binary file not shown.
Empty file.
Binary file added app/src/main/.DS_Store
Binary file not shown.
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="mg.studio.weatherappdesign">

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:icon="@mipmap/logo"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
Expand Down
Binary file added app/src/main/java/.DS_Store
Binary file not shown.
Binary file added app/src/main/java/com/.DS_Store
Binary file not shown.
Binary file added app/src/main/java/com/example/.DS_Store
Binary file not shown.
39 changes: 39 additions & 0 deletions app/src/main/java/com/example/weather/test/WeatherGetTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.example.weather.test;

/**
* Created by apple on 2018/3/23.
*/

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import com.example.weather.util.HttpCallbackListener;
import com.example.weather.util.HttpUtil;

import android.test.AndroidTestCase;

public class WeatherGetTest extends AndroidTestCase{
public void testGetData(){
String cityName;
try {
cityName = URLEncoder.encode("重庆", "utf-8");
String weatherUrl="http://v.juhe.cn/weather/index?format=2&cityname="+cityName+"&key=3f915b0cad6ae92729f8eb1f0446b66d";

HttpUtil.sendHttpRequest(weatherUrl, new HttpCallbackListener() {

public void onFinish(String response) {
// TODO Auto-generated method stub
System.out.println(response);
}

public void onError(Exception e) {
// TODO Auto-generated method stub

}
});
}catch (Exception e) {
// TODO: handle exception
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.weather.util;

/**
* Created by apple on 2018/3/23.
*/

public interface HttpCallbackListener {
void onFinish(String response);
void onError(Exception e);
}
53 changes: 53 additions & 0 deletions app/src/main/java/com/example/weather/util/HttpUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.example.weather.util;

/**
* Created by apple on 2018/3/23.
*/

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

import android.util.Log;

public class HttpUtil {
public static void sendHttpRequest(final String address, final HttpCallbackListener listener) {
new Thread(new Runnable() {
public void run() {
HttpURLConnection connection = null;
try {
URL url = new URL(address);
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setConnectTimeout(8000);
connection.setReadTimeout(8000);
connection.setDoInput(true);
connection.setDoOutput(true);
InputStream in = connection.getInputStream();
BufferedReader reader =
new BufferedReader(new InputStreamReader(in));
StringBuilder response = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
response.append(line);
}
if (listener != null) {
// 回调 onFinish()方法
listener.onFinish(response.toString());
}
} catch (Exception e) {
if (listener != null) {
// 回调 onError()方法
listener.onError(e);
}
} finally {
if (connection != null) {
connection.disconnect();
}
}
}
}).start();
}
}
62 changes: 60 additions & 2 deletions app/src/main/java/mg/studio/weatherappdesign/MainActivity.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,72 @@
import java.net.ProtocolException;
import java.net.URL;

import java.util.*;
import org.json.JSONObject;


public class MainActivity extends AppCompatActivity {

private static final int msgKey1 = 1;
private TextView mData;
private TextView mWeek;
private TextView mLocation;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mData = (TextView) findViewById(R.id.tv_date);
mWeek = (TextView) findViewById(R.id.tv_week);
mLocation = (TextView) findViewById(R.id.tv_location);

new DownloadUpdate().execute();
}


//获得当前年月日
public String getData(){
final Calendar c = Calendar.getInstance();
c.setTimeZone(TimeZone.getTimeZone("GMT+8:00"));
String mYear = String.valueOf(c.get(Calendar.YEAR)); // 获取当前年份
String mMonth = String.valueOf(c.get(Calendar.MONTH) + 1);// 获取当前月份
String mDay = String.valueOf(c.get(Calendar.DAY_OF_MONTH));// 获取当前月份的日期号码

//统一格式
if(Integer.parseInt(mMonth)<10){mMonth="0"+mMonth;}
if(Integer.parseInt(mDay)<10){mDay="0"+mDay;}

return mMonth + "/" +mDay + "/" + mYear;
}

//获得当前星期
public String getWeek(){
final Calendar c = Calendar.getInstance();
c.setTimeZone(TimeZone.getTimeZone("GMT+8:00"));
String mWay = String.valueOf(c.get(Calendar.DAY_OF_WEEK));

if("1".equals(mWay)){
mWay ="SUNDAY";
}else if("2".equals(mWay)){
mWay ="MONDAY";
}else if("3".equals(mWay)){
mWay ="TUESDAY";
}else if("4".equals(mWay)){
mWay ="WEDNESDAY";
}else if("5".equals(mWay)){
mWay ="THURSDAY";
}else if("6".equals(mWay)){
mWay ="FRIDAY";
}else if("7".equals(mWay)){
mWay ="SATURDAY";
}

return mWay;
}


public void btnClick(View view) {

new DownloadUpdate().execute();
}

Expand All @@ -34,9 +90,11 @@ private class DownloadUpdate extends AsyncTask<String, Void, String> {

@Override
protected String doInBackground(String... strings) {
String stringUrl = "http://mpianatra.com/Courses/info.txt";
String stringUrl= "http://v.juhe.cn/weather/index?format=2&cityname=重庆&key=3f915b0cad6ae92729f8eb1f0446b66d";
HttpURLConnection urlConnection = null;
BufferedReader reader;
mData.setText(getData());
mWeek.setText(getWeek());

try {
URL url = new URL(stringUrl);
Expand Down Expand Up @@ -67,7 +125,7 @@ protected String doInBackground(String... strings) {
return null;
}
//The temperature
return buffer.toString();
return buffer.toString().substring(66,68);

} catch (MalformedURLException e) {
e.printStackTrace();
Expand Down
Binary file added app/src/main/res/.DS_Store
Binary file not shown.
19 changes: 19 additions & 0 deletions app/src/main/res/drawable-v24/circular_shape.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
android:useLevel="false" >
<solid android:color="#2495d1" />
<padding
android:left="2dp"
android:top="1dp"
android:right="2dp"
android:bottom="1dp" />
<solid
android:color="#2495d1" />
<stroke
android:width="1dp"
android:color="#2495d1" />
<size android:width="15dp"
android:height="15dp" />
</shape>
Empty file modified app/src/main/res/drawable-v24/ic_launcher_foreground.xml
100644 → 100755
Empty file.
Loading