private void validateAddress(boolean isTyping) { if (address == null) { String input = sendToAddressView.getText().toString().trim(); try { if (!input.isEmpty()) { // Process fast the input string if (processInput(input)) return; // Try to fix address if needed parseAddress(GenericUtils.fixAddress(input)); } else { // empty field should not raise error message clearAddress(false); } addressError.setVisibility(View.GONE); } catch (final AddressFormatException x) { // could not decode address at all if (!isTyping) { clearAddress(false); addressError.setText(R.string.address_error); addressError.setVisibility(View.VISIBLE); } } updateView(); } }
private void parseAddress(String addressStr) throws AddressFormatException { List<CoinType> possibleTypes = GenericUtils.getPossibleTypes(addressStr); if (possibleTypes.contains(pocket.getCoinType())) { setAddress(new Address(pocket.getCoinType(), addressStr), true); sendAmountType = pocket.getCoinType(); } else if (possibleTypes.size() == 1) { setAddress(new Address(possibleTypes.get(0), addressStr), true); sendAmountType = possibleTypes.get(0); } else { // This address string could be more that one coin type so first check if this address // comes from an account to determine the type. List<WalletAccount> possibleAccounts = application.getAccounts(possibleTypes); Address addressOfAccount = null; for (WalletAccount account : possibleAccounts) { Address testAddress = new Address(account.getCoinType(), addressStr); if (account.isAddressMine(testAddress)) { addressOfAccount = testAddress; break; } } if (addressOfAccount != null) { // If address is from an account don't show a dialog. The type should not change as // we know 100% that is correct one setAddress(addressOfAccount, false); sendAmountType = (CoinType) addressOfAccount.getParameters(); } else { // As a last resort let the use choose the correct coin type showPayToDialog(addressStr); } } }
@Override public void bindView(final View view, final Context context, final Cursor cursor) { final String label = cursor.getString(cursor.getColumnIndexOrThrow(AddressBookProvider.KEY_LABEL)); final String address = cursor.getString(cursor.getColumnIndexOrThrow(AddressBookProvider.KEY_ADDRESS)); final ViewGroup viewGroup = (ViewGroup) view; final TextView labelView = (TextView) viewGroup.findViewById(R.id.address_book_row_label); labelView.setText(label); final TextView addressView = (TextView) viewGroup.findViewById(R.id.address_book_row_address); addressView.setText(GenericUtils.addressSplitToGroupsMultiline(address)); }
@Override public void onClick(View v) { if (address != null) { final boolean showChangeType = addressTypeCanChange && GenericUtils.hasMultipleTypes(address); ActionMode.Callback callback = new UiUtils.AddressActionModeCallback( address, application.getApplicationContext(), getFragmentManager()) { @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { mode.getMenuInflater().inflate(R.menu.address_options_extra, menu); return super.onCreateActionMode(mode, menu); } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { menu.findItem(R.id.action_change_address_type).setVisible(showChangeType); return super.onPrepareActionMode(mode, menu); } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.action_change_address_type: showPayToDialog(getAddress().toString()); mode.finish(); return true; } return super.onActionItemClicked(mode, menuItem); } }; actionMode = UiUtils.startActionMode(getActivity(), callback); // Hack to dismiss this action mode when back is pressed if (listener != null && listener instanceof WalletActivity) { ((WalletActivity) listener).registerActionMode(actionMode); } } }