Skip to content

Commit

Permalink
Merge branch 'release/v_1.7.1' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
hpuhsp committed May 6, 2023
2 parents 56b2b97 + 22b1c63 commit 5023f80
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 277 deletions.
19 changes: 9 additions & 10 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
id 'kotlin-android-extensions'
id 'kotlin-parcelize'
}

android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
compileSdk 33

defaultConfig {
applicationId "com.hsp.scanner"
minSdkVersion 21
targetSdkVersion 30
versionCode 20
versionName "1.7.0"
minSdk 21
targetSdk 33

versionCode 21
versionName "1.7.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -40,6 +39,7 @@ android {
buildFeatures {
viewBinding true
}
ndkVersion '22.1.7171670'
}

dependencies {
Expand All @@ -54,7 +54,6 @@ dependencies {
//noinspection LifecycleAnnotationProcessorWithJava8
kapt 'androidx.lifecycle:lifecycle-compiler:2.2.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.2.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.QRScanner">
<activity android:name=".MainActivity">
<activity
android:name=".MainActivity"
android:exported="true"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
79 changes: 47 additions & 32 deletions app/src/main/java/com/hsp/scanner/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,21 @@ package com.hsp.scanner
import android.Manifest
import android.app.Activity
import android.content.Intent
import android.graphics.Bitmap
import android.net.Uri
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.blankj.utilcode.util.FileUtils
import com.blankj.utilcode.util.ImageUtils
import com.bumptech.glide.Glide
import com.hnsh.scanner.CaptureActivity
import com.hnsh.scanner.DeviceScanHelper
import com.hnsh.scanner.decode.DecodeHandler
import com.hnsh.scanner.zbarUtils.Constants
import com.hnsh.scanner.zbarUtils.utils.BeepManager
import kotlinx.android.synthetic.main.activity_main.*
import com.hsp.scanner.databinding.ActivityMainBinding
import pub.devrel.easypermissions.AfterPermissionGranted
import pub.devrel.easypermissions.EasyPermissions
import java.io.File

/**
* @Description:
Expand All @@ -32,6 +28,11 @@ import java.io.File
*/
class MainActivity : AppCompatActivity(), EasyPermissions.PermissionCallbacks,
View.OnClickListener {

private val viewBinding by lazy {
ActivityMainBinding.inflate(LayoutInflater.from(this@MainActivity))
}

companion object {
/**
* 注意添加必需权限
Expand All @@ -40,34 +41,35 @@ class MainActivity : AppCompatActivity(), EasyPermissions.PermissionCallbacks,
Manifest.permission.CAMERA,
Manifest.permission.WRITE_EXTERNAL_STORAGE
)

const val SCAN_REQUEST_CODE = 1001
}

private lateinit var scanHelper: DeviceScanHelper
private var beepManager: BeepManager? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
btn_scanner.setOnClickListener(this)
btn_play.setOnClickListener(this)
setContentView(viewBinding.root)
initScanner()
viewBinding.btnScanner.setOnClickListener(this)
viewBinding.btnPlay.setOnClickListener(this)
Log.d("TAG", "onCreate: ------------------->${viewBinding}")
}

private fun initScanner() {
scanHelper = DeviceScanHelper(this)
scanHelper.setOnScanSuccessListener(object : DeviceScanHelper.OnScanSuccessListener {
override fun onSuccess(result: String?) {
result?.let {
Toast.makeText(this@MainActivity, it, Toast.LENGTH_SHORT).show()
tv_result.text = it
viewBinding.tvResult.text = it
}
}
})

}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == SCAN_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
Expand All @@ -76,10 +78,10 @@ class MainActivity : AppCompatActivity(), EasyPermissions.PermissionCallbacks,
Toast.makeText(this@MainActivity, "扫描结果为空~", Toast.LENGTH_SHORT).show()
} else {
val barCode = bundle.getString(DecodeHandler.BAR_CODE_KEY) ?: ""
tv_result.text = barCode

viewBinding.tvResult.text = barCode
val albumPicPath = bundle.getString(DecodeHandler.ALBUM_PIC_KEY) ?: ""

Log.d(
"TAG",
"onActivityResult: ----------------------barCode---->${barCode}"
Expand All @@ -89,33 +91,37 @@ class MainActivity : AppCompatActivity(), EasyPermissions.PermissionCallbacks,
"onActivityResult: ----------------------albumPicPath---->${albumPicPath}"
)
if (albumPicPath.isNotEmpty()) {
Glide.with(this).load(albumPicPath).into(iv_result)
Glide.with(this).load(albumPicPath).into(viewBinding.ivResult)
}
}
}
}

override fun onResume() {
super.onResume()
scanHelper.onResume()
}

override fun onPause() {
super.onPause()
scanHelper.onPause()
}

override fun onPermissionsGranted(requestCode: Int, perms: MutableList<String>) {
if (requestCode == SCAN_REQUEST_CODE) {
CaptureActivity.start(this@MainActivity, SCAN_REQUEST_CODE, true)
}
}

override fun onPermissionsDenied(requestCode: Int, perms: MutableList<String>) {
Toast.makeText(this@MainActivity, "应用没有拍照权限,请在手机设置中修改~", Toast.LENGTH_SHORT).show()

Toast.makeText(
this@MainActivity,
"应用没有拍照权限,请在手机设置中修改~",
Toast.LENGTH_SHORT
).show()

}

override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
Expand All @@ -124,22 +130,31 @@ class MainActivity : AppCompatActivity(), EasyPermissions.PermissionCallbacks,
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this)
}

override fun onClick(v: View?) {
when (v?.id) {
R.id.btn_scanner -> {
viewBinding.btnScanner.id -> {
Log.d(
"TAG",
"onClick: ----------btnScanner--------->${viewBinding.btnScanner.text}"
)

checkScannerPermission()
}
R.id.btn_play -> {

viewBinding.btnPlay.id -> {
Log.d("TAG", "onClick: ----------btnPlay--------->${viewBinding.btnPlay.text}")

// 播放扫描成语音
beepManager = BeepManager(this, R.raw.scan_success)
beepManager?.autoPlay()
}

else -> {
}
}
}

@AfterPermissionGranted(SCAN_REQUEST_CODE)
private fun checkScannerPermission() {
if (EasyPermissions.hasPermissions(this, *CAMERA_PERMISSIONS)) {
Expand All @@ -153,7 +168,7 @@ class MainActivity : AppCompatActivity(), EasyPermissions.PermissionCallbacks,
)
}
}

override fun onDestroy() {
super.onDestroy()
beepManager?.close()
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
android:layout_height="44dp"
android:layout_marginTop="45dp"
android:background="@android:color/holo_blue_light"
android:clickable="true"
android:gravity="center"
android:text="扫描"
android:textColor="@color/black"
Expand All @@ -46,6 +47,7 @@
android:layout_height="44dp"
android:layout_marginTop="45dp"
android:background="@android:color/holo_blue_light"
android:clickable="true"
android:gravity="center"
android:text="播报语音"
android:textColor="@color/black"
Expand Down
55 changes: 5 additions & 50 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,50 +1,5 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.4.10"
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.2"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// classpath 'com.novoda:bintray-release:0.9.2'
// classpath 'com.github.panpf.bintray-publish:bintray-publish:1.0.0'
// JitPack
// classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
}
}

allprojects {
repositories {
google()
mavenCentral()
maven { url 'https://maven.google.com' }
maven { url 'https://jitpack.io' }
maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }
}
// 解决上传乱码问题
tasks.withType(Javadoc) {
options {
encoding "UTF-8"
charSet "UTF-8"
links "http://docs.oracle.com/javase/7/docs/api"
}
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}
configurations.all {
resolutionStrategy {
eachDependency { details ->
// Force all of the primary libraries to use the same version.
if (details.requested.name == 'appcompat'
&& details.requested.name == 'annotation'
&& details.requested.name == 'recyclerview') {
details.useVersion rootProject.ext.version["androidXSdkVersion"]
}
}
}
}
plugins {
id 'com.android.application' version '7.3.0' apply false
id 'com.android.library' version '7.3.0' apply false
id 'org.jetbrains.kotlin.android' version '1.8.10' apply false
}
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Dec 21 13:51:03 GMT+08:00 2020
#Thu Mar 18 10:20:07 GMT+08:00 2021
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
2 changes: 1 addition & 1 deletion local.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
# header note.
#Fri May 05 19:45:09 GMT+08:00 2023
sdk.dir=C\:\\Users\\HSP\\AppData\\Local\\Android\\Sdk
#ndk.dir=C\:\\Users\\HSP\\AppData\\Local\\Android\\Sdk\\ndk\\21.0.6113669
ndk.dir=C\:\\Users\\HSP\\AppData\\Local\\Android\\Sdk\\ndk\\22.1.7171670
32 changes: 14 additions & 18 deletions scanner/build.gradle
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'maven-publish'

plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
id 'kotlin-parcelize'
id 'maven-publish'
}
task generateSourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier 'sources'
}

android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
compileSdk 33
ndkVersion '22.1.7171670' // Jitpack构建ndk版本,发布新版本时打开

defaultConfig {
minSdkVersion 21
targetSdkVersion 30
minSdk 21
targetSdk 33

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
Expand Down Expand Up @@ -51,26 +52,21 @@ android {

dependencies {
api fileTree(dir: "libs", include: ["*.jar"])
api 'com.google.zxing:core:3.3.3'

implementation 'androidx.core:core-ktx:1.3.1'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.2.0'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
// Test
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
api 'com.google.zxing:core:3.3.3'
}

publishing {
publications {
release(MavenPublication) {
groupId = 'com.github.hpuhsp'
artifactId = 'QRScanner'
version = '1.7.0'
version = '1.7.1'

afterEvaluate {
from components.release
Expand Down
Loading

0 comments on commit 5023f80

Please sign in to comment.