add qrcode scan on dev kit connect
This commit is contained in:
		| @@ -21,6 +21,7 @@ allprojects { | ||||
|         maven { | ||||
|             url "https://dl.bintray.com/osborn/Android" | ||||
|         } | ||||
|         maven { url 'https://jitpack.io' } | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -54,6 +54,9 @@ dependencies { | ||||
|     implementation 'com.google.code.gson:gson:2.8.6' | ||||
|     api "com.google.android.material:material:1.0.0" | ||||
|     implementation 'androidx.constraintlayout:constraintlayout:1.1.3' | ||||
|     implementation 'cn.bingoogolapple:bga-qrcode-zxing:1.3.7' | ||||
|     implementation 'com.github.tbruyelle:rxpermissions:0.10.2' | ||||
|     implementation "io.reactivex.rxjava2:rxjava:2.2.14" | ||||
|  | ||||
|     testImplementation 'junit:junit:4.12' | ||||
|     androidTestImplementation 'androidx.test.ext:junit:1.1.1' | ||||
|   | ||||
| @@ -1,2 +1,9 @@ | ||||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||||
|     package="pub.doric" /> | ||||
|     package="pub.doric"> | ||||
|  | ||||
|     <uses-permission android:name="android.permission.CAMERA" /> | ||||
|  | ||||
|     <application> | ||||
|         <activity android:name=".dev.ScanQRCodeActivity" /> | ||||
|     </application> | ||||
| </manifest> | ||||
|   | ||||
| @@ -1,5 +1,7 @@ | ||||
| package pub.doric.dev; | ||||
|  | ||||
| import android.Manifest; | ||||
| import android.content.Intent; | ||||
| import android.os.Bundle; | ||||
| import android.view.LayoutInflater; | ||||
| import android.view.View; | ||||
| @@ -9,7 +11,10 @@ import androidx.annotation.NonNull; | ||||
| import androidx.annotation.Nullable; | ||||
|  | ||||
| import com.google.android.material.bottomsheet.BottomSheetDialogFragment; | ||||
| import com.tbruyelle.rxpermissions2.RxPermissions; | ||||
|  | ||||
| import io.reactivex.disposables.Disposable; | ||||
| import io.reactivex.functions.Consumer; | ||||
| import pub.doric.R; | ||||
|  | ||||
| public class DevPanel extends BottomSheetDialogFragment { | ||||
| @@ -27,4 +32,28 @@ public class DevPanel extends BottomSheetDialogFragment { | ||||
|     ) { | ||||
|         return inflater.inflate(R.layout.layout_dev, container, false); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void onStart() { | ||||
|         super.onStart(); | ||||
|  | ||||
|         getView().findViewById(R.id.menu1_text_view).setOnClickListener(new View.OnClickListener() { | ||||
|             @Override | ||||
|             public void onClick(View v) { | ||||
|                 final RxPermissions rxPermissions = new RxPermissions(DevPanel.this); | ||||
|                 Disposable disposable = rxPermissions | ||||
|                         .request(Manifest.permission.CAMERA) | ||||
|                         .subscribe(new Consumer<Boolean>() { | ||||
|                             @Override | ||||
|                             public void accept(Boolean grant) throws Exception { | ||||
|                                 if (grant){ | ||||
|                                     Intent intent = new Intent(getContext(), ScanQRCodeActivity.class); | ||||
|                                     getContext().startActivity(intent); | ||||
|                                 } | ||||
|                             } | ||||
|                         }); | ||||
|  | ||||
|             } | ||||
|         }); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -0,0 +1,72 @@ | ||||
| package pub.doric.dev; | ||||
|  | ||||
| import android.os.Bundle; | ||||
|  | ||||
| import androidx.annotation.Nullable; | ||||
| import androidx.appcompat.app.AppCompatActivity; | ||||
|  | ||||
| import cn.bingoogolapple.qrcode.core.QRCodeView; | ||||
| import cn.bingoogolapple.qrcode.zxing.ZXingView; | ||||
| import pub.doric.R; | ||||
|  | ||||
| public class ScanQRCodeActivity extends AppCompatActivity implements QRCodeView.Delegate { | ||||
|  | ||||
|     private ZXingView mZXingView; | ||||
|  | ||||
|     @Override | ||||
|     protected void onCreate(@Nullable Bundle savedInstanceState) { | ||||
|         super.onCreate(savedInstanceState); | ||||
|  | ||||
|         setContentView(R.layout.layout_scan_qrcode); | ||||
|         mZXingView = findViewById(R.id.zxingview); | ||||
|         mZXingView.setDelegate(this); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     protected void onStart() { | ||||
|         super.onStart(); | ||||
|  | ||||
|         mZXingView.startCamera(); | ||||
|         mZXingView.startSpotAndShowRect(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     protected void onStop() { | ||||
|         super.onStop(); | ||||
|  | ||||
|         mZXingView.stopCamera(); | ||||
|         super.onStop(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     protected void onDestroy() { | ||||
|         mZXingView.onDestroy(); | ||||
|         super.onDestroy(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void onScanQRCodeSuccess(String result) { | ||||
|         setTitle("扫描结果为:" + result); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void onCameraAmbientBrightnessChanged(boolean isDark) { | ||||
|         String tipText = mZXingView.getScanBoxView().getTipText(); | ||||
|         String ambientBrightnessTip = "\n环境过暗,请打开闪光灯"; | ||||
|         if (isDark) { | ||||
|             if (!tipText.contains(ambientBrightnessTip)) { | ||||
|                 mZXingView.getScanBoxView().setTipText(tipText + ambientBrightnessTip); | ||||
|             } | ||||
|         } else { | ||||
|             if (tipText.contains(ambientBrightnessTip)) { | ||||
|                 tipText = tipText.substring(0, tipText.indexOf(ambientBrightnessTip)); | ||||
|                 mZXingView.getScanBoxView().setTipText(tipText); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void onScanQRCodeOpenCameraError() { | ||||
|         System.out.println(); | ||||
|     } | ||||
| } | ||||
| @@ -1,6 +1,5 @@ | ||||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||||
|     xmlns:app="http://schemas.android.com/apk/res-auto" | ||||
|     android:layout_width="match_parent" | ||||
|     android:layout_height="match_parent" | ||||
|     android:orientation="vertical"> | ||||
| @@ -10,11 +9,8 @@ | ||||
|         android:layout_width="match_parent" | ||||
|         android:layout_height="60dp" | ||||
|         android:gravity="center" | ||||
|         android:text="Debug via Visual Studio Code" | ||||
|         android:textSize="20sp" | ||||
|         app:layout_constraintEnd_toEndOf="parent" | ||||
|         app:layout_constraintStart_toStartOf="parent" | ||||
|         app:layout_constraintTop_toTopOf="parent" /> | ||||
|         android:text="Dev Kit" | ||||
|         android:textSize="20sp" /> | ||||
|  | ||||
|     <View | ||||
|         android:layout_width="match_parent" | ||||
| @@ -26,9 +22,19 @@ | ||||
|         android:layout_width="match_parent" | ||||
|         android:layout_height="60dp" | ||||
|         android:gravity="center" | ||||
|         android:text="Debug via Visual Studio Code" | ||||
|         android:textSize="20sp" /> | ||||
|  | ||||
|     <View | ||||
|         android:layout_width="match_parent" | ||||
|         android:layout_height="1dp" | ||||
|         android:background="#cccccc" /> | ||||
|  | ||||
|     <TextView | ||||
|         android:id="@+id/menu3_text_view" | ||||
|         android:layout_width="match_parent" | ||||
|         android:layout_height="60dp" | ||||
|         android:gravity="center" | ||||
|         android:text="Enable Hot Reload" | ||||
|         android:textSize="20sp" | ||||
|         app:layout_constraintEnd_toEndOf="parent" | ||||
|         app:layout_constraintStart_toStartOf="parent" | ||||
|         app:layout_constraintTop_toBottomOf="@+id/menu1_text_view" /> | ||||
|         android:textSize="20sp" /> | ||||
| </LinearLayout> | ||||
							
								
								
									
										20
									
								
								Android/doric/src/main/res/layout/layout_scan_qrcode.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								Android/doric/src/main/res/layout/layout_scan_qrcode.xml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,20 @@ | ||||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||||
|     xmlns:app="http://schemas.android.com/apk/res-auto" | ||||
|     android:layout_width="match_parent" | ||||
|     android:layout_height="match_parent"> | ||||
|  | ||||
|     <cn.bingoogolapple.qrcode.zxing.ZXingView | ||||
|         android:id="@+id/zxingview" | ||||
|         android:layout_width="match_parent" | ||||
|         android:layout_height="match_parent" | ||||
|         app:qrcv_animTime="1000" | ||||
|         app:qrcv_borderColor="@android:color/white" | ||||
|         app:qrcv_borderSize="1dp" | ||||
|         app:qrcv_cornerLength="20dp" | ||||
|         app:qrcv_cornerSize="3dp" | ||||
|         app:qrcv_maskColor="#33FFFFFF" | ||||
|         app:qrcv_rectWidth="200dp" | ||||
|         app:qrcv_scanLineSize="1dp" | ||||
|         app:qrcv_topOffset="90dp" /> | ||||
| </LinearLayout> | ||||
		Reference in New Issue
	
	Block a user