Example usage for android.text.format DateUtils isToday

List of usage examples for android.text.format DateUtils isToday

Introduction

In this page you can find the example usage for android.text.format DateUtils isToday.

Prototype

public static boolean isToday(long when) 

Source Link

Usage

From source file:com.guldencoin.androidwallet.nlg.ui.TransactionsListFragment.java

private void handleTransactionClick(@Nonnull final Transaction tx) {
    activity.startActionMode(new ActionMode.Callback() {
        private Address address;
        private byte[] serializedTx;

        private static final int SHOW_QR_THRESHOLD_BYTES = 2500;

        @Override//from ww w. j a  v  a2  s.  c  o m
        public boolean onCreateActionMode(final ActionMode mode, final Menu menu) {
            final MenuInflater inflater = mode.getMenuInflater();
            inflater.inflate(R.menu.wallet_transactions_context, menu);

            return true;
        }

        @Override
        public boolean onPrepareActionMode(final ActionMode mode, final Menu menu) {
            try {
                final Date time = tx.getUpdateTime();
                final DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(activity);
                final DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(activity);

                mode.setTitle(time != null ? (DateUtils.isToday(time.getTime()) ? getString(R.string.time_today)
                        : dateFormat.format(time)) + ", " + timeFormat.format(time) : null);

                final BigInteger value = tx.getValue(wallet);
                final boolean sent = value.signum() < 0;

                address = sent ? WalletUtils.getFirstToAddress(tx) : WalletUtils.getFirstFromAddress(tx);

                final String label;
                if (tx.isCoinBase())
                    label = getString(R.string.wallet_transactions_fragment_coinbase);
                else if (address != null)
                    label = AddressBookProvider.resolveLabel(activity, address.toString());
                else
                    label = "?";

                final String prefix = getString(sent ? R.string.symbol_to : R.string.symbol_from) + " ";

                if (tx.getPurpose() != Purpose.KEY_ROTATION)
                    mode.setSubtitle(label != null ? prefix + label
                            : WalletUtils.formatAddress(prefix, address, Constants.ADDRESS_FORMAT_GROUP_SIZE,
                                    Constants.ADDRESS_FORMAT_LINE_SIZE));
                else
                    mode.setSubtitle(null);

                menu.findItem(R.id.wallet_transactions_context_edit_address).setVisible(address != null);

                serializedTx = tx.unsafeBitcoinSerialize();

                menu.findItem(R.id.wallet_transactions_context_show_qr)
                        .setVisible(serializedTx.length < SHOW_QR_THRESHOLD_BYTES);

                Nfc.publishMimeObject(nfcManager, activity, Constants.MIMETYPE_TRANSACTION, serializedTx,
                        false);

                return true;
            } catch (final ScriptException x) {
                return false;
            }
        }

        @Override
        public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) {
            switch (item.getItemId()) {
            case R.id.wallet_transactions_context_edit_address:
                handleEditAddress(tx);

                mode.finish();
                return true;

            case R.id.wallet_transactions_context_show_qr:
                handleShowQr();

                mode.finish();
                return true;

            case R.id.wallet_transactions_context_browse:
                startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse(Constants.EXPLORE_BASE_URL + "tx/" + tx.getHashAsString())));

                mode.finish();
                return true;
            }
            return false;
        }

        @Override
        public void onDestroyActionMode(final ActionMode mode) {
            Nfc.unpublish(nfcManager, activity);
        }

        private void handleEditAddress(@Nonnull final Transaction tx) {
            EditAddressBookEntryFragment.edit(getFragmentManager(), address.toString());
        }

        private void handleShowQr() {
            final int size = (int) (384 * getResources().getDisplayMetrics().density);
            final Bitmap qrCodeBitmap = Qr.bitmap(Qr.encodeCompressBinary(serializedTx), size);
            BitmapFragment.show(getFragmentManager(), qrCodeBitmap);
        }
    });
}

From source file:com.markupartist.sthlmtraveling.utils.DateTimeUtil.java

