diff --git a/doric-android/devkit/build.gradle b/doric-android/devkit/build.gradle
index 94940fed..78479401 100644
--- a/doric-android/devkit/build.gradle
+++ b/doric-android/devkit/build.gradle
@@ -32,11 +32,12 @@ dependencies {
implementation "com.google.android.material:material:1.0.0"
implementation 'com.squareup.okhttp3:okhttp:3.12.1'
implementation 'com.google.code.gson:gson:2.8.5'
- implementation 'cn.bingoogolapple:bga-qrcode-zbar:1.3.7'
api 'org.greenrobot:eventbus:3.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
+ implementation 'cn.yipianfengye.android:zxing-library:2.2'
+
}
apply from: rootProject.file('scripts/upload.gradle')
\ No newline at end of file
diff --git a/doric-android/devkit/src/main/AndroidManifest.xml b/doric-android/devkit/src/main/AndroidManifest.xml
index 6a6b118b..aab69485 100644
--- a/doric-android/devkit/src/main/AndroidManifest.xml
+++ b/doric-android/devkit/src/main/AndroidManifest.xml
@@ -1,12 +1,11 @@
-
+
-
diff --git a/doric-android/devkit/src/main/java/pub/doric/devkit/WSClient.java b/doric-android/devkit/src/main/java/pub/doric/devkit/WSClient.java
index a02f004d..b58504ee 100644
--- a/doric-android/devkit/src/main/java/pub/doric/devkit/WSClient.java
+++ b/doric-android/devkit/src/main/java/pub/doric/devkit/WSClient.java
@@ -53,7 +53,7 @@ public class WSClient extends WebSocketListener {
}
public void close() {
- webSocket.close(1024, "Close");
+ webSocket.close(1000, "Close");
}
@Override
@@ -97,6 +97,7 @@ public class WSClient extends WebSocketListener {
@Override
public void onClosed(WebSocket webSocket, int code, String reason) {
super.onClosed(webSocket, code, reason);
+ EventBus.getDefault().post(new ConnectExceptionEvent());
}
@Override
diff --git a/doric-android/devkit/src/main/java/pub/doric/devkit/ui/DoricDevActivity.java b/doric-android/devkit/src/main/java/pub/doric/devkit/ui/DoricDevActivity.java
index 64fac4fe..aafe5446 100644
--- a/doric-android/devkit/src/main/java/pub/doric/devkit/ui/DoricDevActivity.java
+++ b/doric-android/devkit/src/main/java/pub/doric/devkit/ui/DoricDevActivity.java
@@ -9,6 +9,7 @@ import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
+import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -17,6 +18,9 @@ import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import com.google.gson.JsonObject;
+import com.uuzuche.lib_zxing.activity.CaptureActivity;
+import com.uuzuche.lib_zxing.activity.CodeUtils;
+import com.uuzuche.lib_zxing.activity.ZXingLibrary;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
@@ -34,11 +38,12 @@ import pub.doric.devkit.event.OpenEvent;
import pub.doric.devkit.event.StartDebugEvent;
public class DoricDevActivity extends AppCompatActivity {
-
+ private int REQUEST_CODE=100;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EventBus.getDefault().register(this);
+ ZXingLibrary.initDisplayOpinion(this);
setContentView(R.layout.layout_debug_context);
initDisconnect();
if (DoricDev.getInstance().isInDevMode()) {
@@ -57,8 +62,8 @@ public class DoricDevActivity extends AppCompatActivity {
new String[]{Manifest.permission.CAMERA,}, 1);
}
} else {
- Intent intent = new Intent(DoricDevActivity.this, ScanQRCodeActivity.class);
- startActivity(intent);
+ Intent intent = new Intent(DoricDevActivity.this, CaptureActivity.class);
+ startActivityForResult(intent, REQUEST_CODE);
}
}
}
@@ -71,13 +76,30 @@ public class DoricDevActivity extends AppCompatActivity {
if (requestCode == 1) {
for (int i = 0; i < permissions.length; i++) {
if (grantResults[i] == PackageManager.PERMISSION_GRANTED) {
- Intent intent = new Intent(DoricDevActivity.this, ScanQRCodeActivity.class);
- startActivity(intent);
+ Intent intent = new Intent(DoricDevActivity.this, CaptureActivity.class);
+ startActivityForResult(intent, REQUEST_CODE);
}
}
}
}
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+ if (null != data) {
+ Bundle bundle = data.getExtras();
+ if (bundle == null) {
+ return;
+ }
+ if (bundle.getInt(CodeUtils.RESULT_TYPE) == CodeUtils.RESULT_SUCCESS) {
+ String result = bundle.getString(CodeUtils.RESULT_STRING);
+ DevKit.ip = result;
+ Toast.makeText(this, "dev kit connecting to " + result, Toast.LENGTH_LONG).show();
+ DevKit.getInstance().connectDevKit("ws://" + result + ":7777");
+ }
+ }
+ }
+
@Override
protected void onDestroy() {
super.onDestroy();
@@ -107,7 +129,9 @@ public class DoricDevActivity extends AppCompatActivity {
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- DoricDev.getInstance().closeDevMode();
+ if(DoricDev.getInstance().isInDevMode()){
+ DoricDev.getInstance().closeDevMode();
+ }
finish();
}
});
diff --git a/doric-android/devkit/src/main/java/pub/doric/devkit/ui/ScanQRCodeActivity.java b/doric-android/devkit/src/main/java/pub/doric/devkit/ui/ScanQRCodeActivity.java
deleted file mode 100644
index 2dbe7428..00000000
--- a/doric-android/devkit/src/main/java/pub/doric/devkit/ui/ScanQRCodeActivity.java
+++ /dev/null
@@ -1,76 +0,0 @@
-package pub.doric.devkit.ui;
-
-import android.os.Bundle;
-import android.widget.Toast;
-
-import androidx.annotation.Nullable;
-import androidx.appcompat.app.AppCompatActivity;
-
-import cn.bingoogolapple.qrcode.core.QRCodeView;
-import cn.bingoogolapple.qrcode.zbar.ZBarView;
-import pub.doric.devkit.DevKit;
-import pub.doric.devkit.R;
-
-public class ScanQRCodeActivity extends AppCompatActivity implements QRCodeView.Delegate {
-
- private ZBarView mZbarView;
-
- @Override
- protected void onCreate(@Nullable Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- setContentView(R.layout.layout_scan_qrcode);
- mZbarView = findViewById(R.id.zbar_view);
- mZbarView.setDelegate(this);
- }
-
- @Override
- protected void onStart() {
- super.onStart();
-
- mZbarView.startCamera();
- mZbarView.startSpotAndShowRect();
- }
-
- @Override
- protected void onStop() {
- super.onStop();
- mZbarView.stopCamera();
- }
-
- @Override
- protected void onDestroy() {
- mZbarView.onDestroy();
- super.onDestroy();
- }
-
- @Override
- public void onScanQRCodeSuccess(String result) {
- setTitle("扫描结果为:" + result);
- DevKit.ip = result;
- Toast.makeText(this, "dev kit connecting to " + result, Toast.LENGTH_LONG).show();
- DevKit.getInstance().connectDevKit("ws://" + result + ":7777");
- finish();
- }
-
- @Override
- public void onCameraAmbientBrightnessChanged(boolean isDark) {
- String tipText = mZbarView.getScanBoxView().getTipText();
- String ambientBrightnessTip = "\n环境过暗,请打开闪光灯";
- if (isDark) {
- if (!tipText.contains(ambientBrightnessTip)) {
- mZbarView.getScanBoxView().setTipText(tipText + ambientBrightnessTip);
- }
- } else {
- if (tipText.contains(ambientBrightnessTip)) {
- tipText = tipText.substring(0, tipText.indexOf(ambientBrightnessTip));
- mZbarView.getScanBoxView().setTipText(tipText);
- }
- }
- }
-
- @Override
- public void onScanQRCodeOpenCameraError() {
- System.out.println();
- }
-}
diff --git a/doric-android/devkit/src/main/res/layout/layout_scan_qrcode.xml b/doric-android/devkit/src/main/res/layout/layout_scan_qrcode.xml
deleted file mode 100644
index 8bf17883..00000000
--- a/doric-android/devkit/src/main/res/layout/layout_scan_qrcode.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
-
-
-