Skip to content

Commit

Permalink
add open external edge
Browse files Browse the repository at this point in the history
  • Loading branch information
engrpanda committed May 20, 2024
1 parent fd51cfe commit 45d906c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
20 changes: 15 additions & 5 deletions app/src/main/java/com/evo/qrgo/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package com.evo.qrgo

import android.Manifest
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Bundle
import android.view.View
import android.widget.Toast
Expand All @@ -16,8 +18,6 @@ import com.journeyapps.barcodescanner.ScanContract
import com.journeyapps.barcodescanner.ScanIntentResult
import com.journeyapps.barcodescanner.ScanOptions



class MainActivity : AppCompatActivity() {

private val reqId = 0
Expand Down Expand Up @@ -47,14 +47,19 @@ class MainActivity : AppCompatActivity() {
// Hide the ImageView after scanning
binding.imageView.visibility = View.GONE

RobotApi.getInstance().startNavigation(0, string, 1.0, (10 * 1000).toLong(), mMotionListener)
// Check if the scanned string is a URL
if (string.startsWith("http://") || string.startsWith("https://")) {
openLink(string)
} else {
RobotApi.getInstance().startNavigation(0, string, 1.0, (10 * 1000).toLong(), mMotionListener)
}
}

private fun showCamera() {
val options = ScanOptions()
options.setDesiredBarcodeFormats(ScanOptions.QR_CODE)
options.setPrompt("Scan QR Code")
options.setCameraId(1) //default 0 back, 1 is front
options.setCameraId(0) //default 0 back, 1 is front
options.setBeepEnabled(false)
options.setBarcodeImageEnabled(true)
options.setOrientationLocked(false)
Expand Down Expand Up @@ -93,11 +98,12 @@ class MainActivity : AppCompatActivity() {
setContentView(binding.root)
}


private val mMotionListener: CommandListener = object : CommandListener() {
override fun onResult(result: Int, message: String) {
if ("succeed" == message) {
// Add any additional success handling here
} else {
// Add any failure handling here
}
}
}
Expand All @@ -111,4 +117,8 @@ class MainActivity : AppCompatActivity() {
onBackPressed()
}

private fun openLink(url: String) {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
startActivity(intent)
}
}
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<resources>
<string name="app_name">QRgo</string>
<string name="app_name">QRgo Lucki</string>
</resources>

0 comments on commit 45d906c

Please sign in to comment.