# QRCodeReaderView **Repository Path**: baijuncheng-open-source/qrcode-reader-view ## Basic Information - **Project Name**: QRCodeReaderView - **Description**: 一个简易的相机扫码工具。 进入应用,开启相机预览,可打开相机闪光灯;打开QR扫码开关,可扫码,将二维码的4个角绘制在屏幕上,并显示二维码链接。 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 5 - **Forks**: 3 - **Created**: 2021-02-22 - **Last Updated**: 2022-09-06 ## Categories & Tags **Categories**: harmonyos-barcode **Tags**: None ## README ### **QRCodeReaderView** Modification of ZXING Barcode Scanner project for easy ohos QR-Code detection and AR purposes. This project implements an ohos component which show camera and notify when there's a QR code inside the preview. Some Classes of camera controls and autofocus are taken and slightly modified from Barcode Scanner ohos App. You can also use this for Augmented Reality purposes, as you get QR control points coordinates when decoding. ### **Preview** ![](img/qrcode.gif) ### **Usage** Add a "QRCodeReaderView" in the layout editor like you actually do with a button for example. In your onCreate method, you can find the component as usual, using findComponentById() function. Create an ability which implements onQRCodeReadListener, and let implements required methods or set a onQRCodeReadListener to the QRCodeReaderView object Make sure you have camera permissions in order to use the library. ``` ``` Start & Stop camera preview in onStop() and onActive() overriden methods. You can place widgets or views over QRDecoderView. ``` public class MainAbility extends Ability implements SurfaceOps.Callback,QRCodeReaderView.OnQRCodeReadListener { private QRCodeReaderView mQrCodeReaderView; private PointsOverlayView pointsOverlayView; private Text resultTextView; @Override public void onStart(Intent intent) { super.onStart(intent); super.setUIContent(ResourceTable.Layout_ability_main); WindowManager windowManager = WindowManager.getInstance(); Window window = windowManager.getTopWindow().get(); window.setTransparent(true); mQrCodeReaderView = (QRCodeReaderView)findComponentById(ResourceTable.Id_qrcoderView); mQrCodeReaderView.getSurfaceOps().get().addCallback(this); } ``` ``` // Called when a QR is decoded // "text" : the text encoded in QR // "points" : points where QR control points are placed @Override public void onQRCodeRead(String text, Point[] points) { resultTextView.setText(text); pointsOverlayView.setVisibility(Component.VISIBLE); pointsOverlayView.setPoints(points); mQrCodeReaderView.stopDecode(); } @Override protected void onActive() { super.onActive(); Logger.getLogger(TAG).severe("onActive mQrCodeReaderView ="+mQrCodeReaderView ); if(mQrCodeReaderView != null ){ mQrCodeReaderView.startCamera(); } } @Override protected void onStop() { super.onStop(); if (mQrCodeReaderView != null) { mQrCodeReaderView.stopCamera(); } } } ``` ### Using the Library in your application Solution 1: local source code integration, users can customize base on the source code 1.Copy qrcodereaderview folder to the project directory; 2.Modify project settings.gradle, add dependencies on three modules as follows: include ':qrcodereaderview' 3.Introduce the dependency of imported module in the project. Take the entry module as an example, you need to modify the dependency of imported module in the entry module build.gradle file to add dependencies: ```xml dependencies { entryImplementation project(':entry') implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) debugImplementation project(path: ':qrcodereaderview') } ``` Solution 2: Local HAR package integration 1. Add the HAR(qrcodereaderview-debug.har) package to the lib folder 2. Add the following code to gradle of Entry `implementation fileTree(dir: 'libs', include: ['*.jar', '*.har'])` Solution 3: remote maven repo integration Add the following code in the entry's gradle ```xml implementation 'com.gitee.baijuncheng-open-source:QRCodeReaderView:1.0.0' ``` ### License > Copyright 2017 David Lázaro > > Licensed under the Apache License, Version 2.0 (the "License"); > you may not use this file except in compliance with the License. > You may obtain a copy of the License at > > http://www.apache.org/licenses/LICENSE-2.0 > > Unless required by applicable law or agreed to in writing, software > distributed under the License is distributed on an "AS IS" BASIS, > WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. > See the License for the specific language governing permissions and > limitations under the License.