From 3291998651973ee78ceca0ff037709ae2a0f5fed Mon Sep 17 00:00:00 2001
From: = <=>
Date: Sun, 12 May 2019 16:22:08 +0800
Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E9=AA=8C7?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../main/AndroidManifest.xml" | 30 +++
.../example/myapplication/Main2Activity.java" | 199 +++++++++++++++
.../example/myapplication/Main3Activity.java" | 97 ++++++++
.../example/myapplication/MainActivity.java" | 37 +++
.../res/drawable/ic_launcher_background.xml" | 170 +++++++++++++
.../main/res/drawable/shape.xml" | 8 +
.../main/res/layout/activity_main.xml" | 228 ++++++++++++++++++
.../main/res/layout/activity_main2.xml" | 96 ++++++++
.../main/res/layout/activity_main3.xml" | 64 +++++
.../main/res/layout/activity_main4.xml" | 68 ++++++
10 files changed, 997 insertions(+)
create mode 100644 "students/soft1714080902301/\345\256\236\351\252\2147/main/AndroidManifest.xml"
create mode 100644 "students/soft1714080902301/\345\256\236\351\252\2147/main/java/com/example/myapplication/Main2Activity.java"
create mode 100644 "students/soft1714080902301/\345\256\236\351\252\2147/main/java/com/example/myapplication/Main3Activity.java"
create mode 100644 "students/soft1714080902301/\345\256\236\351\252\2147/main/java/com/example/myapplication/MainActivity.java"
create mode 100644 "students/soft1714080902301/\345\256\236\351\252\2147/main/res/drawable/ic_launcher_background.xml"
create mode 100644 "students/soft1714080902301/\345\256\236\351\252\2147/main/res/drawable/shape.xml"
create mode 100644 "students/soft1714080902301/\345\256\236\351\252\2147/main/res/layout/activity_main.xml"
create mode 100644 "students/soft1714080902301/\345\256\236\351\252\2147/main/res/layout/activity_main2.xml"
create mode 100644 "students/soft1714080902301/\345\256\236\351\252\2147/main/res/layout/activity_main3.xml"
create mode 100644 "students/soft1714080902301/\345\256\236\351\252\2147/main/res/layout/activity_main4.xml"
diff --git "a/students/soft1714080902301/\345\256\236\351\252\2147/main/AndroidManifest.xml" "b/students/soft1714080902301/\345\256\236\351\252\2147/main/AndroidManifest.xml"
new file mode 100644
index 000000000..8c27780ea
--- /dev/null
+++ "b/students/soft1714080902301/\345\256\236\351\252\2147/main/AndroidManifest.xml"
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/students/soft1714080902301/\345\256\236\351\252\2147/main/java/com/example/myapplication/Main2Activity.java" "b/students/soft1714080902301/\345\256\236\351\252\2147/main/java/com/example/myapplication/Main2Activity.java"
new file mode 100644
index 000000000..bcfabcf2d
--- /dev/null
+++ "b/students/soft1714080902301/\345\256\236\351\252\2147/main/java/com/example/myapplication/Main2Activity.java"
@@ -0,0 +1,199 @@
+package com.example.myapplication;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.os.Environment;
+import android.support.v7.app.AppCompatActivity;
+import android.util.Log;
+import android.view.View;
+import android.widget.Button;
+import android.widget.TextView;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+
+public class Main2Activity extends AppCompatActivity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_main2);
+ Button button=(Button)findViewById(R.id.button);
+ button.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ TextView spsl=findViewById(R.id.spsl);
+ TextView sl=findViewById(R.id.sl);
+ TextView spjg=findViewById(R.id.spjg);
+ TextView jg=findViewById(R.id.jg);
+ TextView spdd=findViewById(R.id.spdd);
+ TextView ddh=findViewById(R.id.ddh);
+ String text=spsl.getText().toString()+sl.getText().toString()+"\n"+spjg.getText().toString()+jg.getText().toString()+"\n"+spdd.getText().toString()+ddh.getText().toString();
+ // Log.i("1",spsl.getText().toString());
+ //save(text);
+ saveTextIntoExternalStorage(text);
+
+ }
+ });
+ }
+ private void save(String text){
+ // 获取内部存储目录
+ File dir = this.getFilesDir();
+ //File dir = getCacheDir();
+ File file = new File(dir,"test.txt");
+ if (file.exists()) { // 判断文件是否存在
+ Log.i("TAG", file.getAbsolutePath());
+ Log.i("TAG", file.length() + ""); // bytes*1024=kb *1024 MB
+ Log.i("TAG", file.isFile() + "");
+ file.canRead();
+ file.canWrite();
+ file.canExecute();
+
+ file.getFreeSpace();
+ file.getTotalSpace();
+ }
+
+ FileOutputStream fos = null; // 字节流 | char | cn : gbk 2 bytes, utf8 3 bytes
+
+ try { // 使用API打开输出流
+ fos = openFileOutput("test.txt", MODE_PRIVATE);
+ //FileOutputStream fos = new FileOutputStream(file);
+ fos.write(text.getBytes()); // 写入内容
+ fos.close(); // 关闭流
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ try {
+ fos.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ FileReader reader = null; // char
+
+ try {
+ reader = new FileReader(file.getAbsoluteFile());
+ String line;
+ BufferedReader bReader = new BufferedReader(reader);
+ while ((line =bReader.readLine())!=null){
+ Log.i("读取","从文件读取的内容: " + line);
+ }
+ bReader.close();
+ reader.close();
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ // 显示结果
+ showResult(file.getAbsolutePath());
+
+ // 删除文件
+ file.delete();
+ deleteFile("test.txt");
+ }
+
+ // 将文字保存到外部存储
+ private void saveTextIntoExternalStorage(String text) {
+ if (!isExternalStorageWritable()) {
+ Log.e("外部存储", "外部存储不可写!");
+ return;
+ }
+
+ File dir = getPublicExtStorageDir("DIRECTORY", Environment.DIRECTORY_DOWNLOADS);
+ File file = new File(dir, "test01.txt");
+
+ try {
+ FileOutputStream fos = new FileOutputStream(file);
+ fos.write(text.getBytes());
+ fos.close();
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ FileReader reader = null;
+ try {
+ reader = new FileReader(file.getAbsoluteFile());
+ String line;
+ BufferedReader bReader = new BufferedReader(reader);
+ while ((line =bReader.readLine())!=null){
+ Log.i("读取","从文件读取的内容: " + line);
+ }
+ bReader.close();
+ reader.close();
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ // 显示结果
+ showResult(file.getAbsolutePath());
+ }
+
+ /* Checks if external storage is available for read and write */
+ private boolean isExternalStorageWritable() {
+ String state = Environment.getExternalStorageState();
+ if (Environment.MEDIA_MOUNTED.equals(state)) {
+ return true;
+ }
+ return false;
+ }
+
+ /* Checks if external storage is available to at least read */
+ private boolean isExternalStorageReadable() {
+ String state = Environment.getExternalStorageState();
+ if (Environment.MEDIA_MOUNTED.equals(state) ||
+ Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
+ return true;
+ }
+ return false;
+ }
+
+ // 创建公开的外部存储目录(App卸载时不会删除)
+ private File getPublicExtStorageDir(String dirName, String type) {
+ if (type == null) { // 指定文件类型
+ type = Environment.DIRECTORY_PICTURES;
+ }
+ File dir = new File(Environment.getExternalStoragePublicDirectory(type), dirName);
+ if (!dir.mkdirs()) {
+ Log.e("无法创建", "目录无法创建!");
+ }
+
+ long freeSpace = dir.getFreeSpace();
+ Log.i("剩余空间", "剩余空间大小: " + (freeSpace / 1024 / 1024) + "MB");
+ long totalSpace = dir.getTotalSpace();
+ Log.i("总空间", "总空间大小: " + (totalSpace / 1024 / 1024) + "MB");
+
+ return dir;
+ }
+
+ // 创建私有的外部存储目录(App卸载时会一同删除)
+ private File getPrivateExtStorageDir(Context context, String dirName, String type) {
+ if (type == null) { // 指定文件类型
+ type = Environment.DIRECTORY_PICTURES;
+ }
+ File file = new File(context //
+ .getExternalFilesDir(type), dirName);
+ if (!file.mkdirs()) {
+ Log.e("无法创建", "目录无法创建!");
+ }
+ return file;
+ }
+
+
+ private void showResult(String result) {
+ ((TextView) findViewById(R.id.text_path)) //
+ .setText(result.toCharArray(), 0, result.length());
+ }
+}
diff --git "a/students/soft1714080902301/\345\256\236\351\252\2147/main/java/com/example/myapplication/Main3Activity.java" "b/students/soft1714080902301/\345\256\236\351\252\2147/main/java/com/example/myapplication/Main3Activity.java"
new file mode 100644
index 000000000..7b30d3d2a
--- /dev/null
+++ "b/students/soft1714080902301/\345\256\236\351\252\2147/main/java/com/example/myapplication/Main3Activity.java"
@@ -0,0 +1,97 @@
+package com.example.myapplication;
+
+import android.content.Intent;
+import android.graphics.Bitmap;
+import android.os.Bundle;
+import android.provider.MediaStore;
+import android.support.v7.app.AppCompatActivity;
+import android.util.Log;
+import android.view.View;
+import android.widget.ImageButton;
+import android.widget.TextView;
+
+import org.json.JSONObject;
+
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+public class Main3Activity extends AppCompatActivity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_main3);
+ getJson();
+ ImageButton imageButton=(ImageButton)findViewById(R.id.imageButton);
+ imageButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+
+ dispatchTakePictureIntent();
+
+ }
+ });
+ }
+ public void getJson(){
+ Thread thread=new Thread(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ String url_s="https://raw.githubusercontent.com/517865058/android-labs-2019/master/students/soft1714080902301/json/test.json";
+
+ URL url=new URL(url_s);
+ HttpURLConnection conn = (HttpURLConnection)url.openConnection();
+ conn.setConnectTimeout(5000);//设置超时
+ conn.setUseCaches(false);//数据不多不用缓存了
+ conn.connect();
+ InputStream inputStream=conn.getInputStream();
+ InputStreamReader inputStreamReader=new InputStreamReader(inputStream);
+ BufferedReader bufferedReader=new BufferedReader(inputStreamReader);
+
+ if (conn.getResponseCode()==200){
+ String inputLine;
+ StringBuffer resultData=new StringBuffer();
+ while ((inputLine=bufferedReader.readLine())!=null){
+ resultData.append(inputLine);
+ }
+ String text=resultData.toString();
+ Log.v("out-----",text);
+ JSONObject jsonObject=new JSONObject(text);
+ TextView textView=(TextView)findViewById(R.id.name);
+ TextView textView1=(TextView)findViewById(R.id.username);
+ textView.setText(jsonObject.getString("name"));
+ textView1.setText(jsonObject.getString("username"));
+ //JSONArray jsonArray=jsonObject.getJSONArray("");
+
+ }
+ }catch (Exception e){
+ e.printStackTrace();
+ }
+
+ }
+ });
+ thread.start();
+ }
+ static final int REQUEST_IMAGE_CAPTURE = 1;
+ private void dispatchTakePictureIntent() {
+ Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
+ if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
+ startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
+ setResult(1);
+ }
+
+ }
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
+ Bundle extras = data.getExtras();
+ Bitmap imageBitmap = (Bitmap) extras.get("data");
+ ImageButton imageButton=(ImageButton)findViewById(R.id.imageButton);
+ imageButton.setImageBitmap(imageBitmap);
+ }
+ }
+
+}
diff --git "a/students/soft1714080902301/\345\256\236\351\252\2147/main/java/com/example/myapplication/MainActivity.java" "b/students/soft1714080902301/\345\256\236\351\252\2147/main/java/com/example/myapplication/MainActivity.java"
new file mode 100644
index 000000000..da16f8063
--- /dev/null
+++ "b/students/soft1714080902301/\345\256\236\351\252\2147/main/java/com/example/myapplication/MainActivity.java"
@@ -0,0 +1,37 @@
+package com.example.myapplication;
+
+import android.content.Intent;
+import android.os.Bundle;
+import android.support.v7.app.AppCompatActivity;
+import android.view.View;
+import android.widget.Button;
+
+public class MainActivity extends AppCompatActivity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_main);
+ Button button=(Button) findViewById(R.id.v);
+ button.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+
+ // 另一个Activity的完整名称 = edu.androidlabs.soft123456(包名小写).Soft123456Activity(类名)
+ Intent intent = new Intent(MainActivity.this,Main2Activity.class);
+ startActivity(intent);
+ //startActivity(intent);
+
+ }
+ });
+ Button button1=(Button) findViewById(R.id.me);
+ button1.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ Intent intent = new Intent(MainActivity.this,Main3Activity.class);
+ startActivity(intent);
+ }
+ });
+
+ }
+}
diff --git "a/students/soft1714080902301/\345\256\236\351\252\2147/main/res/drawable/ic_launcher_background.xml" "b/students/soft1714080902301/\345\256\236\351\252\2147/main/res/drawable/ic_launcher_background.xml"
new file mode 100644
index 000000000..0d025f9bf
--- /dev/null
+++ "b/students/soft1714080902301/\345\256\236\351\252\2147/main/res/drawable/ic_launcher_background.xml"
@@ -0,0 +1,170 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git "a/students/soft1714080902301/\345\256\236\351\252\2147/main/res/drawable/shape.xml" "b/students/soft1714080902301/\345\256\236\351\252\2147/main/res/drawable/shape.xml"
new file mode 100644
index 000000000..b7f4f70d2
--- /dev/null
+++ "b/students/soft1714080902301/\345\256\236\351\252\2147/main/res/drawable/shape.xml"
@@ -0,0 +1,8 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/students/soft1714080902301/\345\256\236\351\252\2147/main/res/layout/activity_main.xml" "b/students/soft1714080902301/\345\256\236\351\252\2147/main/res/layout/activity_main.xml"
new file mode 100644
index 000000000..9692ff0ba
--- /dev/null
+++ "b/students/soft1714080902301/\345\256\236\351\252\2147/main/res/layout/activity_main.xml"
@@ -0,0 +1,228 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git "a/students/soft1714080902301/\345\256\236\351\252\2147/main/res/layout/activity_main2.xml" "b/students/soft1714080902301/\345\256\236\351\252\2147/main/res/layout/activity_main2.xml"
new file mode 100644
index 000000000..16cdee64d
--- /dev/null
+++ "b/students/soft1714080902301/\345\256\236\351\252\2147/main/res/layout/activity_main2.xml"
@@ -0,0 +1,96 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/students/soft1714080902301/\345\256\236\351\252\2147/main/res/layout/activity_main3.xml" "b/students/soft1714080902301/\345\256\236\351\252\2147/main/res/layout/activity_main3.xml"
new file mode 100644
index 000000000..b3f875e5d
--- /dev/null
+++ "b/students/soft1714080902301/\345\256\236\351\252\2147/main/res/layout/activity_main3.xml"
@@ -0,0 +1,64 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/students/soft1714080902301/\345\256\236\351\252\2147/main/res/layout/activity_main4.xml" "b/students/soft1714080902301/\345\256\236\351\252\2147/main/res/layout/activity_main4.xml"
new file mode 100644
index 000000000..5e90b04a8
--- /dev/null
+++ "b/students/soft1714080902301/\345\256\236\351\252\2147/main/res/layout/activity_main4.xml"
@@ -0,0 +1,68 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file