public static CharSequence routeToTimeDisplay(Context context, Route route) {
    java.text.DateFormat format = android.text.format.DateFormat.getTimeFormat(context);
    BidiFormatter bidiFormatter = BidiFormatter.getInstance(RtlUtils.isRtl(Locale.getDefault()));

    Pair<Date, RealTimeState> departsAt = route.departsAt(true);
    Pair<Date, RealTimeState> arrivesAt = route.arrivesAt(true);

    String departsAtStr = format.format(departsAt.first);
    String arrivesAtStr = format.format(arrivesAt.first);
    CharSequence displayTime;/*from   w w w  . jav a  2  s . c  om*/
    if (!DateUtils.isToday(departsAt.first.getTime())) {
        displayTime = String.format("%s %s  %s",
                bidiFormatter.unicodeWrap(DateUtils.getRelativeTimeSpanString(departsAt.first.getTime(),
                        System.currentTimeMillis(), DateUtils.DAY_IN_MILLIS).toString()),
                bidiFormatter.unicodeWrap(departsAtStr), bidiFormatter.unicodeWrap(arrivesAtStr));
    } else {
        displayTime = String.format("%s  %s", bidiFormatter.unicodeWrap(departsAtStr),
                bidiFormatter.unicodeWrap(arrivesAtStr));
    }

    ForegroundColorSpan spanDepartsAt = new ForegroundColorSpan(
            ContextCompat.getColor(context, ViewHelper.getTextColorByRealtimeState(departsAt.second)));
    Pattern patternDepartsAt = Pattern.compile(departsAtStr);
    displayTime = SpanUtils.createSpannable(displayTime, patternDepartsAt, spanDepartsAt);

    ForegroundColorSpan spanArrivessAt = new ForegroundColorSpan(
            ContextCompat.getColor(context, ViewHelper.getTextColorByRealtimeState(arrivesAt.second)));
    Pattern patternArrivesAt = Pattern.compile(arrivesAtStr);
    displayTime = SpanUtils.createSpannable(displayTime, patternArrivesAt, spanArrivessAt);

    return displayTime;
}

From source file:cc.mintcoin.wallet.ui.TransactionsListFragment.java

private void handleTransactionClick(@Nonnull final Transaction tx) {
    activity.startActionMode(new ActionMode.Callback() {
        private Address address;
        private byte[] serializedTx;

        private static final int SHOW_QR_THRESHOLD_BYTES = 2500;

        @Override//from   w  w w.  ja va2 s . c om
        public boolean onCreateActionMode(final ActionMode mode, final Menu menu) {
            final MenuInflater inflater = mode.getMenuInflater();
            inflater.inflate(R.menu.wallet_transactions_context, menu);

            return true;
        }

        @Override
        public boolean onPrepareActionMode(final ActionMode mode, final Menu menu) {
            try {
                final Date time = tx.getUpdateTime();
                final DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(activity);
                final DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(activity);

                mode.setTitle(time != null
                        ? (DateUtils.isToday(time.getTime()) ? activity.getString(R.string.time_today)
                                : dateFormat.format(time)) + ", " + timeFormat.format(time)
                        : null);

                final BigInteger value = tx.getValue(wallet);
                final boolean sent = value.signum() < 0;

                address = sent ? WalletUtils.getFirstToAddress(tx) : WalletUtils.getFirstFromAddress(tx);

                final String label;
                if (tx.isCoinBase())
                    label = activity.getString(R.string.wallet_transactions_fragment_coinbase);
                else if (address != null)
                    label = AddressBookProvider.resolveLabel(activity, address.toString());
                else
                    label = "?";

                final String prefix = activity.getString(sent ? R.string.symbol_to : R.string.symbol_from)
                        + " ";

                if (tx.getPurpose() != Purpose.KEY_ROTATION)
                    mode.setSubtitle(label != null ? prefix + label
                            : WalletUtils.formatAddress(prefix, address, Constants.ADDRESS_FORMAT_GROUP_SIZE,
                                    Constants.ADDRESS_FORMAT_LINE_SIZE));
                else
                    mode.setSubtitle(null);

                menu.findItem(R.id.wallet_transactions_context_edit_address).setVisible(address != null);

                serializedTx = tx.unsafeBitcoinSerialize();

                menu.findItem(R.id.wallet_transactions_context_show_qr)
                        .setVisible(serializedTx.length < SHOW_QR_THRESHOLD_BYTES);

                Nfc.publishMimeObject(nfcManager, activity, Constants.MIMETYPE_TRANSACTION, serializedTx,
                        false);

                return true;
            } catch (final ScriptException x) {
                return false;
            }
        }

        @Override
        public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) {
            switch (item.getItemId()) {
            case R.id.wallet_transactions_context_edit_address:
                handleEditAddress(tx);

                mode.finish();
                return true;

            case R.id.wallet_transactions_context_show_qr:
                handleShowQr();

                mode.finish();
                return true;

            case R.id.wallet_transactions_context_open_blockexplorer:
                startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse(Constants.BLOCKEXPLORER_BASE_URL + "tx/" + tx.getHashAsString())));

                mode.finish();
                return true;
            }
            return false;
        }

        @Override
        public void onDestroyActionMode(final ActionMode mode) {
            try {
                Nfc.unpublish(nfcManager, activity);
            } catch (IllegalStateException ise) {
                // Swallow. Activity is probably paused currently. No need to unpublish.
            }
        }

        private void handleEditAddress(@Nonnull final Transaction tx) {
            EditAddressBookEntryFragment.edit(getFragmentManager(), address.toString());
        }

        private void handleShowQr() {
            final int size = (int) (384 * getResources().getDisplayMetrics().density);
            final Bitmap qrCodeBitmap = Qr.bitmap(Qr.encodeCompressBinary(serializedTx), size);
            BitmapFragment.show(getFragmentManager(), qrCodeBitmap);
        }
    });
}

