diff --git a/soft1614080902221/app/src/main/AndroidManifest.xml b/soft1614080902221/app/src/main/AndroidManifest.xml
index 33e74612c..379161e7c 100644
--- a/soft1614080902221/app/src/main/AndroidManifest.xml
+++ b/soft1614080902221/app/src/main/AndroidManifest.xml
@@ -2,6 +2,13 @@
+
+
+
+
+
+
+
-
+
+
+
+
\ No newline at end of file
diff --git a/soft1614080902221/app/src/main/java/edu/hzuapps/androidlabs/soft1614080902221/Activity3.java b/soft1614080902221/app/src/main/java/edu/hzuapps/androidlabs/soft1614080902221/Activity3.java
index c638b9983..00f6b6df2 100644
--- a/soft1614080902221/app/src/main/java/edu/hzuapps/androidlabs/soft1614080902221/Activity3.java
+++ b/soft1614080902221/app/src/main/java/edu/hzuapps/androidlabs/soft1614080902221/Activity3.java
@@ -57,10 +57,11 @@ protected void onCreate(Bundle savedInstanceState) {
initButton(); //实现中间1-9个Button功能
timer = (TextView) findViewById(R.id.timer); //获取计时控件
handler.postDelayed(runnable, 1000); //实现右上角计时功能
- rankList(); //实现排行榜Button功能
-
+ rankList(); //实现本地排行榜Button功能
+ networkListButton();
}
+
//显示当前玩家信息
private void initCurrentPlayerTextView() {
Intent recIntent = getIntent();//获取Activity2传递过来的玩家信息
@@ -134,6 +135,17 @@ public void onClick(View v) {
}
+ private void networkListButton() {
+ Button networkListButton = (Button)findViewById(R.id.NetworkListButton);
+ networkListButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ Intent jumpIntent = new Intent(Activity3.this, Activity5.class);
+ startActivity(jumpIntent);
+ }
+ });
+ }
+
//强制玩家必须按1-9的数字顺序点击,否则不能消去
class ButtonMonitor implements View.OnClickListener {
@Override
diff --git a/soft1614080902221/app/src/main/java/edu/hzuapps/androidlabs/soft1614080902221/Activity5.java b/soft1614080902221/app/src/main/java/edu/hzuapps/androidlabs/soft1614080902221/Activity5.java
new file mode 100644
index 000000000..e89e57d91
--- /dev/null
+++ b/soft1614080902221/app/src/main/java/edu/hzuapps/androidlabs/soft1614080902221/Activity5.java
@@ -0,0 +1,83 @@
+package edu.hzuapps.androidlabs.soft1614080902221;
+
+import android.support.v7.app.AppCompatActivity;
+import android.os.Bundle;
+import android.support.v7.widget.LinearLayoutManager;
+import android.support.v7.widget.RecyclerView;
+import android.util.Log;
+import android.widget.Toast;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import okhttp3.Call;
+import okhttp3.Response;
+
+public class Activity5 extends AppCompatActivity {
+
+ private List playerDataList = new ArrayList();
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_5);
+ String address = "https://raw.githubusercontent.com/yangyangyang2017/android-labs-2018/master/soft1614080902221/网络排行榜.json";
+ //发送请求
+ HttpUtil.sendOkHttpRequest(address, new okhttp3.Callback() {
+ @Override
+ public void onFailure(Call call, IOException e) {
+ Log.d("排行榜","网络异常");
+ }
+
+ @Override
+ public void onResponse(Call call, Response response) throws IOException {
+ //获取的json数据
+ String responseData = response.body().string();
+ try {
+ //解析json
+ JSONArray jsonArray = new JSONArray(responseData);
+ for (int i = 0; i < jsonArray.length(); i++) {
+ JSONObject jsonObject = jsonArray.getJSONObject(i);
+ String strPlayerName = jsonObject.getString("playerName");
+ String strSex = jsonObject.getString("sex");
+ String strGameCharacters = jsonObject.getString("gameCharacters");
+ int intTime = jsonObject.getInt("time");
+ PlayerData playerData = new PlayerData(strPlayerName, strSex, strGameCharacters, intTime);
+ playerDataList.add(playerData);
+
+ }
+
+
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+
+ //更新UI
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ //通过id找到RecyclerView2组件对象
+ RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view2);
+ //创建一个LinearLayoutManager对象
+ LinearLayoutManager linearLayoutManager = new LinearLayoutManager(Activity5.this);
+ //设置recyclerView的布局方式为LinearLayout
+ recyclerView.setLayoutManager(linearLayoutManager);
+ //创建适配器,并将playerDataList传入PlayerDataAdapter的构造函数中
+ PlayerDataAdapter playerDataAdapter = new PlayerDataAdapter(playerDataList);
+ //给recyclerView设置适配器
+ recyclerView.setAdapter(playerDataAdapter);
+ }
+ });
+
+
+ }
+ });
+
+
+ }
+}
diff --git a/soft1614080902221/app/src/main/java/edu/hzuapps/androidlabs/soft1614080902221/HttpUtil.java b/soft1614080902221/app/src/main/java/edu/hzuapps/androidlabs/soft1614080902221/HttpUtil.java
new file mode 100644
index 000000000..d50f01b3c
--- /dev/null
+++ b/soft1614080902221/app/src/main/java/edu/hzuapps/androidlabs/soft1614080902221/HttpUtil.java
@@ -0,0 +1,17 @@
+package edu.hzuapps.androidlabs.soft1614080902221;
+
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+
+public class HttpUtil{
+
+ public static void sendOkHttpRequest(String address,okhttp3.Callback callback){
+
+ OkHttpClient client = new OkHttpClient();
+ Request request = new Request.Builder()
+ .url(address)
+ .build();
+ client.newCall(request).enqueue(callback);
+ }
+
+}
\ No newline at end of file
diff --git a/soft1614080902221/app/src/main/res/layout/activity_3.xml b/soft1614080902221/app/src/main/res/layout/activity_3.xml
index 3c4bfba5e..b129346bc 100644
--- a/soft1614080902221/app/src/main/res/layout/activity_3.xml
+++ b/soft1614080902221/app/src/main/res/layout/activity_3.xml
@@ -107,13 +107,13 @@
android:id="@+id/instructionsText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_marginBottom="166dp"
+ android:layout_marginBottom="19dp"
android:layout_marginLeft="30dp"
android:layout_marginStart="30dp"
android:text="请按数字顺序消除中间的小方块,\n以右上角时间作为成绩!\n抓紧时间了,加油!"
android:textColor="#FF0000"
android:textSize="20dp"
- app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintBottom_toTopOf="@+id/rankListButton"
app:layout_constraintStart_toStartOf="parent" />
@@ -121,13 +121,24 @@
android:id="@+id/rankListButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_marginTop="37dp"
- android:text="排行榜"
+ android:layout_marginBottom="11dp"
+ android:text="本地排行榜"
+ android:textColor="#0000FF"
+ android:textSize="30dp"
+ app:layout_constraintBottom_toTopOf="@+id/NetworkListButton"
+ app:layout_constraintStart_toStartOf="@+id/NetworkListButton" />
+
+
+ app:layout_constraintStart_toStartOf="parent" />
\ No newline at end of file
diff --git a/soft1614080902221/app/src/main/res/layout/activity_5.xml b/soft1614080902221/app/src/main/res/layout/activity_5.xml
new file mode 100644
index 000000000..798469473
--- /dev/null
+++ b/soft1614080902221/app/src/main/res/layout/activity_5.xml
@@ -0,0 +1,66 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/soft1614080902221/report6.md b/soft1614080902221/report6.md
new file mode 100644
index 000000000..f27740c5c
--- /dev/null
+++ b/soft1614080902221/report6.md
@@ -0,0 +1,28 @@
+实验六
+=
+一.实验目的
+-
+掌握Android网络访问方法;
+
+二.实验内容
+-
+在个人目录中创建一个表示数据的XML或JSON文件;
+数据文件代码提交之后从GitHub获取文件URL;
+在应用中通过网络编程访问GitHub的数据文件;
+在应用中解析并显示文件所包含的数据;
+将应用运行结果截图。
+
+三.实验步骤
+-
+1.创建一个HttpUtil.java类,里面有一个静态方法sendOkHttpRequest来发送OkHttp请求.
+2.在Activity5中调用HttpUtil.sendOkHttpRequest方法,传入参数address(json数据源地址),和实现Callback回调类.
+3.在onResponse中用JSONArray解析接收到的json数据.
+4.最后用runOnUiThread回到主线程更新UI,实现网络排行榜.
+
+四.实验截图
+-
+![](https://github.com/yangyangyang2017/android-labs-2018/blob/master/soft1614080902221/%E7%AC%AC%E5%85%AD%E6%AC%A1%E5%AE%9E%E9%AA%8C%E6%88%AA%E5%9B%BE.gif)
+
+五.实验体会
+-
+1.这次实验比较简单,从自己github库中获取json并解析。要注意的是不能在子线程中更新UI,要调用runOnUiThread方法。
diff --git "a/soft1614080902221/\347\254\254\345\205\255\346\254\241\345\256\236\351\252\214\346\210\252\345\233\276.gif" "b/soft1614080902221/\347\254\254\345\205\255\346\254\241\345\256\236\351\252\214\346\210\252\345\233\276.gif"
new file mode 100644
index 000000000..e747dac0e
Binary files /dev/null and "b/soft1614080902221/\347\254\254\345\205\255\346\254\241\345\256\236\351\252\214\346\210\252\345\233\276.gif" differ
diff --git "a/soft1614080902221/\347\275\221\347\273\234\346\216\222\350\241\214\346\246\234.json" "b/soft1614080902221/\347\275\221\347\273\234\346\216\222\350\241\214\346\246\234.json"
new file mode 100644
index 000000000..8f80b69b5
--- /dev/null
+++ "b/soft1614080902221/\347\275\221\347\273\234\346\216\222\350\241\214\346\246\234.json"
@@ -0,0 +1,3 @@
+[{"playerName":"周杰伦","sex":"男","gameCharacters":"若烟","time":"1"},
+ {"playerName":"方文山","sex":"男","gameCharacters":"宛海","time":"3"},
+ {"playerName":"张韶涵","sex":"女","gameCharacters":"慕灵","time":"5"}]
\ No newline at end of file