Skip to content

Commit

Permalink
Merge pull request #1895 from kunknu/master
Browse files Browse the repository at this point in the history
#7 #666 提交实验7代码
  • Loading branch information
zengsn authored May 14, 2019
2 parents 288bdaa + 7adf91e commit 69a25ee
Show file tree
Hide file tree
Showing 9 changed files with 447 additions and 0 deletions.
73 changes: 73 additions & 0 deletions students/soft1714080902324/shiyan5/dlMainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package edu.hzu.shiyan5;

import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import java.io.FileInputStream;
import java.io.FileOutputStream;

public class dlMainActivity extends AppCompatActivity {

private EditText et_info;
private EditText et_info2;
private Button btn_save;
private Button btn_read;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dlactivity_main);

et_info = (EditText) findViewById(R.id.et_info);
et_info2= (EditText) findViewById(R.id.et_info2);
btn_save = (Button) findViewById(R.id.btn_save);
btn_read = (Button) findViewById(R.id.btn_read);
btn_read.setOnClickListener(new ButtonListener());
btn_save.setOnClickListener(new ButtonListener());
}

private class ButtonListener implements View.OnClickListener {
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_save:
String hang="\n";
String saveinfo = et_info.getText().toString().trim();
String saveinfo2 = et_info2.getText().toString().trim();
FileOutputStream fos;
try {
fos = openFileOutput("data.txt", Context.MODE_APPEND);
fos.write(hang.getBytes());
fos.write(saveinfo.getBytes());
fos.write(hang.getBytes());
fos.write(saveinfo2.getBytes());
fos.write(hang.getBytes());
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
Toast.makeText(dlMainActivity.this, "数据保存成功", 0).show();
break;
case R.id.btn_read:
String content = "";
try {
FileInputStream fis = openFileInput("data.txt");
byte[] buffer = new byte[fis.available()];
fis.read(buffer);
content = new String(buffer);
fis.close();
} catch (Exception e) {
e.printStackTrace();
}
Toast.makeText(dlMainActivity.this, "保存的数据是:" + content,Toast.LENGTH_SHORT).show();
break;
default:
break;
}
}
}
}
71 changes: 71 additions & 0 deletions students/soft1714080902324/shiyan5/dlactivity_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
tools:context=".MainActivity">

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="账号"
android:textSize="20dp" />

<EditText
android:id="@+id/et_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"

android:ems="10">

<requestFocus />
</EditText>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="密码"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:textSize="20dp"
android:layout_centerInParent="true"/>
<EditText
android:id="@+id/et_info2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"

android:ems="10">

<requestFocus />
</EditText>

<Button
android:id="@+id/btn_read"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/et_info"
android:layout_alignRight="@+id/et_info"
android:text="读取信息" />

<Button
android:id="@+id/btn_save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/et_info"
android:text="保存信息" />




</LinearLayout>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions students/soft1714080902324/shiyan6/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="edu.hzu.zhangshanghuiyuan" >

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

</application>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
95 changes: 95 additions & 0 deletions students/soft1714080902324/shiyan6/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package edu.hzu.zhangshanghuiyuan;

import android.Manifest;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import javax.net.ssl.HttpsURLConnection;

public class MainActivity extends AppCompatActivity {

protected static final int CHANGE_UI=1;
protected static final int ERROR=2;
private EditText et_path;
private ImageView iv;

//主线建立消息处理器

private Handler handler=new Handler(){
public void handleMessage(android.os.Message msg){
if(msg.what==CHANGE_UI){
Bitmap bitmap=(Bitmap) msg.obj;
iv.setImageBitmap(bitmap);
}
else if(msg.what==ERROR){
Toast.makeText(MainActivity.this,"显示图片错误",0).show();
}
};
};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et_path=(EditText) findViewById(R.id.et_path);
iv=(ImageView) findViewById(R.id.iv);

}



public void click(View view){
final String path=et_path.getText().toString().trim();
if(TextUtils.isEmpty(path)){
Toast.makeText(this,"图片路径不能为空",0).show();
}
else{
//子程序请求网络
new Thread(){
private HttpURLConnection conn;
private Bitmap bitmap;
public void run(){
try{
URL url=new URL(path);
conn=(HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(5000);
conn.setRequestProperty("User-Agent","Mozilla/4.0(compatible;MSIE 6.0;Window NT 5.1;"+"SV1;.NET4.0C;.NET ClR 2.0.50727;"+".NET CLR 3.04506.2152;.NET CLR 3.5.30729;shuame)");
int code=conn.getResponseCode();
if(code==200){
InputStream is=conn.getInputStream();
bitmap= BitmapFactory.decodeStream(is);
//告诉主线程一个消息:帮我更改界面
Message msg=new Message();
msg.what=CHANGE_UI;
msg.obj=bitmap;
handler.sendMessage(msg);
} else{
Message msg=new Message();
msg.what=ERROR;
handler.sendMessage(msg);
}
}catch (Exception e){
e.printStackTrace();
Message msg=new Message();
msg.what=ERROR;
handler.sendMessage(msg);
}
};
}.start();
}
}
}
30 changes: 30 additions & 0 deletions students/soft1714080902324/shiyan6/activity_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">


<ImageView
android:layout_weight="1000"
android:id="@+id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:id="@+id/et_path"
android:text="请输入图片路径"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="click"
android:text="浏览"/>
</LinearLayout>



34 changes: 34 additions & 0 deletions students/soft1714080902324/shiyan7/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="edu.hzu.myapplication">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.example.cameraalbumtest.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"/>
</provider>
</application>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-feature android:name="android.hardware.camera"
android:required="false" />


</manifest>
Loading

0 comments on commit 69a25ee

Please sign in to comment.