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

Commit 77f1fda3 authored by Wenyi Wang's avatar Wenyi Wang
Browse files

Fix usage of getColor() on pre-M SDKs (1/2)

Bug: 25629359
Change-Id: I10e35d117ce9087e3031d2b90e41f0ce9a59ee81
parent 17ed9519
Loading
Loading
Loading
Loading
+34 −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.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);
        }
    }
}
+4 −2
Original line number Diff line number Diff line
@@ -63,6 +63,8 @@ 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
@@ -1517,8 +1519,8 @@ public class ContactListItemView extends ViewGroup
        ImageView photo = getPhotoView();
        photo.setScaleType(ImageView.ScaleType.CENTER);
        photo.setImageDrawable(getContext().getDrawable(drawableId));
        photo.setImageTintList(ColorStateList.valueOf(
                getContext().getColor(R.color.search_shortcut_icon_color)));
        photo.setImageTintList(ColorStateList.valueOf(CompatUtils.getColorCompat(
                        getContext(), R.color.search_shortcut_icon_color)));
    }

    @Override