-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2641 from spemed/master
#6 第六次实验 spemed
- Loading branch information
Showing
9 changed files
with
189 additions
and
4 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 12 additions & 1 deletion
13
...14080901139/app/src/main/java/edu/hzuapps/androidlabs/com1614080901139/Main2Activity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,35 @@ | ||
package edu.hzuapps.androidlabs.com1614080901139; | ||
|
||
import android.content.Intent; | ||
import android.content.SharedPreferences; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.view.View; | ||
import android.widget.Button; | ||
import android.widget.TextView; | ||
|
||
public class Main2Activity extends AppCompatActivity { | ||
|
||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main2); | ||
|
||
TextView user=(TextView) findViewById(R.id.user); | ||
SharedPreferences pref=getSharedPreferences("user",MODE_PRIVATE); | ||
String userName=pref.getString("userName",""); | ||
user.setText(userName); | ||
TextView password=(TextView) findViewById(R.id.password); | ||
String passWord=pref.getString("passWord",""); | ||
password.setText(passWord); | ||
Button button=(Button)findViewById(R.id.button); | ||
button.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
Intent intent=new Intent(Main2Activity.this,jsonActivity.class); | ||
startActivity(intent); | ||
} | ||
}); | ||
|
||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
...614080901139/app/src/main/java/edu/hzuapps/androidlabs/com1614080901139/jsonActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package edu.hzuapps.androidlabs.com1614080901139; | ||
|
||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.util.Log; | ||
import android.widget.ArrayAdapter; | ||
import android.widget.ListView; | ||
|
||
import org.json.JSONArray; | ||
import org.json.JSONObject; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.net.HttpURLConnection; | ||
import java.net.URL; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class jsonActivity extends AppCompatActivity { | ||
private String text; | ||
private ListView listView; | ||
private ArrayAdapter<String> adapter; | ||
private List<String> list=new ArrayList<>(); | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_json); | ||
listView=(ListView)findViewById(R.id.listview); | ||
getjson(); | ||
} | ||
public void getjson() | ||
{ | ||
new Thread(new Runnable() { | ||
@Override | ||
public void run() { | ||
try { | ||
URL url = new URL("https://raw.githubusercontent.com/1614080901144/android-labs-2018/master/com1614080901144/content.json"); | ||
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); | ||
connection.setRequestMethod("GET"); | ||
connection.setConnectTimeout(8000); | ||
connection.setReadTimeout(8000); | ||
connection.setUseCaches(false); | ||
connection.connect(); | ||
InputStream in = connection.getInputStream(); | ||
InputStreamReader input=new InputStreamReader(in); | ||
BufferedReader reader=new BufferedReader(input); | ||
if (connection.getResponseCode() == 200) { | ||
StringBuilder response = new StringBuilder(); | ||
String Line; | ||
while ((Line = reader.readLine()) != null) { | ||
response.append(Line); | ||
} | ||
text = response.toString(); | ||
Log.v("out---------------->",text); | ||
analyzejson(); | ||
} | ||
} | ||
catch(Exception e) | ||
{ | ||
e.printStackTrace(); | ||
} | ||
runOnUiThread(new Runnable() { | ||
@Override public void run() { | ||
adapter=new ArrayAdapter<String>(jsonActivity.this,android.R.layout.simple_list_item_1,list); | ||
listView.setAdapter(adapter); | ||
} | ||
}); | ||
} | ||
}).start(); | ||
} | ||
public void analyzejson() | ||
{ | ||
try{ | ||
JSONArray jsonArray=new JSONArray(text); | ||
for(int a=0;a<jsonArray.length();a++) | ||
{ | ||
JSONObject jsonObject=jsonArray.getJSONObject(a); | ||
String number=jsonObject.getString("number"); | ||
String number1=jsonObject.getString("number1"); | ||
String number2=jsonObject.getString("number2"); | ||
String add; | ||
add=number+" "+number1+" "+number2; | ||
list.add(add); | ||
Log.v("结果",add); | ||
} | ||
|
||
} | ||
catch (Exception e) | ||
{ | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
com1614080901139/app/src/main/res/drawable-v24/ic_launcher_foreground.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:aapt="http://schemas.android.com/aapt" | ||
android:width="108dp" | ||
android:height="108dp" | ||
android:viewportHeight="108" | ||
android:viewportWidth="108"> | ||
<path | ||
android:fillType="evenOdd" | ||
android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z" | ||
android:strokeColor="#00000000" | ||
android:strokeWidth="1"> | ||
<aapt:attr name="android:fillColor"> | ||
<gradient | ||
android:endX="78.5885" | ||
android:endY="90.9159" | ||
android:startX="48.7653" | ||
android:startY="61.0927" | ||
android:type="linear"> | ||
<item | ||
android:color="#44000000" | ||
android:offset="0.0" /> | ||
<item | ||
android:color="#00000000" | ||
android:offset="1.0" /> | ||
</gradient> | ||
</aapt:attr> | ||
</path> | ||
<path | ||
android:fillColor="#FFFFFF" | ||
android:fillType="nonZero" | ||
android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z" | ||
android:strokeColor="#00000000" | ||
android:strokeWidth="1" /> | ||
</vector> |
13 changes: 13 additions & 0 deletions
13
com1614080901139/app/src/main/res/layout/activity_json.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context="edu.hzuapps.androidlabs.com1614080901139.jsonActivity"> | ||
<ListView | ||
android:id="@+id/listview" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"></ListView> | ||
|
||
</android.support.constraint.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# 一、实验目的 | ||
1 掌握Android网络访问方法; | ||
2 理解XML和JSON表示数据的方法。 | ||
|
||
# 二、实验要求 | ||
|
||
1 从网络下载一个文件(图片、MP3、MP4); | ||
2 保存到手机,在应用中使用文件; | ||
3 将应用运行结果截图。 | ||
|
||
|
||
# 三、实验步骤 | ||
|
||
1 新建一个Activity用来保存从网络上下载的图片 | ||
2 在AddPictureActivity.java文件中加入跳转到ThirdMainActivity.java相关代码 | ||
3 在activity_add_picture.xml和activity_third_main.xml文件中加入相关页面设计代码 | ||
4 在ThirdMainActivity.java文件中加入下载图片的相关代码 | ||
5 将app安装在手机中并把结果截图 | ||
|
||
# 四、实验体会 | ||
|
||
本次实验室安卓课程的最后一次实验。本学期的课程让我学习到了很多,学会怎么去创建一个安卓项目,调试安卓代码。怎么在app中引入网络图片。老师教学很有水平,要求同学们使用git上传提交文件,便利了同学们提交作业,也让我们学习到了非常有益的新知识 |