implement eSIM QR code scanning

This commit is contained in:
Peter Cai 2022-04-30 14:36:12 -04:00
parent 9c376d0a3c
commit 3219497cb0
7 changed files with 56 additions and 5 deletions

View file

@ -3,11 +3,13 @@
<component name="DesignSurface">
<option name="filePathToZoomLevelMap">
<map>
<entry key="app/src/main/res/drawable/ic_add.xml" value="0.2015" />
<entry key="app/src/main/res/layout/activity_main.xml" value="0.19375" />
<entry key="app/src/main/res/layout/euicc_profile.xml" value="0.19375" />
<entry key="app/src/main/res/layout/fragment_euicc.xml" value="0.19375" />
<entry key="app/src/main/res/layout/fragment_profile_download.xml" value="0.19375" />
<entry key="app/src/main/res/menu/activity_main_slot_spinner.xml" value="0.19375" />
<entry key="app/src/main/res/menu/fragment_profile_download.xml" value="0.19375" />
</map>
</option>
</component>

View file

@ -44,6 +44,7 @@ dependencies {
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.1'
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
implementation "androidx.cardview:cardview:1.0.0"
implementation 'com.journeyapps:zxing-android-embedded:4.3.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

View file

@ -26,6 +26,11 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.journeyapps.barcodescanner.CaptureActivity"
android:screenOrientation="fullSensor"
tools:replace="screenOrientation" />
</application>
</manifest>

View file

@ -2,17 +2,17 @@ package im.angry.openeuicc.ui
import android.app.Dialog
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.Window
import android.view.*
import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.DialogFragment
import com.journeyapps.barcodescanner.ScanContract
import com.journeyapps.barcodescanner.ScanOptions
import im.angry.openeuicc.R
import im.angry.openeuicc.core.EuiccChannel
import im.angry.openeuicc.databinding.FragmentProfileDownloadBinding
import im.angry.openeuicc.util.setWidthPercent
class ProfileDownloadFragment(val channel: EuiccChannel) : DialogFragment() {
class ProfileDownloadFragment(val channel: EuiccChannel) : DialogFragment(), Toolbar.OnMenuItemClickListener {
companion object {
const val TAG = "ProfileDownloadFragment"
}
@ -20,12 +20,22 @@ class ProfileDownloadFragment(val channel: EuiccChannel) : DialogFragment() {
private var _binding: FragmentProfileDownloadBinding? = null
private val binding get() = _binding!!
private val barcodeScannerLauncher = registerForActivityResult(ScanContract()) { result ->
result.contents?.let { content ->
val components = content.split("$")
if (components.size != 3 || components[0] != "LPA:1") return@registerForActivityResult
binding.profileDownloadServer.editText?.setText(components[1])
binding.profileDownloadCode.editText?.setText(components[2])
}
}
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = FragmentProfileDownloadBinding.inflate(inflater, container, false)
binding.toolbar.inflateMenu(R.menu.fragment_profile_download)
return binding.root
}
@ -36,9 +46,22 @@ class ProfileDownloadFragment(val channel: EuiccChannel) : DialogFragment() {
setNavigationOnClickListener {
dismiss()
}
setOnMenuItemClickListener(this@ProfileDownloadFragment)
}
}
override fun onMenuItemClick(item: MenuItem): Boolean =
when (item.itemId) {
R.id.scan -> {
barcodeScannerLauncher.launch(ScanOptions().apply {
setDesiredBarcodeFormats(ScanOptions.QR_CODE)
setOrientationLocked(false)
})
true
}
else -> false
}
override fun onResume() {
super.onResume()
setWidthPercent(95)

View file

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M9.5,6.5v3h-3v-3H9.5M11,5H5v6h6V5L11,5zM9.5,14.5v3h-3v-3H9.5M11,13H5v6h6V13L11,13zM17.5,6.5v3h-3v-3H17.5M19,5h-6v6h6V5L19,5zM13,13h1.5v1.5H13V13zM14.5,14.5H16V16h-1.5V14.5zM16,13h1.5v1.5H16V13zM13,16h1.5v1.5H13V16zM14.5,17.5H16V19h-1.5V17.5zM16,16h1.5v1.5H16V16zM17.5,14.5H19V16h-1.5V14.5zM17.5,17.5H19V19h-1.5V17.5zM22,7h-2V4h-3V2h5V7zM22,22v-5h-2v3h-3v2H22zM2,22h5v-2H4v-3H2V22zM2,2v5h2V4h3V2H2z"/>
</vector>

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/scan"
android:icon="@drawable/ic_scan_black"
android:title="@string/profile_download_scan"
app:showAsAction="ifRoom"/>
</menu>

View file

@ -11,4 +11,5 @@
<string name="profile_download">New eSIM</string>
<string name="profile_download_server">Server (RSP / SM-DP+)</string>
<string name="profile_download_code">Activation Code</string>
<string name="profile_download_scan">Scan QR Code</string>
</resources>