add qr scanner for creator app and android app
This commit is contained in:
1 parent
2bad03c542
commit
be69b94560
18 files changed
+397
-15
No files matched your search
@@ -9,6 +9,11 @@
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"
|
||||
tools:ignore="QueryAllPackagesPermission" />
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
|
||||
<uses-feature
|
||||
android:name="android.hardware.camera"
|
||||
android:required="false" />
|
||||
|
||||
<application
|
||||
android:name=".App"
|
||||
@@ -34,6 +39,13 @@
|
||||
<action android:name="android.service.quicksettings.action.QS_TILE_PREFERENCES" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ui.QrCaptureActivity"
|
||||
android:clearTaskOnLaunch="true"
|
||||
android:screenOrientation="portrait"
|
||||
android:stateNotNeeded="true"
|
||||
android:theme="@style/zxing_CaptureTheme"
|
||||
android:windowSoftInputMode="stateAlwaysHidden" />
|
||||
<service
|
||||
android:name=".tunnel.TunnelVpnService"
|
||||
android:permission="android.permission.BIND_VPN_SERVICE"
|
||||
|
||||
@@ -33,6 +33,12 @@ class AddDestinationSheet : BottomSheetDialogFragment() {
|
||||
val buttonCancel = view.findViewById<Button>(R.id.buttonCancel)
|
||||
val buttonSave = view.findViewById<Button>(R.id.buttonSave)
|
||||
|
||||
val prefillLink = arguments?.getString(ARG_PREFILL_LINK).orEmpty()
|
||||
if (prefillLink.isNotEmpty()) {
|
||||
inputLink.setText(prefillLink)
|
||||
inputName.setText(CallConfig.suggestNameFor(prefillLink))
|
||||
}
|
||||
|
||||
pasteChip.setOnClickListener {
|
||||
val clipboard = requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||
val clip = clipboard.primaryClip
|
||||
@@ -80,8 +86,14 @@ class AddDestinationSheet : BottomSheetDialogFragment() {
|
||||
companion object {
|
||||
const val TAG = "AddDestinationSheet"
|
||||
|
||||
fun show(manager: FragmentManager) {
|
||||
AddDestinationSheet().show(manager, TAG)
|
||||
private const val ARG_PREFILL_LINK = "prefill_link"
|
||||
|
||||
fun show(manager: FragmentManager, prefillLink: String = "") {
|
||||
val sheet = AddDestinationSheet()
|
||||
if (prefillLink.isNotEmpty()) {
|
||||
sheet.arguments = Bundle().apply { putString(ARG_PREFILL_LINK, prefillLink) }
|
||||
}
|
||||
sheet.show(manager, TAG)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,9 +11,18 @@ import bypass.whitelist.tunnel.CallPlatform
|
||||
import bypass.whitelist.tunnel.TunnelMode
|
||||
import bypass.whitelist.tunnel.VpnStatus
|
||||
import bypass.whitelist.util.Prefs
|
||||
import com.journeyapps.barcodescanner.ScanContract
|
||||
import com.journeyapps.barcodescanner.ScanOptions
|
||||
|
||||
class MainFragment : Fragment(R.layout.fragment_main_screen) {
|
||||
|
||||
private val scanQrLauncher = registerForActivityResult(ScanContract()) { result ->
|
||||
val scanned = result.contents?.trim().orEmpty()
|
||||
if (scanned.isNotEmpty()) {
|
||||
AddDestinationSheet.show(parentFragmentManager, scanned)
|
||||
}
|
||||
}
|
||||
|
||||
private var content: MainFragmentView? = null
|
||||
private var pendingStatus: VpnStatus? = null
|
||||
private var connectedSinceMs: Long = 0L
|
||||
@@ -44,6 +53,16 @@ class MainFragment : Fragment(R.layout.fragment_main_screen) {
|
||||
container.onAddCallClicked = {
|
||||
AddDestinationSheet.show(parentFragmentManager)
|
||||
}
|
||||
container.onScanQrClicked = {
|
||||
scanQrLauncher.launch(
|
||||
ScanOptions()
|
||||
.setDesiredBarcodeFormats(ScanOptions.QR_CODE)
|
||||
.setPrompt(getString(R.string.scan_qr_prompt))
|
||||
.setBeepEnabled(false)
|
||||
.setOrientationLocked(false)
|
||||
.setCaptureActivity(QrCaptureActivity::class.java)
|
||||
)
|
||||
}
|
||||
container.onHeroPressed = {
|
||||
if (isHostConnected() || isHostConnecting()) {
|
||||
host()?.onDisconnectPressed()
|
||||
|
||||
@@ -21,6 +21,7 @@ class MainFragmentView(private val root: View) {
|
||||
|
||||
private val headerSub: TextView = root.findViewById(R.id.headerSub)
|
||||
private val addButton: View = root.findViewById(R.id.headerAddButton)
|
||||
private val scanButton: View = root.findViewById(R.id.headerScanButton)
|
||||
private val hero: View = root.findViewById(R.id.heroButton)
|
||||
private val heroLabel: TextView = root.findViewById(R.id.heroLabel)
|
||||
private val heroPowerIcon: ImageView = root.findViewById(R.id.heroPowerIcon)
|
||||
@@ -43,6 +44,7 @@ class MainFragmentView(private val root: View) {
|
||||
private val statMode: TextView = root.findViewById(R.id.statMode)
|
||||
|
||||
var onAddCallClicked: Callback? = null
|
||||
var onScanQrClicked: Callback? = null
|
||||
var onHeroPressed: Callback? = null
|
||||
var onPingPressed: Callback? = null
|
||||
var onCallSelected: ParamCallback<CallConfig>? = null
|
||||
@@ -58,6 +60,7 @@ class MainFragmentView(private val root: View) {
|
||||
emptyCta.clipToOutline = true
|
||||
pingButton.clipToOutline = true
|
||||
addButton.setOnClickListener { onAddCallClicked?.invoke() }
|
||||
scanButton.setOnClickListener { onScanQrClicked?.invoke() }
|
||||
emptyCta.setOnClickListener { onAddCallClicked?.invoke() }
|
||||
hero.setOnTouchListener { v, event ->
|
||||
when (event.action) {
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package bypass.whitelist.ui
|
||||
|
||||
import com.journeyapps.barcodescanner.CaptureActivity
|
||||
|
||||
class QrCaptureActivity : CaptureActivity()
|
||||
@@ -0,0 +1,40 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="16dp"
|
||||
android:height="16dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:strokeColor="@android:color/white"
|
||||
android:strokeWidth="1.8"
|
||||
android:strokeLineCap="round"
|
||||
android:strokeLineJoin="round"
|
||||
android:fillColor="@android:color/transparent"
|
||||
android:pathData="M4,9 L4,6 A2,2 0 0,1 6,4 L9,4" />
|
||||
<path
|
||||
android:strokeColor="@android:color/white"
|
||||
android:strokeWidth="1.8"
|
||||
android:strokeLineCap="round"
|
||||
android:strokeLineJoin="round"
|
||||
android:fillColor="@android:color/transparent"
|
||||
android:pathData="M15,4 L18,4 A2,2 0 0,1 20,6 L20,9" />
|
||||
<path
|
||||
android:strokeColor="@android:color/white"
|
||||
android:strokeWidth="1.8"
|
||||
android:strokeLineCap="round"
|
||||
android:strokeLineJoin="round"
|
||||
android:fillColor="@android:color/transparent"
|
||||
android:pathData="M20,15 L20,18 A2,2 0 0,1 18,20 L15,20" />
|
||||
<path
|
||||
android:strokeColor="@android:color/white"
|
||||
android:strokeWidth="1.8"
|
||||
android:strokeLineCap="round"
|
||||
android:strokeLineJoin="round"
|
||||
android:fillColor="@android:color/transparent"
|
||||
android:pathData="M9,20 L6,20 A2,2 0 0,1 4,18 L4,15" />
|
||||
<path
|
||||
android:strokeColor="@android:color/white"
|
||||
android:strokeWidth="1.8"
|
||||
android:strokeLineCap="round"
|
||||
android:fillColor="@android:color/transparent"
|
||||
android:pathData="M4,12 L20,12" />
|
||||
</vector>
|
||||
@@ -38,6 +38,18 @@
|
||||
android:textSize="10sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/headerScanButton"
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:background="@drawable/bg_icon_button"
|
||||
android:contentDescription="@string/scan_qr_title"
|
||||
android:padding="8dp"
|
||||
android:scaleType="fitCenter"
|
||||
android:src="@drawable/ic_qr"
|
||||
app:tint="@color/ink_2" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/headerAddButton"
|
||||
android:layout_width="36dp"
|
||||
|
||||
@@ -97,6 +97,8 @@
|
||||
|
||||
<string name="paste_from_clipboard">Paste from clipboard</string>
|
||||
<string name="clipboard_empty">Clipboard is empty</string>
|
||||
<string name="scan_qr_title">Scan QR code</string>
|
||||
<string name="scan_qr_prompt">Point the camera at the QR code shown in the creator app</string>
|
||||
|
||||
|
||||
<string name="settings_row_tunnel_mode">Tunnel mode</string>
|
||||
|
||||
Reference in new issue
Block a user