mirror of
https://github.com/yexuejc/rrxjava.git
synced 2025-12-25 04:12:45 +08:00
first
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
package com.yexue.android.rrxjava.utils;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.os.Handler;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* Created by admin on 2017/7/6.
|
||||
*/
|
||||
|
||||
public class HttpConn extends Thread {
|
||||
String picStr;
|
||||
CallBack callBack;
|
||||
private Handler handler;
|
||||
|
||||
public HttpConn(String picStr, Handler handler, CallBack callBack) {
|
||||
this.picStr = picStr;
|
||||
this.callBack = callBack;
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
URL imgUrl = null;
|
||||
try {
|
||||
imgUrl = new URL(picStr);
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
/*取得联机*/
|
||||
HttpURLConnection conn = (HttpURLConnection) imgUrl.openConnection();
|
||||
conn.connect();
|
||||
/*取得回传的InputStream*/
|
||||
InputStream is = conn.getInputStream();
|
||||
/*将InputStream转化为Bitmap*/
|
||||
final Bitmap bitmap = BitmapFactory.decodeStream(is);
|
||||
//用Handler post()方法通知主线程
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
callBack.onCompleted(bitmap);
|
||||
}
|
||||
});
|
||||
/*关闭InputStream*/
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public interface CallBack {
|
||||
public void onCompleted(Bitmap bitmap);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# By default, the flags in this file are appended to flags specified
|
||||
# in C:\Users\admin\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt
|
||||
# You can edit the include path and order by changing the proguardFiles
|
||||
# directive in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# Add any project specific keep options here:
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
Reference in New Issue
Block a user