Added a brainkey derivation feature to the sample app
This commit is contained in:
parent
8b7b3deafe
commit
c861c72a31
9 changed files with 179 additions and 3 deletions
|
@ -22,6 +22,6 @@ buildscript {
|
||||||
google()
|
google()
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:3.3.1'
|
classpath 'com.android.tools.build:gradle:3.3.2'
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -14,10 +14,15 @@
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/AppTheme"
|
android:theme="@style/AppTheme"
|
||||||
tools:ignore="GoogleAppIndexingWarning">
|
tools:ignore="GoogleAppIndexingWarning">
|
||||||
|
<activity
|
||||||
|
android:name=".BrainkeyActivity"
|
||||||
|
android:label="@string/title_activity_brainkey"
|
||||||
|
android:theme="@style/AppTheme.NoActionBar"></activity>
|
||||||
<activity android:name=".SubscriptionActivity" />
|
<activity android:name=".SubscriptionActivity" />
|
||||||
<activity android:name=".CallsActivity">
|
<activity android:name=".CallsActivity">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
package cy.agorise.labs.sample;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.design.widget.TextInputEditText;
|
||||||
|
import android.support.v7.app.AppCompatActivity;
|
||||||
|
import android.support.v7.widget.Toolbar;
|
||||||
|
import android.text.Spannable;
|
||||||
|
import android.text.SpannableStringBuilder;
|
||||||
|
import android.text.style.StyleSpan;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import butterknife.BindView;
|
||||||
|
import butterknife.ButterKnife;
|
||||||
|
import butterknife.OnClick;
|
||||||
|
import cy.agorise.graphenej.BrainKey;
|
||||||
|
|
||||||
|
public class BrainkeyActivity extends AppCompatActivity {
|
||||||
|
private final String TAG = this.getClass().getName();
|
||||||
|
@BindView(R.id.brainkey)
|
||||||
|
TextInputEditText mBrainkeyView;
|
||||||
|
|
||||||
|
@BindView(R.id.pubkey)
|
||||||
|
TextInputEditText mDesiredPubKey;
|
||||||
|
|
||||||
|
@BindView(R.id.pubkey_display)
|
||||||
|
TextView mPubkeyDisplay;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_brainkey);
|
||||||
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||||
|
setSupportActionBar(toolbar);
|
||||||
|
ButterKnife.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnClick(R.id.button_generate)
|
||||||
|
public void onGenerateClicked(View v){
|
||||||
|
String target = mDesiredPubKey.getText().toString();
|
||||||
|
String brainkeyText = mBrainkeyView.getText().toString();
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
for(int i = 0; i < 10; i++){
|
||||||
|
BrainKey brainKey = new BrainKey(brainkeyText, i);
|
||||||
|
builder.append(String.format(Locale.ROOT, "%d -> ", i))
|
||||||
|
.append(brainKey.getPublicAddress("BTS").toString())
|
||||||
|
.append("\n");
|
||||||
|
}
|
||||||
|
String derivationResult = builder.toString();
|
||||||
|
mPubkeyDisplay.setText(derivationResult);
|
||||||
|
if(!target.isEmpty() && derivationResult.contains(target)){
|
||||||
|
int start = derivationResult.indexOf(target);
|
||||||
|
SpannableStringBuilder sBuilder = new SpannableStringBuilder(derivationResult);
|
||||||
|
sBuilder.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), start, (start + 53), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
|
mPubkeyDisplay.setText(sBuilder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -26,6 +26,7 @@ public class CallsActivity extends AppCompatActivity {
|
||||||
private final String TAG = this.getClass().getName();
|
private final String TAG = this.getClass().getName();
|
||||||
|
|
||||||
private static final String REMOVE_CURRENT_NODE = "remove_current_node";
|
private static final String REMOVE_CURRENT_NODE = "remove_current_node";
|
||||||
|
private static final String TEST_BRAINKEY_DERIVATION = "test_brainkey_derivation";
|
||||||
|
|
||||||
@BindView(R.id.call_list)
|
@BindView(R.id.call_list)
|
||||||
RecyclerView mRecyclerView;
|
RecyclerView mRecyclerView;
|
||||||
|
@ -81,7 +82,8 @@ public class CallsActivity extends AppCompatActivity {
|
||||||
RPC.CALL_GET_ACCOUNT_BALANCES,
|
RPC.CALL_GET_ACCOUNT_BALANCES,
|
||||||
RPC.CALL_BROADCAST_TRANSACTION,
|
RPC.CALL_BROADCAST_TRANSACTION,
|
||||||
RPC.CALL_GET_TRANSACTION,
|
RPC.CALL_GET_TRANSACTION,
|
||||||
REMOVE_CURRENT_NODE
|
REMOVE_CURRENT_NODE,
|
||||||
|
TEST_BRAINKEY_DERIVATION
|
||||||
};
|
};
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
|
@ -104,6 +106,8 @@ public class CallsActivity extends AppCompatActivity {
|
||||||
intent = new Intent(CallsActivity.this, SubscriptionActivity.class);
|
intent = new Intent(CallsActivity.this, SubscriptionActivity.class);
|
||||||
} else if (selectedCall.equals(REMOVE_CURRENT_NODE)){
|
} else if (selectedCall.equals(REMOVE_CURRENT_NODE)){
|
||||||
intent = new Intent(CallsActivity.this, RemoveNodeActivity.class);
|
intent = new Intent(CallsActivity.this, RemoveNodeActivity.class);
|
||||||
|
} else if (selectedCall.equals(TEST_BRAINKEY_DERIVATION)){
|
||||||
|
intent = new Intent(CallsActivity.this, BrainkeyActivity.class);
|
||||||
} else {
|
} else {
|
||||||
intent = new Intent(CallsActivity.this, PerformCallActivity.class);
|
intent = new Intent(CallsActivity.this, PerformCallActivity.class);
|
||||||
intent.putExtra(Constants.KEY_SELECTED_CALL, selectedCall);
|
intent.putExtra(Constants.KEY_SELECTED_CALL, selectedCall);
|
||||||
|
|
25
sample/src/main/res/layout/activity_brainkey.xml
Normal file
25
sample/src/main/res/layout/activity_brainkey.xml
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<android.support.design.widget.CoordinatorLayout 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"
|
||||||
|
tools:context=".BrainkeyActivity">
|
||||||
|
|
||||||
|
<android.support.design.widget.AppBarLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:theme="@style/AppTheme.AppBarOverlay">
|
||||||
|
|
||||||
|
<android.support.v7.widget.Toolbar
|
||||||
|
android:id="@+id/toolbar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="?attr/actionBarSize"
|
||||||
|
android:background="?attr/colorPrimary"
|
||||||
|
app:popupTheme="@style/AppTheme.PopupOverlay" />
|
||||||
|
|
||||||
|
</android.support.design.widget.AppBarLayout>
|
||||||
|
|
||||||
|
<include layout="@layout/content_brainkey" />
|
||||||
|
|
||||||
|
</android.support.design.widget.CoordinatorLayout>
|
64
sample/src/main/res/layout/content_brainkey.xml
Normal file
64
sample/src/main/res/layout/content_brainkey.xml
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
<?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"
|
||||||
|
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||||
|
tools:context=".BrainkeyActivity"
|
||||||
|
tools:showIn="@layout/activity_brainkey">
|
||||||
|
<android.support.design.widget.TextInputLayout
|
||||||
|
android:id="@+id/container_brainkey"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginEnd="8dp"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:layout_marginTop="32dp"
|
||||||
|
android:hint="@string/hint_brainkey"
|
||||||
|
app:layout_constraintBottom_toTopOf="@+id/container_pub_key"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintHorizontal_bias="0.5"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent">
|
||||||
|
<android.support.design.widget.TextInputEditText
|
||||||
|
android:id="@+id/brainkey"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:lines="4"/>
|
||||||
|
</android.support.design.widget.TextInputLayout>
|
||||||
|
<android.support.design.widget.TextInputLayout
|
||||||
|
android:id="@+id/container_pub_key"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginEnd="8dp"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:hint="@string/hint_pubkey"
|
||||||
|
app:layout_constraintBottom_toTopOf="@+id/pubkey_display"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintHorizontal_bias="0.5"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/container_brainkey">
|
||||||
|
<android.support.design.widget.TextInputEditText
|
||||||
|
android:id="@+id/pubkey"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"/>
|
||||||
|
</android.support.design.widget.TextInputLayout>
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/pubkey_display"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:textSize="10sp"
|
||||||
|
android:layout_margin="8dp"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintBottom_toTopOf="@+id/button_generate"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/container_pub_key"/>
|
||||||
|
<Button android:id="@+id/button_generate"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="8dp"
|
||||||
|
android:text="@string/button_generate"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"/>
|
||||||
|
</android.support.constraint.ConstraintLayout>
|
3
sample/src/main/res/values/dimens.xml
Normal file
3
sample/src/main/res/values/dimens.xml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
<resources>
|
||||||
|
<dimen name="fab_margin">16dp</dimen>
|
||||||
|
</resources>
|
|
@ -64,4 +64,10 @@
|
||||||
<!-- GetAccountBalances -->
|
<!-- GetAccountBalances -->
|
||||||
<string name="get_account_balances_arg1">User account</string>
|
<string name="get_account_balances_arg1">User account</string>
|
||||||
<string name="get_account_balances_arg2">Comma-separated list of assets</string>
|
<string name="get_account_balances_arg2">Comma-separated list of assets</string>
|
||||||
|
<string name="title_activity_brainkey">BrainkeyActivity</string>
|
||||||
|
|
||||||
|
<!-- BrainkeyActivity strings -->
|
||||||
|
<string name="hint_brainkey">Brainkey</string>
|
||||||
|
<string name="hint_pubkey">Desired public key / address</string>
|
||||||
|
<string name="button_generate">Generate public key</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -8,4 +8,13 @@
|
||||||
<item name="colorAccent">@color/colorAccent</item>
|
<item name="colorAccent">@color/colorAccent</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<style name="AppTheme.NoActionBar">
|
||||||
|
<item name="windowActionBar">false</item>
|
||||||
|
<item name="windowNoTitle">true</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
|
||||||
|
|
||||||
|
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in a new issue