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

Commit 34d81ed8 authored by Wenyi Wang's avatar Wenyi Wang
Browse files

Use ContextCompat to handle getColor (1/2)

Bug: 25629359
Change-Id: I38192f608728fbd338a572295ad85b0fba0e892d
parent 77f1fda3
Loading
Loading
Loading
Loading
+0 −34
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.Context;
import android.os.Build;

public class CompatUtils {
    // private constructor to prevent this class from being initialized from outside uses
    private CompatUtils() {}

    public static int getColorCompat(Context context, int resId) {
        if (SdkVersionOverride.getSdkVersion(Build.VERSION_CODES.LOLLIPOP)
                >= Build.VERSION_CODES.M) {
            return context.getColor(resId);
        } else {
            return context.getResources().getColor(resId);
        }
    }
}
+3 −4
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.provider.ContactsContract.Contacts;
import android.support.v4.content.ContextCompat;
import android.telephony.PhoneNumberUtils;
import android.text.Spannable;
import android.text.SpannableString;
@@ -63,8 +64,6 @@ import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.android.contacts.common.compat.CompatUtils;

/**
 * A custom view for an item in the contact list.
 * The view contains the contact's photo, a set of text views (for name, status, etc...) and
@@ -1519,7 +1518,7 @@ public class ContactListItemView extends ViewGroup
        ImageView photo = getPhotoView();
        photo.setScaleType(ImageView.ScaleType.CENTER);
        photo.setImageDrawable(getContext().getDrawable(drawableId));
        photo.setImageTintList(ColorStateList.valueOf(CompatUtils.getColorCompat(
        photo.setImageTintList(ColorStateList.valueOf(ContextCompat.getColor(
                getContext(), R.color.search_shortcut_icon_color)));
    }