Android Open Source - neoscoin-wallet Transaction Fragment






From Project

Back to project page neoscoin-wallet.

License

The source code is released under:

GNU General Public License

If you think the Android project neoscoin-wallet 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

/*
 * Copyright 2011-2013 the original author or authors.
 */* w  w w.j a v  a  2 s . co  m*/
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package de.schildbach.wallet.ui;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Typeface;
import android.os.Bundle;
import android.text.format.DateUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.actionbarsherlock.app.SherlockFragment;
import com.google.bitcoin.core.*;
import de.schildbach.wallet.AddressBookProvider;
import de.schildbach.wallet.Constants;
import de.schildbach.wallet.WalletApplication;
import de.schildbach.wallet.util.*;
import katastrophos.neoscoin.wallet.R;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.math.BigInteger;
import java.text.DateFormat;
import java.util.Date;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.zip.GZIPOutputStream;

/**
 * @author Andreas Schildbach, Litecoin Dev Team
 */

public final class TransactionFragment extends SherlockFragment
{
  public static final String FRAGMENT_TAG = TransactionFragment.class.getName();

  private static final int SHOW_QR_THRESHOLD_BYTES = 2500;

  private AbstractWalletActivity activity;

  private AbstractClipboardManager clipboardManager;

  private DateFormat dateFormat;
  private DateFormat timeFormat;

  @Override
    @SuppressWarnings("deprecation")
  public void onAttach(final Activity activity)
  {
    super.onAttach(activity);

    this.activity = (AbstractWalletActivity) activity;

    dateFormat = android.text.format.DateFormat.getDateFormat(activity);
    timeFormat = android.text.format.DateFormat.getTimeFormat(activity);
    clipboardManager = new AbstractClipboardManager(getActivity());
  }

