Skip to content

Commit

Permalink
Merge pull request #1 from uport-project/feature/add_demo_app
Browse files Browse the repository at this point in the history
add demo app
  • Loading branch information
mirceanis authored Jan 22, 2018
2 parents 9d757f3 + 8b34caf commit 297dd93
Show file tree
Hide file tree
Showing 13 changed files with 332 additions and 25 deletions.
27 changes: 2 additions & 25 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,8 @@ buildscript {
allprojects {
repositories {
jcenter()
google()
maven { url 'https://jitpack.io' }
}

apply plugin: "kotlin"
apply plugin: "jacoco"
apply plugin: "maven"

dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

testCompile "junit:junit:$junit_version"
}

task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}

task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}

artifacts {
archives sourcesJar
archives javadocJar
}
}
}
1 change: 1 addition & 0 deletions demoapp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
60 changes: 60 additions & 0 deletions demoapp/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
buildscript {
ext {
gradle_tools_version = "3.0.1"

build_tools_version = "27.0.2"
compile_sdk_version = 27
target_sdk_version = compile_sdk_version
min_sdk_version = 19

support_lib_version = "27.0.2"
constraint_layout_version = "1.0.2"

test_runner_version = "1.0.1"
espresso_version = "3.0.1"
}

repositories {
jcenter()
google()
}

dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.android.tools.build:gradle:$gradle_tools_version"
}
}

apply plugin: 'com.android.application'

android {
compileSdkVersion compile_sdk_version
buildToolsVersion build_tools_version

defaultConfig {
applicationId "me.uport.mnid.demo"
minSdkVersion min_sdk_version
targetSdkVersion target_sdk_version
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

}

dependencies {

implementation "com.android.support:appcompat-v7:$support_lib_version"
implementation "com.android.support.constraint:constraint-layout:$constraint_layout_version"

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

//this needs to be added to your project
implementation "com.github.uport-project:kmnid:master-SNAPSHOT"
}
21 changes: 21 additions & 0 deletions demoapp/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions demoapp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="me.uport.mnid.demo">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher_round"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:theme="@style/AppTheme" >

<activity android:name=".MnidActivity"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>
</manifest>
103 changes: 103 additions & 0 deletions demoapp/src/main/java/me/uport/mnid/demo/MnidActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package me.uport.mnid.demo

import android.os.Bundle
import android.support.v7.app.AppCompatActivity

import android.annotation .SuppressLint
import android.text.Editable
import android.text.TextWatcher
import android.widget.EditText
import android.widget.TextView
import me.uport.mnid.MNID

class MnidActivity : AppCompatActivity() {

private lateinit var mnidField : EditText
private lateinit var networkField : EditText
private lateinit var addressField : EditText
private lateinit var statusField: TextView

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_mnid)

mnidField = findViewById(R.id.mnid)
networkField = findViewById(R.id.network)
addressField = findViewById(R.id.address)
statusField = findViewById(R.id.status_box)

mnidField.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {}
override fun afterTextChanged(p0: Editable?) {}

override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
onMnidChanged(p0!!)
}
})

val fieldWatcher = object : TextWatcher {
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {}
override fun afterTextChanged(p0: Editable?) {}

override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
onFieldChanged()
}
}

networkField.addTextChangedListener(fieldWatcher)

addressField.addTextChangedListener(fieldWatcher)
}


private var disableOtherUpdates: Boolean = false

@SuppressLint("SetTextI18n")
fun onMnidChanged(newValue: CharSequence) {
if (disableOtherUpdates) {
return
}
disableOtherUpdates = true
val mnid = newValue.toString()

if (MNID.isMNID(mnid)) {
var status = "it looks like MNID\n"
try {
val account = MNID.decode(mnid)
networkField.setText(account.network)
addressField.setText(account.address)
} catch (e: Exception) {
status += "but I get this error when decoding:\n" + e.message
networkField.setText("0x00")
addressField.setText("0x0000000000000000000000000000000000000000")
}

statusField.text = status

} else {
statusField.text = "it doesn't look like MNID"
networkField.setText("0x00")
addressField.setText("0x0000000000000000000000000000000000000000")
}
disableOtherUpdates = false
}

fun onFieldChanged() {
if (disableOtherUpdates) {
return
}
disableOtherUpdates = true
val address = addressField.text.toString()
val network = networkField.text.toString()

try {
val mnid = MNID.encode(network, address)
mnidField.setText(mnid)
statusField.text = ""
} catch (e: Exception) {
statusField.text = e.message
}

disableOtherUpdates = false
}
}
72 changes: 72 additions & 0 deletions demoapp/src/main/res/layout/activity_mnid.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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:layout_width="match_parent"
android:layout_height="match_parent">

<EditText
android:id="@+id/mnid"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="32dp"
android:ems="10"
android:hint="@string/mnid"
android:inputType="text"
android:maxLines="1"
android:selectAllOnFocus="true"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/status_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintLeft_toLeftOf="@+id/mnid"
app:layout_constraintTop_toBottomOf="@+id/mnid"
tools:text="not MNID" />

<EditText
android:id="@+id/network"
android:layout_width="215dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="32dp"
android:ems="10"
android:hint="@string/network"
android:inputType="text"
android:maxLines="1"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/mnid" />


<EditText
android:id="@+id/address"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:hint="@string/address"
android:inputType="text"
android:maxLines="1"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/network" />


</android.support.constraint.ConstraintLayout>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions demoapp/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>
6 changes: 6 additions & 0 deletions demoapp/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<resources>
<string name="app_name">MNID demo</string>
<string name="mnid">MNID</string>
<string name="network">network</string>
<string name="address">address</string>
</resources>
16 changes: 16 additions & 0 deletions demoapp/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>

</resources>
23 changes: 23 additions & 0 deletions mnid/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
apply plugin: "kotlin"
apply plugin: "jacoco"
apply plugin: "maven"
apply plugin: "java-library"

dependencies {
compile "com.madgag.spongycastle:prov:$spongycastle_version"
compile "com.github.walleth:kethereum:$kethereum_version"

compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

testCompile "junit:junit:$junit_version"
}

task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}

task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}

artifacts {
archives sourcesJar
archives javadocJar
}
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
include ':mnid'
include ':demoapp'

0 comments on commit 297dd93

Please sign in to comment.