Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fade1bb2 authored by Steve Kondik's avatar Steve Kondik Committed by Gerrit Code Review
Browse files

Merge "Allow user to add a phone only contact even when other contact accounts...

Merge "Allow user to add a phone only contact even when other contact accounts are available" into froyo
parents 186b0736 acd3213b
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1583,7 +1583,7 @@ public class ContactsListActivity extends ListActivity implements View.OnCreateC
        // - just one account -> use the account without asking the user
        // - no account -> use phone-local storage without asking the user
        final Sources sources = Sources.getInstance(this);
        final List<Account> accountList = sources.getAccounts(true);
        final List<Account> accountList = sources.getAccounts(true, true);
        final int size = accountList.size();
        if (size > 1) {
            showDialog(resId);
+4 −2
Original line number Diff line number Diff line
@@ -734,7 +734,9 @@ public class ImportVCardActivity extends Activity {
        super.onCreate(bundle);

        final Intent intent = getIntent();
        boolean accountIsNull = false;
        if (intent != null) {
            accountIsNull = intent.getBooleanExtra("account_isnull", false);
            final String accountName = intent.getStringExtra("account_name");
            final String accountType = intent.getStringExtra("account_type");
            if (!TextUtils.isEmpty(accountName) && !TextUtils.isEmpty(accountType)) {
@@ -745,13 +747,13 @@ public class ImportVCardActivity extends Activity {
        }

        // The caller often does not know account information at all, so we show the UI instead.
        if (mAccount == null) {
        if (!accountIsNull && mAccount == null) {
            // There's three possibilities:
            // - more than one accounts -> ask the user
            // - just one account -> use the account without asking the user
            // - no account -> use phone-local storage without asking the user
            final Sources sources = Sources.getInstance(this);
            final List<Account> accountList = sources.getAccounts(true);
            final List<Account> accountList = sources.getAccounts(true, true);
            final int size = accountList.size();
            if (size > 1) {
                final int resId = R.string.import_from_sdcard;
+9 −1
Original line number Diff line number Diff line
@@ -246,11 +246,15 @@ public class Sources extends BroadcastReceiver implements OnAccountsUpdateListen
        return null;
    }

    public ArrayList<Account> getAccounts(boolean writableOnly) {
        return getAccounts(writableOnly, false);
    }

    /**
     * Return list of all known, writable {@link ContactsSource}. Sources
     * returned may require inflation before they can be used.
     */
    public ArrayList<Account> getAccounts(boolean writableOnly) {
    public ArrayList<Account> getAccounts(boolean writableOnly, boolean addPhoneOnlyDummy) {
        final AccountManager am = mAccountManager;
        final Account[] accounts = am.getAccounts();
        final ArrayList<Account> matching = Lists.newArrayList();
@@ -265,6 +269,10 @@ public class Sources extends BroadcastReceiver implements OnAccountsUpdateListen
                matching.add(account);
            }
        }

        if (addPhoneOnlyDummy)
            matching.add(null);

        return matching;
    }

+11 −5
Original line number Diff line number Diff line
@@ -1206,7 +1206,7 @@ public final class EditContactActivity extends Activity
        @Override
        protected ArrayList<Account> doInBackground(final EditContactActivity target,
                Void... params) {
            return Sources.getInstance(target).getAccounts(true);
            return Sources.getInstance(target).getAccounts(true, true);
        }

        @Override
@@ -1250,11 +1250,17 @@ public final class EditContactActivity extends Activity
                final TextView text2 = (TextView)convertView.findViewById(android.R.id.text2);

                final Account account = this.getItem(position);
                final ContactsSource source = sources.getInflatedSource(account.type,
                final ContactsSource source =
                    sources.getInflatedSource(account != null ? account.type : null,
                            ContactsSource.LEVEL_SUMMARY);

                if (account == null) {
                    text1.setText(source.getDisplayLabel(EditContactActivity.this));
                    text2.setText("");
                } else {
                    text1.setText(account.name);
                    text2.setText(source.getDisplayLabel(EditContactActivity.this));
                }

                return convertView;
            }
+15 −6
Original line number Diff line number Diff line
@@ -90,7 +90,7 @@ public class AccountSelectionUtil {
            DialogInterface.OnClickListener onClickListener,
            DialogInterface.OnCancelListener onCancelListener) {
        final Sources sources = Sources.getInstance(context);
        final List<Account> writableAccountList = sources.getAccounts(true);
        final List<Account> writableAccountList = sources.getAccounts(true, true);

        // Assume accountList.size() > 1

@@ -119,12 +119,17 @@ public class AccountSelectionUtil {

                final Account account = this.getItem(position);
                final ContactsSource source =
                    sources.getInflatedSource(account.type,
                    sources.getInflatedSource(account != null ? account.type : null,
                            ContactsSource.LEVEL_SUMMARY);
                final Context context = getContext();

                if (account == null) {
                    text1.setText(source.getDisplayLabel(context));
                    text2.setText("");
                } else {
                    text1.setText(account.name);
                    text2.setText(source.getDisplayLabel(context));
                }

                return convertView;
            }
@@ -169,7 +174,9 @@ public class AccountSelectionUtil {

        Intent importIntent = new Intent(Intent.ACTION_VIEW);
        importIntent.setType("vnd.android.cursor.item/sim-contact");
        if (account != null) {
        if (account == null) {
            importIntent.putExtra("account_isnull", true);
        } else {
            importIntent.putExtra("account_name", account.name);
            importIntent.putExtra("account_type", account.type);
        }
@@ -183,7 +190,9 @@ public class AccountSelectionUtil {
        }

        Intent importIntent = new Intent(context, ImportVCardActivity.class);
        if (account != null) {
        if (account == null) {
            importIntent.putExtra("account_isnull", true);
        } else {
            importIntent.putExtra("account_name", account.name);
            importIntent.putExtra("account_type", account.type);
        }