Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#5 第五次实验,#6 第六次实验 #2617

Merged
merged 5 commits into from
Jun 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions soft1614080902434/2.app/2.app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="edu.hzuapps.androidlabs.soft1614080902434">
package="soft1614080902434.androidlabs.hzuapps.edu.soft1614080902434">
<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"
Expand All @@ -9,13 +15,15 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".Soft1614080902434_Activity">

<activity android:name=".Wechat">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Second_Activity"></activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -1,44 +1,118 @@
package soft1614080902434.androidlabs.hzuapps.edu.soft1614080902434;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.RequiresPermission;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.net.MalformedURLException;
import java.net.URL;

public class Second_Activity extends AppCompatActivity implements View.OnClickListener {
TextView t[] = new TextView[12];
EditText ed;
Button send,down;
public TextView text;
private ImageView imageview;
private Bitmap bitmap;
Handler handler=new Handler(){
public void handleMessage(Message msg) {
if(msg.what==123){
imageview.setImageBitmap(bitmap);
}
};
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second_);
this.RegisterEcent();
}
public void RegisterEcent(){
t[0]=(TextView) findViewById(R.id.n_0);
t[1]=(TextView) findViewById(R.id.n_1);
t[2]=(TextView) findViewById(R.id.n_2);
t[3]=(TextView) findViewById(R.id.n_3);
t[4]=(TextView) findViewById(R.id.n_4);
t[5]=(TextView) findViewById(R.id.n_5);
t[6]=(TextView) findViewById(R.id.n_6);
t[7]=(TextView) findViewById(R.id.n_7);
t[8]=(TextView) findViewById(R.id.n_8);
t[9]=(TextView) findViewById(R.id.n_9);
t[10]=(TextView) findViewById(R.id.n_10);
t[11]=(TextView) findViewById(R.id.n_11);
t[12]=(TextView) findViewById(R.id.n_12);
t[13]=(TextView) findViewById(R.id.n_13);
t[14]=(TextView) findViewById(R.id.n_14);
t[15]=(TextView) findViewById(R.id.n_15);
t[16]=(TextView) findViewById(R.id.n_16);
for(int i=0;i<17;i++){
t[i].setOnClickListener(this);
}

down = (Button)findViewById(R.id.Down);
down.setOnClickListener(this);
imageview=(ImageView) findViewById(R.id.image);
text = (TextView)findViewById(R.id.address);
ed = (EditText)findViewById(R.id.edit_text);
send = (Button)findViewById(R.id.n_12);
send.setOnClickListener(this);
Log.d("dd","789");
}

