Android Open Source - My-Wallet-Android Pair Wallet Activity






From Project

Back to project page My-Wallet-Android.

License

The source code is released under:

GNU General Public License

If you think the Android project My-Wallet-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package piuk.blockchain.android.ui;
/* w w  w  .j  a  v a 2  s  .c o m*/
import java.util.regex.Pattern;

import piuk.blockchain.R;
import piuk.blockchain.android.Constants;
import piuk.blockchain.android.WalletApplication;
import piuk.blockchain.android.util.ActionBarFragment;
import android.content.Intent;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class PairWalletActivity extends AbstractWalletActivity {
  private static final int REQUEST_CODE_SCAN = 0;

  @Override
  protected void onCreate(final Bundle savedInstanceState)
  {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.pair_wallet_content);

    final ActionBarFragment actionBar = getActionBar();

    actionBar.setPrimaryTitle(R.string.pair_wallet_title);

    //showQRReader();  

    actionBar.setBack(new OnClickListener()
    {
      public void onClick(final View v)
      {
        finish();
      }
    });

    final Button pairDeviceButton = (Button) getWindow().findViewById(R.id.pair_qr_button);

    pairDeviceButton.setOnClickListener(new OnClickListener() {
      public void onClick(View v) {  
        showQRReader();
      }
    });
  }



  @Override
  public void onActivityResult(final int requestCode, final int resultCode, final Intent intent)
  {
    if (requestCode == REQUEST_CODE_SCAN && resultCode == RESULT_OK && "QR_CODE".equals(intent.getStringExtra("SCAN_RESULT_FORMAT")))
    {
      final WalletApplication application = (WalletApplication) getApplication();

      try {
        final String contents = intent.getStringExtra("SCAN_RESULT");

        String[] components = contents.split("\\|", Pattern.LITERAL);

        System.out.println(components.length);

        if (components.length < 3 || contents.length() < 36+36+3) {
          errorDialog(R.string.error_pairing_wallet, "Invalid Pairing QR Code");
          return;
        }

        String guid = contents.substring(0, 36);
        String sharedKey = contents.substring(37, 73);
        String password = contents.substring(74, contents.length());

        if (guid == null || guid.length() == 0) {
          errorDialog(R.string.error_pairing_wallet, "Invalid GUID");
          return;
        }

        if (sharedKey == null || sharedKey.length() == 0) {
          errorDialog(R.string.error_pairing_wallet, "Invalid sharedKey");
          return;
        }

        if (password == null || password.length() < 10) {
          errorDialog(R.string.error_pairing_wallet, "Password must be greater than 10 characters in length");
          return;
        }

        Editor edit = PreferenceManager.getDefaultSharedPreferences(this).edit();

        edit.putString("guid", guid);
        edit.putString("sharedKey", sharedKey);
        edit.putString("password", password);

        if (edit.commit()) {
            application.loadRemoteWallet();
        } else {
          errorDialog(R.string.error_pairing_wallet, "Error saving preferences");
        }

      } catch (Exception e) {
        errorDialog(R.string.error_pairing_wallet, "Unknown Exception caught. Please submit a bug report");

        e.printStackTrace();

        application.writeException(e);
      }
    }

    finish();
  }
  public void showQRReader() {
    if (getPackageManager().resolveActivity(Constants.INTENT_QR_SCANNER, 0) != null)
    {
      startActivityForResult(Constants.INTENT_QR_SCANNER, REQUEST_CODE_SCAN);
    }
    else
    {
      showMarketPage(Constants.PACKAGE_NAME_ZXING);
      longToast(R.string.send_coins_install_qr_scanner_msg);
    }
  }
}




Java Source Code List

piuk.BitcoinAddress.java
piuk.BitcoinScript.java
piuk.Hash.java
piuk.MyBlockChain.java
piuk.MyRemoteWallet.java
piuk.MyTransactionConfidence.java
piuk.MyTransactionInput.java
piuk.MyTransactionOutPoint.java
piuk.MyTransactionOutput.java
piuk.MyTransaction.java
piuk.MyWallet.java
piuk.blockchain.android.AddressBookProvider.java
piuk.blockchain.android.BlockchainService.java
piuk.blockchain.android.Constants.java
piuk.blockchain.android.DetermineFirstSeenThread.java
piuk.blockchain.android.ExchangeRatesProvider.java
piuk.blockchain.android.WalletApplication.java
piuk.blockchain.android.WalletBalanceWidgetProvider.java
piuk.blockchain.android.ui.AbstractWalletActivity.java
piuk.blockchain.android.ui.AmountCalculatorFragment.java
piuk.blockchain.android.ui.CurrencyAmountView.java
piuk.blockchain.android.ui.CurrencyCodeDrawable.java
piuk.blockchain.android.ui.EditAddressBookEntryFragment.java
piuk.blockchain.android.ui.ExchangeRatesFragment.java
piuk.blockchain.android.ui.NewAccountFragment.java
piuk.blockchain.android.ui.PairWalletActivity.java
piuk.blockchain.android.ui.PreferencesActivity.java
piuk.blockchain.android.ui.RequestCoinsActivity.java
piuk.blockchain.android.ui.RequestCoinsFragment.java
piuk.blockchain.android.ui.SecondPasswordFragment.java
piuk.blockchain.android.ui.SendCoinsActivity.java
piuk.blockchain.android.ui.SendCoinsFragment.java
piuk.blockchain.android.ui.SendingAddressesFragment.java
piuk.blockchain.android.ui.TransactionActivity.java
piuk.blockchain.android.ui.TransactionFragment.java
piuk.blockchain.android.ui.WalletActivity.java
piuk.blockchain.android.ui.WalletAddressesFragment.java
piuk.blockchain.android.ui.WalletBalanceFragment.java
piuk.blockchain.android.ui.WalletTransactionsFragment.java
piuk.blockchain.android.ui.WelcomeFragment.java
piuk.blockchain.android.util.ActionBarFragment.java
piuk.blockchain.android.util.Base43.java
piuk.blockchain.android.util.CircularProgressView.java
piuk.blockchain.android.util.ErrorReporter.java
piuk.blockchain.android.util.IOUtils.java
piuk.blockchain.android.util.Iso8601Format.java
piuk.blockchain.android.util.NfcTools.java
piuk.blockchain.android.util.QrDialog.java
piuk.blockchain.android.util.ViewPagerTabs.java
piuk.blockchain.android.util.WalletUtils.java