  @Override
  public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState)
  {
    return inflater.inflate(R.layout.transaction_fragment, null);
  }

  public void update(final Transaction tx)
  {
    final Wallet wallet = ((WalletApplication) activity.getApplication()).getWallet();

    final byte[] serializedTx = tx.unsafeBitcoinSerialize();

    Address from = null;
    boolean fromMine = false;
    try
    {
      from = tx.getInputs().get(0).getFromAddress();
      fromMine = wallet.isPubKeyHashMine(from.getHash160());
    }
    catch (final ScriptException x)
    {
      x.printStackTrace();
    }

    Address to = null;
    boolean toMine = false;
    try
    {
      to = tx.getOutputs().get(0).getScriptPubKey().getToAddress(Constants.NETWORK_PARAMETERS);
      toMine = wallet.isPubKeyHashMine(to.getHash160());
    }
    catch (final ScriptException x)
    {
      x.printStackTrace();
    }

    final View view = getView();

    final Date time = tx.getUpdateTime();
    view.findViewById(R.id.transaction_fragment_time_row).setVisibility(time != null ? View.VISIBLE : View.GONE);
    if (time != null)
    {
      final TextView viewDate = (TextView) view.findViewById(R.id.transaction_fragment_time);
      viewDate.setText((DateUtils.isToday(time.getTime()) ? getString(R.string.time_today) : dateFormat.format(time)) + ", "
          + timeFormat.format(time));
    }

    try
    {
      final BigInteger amountSent = tx.getValueSentFromMe(wallet);
      view.findViewById(R.id.transaction_fragment_amount_sent_row).setVisibility(amountSent.signum() != 0 ? View.VISIBLE : View.GONE);
      if (amountSent.signum() != 0)
      {
        final TextView viewAmountSent = (TextView) view.findViewById(R.id.transaction_fragment_amount_sent);
        viewAmountSent.setText(Constants.CURRENCY_MINUS_SIGN + GenericUtils.formatValue(amountSent, Constants.BTC_MAX_PRECISION, 0));
      }
    }
    catch (final ScriptException x)
    {
      x.printStackTrace();
    }

    final BigInteger amountReceived = tx.getValueSentToMe(wallet);
    view.findViewById(R.id.transaction_fragment_amount_received_row).setVisibility(amountReceived.signum() != 0 ? View.VISIBLE : View.GONE);
    if (amountReceived.signum() != 0)
    {
      final TextView viewAmountReceived = (TextView) view.findViewById(R.id.transaction_fragment_amount_received);
      viewAmountReceived.setText(Constants.CURRENCY_PLUS_SIGN + GenericUtils.formatValue(amountReceived, Constants.BTC_MAX_PRECISION, 0));
    }

    final View viewFromButton = view.findViewById(R.id.transaction_fragment_from_button);
    final TextView viewFromLabel = (TextView) view.findViewById(R.id.transaction_fragment_from_label);
    if (from != null)
    {
      final String label = AddressBookProvider.resolveLabel(activity, from.toString());
      final StringBuilder builder = new StringBuilder();

      if (fromMine)
        builder.append(getString(R.string.transaction_fragment_you)).append(", ");

      if (label != null)
      {
        builder.append(label);
      }
      else
      {
        builder.append(from.toString());
        viewFromLabel.setTypeface(Typeface.MONOSPACE);
      }

      viewFromLabel.setText(builder.toString());

      final String addressStr = from.toString();
      viewFromButton.setOnClickListener(new OnClickListener()
      {
        public void onClick(final View v)
        {
          EditAddressBookEntryFragment.edit(getFragmentManager(), addressStr);
        }
      });
    }
    else
    {
      viewFromLabel.setText(null);
    }

    final View viewToButton = view.findViewById(R.id.transaction_fragment_to_button);
    final TextView viewToLabel = (TextView) view.findViewById(R.id.transaction_fragment_to_label);
    if (to != null)
    {
      final String label = AddressBookProvider.resolveLabel(activity, to.toString());
      final StringBuilder builder = new StringBuilder();

      if (toMine)
        builder.append(getString(R.string.transaction_fragment_you)).append(", ");

      if (label != null)
      {
        builder.append(label);
      }
      else
      {
        builder.append(to.toString());
        viewToLabel.setTypeface(Typeface.MONOSPACE);
      }

      viewToLabel.setText(builder.toString());

      final String addressStr = to.toString();
      viewToButton.setOnClickListener(new OnClickListener()
      {
        public void onClick(final View v)
        {
          EditAddressBookEntryFragment.edit(getFragmentManager(), addressStr);
        }
      });
    }
    else
    {
      viewToLabel.setText(null);
    }

    final TextView viewStatus = (TextView) view.findViewById(R.id.transaction_fragment_status);
        final TransactionConfidence confidence = tx.getConfidence();
        final TransactionConfidence.ConfidenceType confidenceType = confidence.getConfidenceType();
    if (confidenceType == TransactionConfidence.ConfidenceType.DEAD)
      viewStatus.setText(R.string.transaction_fragment_status_dead);
    else if (confidenceType == TransactionConfidence.ConfidenceType.PENDING)
      viewStatus.setText(R.string.transaction_fragment_status_pending);
    else if (confidenceType == TransactionConfidence.ConfidenceType.BUILDING)
      viewStatus.setText(R.string.transaction_fragment_status_confirmed);
    else
      viewStatus.setText(R.string.transaction_fragment_status_unknown);

        final TextView viewConfirmations = (TextView)view.findViewById(R.id.transaction_fragment_confirmations);
        viewConfirmations.setText(String.valueOf(confidence.getDepthInBlocks()));

    final TextView viewHash = (TextView) view.findViewById(R.id.transaction_fragment_hash);
    final View viewHashButton = view.findViewById(R.id.transaction_fragment_hash_button);
    final String txHashString = tx.getHash().toString();
    viewHash.setText(txHashString);
    viewHashButton.setOnClickListener(new OnClickListener()
    {
      public void onClick(final View v)
      {
        clipboardManager.setText("transaction", txHashString);
        activity.toast(R.string.transaction_fragment_hash_clipboard_msg);
      }
    });

    final TextView viewLength = (TextView) view.findViewById(R.id.transaction_fragment_length);
    viewLength.setText(Integer.toString(serializedTx.length));

    final ImageView viewQr = (ImageView) view.findViewById(R.id.transaction_fragment_qr);
    if (serializedTx.length < SHOW_QR_THRESHOLD_BYTES)
    {
      viewQr.setVisibility(View.VISIBLE);

      try
      {
        // encode transaction URI
        final ByteArrayOutputStream bos = new ByteArrayOutputStream(serializedTx.length);
        final GZIPOutputStream gos = new GZIPOutputStream(bos);
        gos.write(serializedTx);
        gos.close();

        final byte[] gzippedSerializedTx = bos.toByteArray();
        final boolean useCompressioon = gzippedSerializedTx.length < serializedTx.length;

        final StringBuilder txStr = new StringBuilder("ltctx:");
        txStr.append(useCompressioon ? 'Z' : '-');
        txStr.append(Base43.encode(useCompressioon ? gzippedSerializedTx : serializedTx));
        final Bitmap qrCodeBitmap = Qr.bitmap(txStr.toString().toUpperCase(Locale.US), 512);
        viewQr.setImageBitmap(qrCodeBitmap);
        viewQr.setOnClickListener(new OnClickListener()
        {
          public void onClick(final View v)
          {
            BitmapFragment.show(getFragmentManager(), qrCodeBitmap);
          }
        });
      }
      catch (final IOException x)
      {
        throw new RuntimeException(x);
      }
    }
    else
    {
      viewQr.setVisibility(View.GONE);
    }
  }
}




Java Source Code List

