Skip to content

Commit

Permalink
hzuapps#6#1614080902142第六次实验
Browse files Browse the repository at this point in the history
  • Loading branch information
HandsomeFace committed Jun 1, 2018
1 parent d4039b0 commit 3dadce9
Show file tree
Hide file tree
Showing 16 changed files with 134 additions and 2 deletions.
2 changes: 1 addition & 1 deletion soft1614080902142/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.muren.soft1614080902142">

<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.example.muren.soft1614080902142;


import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package com.example.muren.soft1614080902142;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class Xia extends AppCompatActivity {
private Handler handler=new Handler();
ImageView imageView;
private String url = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1527531897964&di=94ebd784238561ddbcd0647b1cd4e745&imgtype=0&src=http%3A%2F%2Fd.hiphotos.baidu.com%2Fimage%2Fpic%2Fitem%2F94cad1c8a786c9171cc12b9dc53d70cf3ac75757.jpg";
Bitmap bmImg;

//在消息队列中实现对控件的更改
private Handler handle = new Handler() {
public void handleMessage(Message msg) {
switch (msg.what) {
case 0:
System.out.println("111");
Bitmap bmp=(Bitmap)msg.obj;
imageView.setImageBitmap(bmp);
break;
}
};
};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = (ImageView) findViewById(R.id.my_view);
Button btn=(Button) findViewById(R.id.download);
btn.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
//新建线程加载图片信息,发送到消息队列中
new Thread(new Runnable() {

@Override
public void run() {
// TODO Auto-generated method stub
Bitmap bmp = getURLimage(url);
Message msg = new Message();
msg.what = 0;
msg.obj = bmp;
System.out.println("000");
handle.sendMessage(msg);
}
}).start();
}
});
}


//加载图片
public Bitmap getURLimage(String url) {
Bitmap bmp = null;
try {
URL myurl = new URL(url);
// 获得连接
HttpURLConnection conn = (HttpURLConnection) myurl.openConnection();
conn.setConnectTimeout(6000);//设置超时
conn.setDoInput(true);
conn.setUseCaches(false);//不缓存
conn.connect();
InputStream is = conn.getInputStream();//获得图片的数据流
bmp = BitmapFactory.decodeStream(is);
is.close();
} catch (Exception e) {
e.printStackTrace();
}
return bmp;
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions soft1614080902142/app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,16 @@
android:id="@+id/savetime"
android:layout_weight="0.05" />

<Button
android:text="下载图片"
android:textSize="@dimen/activity_horizontal_margin"
android:background="@color/colorYellow"
android:layout_width="103dp"
android:layout_height="wrap_content"
android:id="@+id/download"
android:layout_weight="0.05" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/my_view"/>
</LinearLayout>
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.
Binary file added soft1614080902142/实验六截图.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions soft1614080902142/实验六报告.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
һ��ʵ��Ŀ��

1������Android������ʷ���

����ʵ������

1������������һ��ͼƬ

2�����浽�ֻ�����Ӧ����ʹ���ļ�

3����Ӧ�����н����ͼ

����ʵ�鲽��

1����AndroidManifest�ļ��������������Ȩ��

2���޸IJ��֣���xml�ļ��м�һ��Button���ڵ������ͼƬ����һ��ImageView�ؼ�������ʾͼƬ

3���½�һ���࣬����һ���̣߳����������緢������

4����Activity�����е��ô��̷߳�����ʵ�ֵ����ťʱ����ͼƬ
Binary file removed soft1614080902142/实验截图5 (2).jpg
Binary file not shown.
Binary file removed soft1614080902142/实验截图5.jpg
Binary file not shown.
Binary file added soft1614080902142/实验截图六(1).jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.

0 comments on commit 3dadce9

Please sign in to comment.