@Override
public void onClick(View v) {

public void save(String str){
String data=str;
FileOutputStream out=null;
BufferedWriter writer=null;

try{
out =openFileOutput("wechat", Context.MODE_PRIVATE);
writer=new BufferedWriter(new OutputStreamWriter(out));
Log.d("dd","456");
writer.write(data);
} catch(IOException e){
e.printStackTrace();
} finally {
if (writer !=null){
try {
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
@Override
public void onClick(View view){
if(view==send) {
String str = ed.getText().toString();
this.save(str);
Log.d("dd", "123");
}
if(view==down){
new Thread(download).start();
}
}
Thread download = new Thread(){

public void run() {
String Path=text.getText().toString();//下载图片的路径
try {
URL url=new URL(Path);//对资源链接
InputStream inputStream=url.openStream();
bitmap= BitmapFactory.decodeStream(inputStream);//转换成位图图片
handler.sendEmptyMessage(123);
inputStream.close();
inputStream=url.openStream();
File file=new File(Environment.getExternalStorageDirectory()+"./DCIM/wechat.jpg");
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();
}
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
android:layout_width="match_parent"
android:layout_height="304dp"
android:layout_x="0dp"
android:layout_y="2dp"
android:layout_y="0dp"
android:background="#EBEBEB"
tools:layout_editor_absoluteX="1dp"
tools:layout_editor_absoluteY="0dp" />
Expand Down Expand Up @@ -142,6 +142,7 @@
android:layout_x="269dp"
android:layout_y="262dp"
android:text="发送"
android:clickable="true"
tools:layout_editor_absoluteX="298dp"
tools:layout_editor_absoluteY="538dp" />

Expand All @@ -165,15 +166,6 @@
tools:layout_editor_absoluteX="340dp"
tools:layout_editor_absoluteY="212dp" />

<Button
android:id="@+id/n_15"
android:layout_width="414dp"
android:layout_height="wrap_content"
android:layout_x="0dp"
android:layout_y="2dp"
android:text=" " />


<TextView
android:id="@+id/n_16"
android:layout_width="250dp"
Expand All @@ -193,5 +185,29 @@
android:layout_x="7dp"
android:layout_y="260dp" />

<Button
android:id="@+id/Down"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="20dp"
android:layout_y="199dp"
android:text="图片"
android:clickable="true"/>

<TextView
android:id="@+id/address"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_x="13dp"
android:layout_y="0dp"
android:text="https://upload.wikimedia.org/wikipedia/commons/8/84/Tibia_insulaechorab.jpg" />

<ImageView
android:id="@+id/image"
android:layout_width="232dp"
android:layout_height="131dp"
android:layout_x="74dp"
android:layout_y="53dp" />


</AbsoluteLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
android:layout_x="243dp"
android:layout_y="293dp"
android:text="表情包"
android:clickable="true"
tools:layout_editor_absoluteX="262dp"
tools:layout_editor_absoluteY="47dp" />

Expand Down
Binary file added soft1614080902434/5.1.png
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 soft1614080902434/5.2.png
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 soft1614080902434/6.1.png
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 soft1614080902434/6.2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions soft1614080902434/report5.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 第五次实验

## 1.实验目的

Android存储编程
## 2.实验步骤
1.打开实验4的工程项目,我要存储发送出去的数据,我做的是内部存储。


2.用到两个关键字: FileOutputStream和BufferedWriter writer。

3.把按钮“发送”作为监听器,当你写上一些数据时,然后点击“发送”,系统此时就自动存储数据.

4.运行程序,然后从Android上面一排的View-Tool Windows-Device File Explorer,在这里找到soft1614080902434里面的File。

5.git push.并pull request.


## 3.实验结果
运行截图:
![Image text](https://github.com/Min4396/android-labs-2018/blob/master/soft1614080902434/5.1.png)
![Image text](https://github.com/Min4396/android-labs-2018/blob/master/soft1614080902434/5.2.png)


## 4.实验心得
这次实验还是比较难,因为我对存储文件很陌生,然后,我查看了一些课外书,找到了一些方法,一开始我运行之后,发现存储不了,找不到原因,然后就在别人的电脑运行,结果可以,然后我回到自己的电脑运行,结果可以了,这个,我学到了一点存储的方法。

27 changes: 27 additions & 0 deletions soft1614080902434/report6.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 实验6
## 一、实验目的

掌握Android网络访问方法。

## 二、实验内容

从百度上寻找一张网址以后缀名为.jpg的图片,把图片的网址放到activity_second_xml文件中。

## 三、实验步骤
1.AndroidManifest.xml中添加能够写入读出内存空间权限和网络连接权限的代码。

2.然后在activity_second_xml中添加一个新的按钮和一个TextView,是用来显示图片的,按钮用来监听。

3.在Second_Activity中写一个线程函数,用来管理下载和显示的图片。

4.编译运行,然后push。


## 四.实验截图
![Image text](https://github.com/Min4396/android-labs-2018/blob/master/soft1614080902434/6.1.png)
![Image text](https://github.com/Min4396/android-labs-2018/blob/master/soft1614080902434/6.2.png)


## 五.实验心得
这次实验主要从网上找图片,然后放到我写的app中,我点击图片按钮的时候,发现没变化,看了一下,原来没开网,同时遇到了线程的函数,我不会,只能上网找资料以及求助同学了,同时注意的是还要给网络连接权限以及空间权限才能下载图片。