1/* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.support.design.testutils; 18 19import android.graphics.drawable.GradientDrawable; 20import android.support.annotation.ColorInt; 21 22/** 23 * Custom drawable class that provides a reliable way for testing various tinting scenarios 24 * across a range of platform versions. ColorDrawable doesn't support tinting on Kitkat and 25 * below, and BitmapDrawable (PNG sources) appears to slightly alter green and blue channels 26 * by a few units on some of the older platform versions (Gingerbread). Using GradientDrawable 27 * allows doing reliable tests at the level of individual channels (alpha / red / green / blue) 28 * for tinted and untinted icons in the testIconTinting method. 29 */ 30public class TestDrawable extends GradientDrawable { 31 private int mWidth; 32 private int mHeight; 33 34 public TestDrawable(@ColorInt int color, int width, int height) { 35 super(Orientation.TOP_BOTTOM, new int[] { color, color }); 36 mWidth = width; 37 mHeight = height; 38 } 39 40 @Override 41 public int getIntrinsicWidth() { 42 return mWidth; 43 } 44 45 @Override 46 public int getIntrinsicHeight() { 47 return mHeight; 48 } 49} 50