de.schildbach.wallet.AddressBookProvider.java
de.schildbach.wallet.Configuration.java
de.schildbach.wallet.Constants.java
de.schildbach.wallet.ExchangeRatesProvider.java
de.schildbach.wallet.PaymentIntent.java
de.schildbach.wallet.WalletApplication.java
de.schildbach.wallet.WalletBalanceWidgetProvider.java
de.schildbach.wallet.camera.CameraManager.java
de.schildbach.wallet.integration.android.BitcoinIntegration.java
de.schildbach.wallet.integration.sample.SampleActivity.java
de.schildbach.wallet.offline.AcceptBluetoothService.java
de.schildbach.wallet.offline.AcceptBluetoothThread.java
de.schildbach.wallet.offline.DirectPaymentTask.java
de.schildbach.wallet.service.AutosyncReceiver.java
de.schildbach.wallet.service.BlockchainServiceImpl.java
de.schildbach.wallet.service.BlockchainService.java
de.schildbach.wallet.ui.AboutActivity.java
de.schildbach.wallet.ui.AbstractBindServiceActivity.java
de.schildbach.wallet.ui.AbstractOnDemandServiceActivity.java
de.schildbach.wallet.ui.AbstractWalletActivity.java
de.schildbach.wallet.ui.AddressAndLabel.java
de.schildbach.wallet.ui.AddressBookActivity.java
de.schildbach.wallet.ui.BlockListFragment.java
de.schildbach.wallet.ui.CurrencyAmountView.java
de.schildbach.wallet.ui.CurrencyCalculatorLink.java
de.schildbach.wallet.ui.CurrencySymbolDrawable.java
de.schildbach.wallet.ui.CurrencyTextView.java
de.schildbach.wallet.ui.DialogBuilder.java
de.schildbach.wallet.ui.EditAddressBookEntryFragment.java
de.schildbach.wallet.ui.ExchangeRateLoader.java
de.schildbach.wallet.ui.ExchangeRatesActivity.java
de.schildbach.wallet.ui.ExchangeRatesFragment.java
de.schildbach.wallet.ui.FileAdapter.java
de.schildbach.wallet.ui.HelpDialogFragment.java
de.schildbach.wallet.ui.ImportDialogButtonEnablerListener.java
de.schildbach.wallet.ui.ImportKeysActivity.java
de.schildbach.wallet.ui.InputParser.java
de.schildbach.wallet.ui.NetworkMonitorActivity.java
de.schildbach.wallet.ui.PeerListFragment.java
de.schildbach.wallet.ui.PreferencesActivity.java
de.schildbach.wallet.ui.ProgressDialogFragment.java
de.schildbach.wallet.ui.ReportIssueDialogBuilder.java
de.schildbach.wallet.ui.RequestCoinsActivity.java
de.schildbach.wallet.ui.RequestCoinsFragment.java
de.schildbach.wallet.ui.RequestPaymentRequestTask.java
de.schildbach.wallet.ui.ScanActivity.java
de.schildbach.wallet.ui.ScannerView.java
de.schildbach.wallet.ui.SendCoinsActivity.java
de.schildbach.wallet.ui.SendCoinsFragment.java
de.schildbach.wallet.ui.SendCoinsOfflineTask.java
de.schildbach.wallet.ui.SendCoinsQrActivity.java
de.schildbach.wallet.ui.SendingAddressesFragment.java
de.schildbach.wallet.ui.ShowPasswordCheckListener.java
de.schildbach.wallet.ui.TransactionActivity.java
de.schildbach.wallet.ui.TransactionFragment.java
de.schildbach.wallet.ui.TransactionsListAdapter.java
de.schildbach.wallet.ui.TransactionsListFragment.java
de.schildbach.wallet.ui.WalletActionsFragment.java
de.schildbach.wallet.ui.WalletActivity.java
de.schildbach.wallet.ui.WalletAddressFragment.java
de.schildbach.wallet.ui.WalletAddressesAdapter.java
de.schildbach.wallet.ui.WalletAddressesFragment.java
de.schildbach.wallet.ui.WalletBalanceFragment.java
de.schildbach.wallet.ui.WalletBalanceLoader.java
de.schildbach.wallet.ui.WalletDisclaimerFragment.java
de.schildbach.wallet.ui.WalletTransactionsFragment.java
de.schildbach.wallet.util.AbstractClipboardManager.java
de.schildbach.wallet.util.Base43.java
de.schildbach.wallet.util.BitmapFragment.java
de.schildbach.wallet.util.Bluetooth.java
de.schildbach.wallet.util.CircularProgressView.java
de.schildbach.wallet.util.CrashReporter.java
de.schildbach.wallet.util.Crypto.java
de.schildbach.wallet.util.GenericUtils.java
de.schildbach.wallet.util.HttpGetThread.java
de.schildbach.wallet.util.Io.java
de.schildbach.wallet.util.Iso8601Format.java
de.schildbach.wallet.util.LinuxSecureRandom.java
de.schildbach.wallet.util.Nfc.java
de.schildbach.wallet.util.PaymentProtocol.java
de.schildbach.wallet.util.Qr.java
de.schildbach.wallet.util.ThrottlingWalletChangeListener.java
de.schildbach.wallet.util.ViewPagerTabs.java
de.schildbach.wallet.util.WalletUtils.java