Skip to content

Commit

Permalink
hzuapps#6 hzuapps#938 万能遥控器
Browse files Browse the repository at this point in the history
  • Loading branch information
hzutanziyang committed May 23, 2018
1 parent c18e1ef commit 2602508
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 2 deletions.
7 changes: 6 additions & 1 deletion soft1614080902227/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,10 @@
android:label="乐视TV" />
<activity android:name=".UserDBHelper" />
</application>

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,32 @@
import android.media.Image;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import org.json.JSONObject;

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

public class Remote_0f_Air extends AppCompatActivity {
private TextView wd_textview;
private TextView fh_textview;
private ImageView ms_imageview;
private int dushu;
private String text;
private String weatherstr;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_remote_0f__air);

getJson();


wd_textview = findViewById(R.id.wendu);
Expand Down Expand Up @@ -106,4 +117,69 @@ public void onClick(View v){
}
}
}
public void getJson(){

new Thread(new Runnable() {
@Override
public void run() {

try {
String url_s = "http://v.juhe.cn/weather/index?format=2&cityname=%E6%83%A0%E5%B7%9E&key=924efc38443b4e06625880c4d864a78b";
URL url = new URL(url_s);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setConnectTimeout(5000);
conn.setUseCaches(false);
conn.connect();
InputStream inputStream = conn.getInputStream();
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
if(conn.getResponseCode()==200){
String inputLine;
StringBuffer resultData = new StringBuffer();
while ((inputLine = bufferedReader.readLine()) != null){
resultData.append(inputLine);
}
text = resultData.toString();

Log.d("out--------->",text);
try {
weatherstr = parsesJson(text);
//stextView.setText(str);
} catch (Exception e) {
Log.d("有异常","444");
}

}
}catch (Exception e) {
e.printStackTrace();
}
runOnUiThread(new Runnable() {
@Override
public void run() {
TextView textView = findViewById(R.id.weather);
textView.setText(weatherstr);
}
});

}
}).start();

}

public String parsesJson(String string) throws Exception{
String result="";
JSONObject object = new JSONObject(string);
//JSONArray listArray = new JSONArray(string);
//JSONObject list_item = listArray.getJSONObject(2);
//String item = list_item.getString("playerName");
JSONObject object1 = object.getJSONObject("result").getJSONObject("sk");
// Log.d("outitem--------->",item);
String item = object1.getString("temp");
String item1 = object1.getString("wind_direction");
String item2 = object1.getString("humidity");
result = String.format("%s室外温度:%s",result,item);
result = String.format("%s 风向:%s",result,item1);
result = String.format("%s 湿度:%s",result,item2);
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@
android:layout_marginStart="22dp"
android:src="@drawable/zidong"
android:visibility="invisible"/>

<TextView
android:id="@+id/weather"
android:layout_width="match_parent"
android:layout_height="40dp"
android:textSize="20dp"
android:layout_alignParentStart="true"
android:layout_below="@+id/wendu"/>
</RelativeLayout>

<LinearLayout
Expand Down
Binary file added soft1614080902227/第六次实验截图.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2602508

Please sign in to comment.