QrCodeScannerView-Android is a simple tool that can help you decode Qr Code and create a Qr code by content
base on:
https://github.com/zxing/zxing
https://github.com/dlazaro66/QRCodeReaderView
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
compile 'com.github.qingmei2:QrCodeScannerView-Android:1.1.2'
}
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.qingmei2.qrcodedemos.MainActivity">
<com.qingmei2.library.view.QRCodeScannerView
android:id="@+id/scanner"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.qingmei2.library.view.QRCoverView
android:id="@+id/cover"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cornerColor="#0f0"
app:laserVisible="false"
app:outsideBackgroundColor="#22000000"
app:scanRectHeight="250dp"
app:scanRectWidth="250dp" />
</FrameLayout>
mScannerView.setAutofocusInterval(2000L);
mScannerView.setOnQRCodeReadListener(new QRCodeScannerView.OnQRCodeScannerListener() {
@Override
public void onDecodeFinish(String text, PointF[] points) {
Log.d("tag", "result : " + text);
}
});
mScannerView.setOnCheckCameraPermissionListener(new QRCodeScannerView.OnCheckCameraPermissionListener() {
@Override
public boolean onCheckCameraPermission() {
if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CAMERA)
== PackageManager.PERMISSION_GRANTED) {
return true;
} else {
ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.CAMERA}, PERMISSION_REQUEST_CAMERA);
return false;
}
}
});
mScannerView.setBackCamera();
Method | detail | about |
---|---|---|
setQRDecodingEnabled(boolean qrDecodingEnabled) | Enable decoding,default true | |
setAutofocusInterval(int times) | Auto focus,default 2s | |
setOnQRCodeReadListener(OnQRCodeScannerListener onQRCodeScannerListener) | Call back of decode result | need implement |
setFrontCamera()/setBackCamera() | Default face oritation | need implement |
setOnCheckCameraPermissionListener(OnCheckCameraPermissionListener listener) | Call back of the Camera permission | need implement |
switchCameraFace() | Switch the Camera | |
startCamera() | Start scan Qrcode | should use it in activity.onResume() |
stopCamera() | Stop scan Qrcode | should use it in activity.onPause() |
Method | detail | about |
---|---|---|
setCoverViewOutsideColor(int colorRes) | Scan rect outside color | |
setCoverViewCornerColor(int colorRes) | Scan corner color | |
setCoverViewCorner(int cornerH, int cornerW, boolean isDp) | Scan corner color length and width | |
setCoverViewConnerFace(boolean isOutside) | Scan corner outside of scan Rect | default false |
setCoverViewScanner(int width, int height) | Scan rect width&height | |
RectF getViewFinderRect() | Get the Scan rect |
also you can init UI by this:
<com.qingmei2.library.view.QRCoverView
android:id="@+id/cover"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cornerColor="#0f0"
app:cornerLength="16dp"
app:cornerWidth="3dp"
app:cornerOutside="false"
app:laserVisible="false"
app:laserColor="#0f0"
app:outsideBackgroundColor="#22000000"
app:scanRectHeight="250dp"
app:scanRectWidth="250dp"
/>
public QRCodeEncoder(Activity activity)
//use it in activity:
qrCodeEncoder = new QRCodeEncoder(this); //init
qrCodeEncoder.createQrCode2ImageView(textContent, ivQRCode);
//or
qrCodeEncoder.createQrCode2ImageView(textContent, ivQRCode, R.mipmap.ic_launcher);
Method | detail | about |
---|---|---|
Bitmap createQrCode(String content, int widthAndHeight); | createQrCode | |
void createQrCode2ImageView(String content, ImageView imageView); | create QrCode into ImageView | |
also you can add a icon into QrCode Bitmap | ||
Bitmap createQrCode(String content, int width, int iconRes); | createQrCode with icon | |
void createQrCode2ImageView(String content, ImageView imageView, int iconRes); | create QrCode with icon into ImageView |
Override Methods:
Result: