新增二维码扫描操作

This commit is contained in:
limqsh
2020-07-28 18:37:44 +08:00
parent 032fe493a0
commit 7557fa202d
5 changed files with 72 additions and 489 deletions

View File

@@ -95,5 +95,7 @@ dependencies {
implementation 'de.mrmaffen:libvlc-android:2.1.12@aar' implementation 'de.mrmaffen:libvlc-android:2.1.12@aar'
implementation "org.java-websocket:Java-WebSocket:1.4.0" implementation "org.java-websocket:Java-WebSocket:1.4.0"
implementation 'com.tencent.bugly:crashreport:latest.release' implementation 'com.tencent.bugly:crashreport:latest.release'
implementation 'com.google.zxing:core:3.2.1'
implementation 'cn.bingoogolapple:bga-qrcodecore:1.1.7@aar'
implementation 'cn.bingoogolapple:bga-zxing:1.1.7@aar'
} }

View File

@@ -32,39 +32,14 @@ public class MainActivity extends SDBaseActivity {
private final String TAG = "MainActivity"; private final String TAG = "MainActivity";
public final int welcome_show = 10;
public final int user_info_ok = 11;
public final int user_info_fail = 12;
public final int user_info_out_ok = 13;
public final int user_info_recahrge = 14;
@BindView(R.id.welcome_layout)
LinearLayout welcome_layout;
@BindView(R.id.welcome_label) @BindView(R.id.welcome_label)
TextView welcome_label; TextView welcome_label;
@BindView(R.id.topInfoTextView) @BindView(R.id.topInfoTextView)
TextView topInfoTextView; TextView topInfoTextView;
@BindView(R.id.user_avator) @BindView(R.id.order_view)
CircleImageView avator_imageview; WebView order_view;
@BindView(R.id.user_name_label)
TextView user_name_label;
@BindView(R.id.user_phone_label)
TextView user_phone_label;
@BindView(R.id.user_amount_label)
TextView user_amount_label;
@BindView(R.id.faceid_video_view)
WebView faceid_video_view;
@BindView(R.id.sb_string_label) @BindView(R.id.sb_string_label)
TextView sb_string_label; TextView sb_string_label;
@@ -72,37 +47,6 @@ public class MainActivity extends SDBaseActivity {
@BindView(R.id.count_down_label) @BindView(R.id.count_down_label)
TextView count_down_label; TextView count_down_label;
@BindView(R.id.userInfoLayout)
LinearLayout userInfoLayout;
@BindView(R.id.package_name_label)
TextView package_name_label;
@BindView(R.id.user_place_label)
TextView user_place_label;
@BindView(R.id.memberInfoLineView)
LinearLayout memberInfoLineView;
@BindView(R.id.memberInfopackLayout)
LinearLayout memberInfopackLayout;
@BindView(R.id.unit_price_layout)
LinearLayout unit_price_layout;
@BindView(R.id.unit_price_label)
TextView unit_price_label;
@BindView(R.id.unit_price_line_view)
LinearLayout unit_price_line_view;
public int current_status;
public CountDownTimer countDownTimer;
public CountDownTimer firstCountDownTimer;
public EggClickUtil eggClickUtil; public EggClickUtil eggClickUtil;
public void setMaxCountDownTime(int maxCountDownTime) { public void setMaxCountDownTime(int maxCountDownTime) {
@@ -118,25 +62,6 @@ public class MainActivity extends SDBaseActivity {
public static final int maxTime = 15; public static final int maxTime = 15;
public int maxCountDownTime = 15; public int maxCountDownTime = 15;
private static final int SURFACE_BEST_FIT = 0;
private static final int SURFACE_FIT_SCREEN = 1;
private static final int SURFACE_FILL = 2;
private static final int SURFACE_16_9 = 3;
private static final int SURFACE_4_3 = 4;
private static final int SURFACE_ORIGINAL = 5;
private static int CURRENT_SIZE = SURFACE_4_3;
private final Handler mHandler = new Handler();
private int mVideoHeight = 0;
private int mVideoWidth = 0;
private int mVideoVisibleHeight = 0;
private int mVideoVisibleWidth = 0;
private int mVideoSarNum = 0;
private int mVideoSarDen = 0;
private View.OnLayoutChangeListener mOnLayoutChangeListener = null;
private SDErrorDialog errorDialog; private SDErrorDialog errorDialog;
@@ -152,6 +77,7 @@ public class MainActivity extends SDBaseActivity {
configView(); configView();
// 应该是原来的保持屏幕常亮的代码 // 应该是原来的保持屏幕常亮的代码
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
order_view.loadUrl("https://www.baidu.com");
//启动Service //启动Service
Intent socketService = new Intent(this, ClientService.class); Intent socketService = new Intent(this, ClientService.class);
startService(socketService); startService(socketService);
@@ -160,8 +86,6 @@ public class MainActivity extends SDBaseActivity {
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
faceid_video_view.loadUrl("https://www.baidu.com");
faceid_video_view.onResume();
} }
private void initScreen() { private void initScreen() {
@@ -174,32 +98,14 @@ public class MainActivity extends SDBaseActivity {
} }
public void setCurrentStatus(int current_status) { public void setCurrentStatus(int current_status) {
this.current_status = current_status; // 控制样式
this.sb_string_label.setVisibility(View.GONE); if(1 == current_status){
this.unit_price_layout.setVisibility(View.GONE);
this.unit_price_line_view.setVisibility(View.GONE);
if (this.current_status == welcome_show) {
this.count_down_label.setVisibility(View.GONE);
this.welcome_layout.setVisibility(View.VISIBLE);
this.welcome_label.setVisibility(View.GONE);
this.topInfoTextView.setText(getResources().getString(R.string.top_line_info1));
} else {
this.welcome_layout.setVisibility(View.GONE);
this.welcome_label.setVisibility(View.VISIBLE);
}
if (this.current_status == user_info_fail){
this.sb_string_label.setVisibility(View.VISIBLE); this.sb_string_label.setVisibility(View.VISIBLE);
} }
if (this.current_status == user_info_ok || this.current_status == user_info_fail || this.current_status == user_info_out_ok || this.current_status == user_info_recahrge) {
this.userInfoLayout.setVisibility(View.VISIBLE);
} else {
this.userInfoLayout.setVisibility(View.GONE);
}
} }
public void configView() { public void configView() {
this.setCurrentStatus(welcome_show); this.setCurrentStatus(1);
eggClickUtil = new EggClickUtil(() -> { eggClickUtil = new EggClickUtil(() -> {
Intent intent = new Intent(MainActivity.this, SDSettingActivity.class); Intent intent = new Intent(MainActivity.this, SDSettingActivity.class);
startActivity(intent); startActivity(intent);
@@ -210,7 +116,7 @@ public class MainActivity extends SDBaseActivity {
* 加载人脸识别信息 * 加载人脸识别信息
*/ */
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
public void loadFaceidInfo(QRCodeEvent qrCodeEvent) { public void getQRResult(QRCodeEvent qrCodeEvent) {
if (qrCodeEvent.getMsg().equals("不是会员")){ if (qrCodeEvent.getMsg().equals("不是会员")){
// 这个是非会员进入现场 // 这个是非会员进入现场
this.showStrangerDialog(); this.showStrangerDialog();
@@ -218,40 +124,11 @@ public class MainActivity extends SDBaseActivity {
} }
CrashReport.postCatchedException(new Throwable("接受到命令 " + qrCodeEvent.getMsg())); CrashReport.postCatchedException(new Throwable("接受到命令 " + qrCodeEvent.getMsg()));
// 监听到头像 // 监听到头像
Glide.with(this).load("https://www.baidu.com").into(this.avator_imageview);
user_name_label.setText("张三");
user_phone_label.setText("1234567");
user_amount_label.setText("amount");
unit_price_label.setText("price");
welcome_label.setText(String.format("欢迎%s进场", "张三")); welcome_label.setText(String.format("欢迎%s进场", "张三"));
if (TextUtils.isEmpty(qrCodeEvent.getMsg())) { int code = qrCodeEvent.getAction();
memberInfoLineView.setVisibility(View.GONE); switch (code){
memberInfopackLayout.setVisibility(View.GONE); // 场地的信息 case 1:
} else { // TODO 通过处理结果调整页面显示
memberInfoLineView.setVisibility(View.VISIBLE);
memberInfopackLayout.setVisibility(View.VISIBLE);
this.user_place_label.setText(qrCodeEvent.getMsg());
}
int code = 1; // TODO 这个是获取事件的参数
if (code == 2){
// 出场成功
startCountDownTime(user_info_out_ok);
}else if (code == 1){
// 入场成功
if ("firstTime".equals(code)){
// 每天的第一次
firstEnterHome();
}else{
startCountDownTime(user_info_ok);
}
}else if (code == 0 ){
// 入场失败
startCountDownTime(user_info_fail);
}else if (code == -1){
// 余额不足
startCountDownTime(user_info_recahrge);
} }
} }
@@ -268,84 +145,6 @@ public class MainActivity extends SDBaseActivity {
} }
} }
public void firstEnterHome(){
if (this.firstCountDownTimer != null){
this.firstCountDownTimer.cancel();
this.firstCountDownTimer = null;
}
topInfoTextView.setText("人脸认证通过");
// 欢迎页面
this.welcome_layout.setVisibility(View.GONE);
// 顶部的 文字
this.welcome_label.setVisibility(View.VISIBLE);
// 用户信息 layout
this.userInfoLayout.setVisibility(View.VISIBLE);
// 用户信息中的 价格layout
this.unit_price_layout.setVisibility(View.VISIBLE);
this.unit_price_line_view.setVisibility(View.VISIBLE);
this.firstCountDownTimer = new CountDownTimer(3 * 1000, 1 * 1000) {
@Override
public void onTick(long l) {
}
@Override
public void onFinish() {
firstCountDownTimer.cancel();
firstCountDownTimer = null;
startCountDownTime(user_info_ok);
}
};
this.firstCountDownTimer.start();
}
public void startCountDownTime(final int current_status) {
if (this.countDownTimer != null) {
stopCountDownTime();
}
if (this.firstCountDownTimer != null){
firstCountDownTimer.cancel();
firstCountDownTimer = null;
}
topInfoTextView.setVisibility(View.VISIBLE);
count_down_label.setVisibility(View.GONE);
if (current_status == user_info_ok) {
this.setMaxCountDownTime(maxTime);
topInfoTextView.setVisibility(View.GONE);
} else if (current_status == user_info_recahrge){
topInfoTextView.setText("当前余额不足,请立即充值!");
} else if (current_status == user_info_out_ok){
topInfoTextView.setText("欢迎下次光临");
}else if (current_status == user_info_fail){
topInfoTextView.setText("入场失败");
}
this.setCurrentStatus(current_status);
this.countDownTimer = new CountDownTimer(maxTime * 1000, 1 * 1000) {
@Override
public void onTick(long l) {
if (current_status == user_info_ok) {
topInfoTextView.setVisibility(View.GONE);
setMaxCountDownTime(maxCountDownTime - 1);
} else if (current_status == user_info_recahrge){
topInfoTextView.setText("当前余额不足,请立即充值!");
}else {
}
}
@Override
public void onFinish() {
setCurrentStatus(welcome_show);
stopCountDownTime();
}
};
this.countDownTimer.start();
}
public void stopCountDownTime() {
this.countDownTimer.cancel();
this.countDownTimer = null;
}
public void showStrangerDialog(){ public void showStrangerDialog(){
if (errorDialog == null){ if (errorDialog == null){
errorDialog = new SDErrorDialog(this); errorDialog = new SDErrorDialog(this);

View File

@@ -0,0 +1,55 @@
package com.ydd.sportfaceid.utils;
import android.graphics.Bitmap;
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 java.util.Hashtable;
/**
* 生成条形码和二维码的工具
*/
public class QRCodeUtil {
/**
* 生成二维码 要转换的地址或字符串,可以是中文
*
* @param str
* @param width
* @param height
* @return
*/
public static Bitmap createQRImage(String str, int width, int height) {
try {
// 判断URL合法性
if (str == null || "".equals(str) || str.length() < 1) {
return null;
}
Hashtable<EncodeHintType, String> hints = new Hashtable<>();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
// 图像数据转换,使用了矩阵转换
BitMatrix bitMatrix = new QRCodeWriter().encode(str,
BarcodeFormat.QR_CODE, width, height, hints);
int[] pixels = new int[width * height];
// 两个for循环是图片横列扫描的结果
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
if (bitMatrix.get(x, y)) {
pixels[y * width + x] = 0xff000000;
} else {
pixels[y * width + x] = 0xffffffff;
}
}
}
// 生成二维码图片的格式使用ARGB_8888
Bitmap bitmap = Bitmap.createBitmap(width, height,
Bitmap.Config.ARGB_8888);
bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
return bitmap;
} catch (WriterException e) {
e.printStackTrace();
}
return null;
}
}

View File

@@ -25,7 +25,7 @@
android:layout_weight="1"> android:layout_weight="1">
<WebView <WebView
android:id="@+id/faceid_video_view" android:id="@+id/order_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_centerInParent="true" /> android:layout_centerInParent="true" />
@@ -51,7 +51,7 @@
android:id="@+id/topInfoTextView" android:id="@+id/topInfoTextView"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/top_line_info1" android:text="@string/top_line_info"
android:textColor="@color/topInfoRed" android:textColor="@color/topInfoRed"
android:textSize="18sp" /> android:textSize="18sp" />
@@ -85,279 +85,6 @@
android:textColor="#ff0000" android:textColor="#ff0000"
android:textSize="15sp" /> android:textSize="15sp" />
</LinearLayout> </LinearLayout>
<LinearLayout
android:id="@+id/welcome_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="54dp"
android:layout_marginTop="30dp"
android:text="@string/well_string1"
android:textColor="@color/color_gray"
android:textSize="15sp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:gravity="center">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical">
<RelativeLayout
android:layout_width="50px"
android:layout_height="50px"
android:background="@mipmap/ico_fi"></RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="微信搜索小程序\n【MAX共享运动】"
android:textAlignment="center"
android:textColor="@color/color_gray" />
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:src="@mipmap/ico_nex" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical">
<RelativeLayout
android:layout_width="50px"
android:layout_height="50px"
android:background="@mipmap/ico_add"></RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="完成人脸注册"
android:textAlignment="center"
android:textColor="@color/color_gray" />
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:src="@mipmap/ico_nex" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical">
<RelativeLayout
android:layout_width="50px"
android:layout_height="50px"
android:background="@mipmap/ico_guest"></RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="成为会员"
android:textAlignment="center"
android:textColor="@color/color_gray" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/userInfoLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:gravity="center">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/user_avator"
android:layout_width="91dp"
android:layout_height="91dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="40dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ico_user" />
<TextView
android:id="@+id/user_name_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:text="BBBBBBBBB" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ico_phone" />
<TextView
android:id="@+id/user_phone_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:text="BBBBBBBBB" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:background="@mipmap/ico_line"></LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical">
<LinearLayout
android:id="@+id/unit_price_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="本次消费"
android:textSize="16sp" />
<TextView
android:id="@+id/unit_price_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="18dp"
android:text="0.00"
android:textColor="@color/topInfoRed"
android:textSize="28sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/unit_price_line_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:background="@mipmap/ico_s_line"
android:orientation="vertical"></LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="余额"
android:textSize="16sp" />
<TextView
android:id="@+id/user_amount_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="18dp"
android:text="100.00"
android:textColor="@color/topInfoRed"
android:textSize="28sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/memberInfoLineView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:background="@mipmap/ico_s_line"
android:orientation="vertical"></LinearLayout>
<LinearLayout
android:id="@+id/memberInfopackLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:id="@+id/package_name_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="场地名称"
android:textSize="16sp" />
<TextView
android:id="@+id/user_place_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="#####"
android:textColor="@color/black"
android:textSize="23sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>

View File

@@ -1,6 +1,6 @@
<resources> <resources>
<string name="app_name">sport-faceid</string> <string name="app_name">sport-faceid</string>
<string name="top_line_info1">预订信息如下</string> <string name="top_line_info">扫码下方二维码进场</string>
<string name="well_string1">新用户注册</string> <string name="well_string1">新用户注册</string>
<string name="setting">设置</string> <string name="setting">设置</string>
<string name="camera_setting_type_title">请选择场馆,以及门禁类型</string> <string name="camera_setting_type_title">请选择场馆,以及门禁类型</string>