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

Commit ff84e49e authored by takuo's avatar takuo
Browse files

Merge remote branch 'cyanogen/eclair' into eclair

parents 52641b00 0c79d8c3
Loading
Loading
Loading
Loading
+10 −37
Original line number Diff line number Diff line
@@ -2017,52 +2017,21 @@ public class ContactsListActivity extends ListActivity implements
                return false;
            }

            String phone = null;
            Cursor phonesCursor = null;
            phonesCursor = queryPhoneNumbers(cursor.getLong(SUMMARY_ID_COLUMN_INDEX));
            if (phonesCursor == null || phonesCursor.getCount() == 0) {
                // No valid number
	    long contactId = cursor.getLong(SUMMARY_ID_COLUMN_INDEX);
	    if(!ContactsUtils.callOrSmsContact(contactId, this, sendSms)) {
                signalError();
                return false;
            } else if (phonesCursor.getCount() == 1) {
                // only one number, call it.
                phone = phonesCursor.getString(phonesCursor.getColumnIndex(Phone.NUMBER));
            } else {
                phonesCursor.moveToPosition(-1);
                while (phonesCursor.moveToNext()) {
                    if (phonesCursor.getInt(phonesCursor.
                            getColumnIndex(Phone.IS_SUPER_PRIMARY)) != 0) {
                        // Found super primary, call it.
                        phone = phonesCursor.
                                getString(phonesCursor.getColumnIndex(Phone.NUMBER));
                        break;
                    }
                }
            }

            if (phone == null) {
                // Display dialog to choose a number to call.
                PhoneDisambigDialog phoneDialog = new PhoneDisambigDialog(
                        this, phonesCursor, sendSms);
                phoneDialog.show();
            } else {
                if (sendSms) {
                    ContactsUtils.initiateSms(this, phone);
                } else {
                    ContactsUtils.initiateCall(this, phone);
                }
            }
            return true;
	}

	return false;
    }

    private Cursor queryPhoneNumbers(long contactId) {
    private Cursor queryPhoneNumbers(ContentResolver resolver, long contactId) {
        Uri baseUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId);
        Uri dataUri = Uri.withAppendedPath(baseUri, Contacts.Data.CONTENT_DIRECTORY);

        Cursor c = getContentResolver().query(dataUri,
        Cursor c = resolver.query(dataUri,
                new String[] {Phone._ID, Phone.NUMBER, Phone.IS_SUPER_PRIMARY},
                Data.MIMETYPE + "=?", new String[] {Phone.CONTENT_ITEM_TYPE}, null);
        if (c != null && c.moveToFirst()) {
@@ -2071,6 +2040,10 @@ public class ContactsListActivity extends ListActivity implements
        return null;
    }

    private Cursor queryPhoneNumbers(long contactId) {
        return ContactsUtils.queryPhoneNumbers(getContentResolver(), contactId);
    }

    /**
     * Signal an error to the user.
     */
+55 −0
Original line number Diff line number Diff line
@@ -424,4 +424,59 @@ public class ContactsUtils {
    public static boolean isGraphic(CharSequence str) {
        return !TextUtils.isEmpty(str) && TextUtils.isGraphic(str);
    }

    /**
     * Calls the specified contact ID, displaying a number picker if necessary.
     * @return true if the call was initiated, false otherwise
     */
    public static boolean callOrSmsContact(long contactId, Context context, boolean sendSms) {
        String phone = null;
        Cursor phonesCursor = null;
        phonesCursor = queryPhoneNumbers(context.getContentResolver(), contactId);
        if (phonesCursor == null || phonesCursor.getCount() == 0) {
            // No valid number
            return false;
        } else if (phonesCursor.getCount() == 1) {
            // only one number, call it.
            phone = phonesCursor.getString(phonesCursor.getColumnIndex(Phone.NUMBER));
        } else {
            phonesCursor.moveToPosition(-1);
            while (phonesCursor.moveToNext()) {
                if (phonesCursor.getInt(phonesCursor.
                        getColumnIndex(Phone.IS_SUPER_PRIMARY)) != 0) {
                    // Found super primary, call it.
                    phone = phonesCursor.
                            getString(phonesCursor.getColumnIndex(Phone.NUMBER));
                    break;
                }
            }
        }

        if (phone == null) {
            // Display dialog to choose a number to call.
            PhoneDisambigDialog phoneDialog = new PhoneDisambigDialog(
                    context, phonesCursor, sendSms);
            phoneDialog.show();
        } else {
            if (sendSms) {
                ContactsUtils.initiateSms(context, phone);
            } else {
                ContactsUtils.initiateCall(context, phone);
            }
        }
        return true;
    }

    public static Cursor queryPhoneNumbers(ContentResolver resolver, long contactId) {
        Uri baseUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId);
        Uri dataUri = Uri.withAppendedPath(baseUri, Contacts.Data.CONTENT_DIRECTORY);

        Cursor c = resolver.query(dataUri,
                new String[] {Phone._ID, Phone.NUMBER, Phone.IS_SUPER_PRIMARY},
                Data.MIMETYPE + "=?", new String[] {Phone.CONTENT_ITEM_TYPE}, null);
        if (c != null && c.moveToFirst()) {
            return c;
        }
        return null;
    }
}
+5 −6
Original line number Diff line number Diff line
@@ -722,13 +722,12 @@ public class ViewContactActivity extends Activity
                        startActivity(entry.intent);
                    }
                } else if (mNumPhoneNumbers != 0) {
                    // There isn't anything selected, call the default number
                    // There isn't anything selected; pick the correct number to dial.
                    long freshContactId = getRefreshedContactId();
                    if (freshContactId > 0) {
                        Uri hardContacUri = ContentUris.withAppendedId(
                                Contacts.CONTENT_URI, freshContactId);
                        Intent intent = new Intent(Intent.ACTION_CALL_PRIVILEGED, hardContacUri);
                        startActivity(intent);

                    if(!ContactsUtils.callOrSmsContact(freshContactId, this, false)) {
                        signalError();
                        return false;
                    }
                }
                return true;