-
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 #2227 from xiaozzcc/master
第六次实验
- Loading branch information
Showing
11 changed files
with
201 additions
and
0 deletions.
There are no files selected for viewing
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 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); | ||
} | ||
} ); | ||
} | ||
|
||
} |
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,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(); | ||
} | ||
} |
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
23 changes: 23 additions & 0 deletions
23
Soft1614080902415/layout/activity_soft1614080902415_03.xml
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,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
34
Soft1614080902415/layout/activity_soft1614080902415_04.xml
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,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> |
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,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) | ||
|
||
四、实验体会 | ||
本次实验学会了安装软件的联网操作,从网络下载了一个文件保存到手机并使用 |