diff --git a/tangemtest/.gitignore b/tangemtest/.gitignore new file mode 100644 index 0000000000..796b96d1c4 --- /dev/null +++ b/tangemtest/.gitignore @@ -0,0 +1 @@ +/build diff --git a/tangemtest/build.gradle b/tangemtest/build.gradle new file mode 100644 index 0000000000..e3849d649e --- /dev/null +++ b/tangemtest/build.gradle @@ -0,0 +1,46 @@ +apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' +android { + compileSdkVersion 29 + buildToolsVersion "29.0.0" + + + defaultConfig { + applicationId "com.tangem.tangemtest" + minSdkVersion 21 + targetSdkVersion 29 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = '1.8' + } +} + +dependencies { + implementation project(':tangem-card-new') + implementation project(':tangem-sdk-new') + + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'androidx.core:core-ktx:1.1.0' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test:runner:1.2.0' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' +} diff --git a/tangemtest/proguard-rules.pro b/tangemtest/proguard-rules.pro new file mode 100644 index 0000000000..f1b424510d --- /dev/null +++ b/tangemtest/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/tangemtest/src/main/AndroidManifest.xml b/tangemtest/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..051383031e --- /dev/null +++ b/tangemtest/src/main/AndroidManifest.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tangemtest/src/main/java/com/tangem/tangemtest/MainActivity.kt b/tangemtest/src/main/java/com/tangem/tangemtest/MainActivity.kt new file mode 100644 index 0000000000..7f9dc6dea5 --- /dev/null +++ b/tangemtest/src/main/java/com/tangem/tangemtest/MainActivity.kt @@ -0,0 +1,87 @@ +package com.tangem.tangemtest + +import android.os.Bundle +import androidx.appcompat.app.AppCompatActivity +import com.tangem.CardManager +import com.tangem.CardManagerDelegate +import com.tangem.tangem_sdk_new.DefaultCardManagerDelegate +import com.tangem.tangem_sdk_new.NfcManager +import com.tangem.tangem_sdk_new.NfcReader +import com.tangem.tangem_sdk_new.postUI +import com.tangem.tasks.ScanEvent +import com.tangem.tasks.TaskEvent +import kotlinx.android.synthetic.main.activity_main.* + +class MainActivity : AppCompatActivity() { + + private val nfcReader = NfcReader() + private val nfcManager = NfcManager(nfcReader) + private val cardManagerDelegate: CardManagerDelegate = DefaultCardManagerDelegate(this, nfcReader) + private val cardManager = CardManager(nfcReader, cardManagerDelegate) + private lateinit var cid: String + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + + nfcManager.setCurrentActivity(this) + +// lifecycle.addObserver(NfcLifecycleObserver(nfcManager)) + + btn_scan?.setOnClickListener { _ -> + cardManager.scanCard { + if (it is TaskEvent.Event) { + when (it.data) { + is ScanEvent.OnReadEvent -> { + cid = (it.data as ScanEvent.OnReadEvent).result.cardId + } + is ScanEvent.OnVerifyEvent -> { + postUI { + tv_card_cid?.text = cid + btn_sign.isEnabled = true + } + } + } + } + } + } + btn_sign?.setOnClickListener { _ -> + val hash1 = ByteArray(32) + for (i in 0 until 32) { + hash1[i] = 1 + } + val hash2 = ByteArray(32) + for (i in 0 until 32) { + hash2[i] = 2 + } + cardManager.sign( + arrayOf(hash1, hash2), + cid) { + when (it) { + is TaskEvent.Completion -> { + if (it.error != null) postUI { tv_card_cid?.text = it.error!!::class.simpleName } + } + is TaskEvent.Event -> postUI { tv_card_cid?.text = cid + " used to sign sample hashes." } + } + + } + } + } + + override fun onResume() { + super.onResume() + nfcManager.onResume() + } + + + override fun onPause() { + super.onPause() + nfcManager.onPause() + } + + + override fun onDestroy() { + super.onDestroy() + nfcManager.onDestroy() + } +} \ No newline at end of file diff --git a/tangemtest/src/main/java/com/tangem/tangemtest/TestApp.kt b/tangemtest/src/main/java/com/tangem/tangemtest/TestApp.kt new file mode 100644 index 0000000000..39bdd77875 --- /dev/null +++ b/tangemtest/src/main/java/com/tangem/tangemtest/TestApp.kt @@ -0,0 +1,28 @@ +package com.tangem.tangemtest + +import android.app.Application +import com.tangem.Log +import com.tangem.LoggerInterface + +class TestApp : Application() { + + override fun onCreate() { + super.onCreate() + + Log.setLogger( + object : LoggerInterface { + override fun i(logTag: String, message: String) { + android.util.Log.i(logTag, message) + } + + override fun e(logTag: String, message: String) { + android.util.Log.e(logTag, message) + } + + override fun v(logTag: String, message: String) { + android.util.Log.v(logTag, message) + } + } + ) + } +} \ No newline at end of file diff --git a/tangemtest/src/main/res/drawable-v24/ic_launcher_foreground.xml b/tangemtest/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000000..1f6bb29060 --- /dev/null +++ b/tangemtest/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/tangemtest/src/main/res/drawable/ic_launcher_background.xml b/tangemtest/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000000..0d025f9bf6 --- /dev/null +++ b/tangemtest/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tangemtest/src/main/res/layout/activity_main.xml b/tangemtest/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000000..ce8879e576 --- /dev/null +++ b/tangemtest/src/main/res/layout/activity_main.xml @@ -0,0 +1,45 @@ + + + + + +