Skip to content

Commit

Permalink
#6 #1510 第六次实验及报告
Browse files Browse the repository at this point in the history
  • Loading branch information
CharleyChase committed Jun 2, 2018
1 parent d43cfd7 commit 992051b
Show file tree
Hide file tree
Showing 11 changed files with 434 additions and 3 deletions.
Binary file added com1614080901245/61.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added com1614080901245/62.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added com1614080901245/63.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 17 additions & 3 deletions com1614080901245/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,23 @@
</intent-filter>
</activity>
<activity
android:name=".SecondActivity"
android:label="@string/title_activity_second"
android:theme="@style/AppTheme.NoActionBar"></activity>
android:name=".com1614080901245Activity2"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".change"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".view"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" />
</application>
<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" />

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package edu.hzuapps.androidlabs.com1614080901245;

import android.app.Activity;
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.widget.Button;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.app.Activity;
import android.content.Intent;
import android.os.Environment;
import android.util.Log;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;

public class change extends AppCompatActivity {

public static final String DIRECTORY = "demo";
public static final String FILENAME = "file_demo.txt";
public static final String TAG = change.class.getSimpleName();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_change);
final Activity thisActivity = this;
((Button) findViewById(R.id.btn_2)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String text = ((EditText) findViewById(R.id.edit_text)).getText().toString();
saveTextIntoInternalStorage(text);
}
});

}
// 将文字保存到内部存储
private void saveTextIntoInternalStorage(String text) {
// 获取内部存储目录
File dir = this.getFilesDir();
//File dir = getCacheDir();
if (dir.isDirectory()) {
// dir.mkdir();
// dir.mkdirs();
}
if (dir.isFile()) {
// D:/Abc.txt , -> D:/Abc1.txt ->D:/abc.txt
}
File file = new File(dir, FILENAME);
// try {
// File = File.createTempFile(FILENAME, null, dir);
// } catch (IOException e) {
// e.printStackTrace();
// }
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(FILENAME, 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());
BufferedReader bReader = new BufferedReader(reader);
String line = bReader.readLine();
Log.i(TAG, "从文件读取的内容: " + line);
bReader.close();
reader.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// 显示结果
showResult(file.getAbsolutePath());
// 删除文件
// file.delete();
// deleteFile(FILENAME);
}
private void showResult(String result) {
((TextView) findViewById(R.id.view1))
.setText(result.toCharArray(), 0, result.length());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package edu.hzuapps.androidlabs.com1614080901245;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;

public class view extends Activity {
private EditText editText;
private Button button;
private ImageView imageView;
private Bitmap bitmap;
//手柄更新的作用
Handler handler=new Handler(){
public void handleMessage(Message msg) {
if(msg.what==111){
imageView.setImageBitmap(bitmap);
}
};
};
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view);
//初始化组件
editText=(EditText) findViewById(R.id.view2);
button=(Button) findViewById(R.id.btn_3);
imageView=(ImageView) findViewById(R.id.imview);
//给下载按钮添加一个监听
button.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
new Thread(t).start();
}
});
}
//为了下载图片资源,开辟一个新的子线程
Thread t=new Thread(){
public void run() {
//下载图片的路径
String iPath=editText.getText().toString();
try {
//对资源链接
URL url=new URL(iPath);
//打开输入流
InputStream inputStream=url.openStream();
//对网上资源进行下载转换位图图片
bitmap=BitmapFactory.decodeStream(inputStream);
handler.sendEmptyMessage(111);
inputStream.close();
//再一次打开
inputStream=url.openStream();
File file=new File(Environment.getExternalStorageDirectory()+"/DCIM/");
FileOutputStream fileOutputStream=new FileOutputStream(file);
int hasRead=0;
while((hasRead=inputStream.read())!=-1){
fileOutputStream.write(hasRead);
}
fileOutputStream.close();
inputStream.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
};
};
}
49 changes: 49 additions & 0 deletions com1614080901245/main/res/layout/activity_change.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
android:background="@drawable/b"
tools:context=".change">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="编辑信息"
android:textColor="#000000"
android:textSize="25sp"
android:layout_marginTop="10dp"
android:layout_marginLeft="140dp"/>

<Button
android:id="@+id/btn_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="保存"
android:textColor="#000000"
android:layout_marginTop="0dp"
android:layout_marginLeft="300dp"/>

<EditText
android:id="@+id/edit_text"
android:layout_width="383dp"
android:layout_height="480dp"
android:layout_marginTop="50dp"
android:gravity="top"/>
<TextView
android:id="@+id/view1"
android:layout_width="match_parent"
android:layout_height="33dp"
android:gravity="center"
android:layout_marginTop="530dp"
android:textColor="#30F"
android:textStyle="bold"/>
</RelativeLayout>


</android.support.constraint.ConstraintLayout>
51 changes: 51 additions & 0 deletions com1614080901245/main/res/layout/activity_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/c"
tools:context=".view">

<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="384dp"
android:layout_height="60dp"
android:gravity="center"
android:text="头像查看"
android:textColor="#3232CD"
android:textSize="40dp"
android:textStyle="bold"/>
<Button
android:id="@+id/btn_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="显示"
android:textSize="25dp"
android:textColor="#000000"
android:layout_marginTop="515dp"
android:layout_marginLeft="150dp"/>
<EditText
android:id="@+id/view2"
android:layout_width="match_parent"
android:layout_height="40dp"
android:text="http://image.so.com/v?q=10086&src=tab_www&correct=10086&cmsid=380e24427da160cfe109e84e96741c4f&cmran=0&cmras=0&cn=0&gn=0&kn=6#multiple=0&gsrc=1&dataindex=13&id=9b80529c67408c4e35d7f67d89d8fb89&currsn=0&jdx=13&fsn=66"
android:layout_marginTop="60dp"/>
<ImageView
android:id="@+id/imview"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_marginTop="100dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="查看"
android:textColor="#000000"
android:textSize="30dp"
android:layout_marginTop="400dp"/>

</RelativeLayout>
</LinearLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".com1614080901245Activity"
>

<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/app"
>
<Button
android:id="@+id/btn01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="查看"
android:textColor="#3F51B5"
android:textSize="25dp"
android:layout_marginLeft="150dp"
android:layout_marginTop="300dp"/>
</RelativeLayout>

</android.support.constraint.ConstraintLayout>
Loading

0 comments on commit 992051b

Please sign in to comment.