Skip to content

Commit

Permalink
cleanup/refactor library and progess reports
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanraes committed Jun 4, 2017
1 parent 86b677f commit 2bdd221
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 64 deletions.
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

2 changes: 1 addition & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ dependencies {
compile 'org.jmrtd:jmrtd:0.5.5'
compile 'com.madgag.spongycastle:prov:1.54.0.0'
compile 'net.sf.scuba:scuba-sc-android:0.0.9'
compile('com.github.jonathanraes:digital-voting-pass-bitcoinj', {
exclude group: 'bitcoinj-examples'
exclude group: 'bitcoinj-tools'
exclude group: 'bitcoinj-parent'
})
// compile('com.github.jonathanraes:digital-voting-pass-bitcoinj', {
// exclude group: 'bitcoinj-examples'
// exclude group: 'bitcoinj-tools'
// exclude group: 'bitcoinj-parent'
// })
testCompile 'junit:junit:4.12'

compile group: 'org.slf4j', name:'slf4j-api', version: '1.7.2'
Expand All @@ -64,5 +64,5 @@ dependencies {
compile 'com.android.volley:volley:1.0.0'

// compile project(':digital-voting-pass-bitcoinj')
// compile project(':bitcoinj-core')
compile project(':bitcoinj-core')
}
63 changes: 38 additions & 25 deletions app/src/main/java/com/digitalvotingpass/blockchain/BlockChain.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.util.Log;

import com.digitalvotingpass.digitalvotingpass.SplashActivity;
import com.google.common.util.concurrent.Service;

import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.core.PeerAddress;
Expand All @@ -20,6 +21,8 @@ public class BlockChain {
public static final String PEER_IP = "188.226.149.56";
private static BlockChain instance;
InetAddress peeraddr;
WalletAppKit kit;
private boolean initialized = false;

private BlockChain() {
try {
Expand All @@ -36,38 +39,48 @@ public static synchronized BlockChain getInstance() {
return instance;
}

public void receiveBlockChain(BlockchainCallBackListener listener) {
BriefLogFormatter.init();
final NetworkParameters params = MultiChainParams.get(
"00ea493df401cee6694c68a35d2b50dbdd197bd630cc2a95875933e16b7d0590",
"010000000000000000000000000000000000000000000000000000000000000000000000b59757b81c569f8b3854d83fe1b09b9a69a7b6ea1c33863a2a1640ee865ce1dc0f373059ffff0020a70100000101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff1704ffff002001040f4d756c7469436861696e20766f7465ffffffff0200000000000000002f76a914a18876083c6b7e3a76b0549dcd49cadf7222a05788ac1473706b703731000000000000ffffffff0f373059750000000000000000131073706b6e0200040101000104726f6f74756a00000000"
);
public void startDownload(BlockchainCallBackListener listener) {
if (!initialized) {
BriefLogFormatter.init();
final NetworkParameters params = MultiChainParams.get(
"00ea493df401cee6694c68a35d2b50dbdd197bd630cc2a95875933e16b7d0590",
"010000000000000000000000000000000000000000000000000000000000000000000000b59757b81c569f8b3854d83fe1b09b9a69a7b6ea1c33863a2a1640ee865ce1dc0f373059ffff0020a70100000101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff1704ffff002001040f4d756c7469436861696e20766f7465ffffffff0200000000000000002f76a914a18876083c6b7e3a76b0549dcd49cadf7222a05788ac1473706b703731000000000000ffffffff0f373059750000000000000000131073706b6e0200040101000104726f6f74756a00000000"
);

String filePrefix = "voting-wallet";
String filePrefix = "voting-wallet";

File walletFile = new File(Environment.getExternalStorageDirectory() + "/DigitalVotingPass");
if (!walletFile.exists()) {
if (!walletFile.mkdirs()) { //getParent because otherwise it creates a folder with that filename, we just need the dirs
Log.e("BlockChain", "Cannot create path!");
File walletFile = new File(Environment.getExternalStorageDirectory() + "/DigitalVotingPass");
if (!walletFile.exists()) {
if (!walletFile.mkdirs()) { //getParent because otherwise it creates a folder with that filename, we just need the dirs
Log.e("BlockChain", "Cannot create path!");
}
}
}
// Start up a basic app using a class that automates some boilerplate.
WalletAppKit kit = new WalletAppKit(params, walletFile, filePrefix);
// Start up a basic app using a class that automates some boilerplate.
kit = new WalletAppKit(params, walletFile, filePrefix);

if (params == RegTestParams.get()) {
// Regression test mode is designed for testing and development only, so there's no public network for it.
// If you pick this mode, you're expected to be running a local "bitcoind -regtest" instance.
kit.connectToLocalHost();
}
if (params == RegTestParams.get()) {
// Regression test mode is designed for testing and development only, so there's no public network for it.
// If you pick this mode, you're expected to be running a local "bitcoind -regtest" instance.
kit.connectToLocalHost();
}

kit = kit.setDownloadListener(new ProgressTracker(listener));
kit.setBlockingStartup(false);
kit = kit.setDownloadListener(new ProgressTracker(listener));
kit.setBlockingStartup(false);

PeerAddress peer = new PeerAddress(params, peeraddr);
PeerAddress peer = new PeerAddress(params, peeraddr);
kit.setPeerNodes(peer);
kit.startAsync();
}
}

public Service.State state() {
if (kit == null)
return null;
return kit.state();
}

kit.setPeerNodes(peer);
kit.startAsync();
Log.e("SplashActivity", "Chain started");
public void disconnect() {
kit.stopAsync();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,18 @@ class ProgressTracker extends DownloadProgressTracker {

@Override
protected void progress(double pct, int blocksSoFar, Date date) {
Log.e("Progress", "Progress update");
listener.onDownloadProgress(pct, blocksSoFar, date);
if (pct == 100) {
listener.onDownloadComplete();
}
}

@Override
protected void startDownload(int blocks) {
super.startDownload(blocks);
listener.onInitComplete();
}

@Override
protected void doneDownload() {
super.doneDownload();
listener.onDownloadComplete();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import android.support.annotation.NonNull;
import android.support.v13.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.widget.ProgressBar;
import android.widget.TextView;

Expand All @@ -23,10 +22,9 @@

public class SplashActivity extends Activity implements BlockchainCallBackListener {
public static final int REQUEST_CODE_STORAGE = 15;
public static final int REQUEST_CODE_INTERNET = 5;
private int DELAY_INIT_TEXT_UPDATES = 800;

// Duration of splash screen in millis
private final int SPLASH_DISPLAY_LENGTH = 1000;
private String TAG = getClass().getSimpleName();

private TextView downloadPogressText;
Expand All @@ -46,39 +44,41 @@ public void run() {
requestStoragePermissions();
return;
}
BlockChain.getInstance().receiveBlockChain(thisActivity);
BlockChain.getInstance().startDownload(thisActivity);
}
};

Runnable initUpdate = new Runnable() {
Runnable initTextUpdater = new Runnable() {
int i = 0;
@Override
public void run() {
String[] s = ((Activity)thisActivity).getResources().getStringArray(R.array.init_array);
currentTask.setText(s[i % s.length]);
i++;
initTextHandler.postDelayed(this, 500);
initTextHandler.postDelayed(this, DELAY_INIT_TEXT_UPDATES);
}
};

/**
* Creates a splash screen
* @param bundle
* @param savedInstanceState
*/
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);

downloadPogressText = (TextView) findViewById(R.id.download_progress_text);
currentTask = (TextView) findViewById(R.id.progress_current_task);
downloadProgressBar = (ProgressBar) findViewById(R.id.download_progress_bar);

thisActivity = this;
handler = new Handler();
initTextHandler = new Handler();
initTextHandler.post(initUpdate);
handler.post(startBlockChain);
if (savedInstanceState == null) {
handler = new Handler();
initTextHandler = new Handler();
initTextHandler.post(initTextUpdater);
handler.post(startBlockChain);
}
}

@Override
Expand All @@ -105,26 +105,30 @@ private void requestStoragePermissions() {

@Override
public void onInitComplete() {
initTextHandler.removeCallbacks(initUpdate);
initTextHandler.removeCallbacks(initTextUpdater);
currentTask.setText(R.string.downloading_text);
downloadPogressText.setText(percentFormatter.format(0) + "%");
}

@Override
public void onDownloadComplete() {
Intent mainIntent = new Intent(SplashActivity.this, ElectionChoiceActivity.class);
SplashActivity.this.startActivity(mainIntent);
SplashActivity.this.finish();
startActivity(mainIntent);
finish();
}

@Override
protected void onDestroy() {
super.onDestroy();
Log.e("","");
initTextHandler.removeCallbacks(initUpdate);
}

@Override
protected void onStop() {
super.onStop();
}

@Override
public void onDownloadProgress(double pct, int blocksSoFar, Date date) {
onInitComplete();
runOnUiThread(new Runnable() {
@Override
public void run() {
Expand Down
Binary file not shown.
2 changes: 0 additions & 2 deletions bitcoinj-core-0.15-SNAPSHOT-bundled/build.gradle

This file was deleted.

2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ buildscript {

allprojects {
repositories {
// maven { url "https://jitpack.io" }
jcenter()
maven { url "https://jitpack.io" }
}
}

Expand Down
1 change: 0 additions & 1 deletion digital-voting-pass-bitcoinj
Submodule digital-voting-pass-bitcoinj deleted from 700b9f
3 changes: 2 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
include ':app', ':bitcoinj-core-0.15-SNAPSHOT-bundled'
include ':app', ':bitcoinj-core'
//include(':app', 'digital-voting-pass-bitcoinj')

0 comments on commit 2bdd221

Please sign in to comment.