183b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar/* 283b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar * Copyright (C) 2014 The Android Open Source Project 383b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar * 483b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar * Licensed under the Apache License, Version 2.0 (the "License"); 583b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar * you may not use this file except in compliance with the License. 683b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar * You may obtain a copy of the License at 783b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar * 883b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar * http://www.apache.org/licenses/LICENSE-2.0 983b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar * 1083b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar * Unless required by applicable law or agreed to in writing, software 1183b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar * distributed under the License is distributed on an "AS IS" BASIS, 1283b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1383b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar * See the License for the specific language governing permissions and 1483b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar * limitations under the License. 1583b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar */ 1683b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar 1783b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyarpackage android.support.v7.widget; 1883b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar 1983b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyarimport android.content.Context; 20d2c60296856244030e9a92ef3065d3884ac67527Aurimas Liutikasimport android.content.res.ColorStateList; 2183b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyarimport android.content.res.TypedArray; 22dba32f5fecbcd344460fc8cbcfb82ae4fcd0ba69Chris Banesimport android.graphics.Color; 2318ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyarimport android.graphics.Rect; 24ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banesimport android.graphics.drawable.Drawable; 2583b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyarimport android.os.Build; 2686223c8f397daa57fff72d6bd5cf10ceeb74d40eChris Banesimport android.support.annotation.ColorInt; 27d2c60296856244030e9a92ef3065d3884ac67527Aurimas Liutikasimport android.support.annotation.Nullable; 2883b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyarimport android.support.v7.cardview.R; 2983b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyarimport android.util.AttributeSet; 30ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banesimport android.view.View; 3183b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyarimport android.widget.FrameLayout; 3283b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar 3383b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar/** 3418ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar * A FrameLayout with a rounded corner background and shadow. 3583b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar * <p> 36e4548b3ac721f2b85f7b030d7043c94b24288670Kirill Grouchnikov * CardView uses <code>elevation</code> property on Lollipop for shadows and falls back to a 37e4548b3ac721f2b85f7b030d7043c94b24288670Kirill Grouchnikov * custom emulated shadow implementation on older platforms. 3883b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar * <p> 39e4548b3ac721f2b85f7b030d7043c94b24288670Kirill Grouchnikov * Due to expensive nature of rounded corner clipping, on platforms before Lollipop, CardView does 40e4548b3ac721f2b85f7b030d7043c94b24288670Kirill Grouchnikov * not clip its children that intersect with rounded corners. Instead, it adds padding to avoid such 41c42ba8c000d1e6ce85e152dfc17089a0a69e739fYigit Boyar * intersection (See {@link #setPreventCornerOverlap(boolean)} to change this behavior). 4218ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar * <p> 43e4548b3ac721f2b85f7b030d7043c94b24288670Kirill Grouchnikov * Before Lollipop, CardView adds padding to its content and draws shadows to that area. This 44e4548b3ac721f2b85f7b030d7043c94b24288670Kirill Grouchnikov * padding amount is equal to <code>maxCardElevation + (1 - cos45) * cornerRadius</code> on the 45e4548b3ac721f2b85f7b030d7043c94b24288670Kirill Grouchnikov * sides and <code>maxCardElevation * 1.5 + (1 - cos45) * cornerRadius</code> on top and bottom. 46bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar * <p> 47c42ba8c000d1e6ce85e152dfc17089a0a69e739fYigit Boyar * Since padding is used to offset content for shadows, you cannot set padding on CardView. 48e4548b3ac721f2b85f7b030d7043c94b24288670Kirill Grouchnikov * Instead, you can use content padding attributes in XML or 49e4548b3ac721f2b85f7b030d7043c94b24288670Kirill Grouchnikov * {@link #setContentPadding(int, int, int, int)} in code to set the padding between the edges of 50e4548b3ac721f2b85f7b030d7043c94b24288670Kirill Grouchnikov * the CardView and children of CardView. 51bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar * <p> 52bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar * Note that, if you specify exact dimensions for the CardView, because of the shadows, its content 53e4548b3ac721f2b85f7b030d7043c94b24288670Kirill Grouchnikov * area will be different between platforms before Lollipop and after Lollipop. By using api version 54e4548b3ac721f2b85f7b030d7043c94b24288670Kirill Grouchnikov * specific resource values, you can avoid these changes. Alternatively, If you want CardView to add 55e4548b3ac721f2b85f7b030d7043c94b24288670Kirill Grouchnikov * inner padding on platforms Lollipop and after as well, you can call 56e4548b3ac721f2b85f7b030d7043c94b24288670Kirill Grouchnikov * {@link #setUseCompatPadding(boolean)} and pass <code>true</code>. 5718ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar * <p> 5818ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar * To change CardView's elevation in a backward compatible way, use 59e4548b3ac721f2b85f7b030d7043c94b24288670Kirill Grouchnikov * {@link #setCardElevation(float)}. CardView will use elevation API on Lollipop and before 60e4548b3ac721f2b85f7b030d7043c94b24288670Kirill Grouchnikov * Lollipop, it will change the shadow size. To avoid moving the View while shadow size is changing, 61e4548b3ac721f2b85f7b030d7043c94b24288670Kirill Grouchnikov * shadow size is clamped by {@link #getMaxCardElevation()}. If you want to change elevation 62e4548b3ac721f2b85f7b030d7043c94b24288670Kirill Grouchnikov * dynamically, you should call {@link #setMaxCardElevation(float)} when CardView is initialized. 6383b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar * 6483b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar * @attr ref android.support.v7.cardview.R.styleable#CardView_cardBackgroundColor 65bc943f7fa746c149c5e4c3a4eed7febe494d5df5Yigit Boyar * @attr ref android.support.v7.cardview.R.styleable#CardView_cardCornerRadius 6618ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar * @attr ref android.support.v7.cardview.R.styleable#CardView_cardElevation 6718ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar * @attr ref android.support.v7.cardview.R.styleable#CardView_cardMaxElevation 68bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar * @attr ref android.support.v7.cardview.R.styleable#CardView_cardUseCompatPadding 69c42ba8c000d1e6ce85e152dfc17089a0a69e739fYigit Boyar * @attr ref android.support.v7.cardview.R.styleable#CardView_cardPreventCornerOverlap 70bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar * @attr ref android.support.v7.cardview.R.styleable#CardView_contentPadding 71bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar * @attr ref android.support.v7.cardview.R.styleable#CardView_contentPaddingLeft 72bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar * @attr ref android.support.v7.cardview.R.styleable#CardView_contentPaddingTop 73bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar * @attr ref android.support.v7.cardview.R.styleable#CardView_contentPaddingRight 74bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar * @attr ref android.support.v7.cardview.R.styleable#CardView_contentPaddingBottom 7583b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar */ 76ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banespublic class CardView extends FrameLayout { 7783b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar 78dba32f5fecbcd344460fc8cbcfb82ae4fcd0ba69Chris Banes private static final int[] COLOR_BACKGROUND_ATTR = {android.R.attr.colorBackground}; 79bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar private static final CardViewImpl IMPL; 8018ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar 8183b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar static { 82a52784195525cdb1f2bb4d8dde1b8b314f480957Chet Haase if (Build.VERSION.SDK_INT >= 21) { 8383b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar IMPL = new CardViewApi21(); 8483b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar } else if (Build.VERSION.SDK_INT >= 17) { 8583b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar IMPL = new CardViewJellybeanMr1(); 8683b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar } else { 8783b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar IMPL = new CardViewEclairMr1(); 8883b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar } 8983b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar IMPL.initStatic(); 9083b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar } 9183b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar 92bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar private boolean mCompatPadding; 93bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar 94c42ba8c000d1e6ce85e152dfc17089a0a69e739fYigit Boyar private boolean mPreventCornerOverlap; 95c42ba8c000d1e6ce85e152dfc17089a0a69e739fYigit Boyar 9672aedb5058595ed481c93f78deb9dc1b00fecf2aYigit Boyar /** 9772aedb5058595ed481c93f78deb9dc1b00fecf2aYigit Boyar * CardView requires to have a particular minimum size to draw shadows before API 21. If 9872aedb5058595ed481c93f78deb9dc1b00fecf2aYigit Boyar * developer also sets min width/height, they might be overridden. 9972aedb5058595ed481c93f78deb9dc1b00fecf2aYigit Boyar * 10072aedb5058595ed481c93f78deb9dc1b00fecf2aYigit Boyar * CardView works around this issue by recording user given parameters and using an internal 10172aedb5058595ed481c93f78deb9dc1b00fecf2aYigit Boyar * method to set them. 10272aedb5058595ed481c93f78deb9dc1b00fecf2aYigit Boyar */ 10372aedb5058595ed481c93f78deb9dc1b00fecf2aYigit Boyar private int mUserSetMinWidth, mUserSetMinHeight; 10472aedb5058595ed481c93f78deb9dc1b00fecf2aYigit Boyar 105bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar private final Rect mContentPadding = new Rect(); 106bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar 107bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar private final Rect mShadowBounds = new Rect(); 108bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar 10983b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar public CardView(Context context) { 11083b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar super(context); 11183b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar initialize(context, null, 0); 11283b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar } 11383b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar 11483b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar public CardView(Context context, AttributeSet attrs) { 11583b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar super(context, attrs); 11683b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar initialize(context, attrs, 0); 11783b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar } 11883b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar 11983b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar public CardView(Context context, AttributeSet attrs, int defStyleAttr) { 12083b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar super(context, attrs, defStyleAttr); 12183b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar initialize(context, attrs, defStyleAttr); 12283b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar } 12383b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar 124bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar @Override 125bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar public void setPadding(int left, int top, int right, int bottom) { 126bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar // NO OP 127bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar } 128bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar 129bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar public void setPaddingRelative(int start, int top, int end, int bottom) { 130bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar // NO OP 131bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar } 132bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar 133bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar /** 134e4548b3ac721f2b85f7b030d7043c94b24288670Kirill Grouchnikov * Returns whether CardView will add inner padding on platforms Lollipop and after. 135bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar * 136e4548b3ac721f2b85f7b030d7043c94b24288670Kirill Grouchnikov * @return <code>true</code> if CardView adds inner padding on platforms Lollipop and after to 137e4548b3ac721f2b85f7b030d7043c94b24288670Kirill Grouchnikov * have same dimensions with platforms before Lollipop. 138bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar */ 139bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar public boolean getUseCompatPadding() { 140bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar return mCompatPadding; 141bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar } 142bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar 143bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar /** 144e4548b3ac721f2b85f7b030d7043c94b24288670Kirill Grouchnikov * CardView adds additional padding to draw shadows on platforms before Lollipop. 145bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar * <p> 146e4548b3ac721f2b85f7b030d7043c94b24288670Kirill Grouchnikov * This may cause Cards to have different sizes between Lollipop and before Lollipop. If you 147e4548b3ac721f2b85f7b030d7043c94b24288670Kirill Grouchnikov * need to align CardView with other Views, you may need api version specific dimension 148e4548b3ac721f2b85f7b030d7043c94b24288670Kirill Grouchnikov * resources to account for the changes. 149bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar * As an alternative, you can set this flag to <code>true</code> and CardView will add the same 150e4548b3ac721f2b85f7b030d7043c94b24288670Kirill Grouchnikov * padding values on platforms Lollipop and after. 151bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar * <p> 152bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar * Since setting this flag to true adds unnecessary gaps in the UI, default value is 153bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar * <code>false</code>. 154bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar * 155e4548b3ac721f2b85f7b030d7043c94b24288670Kirill Grouchnikov * @param useCompatPadding <code>true></code> if CardView should add padding for the shadows on 156e4548b3ac721f2b85f7b030d7043c94b24288670Kirill Grouchnikov * platforms Lollipop and above. 157c42ba8c000d1e6ce85e152dfc17089a0a69e739fYigit Boyar * @attr ref android.support.v7.cardview.R.styleable#CardView_cardUseCompatPadding 158bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar */ 159bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar public void setUseCompatPadding(boolean useCompatPadding) { 160ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes if (mCompatPadding != useCompatPadding) { 161ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes mCompatPadding = useCompatPadding; 162ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes IMPL.onCompatPaddingChanged(mCardViewDelegate); 163bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar } 164bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar } 165bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar 166bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar /** 167bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar * Sets the padding between the Card's edges and the children of CardView. 168bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar * <p> 169bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar * Depending on platform version or {@link #getUseCompatPadding()} settings, CardView may 170bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar * update these values before calling {@link android.view.View#setPadding(int, int, int, int)}. 171bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar * 172c42ba8c000d1e6ce85e152dfc17089a0a69e739fYigit Boyar * @param left The left padding in pixels 173c42ba8c000d1e6ce85e152dfc17089a0a69e739fYigit Boyar * @param top The top padding in pixels 174c42ba8c000d1e6ce85e152dfc17089a0a69e739fYigit Boyar * @param right The right padding in pixels 175c42ba8c000d1e6ce85e152dfc17089a0a69e739fYigit Boyar * @param bottom The bottom padding in pixels 176bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar * @attr ref android.support.v7.cardview.R.styleable#CardView_contentPadding 177bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar * @attr ref android.support.v7.cardview.R.styleable#CardView_contentPaddingLeft 178bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar * @attr ref android.support.v7.cardview.R.styleable#CardView_contentPaddingTop 179bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar * @attr ref android.support.v7.cardview.R.styleable#CardView_contentPaddingRight 180bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar * @attr ref android.support.v7.cardview.R.styleable#CardView_contentPaddingBottom 181bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar */ 182bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar public void setContentPadding(int left, int top, int right, int bottom) { 183bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar mContentPadding.set(left, top, right, bottom); 184ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes IMPL.updatePadding(mCardViewDelegate); 185bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar } 18618ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar 18718ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar @Override 18818ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 18972aedb5058595ed481c93f78deb9dc1b00fecf2aYigit Boyar if (!(IMPL instanceof CardViewApi21)) { 19018ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar final int widthMode = MeasureSpec.getMode(widthMeasureSpec); 19118ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar switch (widthMode) { 19218ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar case MeasureSpec.EXACTLY: 19318ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar case MeasureSpec.AT_MOST: 194ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes final int minWidth = (int) Math.ceil(IMPL.getMinWidth(mCardViewDelegate)); 19518ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar widthMeasureSpec = MeasureSpec.makeMeasureSpec(Math.max(minWidth, 19618ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar MeasureSpec.getSize(widthMeasureSpec)), widthMode); 19718ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar break; 19818ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar } 19918ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar 20018ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar final int heightMode = MeasureSpec.getMode(heightMeasureSpec); 20118ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar switch (heightMode) { 20218ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar case MeasureSpec.EXACTLY: 20318ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar case MeasureSpec.AT_MOST: 204ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes final int minHeight = (int) Math.ceil(IMPL.getMinHeight(mCardViewDelegate)); 20518ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar heightMeasureSpec = MeasureSpec.makeMeasureSpec(Math.max(minHeight, 20618ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar MeasureSpec.getSize(heightMeasureSpec)), heightMode); 20718ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar break; 20818ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar } 20918ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar super.onMeasure(widthMeasureSpec, heightMeasureSpec); 21018ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar } else { 21118ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar super.onMeasure(widthMeasureSpec, heightMeasureSpec); 21218ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar } 21318ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar } 21418ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar 21583b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar private void initialize(Context context, AttributeSet attrs, int defStyleAttr) { 21683b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CardView, defStyleAttr, 217dba32f5fecbcd344460fc8cbcfb82ae4fcd0ba69Chris Banes R.style.CardView); 218d2c60296856244030e9a92ef3065d3884ac67527Aurimas Liutikas ColorStateList backgroundColor; 219dba32f5fecbcd344460fc8cbcfb82ae4fcd0ba69Chris Banes if (a.hasValue(R.styleable.CardView_cardBackgroundColor)) { 220d2c60296856244030e9a92ef3065d3884ac67527Aurimas Liutikas backgroundColor = a.getColorStateList(R.styleable.CardView_cardBackgroundColor); 221dba32f5fecbcd344460fc8cbcfb82ae4fcd0ba69Chris Banes } else { 222dba32f5fecbcd344460fc8cbcfb82ae4fcd0ba69Chris Banes // There isn't one set, so we'll compute one based on the theme 223dba32f5fecbcd344460fc8cbcfb82ae4fcd0ba69Chris Banes final TypedArray aa = getContext().obtainStyledAttributes(COLOR_BACKGROUND_ATTR); 224dba32f5fecbcd344460fc8cbcfb82ae4fcd0ba69Chris Banes final int themeColorBackground = aa.getColor(0, 0); 225dba32f5fecbcd344460fc8cbcfb82ae4fcd0ba69Chris Banes aa.recycle(); 226dba32f5fecbcd344460fc8cbcfb82ae4fcd0ba69Chris Banes 227dba32f5fecbcd344460fc8cbcfb82ae4fcd0ba69Chris Banes // If the theme colorBackground is light, use our own light color, otherwise dark 228dba32f5fecbcd344460fc8cbcfb82ae4fcd0ba69Chris Banes final float[] hsv = new float[3]; 229dba32f5fecbcd344460fc8cbcfb82ae4fcd0ba69Chris Banes Color.colorToHSV(themeColorBackground, hsv); 230d2c60296856244030e9a92ef3065d3884ac67527Aurimas Liutikas backgroundColor = ColorStateList.valueOf(hsv[2] > 0.5f 231dba32f5fecbcd344460fc8cbcfb82ae4fcd0ba69Chris Banes ? getResources().getColor(R.color.cardview_light_background) 232d2c60296856244030e9a92ef3065d3884ac67527Aurimas Liutikas : getResources().getColor(R.color.cardview_dark_background)); 233dba32f5fecbcd344460fc8cbcfb82ae4fcd0ba69Chris Banes } 23483b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar float radius = a.getDimension(R.styleable.CardView_cardCornerRadius, 0); 23518ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar float elevation = a.getDimension(R.styleable.CardView_cardElevation, 0); 23618ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar float maxElevation = a.getDimension(R.styleable.CardView_cardMaxElevation, 0); 237bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar mCompatPadding = a.getBoolean(R.styleable.CardView_cardUseCompatPadding, false); 238c42ba8c000d1e6ce85e152dfc17089a0a69e739fYigit Boyar mPreventCornerOverlap = a.getBoolean(R.styleable.CardView_cardPreventCornerOverlap, true); 239bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar int defaultPadding = a.getDimensionPixelSize(R.styleable.CardView_contentPadding, 0); 240bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar mContentPadding.left = a.getDimensionPixelSize(R.styleable.CardView_contentPaddingLeft, 241bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar defaultPadding); 242bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar mContentPadding.top = a.getDimensionPixelSize(R.styleable.CardView_contentPaddingTop, 243bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar defaultPadding); 244bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar mContentPadding.right = a.getDimensionPixelSize(R.styleable.CardView_contentPaddingRight, 245bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar defaultPadding); 246bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar mContentPadding.bottom = a.getDimensionPixelSize(R.styleable.CardView_contentPaddingBottom, 247bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar defaultPadding); 24818ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar if (elevation > maxElevation) { 24918ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar maxElevation = elevation; 25018ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar } 25172aedb5058595ed481c93f78deb9dc1b00fecf2aYigit Boyar mUserSetMinWidth = a.getDimensionPixelSize(R.styleable.CardView_android_minWidth, 0); 25272aedb5058595ed481c93f78deb9dc1b00fecf2aYigit Boyar mUserSetMinHeight = a.getDimensionPixelSize(R.styleable.CardView_android_minHeight, 0); 25383b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar a.recycle(); 25472aedb5058595ed481c93f78deb9dc1b00fecf2aYigit Boyar 255ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes IMPL.initialize(mCardViewDelegate, context, backgroundColor, radius, 256ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes elevation, maxElevation); 25783b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar } 25883b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar 25972aedb5058595ed481c93f78deb9dc1b00fecf2aYigit Boyar @Override 26072aedb5058595ed481c93f78deb9dc1b00fecf2aYigit Boyar public void setMinimumWidth(int minWidth) { 26172aedb5058595ed481c93f78deb9dc1b00fecf2aYigit Boyar mUserSetMinWidth = minWidth; 26272aedb5058595ed481c93f78deb9dc1b00fecf2aYigit Boyar super.setMinimumWidth(minWidth); 26372aedb5058595ed481c93f78deb9dc1b00fecf2aYigit Boyar } 26472aedb5058595ed481c93f78deb9dc1b00fecf2aYigit Boyar 26572aedb5058595ed481c93f78deb9dc1b00fecf2aYigit Boyar @Override 26672aedb5058595ed481c93f78deb9dc1b00fecf2aYigit Boyar public void setMinimumHeight(int minHeight) { 26772aedb5058595ed481c93f78deb9dc1b00fecf2aYigit Boyar mUserSetMinHeight = minHeight; 26872aedb5058595ed481c93f78deb9dc1b00fecf2aYigit Boyar super.setMinimumHeight(minHeight); 26972aedb5058595ed481c93f78deb9dc1b00fecf2aYigit Boyar } 27072aedb5058595ed481c93f78deb9dc1b00fecf2aYigit Boyar 27172aedb5058595ed481c93f78deb9dc1b00fecf2aYigit Boyar /** 2724eb77f0ed24a9d300f7d12959de8cf7efd837e2fYigit Boyar * Updates the background color of the CardView 2734eb77f0ed24a9d300f7d12959de8cf7efd837e2fYigit Boyar * 2744eb77f0ed24a9d300f7d12959de8cf7efd837e2fYigit Boyar * @param color The new color to set for the card background 2754eb77f0ed24a9d300f7d12959de8cf7efd837e2fYigit Boyar * @attr ref android.support.v7.cardview.R.styleable#CardView_cardBackgroundColor 2764eb77f0ed24a9d300f7d12959de8cf7efd837e2fYigit Boyar */ 27786223c8f397daa57fff72d6bd5cf10ceeb74d40eChris Banes public void setCardBackgroundColor(@ColorInt int color) { 27886223c8f397daa57fff72d6bd5cf10ceeb74d40eChris Banes IMPL.setBackgroundColor(mCardViewDelegate, ColorStateList.valueOf(color)); 279d2c60296856244030e9a92ef3065d3884ac67527Aurimas Liutikas } 280d2c60296856244030e9a92ef3065d3884ac67527Aurimas Liutikas 281d2c60296856244030e9a92ef3065d3884ac67527Aurimas Liutikas /** 282d2c60296856244030e9a92ef3065d3884ac67527Aurimas Liutikas * Updates the background ColorStateList of the CardView 283d2c60296856244030e9a92ef3065d3884ac67527Aurimas Liutikas * 284d2c60296856244030e9a92ef3065d3884ac67527Aurimas Liutikas * @param color The new ColorStateList to set for the card background 285d2c60296856244030e9a92ef3065d3884ac67527Aurimas Liutikas * @attr ref android.support.v7.cardview.R.styleable#CardView_cardBackgroundColor 286d2c60296856244030e9a92ef3065d3884ac67527Aurimas Liutikas */ 287d2c60296856244030e9a92ef3065d3884ac67527Aurimas Liutikas public void setCardBackgroundColor(@Nullable ColorStateList color) { 288ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes IMPL.setBackgroundColor(mCardViewDelegate, color); 2894eb77f0ed24a9d300f7d12959de8cf7efd837e2fYigit Boyar } 2904eb77f0ed24a9d300f7d12959de8cf7efd837e2fYigit Boyar 2914eb77f0ed24a9d300f7d12959de8cf7efd837e2fYigit Boyar /** 292e7c701f05b4f6afa2913c3743638d7b25b96df83Aurimas Liutikas * Returns the background color state list of the CardView. 293e7c701f05b4f6afa2913c3743638d7b25b96df83Aurimas Liutikas * 294e7c701f05b4f6afa2913c3743638d7b25b96df83Aurimas Liutikas * @return The background color state list of the CardView. 295e7c701f05b4f6afa2913c3743638d7b25b96df83Aurimas Liutikas */ 296e7c701f05b4f6afa2913c3743638d7b25b96df83Aurimas Liutikas public ColorStateList getCardBackgroundColor() { 297e7c701f05b4f6afa2913c3743638d7b25b96df83Aurimas Liutikas return IMPL.getBackgroundColor(mCardViewDelegate); 298e7c701f05b4f6afa2913c3743638d7b25b96df83Aurimas Liutikas } 299e7c701f05b4f6afa2913c3743638d7b25b96df83Aurimas Liutikas 300e7c701f05b4f6afa2913c3743638d7b25b96df83Aurimas Liutikas /** 301bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar * Returns the inner padding after the Card's left edge 302bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar * 303bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar * @return the inner padding after the Card's left edge 304bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar */ 305bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar public int getContentPaddingLeft() { 306bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar return mContentPadding.left; 307bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar } 308bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar 309bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar /** 310bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar * Returns the inner padding before the Card's right edge 311bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar * 312bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar * @return the inner padding before the Card's right edge 313bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar */ 314bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar public int getContentPaddingRight() { 315bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar return mContentPadding.right; 316bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar } 317bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar 318bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar /** 319bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar * Returns the inner padding after the Card's top edge 320bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar * 321bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar * @return the inner padding after the Card's top edge 322bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar */ 323bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar public int getContentPaddingTop() { 324bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar return mContentPadding.top; 325bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar } 326bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar 327bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar /** 328bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar * Returns the inner padding before the Card's bottom edge 329bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar * 330bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar * @return the inner padding before the Card's bottom edge 331bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar */ 332bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar public int getContentPaddingBottom() { 333bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar return mContentPadding.bottom; 334bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar } 335bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar 336bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar /** 33783b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar * Updates the corner radius of the CardView. 33883b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar * 33983b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar * @param radius The radius in pixels of the corners of the rectangle shape 340bc943f7fa746c149c5e4c3a4eed7febe494d5df5Yigit Boyar * @attr ref android.support.v7.cardview.R.styleable#CardView_cardCornerRadius 34183b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar * @see #setRadius(float) 34283b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar */ 34383b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar public void setRadius(float radius) { 344ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes IMPL.setRadius(mCardViewDelegate, radius); 34583b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar } 34683b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar 34783b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar /** 34883b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar * Returns the corner radius of the CardView. 34983b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar * 35083b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar * @return Corner radius of the CardView 35183b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar * @see #getRadius() 35283b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar */ 35383b8526436ba2e564dff99ec4c6cf46fabfdf22eYigit Boyar public float getRadius() { 354ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes return IMPL.getRadius(mCardViewDelegate); 355bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar } 356bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar 357bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar /** 35818ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar * Updates the backward compatible elevation of the CardView. 35918ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar * 360e4548b3ac721f2b85f7b030d7043c94b24288670Kirill Grouchnikov * @param elevation The backward compatible elevation in pixels. 36118ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar * @attr ref android.support.v7.cardview.R.styleable#CardView_cardElevation 36218ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar * @see #getCardElevation() 36318ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar * @see #setMaxCardElevation(float) 36418ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar */ 365e4548b3ac721f2b85f7b030d7043c94b24288670Kirill Grouchnikov public void setCardElevation(float elevation) { 366ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes IMPL.setElevation(mCardViewDelegate, elevation); 36718ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar } 36818ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar 36918ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar /** 37018ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar * Returns the backward compatible elevation of the CardView. 37118ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar * 37218ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar * @return Elevation of the CardView 37318ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar * @see #setCardElevation(float) 37418ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar * @see #getMaxCardElevation() 37518ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar */ 37618ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar public float getCardElevation() { 377ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes return IMPL.getElevation(mCardViewDelegate); 37818ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar } 37918ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar 38018ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar /** 381e4548b3ac721f2b85f7b030d7043c94b24288670Kirill Grouchnikov * Updates the backward compatible maximum elevation of the CardView. 38218ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar * <p> 383e4548b3ac721f2b85f7b030d7043c94b24288670Kirill Grouchnikov * Calling this method has no effect if device OS version is Lollipop or newer and 384bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar * {@link #getUseCompatPadding()} is <code>false</code>. 38518ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar * 386e4548b3ac721f2b85f7b030d7043c94b24288670Kirill Grouchnikov * @param maxElevation The backward compatible maximum elevation in pixels. 387e4548b3ac721f2b85f7b030d7043c94b24288670Kirill Grouchnikov * @attr ref android.support.v7.cardview.R.styleable#CardView_cardMaxElevation 38818ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar * @see #setCardElevation(float) 38918ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar * @see #getMaxCardElevation() 39018ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar */ 391e4548b3ac721f2b85f7b030d7043c94b24288670Kirill Grouchnikov public void setMaxCardElevation(float maxElevation) { 392ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes IMPL.setMaxElevation(mCardViewDelegate, maxElevation); 39318ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar } 39418ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar 39518ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar /** 396e4548b3ac721f2b85f7b030d7043c94b24288670Kirill Grouchnikov * Returns the backward compatible maximum elevation of the CardView. 39718ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar * 398e4548b3ac721f2b85f7b030d7043c94b24288670Kirill Grouchnikov * @return Maximum elevation of the CardView 39918ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar * @see #setMaxCardElevation(float) 40018ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar * @see #getCardElevation() 40118ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar */ 40218ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar public float getMaxCardElevation() { 403ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes return IMPL.getMaxElevation(mCardViewDelegate); 40418ef68d444a1c059041bf5b683eb612ffed22ea9Yigit Boyar } 405bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar 406c42ba8c000d1e6ce85e152dfc17089a0a69e739fYigit Boyar /** 407c42ba8c000d1e6ce85e152dfc17089a0a69e739fYigit Boyar * Returns whether CardView should add extra padding to content to avoid overlaps with rounded 408e4548b3ac721f2b85f7b030d7043c94b24288670Kirill Grouchnikov * corners on pre-Lollipop platforms. 409c42ba8c000d1e6ce85e152dfc17089a0a69e739fYigit Boyar * 410e4548b3ac721f2b85f7b030d7043c94b24288670Kirill Grouchnikov * @return True if CardView prevents overlaps with rounded corners on platforms before Lollipop. 411c42ba8c000d1e6ce85e152dfc17089a0a69e739fYigit Boyar * Default value is <code>true</code>. 412c42ba8c000d1e6ce85e152dfc17089a0a69e739fYigit Boyar */ 413c42ba8c000d1e6ce85e152dfc17089a0a69e739fYigit Boyar public boolean getPreventCornerOverlap() { 414c42ba8c000d1e6ce85e152dfc17089a0a69e739fYigit Boyar return mPreventCornerOverlap; 415c42ba8c000d1e6ce85e152dfc17089a0a69e739fYigit Boyar } 416c42ba8c000d1e6ce85e152dfc17089a0a69e739fYigit Boyar 417c42ba8c000d1e6ce85e152dfc17089a0a69e739fYigit Boyar /** 418e4548b3ac721f2b85f7b030d7043c94b24288670Kirill Grouchnikov * On pre-Lollipop platforms, CardView does not clip the bounds of the Card for the rounded 419e4548b3ac721f2b85f7b030d7043c94b24288670Kirill Grouchnikov * corners. Instead, it adds padding to content so that it won't overlap with the rounded 420e4548b3ac721f2b85f7b030d7043c94b24288670Kirill Grouchnikov * corners. You can disable this behavior by setting this field to <code>false</code>. 421c42ba8c000d1e6ce85e152dfc17089a0a69e739fYigit Boyar * <p> 422e4548b3ac721f2b85f7b030d7043c94b24288670Kirill Grouchnikov * Setting this value on Lollipop and above does not have any effect unless you have enabled 423c42ba8c000d1e6ce85e152dfc17089a0a69e739fYigit Boyar * compatibility padding. 424c42ba8c000d1e6ce85e152dfc17089a0a69e739fYigit Boyar * 425c42ba8c000d1e6ce85e152dfc17089a0a69e739fYigit Boyar * @param preventCornerOverlap Whether CardView should add extra padding to content to avoid 426c42ba8c000d1e6ce85e152dfc17089a0a69e739fYigit Boyar * overlaps with the CardView corners. 427c42ba8c000d1e6ce85e152dfc17089a0a69e739fYigit Boyar * @attr ref android.support.v7.cardview.R.styleable#CardView_cardPreventCornerOverlap 428c42ba8c000d1e6ce85e152dfc17089a0a69e739fYigit Boyar * @see #setUseCompatPadding(boolean) 429c42ba8c000d1e6ce85e152dfc17089a0a69e739fYigit Boyar */ 430c42ba8c000d1e6ce85e152dfc17089a0a69e739fYigit Boyar public void setPreventCornerOverlap(boolean preventCornerOverlap) { 431ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes if (preventCornerOverlap != mPreventCornerOverlap) { 432ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes mPreventCornerOverlap = preventCornerOverlap; 433ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes IMPL.onPreventCornerOverlapChanged(mCardViewDelegate); 434c42ba8c000d1e6ce85e152dfc17089a0a69e739fYigit Boyar } 435bdb07a1802c017efa64a5cfd8ab5a7ff4c4926b0Yigit Boyar } 436ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes 437ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes private final CardViewDelegate mCardViewDelegate = new CardViewDelegate() { 438ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes private Drawable mCardBackground; 439ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes 440ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes @Override 441ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes public void setCardBackground(Drawable drawable) { 442ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes mCardBackground = drawable; 443ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes setBackgroundDrawable(drawable); 444ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes } 445ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes 446ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes @Override 447ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes public boolean getUseCompatPadding() { 448ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes return CardView.this.getUseCompatPadding(); 449ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes } 450ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes 451ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes @Override 452ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes public boolean getPreventCornerOverlap() { 453ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes return CardView.this.getPreventCornerOverlap(); 454ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes } 455ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes 456ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes @Override 457ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes public void setShadowPadding(int left, int top, int right, int bottom) { 458ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes mShadowBounds.set(left, top, right, bottom); 459ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes CardView.super.setPadding(left + mContentPadding.left, top + mContentPadding.top, 460ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes right + mContentPadding.right, bottom + mContentPadding.bottom); 461ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes } 462ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes 463ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes @Override 464ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes public void setMinWidthHeightInternal(int width, int height) { 465ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes if (width > mUserSetMinWidth) { 466ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes CardView.super.setMinimumWidth(width); 467ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes } 468ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes if (height > mUserSetMinHeight) { 469ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes CardView.super.setMinimumHeight(height); 470ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes } 471ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes } 472ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes 473ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes @Override 474ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes public Drawable getCardBackground() { 475ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes return mCardBackground; 476ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes } 477ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes 478ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes @Override 479ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes public View getCardView() { 480ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes return CardView.this; 481ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes } 482ffbf42aa3acb41b82cc6c1226c63c3649bedfe49Chris Banes }; 483bc943f7fa746c149c5e4c3a4eed7febe494d5df5Yigit Boyar} 484