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

Commit 893ab9aa authored by Wenyi Wang's avatar Wenyi Wang Committed by Android (Google) Code Review
Browse files

Merge "Backport ContactsContract methods (2/2)" into ub-contactsdialer-b-dev

parents a949f537 fe4048c7
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -17,16 +17,28 @@
package com.android.contacts.common.compat;

import android.net.Uri;
import android.provider.ContactsContract;
import android.provider.ContactsContract.Contacts;

import com.android.contacts.common.ContactsUtils;

/**
 * Compatibility class for {@link ContactsContract.Contacts}
 */
public class ContactsCompat {
    /**
     * Not instantiable.
     */
    private ContactsCompat() {
    }

    // TODO: Use N APIs
    private static final Uri ENTERPRISE_CONTENT_FILTER_URI =
            Uri.withAppendedPath(Contacts.CONTENT_URI, "filter_enterprise");

    // Copied from ContactsContract.Contacts#ENTERPRISE_CONTACT_ID_BASE, which is hidden.
    private static final long ENTERPRISE_CONTACT_ID_BASE = 1000000000;

    public static Uri getContentUri() {
        // TODO: Use N APIs
        if (ContactsUtils.FLAG_N_FEATURE && android.os.Build.VERSION.CODENAME.startsWith("N")) {
@@ -34,4 +46,17 @@ public class ContactsCompat {
        }
        return Contacts.CONTENT_FILTER_URI;
    }

    /**
     * Return {@code true} if a contact ID is from the contacts provider on the enterprise profile.
     */
    public static boolean isEnterpriseContactId(long contactId) {
        if (CompatUtils.isLollipopCompatible()) {
            return Contacts.isEnterpriseContactId(contactId);
        } else {
            // copied from ContactsContract.Contacts.isEnterpriseContactId
            return (contactId >= ENTERPRISE_CONTACT_ID_BASE) &&
                    (contactId < ContactsContract.Profile.MIN_ID);
        }
    }
}
+58 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.contacts.common.compat;

import android.content.res.Resources;
import android.provider.ContactsContract.CommonDataKinds.BaseTypes;
import android.provider.ContactsContract.CommonDataKinds.Event;
import android.text.TextUtils;

/**
 * Compatibility class for {@link Event}
 */
public class EventCompat {
    /**
     * Not instantiable.
     */
    private EventCompat() {
    }

    /**
     * Return a {@link CharSequence} that best describes the given type, possibly substituting
     * the given label value for TYPE_CUSTOM.
     */
    public static CharSequence getTypeLabel(Resources res, int type, CharSequence label) {
        if (CompatUtils.isLollipopCompatible()) {
            return Event.getTypeLabel(res, type, label);
        } else {
            return getTypeLabelInternal(res, type, label);
        }
    }

    /**
     * The method was added in API level 21, and below is the implementation copied from
     * {@link Event#getTypeLabel(Resources, int, CharSequence)}
     */
    private static CharSequence getTypeLabelInternal(Resources res, int type, CharSequence label) {
        if (type == BaseTypes.TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
            return label;
        } else {
            return res.getText(Event.getTypeResource(type));
        }
    }

}
+27 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.contacts.common.compat;

import android.telephony.PhoneNumberFormattingTextWatcher;

public class PhoneNumberFormattingTextWatcherCompat {
    public static PhoneNumberFormattingTextWatcher newInstance(String countryCode) {
        if (CompatUtils.isLollipopCompatible()) {
            return new PhoneNumberFormattingTextWatcher(countryCode);
        }
        return new PhoneNumberFormattingTextWatcher();
    }
}
+2 −1
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.widget.ListView;
import com.android.contacts.common.ContactPhotoManager;
import com.android.contacts.common.ContactPhotoManager.DefaultImageRequest;
import com.android.contacts.common.R;
import com.android.contacts.common.compat.ContactsCompat;
import com.android.contacts.common.preference.ContactsPreferences;

/**
@@ -176,7 +177,7 @@ public abstract class ContactListAdapter extends ContactEntryListAdapter {
        final Cursor cursor = (Cursor) getItem(position);
        if (cursor != null) {
            final long contactId = cursor.getLong(ContactQuery.CONTACT_ID);
            return Contacts.isEnterpriseContactId(contactId);
            return ContactsCompat.isEnterpriseContactId(contactId);
        }
        return false;
    }
+2 −2
Original line number Diff line number Diff line
@@ -134,7 +134,8 @@ public class BitmapUtil {
        final Paint paint = new Paint();
        canvas.drawARGB(0, 0, 0, 0);
        paint.setAntiAlias(true);
        canvas.drawOval(0, 0, targetWidth, targetHeight, paint);
        final RectF dst = new RectF(0, 0, targetWidth, targetHeight);
        canvas.drawOval(dst, paint);

        // Specifies that only pixels present in the destination (i.e. the drawn oval) should
        // be overwritten with pixels from the input bitmap.
@@ -157,7 +158,6 @@ public class BitmapUtil {
                inputWidth / 2 + xCropAmountHalved,
                inputHeight / 2 + yCropAmountHalved);

        final RectF dst = new RectF(0, 0, targetWidth, targetHeight);
        canvas.drawBitmap(input, src, dst, paint);
        return result;
    }
Loading