From source file:com.hamradiocoin.wallet.ui.TransactionsListFragment.java

private void handleTransactionClick(@Nonnull final Transaction tx) {
    activity.startActionMode(new ActionMode.Callback() {
        private Address address;
        private byte[] serializedTx;

        private static final int SHOW_QR_THRESHOLD_BYTES = 2500;

        @Override/*ww w .j a  v a 2s  .c o  m*/
        public boolean onCreateActionMode(final ActionMode mode, final Menu menu) {
            final MenuInflater inflater = mode.getMenuInflater();
            inflater.inflate(R.menu.wallet_transactions_context, menu);

            return true;
        }

        @Override
        public boolean onPrepareActionMode(final ActionMode mode, final Menu menu) {
            try {
                final Date time = tx.getUpdateTime();
                final DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(activity);
                final DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(activity);

                mode.setTitle(time != null ? (DateUtils.isToday(time.getTime()) ? getString(R.string.time_today)
                        : dateFormat.format(time)) + ", " + timeFormat.format(time) : null);

                final BigInteger value = tx.getValue(wallet);
                final boolean sent = value.signum() < 0;

                address = sent ? WalletUtils.getFirstToAddress(tx) : WalletUtils.getFirstFromAddress(tx);

                final String label;
                if (tx.isCoinBase())
                    label = getString(R.string.wallet_transactions_fragment_coinbase);
                else if (address != null)
                    label = AddressBookProvider.resolveLabel(activity, address.toString());
                else
                    label = "?";

                final String prefix = getString(sent ? R.string.symbol_to : R.string.symbol_from) + " ";

                if (tx.getPurpose() != Purpose.KEY_ROTATION)
                    mode.setSubtitle(label != null ? prefix + label
                            : WalletUtils.formatAddress(prefix, address, Constants.ADDRESS_FORMAT_GROUP_SIZE,
                                    Constants.ADDRESS_FORMAT_LINE_SIZE));
                else
                    mode.setSubtitle(null);

                menu.findItem(R.id.wallet_transactions_context_edit_address).setVisible(address != null);

                serializedTx = tx.unsafeBitcoinSerialize();

                menu.findItem(R.id.wallet_transactions_context_show_qr)
                        .setVisible(serializedTx.length < SHOW_QR_THRESHOLD_BYTES);

                Nfc.publishMimeObject(nfcManager, activity, Constants.MIMETYPE_TRANSACTION, serializedTx);

                return true;
            } catch (final ScriptException x) {
                return false;
            }
        }

        @Override
        public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) {
            switch (item.getItemId()) {
            case R.id.wallet_transactions_context_edit_address:
                handleEditAddress(tx);

                mode.finish();
                return true;

            case R.id.wallet_transactions_context_show_qr:
                handleShowQr();

                mode.finish();
                return true;

            case R.id.wallet_transactions_context_browse:
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.EXPLORE_BASE_URL
                        + Constants.EXPLORE_TRANSACTION_PATH + tx.getHashAsString())));

                mode.finish();
                return true;
            case R.id.wallet_transactions_context_show_transaction:
                TransactionActivity.show(activity, tx);
            }
            return false;
        }

        @Override
        public void onDestroyActionMode(final ActionMode mode) {
            Nfc.unpublish(nfcManager, activity);
        }

        private void handleEditAddress(@Nonnull final Transaction tx) {
            EditAddressBookEntryFragment.edit(getFragmentManager(), address.toString());
        }

        private void handleShowQr() {
            final int size = (int) (384 * getResources().getDisplayMetrics().density);
            final Bitmap qrCodeBitmap = Qr.bitmap(Qr.encodeCompressBinary(serializedTx), size);
            BitmapFragment.show(getFragmentManager(), qrCodeBitmap);
        }
    });
}

