Added default Cow account.

Initialize ethereum on account change.
This commit is contained in:
Adrian Tiberius 2015-08-10 17:51:46 +02:00
parent f881d93d08
commit 4d0e06b400
3 changed files with 38 additions and 159 deletions

View File

@ -1,155 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="syng-client" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
<option name="GRADLE_PROJECT_PATH" value=":app" />
</configuration>
</facet>
<facet type="android" name="Android">
<configuration>
<option name="SELECTED_BUILD_VARIANT" value="debug" />
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugAndroidTest" />
<option name="COMPILE_JAVA_TEST_TASK_NAME" value="compileDebugAndroidTestSources" />
<afterSyncTasks>
<task>generateDebugAndroidTestSources</task>
<task>generateDebugSources</task>
</afterSyncTasks>
<option name="ALLOW_USER_CONFIGURATION" value="false" />
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/androidTest/debug" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/androidTest/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/co.dift.ui.swipetoaction/library/1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.afollestad/material-dialogs/0.7.7.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/22.2.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/cardview-v7/22.2.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/design/22.2.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/multidex/1.0.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/recyclerview-v7/22.2.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/22.2.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.getbase/floatingactionbutton/1.9.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.squareup.leakcanary/leakcanary-android/1.3.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="ormlite-android-4.48" level="project" />
<orderEntry type="library" exported="" name="design-22.2.1" level="project" />
<orderEntry type="library" exported="" name="floatingactionbutton-1.9.0" level="project" />
<orderEntry type="library" exported="" name="dagger-compiler-2.0" level="project" />
<orderEntry type="library" exported="" name="dagger-producers-2.0-beta" level="project" />
<orderEntry type="library" exported="" name="apktool-lib-1.4.4-3" level="project" />
<orderEntry type="library" exported="" name="ormlite-core-4.48" level="project" />
<orderEntry type="library" exported="" name="jsonrpc2-base-1.36" level="project" />
<orderEntry type="library" exported="" name="java-util-1.8.0" level="project" />
<orderEntry type="library" exported="" name="material-dialogs-0.7.7.0" level="project" />
<orderEntry type="library" exported="" name="leakcanary-analyzer-1.3.1" level="project" />
<orderEntry type="library" exported="" name="glide-3.6.1" level="project" />
<orderEntry type="library" exported="" name="commons-collections4-4.0" level="project" />
<orderEntry type="library" exported="" name="recyclerview-v7-22.2.1" level="project" />
<orderEntry type="library" exported="" name="cardview-v7-22.2.1" level="project" />
<orderEntry type="library" exported="" name="logback-android-core-1.1.1-3" level="project" />
<orderEntry type="library" exported="" name="haha-1.3" level="project" />
<orderEntry type="library" exported="" name="jsonrpc2-server-1.11" level="project" />
<orderEntry type="library" exported="" name="leakcanary-android-1.3.1" level="project" />
<orderEntry type="library" exported="" name="logback-android-classic-1.1.1-3" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-22.2.1" level="project" />
<orderEntry type="library" exported="" name="json-io-2.4.1" level="project" />
<orderEntry type="library" exported="" name="leveldb-api-0.7" level="project" />
<orderEntry type="library" exported="" name="jackson-databind-2.5.1" level="project" />
<orderEntry type="library" exported="" name="leveldb-0.7" level="project" />
<orderEntry type="library" exported="" name="persistence-api-1.0.2" level="project" />
<orderEntry type="library" exported="" name="netty-all-4.0.28.Final" level="project" />
<orderEntry type="library" exported="" name="multidex-1.0.1" level="project" />
<orderEntry type="library" exported="" name="commons-io-2.4" level="project" />
<orderEntry type="library" exported="" name="log4j-1.2.17" level="project" />
<orderEntry type="library" exported="" name="library-1.1" level="project" />
<orderEntry type="library" exported="" name="guava-18.0" level="project" />
<orderEntry type="library" exported="" name="javassist-3.15.0-GA" level="project" />
<orderEntry type="library" exported="" name="jackson-annotations-2.5.0" level="project" />
<orderEntry type="library" exported="" name="json-smart-1.3.1" level="project" />
<orderEntry type="library" exported="" name="javax.annotation-10.0-b28" level="project" />
<orderEntry type="library" exported="" name="core-1.51.0.0" level="project" />
<orderEntry type="library" exported="" name="prov-1.51.0.0" level="project" />
<orderEntry type="library" exported="" name="leakcanary-watcher-1.3.1" level="project" />
<orderEntry type="library" exported="" name="support-annotations-22.2.1" level="project" />
<orderEntry type="library" exported="" name="commons-pool-1.5.4" level="project" />
<orderEntry type="library" exported="" name="jsr305-3.0.0" level="project" />
<orderEntry type="library" exported="" name="dagger-2.1-SNAPSHOT" level="project" />
<orderEntry type="library" exported="" name="commons-dbcp-1.4" level="project" />
<orderEntry type="library" exported="" name="slf4j-api-1.7.12" level="project" />
<orderEntry type="library" exported="" name="support-v4-22.2.1" level="project" />
<orderEntry type="library" exported="" name="javax.inject-1" level="project" />
<orderEntry type="library" exported="" name="json-simple-1.1.1" level="project" />
<orderEntry type="library" exported="" name="jsonrpc2-client-1.15" level="project" />
<orderEntry type="library" exported="" name="jackson-core-2.5.1" level="project" />
<orderEntry type="module" module-name="ethereumj-core-android" exported="" />
<orderEntry type="module" module-name="ethereumj-core" exported="" />
<orderEntry type="module" module-name="cordova-android" exported="" />
</component>
</module>

View File

