Skip to content

Commit

Permalink
Merge pull request #2227 from xiaozzcc/master
Browse files Browse the repository at this point in the history
第六次实验
  • Loading branch information
zengsn authored May 24, 2018
2 parents 6449831 + 8662fab commit 4a7813b
Show file tree
Hide file tree
Showing 11 changed files with 201 additions and 0 deletions.
Binary file added Soft1614080902415/6.1.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 Soft1614080902415/6.2.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 Soft1614080902415/6.3.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 Soft1614080902415/6.4.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 Soft1614080902415/6.5.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions Soft1614080902415/java/Soft1614080902415Activity3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package edu.hzuapps.androidlabs.soft1614080902415;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.content.SharedPreferences;
import android.content.Context;
import android.content.Intent;
public class Soft1614080902415Acitvity3 extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.acitivity_soft1614080902415_03);
final EditText editText=(EditText)findViewById(R.id.editText);
//获取控件
Button btnLogin=(Button)findViewById(R.id.button0);
// Button buttonque=(Button)findViewById(R.id.queding);
//final EditText EdPassword=(EditText) findViewById(R.id.edit_text);
final EditText EdUserName=(EditText)findViewById(R.id.editText);

btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences sharedPreferences = getSharedPreferences("jnc", Context.MODE_PRIVATE);//创建SharedPreferences对象
SharedPreferences.Editor editor = sharedPreferences.edit(); //需要获取SharedPreferences的编辑对象
editor.putString("username", editText.getText().toString()); //向preferences写入数据:
//editor.putString("Password", EdPassword.getText().toString());
editor.commit();// 向preferences文件中提交数据:
Intent intent=new Intent(Soft1614080902415Acitvity3.this,Soft1614080902415Activity4.class);
startActivity(intent);
}
} );
}

}
65 changes: 65 additions & 0 deletions Soft1614080902415/java/Soft1614080902415Activity4.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package edu.hzuapps.androidlabs.soft1614080902415;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.widget.ImageView;
import android.widget.TextView;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

public class Soft1614080902415Activity4 extends AppCompatActivity {

private ImageView imageView;
//»ñȡͼƬ
public Bitmap getPicture(String wu){
Bitmap yu=null;
try{
URL url=new URL(wu);
URLConnection connection=url.openConnection();
connection.connect();
InputStream inputStream=connection.getInputStream();
yu= BitmapFactory.decodeStream(inputStream);
} catch (java.net.MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return yu;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_soft1614080902415_04);
imageView = (ImageView) findViewById(R.id.image);
TextView txtUserName=(TextView) findViewById(R.id.textView3);
SharedPreferences sharedPreferences = getSharedPreferences("jnc", Context.MODE_PRIVATE);
final String userName=sharedPreferences.getString("username","");
txtUserName.setText(userName);
new Thread(new Runnable() {
@Override
public void run() {
final Bitmap bitmap=getPicture(userName);
//final Bitmap bitmap=getPicture("https://upload.chebaba.com/cms/article/05338129504020508.jpg");
try {
Thread.sleep(1997);
} catch (InterruptedException e) {
e.printStackTrace();
}

imageView.post(new Runnable() {
@Override
public void run() {
imageView.setImageBitmap(bitmap);
}
});
}
}).start();
}
}
14 changes: 14 additions & 0 deletions Soft1614080902415/layout/acitvity_soft1614080902415_01.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,19 @@
android:textColor="#fff"
android:layout_marginTop="10dp"
/>
<Button
android:id="@+id/btn_login5"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="36dp"
android:background="@drawable/ic_launcher_background"
android:text="下载车辆相关信息"
android:textColor="#fff"
android:textSize="20sp" />

</RelativeLayout>

</RelativeLayout>
</RelativeLayout>
23 changes: 23 additions & 0 deletions Soft1614080902415/layout/activity_soft1614080902415_03.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">



<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName"
android:text="ÇëÊäÈëÏÂÔصØÖ·" />
<Button
android:id="@+id/button0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_below="@id/editText"
android:text="ÏÂÔØ" />
</LinearLayout>
34 changes: 34 additions & 0 deletions Soft1614080902415/layout/activity_soft1614080902415_04.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">


<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"

>

</ImageView>

<TextView
android:id="@+id/textView2"
android:layout_below="@id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10sp"
android:layout_marginLeft="30sp"
android:text="ͼƬµØַΪ" />

<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10sp"
android:layout_marginLeft="120sp"
android:layout_below="@id/textView2"
/>
</RelativeLayout>
27 changes: 27 additions & 0 deletions Soft1614080902415/report6.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
实验6: Android网络编程

一、实验内容

1.从网络下载一个文件(图片、MP3、MP4);

2.保存到手机,在应用中使用文件;

3.将应用运行结果截图。

二、实验步骤

1.acitvity_soft1614080902415_01添加一个租车信息下载按钮,并添加监听跳转到Soft1614080902415Acitvity3,并实现安卓软件的联网功能
2.在Soft1614080902415Acitvity3输入下载连接,点击下载
3.跳转到Soft1614080902415Acitvity4
4.在Soft1614080902415Acitvity4实现接收网址并且从网上下载图片的功能。


## 三、实验
![image](https://raw.githubusercontent.com/xiaozzcc/android-labs-2018/master/Soft1614080902415//6.1.jpg)
![image](https://raw.githubusercontent.com/xiaozzcc/android-labs-2018/master/Soft1614080902415//6.2.jpg)
![image](https://raw.githubusercontent.com/xiaozzcc/android-labs-2018/master/Soft1614080902415//6.3.jpg)
![image](https://raw.githubusercontent.com/xiaozzcc/android-labs-2018/master/Soft1614080902415//6.4.jpg)
![image](https://raw.githubusercontent.com/xiaozzcc/android-labs-2018/master/Soft1614080902415//6.5.jpg)

四、实验体会
本次实验学会了安装软件的联网操作,从网络下载了一个文件保存到手机并使用

0 comments on commit 4a7813b

Please sign in to comment.