Fields Summary |
---|
private static final String | LOG_TAG |
private static final boolean | DBG |
private static final int | MENU_IMPORT |
private static final int | MENU_DELETE |
private static final String | INTENT_EXTRA_NAME |
private static final String | INTENT_EXTRA_NUMBER |
private static final int | PIN2_REQUEST_CODE |
private String | mName |
private String | mNumber |
private String | mPin2 |
private boolean | mAddContact |
private QueryHandler | mQueryHandler |
private android.widget.EditText | mNameField |
private android.widget.EditText | mNumberField |
private android.widget.LinearLayout | mPinFieldContainer |
private android.widget.Button | mButton |
private android.os.Handler | mHandler |
private static final int | CONTACTS_PICKER_CODErequest code when invoking subactivity |
private static final String[] | NUM_PROJECTIONprojection for phone number query |
private static final android.content.Intent | CONTACT_IMPORT_INTENTstatic intent to invoke phone number picker |
private boolean | mDataBusyflag to track saving state |
private View.OnClickListener | mClicked |
View.OnFocusChangeListener | mOnFocusChangeHandler |
Methods Summary |
---|
private void | addContact()
if (DBG) log("addContact");
if (!isValidNumber(getNumberFromTextField())) {
handleResult(false, true);
return;
}
Uri uri = getContentURI();
ContentValues bundle = new ContentValues(3);
bundle.put("tag", getNameFromTextField());
bundle.put("number", getNumberFromTextField());
bundle.put("pin2", mPin2);
mQueryHandler = new QueryHandler(getContentResolver());
mQueryHandler.startInsert(0, null, uri, bundle);
displayProgress(true);
showStatus(getResources().getText(R.string.adding_fdn_contact));
|
private void | authenticatePin2()
Intent intent = new Intent();
intent.setClass(this, GetPin2Screen.class);
startActivityForResult(intent, PIN2_REQUEST_CODE);
|
private void | deleteSelected()Handle the delete command, based upon the state of the Activity.
// delete ONLY if this is NOT a new contact.
if (!mAddContact) {
Intent intent = new Intent();
intent.setClass(this, DeleteFdnContactScreen.class);
intent.putExtra(INTENT_EXTRA_NAME, mName);
intent.putExtra(INTENT_EXTRA_NUMBER, mNumber);
startActivity(intent);
}
finish();
|
private void | displayProgress(boolean flag)
// indicate we are busy.
mDataBusy = flag;
getWindow().setFeatureInt(
Window.FEATURE_INDETERMINATE_PROGRESS,
mDataBusy ? PROGRESS_VISIBILITY_ON : PROGRESS_VISIBILITY_OFF);
// make sure we don't allow calls to save when we're
// not ready for them.
mButton.setClickable(!mDataBusy);
|
private android.net.Uri | getContentURI()
return Uri.parse("content://sim/fdn");
|
private java.lang.String | getNameFromTextField()
return mNameField.getText().toString();
|
private java.lang.String | getNumberFromTextField()
return mNumberField.getText().toString();
|
private void | handleResult(boolean success, boolean invalidNumber)
if (success) {
if (DBG) log("handleResult: success!");
showStatus(getResources().getText(mAddContact ?
R.string.fdn_contact_added : R.string.fdn_contact_updated));
} else {
if (DBG) log("handleResult: failed!");
if (invalidNumber)
showStatus(getResources().getText(R.string.fdn_invalid_number));
else
showStatus(getResources().getText(R.string.pin2_invalid));
}
mHandler.postDelayed(new Runnable() {
public void run() {
finish();
}
}, 2000);
|
private boolean | isValidNumber(java.lang.String number)
return (number.length() <= 20);
|
private void | log(java.lang.String msg)
Log.d(LOG_TAG, "[EditFdnContact] " + msg);
|
protected void | onActivityResult(int requestCode, int resultCode, android.content.Intent intent)We now want to bring up the pin request screen AFTER the
contact information is displayed, to help with user
experience.
Also, process the results from the contact picker.
if (DBG) log("onActivityResult request:" + requestCode + " result:" + resultCode);
switch (requestCode) {
case PIN2_REQUEST_CODE:
Bundle extras = (intent != null) ? intent.getExtras() : null;
if (extras != null) {
mPin2 = extras.getString("pin2");
if (mAddContact) {
addContact();
} else {
updateContact();
}
} else if (resultCode != RESULT_OK) {
// if they cancelled, then we just cancel too.
if (DBG) log("onActivityResult: cancelled.");
finish();
}
break;
// look for the data associated with this number, and update
// the display with it.
case CONTACTS_PICKER_CODE:
if (resultCode != RESULT_OK) {
if (DBG) log("onActivityResult: cancelled.");
return;
}
Cursor cursor = getContentResolver().query(intent.getData(),
NUM_PROJECTION, null, null, null);
if ((cursor == null) || (!cursor.moveToFirst())) {
Log.w(LOG_TAG,"onActivityResult: bad contact data, no results found.");
return;
}
mNameField.setText(cursor.getString(0));
mNumberField.setText(cursor.getString(1));
break;
}
|
protected void | onCreate(android.os.Bundle icicle)
super.onCreate(icicle);
resolveIntent();
getWindow().requestFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.edit_fdn_contact_screen);
setupView();
setTitle(mAddContact ?
R.string.add_fdn_contact : R.string.edit_fdn_contact);
mDataBusy = false;
|
public boolean | onCreateOptionsMenu(android.view.Menu menu)Overridden to display the import and delete commands.
super.onCreateOptionsMenu(menu);
Resources r = getResources();
// Added the icons to the context menu
menu.add(0, MENU_IMPORT, 0, r.getString(R.string.importToFDNfromContacts))
.setIcon(R.drawable.ic_menu_contact);
menu.add(0, MENU_DELETE, 0, r.getString(R.string.menu_delete))
.setIcon(android.R.drawable.ic_menu_delete);
return true;
|
public boolean | onOptionsItemSelected(android.view.MenuItem item)Overridden to allow for handling of delete and import.
switch (item.getItemId()) {
case MENU_IMPORT:
startActivityForResult(CONTACT_IMPORT_INTENT, CONTACTS_PICKER_CODE);
return true;
case MENU_DELETE:
deleteSelected();
return true;
}
return super.onOptionsItemSelected(item);
|
public boolean | onPrepareOptionsMenu(android.view.Menu menu)Allow the menu to be opened ONLY if we're not busy.
boolean result = super.onPrepareOptionsMenu(menu);
return mDataBusy ? false : result;
|
private void | resolveIntent()
Intent intent = getIntent();
mName = intent.getStringExtra(INTENT_EXTRA_NAME);
mNumber = intent.getStringExtra(INTENT_EXTRA_NUMBER);
if (TextUtils.isEmpty(mName)) {
mAddContact = true;
}
|
private void | setupView()We have multiple layouts, one to indicate that the user needs to
open the keyboard to enter information (if the keybord is hidden).
So, we need to make sure that the layout here matches that in the
layout file.
mNameField = (EditText) findViewById(R.id.fdn_name);
if (mNameField != null) {
mNameField.setOnFocusChangeListener(mOnFocusChangeHandler);
mNameField.setOnClickListener(mClicked);
}
mNumberField = (EditText) findViewById(R.id.fdn_number);
if (mNumberField != null) {
mNumberField.setKeyListener(DialerKeyListener.getInstance());
mNumberField.setOnFocusChangeListener(mOnFocusChangeHandler);
mNumberField.setOnClickListener(mClicked);
}
if (!mAddContact) {
if (mNameField != null) {
mNameField.setText(mName);
}
if (mNumberField != null) {
mNumberField.setText(mNumber);
}
}
mButton = (Button) findViewById(R.id.button);
if (mButton != null) {
mButton.setOnClickListener(mClicked);
}
mPinFieldContainer = (LinearLayout) findViewById(R.id.pinc);
|
private void | showStatus(java.lang.CharSequence statusMsg)Removed the status field, with preference to displaying a toast
to match the rest of settings UI.
if (statusMsg != null) {
Toast.makeText(this, statusMsg, Toast.LENGTH_SHORT)
.show();
}
|
private void | updateContact()
if (DBG) log("updateContact");
if (!isValidNumber(getNumberFromTextField())) {
handleResult(false, true);
return;
}
Uri uri = getContentURI();
ContentValues bundle = new ContentValues();
bundle.put("tag", mName);
bundle.put("number", mNumber);
bundle.put("newTag", getNameFromTextField());
bundle.put("newNumber", getNumberFromTextField());
bundle.put("pin2", mPin2);
mQueryHandler = new QueryHandler(getContentResolver());
mQueryHandler.startUpdate(0, null, uri, bundle, null, null);
displayProgress(true);
showStatus(getResources().getText(R.string.updating_fdn_contact));
|