@ -34,6 +34,9 @@ import android.widget.Toast;
import com.afollestad.materialdialogs.MaterialDialog; import com.afollestad.materialdialogs.MaterialDialog;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import org.ethereum.crypto.HashUtil;
import org.spongycastle.util.encoders.Hex;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -50,6 +53,7 @@ import io.syng.util.GeneralUtil;
import static android.view.View.GONE; import static android.view.View.GONE;
import static android.view.View.VISIBLE; import static android.view.View.VISIBLE;
import static org.ethereum.config.SystemProperties.CONFIG;
public abstract class BaseActivity extends AppCompatActivity implements public abstract class BaseActivity extends AppCompatActivity implements
OnClickListener, OnDAppClickListener, OnProfileClickListener { OnClickListener, OnDAppClickListener, OnProfileClickListener {
@ -63,7 +67,7 @@ public abstract class BaseActivity extends AppCompatActivity implements
"EtherEx", "TrustDavis", "Augur", "Console", "DApps", "EtherEx", "TrustDavis", "Augur", "Console", "DApps",
"EtherEx", "TrustDavis")); "EtherEx", "TrustDavis"));
private ArrayList<String> mAccountNamesList = new ArrayList<>(Arrays.asList("Yaroslav", "Frank Underwood", private ArrayList<String> mAccountNamesList = new ArrayList<>(Arrays.asList("Cow", "Yaroslav", "Frank Underwood",
"Jarradh", "Adrian")); "Jarradh", "Adrian"));
private ActionBarDrawerToggle mDrawerToggle; private ActionBarDrawerToggle mDrawerToggle;
@ -153,6 +157,10 @@ public abstract class BaseActivity extends AppCompatActivity implements
Glide.with(this).load(R.drawable.drawer).into(header); Glide.with(this).load(R.drawable.drawer).into(header);
super.setContentView(mDrawerLayout); super.setContentView(mDrawerLayout);
TextView textView = (TextView) findViewById(R.id.tv_name);
if (textView != null) {
textView.setText("Cow");
}
} }
@ -161,6 +169,21 @@ public abstract class BaseActivity extends AppCompatActivity implements
for (String name : mAccountNamesList) { for (String name : mAccountNamesList) {
Profile profile = new Profile(); Profile profile = new Profile();
profile.setName(name); profile.setName(name);
// default cow account
if (name == "Cow") {
// Add default cow and monkey addresses
List<String> addresses = new ArrayList<String>();
byte[] cowAddr = HashUtil.sha3("cow".getBytes());
addresses.add(Hex.toHexString(cowAddr));
String secret = CONFIG.coinbaseSecret();
byte[] cbAddr = HashUtil.sha3(secret.getBytes());
addresses.add(Hex.toHexString(cbAddr));
profile.setPrivateKeys(addresses);
SyngApplication app = (SyngApplication)getApplication();
if (app.currentProfile == null) {
changeProfile(profile);
}
}
mProfiles.add(profile); mProfiles.add(profile);
} }
mAccountDrawerAdapter = new AccountDrawerAdapter(this, mProfiles, this); mAccountDrawerAdapter = new AccountDrawerAdapter(this, mProfiles, this);
@ -192,10 +215,15 @@ public abstract class BaseActivity extends AppCompatActivity implements
protected void changeProfile(Profile profile) { protected void changeProfile(Profile profile) {
TextView textView = (TextView) findViewById(R.id.tv_name);
if (textView != null) {
textView.setText(profile.getName());
}
SyngApplication application = (SyngApplication) getApplication(); SyngApplication application = (SyngApplication) getApplication();
List<String> privateKeys = profile.getPrivateKeys(); List<String> privateKeys = profile.getPrivateKeys();
application.sEthereumConnector.init(privateKeys); application.sEthereumConnector.init(privateKeys);
currentPosition = spinnerAdapter.getPosition(profile); application.currentProfile = profile;
//currentPosition = spinnerAdapter.getPosition(profile);
} }
protected void requestChangeProfile(Profile profile) { protected void requestChangeProfile(Profile profile) {
@ -461,8 +489,7 @@ public abstract class BaseActivity extends AppCompatActivity implements
@Override @Override
public void onProfileClick(Profile profile) { public void onProfileClick(Profile profile) {
TextView textView = (TextView) findViewById(R.id.tv_name); changeProfile(profile);
textView.setText(profile.getName());
flipDrawer(); flipDrawer();
} }

View File

@ -9,6 +9,7 @@ import com.squareup.leakcanary.RefWatcher;
import org.ethereum.android.service.ConnectorHandler; import org.ethereum.android.service.ConnectorHandler;
import org.ethereum.android.service.EthereumConnector; import org.ethereum.android.service.EthereumConnector;
import io.syng.entity.Profile;
import io.syng.service.EthereumService; import io.syng.service.EthereumService;
import io.syng.util.PreferenceManager; import io.syng.util.PreferenceManager;
@ -21,6 +22,8 @@ public class SyngApplication extends MultiDexApplication implements ConnectorHan
private RefWatcher refWatcher; private RefWatcher refWatcher;
public Profile currentProfile = null;
@Override public void onCreate() { @Override public void onCreate() {
super.onCreate(); super.onCreate();
mPreferenceManager = new PreferenceManager(this); mPreferenceManager = new PreferenceManager(this);
@ -50,6 +53,10 @@ public class SyngApplication extends MultiDexApplication implements ConnectorHan
@Override @Override
public void onConnectorConnected() { public void onConnectorConnected() {
if (currentProfile != null) {
sEthereumConnector.init(currentProfile.getPrivateKeys());
}
sEthereumConnector.startJsonRpc(); sEthereumConnector.startJsonRpc();
} }