From source file:com.cannabiscoin.wallet.ui.TransactionsListFragment.java

private void handleTransactionClick(@Nonnull final Transaction tx) {
    activity.startActionMode(new ActionMode.Callback() {
        private Address address;
        private byte[] serializedTx;

        private static final int SHOW_QR_THRESHOLD_BYTES = 2500;

        @Override/*www . jav  a2  s  . c  o m*/
        public boolean onCreateActionMode(final ActionMode mode, final Menu menu) {
            final MenuInflater inflater = mode.getMenuInflater();
            inflater.inflate(R.menu.wallet_transactions_context, menu);

            return true;
        }

        @Override
        public boolean onPrepareActionMode(final ActionMode mode, final Menu menu) {
            try {
                final Date time = tx.getUpdateTime();
                final DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(activity);
                final DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(activity);

                mode.setTitle(time != null ? (DateUtils.isToday(time.getTime()) ? getString(R.string.time_today)
                        : dateFormat.format(time)) + ", " + timeFormat.format(time) : null);

                final BigInteger value = tx.getValue(wallet);
                final boolean sent = value.signum() < 0;

                address = sent ? WalletUtils.getFirstToAddress(tx) : WalletUtils.getFirstFromAddress(tx);

                final String label;
                if (tx.isCoinBase())
                    label = getString(R.string.wallet_transactions_fragment_coinbase);
                else if (address != null)
                    label = AddressBookProvider.resolveLabel(activity, address.toString());
                else
                    label = "?";

                final String prefix = getString(sent ? R.string.symbol_to : R.string.symbol_from) + " ";

                if (tx.getPurpose() != Purpose.KEY_ROTATION)
                    mode.setSubtitle(label != null ? prefix + label
                            : WalletUtils.formatAddress(prefix, address, Constants.ADDRESS_FORMAT_GROUP_SIZE,
                                    Constants.ADDRESS_FORMAT_LINE_SIZE));
                else
                    mode.setSubtitle(null);

                menu.findItem(R.id.wallet_transactions_context_edit_address).setVisible(address != null);

                serializedTx = tx.unsafeBitcoinSerialize();

                menu.findItem(R.id.wallet_transactions_context_show_qr)
                        .setVisible(serializedTx.length < SHOW_QR_THRESHOLD_BYTES);

                Nfc.publishMimeObject(nfcManager, activity, Constants.MIMETYPE_TRANSACTION, serializedTx,
                        false);

                return true;
            } catch (final ScriptException x) {
                return false;
            }
        }

        @Override
        public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) {
            switch (item.getItemId()) {
            case R.id.wallet_transactions_context_edit_address:
                handleEditAddress(tx);

                mode.finish();
                return true;

            case R.id.wallet_transactions_context_show_qr:
                handleShowQr();

                mode.finish();
                return true;

            case R.id.wallet_transactions_context_browse:
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.EXPLORE_BASE_URL
                        + Constants.EXPLORE_TRANSACTION_PATH + tx.getHashAsString())));

                mode.finish();
                return true;
            case R.id.wallet_transactions_context_show_transaction:
                TransactionActivity.show(activity, tx);
            }
            return false;
        }

        @Override
        public void onDestroyActionMode(final ActionMode mode) {
            Nfc.unpublish(nfcManager, activity);
        }

        private void handleEditAddress(@Nonnull final Transaction tx) {
            EditAddressBookEntryFragment.edit(getFragmentManager(), address.toString());
        }

        private void handleShowQr() {
            final int size = (int) (384 * getResources().getDisplayMetrics().density);
            final Bitmap qrCodeBitmap = Qr.bitmap(Qr.encodeCompressBinary(serializedTx), size);
            BitmapFragment.show(getFragmentManager(), qrCodeBitmap);
        }
    });
}

From source file:com.rimbit.android_wallet.ui.TransactionsListFragment.java

private void handleTransactionClick(@Nonnull final Transaction tx) {
    activity.startActionMode(new ActionMode.Callback() {
        private Address address;
        private byte[] serializedTx;

        private static final int SHOW_QR_THRESHOLD_BYTES = 2500;

        @Override//from w w w . ja  v a 2s .com
        public boolean onCreateActionMode(final ActionMode mode, final Menu menu) {
            final MenuInflater inflater = mode.getMenuInflater();
            inflater.inflate(R.menu.wallet_transactions_context, menu);

            return true;
        }

        @Override
        public boolean onPrepareActionMode(final ActionMode mode, final Menu menu) {
            try {
                final Date time = tx.getUpdateTime();
                final DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(activity);
                final DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(activity);

                mode.setTitle(time != null ? (DateUtils.isToday(time.getTime()) ? getString(R.string.time_today)
                        : dateFormat.format(time)) + ", " + timeFormat.format(time) : null);

                final BigInteger value = tx.getValue(wallet);
                final boolean sent = value.signum() < 0;

                address = sent ? WalletUtils.getFirstToAddress(tx) : WalletUtils.getFirstFromAddress(tx);

                final String label;
                if (tx.isCoinBase())
                    label = getString(R.string.wallet_transactions_fragment_coinbase);
                else if (address != null)
                    label = AddressBookProvider.resolveLabel(activity, address.toString());
                else
                    label = "?";

                final String prefix = getString(sent ? R.string.symbol_to : R.string.symbol_from) + " ";

                if (tx.getPurpose() != Purpose.KEY_ROTATION)
                    mode.setSubtitle(label != null ? prefix + label
                            : WalletUtils.formatAddress(prefix, address, Constants.ADDRESS_FORMAT_GROUP_SIZE,
                                    Constants.ADDRESS_FORMAT_LINE_SIZE));
                else
                    mode.setSubtitle(null);

                menu.findItem(R.id.wallet_transactions_context_edit_address).setVisible(address != null);

                serializedTx = tx.unsafeRimbitSerialize();

                menu.findItem(R.id.wallet_transactions_context_show_qr)
                        .setVisible(serializedTx.length < SHOW_QR_THRESHOLD_BYTES);

                Nfc.publishMimeObject(nfcManager, activity, Constants.MIMETYPE_TRANSACTION, serializedTx);

                return true;
            } catch (final ScriptException x) {
                return false;
            }
        }

        @Override
        public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) {
            switch (item.getItemId()) {
            case R.id.wallet_transactions_context_edit_address:
                handleEditAddress(tx);

                mode.finish();
                return true;

            case R.id.wallet_transactions_context_show_qr:
                handleShowQr();

                mode.finish();
                return true;

            case R.id.wallet_transactions_context_browse:
                startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse(Constants.EXPLORE_BASE_URL + "tx/" + tx.getHashAsString())));

                mode.finish();
                return true;
            }
            return false;
        }

        @Override
        public void onDestroyActionMode(final ActionMode mode) {
            Nfc.unpublish(nfcManager, activity);
        }

        private void handleEditAddress(@Nonnull final Transaction tx) {
            EditAddressBookEntryFragment.edit(getFragmentManager(), address.toString());
        }

        private void handleShowQr() {
            final int size = (int) (384 * getResources().getDisplayMetrics().density);
            final Bitmap qrCodeBitmap = Qr.bitmap(Qr.encodeCompressBinary(serializedTx), size);
            BitmapFragment.show(getFragmentManager(), qrCodeBitmap);
        }
    });
}

From source file:com.matthewmitchell.peercoin_android_wallet.ui.TransactionsListFragment.java

