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

Commit 34ce8f1b authored by Tyler Gunn's avatar Tyler Gunn Committed by Android (Google) Code Review
Browse files

Merge "Support carrier presence-based video calling icon." into ub-contactsdialer-b-dev

parents fdb93b70 b31f5d16
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -40,13 +40,13 @@
        <item name="section_header_background">@drawable/list_title_holo</item>
        <item name="list_section_header_height">32dip</item>
        <item name="list_item_padding_top">12dp</item>
        <item name="list_item_padding_right">32dp</item>
        <item name="list_item_padding_right">24dp</item>
        <item name="list_item_padding_bottom">12dp</item>
        <item name="list_item_padding_left">16dp</item>
        <item name="list_item_gap_between_image_and_text">
            @dimen/contact_browser_list_item_gap_between_image_and_text
        </item>
        <item name="list_item_gap_between_label_and_data">5dip</item>
        <item name="list_item_gap_between_label_and_data">8dip</item>
        <item name="list_item_presence_icon_margin">4dip</item>
        <item name="list_item_presence_icon_size">16dip</item>
        <item name="list_item_photo_size">@dimen/contact_browser_list_item_photo_size</item>
@@ -85,6 +85,10 @@
        <item name="android:colorControlActivated">@color/dialer_theme_color</item>
        <item name="android:colorButtonNormal">@color/dialer_theme_color</item>
        <item name="android:textAppearanceButton">@style/DialerButtonTextStyle</item>

        <!-- Video call icon -->
        <item name="list_item_video_call_icon_size">32dip</item>
        <item name="list_item_video_call_icon_margin">8dip</item>
    </style>

    <style name="DialerButtonTextStyle" parent="@android:style/TextAppearance.Material.Widget.Button">
+2 −2
Original line number Diff line number Diff line
@@ -1284,10 +1284,10 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O
    }

    @Override
    public void onPickDataUri(Uri dataUri, int callInitiationType) {
    public void onPickDataUri(Uri dataUri, boolean isVideoCall, int callInitiationType) {
        mClearSearchOnPause = true;
        PhoneNumberInteraction.startInteractionForPhoneCall(
                DialtactsActivity.this, dataUri, callInitiationType);
                DialtactsActivity.this, dataUri, isVideoCall, callInitiationType);
    }

    @Override
+31 −9
Original line number Diff line number Diff line
@@ -75,7 +75,7 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
     *   0-98   KitKat
     * </pre>
     */
    public static final int DATABASE_VERSION = 7;
    public static final int DATABASE_VERSION = 8;
    public static final String DATABASE_NAME = "dialer.db";

    /**
@@ -115,6 +115,7 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
        static final String IS_SUPER_PRIMARY = "is_super_primary";
        static final String IN_VISIBLE_GROUP = "in_visible_group";
        static final String IS_PRIMARY = "is_primary";
        static final String CARRIER_PRESENCE = "carrier_presence";
        static final String LAST_SMARTDIAL_UPDATE_TIME = "last_smartdial_update_time";
    }

@@ -151,6 +152,7 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
            Data.IS_SUPER_PRIMARY,              // 11
            Contacts.IN_VISIBLE_GROUP,          // 12
            Data.IS_PRIMARY,                    // 13
            Data.CARRIER_PRESENCE,              // 14
        };

        static final int PHONE_ID = 0;
@@ -167,6 +169,7 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
        static final int PHONE_IS_SUPER_PRIMARY = 11;
        static final int PHONE_IN_VISIBLE_GROUP = 12;
        static final int PHONE_IS_PRIMARY = 13;
        static final int PHONE_CARRIER_PRESENCE = 14;

        /** Selects only rows that have been updated after a certain time stamp.*/
        static final String SELECT_UPDATED_CLAUSE =
