Loading src/com/android/contacts/ui/EditContactActivity.java +65 −30 Original line number Diff line number Diff line Loading @@ -731,6 +731,15 @@ public final class EditContactActivity extends Activity implements View.OnClickL .getSystemService(Context.LAYOUT_INFLATER_SERVICE); final ArrayList<Account> writable = sources.getAccounts(true); // In the common case of a single account being writable, auto-select // it without showing a dialog. if (writable.size() == 1) { selectAccount(writable.get(0)); // Signal to not show a dialog: return null; } final ArrayAdapter<Account> accountAdapter = new ArrayAdapter<Account>(target, android.R.layout.simple_list_item_2, writable) { @Override Loading Loading @@ -761,6 +770,40 @@ public final class EditContactActivity extends Activity implements View.OnClickL // Create new contact based on selected source final Account account = accountAdapter.getItem(which); selectAccount(account); // Update the UI. EditContactActivity target = mTarget.get(); if (target != null) { target.bindTabs(); target.bindHeader(); } } }; final DialogInterface.OnCancelListener cancelListener = new DialogInterface.OnCancelListener() { public void onCancel(DialogInterface dialog) { // If nothing remains, close activity if (!target.hasValidState()) { target.finish(); } } }; // TODO: when canceled and was single add, finish() final AlertDialog.Builder builder = new AlertDialog.Builder(target); builder.setTitle(R.string.dialog_new_contact_account); builder.setSingleChoiceItems(accountAdapter, 0, clickListener); builder.setOnCancelListener(cancelListener); return builder; } private void selectAccount(Account account) { EditContactActivity target = mTarget.get(); if (target == null) { return; } final Sources sources = Sources.getInstance(target); final ContentValues values = new ContentValues(); values.put(RawContacts.ACCOUNT_NAME, account.name); values.put(RawContacts.ACCOUNT_TYPE, account.type); Loading @@ -782,6 +825,9 @@ public final class EditContactActivity extends Activity implements View.OnClickL HardCodedSources.attemptMyContactsMembership(insert, target); } // TODO: no synchronization here on target.mState. This // runs in the background thread, but it's accessed from // multiple thread, including the UI thread. if (target.mState == null) { // Create state if none exists yet target.mState = EntitySet.fromSingle(insert); Loading @@ -789,32 +835,21 @@ public final class EditContactActivity extends Activity implements View.OnClickL // Add contact onto end of existing state target.mState.add(insert); } target.bindTabs(); target.bindHeader(); } }; final DialogInterface.OnCancelListener cancelListener = new DialogInterface.OnCancelListener() { public void onCancel(DialogInterface dialog) { // If nothing remains, close activity if (!target.hasValidState()) { target.finish(); } } }; // TODO: when canceled and was single add, finish() final AlertDialog.Builder builder = new AlertDialog.Builder(target); builder.setTitle(R.string.dialog_new_contact_account); builder.setSingleChoiceItems(accountAdapter, 0, clickListener); builder.setOnCancelListener(cancelListener); return builder; } @Override protected void onPostExecute(EditContactActivity target, AlertDialog.Builder result) { if (result != null) { // Note: null is returned when no dialog is to be // shown (no multiple accounts to select between) target.showAndManageDialog(result.create()); } else { // Account was auto-selected on the background thread, // but we need to update the UI still in the // now-current UI thread. target.bindTabs(); target.bindHeader(); } } } Loading Loading
src/com/android/contacts/ui/EditContactActivity.java +65 −30 Original line number Diff line number Diff line Loading @@ -731,6 +731,15 @@ public final class EditContactActivity extends Activity implements View.OnClickL .getSystemService(Context.LAYOUT_INFLATER_SERVICE); final ArrayList<Account> writable = sources.getAccounts(true); // In the common case of a single account being writable, auto-select // it without showing a dialog. if (writable.size() == 1) { selectAccount(writable.get(0)); // Signal to not show a dialog: return null; } final ArrayAdapter<Account> accountAdapter = new ArrayAdapter<Account>(target, android.R.layout.simple_list_item_2, writable) { @Override Loading Loading @@ -761,6 +770,40 @@ public final class EditContactActivity extends Activity implements View.OnClickL // Create new contact based on selected source final Account account = accountAdapter.getItem(which); selectAccount(account); // Update the UI. EditContactActivity target = mTarget.get(); if (target != null) { target.bindTabs(); target.bindHeader(); } } }; final DialogInterface.OnCancelListener cancelListener = new DialogInterface.OnCancelListener() { public void onCancel(DialogInterface dialog) { // If nothing remains, close activity if (!target.hasValidState()) { target.finish(); } } }; // TODO: when canceled and was single add, finish() final AlertDialog.Builder builder = new AlertDialog.Builder(target); builder.setTitle(R.string.dialog_new_contact_account); builder.setSingleChoiceItems(accountAdapter, 0, clickListener); builder.setOnCancelListener(cancelListener); return builder; } private void selectAccount(Account account) { EditContactActivity target = mTarget.get(); if (target == null) { return; } final Sources sources = Sources.getInstance(target); final ContentValues values = new ContentValues(); values.put(RawContacts.ACCOUNT_NAME, account.name); values.put(RawContacts.ACCOUNT_TYPE, account.type); Loading @@ -782,6 +825,9 @@ public final class EditContactActivity extends Activity implements View.OnClickL HardCodedSources.attemptMyContactsMembership(insert, target); } // TODO: no synchronization here on target.mState. This // runs in the background thread, but it's accessed from // multiple thread, including the UI thread. if (target.mState == null) { // Create state if none exists yet target.mState = EntitySet.fromSingle(insert); Loading @@ -789,32 +835,21 @@ public final class EditContactActivity extends Activity implements View.OnClickL // Add contact onto end of existing state target.mState.add(insert); } target.bindTabs(); target.bindHeader(); } }; final DialogInterface.OnCancelListener cancelListener = new DialogInterface.OnCancelListener() { public void onCancel(DialogInterface dialog) { // If nothing remains, close activity if (!target.hasValidState()) { target.finish(); } } }; // TODO: when canceled and was single add, finish() final AlertDialog.Builder builder = new AlertDialog.Builder(target); builder.setTitle(R.string.dialog_new_contact_account); builder.setSingleChoiceItems(accountAdapter, 0, clickListener); builder.setOnCancelListener(cancelListener); return builder; } @Override protected void onPostExecute(EditContactActivity target, AlertDialog.Builder result) { if (result != null) { // Note: null is returned when no dialog is to be // shown (no multiple accounts to select between) target.showAndManageDialog(result.create()); } else { // Account was auto-selected on the background thread, // but we need to update the UI still in the // now-current UI thread. target.bindTabs(); target.bindHeader(); } } } Loading