Skip to content

Commit

Permalink
hzuapps#6 hzuapps#916 第六次实验
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhenghizhong committed May 29, 2018
1 parent 9661937 commit 043f796
Show file tree
Hide file tree
Showing 18 changed files with 1,174 additions and 6 deletions.
12 changes: 11 additions & 1 deletion soft1614080902215/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="androidlabs.hzuapps.edu.soft1614080902215">

<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 @@ -21,7 +28,10 @@
android:label="@string/title_activity_second"
android:theme="@style/AppTheme.NoActionBar" />
<activity android:name=".ThirdActivity" />
<activity android:name=".FouthActivity"></activity>
<activity android:name=".FouthActivity" />
<activity android:name=".FifthActivity" />
<activity android:name=".SixthActivity" />
<activity android:name=".SeventhActivity"></activity>
</application>

</manifest>
13 changes: 13 additions & 0 deletions soft1614080902215/app/src/main/java/FifthActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package androidlabs.hzuapps.edu.soft1614080902215;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class FifthActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fifth);
}
}
20 changes: 20 additions & 0 deletions soft1614080902215/app/src/main/java/FouthActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package androidlabs.hzuapps.edu.soft1614080902215;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class FouthActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fouth);
}

}
49 changes: 44 additions & 5 deletions soft1614080902215/app/src/main/java/SecondActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,60 @@

import android.content.Intent;
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.view.View;
import android.*;
import android.widget.Button;

public class SecondActivity extends AppCompatActivity {

public class SecondActivity extends AppCompatActivity {
private Button Time;
private Button Length;
private Button Parities;
private Button HouseLoan;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);

Time=(Button)findViewById(R.id.时间转换);
Time.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(SecondActivity.this,FouthActivity.class);
startActivity(intent);
}
});

Length=(Button)findViewById(R.id.长度转换);
Length.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(SecondActivity.this,FifthActivity.class);
startActivity(intent);
}
});

Parities=(Button)findViewById(R.id.汇率计算);
Parities.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(SecondActivity.this,SixthActivity.class);
startActivity(intent);
}
});

HouseLoan=(Button)findViewById(R.id.房贷计算);
HouseLoan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(SecondActivity.this,SeventhActivity.class);
startActivity(intent);
}
});


}



}
13 changes: 13 additions & 0 deletions soft1614080902215/app/src/main/java/SeventhActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package androidlabs.hzuapps.edu.soft1614080902215;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class SeventhActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_seventh);
}
}
13 changes: 13 additions & 0 deletions soft1614080902215/app/src/main/java/SixthActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package androidlabs.hzuapps.edu.soft1614080902215;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class SixthActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sixth);
}
}
67 changes: 67 additions & 0 deletions soft1614080902215/app/src/main/java/ThirdActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@
import android.widget.EditText;
import android.widget.TextView;

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

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class ThirdActivity extends AppCompatActivity{
private TextView textView;
Expand All @@ -25,6 +32,9 @@ public class ThirdActivity extends AppCompatActivity{
private boolean addNum;
private Button More;
//private Button Build;
private TextView texts;
private String text;
public static final String TAG1 = ThirdActivity.class.getSimpleName();

public static final String DIRECTORY = "demo";
public static final String FILENAME = "file_demo.txt";
Expand All @@ -37,6 +47,9 @@ protected void onCreate(Bundle savedInstanceState) {
textView1 = (TextView) findViewById(R.id.textView);
addNum = true;

texts = ((TextView) findViewById(R.id.textView));
getJson();

More=(Button)findViewById(R.id.btn_more);
More.setOnClickListener(new View.OnClickListener() {
@Override
Expand All @@ -46,13 +59,67 @@ public void onClick(View v) {
}
});



((Button) findViewById(R.id.btn_save)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String text = ((TextView) findViewById(R.id.textView)).getText().toString();
saveTextIntoInternalStorage(text);
}
});}
public void getJson() {
new Thread() {
@Override
public void run() {
try {
//你的URL
Log.i(TAG1, "01");
String url_s = "https://raw.githubusercontent.com/Zhenghizhong/android-labs-2018/master/soft1614080902215/text.json";
URL url = new URL(url_s);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
Log.i(TAG1, "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 = new JSONObject(text);
String str = ob.getString("text");
texts.setText(str);
}catch(Exception e){
e.printStackTrace();
}
}
});

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

}


}.start();
}
// 将文字保存到内部存储
private void saveTextIntoInternalStorage(String text) {
// 获取内部存储目录
Expand Down
Loading

0 comments on commit 043f796

Please sign in to comment.