@@ -268,20 +271,23 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
        public final String phoneNumber;
        public final String lookupKey;
        public final long photoId;
        public final int carrierPresence;

        public ContactNumber(long id, long dataID, String displayName, String phoneNumber,
                String lookupKey, long photoId) {
                String lookupKey, long photoId, int carrierPresence) {
            this.dataId = dataID;
            this.id = id;
            this.displayName = displayName;
            this.phoneNumber = phoneNumber;
            this.lookupKey = lookupKey;
            this.photoId = photoId;
            this.carrierPresence = carrierPresence;
        }

        @Override
        public int hashCode() {
            return Objects.hashCode(id, dataId, displayName, phoneNumber, lookupKey, photoId);
            return Objects.hashCode(id, dataId, displayName, phoneNumber, lookupKey, photoId,
                    carrierPresence);
        }

        @Override
@@ -296,7 +302,8 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
                        && Objects.equal(this.displayName, that.displayName)
                        && Objects.equal(this.phoneNumber, that.phoneNumber)
                        && Objects.equal(this.lookupKey, that.lookupKey)
                        && Objects.equal(this.photoId, that.photoId);
                        && Objects.equal(this.photoId, that.photoId)
                        && Objects.equal(this.carrierPresence, that.carrierPresence);
            }
            return false;
        }
@@ -398,7 +405,8 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
                + SmartDialDbColumns.STARRED + " INTEGER, "
                + SmartDialDbColumns.IS_SUPER_PRIMARY + " INTEGER, "
                + SmartDialDbColumns.IN_VISIBLE_GROUP + " INTEGER, "
                + SmartDialDbColumns.IS_PRIMARY + " INTEGER"
                + SmartDialDbColumns.IS_PRIMARY + " INTEGER, "
                + SmartDialDbColumns.CARRIER_PRESENCE + " INTEGER NOT NULL DEFAULT 0"
                + ");");

        db.execSQL("CREATE TABLE " + Tables.PREFIX_TABLE + " ("
@@ -473,6 +481,11 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
            oldVersion = 7;
        }

        if (oldVersion < 8) {
            upgradeToVersion8(db);
            oldVersion = 8;
        }

        if (oldVersion != DATABASE_VERSION) {
            throw new IllegalStateException(
                    "error upgrading the database to version " + DATABASE_VERSION);
@@ -481,6 +494,10 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
        setProperty(db, DATABASE_VERSION_PROPERTY, String.valueOf(DATABASE_VERSION));
    }

    public void upgradeToVersion8(SQLiteDatabase db) {
        db.execSQL("ALTER TABLE smartdial_table ADD carrier_presence INTEGER NOT NULL DEFAULT 0");
    }

    /**
     * Stores a key-value pair in the {@link Tables#PROPERTIES} table.
     */
@@ -705,8 +722,9 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
                    SmartDialDbColumns.IS_SUPER_PRIMARY + ", " +
                    SmartDialDbColumns.IN_VISIBLE_GROUP+ ", " +
                    SmartDialDbColumns.IS_PRIMARY + ", " +
                    SmartDialDbColumns.CARRIER_PRESENCE + ", " +
                    SmartDialDbColumns.LAST_SMARTDIAL_UPDATE_TIME + ") " +
                    " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
                    " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
            final SQLiteStatement insert = db.compileStatement(sqlInsert);

            final String numberSqlInsert = "INSERT INTO " + Tables.PREFIX_TABLE + " (" +
@@ -753,7 +771,8 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
                insert.bindLong(10, updatedContactCursor.getInt(PhoneQuery.PHONE_IS_SUPER_PRIMARY));
                insert.bindLong(11, updatedContactCursor.getInt(PhoneQuery.PHONE_IN_VISIBLE_GROUP));
                insert.bindLong(12, updatedContactCursor.getInt(PhoneQuery.PHONE_IS_PRIMARY));
                insert.bindLong(13, currentMillis);
                insert.bindLong(13, updatedContactCursor.getInt(PhoneQuery.PHONE_CARRIER_PRESENCE));
                insert.bindLong(14, currentMillis);
                insert.executeInsert();
                final String contactPhoneNumber =
                        updatedContactCursor.getString(PhoneQuery.PHONE_NUMBER);
