Пример #1
0
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    if (IMPL instanceof CardViewApi21 == false) {
      final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
      switch (widthMode) {
        case MeasureSpec.EXACTLY:
        case MeasureSpec.AT_MOST:
          final int minWidth = (int) Math.ceil(IMPL.getMinWidth(this));
          widthMeasureSpec =
              MeasureSpec.makeMeasureSpec(
                  Math.max(minWidth, MeasureSpec.getSize(widthMeasureSpec)), widthMode);
          break;
      }

      final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
      switch (heightMode) {
        case MeasureSpec.EXACTLY:
        case MeasureSpec.AT_MOST:
          final int minHeight = (int) Math.ceil(IMPL.getMinHeight(this));
          heightMeasureSpec =
              MeasureSpec.makeMeasureSpec(
                  Math.max(minHeight, MeasureSpec.getSize(heightMeasureSpec)), heightMode);
          break;
      }
      super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    } else {
      super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
  }
Пример #2
0
 /**
  * On pre-Lollipop platforms, CardView does not clip the bounds of the Card for the rounded
  * corners. Instead, it adds padding to content so that it won't overlap with the rounded corners.
  * You can disable this behavior by setting this field to <code>false</code>.
  *
  * <p>Setting this value on Lollipop and above does not have any effect unless you have enabled
  * compatibility padding.
  *
  * @param preventCornerOverlap Whether CardView should add extra padding to content to avoid
  *     overlaps with the CardView corners.
  * @attr ref android.support.v7.cardview.R.styleable#CardView_cardPreventCornerOverlap
  * @see #setUseCompatPadding(boolean)
  */
 public void setPreventCornerOverlap(boolean preventCornerOverlap) {
   if (preventCornerOverlap == mPreventCornerOverlap) {
     return;
   }
   mPreventCornerOverlap = preventCornerOverlap;
   IMPL.onPreventCornerOverlapChanged(this);
 }
Пример #3
0
 private void initialize(Context context, AttributeSet attrs, int defStyleAttr) {
   TypedArray a =
       context.obtainStyledAttributes(
           attrs, R.styleable.CardView, defStyleAttr, R.style.CardView_Light);
   int backgroundColor = a.getColor(R.styleable.CardView_cardBackgroundColor, 0);
   float radius = a.getDimension(R.styleable.CardView_cardCornerRadius, 0);
   float elevation = a.getDimension(R.styleable.CardView_cardElevation, 0);
   float maxElevation = a.getDimension(R.styleable.CardView_cardMaxElevation, 0);
   mCompatPadding = a.getBoolean(R.styleable.CardView_cardUseCompatPadding, false);
   mPreventCornerOverlap = a.getBoolean(R.styleable.CardView_cardPreventCornerOverlap, true);
   int defaultPadding = a.getDimensionPixelSize(R.styleable.CardView_contentPadding, 0);
   mContentPadding.left =
       a.getDimensionPixelSize(R.styleable.CardView_contentPaddingLeft, defaultPadding);
   mContentPadding.top =
       a.getDimensionPixelSize(R.styleable.CardView_contentPaddingTop, defaultPadding);
   mContentPadding.right =
       a.getDimensionPixelSize(R.styleable.CardView_contentPaddingRight, defaultPadding);
   mContentPadding.bottom =
       a.getDimensionPixelSize(R.styleable.CardView_contentPaddingBottom, defaultPadding);
   if (elevation > maxElevation) {
     maxElevation = elevation;
   }
   a.recycle();
   IMPL.initialize(this, context, backgroundColor, radius, elevation, maxElevation);
 }
Пример #4
0
 /**
  * CardView adds additional padding to draw shadows on platforms before Lollipop.
  *
  * <p>This may cause Cards to have different sizes between Lollipop and before Lollipop. If you
  * need to align CardView with other Views, you may need api version specific dimension resources
  * to account for the changes. As an alternative, you can set this flag to <code>true</code> and
  * CardView will add the same padding values on platforms Lollipop and after.
  *
  * <p>Since setting this flag to true adds unnecessary gaps in the UI, default value is <code>
  * false</code>.
  *
  * @param useCompatPadding <code>true></code> if CardView should add padding for the shadows on
  *     platforms Lollipop and above.
  * @attr ref android.support.v7.cardview.R.styleable#CardView_cardUseCompatPadding
  */
 public void setUseCompatPadding(boolean useCompatPadding) {
   if (mCompatPadding == useCompatPadding) {
     return;
   }
   mCompatPadding = useCompatPadding;
   IMPL.onCompatPaddingChanged(this);
 }