private void handleTransactionClick(@Nonnull final Transaction tx) {
    activity.startActionMode(new ActionMode.Callback() {
        private Address address;
        private byte[] serializedTx;

        private static final int SHOW_QR_THRESHOLD_BYTES = 2500;

        @Override/*from   w w  w. j a  v  a 2 s.com*/
        public boolean onCreateActionMode(final ActionMode mode, final Menu menu) {
            final MenuInflater inflater = mode.getMenuInflater();
            inflater.inflate(R.menu.wallet_transactions_context, menu);

            return true;
        }

        @Override
        public boolean onPrepareActionMode(final ActionMode mode, final Menu menu) {
            try {
                final Date time = tx.getUpdateTime();
                final DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(activity);
                final DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(activity);

                mode.setTitle(time != null ? (DateUtils.isToday(time.getTime()) ? getString(R.string.time_today)
                        : dateFormat.format(time)) + ", " + timeFormat.format(time) : null);

                final Coin value = tx.getValue(wallet);
                final boolean sent = value.signum() < 0;

                address = sent ? WalletUtils.getWalletAddressOfReceived(tx, wallet)
                        : WalletUtils.getFirstFromAddress(tx);

                final String label;
                if (tx.isCoinBase())
                    label = getString(R.string.wallet_transactions_fragment_coinbase);
                else if (address != null)
                    label = AddressBookProvider.resolveLabel(activity, address.toString());
                else
                    label = "?";

                final String prefix = getString(sent ? R.string.symbol_to : R.string.symbol_from) + " ";

                if (tx.getPurpose() != Purpose.KEY_ROTATION)
                    mode.setSubtitle(label != null ? prefix + label
                            : WalletUtils.formatAddress(prefix, address, Constants.ADDRESS_FORMAT_GROUP_SIZE,
                                    Constants.ADDRESS_FORMAT_LINE_SIZE));
                else
                    mode.setSubtitle(null);

                menu.findItem(R.id.wallet_transactions_context_edit_address).setVisible(address != null);

                serializedTx = tx.unsafePeercoinSerialize();

                menu.findItem(R.id.wallet_transactions_context_show_qr)
                        .setVisible(serializedTx.length < SHOW_QR_THRESHOLD_BYTES);

                return true;
            } catch (final ScriptException x) {
                return false;
            }
        }

        @Override
        public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) {
            switch (item.getItemId()) {
            case R.id.wallet_transactions_context_edit_address:
                handleEditAddress(tx);

                mode.finish();
                return true;

            case R.id.wallet_transactions_context_show_qr:
                handleShowQr();

                mode.finish();
                return true;

            case R.id.wallet_transactions_context_browse:
                startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse(Constants.EXPLORE_BASE_URL + "tx/" + tx.getHashAsString())));

                mode.finish();
                return true;
            }
            return false;
        }

        @Override
        public void onDestroyActionMode(final ActionMode mode) {
        }

        private void handleEditAddress(@Nonnull final Transaction tx) {
            EditAddressBookEntryFragment.edit(getFragmentManager(), address.toString());
        }

        private void handleShowQr() {
            final int size = getResources().getDimensionPixelSize(R.dimen.bitmap_dialog_qr_size);
            final Bitmap qrCodeBitmap = Qr.bitmap(Qr.encodeCompressBinary(serializedTx), size);
            BitmapFragment.show(getFragmentManager(), qrCodeBitmap);
        }
    });
}

From source file:com.kncwallet.wallet.ui.TransactionsListFragment.java

private void handleTransactionClick(@Nonnull final Transaction tx) {
    activity.startActionMode(new ActionMode.Callback() {
        private Address address;
        private byte[] serializedTx;

        private static final int SHOW_QR_THRESHOLD_BYTES = 2500;

        @Override/*w w  w . j a va  2 s  .c  o  m*/
        public boolean onCreateActionMode(final ActionMode mode, final Menu menu) {
            final MenuInflater inflater = mode.getMenuInflater();
            inflater.inflate(R.menu.wallet_transactions_context, menu);

            return true;
        }

        @Override
        public boolean onPrepareActionMode(final ActionMode mode, final Menu menu) {
            try {
                final Date time = tx.getUpdateTime();
                final DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(activity);
                final DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(activity);

                mode.setTitle(time != null ? (DateUtils.isToday(time.getTime()) ? getString(R.string.time_today)
                        : dateFormat.format(time)) + ", " + timeFormat.format(time) : null);

                final BigInteger value = tx.getValue(wallet);
                final boolean sent = value.signum() < 0;

                address = sent ? WalletUtils.getFirstToAddress(tx) : WalletUtils.getFirstFromAddress(tx);

                final String label;
                if (tx.isCoinBase())
                    label = getString(R.string.wallet_transactions_fragment_coinbase);
                else if (address != null)
                    label = AddressBookProvider.resolveLabel(activity, address.toString());
                else
                    label = "?";

                final String prefix = getString(sent ? R.string.symbol_to : R.string.symbol_from) + " ";

                if (tx.getPurpose() != Purpose.KEY_ROTATION)
                    mode.setSubtitle(label != null ? prefix + label
                            : WalletUtils.formatAddress(prefix, address, Constants.ADDRESS_FORMAT_GROUP_SIZE,
                                    Constants.ADDRESS_FORMAT_LINE_SIZE));
                else
                    mode.setSubtitle(null);

                MenuItem editIcon = menu.findItem(R.id.wallet_transactions_context_edit_address);
                editIcon.setVisible(address != null);

                if (address != null) {
                    if (label != null) {
                        //edit icon only if no number
                        String number = AddressBookProvider.resolveRawTelephone(activity, address.toString());
                        editIcon.setVisible(true);

                        if (number == null || number.equals("")) {
                            editIcon.setIcon(R.drawable.ic_action_edit);
                        } else {
                            editIcon.setVisible(false);
                        }
                    } else {
                        //this is an add
                        editIcon.setIcon(R.drawable.ic_action_new_label);
                        editIcon.setVisible(true);
                    }
                }

                serializedTx = tx.unsafeBitcoinSerialize();

                menu.findItem(R.id.wallet_transactions_context_show_qr)
                        .setVisible(serializedTx.length < SHOW_QR_THRESHOLD_BYTES);

                Nfc.publishMimeObject(nfcManager, activity, Constants.MIMETYPE_TRANSACTION, serializedTx,
                        false);

                return true;
            } catch (final ScriptException x) {
                return false;
            }
        }

        @Override
        public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) {
            switch (item.getItemId()) {
            case R.id.wallet_transactions_context_edit_address:
                handleEditAddress(tx);

                mode.finish();
                return true;

            case R.id.wallet_transactions_context_show_qr:
                handleShowQr();

                mode.finish();
                return true;

            case R.id.wallet_transactions_context_browse:
                startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse(Constants.EXPLORE_BASE_URL + "tx/" + tx.getHashAsString())));

                mode.finish();
                return true;
            }
            return false;
        }

        @Override
        public void onDestroyActionMode(final ActionMode mode) {
            Nfc.unpublish(nfcManager, activity);
        }

        private void handleEditAddress(@Nonnull final Transaction tx) {
            EditAddressBookEntryFragment.edit(getFragmentManager(), address.toString());
        }

        private void handleShowQr() {
            final int size = (int) (384 * getResources().getDisplayMetrics().density);
            final Bitmap qrCodeBitmap = Qr.bitmap(Qr.encodeBinary(serializedTx), size);
            BitmapFragment.show(getFragmentManager(), qrCodeBitmap);
        }
    });
}