@@ -1020,7 +1039,8 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
                SmartDialDbColumns.PHOTO_ID + ", " +
                SmartDialDbColumns.NUMBER + ", " +
                SmartDialDbColumns.CONTACT_ID + ", " +
                SmartDialDbColumns.LOOKUP_KEY +
                SmartDialDbColumns.LOOKUP_KEY + ", " +
                SmartDialDbColumns.CARRIER_PRESENCE +
                " FROM " + Tables.SMARTDIAL_TABLE + " WHERE " +
                SmartDialDbColumns.CONTACT_ID + " IN " +
                    " (SELECT " + PrefixColumns.CONTACT_ID +
@@ -1044,6 +1064,7 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
            final int columnNumber = 3;
            final int columnId = 4;
            final int columnLookupKey = 5;
            final int columnCarrierPresence = 6;
            if (DEBUG) {
                stopWatch.lap("Found column IDs");
            }
@@ -1061,6 +1082,7 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
                final long id = cursor.getLong(columnId);
                final long photoId = cursor.getLong(columnPhotoId);
                final String lookupKey = cursor.getString(columnLookupKey);
                final int carrierPresence = cursor.getInt(columnCarrierPresence);

                /** If a contact already exists and another phone number of the contact is being
                 * processed, skip the second instance.
@@ -1081,7 +1103,7 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
                    /** If a contact has not been added, add it to the result and the hash set.*/
                    duplicates.add(contactMatch);
                    result.add(new ContactNumber(id, dataID, displayName, phoneNumber, lookupKey,
                            photoId));
                            photoId, carrierPresence));
                    counter++;
                    if (DEBUG) {
                        stopWatch.lap("Added one result: Name: " + displayName);
+1 −0
Original line number Diff line number Diff line
@@ -102,6 +102,7 @@ public class SmartDialCursorLoader extends AsyncTaskLoader<Cursor> {
            row[PhoneQuery.LOOKUP_KEY] = contact.lookupKey;
            row[PhoneQuery.PHOTO_ID] = contact.photoId;
            row[PhoneQuery.DISPLAY_NAME] = contact.displayName;
            row[PhoneQuery.CARRIER_PRESENCE] = contact.carrierPresence;
            cursor.addRow(row);
        }
        return cursor;
+23 −10
Original line number Diff line number Diff line
@@ -196,10 +196,12 @@ public class PhoneNumberInteraction implements OnLoadCompleteListener<Cursor> {
        private ListAdapter mPhonesAdapter;
        private List<PhoneItem> mPhoneList;
        private int mCallInitiationType;
        private boolean mIsVideoCall;

        public static void show(FragmentManager fragmentManager, ArrayList<PhoneItem> phoneList,
                int interactionType, int callInitiationType) {
            PhoneDisambiguationDialogFragment fragment = new PhoneDisambiguationDialogFragment();
                int interactionType, boolean isVideoCall, int callInitiationType) {
            PhoneDisambiguationDialogFragment fragment = new PhoneDisambiguationDialogFragment(
                isVideoCall);
            Bundle bundle = new Bundle();
            bundle.putParcelableArrayList(ARG_PHONE_LIST, phoneList);
            bundle.putInt(ARG_INTERACTION_TYPE, interactionType);
@@ -208,6 +210,11 @@ public class PhoneNumberInteraction implements OnLoadCompleteListener<Cursor> {
            fragment.show(fragmentManager, TAG);
        }

        public PhoneDisambiguationDialogFragment(boolean isVideoCall) {
            super();
            mIsVideoCall = isVideoCall;
        }

        @Override
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            final Activity activity = getActivity();
@@ -242,7 +249,7 @@ public class PhoneNumberInteraction implements OnLoadCompleteListener<Cursor> {
                }

                PhoneNumberInteraction.performAction(activity, phoneItem.phoneNumber,
                        mInteractionType, mCallInitiationType);
                        mInteractionType, mIsVideoCall, mCallInitiationType);
            } else {
                dialog.dismiss();
            }
@@ -288,6 +295,7 @@ public class PhoneNumberInteraction implements OnLoadCompleteListener<Cursor> {
    private long mContactId = UNKNOWN_CONTACT_ID;

    private CursorLoader mLoader;
    private boolean mIsVideoCall;

    /**
     * Constructs a new {@link PhoneNumberInteraction}. The constructor takes in a {@link Context}
@@ -298,25 +306,28 @@ public class PhoneNumberInteraction implements OnLoadCompleteListener<Cursor> {
    @VisibleForTesting
    /* package */ PhoneNumberInteraction(Context context, int interactionType,
            DialogInterface.OnDismissListener dismissListener) {
        this(context, interactionType, dismissListener, LogState.INITIATION_UNKNOWN);
        this(context, interactionType, dismissListener, false /*isVideoCall*/,
                LogState.INITIATION_UNKNOWN);
    }

    private PhoneNumberInteraction(Context context, int interactionType,
            DialogInterface.OnDismissListener dismissListener, int callInitiationType) {
            DialogInterface.OnDismissListener dismissListener, boolean isVideoCall, 
            int callInitiationType) {
        mContext = context;
        mInteractionType = interactionType;
        mDismissListener = dismissListener;
        mCallInitiationType = callInitiationType;
        mIsVideoCall = isVideoCall;
    }

    private void performAction(String phoneNumber) {
        PhoneNumberInteraction.performAction(mContext, phoneNumber, mInteractionType,
        PhoneNumberInteraction.performAction(mContext, phoneNumber, mInteractionType, mIsVideoCall,
                mCallInitiationType);
    }

    private static void performAction(
            Context context, String phoneNumber, int interactionType,
            int callInitiationType) {
            boolean isVideoCall, int callInitiationType) {
        Intent intent;
        switch (interactionType) {
            case ContactDisplayUtils.INTERACTION_SMS:
@@ -326,6 +337,7 @@ public class PhoneNumberInteraction implements OnLoadCompleteListener<Cursor> {
            default:
                intent = new CallIntentBuilder(phoneNumber)
                        .setCallInitiationType(callInitiationType)
                        .setIsVideoCall(isVideoCall)
                        .build();
                break;
        }
@@ -454,12 +466,13 @@ public class PhoneNumberInteraction implements OnLoadCompleteListener<Cursor> {
     * @param activity that is calling this interaction. This must be of type
     * {@link TransactionSafeActivity} because we need to check on the activity state after the
     * phone numbers have been queried for.
     * @param isVideoCall {@code true} if the call is a video call, {@code false} otherwise.
     * @param callInitiationType Indicates the UI affordance that was used to initiate the call.
     */
    public static void startInteractionForPhoneCall(TransactionSafeActivity activity, Uri uri,
            int callInitiationType) {
            boolean isVideoCall, int callInitiationType) {
        (new PhoneNumberInteraction(activity, ContactDisplayUtils.INTERACTION_CALL, null,
                callInitiationType)).startInteraction(uri, true);
                isVideoCall, callInitiationType)).startInteraction(uri, true);
    }

    /**
@@ -493,7 +506,7 @@ public class PhoneNumberInteraction implements OnLoadCompleteListener<Cursor> {
        }
        try {
            PhoneDisambiguationDialogFragment.show(activity.getFragmentManager(),
                    phoneList, mInteractionType, mCallInitiationType);
                    phoneList, mInteractionType, mIsVideoCall, mCallInitiationType);
        } catch (IllegalStateException e) {
            // ignore to be safe. Shouldn't happen because we checked the
            // activity wasn't destroyed, but to be safe.
Loading