Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

readme update

  • Loading branch information...
commit 468ed6d566d7c92ddfce743252d15654a8295e4a 1 parent 6aa0dbd
Brian Armstrong authored
View
2  .project
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
- <name>BitcoinWallet</name>
+ <name>BitcoinAndroid</name>
<comment></comment>
<projects>
</projects>
View
2  AndroidManifest.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.bitcoinwallet" android:versionCode="1"
+ package="com.bitcoinandroid" android:versionCode="1"
android:versionName="1.0" android:installLocation="preferExternal" >
<uses-sdk android:minSdkVersion="8" />
View
2  README.md
@@ -27,6 +27,8 @@ Features
* Wallet file backed up in the cloud (synced to your Google account) in case you lose your phone.
* A free app, 100% open source
+<iframe width="425" height="349" src="http://www.youtube.com/embed/W6EucS5RS24" frameborder="0" allowfullscreen></iframe>
+
Installation
-------------
View
140 gen/com/bitcoinwallet/R.java
@@ -1,140 +0,0 @@
-/* AUTO-GENERATED FILE. DO NOT MODIFY.
- *
- * This class was automatically generated by the
- * aapt tool from the resource data it found. It
- * should not be modified by hand.
- */
-
-package com.bitcoinwallet;
-
-public final class R {
- public static final class anim {
- public static final int rotate=0x7f040000;
- public static final int status_view_animation=0x7f040001;
- }
- public static final class attr {
- }
- public static final class color {
- public static final int contents_text=0x7f060000;
- public static final int encode_view=0x7f060001;
- public static final int help_button_view=0x7f060002;
- public static final int help_view=0x7f060003;
- public static final int possible_result_points=0x7f060004;
- public static final int result_image_border=0x7f060005;
- public static final int result_minor_text=0x7f060006;
- public static final int result_points=0x7f060007;
- public static final int result_text=0x7f060008;
- public static final int result_view=0x7f060009;
- public static final int sbc_header_text=0x7f06000a;
- public static final int sbc_header_view=0x7f06000b;
- public static final int sbc_layout_view=0x7f06000d;
- public static final int sbc_list_item=0x7f06000c;
- public static final int sbc_page_number_text=0x7f06000e;
- public static final int sbc_snippet_text=0x7f06000f;
- public static final int share_text=0x7f060010;
- public static final int share_view=0x7f060011;
- public static final int status_text=0x7f060013;
- public static final int status_view=0x7f060012;
- public static final int transparent=0x7f060014;
- public static final int viewfinder_frame=0x7f060015;
- public static final int viewfinder_laser=0x7f060016;
- public static final int viewfinder_mask=0x7f060017;
- }
- public static final class drawable {
- public static final int background=0x7f020000;
- public static final int ic_menu_refresh=0x7f020001;
- public static final int logo=0x7f020002;
- public static final int my_icon=0x7f020003;
- public static final int my_notification_icon=0x7f020004;
- }
- public static final class id {
- public static final int address=0x7f070020;
- public static final int amount=0x7f070029;
- /** Messages IDs
- */
- public static final int auto_focus=0x7f070000;
- public static final int balanceLabel=0x7f07001d;
- public static final int balanceTable=0x7f07001a;
- public static final int contents_text_view=0x7f070013;
- public static final int copy_button=0x7f070026;
- public static final int decode=0x7f070001;
- public static final int decode_failed=0x7f070002;
- public static final int decode_succeeded=0x7f070003;
- public static final int email_button=0x7f070025;
- public static final int encode_failed=0x7f070004;
- public static final int encode_succeeded=0x7f070005;
- public static final int encode_view=0x7f070011;
- public static final int header=0x7f070016;
- public static final int imageView1=0x7f070014;
- public static final int image_view=0x7f070012;
- public static final int launch_product_query=0x7f070006;
- public static final int linearLayout1=0x7f070017;
- public static final int linearLayout2=0x7f070024;
- public static final int manual_button=0x7f07000e;
- public static final int memo=0x7f07002b;
- public static final int preview_view=0x7f07000c;
- public static final int progressBar=0x7f070015;
- public static final int qr_code=0x7f070021;
- public static final int quit=0x7f070007;
- public static final int receive_amount=0x7f070023;
- public static final int receive_amount_label=0x7f070022;
- public static final int receive_button=0x7f070019;
- public static final int receive_money_layout=0x7f07001f;
- public static final int refresh_menu_item=0x7f07002d;
- public static final int relativeLayout1=0x7f070027;
- public static final int restart_preview=0x7f070008;
- public static final int return_scan_result=0x7f070009;
- public static final int search_book_contents_failed=0x7f07000a;
- public static final int search_book_contents_succeeded=0x7f07000b;
- public static final int send_button=0x7f070018;
- public static final int send_money_button=0x7f07002c;
- public static final int status_view=0x7f07000d;
- public static final int tableRow2=0x7f07001b;
- public static final int textView2=0x7f07001c;
- public static final int textView3=0x7f070028;
- public static final int textView4=0x7f07002a;
- public static final int toast_holder=0x7f070010;
- public static final int transactions=0x7f07001e;
- public static final int viewfinder_view=0x7f07000f;
- }
- public static final class layout {
- public static final int capture=0x7f030000;
- public static final int encode=0x7f030001;
- public static final int header=0x7f030002;
- public static final int main=0x7f030003;
- public static final int receive_money=0x7f030004;
- public static final int send_money=0x7f030005;
- }
- public static final class menu {
- public static final int main=0x7f0a0000;
- }
- public static final class raw {
- public static final int beep=0x7f050000;
- }
- public static final class string {
- public static final int address_label=0x7f080010;
- public static final int amount_label=0x7f08000f;
- public static final int amount_placeholder=0x7f080004;
- public static final int app_name=0x7f080000;
- public static final int balance_label=0x7f080003;
- public static final int blank_label=0x7f080008;
- public static final int contents_contact=0x7f08000a;
- public static final int contents_email=0x7f08000b;
- public static final int contents_location=0x7f08000c;
- public static final int contents_phone=0x7f08000d;
- public static final int contents_sms=0x7f08000e;
- public static final int contents_text=0x7f080009;
- public static final int manual_button_label=0x7f080007;
- public static final int memo_label=0x7f080011;
- public static final int msg_default_status=0x7f080006;
- public static final int receive_button=0x7f080002;
- public static final int scan_label=0x7f080005;
- public static final int send_button=0x7f080001;
- public static final int send_money_button=0x7f080012;
- }
- public static final class style {
- public static final int CustomTheme=0x7f090000;
- public static final int MainActivity=0x7f090001;
- public static final int Transaction=0x7f090002;
- }
-}
View
166 src/com/bitcoinwallet/ApplicationState.java
@@ -1,166 +0,0 @@
-package com.bitcoinwallet;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.InetSocketAddress;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-
-import org.apache.commons.io.IOUtils;
-
-import android.app.Application;
-import android.app.backup.BackupManager;
-import android.util.Log;
-
-import com.google.bitcoin.core.BlockChain;
-import com.google.bitcoin.core.BlockStore;
-import com.google.bitcoin.core.BlockStoreException;
-import com.google.bitcoin.core.BoundedOverheadBlockStore;
-import com.google.bitcoin.core.DnsDiscovery;
-import com.google.bitcoin.core.ECKey;
-import com.google.bitcoin.core.IrcDiscovery;
-import com.google.bitcoin.core.NetworkParameters;
-import com.google.bitcoin.core.Peer;
-import com.google.bitcoin.core.PeerDiscovery;
-import com.google.bitcoin.core.PeerDiscoveryException;
-import com.google.bitcoin.core.Sha256Hash;
-import com.google.bitcoin.core.Transaction;
-import com.google.bitcoin.core.Wallet;
-
-public class ApplicationState extends Application {
- // convenient place to keep global app variables
-
- boolean TEST_MODE = true;
- Wallet wallet;
- String filePrefix = TEST_MODE ? "testnet" : "prodnet";
-
- /**
- * Every access to walletFile must be synch'ed with this lock. Backup agent
- * can be run at any time.
- */
- static final Object[] walletFileLock = new Object[0];
- File walletFile;
- BackupManager backupManager;
-
- NetworkParameters params = TEST_MODE ? NetworkParameters.testNet()
- : NetworkParameters.prodNet();
- PeerDiscovery peerDiscovery;
- private ArrayList<InetSocketAddress> isas = new ArrayList<InetSocketAddress>();
- ArrayList<Peer> connectedPeers = new ArrayList<Peer>();
- BlockStore blockStore = null;
- BlockChain blockChain;
-
- //tracks which transactions we've shown a notification for so we couldn't duplicate them
- //could probably persist this between start/top of the app, but fine for now
- ArrayList<Sha256Hash> notifiedUserOfTheseTransactions = new ArrayList<Sha256Hash>();
-
- public static ApplicationState current;
-
- @Override
- public void onCreate() {
- Log.d("Wallet", "Starting app");
- ApplicationState.current = (ApplicationState) this;
- backupManager = new BackupManager(this);
-
-
- // read or create wallet
- synchronized (ApplicationState.walletFileLock) {
- walletFile = new File(getFilesDir(), filePrefix + ".wallet");
- try {
- wallet = Wallet.loadFromFile(walletFile);
- Log.d("Wallet", "Found wallet file to load");
- } catch (IOException e) {
- wallet = new Wallet(params);
- Log.d("Wallet", "Created new wallet");
- wallet.keychain.add(new ECKey());
- saveWallet();
- } catch (StackOverflowError e) {
- //couldn't unserialize the wallet - maybe it was saved in a previous version of bitcoinj?
- e.printStackTrace();
- }
- }
-
- if (TEST_MODE) {
- peerDiscovery = new IrcDiscovery("#bitcoinTEST");
- } else {
- peerDiscovery = new DnsDiscovery(params);
- }
-
- Log.d("Wallet", "Reading block store from disk");
- try {
- File file = new File(getExternalFilesDir(null), filePrefix
- + ".blockchain");
- if (!file.exists()) {
- Log.d("Wallet", "Copying initial blockchain from assets folder");
- try {
- InputStream is = getAssets().open(
- filePrefix + ".blockchain");
- IOUtils.copy(is, new FileOutputStream(file));
- } catch (IOException e) {
- Log.d("Wallet",
- "Couldn't find initial blockchain in assets folder...starting from scratch");
- }
- }
- blockStore = new BoundedOverheadBlockStore(params, file);
- blockChain = new BlockChain(params, wallet, blockStore);
- } catch (BlockStoreException bse) {
- throw new Error("Couldn't store block.");
- }
- }
-
- public void saveWallet() {
- synchronized (ApplicationState.walletFileLock) {
- Log.d("Wallet", "Saving wallet");
- try {
- wallet.saveToFile(walletFile);
- } catch (IOException e) {
- throw new Error("Can't save wallet file.");
- }
- }
- Log.d("Wallet", "Notifying BackupManager that data has changed. Should backup soon.");
- backupManager.dataChanged();
- }
-
- public synchronized void removeBadPeer(InetSocketAddress isa) {
- Log.d("Wallet", "removing bad peer");
- isas.remove(isa);
- }
-
- @SuppressWarnings("unchecked")
- public ArrayList<InetSocketAddress> discoverPeers() {
- if (isas.size() == 0) {
- try {
- isas.addAll(Arrays.asList(peerDiscovery.getPeers()));
- Collections.shuffle(isas); // try different order each time
- } catch (PeerDiscoveryException e) {
- Log.d("Wallet", "Couldn't discover peers.");
- }
- }
- Log.d("Wallet", "discoverPeers returning "+isas.size()+" peers");
- // shallow clone to prevent concurrent modification exceptions
- return (ArrayList<InetSocketAddress>) isas.clone();
- }
-
- /* rebroadcast pending transactions to all connected peers */
- public synchronized void sendTransaction(Transaction tx) {
- boolean success = false;
- for (Peer peer : connectedPeers) {
- try {
- peer.broadcastTransaction(tx);
- success = true;
- Log.d("Wallet", "Broadcast succeeded");
- } catch (IOException e) {
- peer.disconnect();
- connectedPeers.remove(peer);
- Log.d("Wallet", "Broadcast failed");
- }
- }
- if (success) {
- wallet.confirmSend(tx);
- saveWallet();
- }
- }
-}
View
253 src/com/bitcoinwallet/BitcoinWallet.java
@@ -1,253 +0,0 @@
-package com.bitcoinwallet;
-
-import java.math.BigInteger;
-import java.util.ArrayList;
-
-import android.app.Activity;
-import android.app.Notification;
-import android.app.NotificationManager;
-import android.app.PendingIntent;
-import android.app.ProgressDialog;
-import android.content.Context;
-import android.content.Intent;
-import android.graphics.Color;
-import android.os.Bundle;
-import android.os.Handler;
-import android.os.Message;
-import android.util.Log;
-import android.view.Gravity;
-import android.view.Menu;
-import android.view.MenuInflater;
-import android.view.MenuItem;
-import android.view.View;
-import android.view.ViewGroup.LayoutParams;
-import android.widget.Button;
-import android.widget.ProgressBar;
-import android.widget.TableLayout;
-import android.widget.TableRow;
-import android.widget.TextView;
-
-import com.google.bitcoin.core.Address;
-import com.google.bitcoin.core.ScriptException;
-import com.google.bitcoin.core.Transaction;
-import com.google.bitcoin.core.TransactionInput;
-import com.google.bitcoin.core.Utils;
-import com.google.bitcoin.core.Wallet;
-import com.google.bitcoin.core.Wallet.BalanceType;
-import com.google.bitcoin.core.WalletEventListener;
-import com.google.zxing.client.android.CaptureActivity;
-
-public class BitcoinWallet extends Activity {
-
- ProgressThread progressThread;
- ProgressDialog progressDialog;
- ApplicationState appState;
-
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- Button sendButton = (Button) this.findViewById(R.id.send_button);
- sendButton.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- startActivity(new Intent(BitcoinWallet.this, CaptureActivity.class));
- }
- });
-
- Button receiveButton = (Button) this.findViewById(R.id.receive_button);
- receiveButton.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- startActivity(new Intent(BitcoinWallet.this, ReceiveMoney.class));
- }
- });
-
- appState = ((ApplicationState) getApplication());
-
- updateUI();
- updateBlockChain();
-
- appState.wallet.addEventListener(new WalletEventListener() {
- public void onCoinsReceived(Wallet w, final Transaction tx, BigInteger prevBalance, BigInteger newBalance) {
- runOnUiThread(new Runnable() {
- public void run() {
- moneyReceived(tx);
- Log.d("Wallet", "COINS WE RECEIVED HAVE BEEN CONFIRMED");
- }
- });
- }
-
- public void onCoinsSent(Wallet w, final Transaction tx, BigInteger prevBalance, BigInteger newBalance) {
- runOnUiThread(new Runnable() {
- public void run() {
- updateUI();
- appState.saveWallet();
- Log.d("Wallet", "COINS WE SENT HAVE BEEN CONFIRMED");
- }
- });
- }
-
- public void onPendingCoinsReceived(Wallet w, final Transaction tx) {
- runOnUiThread(new Runnable() {
- public void run() {
- moneyReceived(tx);
- Log.d("Wallet", "PENDING COINS RECEIVED ");
- }
- });
- }
- });
- }
-
- private void updateBlockChain() {
- progressDialog = new ProgressDialog(BitcoinWallet.this);
- progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
- progressDialog.setMessage("Syncing with network...");
- progressDialog.setProgress(0);
-
- Handler handler = new Handler() {
- ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressBar);
-
- public void handleMessage(Message msg) {
- int total = msg.arg1;
- progressDialog.setProgress(total);
- if (total < 80) {
- // progressDialog.show();
- } else if (total < 100) {
- progressBar.setVisibility(View.VISIBLE);
- } else if (total >= 100) {
- progressDialog.hide();
- progressBar.setVisibility(View.GONE);
- updateUI();
- Log.d("Wallet", "Download complete");
- }
- }
- };
- ((ProgressBar) findViewById(R.id.progressBar)).setVisibility(View.VISIBLE);
-
- progressThread = new ProgressThread(handler);
- progressThread.start();
- }
-
- private void updateUI() {
- TextView balance = (TextView) findViewById(R.id.balanceLabel);
- balance.setText("BTC " + Utils.bitcoinValueToFriendlyString(appState.wallet.getBalance(BalanceType.ESTIMATED)));
-
- TableLayout tl = (TableLayout) findViewById(R.id.transactions);
- tl.removeAllViews();
-
- ArrayList<Transaction> transactions = appState.wallet.getAllTransactions();
-
- // Show only the first 100 transaction
- if (transactions.size() > 100)
- transactions = (ArrayList<Transaction>)transactions.subList(0, 99);
-
- for (Transaction tx : transactions) {
- addRowForTransaction(tl, tx);
- }
- }
-
- private void addRowForTransaction(TableLayout tl, Transaction tx) {
- // Create a new row to be added.
- TableRow tr = new TableRow(this);
- // Create a Button to be the row-content.
- TextView description = new TextView(this);
- TextView amount = new TextView(this);
- description.setTextSize(15);
- amount.setTextSize(15);
- String text = "";
-
- // check if pending
- if (appState.wallet.pending.containsKey(tx.getHash())) {
- text += "(Pending) ";
- description.setTextColor(Color.GRAY);
- amount.setTextColor(Color.GRAY);
- } else {
- description.setTextColor(Color.BLACK);
- amount.setTextColor(Color.BLACK);
- }
-
- // check if sent or received
- try {
- if (tx.sent(appState.wallet)) {
- text += "Sent to " + tx.outputs.get(0).getScriptPubKey().getToAddress();
- amount.setText("-" + Utils.bitcoinValueToFriendlyString(tx.amount(appState.wallet)));
- } else {
- text += "Received from " + tx.getInputs().get(0).getFromAddress();
- amount.setText("+" + Utils.bitcoinValueToFriendlyString(tx.amount(appState.wallet)));
- }
- } catch (ScriptException e) {
- // don't display this transaction
- return;
- }
- if (text.length() > 30) {
- text = text.substring(0, 29) + "...";
- }
- description.setText(text);
- description.setPadding(0, 3, 0, 3);
- amount.setPadding(0, 3, 0, 3);
- amount.setGravity(Gravity.RIGHT);
- tr.addView(description);
- tr.addView(amount);
- tl.addView(tr, new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
- }
-
- public boolean onCreateOptionsMenu(Menu menu) {
- MenuInflater inflater = getMenuInflater();
- inflater.inflate(R.menu.main, menu);
- return true;
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle item selection
- switch (item.getItemId()) {
- case R.id.refresh_menu_item:
- updateBlockChain();
- updateUI();
- return true;
- default:
- return super.onOptionsItemSelected(item);
- }
- }
-
- private void moneyReceived(Transaction tx) {
- appState.saveWallet();
- updateUI();
-
- if (appState.notifiedUserOfTheseTransactions.contains(tx.getHash())) {
- //only call once per transaction
- //this could be called multiple times by separate peers
- return;
- } else {
- appState.notifiedUserOfTheseTransactions.add(tx.getHash());
- }
-
- TransactionInput input = tx.getInputs().get(0);
- Address from;
- try {
- from = input.getFromAddress();
- } catch (ScriptException e) {
- return;
- }
- BigInteger value = tx.getValueSentToMe(appState.wallet);
- Log.d("Wallet", "Received " + Utils.bitcoinValueToFriendlyString(value) + " from " + from.toString());
-
- String ticker = Utils.bitcoinValueToFriendlyString(value) + " Bitcoins Received!";
- String ns = Context.NOTIFICATION_SERVICE;
- NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
- Notification notification = new Notification(R.drawable.my_notification_icon, ticker, System.currentTimeMillis());
- notification.defaults |= Notification.DEFAULT_SOUND;
- notification.defaults |= Notification.DEFAULT_VIBRATE;
- notification.flags |= Notification.FLAG_AUTO_CANCEL;
-
- Context context = getApplicationContext();
- CharSequence contentTitle = ticker;
- CharSequence contentText = "From " + from.toString();
- Intent notificationIntent = new Intent(this, BitcoinWallet.class);
- //don't open a new one if it's already on top
- notificationIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
- PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
- notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
- mNotificationManager.notify(1, notification);
- }
-}
View
201 src/com/bitcoinwallet/ProgressThread.java
@@ -1,201 +0,0 @@
-package com.bitcoinwallet;
-
-import java.net.InetSocketAddress;
-import java.util.ArrayList;
-import java.util.concurrent.Callable;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-
-import android.os.Handler;
-import android.os.Message;
-import android.util.Log;
-
-import com.google.bitcoin.core.NetworkConnection;
-import com.google.bitcoin.core.Peer;
-import com.google.bitcoin.core.Transaction;
-
-/* Thread to download the block chain.
- * It downloads from one peer at a time, but will cycle through if one dies or stops talking to us.
- * Once it finishes downloading the blockchain it will make sure we're connected to 8 nearby peers to
- * get new blocks and messages.
- */
-
-public class ProgressThread extends Thread {
- ApplicationState appState = ApplicationState.current;
-
- Peer peer;
- CountDownLatch progress;
- Handler mHandler;
- final static int STATE_DONE = 0;
- final static int STATE_RUNNING = 1;
- int mState;
- int total;
-
- public ProgressThread(Handler h) {
- mHandler = h;
- mState = STATE_RUNNING;
- }
-
- public void run() {
- downloadBlockChain();
- hideDialog();
- connectToLocalPeers();
- resendPendingTransactions();
- }
-
- private void downloadBlockChain() {
- Log.d("Wallet", "Downloading block chain");
- boolean done = false;
- while (!done) {
- ArrayList<InetSocketAddress> isas = appState.discoverPeers();
- if (isas.size() == 0) {
- // not connected to internet, could show a dialog to the user here?
- done = true;
- } else {
- for (InetSocketAddress isa : isas) {
- if (blockChainDownloadSuccessful(isa)) {
- done = true;
- break;
- } else {
- // remove and try next one
- appState.removeBadPeer(isa);
- }
- }
- }
- }
- hideDialog();
- }
-
- private boolean blockChainDownloadSuccessful(InetSocketAddress isa){
- NetworkConnection conn = createNetworkConnection(isa);
- if (conn == null)
- return false;
-
- long max;
- long current;
- long last_current = -1;
-
- Peer peer = new Peer(appState.params, conn, appState.blockChain, appState.wallet);
- peer.start();
- try {
- Log.d("Wallet", "Starting download from new peer");
- progress = peer.startBlockChainDownload();
- max = progress.getCount();
- current = max;
- int no_change_count = 0;
- while (true) {
- double pct = 100.0 - (100.0 * (current / (double) max));
- System.out.println(String.format("Chain download %d%% done", (int) pct));
- progress.await(1, TimeUnit.SECONDS);
- current = progress.getCount();
- if (last_current == -1)
- last_current = current;
- Log.d("Wallet", "no change count is "+no_change_count+" and current is "+current);
- if (current == 0) {
- // we're done!
- return true;
- } else if (current == last_current) {
- no_change_count++;
- // if peer stopped talking to us for 8 seconds, lets break out and try next one :(
- if (no_change_count >= 8)
- return false;
- } else {
- // we're making progress, keep going!
- last_current = current;
- no_change_count = 0;
- Message msg = mHandler.obtainMessage();
- msg.arg1 = (int) pct;
- mHandler.sendMessage(msg);
- }
- }
- } catch (Exception e) {
- // disconnect and try next peer
- Log.d("Wallet", "exception in ProgressThread downloadBlockChainSuccessful");
- e.printStackTrace();
- } finally {
- // always calls this even if we return above
- peer.disconnect();
- }
-
- return false;
- }
-
- /**
- * Wrapped "new NetworkConnection" in a giant executor service since it would sometimes never return, even with the connectTimeout param
- * Copied from http://stackoverflow.com/questions/1164301/how-do-i-call-some-blocking-method-with-a-timeout-in-java
- */
- private NetworkConnection createNetworkConnection(final InetSocketAddress isa) {
- ExecutorService executor = Executors.newCachedThreadPool();
- Callable<NetworkConnection> task = new Callable<NetworkConnection>() {
- public NetworkConnection call() {
- NetworkConnection conn = null;
- try {
- conn = new NetworkConnection(isa.getAddress(), appState.params, appState.blockStore.getChainHead().getHeight(), 5000);
- } catch (Exception e) {
- }
- return conn;
- }
- };
- Future<NetworkConnection> future = executor.submit(task);
- NetworkConnection result = null;
- try {
- result = future.get(10, TimeUnit.SECONDS);
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- future.cancel(true);
- }
- return result;
- }
-
- /* connect to local peers (minimum of 3, maximum of 8) */
- private void connectToLocalPeers(){
- Log.d("Wallet", "Connecting to local peers");
- //clear out any which have disconnected
- for (Peer peer : appState.connectedPeers) {
- if (!peer.isRunning())
- appState.connectedPeers.remove(peer);
- }
-
- if (appState.connectedPeers.size() < 3) {
- for (InetSocketAddress isa : appState.discoverPeers()) {
- NetworkConnection conn = createNetworkConnection(isa);
- if (conn == null) {
- appState.removeBadPeer(isa);
- } else {
- Peer peer = new Peer(appState.params, conn, appState.blockChain, appState.wallet);
- peer.start();
- appState.connectedPeers.add(peer);
- if (appState.connectedPeers.size() >= 8)
- break;
- }
- }
- }
- }
-
- private void resendPendingTransactions(){
- Log.d("Wallet", "Resending pendings transactions");
- for (Transaction tx : appState.wallet.pending.values()) {
- if (tx.sent(appState.wallet)) {
- Log.d("Wallet", "resending");
- appState.sendTransaction(tx);
- }
- }
- }
-
- private void hideDialog() {
- Message msg = mHandler.obtainMessage();
- msg.arg1 = 100;
- mHandler.sendMessage(msg);
- }
-
- /*
- * sets the current state for the thread, used to stop the thread
- */
- public void setState(int state) {
- mState = state;
- }
-}
View
151 src/com/bitcoinwallet/ReceiveMoney.java
@@ -1,151 +0,0 @@
-package com.bitcoinwallet;
-
-import android.app.Activity;
-import android.content.Intent;
-import android.graphics.Bitmap;
-import android.os.Bundle;
-import android.os.Handler;
-import android.os.Message;
-import android.text.ClipboardManager;
-import android.text.Editable;
-import android.text.TextWatcher;
-import android.view.Display;
-import android.view.View;
-import android.view.WindowManager;
-import android.widget.Button;
-import android.widget.EditText;
-import android.widget.ImageView;
-import android.widget.TextView;
-import android.widget.Toast;
-
-import com.google.bitcoin.core.Address;
-import com.google.bitcoin.core.ECKey;
-import com.google.zxing.BarcodeFormat;
-import com.google.zxing.client.android.Contents;
-import com.google.zxing.client.android.Intents;
-import com.google.zxing.client.android.encode.QRCodeEncoder;
-
-public class ReceiveMoney extends Activity {
-
- private QRCodeEncoder qrCodeEncoder;
- int dimension;
- Address address;
- String amount;
- EditText amountField;
- TextView amountLabel;
- ApplicationState appState;
-
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.receive_money);
-
- appState = (ApplicationState) getApplication();
-
- // prevent keyboard from opening
- getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
-
- dimension = getScreenWidth() * 7 / 8;
-
- ECKey key = appState.wallet.keychain.get(0);
- address = key.toAddress(appState.params);
- TextView addressField = (TextView) findViewById(R.id.address);
- addressField.setText(address.toString());
-
- generateQRCode(generateBitCoinURI());
-
- amountField = (EditText) findViewById(R.id.receive_amount);
- amountField.setWidth(dimension);
- amountLabel = (TextView) findViewById(R.id.receive_amount_label);
- amountLabel.setWidth(dimension);
- amountField.addTextChangedListener(new TextWatcher() {
- public void afterTextChanged(Editable s) {
- if (amount != s.toString()) {
- amount = s.toString();
- generateQRCode(generateBitCoinURI());
- }
- }
-
- public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
- // do nothing
- }
-
- public void onTextChanged(CharSequence s, int start, int before, int count) {
- // do nothing
- }
- });
-
- Button emailButton = (Button) this.findViewById(R.id.email_button);
- emailButton.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
- emailIntent.setType("text/plain");
- emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Payment Request From: " + address);
- String message = "Hello,\n\nYou've received a bitcoin payment request. Please send funds to the following address.";
- message += "\n\nAddress: " + address;
- if (amount != null && amount != "") {
- message += "\nAmount: " + amount + " BTC";
- }
- message += "\n\nThank you!";
-
- emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
- ReceiveMoney.this.startActivity(Intent.createChooser(emailIntent, "Send Request Via..."));
- }
- });
-
- Button copyButton = (Button) this.findViewById(R.id.copy_button);
- copyButton.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
- clipboard.setText(address.toString());
- Toast.makeText(ReceiveMoney.this, "Copied address to clipboard!", Toast.LENGTH_SHORT).show();
- }
- });
- }
-
- private int getScreenWidth() {
- Display display = getWindowManager().getDefaultDisplay();
- return display.getWidth();
- }
-
- private String generateBitCoinURI() {
- String uri = "bitcoin:";
- uri += address.toString() + "?";
- if (amount != null && amount.length() > 0) {
- uri += "amount=" + amount;
- }
- return uri;
- }
-
- private void generateQRCode(String data) {
- Intent intent = new Intent(Intents.Encode.ACTION);
- intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
- intent.putExtra(Intents.Encode.TYPE, Contents.Type.TEXT);
- intent.putExtra(Intents.Encode.DATA, data);
- intent.putExtra(Intents.Encode.FORMAT, BarcodeFormat.QR_CODE.toString());
-
- qrCodeEncoder = new QRCodeEncoder(ReceiveMoney.this, intent);
- qrCodeEncoder.requestBarcode(handler, dimension);
- }
-
- private final Handler handler = new Handler() {
- @Override
- public void handleMessage(Message message) {
- switch (message.what) {
- case R.id.encode_succeeded:
- Bitmap image = (Bitmap) message.obj;
- ImageView view = (ImageView) findViewById(R.id.qr_code);
- view.setImageBitmap(image);
- // TextView contents = (TextView)
- // findViewById(R.id.contents_text_view);
- // contents.setText(qrCodeEncoder.getDisplayContents());
- break;
- case R.id.encode_failed:
- Toast.makeText(ReceiveMoney.this, "QR generation failed", Toast.LENGTH_LONG).show();
- qrCodeEncoder = null;
- break;
- }
- }
- };
-}
View
142 src/com/bitcoinwallet/SendMoney.java
@@ -1,142 +0,0 @@
-package com.bitcoinwallet;
-
-import java.math.BigInteger;
-import java.net.URLDecoder;
-
-import android.app.Activity;
-import android.app.AlertDialog;
-import android.content.DialogInterface;
-import android.content.Intent;
-import android.os.Bundle;
-import android.util.Log;
-import android.view.View;
-import android.widget.Button;
-import android.widget.EditText;
-
-import com.google.bitcoin.core.Address;
-import com.google.bitcoin.core.AddressFormatException;
-import com.google.bitcoin.core.Transaction;
-import com.google.bitcoin.core.Utils;
-
-public class SendMoney extends Activity {
-
- EditText addressField;
- EditText amountField;
- EditText memoField;
-
- Address address;
- BigInteger amount;
-
- /** Called when the activity is first created */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.send_money);
-
- Bundle b = getIntent().getExtras();
- addressField = (EditText) findViewById(R.id.address);
- amountField = (EditText) findViewById(R.id.amount);
- memoField = (EditText) findViewById(R.id.memo);
-
- if (b == null) {
- addressField.requestFocus();
- } else {
- if (b.getString("address") != null) {
- addressField.setText(b.getString("address"));
- }
- if (b.getString("amount") != null) {
- String amount = b.getString("amount");
- if (amount.toLowerCase().endsWith("x8")) {
- amount = amount.toLowerCase().replace("x8", "");
- }
- amountField.setText(amount);
- }
- if (b.getString("label") != null) {
- memoField.setText(URLDecoder.decode(b.getString("label")) + " ");
- }
- if (b.getString("message") != null) {
- memoField.setText(memoField.getText() + URLDecoder.decode(b.getString("message")));
- }
- if (b.getString("memo") != null) {
- memoField.setText(memoField.getText() + URLDecoder.decode(b.getString("memo")));
- }
- memoField.setText(memoField.getText().toString().trim());
- }
-
- if (addressField.getText().toString() == "") {
- addressField.requestFocus();
- } else {
- amountField.requestFocus();
- }
-
- Button sendButton = (Button) this.findViewById(R.id.send_money_button);
- sendButton.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- Transaction sendTx = null;
- ApplicationState appState = ApplicationState.current;
-
- try {
- address = new Address(appState.params, addressField.getText().toString());
- amount = Utils.toNanoCoins(amountField.getText().toString());
- sendTx = appState.wallet.createSend(address, amount);
-
- if (sendTx != null) {
- appState.sendTransaction(sendTx);
- Log.d("Wallet", "Sent " + Utils.bitcoinValueToFriendlyString(amount) + " to " + address.toString());
-
- AlertDialog.Builder builder = new AlertDialog.Builder(SendMoney.this);
- builder.setMessage("Payment successful!").setCancelable(false).setNegativeButton("Ok", new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
- dialog.cancel();
- startActivity(new Intent(SendMoney.this, BitcoinWallet.class));
- }
- });
- AlertDialog alert = builder.create();
- alert.show();
- } else {
- AlertDialog.Builder builder = new AlertDialog.Builder(SendMoney.this);
- String msg = "You're payment exceeds your current balance. \n\n";
- if (appState.wallet.getPendingTransactions().size() > 0){
- msg += " Please wait for your pending transactions to be confirmed, or add additional funds to your wallet using the 'Receive Money' button on the home screen.";
- } else {
- msg += " Try funding your bitcoin wallet by using the 'Receive Money' button on the home screen.";
- }
- builder.setMessage(msg)
- .setCancelable(false).setNegativeButton("Ok", new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
- dialog.cancel();
- startActivity(new Intent(SendMoney.this, BitcoinWallet.class));
- }
- });
- AlertDialog alert = builder.create();
- alert.show();
- }
- } catch (AddressFormatException e) {
- e.printStackTrace();
- AlertDialog.Builder builder = new AlertDialog.Builder(SendMoney.this);
- builder.setMessage("Inalid address, please try again.").setCancelable(false).setNegativeButton("Ok", new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
- dialog.cancel();
- }
- });
- AlertDialog alert = builder.create();
- alert.show();
- } catch (Exception e) {
- e.printStackTrace();
- AlertDialog.Builder builder = new AlertDialog.Builder(SendMoney.this);
- builder.setMessage("Sorry we couldn't send that. Please check your values and try again.").setCancelable(false)
- .setNegativeButton("Ok", new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
- dialog.cancel();
- }
- });
- AlertDialog alert = builder.create();
- alert.show();
- }
-
- }
- });
-
- }
-
-}
View
61 src/com/bitcoinwallet/WalletBackupAgent.java
@@ -1,61 +0,0 @@
-/**
- *
- */
-package com.bitcoinwallet;
-
-import java.io.IOException;
-import java.math.BigInteger;
-
-import android.app.backup.BackupAgentHelper;
-import android.app.backup.BackupDataInput;
-import android.app.backup.BackupDataOutput;
-import android.app.backup.FileBackupHelper;
-import android.os.ParcelFileDescriptor;
-import android.util.Log;
-
-/**
- * @author Brandon To request a backup, call dataChanged() To request a restore,
- * call requestRestore()
- */
-public class WalletBackupAgent extends BackupAgentHelper {
- static final String FILES_BACKUP_KEY = "wallet_files";
-
- @Override
- public void onCreate() {
- FileBackupHelper helper = new FileBackupHelper(this,
- ApplicationState.current.walletFile.getName());
- addHelper(FILES_BACKUP_KEY, helper);
- }
-
- @Override
- public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
- ParcelFileDescriptor newState) throws IOException {
- // Hold the lock while the FileBackupHelper performs backup
- synchronized (ApplicationState.walletFileLock) {
- // Right now, we only keep one backup file in the cloud. The
- // "authoritative" file is the one on the phone. So we don't do any
- // checking to see what we're replacing in the cloud backup.
- Log.d("Wallet", "Backing up wallet file to cloud.");
- super.onBackup(oldState, data, newState);
- }
- }
-
- @Override
- public void onRestore(BackupDataInput data, int appVersionCode,
- ParcelFileDescriptor newState) throws IOException {
- // Hold the lock while the FileBackupHelper restores the file
- synchronized (ApplicationState.walletFileLock) {
- // Ensure that the wallet on the phone has zero balance.
- // We don't want to over-write a wallet file on the phone that has
- // BTC in it.
- if (ApplicationState.current.wallet.getBalance().compareTo(
- BigInteger.ZERO) > 0) {
- Log.d("Wallet",
- "Wallet on phone has a balance. Skipping restore.");
- return;
- }
- Log.d("Wallet", "Restoring wallet file from backup.");
- super.onRestore(data, appVersionCode, newState);
- }
- }
-}
View
4 src/com/google/zxing/client/android/CaptureActivity.java
@@ -49,8 +49,8 @@
import android.widget.TextView;
import android.widget.Toast;
-import com.bitcoinwallet.R;
-import com.bitcoinwallet.SendMoney;
+import com.bitcoinandroid.R;
+import com.bitcoinandroid.SendMoney;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.Result;
import com.google.zxing.ResultMetadataType;
View
2  src/com/google/zxing/client/android/CaptureActivityHandler.java
@@ -16,7 +16,7 @@
package com.google.zxing.client.android;
-import com.bitcoinwallet.R;
+import com.bitcoinandroid.R;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.Result;
import com.google.zxing.client.android.camera.CameraManager;
View
2  src/com/google/zxing/client/android/DecodeHandler.java
@@ -16,7 +16,7 @@
package com.google.zxing.client.android;
-import com.bitcoinwallet.R;
+import com.bitcoinandroid.R;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.DecodeHintType;
import com.google.zxing.MultiFormatReader;
View
2  src/com/google/zxing/client/android/ViewfinderView.java
@@ -16,7 +16,7 @@
package com.google.zxing.client.android;
-import com.bitcoinwallet.R;
+import com.bitcoinandroid.R;
import com.google.zxing.ResultPoint;
import com.google.zxing.client.android.camera.CameraManager;
View
2  src/com/google/zxing/client/android/encode/EncodeActivity.java
@@ -28,7 +28,7 @@
import android.widget.ImageView;
import android.widget.TextView;
-import com.bitcoinwallet.R;
+import com.bitcoinandroid.R;
import com.google.zxing.client.android.FinishListener;
import com.google.zxing.client.android.Intents;
View
2  src/com/google/zxing/client/android/encode/EncodeThread.java
@@ -22,7 +22,7 @@
import android.util.Log;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.WriterException;
-import com.bitcoinwallet.R;
+import com.bitcoinandroid.R;
final class EncodeThread extends Thread {
View
2  src/com/google/zxing/client/android/encode/QRCodeEncoder.java
@@ -30,7 +30,7 @@
import android.telephony.PhoneNumberUtils;
import android.util.Log;
-import com.bitcoinwallet.R;
+import com.bitcoinandroid.R;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
Please sign in to comment.
Something went wrong with that request. Please try again.