private void updateDialTextHelper() { String dialUserValue = dialUser.getText().toString(); accountChooserButtonText.setChangeable(TextUtils.isEmpty(dialUserValue)); SipProfile acc = accountChooserButtonText.getSelectedAccount(); if (!Pattern.matches(".*@.*", dialUserValue) && acc != null && acc.id > SipProfile.INVALID_ID) { domainTextHelper.setText("@" + acc.getDefaultDomain()); } else { domainTextHelper.setText(""); } }
/** * Retrieve the value of the selected sip uri * * @return the contact to call as a ToCall object containing account to use and number to call */ public ToCall getValue() { String userName = dialUser.getText().toString(); String toCall = ""; Long accountToUse = null; if (TextUtils.isEmpty(userName)) { return null; } userName = userName.replaceAll("[ \t]", ""); SipProfile acc = accountChooserButtonText.getSelectedAccount(); if (acc != null) { accountToUse = acc.id; // If this is a sip account if (accountToUse > SipProfile.INVALID_ID) { if (Pattern.matches(".*@.*", userName)) { toCall = "sip:" + userName + ""; } else if (!TextUtils.isEmpty(acc.getDefaultDomain())) { toCall = "sip:" + userName + "@" + acc.getDefaultDomain(); } else { toCall = "sip:" + userName; } } else { toCall = userName; } } else { toCall = userName; } return new ToCall(accountToUse, toCall); }
@Override public void onItemClick(AdapterView<?> ad, View view, int position, long arg3) { String number = (String) view.getTag(); SipProfile account = accountChooserButtonText.getSelectedAccount(); String rewritten = Filter.rewritePhoneNumber(getContext(), account.id, number); setTextValue(rewritten); Log.d(THIS_FILE, "Clicked contact " + number); }
public EditSipUri(Context context, AttributeSet attrs) { super(context, attrs); setGravity(Gravity.CENTER_HORIZONTAL); setOrientation(VERTICAL); LayoutInflater inflater = LayoutInflater.from(context); inflater.inflate(R.layout.edit_sip_uri, this, true); dialUser = (AutoCompleteTextView) findViewById(R.id.dialtxt_user); accountChooserButtonText = (AccountChooserButton) findViewById(R.id.accountChooserButtonText); domainTextHelper = (TextView) findViewById(R.id.dialtxt_domain_helper); completeList = (ListView) findViewById(R.id.autoCompleteList); autoCompleteAdapter = new ContactsAutocompleteAdapter(context); // Map events accountChooserButtonText.setOnAccountChangeListener( new OnAccountChangeListener() { @Override public void onChooseAccount(SipProfile account) { updateDialTextHelper(); long accId = SipProfile.INVALID_ID; if (account != null) { accId = account.id; } autoCompleteAdapter.setSelectedAccount(accId); } }); dialUser.addTextChangedListener(this); if (isInEditMode()) { // Don't bind cursor in this case return; } Cursor c = ContactsWrapper.getInstance().getContactsPhones(context); contactsAdapter = new ContactAdapter(context, c); completeList.setAdapter(contactsAdapter); completeList.setOnItemClickListener(this); dialUser.setAdapter(autoCompleteAdapter); }
public void setShowExternals(boolean b) { accountChooserButtonText.setShowExternals(b); }
public SipProfile getSelectedAccount() { return accountChooserButtonText.getSelectedAccount(); }