Пример #5
0
 static {
   if (Build.VERSION.SDK_INT >= 21) {
     IMPL = new CardViewApi21();
   } else if (Build.VERSION.SDK_INT >= 17) {
     IMPL = new CardViewJellybeanMr1();
   } else {
     IMPL = new CardViewEclairMr1();
   }
   IMPL.initStatic();
 }
Пример #6
0
 /**
  * Returns the backward compatible maximum elevation of the CardView.
  *
  * @return Maximum elevation of the CardView
  * @see #setMaxCardElevation(float)
  * @see #getCardElevation()
  */
 public float getMaxCardElevation() {
   return IMPL.getMaxElevation(this);
 }
Пример #7
0
 /**
  * Updates the backward compatible maximum elevation of the CardView.
  *
  * <p>Calling this method has no effect if device OS version is Lollipop or newer and {@link
  * #getUseCompatPadding()} is <code>false</code>.
  *
  * @param maxElevation The backward compatible maximum elevation in pixels.
  * @attr ref android.support.v7.cardview.R.styleable#CardView_cardMaxElevation
  * @see #setCardElevation(float)
  * @see #getMaxCardElevation()
  */
 public void setMaxCardElevation(float maxElevation) {
   IMPL.setMaxElevation(this, maxElevation);
 }
Пример #8
0
 /**
  * Updates the backward compatible elevation of the CardView.
  *
  * @param elevation The backward compatible elevation in pixels.
  * @attr ref android.support.v7.cardview.R.styleable#CardView_cardElevation
  * @see #getCardElevation()
  * @see #setMaxCardElevation(float)
  */
 public void setCardElevation(float elevation) {
   IMPL.setElevation(this, elevation);
 }
Пример #9
0
 /**
  * Returns the corner radius of the CardView.
  *
  * @return Corner radius of the CardView
  * @see #getRadius()
  */
 public float getRadius() {
   return IMPL.getRadius(this);
 }
Пример #10
0
 /**
  * Updates the corner radius of the CardView.
  *
  * @param radius The radius in pixels of the corners of the rectangle shape
  * @attr ref android.support.v7.cardview.R.styleable#CardView_cardCornerRadius
  * @see #setRadius(float)
  */
 public void setRadius(float radius) {
   IMPL.setRadius(this, radius);
 }
Пример #11
0
 /**
  * Updates the background color of the CardView
  *
  * @param color The new color to set for the card background
  * @attr ref android.support.v7.cardview.R.styleable#CardView_cardBackgroundColor
  */
 public void setCardBackgroundColor(int color) {
   IMPL.setBackgroundColor(this, color);
 }
Пример #12
0
 /**
  * Sets the padding between the Card's edges and the children of CardView.
  *
  * <p>Depending on platform version or {@link #getUseCompatPadding()} settings, CardView may
  * update these values before calling {@link android.view.View#setPadding(int, int, int, int)}.
  *
  * @param left The left padding in pixels
  * @param top The top padding in pixels
  * @param right The right padding in pixels
  * @param bottom The bottom padding in pixels
  * @attr ref android.support.v7.cardview.R.styleable#CardView_contentPadding
  * @attr ref android.support.v7.cardview.R.styleable#CardView_contentPaddingLeft
  * @attr ref android.support.v7.cardview.R.styleable#CardView_contentPaddingTop
  * @attr ref android.support.v7.cardview.R.styleable#CardView_contentPaddingRight
  * @attr ref android.support.v7.cardview.R.styleable#CardView_contentPaddingBottom
  */
 public void setContentPadding(int left, int top, int right, int bottom) {
   mContentPadding.set(left, top, right, bottom);
   IMPL.updatePadding(this);
 }