From source file:com.bushstar.kobocoin_android_wallet.ui.TransactionsListFragment.java

private void handleTransactionClick(@Nonnull final Transaction tx) {
    activity.startActionMode(new ActionMode.Callback() {
        private Address address;
        private byte[] serializedTx;

        private static final int SHOW_QR_THRESHOLD_BYTES = 2500;

        @Override/*from   w ww.  jav  a 2  s  .c o  m*/
        public boolean onCreateActionMode(final ActionMode mode, final Menu menu) {
            final MenuInflater inflater = mode.getMenuInflater();
            inflater.inflate(R.menu.wallet_transactions_context, menu);

            return true;
        }

        @Override
        public boolean onPrepareActionMode(final ActionMode mode, final Menu menu) {
            try {
                final Date time = tx.getUpdateTime();
                final DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(activity);
                final DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(activity);

                mode.setTitle(time != null ? (DateUtils.isToday(time.getTime()) ? getString(R.string.time_today)
                        : dateFormat.format(time)) + ", " + timeFormat.format(time) : null);

                final BigInteger value = tx.getValue(wallet);
                final boolean sent = value.signum() < 0;

                address = sent ? WalletUtils.getFirstToAddress(tx) : WalletUtils.getFirstFromAddress(tx);

                final String label;
                if (tx.isCoinBase())
                    label = getString(R.string.wallet_transactions_fragment_coinbase);
                else if (address != null)
                    label = AddressBookProvider.resolveLabel(activity, address.toString());
                else
                    label = "?";

                final String prefix = getString(sent ? R.string.symbol_to : R.string.symbol_from) + " ";

                if (tx.getPurpose() != Purpose.KEY_ROTATION)
                    mode.setSubtitle(label != null ? prefix + label
                            : WalletUtils.formatAddress(prefix, address, Constants.ADDRESS_FORMAT_GROUP_SIZE,
                                    Constants.ADDRESS_FORMAT_LINE_SIZE));
                else
                    mode.setSubtitle(null);

                menu.findItem(R.id.wallet_transactions_context_edit_address).setVisible(address != null);

                serializedTx = tx.unsafeKobocoinSerialize();

                menu.findItem(R.id.wallet_transactions_context_show_qr)
                        .setVisible(serializedTx.length < SHOW_QR_THRESHOLD_BYTES);

                Nfc.publishMimeObject(nfcManager, activity, Constants.MIMETYPE_TRANSACTION, serializedTx);

                return true;
            } catch (final ScriptException x) {
                return false;
            }
        }

        @Override
        public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) {
            switch (item.getItemId()) {
            case R.id.wallet_transactions_context_edit_address:
                handleEditAddress(tx);

                mode.finish();
                return true;

            case R.id.wallet_transactions_context_show_qr:
                handleShowQr();

                mode.finish();
                return true;

            case R.id.wallet_transactions_context_browse:
                startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse(Constants.EXPLORE_BASE_URL + "tx/" + tx.getHashAsString())));

                mode.finish();
                return true;
            }
            return false;
        }

        @Override
        public void onDestroyActionMode(final ActionMode mode) {
            Nfc.unpublish(nfcManager, activity);
        }

        private void handleEditAddress(@Nonnull final Transaction tx) {
            EditAddressBookEntryFragment.edit(getFragmentManager(), address.toString());
        }

        private void handleShowQr() {
            final int size = (int) (384 * getResources().getDisplayMetrics().density);
            final Bitmap qrCodeBitmap = Qr.bitmap(Qr.encodeCompressBinary(serializedTx), size);
            BitmapFragment.show(getFragmentManager(), qrCodeBitmap);
        }
    });
}

