-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2217 from wuhengxin/master
- Loading branch information
Showing
12 changed files
with
229 additions
and
10 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
Soft1614080902237/app/src/main/java/com/example/john/soft1614080902237/M1Activity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,37 @@ | ||
package com.example.john.soft1614080902237; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.content.SharedPreferences; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.view.View; | ||
import android.widget.Button; | ||
import android.widget.EditText; | ||
|
||
public class M1Activity extends AppCompatActivity { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_m1); | ||
//获取控件 | ||
Button btnLogin=(Button)findViewById(R.id.btn_login); | ||
final EditText EdPassword=(EditText) findViewById(R.id.Ed_Password); | ||
final EditText EdUserName=(EditText)findViewById(R.id.Ed_UserName); | ||
|
||
btnLogin.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
SharedPreferences sharedPreferences = getSharedPreferences("jzc", Context.MODE_PRIVATE);//创建SharedPreferences对象 | ||
SharedPreferences.Editor editor = sharedPreferences.edit(); //需要获取SharedPreferences的编辑对象 | ||
editor.putString("username", EdUserName.getText().toString()); //向preferences写入数据: | ||
editor.putString("Password", EdPassword.getText().toString()); | ||
editor.commit();// 向preferences文件中提交数据: | ||
Intent intent=new Intent(M1Activity.this,M4Activity.class); | ||
startActivity(intent); | ||
} | ||
} ); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
Soft1614080902237/app/src/main/java/com/example/john/soft1614080902237/M6Activity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,67 @@ | ||
package com.example.john.soft1614080902237; | ||
|
||
import android.content.Context; | ||
import android.content.SharedPreferences; | ||
import android.graphics.Bitmap; | ||
import android.graphics.BitmapFactory; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.widget.ImageView; | ||
import android.widget.TextView; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.net.URLConnection; | ||
|
||
public class M6Activity 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_m6); | ||
imageView = (ImageView) findViewById(R.id.add_image); | ||
TextView txtUserName=(TextView) findViewById(R.id.txt_User); | ||
SharedPreferences sharedPreferences = getSharedPreferences("jnc", Context.MODE_PRIVATE); //创建SharedPreferences对象 | ||
final String userName=sharedPreferences.getString("username","");//根据key获取对应的数据 | ||
txtUserName.setText(userName); | ||
new Thread(new Runnable() { | ||
@Override | ||
public void run() { | ||
final Bitmap bitmap=getPicture(userName); | ||
//final Bitmap bitmap=getPicture("http://pic36.photophoto.cn/20150704/0017029369483757_b.jpg"); | ||
try { | ||
Thread.sleep(1997); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
imageView.post(new Runnable() { | ||
@Override | ||
public void run() { | ||
imageView.setImageBitmap(bitmap); | ||
} | ||
}); | ||
} | ||
}).start(); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
Soft1614080902237/app/src/main/java/com/example/john/soft1614080902237/M7Activity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.example.john.soft1614080902237; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.content.SharedPreferences; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.view.View; | ||
import android.widget.Button; | ||
import android.widget.EditText; | ||
|
||
public class M7Activity extends AppCompatActivity { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_m7); | ||
final EditText editText=(EditText)findViewById(R.id.edit_text); | ||
//获取控件 | ||
Button btnLogin=(Button)findViewById(R.id.xiazai); | ||
// Button buttonque=(Button)findViewById(R.id.queding); | ||
//final EditText EdPassword=(EditText) findViewById(R.id.edit_text); | ||
final EditText EdUserName=(EditText)findViewById(R.id.edit_text); | ||
|
||
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(M7Activity.this,M6Activity.class); | ||
startActivity(intent); | ||
} | ||
} ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,31 @@ | ||
<?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" | ||
tools:context=".M6Activity"> | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" | ||
android:layout_height="match_parent" android:paddingLeft="@dimen/fab_margin" | ||
android:paddingRight="@dimen/fab_margin" | ||
android:paddingTop="@dimen/fab_margin" | ||
android:paddingBottom="@dimen/fab_margin" | ||
tools:context="com.example.john.soft1614080902237.M6Activity"> | ||
|
||
</android.support.constraint.ConstraintLayout> | ||
<ImageView | ||
|
||
android:id="@+id/add_image" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_centerInParent="true" | ||
></ImageView> | ||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="8sp" | ||
android:layout_marginLeft="30sp" | ||
android:text="图片网址为:" | ||
android:textSize="40px"/> | ||
|
||
<TextView | ||
android:id="@+id/txt_User" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="8sp" | ||
android:layout_marginLeft="150sp" | ||
android:textSize="40px"/> | ||
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?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" | ||
tools:context=".M7Activity"> | ||
|
||
<LinearLayout | ||
android:id="@+id/linearLayout2" | ||
android:layout_width="0dp" | ||
android:layout_height="0dp" | ||
android:orientation="vertical" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
|
||
|
||
<EditText | ||
android:id="@+id/edit_text" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:layout_margin="10sp" | ||
android:layout_marginEnd="10dp" | ||
android:layout_marginLeft="10dp" | ||
android:layout_marginRight="10dp" | ||
android:layout_marginStart="10dp" | ||
android:hint="请输入下载的图片网址" | ||
android:maxLength="400" | ||
android:textColorHint="#238745" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="@+id/linearLayout2" /> | ||
|
||
<Button | ||
android:id="@+id/xiazai" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginEnd="16dp" | ||
android:layout_marginRight="16dp" | ||
android:layout_marginTop="16dp" | ||
android:text="下载" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintTop_toBottomOf="@+id/edit_text" /> | ||
|
||
|
||
</android.support.constraint.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# 实验6: Android网络编程 | ||
|
||
## 一、实验内容 | ||
|
||
### 1.从网络下载一个文件(图片、MP3、MP4); | ||
|
||
### 2.保存到手机,在应用中使用文件; | ||
|
||
### 3.将应用运行结果截图。 | ||
|
||
## 二、实验步骤 | ||
|
||
### 1.首先将M3Activity中的BUTTON名称改为图片下载 | ||
|
||
### 2.然后新建一个M7Activity来实现“图片下载的一个跳转” | ||
|
||
### 3.并从这个Activity新建一个按钮”下载“,实现跳转到M6Activity,并将TexView记录的图片网址传给M6Activity。 | ||
|
||
### 4.在M6Activity实现接收网址并且从网上下载图片的功能。 | ||
|
||
### 5.给AndroidManifest.xml添加联网权限。 | ||
|
||
## 三、实验截图 | ||
|
||
![image](https://github.com/wuhengxin/android-labs-2018/blob/master/Soft1614080902237/shiyan6.1.jpg?raw=true) | ||
|
||
![image](https://github.com/wuhengxin/android-labs-2018/blob/master/Soft1614080902237/shiyan6.2.jpg?raw=true) | ||
|
||
![image](https://github.com/wuhengxin/android-labs-2018/blob/master/Soft1614080902237/shiyan6.3.jpg?raw=true) | ||
|
||
![image](https://github.com/wuhengxin/android-labs-2018/blob/master/Soft1614080902237/shiyan6.4.jpg?raw=true) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.