Skip to content

Commit

Permalink
添加一个dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
maning committed Nov 10, 2017
1 parent 46a7f8b commit 635328b
Show file tree
Hide file tree
Showing 6 changed files with 883 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
Expand All @@ -38,6 +39,7 @@
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

Expand All @@ -49,6 +51,7 @@
import com.google.zxing.client.android.manager.InactivityTimer;
import com.google.zxing.client.android.utils.ZXingUtils;

import java.io.FileNotFoundException;
import java.util.Collection;
import java.util.Map;

Expand Down Expand Up @@ -91,6 +94,7 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
private TextView tv_scan_light;
private LinearLayout btn_close;
private LinearLayout btn_photo;
private RelativeLayout btn_dialog_bg;
//闪光灯是否打开
private boolean is_light_on = false;
private boolean beepFlag = true;
Expand Down Expand Up @@ -120,6 +124,8 @@ public void onCreate(Bundle icicle) {
tv_scan_light = (TextView) findViewById(R.id.tv_scan_light);
btn_close = (LinearLayout) findViewById(R.id.btn_close);
btn_photo = (LinearLayout) findViewById(R.id.btn_photo);
btn_dialog_bg = (RelativeLayout) findViewById(R.id.btn_dialog_bg);
btn_dialog_bg.setVisibility(View.GONE);

//初始化相关参数
initIntent();
Expand Down Expand Up @@ -159,6 +165,13 @@ public void onClick(View v) {
getImageFromAlbum();
}
});

btn_dialog_bg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

}
});
}

private void initIntent() {
Expand All @@ -183,37 +196,61 @@ private void initIntent() {
* 获取相册中的图片
*/
public void getImageFromAlbum() {
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");//相片类型
Intent intent = new Intent();
/* 开启Pictures画面Type设定为image */
intent.setType("image/*");
/* 使用Intent.ACTION_GET_CONTENT这个Action */
// intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setAction(Intent.ACTION_PICK);
/* 取得相片后返回本画面 */
startActivityForResult(intent, 1000);
//开始转Dialog
btn_dialog_bg.setVisibility(View.VISIBLE);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
//去相册选择图片
if (requestCode == 1000) {
if (data == null) return;
Uri uri = data.getData();
String[] projection = {MediaStore.Images.Media.DATA};
Cursor cursor = this.getContentResolver().query(uri, projection, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
String path = cursor.getString(column_index);
Log.i(TAG, "图片的Path:" + path);

String decodeQRCodeFromBitmap = ZXingUtils.syncDecodeQRCode(path);

Log.i(TAG, "图片的decodeQRCode:" + decodeQRCodeFromBitmap);

if (TextUtils.isEmpty(decodeQRCodeFromBitmap)) {
Toast.makeText(CaptureActivity.this, "未发现二维码", Toast.LENGTH_SHORT).show();
} else {
finishSuccess(decodeQRCodeFromBitmap);
if (data == null){
//隐藏Dialog
btn_dialog_bg.setVisibility(View.GONE);
return;
}

final Uri uri = data.getData();
new Thread(new Runnable() {
@Override
public void run() {
Bitmap bitmapChoose = ZXingUtils.decodeUriAsBitmap(CaptureActivity.this, uri);
if (bitmapChoose != null) {
final String decodeQRCodeFromBitmap = ZXingUtils.syncDecodeQRCode(bitmapChoose);
runOnUiThread(new Runnable() {
@Override
public void run() {
btn_dialog_bg.setVisibility(View.GONE);
Log.i(TAG, "图片的decodeQRCode:" + decodeQRCodeFromBitmap);
if (TextUtils.isEmpty(decodeQRCodeFromBitmap)) {
Toast.makeText(CaptureActivity.this, "未发现二维码", Toast.LENGTH_SHORT).show();
} else {
finishSuccess(decodeQRCodeFromBitmap);
}
}
});
} else {
runOnUiThread(new Runnable() {
@Override
public void run() {
btn_dialog_bg.setVisibility(View.GONE);
}
});
}
}
}).start();
}
}


@Override
protected void onResume() {
super.onResume();
Expand Down
Loading

0 comments on commit 635328b

Please sign in to comment.