Skip to content

Commit

Permalink
Merge pull request #2628 from JinmingH/master
Browse files Browse the repository at this point in the history
#6 #906第六次实验+第4,5次实验报告
  • Loading branch information
zengsn authored Jun 2, 2018
2 parents 88bdaa1 + 86acd8c commit 35f078f
Show file tree
Hide file tree
Showing 6 changed files with 199 additions and 1 deletion.
15 changes: 14 additions & 1 deletion soft1614080902232/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="edu.hzuapps.androidlabs.soft1614080902232">

<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" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Expand All @@ -19,7 +28,11 @@
</activity>
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main"
android:label="@string/title_activity_context"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".Main2Activity"
android:label="@string/title_activity_main2"
android:theme="@style/AppTheme.NoActionBar"></activity>
</application>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package edu.hzuapps.androidlabs.soft1614080902232;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import org.json.JSONArray;
import org.json.JSONObject;
import org.json.JSONStringer;

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

public class Main2Activity extends AppCompatActivity {

private TextView texts;
private String text;
public static final String TAG = Main2Activity.class.getSimpleName();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
texts = ((TextView) findViewById(R.id.readView2));
getJson();
}

public void getJson() {
new Thread() {
@Override
public void run() {
try {
// 你的 URL
Log.i(TAG, "01");
String url_s = "https://raw.githubusercontent.com/JinmingH/android-labs-2018/master/soft1614080902232/information.json";
URL url = new URL(url_s);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
Log.i(TAG, "1");
conn.setConnectTimeout(5000);
conn.setUseCaches(false);
conn.connect();
InputStream inputStream = conn.getInputStream();
InputStreamReader input = new InputStreamReader(inputStream);
BufferedReader buffer = new BufferedReader(input);
if (conn.getResponseCode() == 200) {
String inputLine;
StringBuffer resultData = new StringBuffer();
while ((inputLine = buffer.readLine()) != null) {
resultData.append(inputLine);
}
text = resultData.toString();
Log.v("out---------------->", text);


runOnUiThread(new Runnable() {
@Override
public void run() {
try {
JSONArray js = new JSONArray(text);
JSONObject ob = js.getJSONObject(0);
String str = ob.getString("sentence");
texts.setText(str);
ob = js.getJSONObject(1);
str = ob.getString("data");
texts.append(str);
}catch(Exception e){
e.printStackTrace();
}
}
});

}
} catch (Exception e) {
Log.i(TAG, "5");
e.printStackTrace();
}

}


}.start();
}

}
33 changes: 33 additions & 0 deletions soft1614080902232/app/src/main/res/layout/activity_main2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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=".Main2Activity">

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

<include layout="@layout/content_main2" />

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_dialog_email" />

</android.support.design.widget.CoordinatorLayout>
20 changes: 20 additions & 0 deletions soft1614080902232/report4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 1.实验要求
1)根据选题要求设计界面布局及控件使用;
2)布局xml及界面控制操作代码提交并截图;
3)将应用运行结果截图。
# 2.实验内容
1)使用其中一种布局方式(本界面所选题目的布局为RelativeLayout) ;
2)页面有一个按钮,通过控件id获取界面对象,执行相关操作,跳道各自的页面;
3)实现界面控件的事件处理,例如点击按钮。
# 3.实验步骤
(1)在首页添加了添加按钮,点击后跳转到记事本页面。
(2)在记事本页面 ConstraintLayout 里分别创建了一个 LinearLayout 和一个 RelativeLayout。
(3)在记事本页面增加了保存和取消这 两个按钮,点击后分别执行保存记事本到txt文件和退出操作。
(4)在记事本页面增加了一个 EditText,用于储存文本内容。
# 4实验结果

![image](https://github.com/JinmingH/android-labs-2018/blob/master/soft1614080902232/shiyan4.1.png)
![image](https://github.com/JinmingH/android-labs-2018/blob/master/soft1614080902232/shiyan4.2.png)

# 5.实验体会
这个实验我做了很久,上网查了之后,才知道要一些东西要怎么做。总体来说学到了不少。
30 changes: 30 additions & 0 deletions soft1614080902232/report5.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 第五次实验

## 1. 实验目标

- 掌握在 Android App 中存储数据。

## 2. 实验内容

- (1). 将应用产生的数据保存到文件存储中;
- (2). 说明使用的文件存储方式:内部 or 外部;
- (3). 将运行结果截图。

## 3. 实验步骤

- (1). 添加了一个 textview。
- (2). 把 textview 的内容赋给 string 对象。
- (3). 我用 FileOutputStream 把 String 的内容写到文本中,用的是内部存储。
- (4). 再把数据从文本中读出来显示到 textView。

## 4. 实验结果
![image()](https://github.com/JinmingH/android-labs-2018/blob/master/soft1614080902232/shiyan4.1.png)

![image()](https://github.com/JinmingH/android-labs-2018/blob/master/soft1614080902232/shiyan5.1.png)

![image()](https://github.com/JinmingH/android-labs-2018/blob/master/soft1614080902232/shiyan5.2.PNG)

## 5. 实验体会

通过本次实验掌握在 Android App 中存储数据的一种方法,将应用产生的数据保存到文件存储中。
由于很久没打过 java 了,很多都有点忘记了,这个实验让我把回去把 java.IO 这方面又看了一下。
Binary file added soft1614080902232/shiyan6[1].png
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 35f078f

Please sign in to comment.