forked from hzuapps/android-labs-2018
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d4039b0
commit 3dadce9
Showing
16 changed files
with
134 additions
and
2 deletions.
There are no files selected for viewing
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
1 change: 0 additions & 1 deletion
1
soft1614080902142/app/src/main/java/com/example/muren/soft1614080902142/MainActivity.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
100 changes: 100 additions & 0 deletions
100
soft1614080902142/app/src/main/java/com/example/muren/soft1614080902142/Xia.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,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.
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
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.
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,21 @@ | ||
һ��ʵ��Ŀ�� | ||
|
||
1������Android������ʷ��� | ||
|
||
����ʵ������ | ||
|
||
1������������һ��ͼƬ | ||
|
||
2�����浽�ֻ�����Ӧ����ʹ���ļ� | ||
|
||
3����Ӧ�����н����ͼ | ||
|
||
����ʵ�鲽�� | ||
|
||
1����AndroidManifest�ļ��������������Ȩ�� | ||
|
||
2���IJ��֣���xml�ļ��м�һ��Button���ڵ������ͼƬ����һ��ImageView�ؼ�������ʾͼƬ | ||
|
||
3���½�һ���࣬����һ���̣߳����������緢������ | ||
|
||
4����Activity�����е��ô��̷߳�����ʵ�ֵ����ťʱ����ͼƬ |
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.