Skip to content

Commit

Permalink
Merge pull request #1 from LarryKlugerDS/docusign_test_tool
Browse files Browse the repository at this point in the history
v0
  • Loading branch information
LarryKlugerDS authored May 17, 2024
2 parents a971f09 + ac619e9 commit 3531e4d
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 67 deletions.
3 changes: 3 additions & 0 deletions sample/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions sample/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions sample/.idea/migrations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions sample/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions sample/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.content.ActivityNotFoundException
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.widget.ArrayAdapter
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.snackbar.Snackbar
Expand All @@ -13,47 +12,25 @@ import io.github.g00fy2.quickie.QRResult.QRError
import io.github.g00fy2.quickie.QRResult.QRMissingPermission
import io.github.g00fy2.quickie.QRResult.QRSuccess
import io.github.g00fy2.quickie.QRResult.QRUserCanceled
import io.github.g00fy2.quickie.ScanCustomCode
import io.github.g00fy2.quickie.ScanQRCode
import io.github.g00fy2.quickie.config.BarcodeFormat
import io.github.g00fy2.quickie.config.ScannerConfig
import io.github.g00fy2.quickie.content.QRContent
import io.github.g00fy2.quickiesample.databinding.ActivityMainBinding

class MainActivity : AppCompatActivity() {

private lateinit var binding: ActivityMainBinding
private var selectedBarcodeFormat = BarcodeFormat.FORMAT_ALL_FORMATS

private val scanQrCode = registerForActivityResult(ScanQRCode(), ::showSnackbar)
private val scanCustomCode = registerForActivityResult(ScanCustomCode(), ::showSnackbar)

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
setBarcodeFormatDropdown()

binding.qrScannerButton.setOnClickListener {
scanQrCode.launch(null)
}

binding.customScannerButton.setOnClickListener {
scanCustomCode.launch(
ScannerConfig.build {
setBarcodeFormats(listOf(selectedBarcodeFormat)) // set interested barcode formats
setOverlayStringRes(R.string.scan_barcode) // string resource used for the scanner overlay
setOverlayDrawableRes(R.drawable.ic_scan_barcode) // drawable resource used for the scanner overlay
setHapticSuccessFeedback(false) // enable (default) or disable haptic feedback when a barcode was detected
setShowTorchToggle(true) // show or hide (default) torch/flashlight toggle button
setShowCloseButton(true) // show or hide (default) close button
setHorizontalFrameRatio(2.2f) // set the horizontal overlay ratio (default is 1 / square frame)
setUseFrontCamera(false) // use the front camera
setKeepScreenOn(true) // keep the device's screen turned on
}
)
}

if (intent.extras?.getBoolean(OPEN_SCANNER) == true) scanQrCode.launch(null)
}

Expand All @@ -77,32 +54,22 @@ class MainActivity : AppCompatActivity() {
if (result is QRSuccess) {
val content = result.content
if (content is QRContent.Url) {
setAction(R.string.open_action) { openUrl(content.url) }
setAction(R.string.open_action) { openUrlInBrowser(content.url) }
return@apply
}
}
setAction(R.string.ok_action) { }
}.show()
}

private fun openUrl(url: String) {
private fun openUrlInBrowser(url: String) {
try {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))
} catch (ignored: ActivityNotFoundException) {
// no Activity found to run the given Intent
}
}

private fun setBarcodeFormatDropdown() {
ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_item, BarcodeFormat.entries.map { it.name }).let {
binding.barcodeFormatsAutoCompleteTextView.setAdapter(it)
binding.barcodeFormatsAutoCompleteTextView.setText(it.getItem(it.getPosition(selectedBarcodeFormat.name)), false)
}
binding.barcodeFormatsAutoCompleteTextView.setOnItemClickListener { _, _, position, _ ->
selectedBarcodeFormat = BarcodeFormat.entries[position]
}
}

companion object {
const val OPEN_SCANNER = "open_scanner"
}
Expand Down
35 changes: 7 additions & 28 deletions sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
tools:context=".MainActivity"
>

<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="136dp"
android:gravity="center"
android:text="@string/title"/>

<Button
android:id="@+id/qr_scanner_button"
android:layout_width="match_parent"
Expand All @@ -18,33 +25,5 @@
android:text="@string/qr_button"
/>

<Button
android:id="@+id/custom_scanner_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginEnd="64dp"
android:layout_marginStart="64dp"
android:layout_marginTop="16dp"
android:text="@string/custom_button"
/>

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/barcode_formats_text_input_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="@string/barcode_format"
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.Dense.ExposedDropdownMenu"
>

<AutoCompleteTextView
android:id="@+id/barcode_formats_auto_complete_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="none"
tools:ignore="LabelFor"
/>

</com.google.android.material.textfield.TextInputLayout>

</LinearLayout>
8 changes: 4 additions & 4 deletions sample/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<resources>
<string name="app_name" translatable="false">Quickie Sample</string>
<resources xmlns:tools="http://schemas.android.com/tools">
<string name="app_name" translatable="false">Docusign Webview Tester</string>

<string name="qr_button" translatable="false">QR-Code Scanner</string>
<string name="custom_button" translatable="false">Custom Scanner</string>
<string name="qr_button" translatable="false">Scan the QR-Code</string>
<string name="ok_action" translatable="false">OK</string>
<string name="open_action" translatable="false">Open</string>
<string name="scan_barcode" translatable="false">Scan barcode</string>
<string name="barcode_format" translatable="false">BarcodeFormat</string>
<string name="title" tools:ignore="MissingTranslation">This app opens the QR-Code URL in a Webview</string>
</resources>

0 comments on commit 3531e4d

Please sign in to comment.