From source file:com.bushstar.htmlcoin_android_wallet.ui.TransactionsListFragment.java

private void handleTransactionClick(@Nonnull final Transaction tx) {
    activity.startActionMode(new ActionMode.Callback() {
        private Address address;
        private byte[] serializedTx;

        private static final int SHOW_QR_THRESHOLD_BYTES = 2500;

        @Override/*from  w  w  w  .  java 2  s  . c o  m*/
        public boolean onCreateActionMode(final ActionMode mode, final Menu menu) {
            final MenuInflater inflater = mode.getMenuInflater();
            inflater.inflate(R.menu.wallet_transactions_context, menu);

            return true;
        }

        @Override
        public boolean onPrepareActionMode(final ActionMode mode, final Menu menu) {
            try {
                final Date time = tx.getUpdateTime();
                final DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(activity);
                final DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(activity);

                mode.setTitle(time != null ? (DateUtils.isToday(time.getTime()) ? getString(R.string.time_today)
                        : dateFormat.format(time)) + ", " + timeFormat.format(time) : null);

                final BigInteger value = tx.getValue(wallet);
                final boolean sent = value.signum() < 0;

                address = sent ? WalletUtils.getFirstToAddress(tx) : WalletUtils.getFirstFromAddress(tx);

                final String label;
                if (tx.isCoinBase())
                    label = getString(R.string.wallet_transactions_fragment_coinbase);
                else if (address != null)
                    label = AddressBookProvider.resolveLabel(activity, address.toString());
                else
                    label = "?";

                final String prefix = getString(sent ? R.string.symbol_to : R.string.symbol_from) + " ";

                if (tx.getPurpose() != Purpose.KEY_ROTATION)
                    mode.setSubtitle(label != null ? prefix + label
                            : WalletUtils.formatAddress(prefix, address, Constants.ADDRESS_FORMAT_GROUP_SIZE,
                                    Constants.ADDRESS_FORMAT_LINE_SIZE));
                else
                    mode.setSubtitle(null);

                menu.findItem(R.id.wallet_transactions_context_edit_address).setVisible(address != null);

                serializedTx = tx.unsafeHTMLcoinSerialize();

                menu.findItem(R.id.wallet_transactions_context_show_qr)
                        .setVisible(serializedTx.length < SHOW_QR_THRESHOLD_BYTES);

                Nfc.publishMimeObject(nfcManager, activity, Constants.MIMETYPE_TRANSACTION, serializedTx);

                return true;
            } catch (final ScriptException x) {
                return false;
            }
        }

        @Override
        public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) {
            switch (item.getItemId()) {
            case R.id.wallet_transactions_context_edit_address:
                handleEditAddress(tx);

                mode.finish();
                return true;

            case R.id.wallet_transactions_context_show_qr:
                handleShowQr();

                mode.finish();
                return true;

            case R.id.wallet_transactions_context_browse:
                startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse(Constants.EXPLORE_BASE_URL + "tx/" + tx.getHashAsString())));

                mode.finish();
                return true;
            }
            return false;
        }

        @Override
        public void onDestroyActionMode(final ActionMode mode) {
            Nfc.unpublish(nfcManager, activity);
        }

        private void handleEditAddress(@Nonnull final Transaction tx) {
            EditAddressBookEntryFragment.edit(getFragmentManager(), address.toString());
        }

        private void handleShowQr() {
            final int size = (int) (384 * getResources().getDisplayMetrics().density);
            final Bitmap qrCodeBitmap = Qr.bitmap(Qr.encodeCompressBinary(serializedTx), size);
            BitmapFragment.show(getFragmentManager(), qrCodeBitmap);
        }
    });
}