Browse Source

Implemented functionl QR Code Scanner but unable to pass data scanned

master
jahway603 4 years ago
parent
commit
5537f2a514
  1. 6
      README.md
  2. 3
      app/build.gradle
  3. 107
      app/src/main/java/org/myhush/silentdragon/MainActivity.kt
  4. 109
      app/src/main/res/layout/activity_qr_reader.xml

6
README.md

@ -63,6 +63,10 @@ Make sure you have Gradle 5.4.x or higher, 5.4.1 is known to work:
./gradlew wrapper --gradle-version=5.4.1
Or you can use Android Studio on Linux, OS X, or Windows:
Make sure to install ndkVersion 21.1.6352462
## Release Build Process
The first time you create a release build you'll need to create a keystore file and prepare a properties file. The
@ -114,7 +118,7 @@ This build can be directly uploaded to Google Play.
### Building a release APK for F-Droid
We should do this & will plan to using [this](https://gitlab.com/fdroid/fdroiddata/blob/master/CONTRIBUTING.md)
This will be pursued once lite wallet functionality exists in the SilentDragonAndroid wallet.
...

3
app/build.gradle

@ -86,8 +86,7 @@ dependencies {
implementation 'com.google.android.gms:play-services-vision:17.0.2'
implementation 'com.github.joshjdevl.libsodiumjni:libsodium-jni-aar:2.0.1'
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.19'
//implementation 'com.journeyapps:zxing-android-embedded:3.6.0'
implementation 'com.google.zxing:core:3.4.0'
implementation 'com.journeyapps:zxing-android-embedded:3.6.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'

107
app/src/main/java/org/myhush/silentdragon/MainActivity.kt

@ -10,20 +10,27 @@ import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.os.Handler
import androidx.constraintlayout.widget.ConstraintLayout
import com.google.android.material.snackbar.Snackbar
import androidx.core.text.HtmlCompat
import androidx.appcompat.app.AppCompatActivity
import android.text.Html
import android.util.Log
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.widget.Button
import android.widget.ScrollView
import android.widget.TextView
import android.widget.Toast
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.text.HtmlCompat
import com.beust.klaxon.Klaxon
import com.google.android.material.snackbar.Snackbar
import com.google.zxing.client.android.Intents
import com.google.zxing.client.android.Intents.Scan.QR_CODE_MODE
import com.google.zxing.integration.android.IntentIntegrator
import com.google.zxing.integration.android.IntentResult
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.activity_qr_reader.*
import kotlinx.android.synthetic.main.content_main.*
import org.myhush.silentdragon.DataModel.ConnectionStatus
import org.myhush.silentdragon.DataModel.connStatus
@ -38,6 +45,9 @@ class MainActivity : AppCompatActivity(),
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
// IntentIntegrator is part of zxing-android-embedded to read QR codes
private lateinit var intentIntegrator: IntentIntegrator
override fun onCreate(savedInstanceState: Bundle?) {
//StrictMode.setThreadPolicy(StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build()) // TESTING
@ -50,17 +60,20 @@ class MainActivity : AppCompatActivity(),
// When creating, clear all the data first
setMainStatus("")
DataModel.init()
intentIntegrator = IntentIntegrator(this)
btnConnect.setOnClickListener {
val intent = Intent(this, QrReaderActivity::class.java)
intent.putExtra("REQUEST_CODE",
QrReaderActivity.REQUEST_CONNDATA
)
startActivityForResult(intent,
QrReaderActivity.REQUEST_CONNDATA
)
//startActivity(Intent(this@MainActivity, QrReaderActivity::class.java))
run {
intentIntegrator.setDesiredBarcodeFormats(QR_CODE_MODE)
intentIntegrator.setCameraId(0) // set to back camera
intentIntegrator.setBeepEnabled(true)
intentIntegrator.setOrientationLocked(false) // trying to force portrait here, but it's not working
intentIntegrator.setPrompt("Go to Apps -> Connect mobile app on your desktop wallet and scan the QR Code to connect")
intentIntegrator.initiateScan()
}
}
btnReconnect.setOnClickListener {
@ -294,7 +307,6 @@ class MainActivity : AppCompatActivity(),
R.id.action_refresh -> {
swiperefresh.isRefreshing = true
ConnectionManager.refreshAllData()
return true
}
else -> super.onOptionsItemSelected(item)
@ -341,42 +353,39 @@ class MainActivity : AppCompatActivity(),
super.onDestroy()
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
when(requestCode) {
QrReaderActivity.REQUEST_CONNDATA -> {
if (resultCode == Activity.RESULT_OK) {
Log.i(TAG, "Main Activity got result for QrCode: ${data?.dataString}")
// Check to make sure that the result is an actual address
if (!(data?.dataString ?: "").startsWith("ws")) {
Toast.makeText(applicationContext,
getString(R.string.is_not_a_valid_connection_string, data?.dataString), Toast.LENGTH_SHORT).show()
return
}
// the toasts work here so commenting out
/*override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
val conComponents = data?.dataString?.split(",")
if (conComponents?.size ?: 0 < 2 || conComponents?.size ?: 0 > 3) {
Toast.makeText(applicationContext,
getString(R.string.is_not_a_valid_connection_string, data?.dataString), Toast.LENGTH_SHORT).show()
return
}
var result: IntentResult? = IntentIntegrator.parseActivityResult(requestCode, resultCode, data)
val conString = conComponents!![0]
val secretHex = conComponents[1]
val allowInternetConnections = if (conComponents.size == 3) conComponents[2] == "1" else false
if(result != null){
DataModel.setSecretHex(secretHex)
DataModel.setConnString(
conString,
applicationContext
)
DataModel.setAllowInternet(
allowInternetConnections
)
if(result.contents != null){
//Toast.makeText(applicationContext, result.contents,Toast.LENGTH_LONG).show()
Toast.makeText(this, "Scanned: " + result.contents, Toast.LENGTH_LONG).show();
} else {
//Toast.makeText(applicationContext,"scan failed",Toast.LENGTH_SHORT).show()
Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show()
}
} else {
super.onActivityResult(requestCode, resultCode, data)
}
}*/
ConnectionManager.refreshAllData()
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
var result: IntentResult? = IntentIntegrator.parseActivityResult(requestCode, resultCode, data)
if(result != null){
if(result.contents != null){
Log.d("MainActivity", "Scanned" + result.contents)
Toast.makeText(this, "Scanned: " + result.contents, Toast.LENGTH_LONG).show();
processMobileConnectorText(result.contents)
} else {
Log.d("MainActivity", "Cancelled scan")
Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show()
}
} else {
super.onActivityResult(requestCode, resultCode, data)
}
}
@ -391,5 +400,15 @@ class MainActivity : AppCompatActivity(),
updateUI(true)
}
private fun processMobileConnectorText(qrcodeInfo: String) {
if (qrcodeInfo.startsWith("ws")) {
Log.i(TAG, "It's a ws connection")
//Toast.makeText(this, "YEAH " + qrcodeInfo.toString(), Toast.LENGTH_SHORT).show();
} else {
Log.i(TAG, "Not a ws connection")
//Toast.makeText(this, "Not a ws connection", Toast.LENGTH_SHORT).show();
}
}
private val TAG = "MainActivity"
}

109
app/src/main/res/layout/activity_qr_reader.xml

@ -1,53 +1,70 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/activity_qr_code_reader"
tools:context=".QrCodeReaderActivity" android:id="@+id/camPreview">
<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:id="@+id/camPreview"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="org.myhush.silentdragon.QrReaderActivity"
tools:showIn="@layout/activity_qr_reader">
<SurfaceView
android:layout_width="0dp"
android:layout_height="0dp"
android:id="@+id/camera_view"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintBottom_toBottomOf="parent"/>
android:id="@+id/camera_view"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:src="#ee000000"
android:layout_width="0dp"
android:layout_height="200dp" android:id="@+id/imageView4"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
android:id="@+id/imageView4"
android:layout_width="0dp"
android:layout_height="200dp"
android:src="#ee000000"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:text="@string/how_to_connect_sd2sda"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/txtQrCodeHelp"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="8dp" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="8dp" android:textAlignment="center"
android:layout_marginBottom="16dp" app:layout_constraintBottom_toTopOf="@+id/btnQrCodeCancel"
android:textColor="@android:color/white"/>
android:id="@+id/txtQrCodeHelp"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="16dp"
android:text="@string/how_to_connect_sd2sda"
android:textAlignment="center"
android:textColor="@android:color/white"
app:layout_constraintBottom_toTopOf="@+id/btnQrCodeCancel"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<Button
android:text="@string/cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnQrCodeCancel"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="8dp" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="8dp" android:background="@color/colorPrimary"
android:textColor="@android:color/white" android:layout_marginBottom="16dp"
app:layout_constraintBottom_toTopOf="@+id/lblErrorMsg"/>
android:id="@+id/btnQrCodeCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="16dp"
android:background="@color/colorPrimary"
android:text="@string/cancel"
android:textColor="@android:color/white"
app:layout_constraintBottom_toTopOf="@+id/lblErrorMsg"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/lblErrorMsg"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="8dp" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="8dp" android:textAlignment="center" android:textColor="@color/colorAccent"
android:layout_marginBottom="32dp"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
android:id="@+id/lblErrorMsg"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="32dp"
android:textAlignment="center"
android:textColor="@color/colorAccent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

Loading…
Cancel
Save