Last active
January 4, 2016 00:49
-
-
Save nseidm1/8544457 to your computer and use it in GitHub Desktop.
Workaround for Chips to add a telephone number programmatically with a successful chip conversion. This is the code that's run from an onActivityResult after a telephone number selection.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void processPickResult(final Intent data) { | |
final Handler handler = new Handler(); | |
ExecutorManager.sInstance.mExecutor.execute(new Runnable() { | |
@Override | |
public void run() { | |
Uri pickedPhoneNumber = data.getData(); | |
Cursor cursor = getContentResolver().query(pickedPhoneNumber, null, null, null, null); | |
try{ | |
if (cursor.moveToFirst()) { | |
final String telephone = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DATA1)); | |
final Contact contact = Contact.get(telephone, true); | |
handler.post(new Runnable() { | |
@Override | |
public void run() { | |
Editable current = mRecipientsEditor.getText(); | |
mRecipientsEditor.removeTextChangedListener(mRecipientsWatcher); | |
current.append(PhoneNumberUtils.normalizeNumber(contact.getNumber())); | |
mRecipientsEditor.setSelection(mRecipientsEditor.getText().length()); | |
mRecipientsEditor.addTextChangedListener(mRecipientsWatcher); | |
mRecipientsEditor.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SPACE)); | |
mRecipientsEditor.getAdapter().addUpdateObserver(new EntriesUpdatedObserver() { | |
@Override | |
public void onChanged(List<RecipientEntry> entries) { | |
mRecipientsEditor.getAdapter().removeUpdateObserver(this); | |
mRecipientsEditor.getOnItemClickListener().onItemClick(null, null, 0, 0); | |
mRecipientsEditor.requestFocus(); | |
} | |
}); | |
} | |
}); | |
} | |
} finally { | |
cursor.close(); | |
} | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment