-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: fake scan QR code to open passport
- Loading branch information
Showing
12 changed files
with
193 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
app/src/main/java/com/bqliang/leavesheet/scan/ScanActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package com.bqliang.leavesheet.scan | ||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.widget.Toast | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.bqliang.leavesheet.main.PassPortActivity | ||
import com.bqliang.leavesheet.utils.SoundPoolUtil | ||
import com.bqliang.leavesheet.utils.launchActivity | ||
import com.huawei.hms.hmsscankit.ScanUtil | ||
import com.huawei.hms.ml.scan.HmsScan | ||
import com.huawei.hms.ml.scan.HmsScanAnalyzerOptions | ||
import com.permissionx.guolindev.PermissionX | ||
|
||
class ScanActivity : AppCompatActivity() { | ||
|
||
companion object { | ||
private const val SCAN_TITLE_QR_CODE = 1 | ||
private const val REQUEST_CODE_SCAN_ONE = 0X01 | ||
} | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
val isGrantedCameraPermission = | ||
PermissionX.isGranted(this, android.Manifest.permission.CAMERA) | ||
if (isGrantedCameraPermission) { | ||
startScanCamera() | ||
} else { | ||
requestCameraPermission { startScanCamera() } | ||
} | ||
} | ||
|
||
|
||
private fun requestCameraPermission(onGranted: () -> Unit) = PermissionX.init(this) | ||
.permissions(android.Manifest.permission.CAMERA) | ||
.explainReasonBeforeRequest() | ||
.onExplainRequestReason { scope, deniedList -> | ||
scope.showRequestReasonDialog( | ||
permissions = deniedList, | ||
message = "扫码功能需要您授予我们相机权限", | ||
positiveText = "好的", | ||
negativeText = "取消" | ||
) | ||
} | ||
.onForwardToSettings { scope, deniedList -> | ||
scope.showForwardToSettingsDialog( | ||
permissions = deniedList, | ||
message = "您需要在设置中手动授予相机权限", | ||
positiveText = "好的", | ||
negativeText = "取消" | ||
) | ||
} | ||
.request { allGranted, _, _ -> | ||
if (allGranted) { | ||
onGranted() | ||
} else { | ||
Toast.makeText(this, "无法获取照相机权限", Toast.LENGTH_SHORT).show() | ||
finish() | ||
} | ||
} | ||
|
||
|
||
private fun startScanCamera() { | ||
val scanOptions = HmsScanAnalyzerOptions.Creator() | ||
.setHmsScanTypes(HmsScan.QRCODE_SCAN_TYPE) | ||
.setViewType(SCAN_TITLE_QR_CODE) | ||
.setPhotoMode(false) | ||
.create() | ||
ScanUtil.startScan(this, REQUEST_CODE_SCAN_ONE, scanOptions) | ||
} | ||
|
||
|
||
@Deprecated( | ||
"Deprecated in Java", ReplaceWith( | ||
"super.onActivityResult(requestCode, resultCode, data)", | ||
"androidx.appcompat.app.AppCompatActivity" | ||
) | ||
) | ||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { | ||
@Suppress("deprecation") | ||
super.onActivityResult(requestCode, resultCode, data) | ||
|
||
val scanQrCodeSuccess = | ||
requestCode == REQUEST_CODE_SCAN_ONE && resultCode == RESULT_OK && data != null | ||
if (scanQrCodeSuccess) { | ||
launchActivity<PassPortActivity>() | ||
SoundPoolUtil.beep() | ||
} | ||
finish() | ||
} | ||
} |
Binary file not shown.
42 changes: 42 additions & 0 deletions
42
app/src/main/java/com/bqliang/leavesheet/utils/SoundPoolUtil.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.bqliang.leavesheet.utils | ||
|
||
import android.media.AudioAttributes | ||
import android.media.SoundPool | ||
import com.bqliang.leavesheet.MyApp | ||
import com.bqliang.leavesheet.R | ||
|
||
object SoundPoolUtil { | ||
private val audioAttributes by lazy { | ||
AudioAttributes.Builder() | ||
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) | ||
.setUsage(AudioAttributes.USAGE_NOTIFICATION_EVENT) | ||
.build() | ||
} | ||
|
||
private var soundPool: SoundPool? = null | ||
|
||
fun beep() { | ||
if (soundPool == null) { | ||
soundPool = SoundPool.Builder() | ||
.setAudioAttributes(audioAttributes) | ||
.build() | ||
} | ||
|
||
val soundId = soundPool?.load(MyApp.context, R.raw.beep, 1) | ||
soundPool?.setOnLoadCompleteListener { _, _, _ -> | ||
soundPool?.play( | ||
/* soundID = */ soundId!!, | ||
/* leftVolume = */ 1f, | ||
/* rightVolume = */ 1f, | ||
/* priority = */ 0, | ||
/* loop = */ 0, | ||
/* rate = */ 1f | ||
) | ||
} | ||
} | ||
|
||
fun release() { | ||
soundPool?.release() | ||
soundPool = null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:aapt="http://schemas.android.com/aapt" | ||
android:width="48dp" | ||
android:height="48dp" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24"> | ||
<path | ||
android:pathData="M12,12m-11,0a11,11 0,1 1,22 0a11,11 0,1 1,-22 0" | ||
android:strokeLineJoin="round" | ||
android:strokeWidth="1.15086" | ||
android:fillColor="#f5f5f5" | ||
android:fillType="nonZero" | ||
android:strokeLineCap="round"/> | ||
<path | ||
android:pathData="m10.594,8.906l0,1.688l-1.688,0l0,-1.688l1.688,0M11.438,8.063L8.063,8.063l0,3.375l3.375,0zM10.594,13.406l0,1.688l-1.688,0l0,-1.688l1.688,0M11.438,12.563L8.063,12.563l0,3.375l3.375,0zM15.094,8.906l0,1.688l-1.688,0l0,-1.688l1.688,0M15.938,8.063l-3.375,0l0,3.375l3.375,0zM12.563,12.563l0.844,0l0,0.844L12.563,13.406ZM13.406,13.406L14.25,13.406L14.25,14.25L13.406,14.25ZM14.25,12.563l0.844,0l0,0.844L14.25,13.406ZM12.563,14.25l0.844,0l0,0.844L12.563,15.094ZM13.406,15.094L14.25,15.094L14.25,15.938L13.406,15.938ZM14.25,14.25l0.844,0l0,0.844L14.25,15.094ZM15.094,13.406L15.938,13.406L15.938,14.25l-0.844,0zM15.094,15.094L15.938,15.094L15.938,15.938L15.094,15.938ZM17.063,9.188L17.063,9.188C16.753,9.188 16.5,8.934 16.5,8.625L16.5,7.5L15.375,7.5C15.066,7.5 14.813,7.247 14.813,6.938l0,0c0,-0.309 0.253,-0.563 0.563,-0.563l1.688,0c0.309,0 0.563,0.253 0.563,0.563l0,1.688c0,0.309 -0.253,0.563 -0.563,0.563zM17.625,17.063l0,-1.688c0,-0.309 -0.253,-0.563 -0.563,-0.563l0,0c-0.309,0 -0.563,0.253 -0.563,0.563l0,1.125l-1.125,0c-0.309,0 -0.563,0.253 -0.563,0.563l0,0c0,0.309 0.253,0.563 0.563,0.563l1.688,0c0.309,0 0.563,-0.253 0.563,-0.563zM6.938,17.625l1.688,0c0.309,0 0.563,-0.253 0.563,-0.563l0,0C9.188,16.753 8.934,16.5 8.625,16.5L7.5,16.5L7.5,15.375C7.5,15.066 7.247,14.813 6.938,14.813l0,0c-0.309,0 -0.563,0.253 -0.563,0.563l0,1.688c0,0.309 0.253,0.563 0.563,0.563zM6.375,6.938L6.375,8.625C6.375,8.934 6.628,9.188 6.938,9.188L6.938,9.188C7.247,9.188 7.5,8.934 7.5,8.625L7.5,7.5L8.625,7.5C8.934,7.5 9.188,7.247 9.188,6.938L9.188,6.938C9.188,6.628 8.934,6.375 8.625,6.375L6.938,6.375C6.628,6.375 6.375,6.628 6.375,6.938Z" | ||
android:strokeWidth="0.5" | ||
android:fillColor="#1677ff"/> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters