号簿助手 v4.6.31版本的 MD5 值为:9d7ff98a6bb5cc178eac2df4d1b2f0e0
以下内容为反编译后的 CaptureActivity.java 源代码,内容仅作参考
package com.chinatelecom.pim.activity.zxing;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Vibrator;
import android.support.v4.view.ViewCompat;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.chinatelecom.pim.R;
import com.chinatelecom.pim.activity.setting.WebViewActivity;
import com.chinatelecom.pim.activity.setting.nfc.NfcReadDetailActivity;
import com.chinatelecom.pim.activity.zxing.decoding.CaptureActivityHandler;
import com.chinatelecom.pim.activity.zxing.decoding.InactivityTimer;
import com.chinatelecom.pim.activity.zxing.decoding.RGBLuminanceSource;
import com.chinatelecom.pim.activity.zxing.decoding.Utils;
import com.chinatelecom.pim.core.CoreManagerFactory;
import com.chinatelecom.pim.core.IConstant;
import com.chinatelecom.pim.core.manager.MediaFileManager;
import com.chinatelecom.pim.core.manager.VcardManager;
import com.chinatelecom.pim.foundation.lang.log.Log;
import com.chinatelecom.pim.foundation.lang.model.contact.Contact;
import com.chinatelecom.pim.foundation.lang.utils.StringUtils;
import com.chinatelecom.pim.foundation.lang.utils.ToastTool;
import com.chinatelecom.pim.ui.view.HeaderView;
import com.chinatelecom.pim.ui.zxing.CameraManager;
import com.chinatelecom.pim.ui.zxing.ViewfinderView;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.ChecksumException;
import com.google.zxing.DecodeHintType;
import com.google.zxing.FormatException;
import com.google.zxing.NotFoundException;
import com.google.zxing.Result;
import com.google.zxing.common.HybridBinarizer;
import com.google.zxing.qrcode.QRCodeReader;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.Hashtable;
import java.util.Vector;
public class CaptureActivity extends Activity implements SurfaceHolder.Callback {
public static final int AutoExpoRequest = 888;
private static final float BEEP_VOLUME = 0.1f;
private static final long VIBRATE_DURATION = 200;
public static boolean hasShowFailed = false;
public static boolean hasShowLogin = false;
private Vector<BarcodeFormat> decodeFormats;
private CaptureActivityHandler handler;
private boolean hasSurface;
private ImageView img_left_header_back;
private InactivityTimer inactivityTimer;
private MediaPlayer mediaPlayer;
private String photo_path;
private boolean playBeep;
private String tagId;
private TextView tv_header_title;
private boolean vibrate;
private ViewfinderView viewfinderView;
private String characterSet = "UTF-8";
private MediaFileManager mediaFileManager = CoreManagerFactory.getInstance().getMediaFileManager();
private Log logger = Log.build(CaptureActivity.class);
private final MediaPlayer.OnCompletionListener beepListener = new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
mediaPlayer.seekTo(0);
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(1);
setContentView(R.layout.qr_code_scan);
CameraManager.init(getApplication());
initWiget();
this.hasSurface = false;
this.inactivityTimer = new InactivityTimer(this);
}
private void initWiget() {
this.viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view);
HeaderView headerView = (HeaderView) findViewById(R.id.header_view);
headerView.getLayout().getBackground().setAlpha(255);
headerView.setMiddleView("扫二维码");
headerView.setRightNextView("相册");
setupListener(headerView);
}
private void setupListener(HeaderView headerView) {
headerView.getLeftView().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
CaptureActivity.this.finish();
}
});
headerView.getRightNextTextView().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
CaptureActivity.this.logger.debug("rightnextview on click.................");
Intent innerIntent = new Intent();
if (Build.VERSION.SDK_INT < 19) {
innerIntent.setAction("android.intent.action.GET_CONTENT");
} else {
innerIntent.setAction("android.intent.action.OPEN_DOCUMENT");
}
innerIntent.setType("image/*");
Intent wrapperIntent = Intent.createChooser(innerIntent, "选择二维码图片");
CaptureActivity.this.startActivityForResult(wrapperIntent, 1);
}
});
}
@Override
protected void onResume() {
super.onResume();
SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
SurfaceHolder surfaceHolder = surfaceView.getHolder();
if (this.hasSurface) {
initCamera(surfaceHolder);
} else {
surfaceHolder.addCallback(this);
surfaceHolder.setType(3);
}
this.decodeFormats = null;
this.playBeep = true;
AudioManager audioService = (AudioManager) getSystemService("audio");
if (audioService.getRingerMode() != 2) {
this.playBeep = false;
}
initBeepSound();
this.vibrate = true;
hasShowFailed = false;
hasShowLogin = false;
}
@Override
protected void onPause() {
super.onPause();
if (this.handler != null) {
this.handler.quitSynchronously();
this.handler = null;
}
CameraManager.get().closeDriver();
}
@Override
public void onDestroy() {
this.inactivityTimer.shutdown();
super.onDestroy();
}
public void handleDecode(Result result, Bitmap barcode) {
this.inactivityTimer.onActivity();
playBeepSoundAndVibrate();
String resultString = result.getText();
if (resultString.contains("http://pim.189.cn/") || resultString.contains("http://219.143.33.51:8002/")) {
Intent intent = new Intent(this, (Class<?>) WebViewActivity.class);
intent.putExtra(IConstant.Intent.NO_SET_TIME_TICK, true);
intent.putExtra(IConstant.Intent.INTENT_WEB_URL, resultString);
intent.putExtra(IConstant.Intent.INTENT_WEB_TITLE, "云名片");
startActivity(intent);
} else {
gotoReadNameCard(resultString);
}
System.out.println("handleDecode resultString ======" + resultString);
finish();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case 1:
String[] proj = {"_data"};
if (data != null && data.getData() != null) {
Cursor cursor = getContentResolver().query(data.getData(), proj, null, null, null);
if (cursor != null && cursor.moveToFirst()) {
int column_index = cursor.getColumnIndexOrThrow("_data");
this.photo_path = cursor.getString(column_index);
this.logger.debug("photo_path:%s", this.photo_path);
}
if (this.photo_path == null) {
this.photo_path = Utils.getPath(getApplicationContext(), data.getData());
}
if (this.photo_path != null) {
parseImg(this.photo_path);
return;
}
return;
}
return;
default:
return;
}
}
protected Result scanningImage(String path) {
if (StringUtils.isEmpty(path)) {
return null;
}
Hashtable<DecodeHintType, String> hints = new Hashtable<>();
hints.put(DecodeHintType.CHARACTER_SET, "utf-8");
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(path, options);
options.inJustDecodeBounds = false;
int sampleSize = (int) (options.outHeight / 200.0f);
if (sampleSize <= 0) {
sampleSize = 1;
}
options.inSampleSize = sampleSize;
Bitmap scanBitmap = BitmapFactory.decodeFile(path, options);
RGBLuminanceSource source = new RGBLuminanceSource(scanBitmap);
BinaryBitmap bitmap1 = new BinaryBitmap(new HybridBinarizer(source));
QRCodeReader reader = new QRCodeReader();
try {
return reader.decode(bitmap1, hints);
} catch (ChecksumException e) {
e.printStackTrace();
return null;
} catch (FormatException e2) {
e2.printStackTrace();
return null;
} catch (NotFoundException e3) {
e3.printStackTrace();
return null;
}
}
public byte[] rgb2YUV(Bitmap bitmap) {
int width = bitmap.getWidth();
int height = bitmap.getHeight();
int[] pixels = new int[width * height];
bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
int len = width * height;
byte[] yuv = new byte[(len * 3) / 2];
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
int rgb = pixels[(i * width) + j] & ViewCompat.MEASURED_SIZE_MASK;
int r = rgb & 255;
int g = (rgb >> 8) & 255;
int b = (rgb >> 16) & 255;
int y = (((((r * 66) + (g * 129)) + (b * 25)) + 128) >> 8) + 16;
int u = (((((r * (-38)) - (g * 74)) + (b * 112)) + 128) >> 8) + 128;
int v = (((((r * 112) - (g * 94)) - (b * 18)) + 128) >> 8) + 128;
if (y < 16) {
y = 16;
} else if (y > 255) {
y = 255;
}
if (u >= 0 && u > 255) {
}
if (v > 255) {
}
yuv[(i * width) + j] = (byte) y;
}
}
return yuv;
}
public String recode(String str) {
this.logger.debug("recode str:%s", str);
try {
boolean ISO = Charset.forName("ISO-8859-1").newEncoder().canEncode(str);
if (ISO) {
String formart = new String(str.getBytes("ISO-8859-1"), com.google.zxing.common.StringUtils.GB2312);
return formart;
}
return str;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return "";
}
}
private void parseImg(final String photo_path) {
this.logger.debug("photo_path1:%s", photo_path);
ToastTool.getToast(this).showMessage("正在解析图片中...");
new Thread(new Runnable() {
@Override
public void run() {
CaptureActivity.this.logger.debug("photo_path2:%s", photo_path);
Result result = CaptureActivity.this.scanningImage(photo_path);
CaptureActivity.this.logger.debug("result:%s", result);
if (result != null) {
String recode = CaptureActivity.this.recode(result.toString());
CaptureActivity.this.gotoReadNameCard(recode);
} else {
Looper.prepare();
Toast.makeText(CaptureActivity.this.getApplicationContext(), "图片格式有误", 0).show();
Looper.loop();
}
}
}).start();
}
public void gotoReadNameCard(final String recode) {
runOnUiThread(new Runnable() {
@Override
public void run() {
VcardManager vcardManager = CoreManagerFactory.getInstance().getVcardManager();
Contact contact = vcardManager.generateContact(recode);
if (contact != null && StringUtils.isNotBlank(contact.getDisplayName())) {
ToastTool.getToast(CaptureActivity.this).showMessage("名片解析成功!");
Intent intent = new Intent(CaptureActivity.this, (Class<?>) NfcReadDetailActivity.class);
intent.putExtra(IConstant.Params.CONTACT, contact);
CaptureActivity.this.startActivity(intent);
CaptureActivity.this.finish();
return;
}
ToastTool.getToast(CaptureActivity.this).showMessage("名片解析失败!");
}
});
}
private void initCamera(SurfaceHolder surfaceHolder) {
try {
CameraManager.get().openDriver(surfaceHolder);
if (this.handler == null) {
this.handler = new CaptureActivityHandler(this, this.decodeFormats, this.characterSet);
}
} catch (IOException e) {
} catch (RuntimeException e2) {
}
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
if (!this.hasSurface) {
this.hasSurface = true;
initCamera(holder);
}
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
this.hasSurface = false;
}
public ViewfinderView getViewfinderView() {
return this.viewfinderView;
}
public Handler getHandler() {
return this.handler;
}
public void drawViewfinder() {
this.viewfinderView.drawViewfinder();
}
private void initBeepSound() {
}
private void playBeepSoundAndVibrate() {
if (this.playBeep && this.mediaPlayer != null) {
this.mediaPlayer.start();
}
if (this.vibrate) {
Vibrator vibrator = (Vibrator) getSystemService("vibrator");
vibrator.vibrate(VIBRATE_DURATION);
}
}
}