-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add qr code scanner activity (#1077)
- Loading branch information
1 parent
2492d12
commit 839121a
Showing
9 changed files
with
169 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
68 changes: 68 additions & 0 deletions
68
...allet/src/main/java/com/solana/mobilewalletadapter/fakewallet/ui/scanqr/ScanQRActivity.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,68 @@ | ||
/* | ||
* Copyright (c) 2025 Solana Mobile Inc. | ||
*/ | ||
|
||
package com.solana.mobilewalletadapter.fakewallet.ui.scanqr | ||
|
||
import android.content.Intent | ||
import android.net.Uri | ||
import android.os.Bundle | ||
import androidx.activity.enableEdgeToEdge | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.google.android.material.snackbar.Snackbar | ||
import com.journeyapps.barcodescanner.BarcodeView | ||
import com.solana.mobilewalletadapter.fakewallet.MobileWalletAdapterActivity | ||
import com.solana.mobilewalletadapter.fakewallet.R | ||
import com.solana.mobilewalletadapter.fakewallet.databinding.ActivityScanQrBinding | ||
import com.solana.mobilewalletadapter.walletlib.association.RemoteAssociationUri | ||
|
||
class ScanQRActivity : AppCompatActivity() { | ||
private lateinit var viewBinding: ActivityScanQrBinding | ||
private lateinit var barcodeView: BarcodeView | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
enableEdgeToEdge() | ||
super.onCreate(savedInstanceState) | ||
|
||
viewBinding = ActivityScanQrBinding.inflate(layoutInflater) | ||
setContentView(viewBinding.root) | ||
|
||
barcodeView = viewBinding.scannerViewFinder | ||
} | ||
|
||
override fun onResume() { | ||
super.onResume() | ||
barcodeView.resume() | ||
decodeQRSingle() | ||
} | ||
|
||
public override fun onPause() { | ||
super.onPause() | ||
barcodeView.pauseAndWait() | ||
} | ||
|
||
private fun decodeQRSingle() { | ||
barcodeView.decodeSingle { barcodeResult -> | ||
println("Barcode Result = ${barcodeResult.text}") | ||
runCatching { | ||
val remoteAssociationUri = RemoteAssociationUri(Uri.parse(barcodeResult.text)) | ||
barcodeView.pause() | ||
|
||
startActivity( | ||
Intent(applicationContext, MobileWalletAdapterActivity::class.java) | ||
.setData(remoteAssociationUri.uri)) | ||
}.getOrElse { | ||
Snackbar.make(viewBinding.root, R.string.str_invalid_barcode, Snackbar.LENGTH_LONG).apply { | ||
setAction(R.string.label_try_again) { dismiss() } | ||
addCallback(object : Snackbar.Callback() { | ||
override fun onDismissed(transientBottomBar: Snackbar?, event: Int) { | ||
super.onDismissed(transientBottomBar, event) | ||
decodeQRSingle() | ||
} | ||
}) | ||
show() | ||
} | ||
} | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
android/fakewallet/src/main/res/drawable/drawable_view_finder_cutout.xml
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,27 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<item> | ||
<vector | ||
android:width="540dp" | ||
android:height="1200dp" | ||
android:viewportWidth="540" | ||
android:viewportHeight="1200"> | ||
<path | ||
android:fillColor="#99000000" | ||
android:pathData="M 0 0 L 0 1200 L 540 1200 L 540 0 L 0 0 z M 118 253.71484 L 422 253.71484 C 448.592 253.71484 470 275.12284 470 301.71484 L 470 605.71484 C 470 632.30684 448.592 653.71484 422 653.71484 L 118 653.71484 C 91.408 653.71484 70 632.30684 70 605.71484 L 70 301.71484 C 70 275.12284 91.408 253.71484 118 253.71484 z" /> | ||
</vector> | ||
</item> | ||
<item> | ||
<vector | ||
android:width="372dp" | ||
android:height="372dp" | ||
android:viewportWidth="540" | ||
android:viewportHeight="1200"> | ||
<path | ||
android:strokeWidth="12" | ||
android:strokeLineCap="round" | ||
android:strokeColor="@android:color/white" | ||
android:pathData="m 415.19999,255.71459 c 29.2512,0 52.8,23.5488 52.8,52.8 m 0,290.39999 c 0,29.25119 -23.5488,52.8 -52.8,52.8 m -290.39998,0 c -29.2512,0 -52.799999,-23.54881 -52.799999,-52.8 m 0,-290.39999 c 0,-29.2512 23.5488,-52.8 52.799999,-52.8" /> | ||
</vector> | ||
</item> | ||
</layer-list> |
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
39 changes: 39 additions & 0 deletions
39
android/fakewallet/src/main/res/layout/activity_scan_qr.xml
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,39 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
~ Copyright (c) 2025 Solana Mobile Inc. | ||
--> | ||
|
||
<androidx.constraintlayout.widget.ConstraintLayout 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=".ui.scanqr.ScanQRActivity"> | ||
|
||
<com.journeyapps.barcodescanner.BarcodeView | ||
android:id="@+id/scanner_view_finder" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintTop_toBottomOf="@id/label_scanner_title" | ||
app:layout_constraintBottom_toBottomOf="parent" /> | ||
|
||
<View | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:background="@drawable/drawable_view_finder_cutout"/> | ||
|
||
<TextView | ||
android:id="@+id/label_scanner_title" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="400dp" | ||
android:gravity="center" | ||
android:textColor="@color/white" | ||
android:textAppearance="@style/TextAppearance.AppCompat.Headline" | ||
android:text="@string/str_scan_mwa_qr_code" | ||
app:layout_constraintTop_toTopOf="parent" | ||
app:layout_constraintBottom_toBottomOf="parent" /> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> |
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