From 8199e6fa0f68f2c0f5caf217bfe85423e0151e23 Mon Sep 17 00:00:00 2001 From: yangyangyang2017 <260363217@qq.com> Date: Mon, 21 May 2018 21:16:03 +0800 Subject: [PATCH 1/7] =?UTF-8?q?#6=20#957=20=E7=AC=AC=E5=85=AD=E6=AC=A1?= =?UTF-8?q?=E5=AE=9E=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...5\221\347\273\234\346\216\222\350\241\214\346\246\234.json" | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 "soft1614080902221/\347\275\221\347\273\234\346\216\222\350\241\214\346\246\234.json" 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..623bd57f6 --- /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 From 0fd53b0bc18443fa6abaafe0e23e1393e6909f4e Mon Sep 17 00:00:00 2001 From: yangyangyang2017 <260363217@qq.com> Date: Mon, 21 May 2018 22:19:24 +0800 Subject: [PATCH 2/7] =?UTF-8?q?#6=20#957=20=E7=AC=AC=E5=85=AD=E6=AC=A1?= =?UTF-8?q?=E5=AE=9E=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...21\347\273\234\346\216\222\350\241\214\346\246\234.json" | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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" index 623bd57f6..47704aaae 100644 --- "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" @@ -1,3 +1,3 @@ -[{"playerName":"�ܽ���","sex":"��","gameCharacters":"����","time":"1"}, - {"playerName":"����ɽ","sex":"��","gameCharacters":"��","time":"3"}, - {"playerName":"���غ�","sex":"Ů","gameCharacters":"Ľ��","time":"5"}] \ No newline at end of file +[{"playerName":"�ܽ���","sex":"��","gameCharacters":"����","time":1}, + {"playerName":"����ɽ","sex":"��","gameCharacters":"��","time":3}, + {"playerName":"���غ�","sex":"Ů","gameCharacters":"Ľ��","time":5}] \ No newline at end of file From e1e3e1428f7f1f1fee6aede8c3cf76febda491e8 Mon Sep 17 00:00:00 2001 From: yangyangyang2017 <260363217@qq.com> Date: Mon, 21 May 2018 23:52:01 +0800 Subject: [PATCH 3/7] =?UTF-8?q?#6=20#957=20=E7=AC=AC6=E6=AC=A1=E5=AE=9E?= =?UTF-8?q?=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...21\347\273\234\346\216\222\350\241\214\346\246\234.json" | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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" index 47704aaae..8f80b69b5 100644 --- "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" @@ -1,3 +1,3 @@ -[{"playerName":"�ܽ���","sex":"��","gameCharacters":"����","time":1}, - {"playerName":"����ɽ","sex":"��","gameCharacters":"��","time":3}, - {"playerName":"���غ�","sex":"Ů","gameCharacters":"Ľ��","time":5}] \ No newline at end of file +[{"playerName":"周杰伦","sex":"男","gameCharacters":"若烟","time":"1"}, + {"playerName":"方文山","sex":"男","gameCharacters":"宛海","time":"3"}, + {"playerName":"张韶涵","sex":"女","gameCharacters":"慕灵","time":"5"}] \ No newline at end of file From 5d201b8c3e273c14ad72559de7ff81e3003798ee Mon Sep 17 00:00:00 2001 From: yangyangyang2017 <260363217@qq.com> Date: Tue, 22 May 2018 10:14:53 +0800 Subject: [PATCH 4/7] =?UTF-8?q?#6=20#957=20=E7=AC=AC6=E6=AC=A1=E5=AE=9E?= =?UTF-8?q?=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/src/main/AndroidManifest.xml | 12 ++- .../soft1614080902221/Activity3.java | 16 +++- .../soft1614080902221/Activity5.java | 83 +++++++++++++++++++ .../soft1614080902221/HttpUtil.java | 17 ++++ .../app/src/main/res/layout/activity_3.xml | 23 +++-- .../app/src/main/res/layout/activity_5.xml | 66 +++++++++++++++ 6 files changed, 208 insertions(+), 9 deletions(-) create mode 100644 soft1614080902221/app/src/main/java/edu/hzuapps/androidlabs/soft1614080902221/Activity5.java create mode 100644 soft1614080902221/app/src/main/java/edu/hzuapps/androidlabs/soft1614080902221/HttpUtil.java create mode 100644 soft1614080902221/app/src/main/res/layout/activity_5.xml 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" /> + +