reformat code & optimize import & rearrange code
This commit is contained in:
@ -5,14 +5,17 @@ import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.gh.gamecenter.ShareCardActivity;
|
||||
import com.gh.gamecenter.retrofit.Response;
|
||||
import com.google.zxing.*;
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.EncodeHintType;
|
||||
import com.google.zxing.WriterException;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.qrcode.QRCodeWriter;
|
||||
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@ -25,6 +28,31 @@ import rx.schedulers.Schedulers;
|
||||
* Created by khy on 2016/12/1.
|
||||
*/
|
||||
public class QRCodeUtils {
|
||||
public static void setQRCode(final Context context, final String newsId, final ImageView mShareQrCodeDv) {
|
||||
Observable
|
||||
.create(new Observable.OnSubscribe<String>() {
|
||||
@Override
|
||||
public void call(Subscriber<? super String> subscriber) {
|
||||
String filePath = context.getExternalCacheDir().getPath() + "/ShareImg/ShareQRCode.jpg";
|
||||
boolean success = QRCodeUtils.createQRImage("http://www.ghzhushou.com/article/" + newsId + ".html?source=appshare200"
|
||||
, 200, 200, filePath, context);
|
||||
if (success) {
|
||||
subscriber.onNext(filePath);
|
||||
}
|
||||
subscriber.onCompleted();
|
||||
}
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<String>() {
|
||||
@Override
|
||||
public void onResponse(String response) {
|
||||
super.onResponse(response);
|
||||
mShareQrCodeDv.setImageBitmap(BitmapFactory.decodeFile(response));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成二维码Bitmap
|
||||
*
|
||||
@ -82,29 +110,4 @@ public class QRCodeUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void setQRCode(final Context context, final String newsId, final ImageView mShareQrCodeDv) {
|
||||
Observable
|
||||
.create(new Observable.OnSubscribe<String>() {
|
||||
@Override
|
||||
public void call(Subscriber<? super String> subscriber) {
|
||||
String filePath = context.getExternalCacheDir().getPath() + "/ShareImg/ShareQRCode.jpg";
|
||||
boolean success = QRCodeUtils.createQRImage("http://www.ghzhushou.com/article/" + newsId + ".html?source=appshare200"
|
||||
, 200, 200, filePath, context);
|
||||
if (success) {
|
||||
subscriber.onNext(filePath);
|
||||
}
|
||||
subscriber.onCompleted();
|
||||
}
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<String>(){
|
||||
@Override
|
||||
public void onResponse(String response) {
|
||||
super.onResponse(response);
|
||||
mShareQrCodeDv.setImageBitmap(BitmapFactory.decodeFile(response));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user