diff --git a/app/.gitignore b/app/.gitignore deleted file mode 100644 index 796b96d..0000000 --- a/app/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build diff --git a/app/build.gradle b/app/build.gradle deleted file mode 100644 index 5356db7..0000000 --- a/app/build.gradle +++ /dev/null @@ -1,40 +0,0 @@ -apply plugin: 'com.android.application' - -apply plugin: 'kotlin-android' - -apply plugin: 'kotlin-android-extensions' - -android { - compileSdkVersion 26 - defaultConfig { - applicationId "com.bigman.wmzx.customcardview" - minSdkVersion 14 - targetSdkVersion 26 - versionCode 1 - versionName "1.0" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - } - compileOptions { - targetCompatibility 1.8 - sourceCompatibility 1.8 - } -} - -dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" - implementation 'com.android.support:appcompat-v7:26.1.0' - implementation 'com.android.support.constraint:constraint-layout:1.1.2' - testImplementation 'junit:junit:4.12' - - implementation "com.zhy:autolayout:1.4.5" - - implementation project(':cardviewlibrary') - -} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro deleted file mode 100644 index f1b4245..0000000 --- a/app/proguard-rules.pro +++ /dev/null @@ -1,21 +0,0 @@ -# Add project specific ProGuard rules here. -# You can control the set of applied configuration files using the -# proguardFiles setting in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} - -# Uncomment this to preserve the line number information for -# debugging stack traces. -#-keepattributes SourceFile,LineNumberTable - -# If you keep the line number information, uncomment this to -# hide the original source file name. -#-renamesourcefileattribute SourceFile diff --git a/app/src/androidTest/java/com/bigman/wmzx/customcardview/ExampleInstrumentedTest.kt b/app/src/androidTest/java/com/bigman/wmzx/customcardview/ExampleInstrumentedTest.kt deleted file mode 100644 index 23b6193..0000000 --- a/app/src/androidTest/java/com/bigman/wmzx/customcardview/ExampleInstrumentedTest.kt +++ /dev/null @@ -1,24 +0,0 @@ -package com.bigman.wmzx.customcardview - -import android.support.test.InstrumentationRegistry -import android.support.test.runner.AndroidJUnit4 - -import org.junit.Test -import org.junit.runner.RunWith - -import org.junit.Assert.* - -/** - * Instrumented test, which will execute on an Android device. - * - * See [testing documentation](http://d.android.com/tools/testing). - */ -@RunWith(AndroidJUnit4::class) -class ExampleInstrumentedTest { - @Test - fun useAppContext() { - // Context of the app under test. - val appContext = InstrumentationRegistry.getTargetContext() - assertEquals("com.bigman.wmzx.customcardview", appContext.packageName) - } -} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml deleted file mode 100644 index 51cc899..0000000 --- a/app/src/main/AndroidManifest.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/java/com/bigman/wmzx/customcardview/MainActivity.kt b/app/src/main/java/com/bigman/wmzx/customcardview/MainActivity.kt deleted file mode 100644 index c8f8837..0000000 --- a/app/src/main/java/com/bigman/wmzx/customcardview/MainActivity.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.bigman.wmzx.customcardview - -import android.support.v7.app.AppCompatActivity -import android.os.Bundle - -class MainActivity : AppCompatActivity() { - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContentView(R.layout.activity_main) - } -} diff --git a/app/src/main/java/com/bigman/wmzx/customcardview/library/CardView.kt b/app/src/main/java/com/bigman/wmzx/customcardview/library/CardView.kt deleted file mode 100644 index 8af254b..0000000 --- a/app/src/main/java/com/bigman/wmzx/customcardview/library/CardView.kt +++ /dev/null @@ -1,488 +0,0 @@ -package com.bigman.wmzx.customcardview.library - -/* - * Copyright (C) 2014 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. - */ - -import android.content.Context -import android.content.res.ColorStateList -import android.graphics.Color -import android.graphics.Rect -import android.graphics.drawable.Drawable -import android.os.Build -import android.support.annotation.ColorInt -import android.util.AttributeSet -import android.view.View -import android.widget.FrameLayout -import com.bigman.wmzx.customcardview.R - -/** - * A FrameLayout with a rounded corner background and shadow. - * - * - * CardView uses `elevation` property on Lollipop for shadows and falls back to a - * custom emulated shadow implementation on older platforms. - * - * - * Due to expensive nature of rounded corner clipping, on platforms before Lollipop, CardView does - * not clip its children that intersect with rounded corners. Instead, it adds padding to avoid such - * intersection (See [.setPreventCornerOverlap] to change this behavior). - * - * - * Before Lollipop, CardView adds padding to its content and draws shadows to that area. This - * padding amount is equal to `maxCardElevation + (1 - cos45) * cornerRadius` on the - * sides and `maxCardElevation * 1.5 + (1 - cos45) * cornerRadius` on top and bottom. - * - * - * Since padding is used to offset content for shadows, you cannot set padding on CardView. - * Instead, you can use content padding attributes in XML or - * [.setContentPadding] in code to set the padding between the edges of - * the CardView and children of CardView. - * - * - * Note that, if you specify exact dimensions for the CardView, because of the shadows, its content - * area will be different between platforms before Lollipop and after Lollipop. By using api version - * specific resource values, you can avoid these changes. Alternatively, If you want CardView to add - * inner padding on platforms Lollipop and after as well, you can call - * [.setUseCompatPadding] and pass `true`. - * - * - * To change CardView's elevation in a backward compatible way, use - * [.setCardElevation]. CardView will use elevation API on Lollipop and before - * Lollipop, it will change the shadow size. To avoid moving the View while shadow size is changing, - * shadow size is clamped by [.getMaxCardElevation]. If you want to change elevation - * dynamically, you should call [.setMaxCardElevation] when CardView is initialized. - * - * @attr ref android.support.v7.cardview.R.styleable#CardView_cardBackgroundColor - * @attr ref android.support.v7.cardview.R.styleable#CardView_cardCornerRadius - * @attr ref android.support.v7.cardview.R.styleable#CardView_cardElevation - * @attr ref android.support.v7.cardview.R.styleable#CardView_cardMaxElevation - * @attr ref android.support.v7.cardview.R.styleable#CardView_cardUseCompatPadding - * @attr ref android.support.v7.cardview.R.styleable#CardView_cardPreventCornerOverlap - * @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 - */ -class CardView : FrameLayout { - - private var mCompatPadding: Boolean = false - - private var mPreventCornerOverlap: Boolean = false - - /** - * CardView requires to have a particular minimum size to draw shadows before API 21. If - * developer also sets min width/height, they might be overridden. - * - * CardView works around this issue by recording user given parameters and using an internal - * method to set them. - */ - internal var mUserSetMinWidth: Int = 0 - internal var mUserSetMinHeight: Int = 0 - - internal val mContentPadding = Rect() - - internal val mShadowBounds = Rect() - - private var mEndColor: Int = 0 - - private var mStartColor: Int = 0 - - /** - * Returns whether CardView will add inner padding on platforms Lollipop and after. - * - * @return `true` if CardView adds inner padding on platforms Lollipop and after to - * have same dimensions with platforms before Lollipop. - */ - /** - * CardView adds additional padding to draw shadows on platforms before Lollipop. - * - * - * 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 `true` and CardView will add the same - * padding values on platforms Lollipop and after. - * - * - * Since setting this flag to true adds unnecessary gaps in the UI, default value is - * `false`. - * - * @param useCompatPadding `true>` if CardView should add padding for the shadows on - * platforms Lollipop and above. - * @attr ref android.support.v7.cardview.R.styleable#CardView_cardUseCompatPadding - */ - var useCompatPadding: Boolean - get() = mCompatPadding - set(useCompatPadding) { - if (mCompatPadding != useCompatPadding) { - mCompatPadding = useCompatPadding - IMPL.onCompatPaddingChanged(mCardViewDelegate) - } - } - - /** - * Returns the background color state list of the CardView. - * - * @return The background color state list of the CardView. - */ - val cardBackgroundColor: ColorStateList - get() = IMPL.getBackgroundColor(mCardViewDelegate) - - /** - * Returns the inner padding after the Card's left edge - * - * @return the inner padding after the Card's left edge - */ - val contentPaddingLeft: Int - get() = mContentPadding.left - - /** - * Returns the inner padding before the Card's right edge - * - * @return the inner padding before the Card's right edge - */ - val contentPaddingRight: Int - get() = mContentPadding.right - - /** - * Returns the inner padding after the Card's top edge - * - * @return the inner padding after the Card's top edge - */ - val contentPaddingTop: Int - get() = mContentPadding.top - - /** - * Returns the inner padding before the Card's bottom edge - * - * @return the inner padding before the Card's bottom edge - */ - val contentPaddingBottom: Int - get() = mContentPadding.bottom - - /** - * Returns the corner radius of the CardView. - * - * @return Corner radius of the CardView - * @see .getRadius - */ - /** - * 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 - */ - var radius: Float - get() = IMPL.getRadius(mCardViewDelegate) - set(radius) = IMPL.setRadius(mCardViewDelegate, radius) - - /** - * Returns the backward compatible elevation of the CardView. - * - * @return Elevation of the CardView - * @see .setCardElevation - * @see .getMaxCardElevation - */ - /** - * 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 - */ - var cardElevation: Float - get() = IMPL.getElevation(mCardViewDelegate) - set(elevation) = IMPL.setElevation(mCardViewDelegate, elevation) - - /** - * Returns the backward compatible maximum elevation of the CardView. - * - * @return Maximum elevation of the CardView - * @see .setMaxCardElevation - * @see .getCardElevation - */ - /** - * Updates the backward compatible maximum elevation of the CardView. - * - * - * Calling this method has no effect if device OS version is Lollipop or newer and - * [.getUseCompatPadding] is `false`. - * - * @param maxElevation The backward compatible maximum elevation in pixels. - * @attr ref android.support.v7.cardview.R.styleable#CardView_cardMaxElevation - * @see .setCardElevation - * @see .getMaxCardElevation - */ - var maxCardElevation: Float - get() = IMPL.getMaxElevation(mCardViewDelegate) - set(maxElevation) = IMPL.setMaxElevation(mCardViewDelegate, maxElevation) - - /** - * Returns whether CardView should add extra padding to content to avoid overlaps with rounded - * corners on pre-Lollipop platforms. - * - * @return True if CardView prevents overlaps with rounded corners on platforms before Lollipop. - * Default value is `true`. - */ - /** - * 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 `false`. - * - * - * 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 - */ - var preventCornerOverlap: Boolean - get() = mPreventCornerOverlap - set(preventCornerOverlap) { - if (preventCornerOverlap != mPreventCornerOverlap) { - mPreventCornerOverlap = preventCornerOverlap - IMPL.onPreventCornerOverlapChanged(mCardViewDelegate) - } - } - - private val mCardViewDelegate = object : CardViewDelegate { - private var mCardBackground: Drawable? = null - - override fun setCardBackground(drawable: Drawable) { - mCardBackground = drawable - setBackgroundDrawable(drawable) - } - - override fun getUseCompatPadding(): Boolean { - return this@CardView.useCompatPadding - } - - override fun getPreventCornerOverlap(): Boolean { - return this@CardView.preventCornerOverlap - } - - override fun setShadowPadding(left: Int, top: Int, right: Int, bottom: Int) { - mShadowBounds.set(left, top, right, bottom) - super@CardView.setPadding(left + mContentPadding.left, top + mContentPadding.top, - right + mContentPadding.right, bottom + mContentPadding.bottom) - } - - override fun setMinWidthHeightInternal(width: Int, height: Int) { - if (width > mUserSetMinWidth) { - super@CardView.setMinimumWidth(width) - } - if (height > mUserSetMinHeight) { - super@CardView.setMinimumHeight(height) - } - } - - override fun getCardBackground(): Drawable? { - return mCardBackground - } - - override fun getCardView(): View { - return this@CardView - } - } - - constructor(context: Context) : super(context) { - initialize(context, null, 0) - } - - constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { - initialize(context, attrs, 0) - } - - constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { - initialize(context, attrs, defStyleAttr) - } - - override fun setPadding(left: Int, top: Int, right: Int, bottom: Int) { - // NO OP - } - - override fun setPaddingRelative(start: Int, top: Int, end: Int, bottom: Int) { - // NO OP - } - - /** - * Sets the padding between the Card's edges and the children of CardView. - * - * - * Depending on platform version or [.getUseCompatPadding] settings, CardView may - * update these values before calling [View.setPadding]. - * - * @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 - */ - fun setContentPadding(left: Int, top: Int, right: Int, bottom: Int) { - mContentPadding.set(left, top, right, bottom) - IMPL.updatePadding(mCardViewDelegate) - } - - override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { - var widthMeasureSpec = widthMeasureSpec - var heightMeasureSpec = heightMeasureSpec - if (IMPL !is CardViewApi21Impl) { - val widthMode = View.MeasureSpec.getMode(widthMeasureSpec) - when (widthMode) { - View.MeasureSpec.EXACTLY, View.MeasureSpec.AT_MOST -> { - val minWidth = Math.ceil(IMPL.getMinWidth(mCardViewDelegate).toDouble()).toInt() - widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(Math.max(minWidth, - View.MeasureSpec.getSize(widthMeasureSpec)), widthMode) - } - View.MeasureSpec.UNSPECIFIED -> { - } - }// Do nothing - - val heightMode = View.MeasureSpec.getMode(heightMeasureSpec) - when (heightMode) { - View.MeasureSpec.EXACTLY, View.MeasureSpec.AT_MOST -> { - val minHeight = Math.ceil(IMPL.getMinHeight(mCardViewDelegate).toDouble()).toInt() - heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(Math.max(minHeight, - View.MeasureSpec.getSize(heightMeasureSpec)), heightMode) - } - View.MeasureSpec.UNSPECIFIED -> { - } - }// Do nothing - super.onMeasure(widthMeasureSpec, heightMeasureSpec) - } else { - super.onMeasure(widthMeasureSpec, heightMeasureSpec) - } - } - - private fun initialize(context: Context, attrs: AttributeSet?, defStyleAttr: Int) { - val a = context.obtainStyledAttributes(attrs, R.styleable.CardView, defStyleAttr, - R.style.CardView) - - - val backgroundColor: ColorStateList? - if (a.hasValue(R.styleable.CardView_cardBackgroundColor)) { - backgroundColor = a.getColorStateList(R.styleable.CardView_cardBackgroundColor) - } else { - // There isn't one set, so we'll compute one based on the theme - val aa = getContext().obtainStyledAttributes(COLOR_BACKGROUND_ATTR) - val themeColorBackground = aa.getColor(0, 0) - aa.recycle() - - // If the theme colorBackground is light, use our own light color, otherwise dark - val hsv = FloatArray(3) - Color.colorToHSV(themeColorBackground, hsv) - backgroundColor = ColorStateList.valueOf(if (hsv[2] > 0.5f) - resources.getColor(R.color.cardview_light_background) - else - resources.getColor(R.color.cardview_dark_background)) - } - val radius = a.getDimension(R.styleable.CardView_cardCornerRadius, 0f) - val elevation = a.getDimension(R.styleable.CardView_cardElevation, 0f) - var maxElevation = a.getDimension(R.styleable.CardView_cardMaxElevation, 0f) - mCompatPadding = a.getBoolean(R.styleable.CardView_cardUseCompatPadding, false) - mPreventCornerOverlap = a.getBoolean(R.styleable.CardView_cardPreventCornerOverlap, true) - val 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 - } - mUserSetMinWidth = a.getDimensionPixelSize(R.styleable.CardView_android_minWidth, 0) - mUserSetMinHeight = a.getDimensionPixelSize(R.styleable.CardView_android_minHeight, 0) - a.recycle() - - val a2 = context.obtainStyledAttributes(attrs, com.bigman.wmzx.customcardview.R.styleable.CardViewShadow) - val n = a2.indexCount - if (a2.hasValue(com.bigman.wmzx.customcardview.R.styleable.CardViewShadow_endColor) && a2.hasValue(com.bigman.wmzx.customcardview.R.styleable.CardViewShadow_startColor)) { - for (i in 0 until n) { - val attr = a.getIndex(i) - when (attr) { - com.bigman.wmzx.customcardview.R.styleable.CardViewShadow_endColor -> mEndColor = a.getColor(attr, resources.getColor(com.bigman.wmzx.customcardview.R.color.cardview_shadow_end_color)) - com.bigman.wmzx.customcardview.R.styleable.CardViewShadow_startColor -> mStartColor = a.getColor(attr, resources.getColor(com.bigman.wmzx.customcardview.R.color.cardview_shadow_start_color)) - } - - } - IMPL.initialize(mCardViewDelegate, context, backgroundColor, radius, - elevation, maxElevation, mStartColor, mEndColor) - } else { - IMPL.initialize(mCardViewDelegate, context, backgroundColor, radius, - elevation, maxElevation) - } - - - } - - override fun setMinimumWidth(minWidth: Int) { - mUserSetMinWidth = minWidth - super.setMinimumWidth(minWidth) - } - - override fun setMinimumHeight(minHeight: Int) { - mUserSetMinHeight = minHeight - super.setMinimumHeight(minHeight) - } - - /** - * 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 - */ - fun setCardBackgroundColor(@ColorInt color: Int) { - IMPL.setBackgroundColor(mCardViewDelegate, ColorStateList.valueOf(color)) - } - - /** - * Updates the background ColorStateList of the CardView - * - * @param color The new ColorStateList to set for the card background - * @attr ref android.support.v7.cardview.R.styleable#CardView_cardBackgroundColor - */ - fun setCardBackgroundColor(color: ColorStateList?) { - IMPL.setBackgroundColor(mCardViewDelegate, color) - } - - companion object { - - private val COLOR_BACKGROUND_ATTR = intArrayOf(android.R.attr.colorBackground) - private val IMPL: CardViewImpl = if (Build.VERSION.SDK_INT >= 17) { - CardViewApi17Impl() - } else { - CardViewBaseImpl() - } - - init { - IMPL.initStatic() - } - } -} - - diff --git a/app/src/main/java/com/bigman/wmzx/customcardview/library/CardViewApi17Impl.kt b/app/src/main/java/com/bigman/wmzx/customcardview/library/CardViewApi17Impl.kt deleted file mode 100644 index fc02233..0000000 --- a/app/src/main/java/com/bigman/wmzx/customcardview/library/CardViewApi17Impl.kt +++ /dev/null @@ -1,25 +0,0 @@ -package com.bigman.wmzx.customcardview.library - -import android.graphics.Canvas -import android.graphics.Paint -import android.graphics.RectF - - -/** - * create by bigman - * create date == 2018/7/10 - * create time == 15:48 - */ -internal class CardViewApi17Impl : CardViewBaseImpl() { - override fun initStatic() { - RoundRectDrawableWithShadow.sRoundRectHelper = object : RoundRectDrawableWithShadow.RoundRectHelper { - override fun drawRoundRect(canvas: Canvas, bounds: RectF, cornerRadius: Float, paint: Paint?) { - canvas.drawRoundRect(bounds, cornerRadius, cornerRadius, paint) - } - - - } - - } - -} \ No newline at end of file diff --git a/app/src/main/java/com/bigman/wmzx/customcardview/library/CardViewApi21Impl.kt b/app/src/main/java/com/bigman/wmzx/customcardview/library/CardViewApi21Impl.kt deleted file mode 100644 index a3989e2..0000000 --- a/app/src/main/java/com/bigman/wmzx/customcardview/library/CardViewApi21Impl.kt +++ /dev/null @@ -1,95 +0,0 @@ -package com.bigman.wmzx.customcardview.library - - -import android.content.Context -import android.content.res.ColorStateList -import android.support.annotation.RequiresApi - -@RequiresApi(21) -internal class CardViewApi21Impl : CardViewImpl { - - override fun initialize(cardView: CardViewDelegate, context: Context, - backgroundColor: ColorStateList, radius: Float, elevation: Float, maxElevation: Float) { - val background = RoundRectDrawable(backgroundColor, radius) - cardView.cardBackground = background - - val view = cardView.cardView - view.clipToOutline = true - view.elevation = elevation - setMaxElevation(cardView, maxElevation) - } - - override fun setRadius(cardView: CardViewDelegate, radius: Float) { - getCardBackground(cardView).radius = radius - } - - override fun initStatic() {} - - override fun setMaxElevation(cardView: CardViewDelegate, maxElevation: Float) { - getCardBackground(cardView).setPadding(maxElevation, - cardView.useCompatPadding, cardView.preventCornerOverlap) - updatePadding(cardView) - } - - override fun getMaxElevation(cardView: CardViewDelegate): Float { - return getCardBackground(cardView).padding - } - - override fun getMinWidth(cardView: CardViewDelegate): Float { - return getRadius(cardView) * 2 - } - - override fun getMinHeight(cardView: CardViewDelegate): Float { - return getRadius(cardView) * 2 - } - - override fun getRadius(cardView: CardViewDelegate): Float { - return getCardBackground(cardView).radius - } - - override fun setElevation(cardView: CardViewDelegate, elevation: Float) { - cardView.cardView.elevation = elevation - } - - override fun getElevation(cardView: CardViewDelegate): Float { - return cardView.cardView.elevation - } - - override fun updatePadding(cardView: CardViewDelegate) { - if (!cardView.useCompatPadding) { - cardView.setShadowPadding(0, 0, 0, 0) - return - } - val elevation = getMaxElevation(cardView) - val radius = getRadius(cardView) - val hPadding = Math.ceil(RoundRectDrawableWithShadow - .calculateHorizontalPadding(elevation, radius, cardView.preventCornerOverlap).toDouble()).toInt() - val vPadding = Math.ceil(RoundRectDrawableWithShadow - .calculateVerticalPadding(elevation, radius, cardView.preventCornerOverlap).toDouble()).toInt() - cardView.setShadowPadding(hPadding, vPadding, hPadding, vPadding) - } - - override fun onCompatPaddingChanged(cardView: CardViewDelegate) { - setMaxElevation(cardView, getMaxElevation(cardView)) - } - - override fun onPreventCornerOverlapChanged(cardView: CardViewDelegate) { - setMaxElevation(cardView, getMaxElevation(cardView)) - } - - override fun setBackgroundColor(cardView: CardViewDelegate, color: ColorStateList?) { - getCardBackground(cardView).color = color - } - - override fun getBackgroundColor(cardView: CardViewDelegate): ColorStateList { - return getCardBackground(cardView).color - } - - override fun initialize(cardViewDelegate: CardViewDelegate, context: Context, backgroundColor: ColorStateList, radius: Float, elevation: Float, maxElevation: Float, startColor: Int, endColor: Int) { - - } - - private fun getCardBackground(cardView: CardViewDelegate): RoundRectDrawable { - return cardView.cardBackground as RoundRectDrawable - } -} diff --git a/app/src/main/java/com/bigman/wmzx/customcardview/library/CardViewBaseImpl.java b/app/src/main/java/com/bigman/wmzx/customcardview/library/CardViewBaseImpl.java deleted file mode 100644 index c0bba5c..0000000 --- a/app/src/main/java/com/bigman/wmzx/customcardview/library/CardViewBaseImpl.java +++ /dev/null @@ -1,169 +0,0 @@ -package com.bigman.wmzx.customcardview.library; - -import android.content.Context; -import android.content.res.ColorStateList; -import android.graphics.Rect; -import android.graphics.RectF; -import android.support.annotation.Nullable; - - - -class CardViewBaseImpl implements CardViewImpl { - - private final RectF mCornerRect = new RectF(); - - @Override - public void initStatic() { - // Draws a round rect using 7 draw operations. This is faster than using - // canvas.drawRoundRect before JBMR1 because API 11-16 used alpha mask textures to draw - // shapes. - RoundRectDrawableWithShadow.Companion.setSRoundRectHelper((canvas, bounds, cornerRadius, paint) -> { - final float twoRadius = cornerRadius * 2; - final float innerWidth = bounds.width() - twoRadius - 1; - final float innerHeight = bounds.height() - twoRadius - 1; - if (cornerRadius >= 1f) { - // increment corner radius to account for half pixels. - float roundedCornerRadius = cornerRadius + .5f; - mCornerRect.set(-roundedCornerRadius, -roundedCornerRadius, roundedCornerRadius, - roundedCornerRadius); - int saved = canvas.save(); - canvas.translate(bounds.left + roundedCornerRadius, - bounds.top + roundedCornerRadius); - canvas.drawArc(mCornerRect, 180, 90, true, paint); - canvas.translate(innerWidth, 0); - canvas.rotate(90); - canvas.drawArc(mCornerRect, 180, 90, true, paint); - canvas.translate(innerHeight, 0); - canvas.rotate(90); - canvas.drawArc(mCornerRect, 180, 90, true, paint); - canvas.translate(innerWidth, 0); - canvas.rotate(90); - canvas.drawArc(mCornerRect, 180, 90, true, paint); - canvas.restoreToCount(saved); - //draw top and bottom pieces - canvas.drawRect(bounds.left + roundedCornerRadius - 1f, bounds.top, - bounds.right - roundedCornerRadius + 1f, - bounds.top + roundedCornerRadius, paint); - - canvas.drawRect(bounds.left + roundedCornerRadius - 1f, - bounds.bottom - roundedCornerRadius, - bounds.right - roundedCornerRadius + 1f, bounds.bottom, paint); - } - // center - canvas.drawRect(bounds.left, bounds.top + cornerRadius, - bounds.right, bounds.bottom - cornerRadius, paint); - }); - } - - @Override - public void initialize(CardViewDelegate cardView, Context context, - ColorStateList backgroundColor, float radius, float elevation, float maxElevation) { - RoundRectDrawableWithShadow background = createBackground(context, backgroundColor, radius, - elevation, maxElevation); - background.setAddPaddingForCorners(cardView.getPreventCornerOverlap()); - cardView.setCardBackground(background); - updatePadding(cardView); - } - - private RoundRectDrawableWithShadow createBackground(Context context, - ColorStateList backgroundColor, float radius, float elevation, - float maxElevation) { - return new RoundRectDrawableWithShadow(context.getResources(), backgroundColor, radius, - elevation, maxElevation); - } - - @Override - public void updatePadding(CardViewDelegate cardView) { - Rect shadowPadding = new Rect(); - getShadowBackground(cardView).getMaxShadowAndCornerPadding(shadowPadding); - cardView.setMinWidthHeightInternal((int) Math.ceil(getMinWidth(cardView)), - (int) Math.ceil(getMinHeight(cardView))); - cardView.setShadowPadding(shadowPadding.left, shadowPadding.top, - shadowPadding.right, shadowPadding.bottom); - } - - @Override - public void onCompatPaddingChanged(CardViewDelegate cardView) { - // NO OP - } - - @Override - public void onPreventCornerOverlapChanged(CardViewDelegate cardView) { - getShadowBackground(cardView).setAddPaddingForCorners(cardView.getPreventCornerOverlap()); - updatePadding(cardView); - } - - @Override - public void setBackgroundColor(CardViewDelegate cardView, @Nullable ColorStateList color) { - getShadowBackground(cardView).setColor(color); - } - - @Override - public ColorStateList getBackgroundColor(CardViewDelegate cardView) { - return getShadowBackground(cardView).getColor(); - } - - @Override - public void initialize(CardViewDelegate cardView, Context context, - ColorStateList backgroundColor, float radius, float elevation, - float maxElevation, int startColor, int endColor) { - RoundRectDrawableWithShadow background = createBackground(context, backgroundColor, radius, - elevation, maxElevation,startColor,endColor); - background.setAddPaddingForCorners(cardView.getPreventCornerOverlap()); - cardView.setCardBackground(background); - updatePadding(cardView); - } - - private RoundRectDrawableWithShadow createBackground(Context context, ColorStateList backgroundColor, - float radius, float elevation, float maxElevation, - int startColor, int endColor) { - return new RoundRectDrawableWithShadow(context.getResources(), backgroundColor, radius, - elevation, maxElevation,startColor,endColor); - } - - @Override - public void setRadius(CardViewDelegate cardView, float radius) { - getShadowBackground(cardView).setCornerRadius(radius); - updatePadding(cardView); - } - - @Override - public float getRadius(CardViewDelegate cardView) { - return getShadowBackground(cardView).getCornerRadius(); - } - - @Override - public void setElevation(CardViewDelegate cardView, float elevation) { - getShadowBackground(cardView).setShadowSize(elevation); - } - - @Override - public float getElevation(CardViewDelegate cardView) { - return getShadowBackground(cardView).getShadowSize(); - } - - @Override - public void setMaxElevation(CardViewDelegate cardView, float maxElevation) { - getShadowBackground(cardView).setMaxShadowSize(maxElevation); - updatePadding(cardView); - } - - @Override - public float getMaxElevation(CardViewDelegate cardView) { - return getShadowBackground(cardView).getMaxShadowSize(); - } - - @Override - public float getMinWidth(CardViewDelegate cardView) { - return getShadowBackground(cardView).getMinWidth(); - } - - @Override - public float getMinHeight(CardViewDelegate cardView) { - return getShadowBackground(cardView).getMinHeight(); - } - - private RoundRectDrawableWithShadow getShadowBackground(CardViewDelegate cardView) { - return ((RoundRectDrawableWithShadow) cardView.getCardBackground()); - } -} diff --git a/app/src/main/java/com/bigman/wmzx/customcardview/library/CardViewDelegate.java b/app/src/main/java/com/bigman/wmzx/customcardview/library/CardViewDelegate.java deleted file mode 100644 index 8d8b57a..0000000 --- a/app/src/main/java/com/bigman/wmzx/customcardview/library/CardViewDelegate.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.bigman.wmzx.customcardview.library; - -import android.graphics.drawable.Drawable; -import android.view.View; - -/** - * create by bigman - * create date == 2018/7/10 - * create time == 11:01 - */ - - interface CardViewDelegate { - void setCardBackground(Drawable drawable); - Drawable getCardBackground(); - boolean getUseCompatPadding(); - boolean getPreventCornerOverlap(); - void setShadowPadding(int left, int top, int right, int bottom); - void setMinWidthHeightInternal(int width, int height); - View getCardView(); -} diff --git a/app/src/main/java/com/bigman/wmzx/customcardview/library/CardViewImpl.kt b/app/src/main/java/com/bigman/wmzx/customcardview/library/CardViewImpl.kt deleted file mode 100644 index 992955d..0000000 --- a/app/src/main/java/com/bigman/wmzx/customcardview/library/CardViewImpl.kt +++ /dev/null @@ -1,41 +0,0 @@ -package com.bigman.wmzx.customcardview.library - -import android.content.Context -import android.content.res.ColorStateList - - -internal interface CardViewImpl { - fun initialize(cardView: CardViewDelegate, context: Context, backgroundColor: ColorStateList, - radius: Float, elevation: Float, maxElevation: Float) - - fun setRadius(cardView: CardViewDelegate, radius: Float) - - fun getRadius(cardView: CardViewDelegate): Float - - fun setElevation(cardView: CardViewDelegate, elevation: Float) - - fun getElevation(cardView: CardViewDelegate): Float - - fun initStatic() - - fun setMaxElevation(cardView: CardViewDelegate, maxElevation: Float) - - fun getMaxElevation(cardView: CardViewDelegate): Float - - fun getMinWidth(cardView: CardViewDelegate): Float - - fun getMinHeight(cardView: CardViewDelegate): Float - - fun updatePadding(cardView: CardViewDelegate) - - fun onCompatPaddingChanged(cardView: CardViewDelegate) - - fun onPreventCornerOverlapChanged(cardView: CardViewDelegate) - - fun setBackgroundColor(cardView: CardViewDelegate, color: ColorStateList?) - - fun getBackgroundColor(cardView: CardViewDelegate): ColorStateList - - fun initialize(cardViewDelegate: CardViewDelegate, context: Context, - backgroundColor: ColorStateList, radius: Float, elevation: Float, maxElevation: Float, startColor: Int, endColor: Int) -} diff --git a/app/src/main/java/com/bigman/wmzx/customcardview/library/RoundRectDrawable.java b/app/src/main/java/com/bigman/wmzx/customcardview/library/RoundRectDrawable.java deleted file mode 100644 index 1a3d750..0000000 --- a/app/src/main/java/com/bigman/wmzx/customcardview/library/RoundRectDrawable.java +++ /dev/null @@ -1,200 +0,0 @@ -package com.bigman.wmzx.customcardview.library; - - - - -import android.content.res.ColorStateList; -import android.graphics.Canvas; -import android.graphics.Color; -import android.graphics.ColorFilter; -import android.graphics.Outline; -import android.graphics.Paint; -import android.graphics.PixelFormat; -import android.graphics.PorterDuff; -import android.graphics.PorterDuffColorFilter; -import android.graphics.Rect; -import android.graphics.RectF; -import android.graphics.drawable.Drawable; -import android.support.annotation.Nullable; -import android.support.annotation.RequiresApi; - - -/** - * Very simple drawable that draws a rounded rectangle background with arbitrary corners and also - * reports proper outline for Lollipop. - *

- * Simpler and uses less resources compared to GradientDrawable or ShapeDrawable. - */ -@RequiresApi(21) -class RoundRectDrawable extends Drawable { - private float mRadius; - private final Paint mPaint; - private final RectF mBoundsF; - private final Rect mBoundsI; - private float mPadding; - private boolean mInsetForPadding = false; - private boolean mInsetForRadius = true; - - private ColorStateList mBackground; - private PorterDuffColorFilter mTintFilter; - private ColorStateList mTint; - private PorterDuff.Mode mTintMode = PorterDuff.Mode.SRC_IN; - - RoundRectDrawable(ColorStateList backgroundColor, float radius) { - mRadius = radius; - mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG); - setBackground(backgroundColor); - - mBoundsF = new RectF(); - mBoundsI = new Rect(); - } - - private void setBackground(ColorStateList color) { - mBackground = (color == null) ? ColorStateList.valueOf(Color.TRANSPARENT) : color; - mPaint.setColor(mBackground.getColorForState(getState(), mBackground.getDefaultColor())); - } - - void setPadding(float padding, boolean insetForPadding, boolean insetForRadius) { - if (padding == mPadding && mInsetForPadding == insetForPadding - && mInsetForRadius == insetForRadius) { - return; - } - mPadding = padding; - mInsetForPadding = insetForPadding; - mInsetForRadius = insetForRadius; - updateBounds(null); - invalidateSelf(); - } - - float getPadding() { - return mPadding; - } - - @Override - public void draw(Canvas canvas) { - final Paint paint = mPaint; - - final boolean clearColorFilter; - if (mTintFilter != null && paint.getColorFilter() == null) { - paint.setColorFilter(mTintFilter); - clearColorFilter = true; - } else { - clearColorFilter = false; - } - - canvas.drawRoundRect(mBoundsF, mRadius, mRadius, paint); - - if (clearColorFilter) { - paint.setColorFilter(null); - } - } - - private void updateBounds(Rect bounds) { - if (bounds == null) { - bounds = getBounds(); - } - mBoundsF.set(bounds.left, bounds.top, bounds.right, bounds.bottom); - mBoundsI.set(bounds); - if (mInsetForPadding) { - float vInset = RoundRectDrawableWithShadow.Companion.calculateVerticalPadding(mPadding, mRadius, mInsetForRadius); - float hInset = RoundRectDrawableWithShadow.Companion.calculateHorizontalPadding(mPadding, mRadius, mInsetForRadius); - mBoundsI.inset((int) Math.ceil(hInset), (int) Math.ceil(vInset)); - // to make sure they have same bounds. - mBoundsF.set(mBoundsI); - } - } - - @Override - protected void onBoundsChange(Rect bounds) { - super.onBoundsChange(bounds); - updateBounds(bounds); - } - - @Override - public void getOutline(Outline outline) { - outline.setRoundRect(mBoundsI, mRadius); - } - - void setRadius(float radius) { - if (radius == mRadius) { - return; - } - mRadius = radius; - updateBounds(null); - invalidateSelf(); - } - - @Override - public void setAlpha(int alpha) { - mPaint.setAlpha(alpha); - } - - @Override - public void setColorFilter(ColorFilter cf) { - mPaint.setColorFilter(cf); - } - - @Override - public int getOpacity() { - return PixelFormat.TRANSLUCENT; - } - - public float getRadius() { - return mRadius; - } - - public void setColor(@Nullable ColorStateList color) { - setBackground(color); - invalidateSelf(); - } - - public ColorStateList getColor() { - return mBackground; - } - - @Override - public void setTintList(ColorStateList tint) { - mTint = tint; - mTintFilter = createTintFilter(mTint, mTintMode); - invalidateSelf(); - } - - @Override - public void setTintMode(PorterDuff.Mode tintMode) { - mTintMode = tintMode; - mTintFilter = createTintFilter(mTint, mTintMode); - invalidateSelf(); - } - - @Override - protected boolean onStateChange(int[] stateSet) { - final int newColor = mBackground.getColorForState(stateSet, mBackground.getDefaultColor()); - final boolean colorChanged = newColor != mPaint.getColor(); - if (colorChanged) { - mPaint.setColor(newColor); - } - if (mTint != null && mTintMode != null) { - mTintFilter = createTintFilter(mTint, mTintMode); - return true; - } - return colorChanged; - } - - @Override - public boolean isStateful() { - return (mTint != null && mTint.isStateful()) - || (mBackground != null && mBackground.isStateful()) || super.isStateful(); - } - - /** - * Ensures the tint filter is consistent with the current tint color and - * mode. - */ - private PorterDuffColorFilter createTintFilter(ColorStateList tint, PorterDuff.Mode tintMode) { - if (tint == null || tintMode == null) { - return null; - } - final int color = tint.getColorForState(getState(), Color.TRANSPARENT); - return new PorterDuffColorFilter(color, tintMode); - } -} diff --git a/app/src/main/java/com/bigman/wmzx/customcardview/library/RoundRectDrawableWithShadow.kt b/app/src/main/java/com/bigman/wmzx/customcardview/library/RoundRectDrawableWithShadow.kt deleted file mode 100644 index 1c741c9..0000000 --- a/app/src/main/java/com/bigman/wmzx/customcardview/library/RoundRectDrawableWithShadow.kt +++ /dev/null @@ -1,365 +0,0 @@ -package com.bigman.wmzx.customcardview.library - - -import android.content.res.ColorStateList -import android.content.res.Resources -import android.graphics.* -import android.graphics.drawable.Drawable -import com.bigman.wmzx.customcardview.R - -/** - * A rounded rectangle drawable which also includes a shadow around. - */ -internal class RoundRectDrawableWithShadow : Drawable { - - private val mInsetShadow: Int // extra shadow to avoid gaps between card and shadow - - private var mPaint: Paint? = null - - private var mCornerShadowPaint: Paint? = null - - private var mEdgeShadowPaint: Paint? = null - - private val mCardBounds: RectF - - private var mCornerRadius: Float = 0.toFloat() - - private var mCornerShadowPath: Path? = null - - // actual value set by developer - private var mRawMaxShadowSize: Float = 0.toFloat() - - // multiplied value to account for shadow offset - private var mShadowSize: Float = 0.toFloat() - - // actual value set by developer - private var mRawShadowSize: Float = 0.toFloat() - - private var mBackground: ColorStateList? = null - - private var mDirty = true - - private val mShadowStartColor: Int - - private val mShadowEndColor: Int - - private var mAddPaddingForCorners = true - - /** - * If shadow size is set to a value above max shadow, we print a warning - */ - private var mPrintedShadowClipWarning = false - - var cornerRadius: Float - get() = mCornerRadius - set(radius) { - var radius = radius - if (radius < 0f) { - throw IllegalArgumentException("Invalid radius $radius. Must be >= 0") - } - radius = (radius + .5f).toInt().toFloat() - if (mCornerRadius == radius) { - return - } - mCornerRadius = radius - mDirty = true - invalidateSelf() - } - - var shadowSize: Float - get() = mRawShadowSize - set(size) = setShadowSize(size, mRawMaxShadowSize) - - var maxShadowSize: Float - get() = mRawMaxShadowSize - set(size) = setShadowSize(mRawShadowSize, size) - - val minWidth: Float - get() { - val content = 2 * Math.max(mRawMaxShadowSize, mCornerRadius + mInsetShadow.toFloat() + mRawMaxShadowSize / 2) - return content + (mRawMaxShadowSize + mInsetShadow) * 2 - } - - val minHeight: Float - get() { - val content = 2 * Math.max(mRawMaxShadowSize, mCornerRadius + mInsetShadow.toFloat() - + mRawMaxShadowSize * SHADOW_MULTIPLIER / 2) - return content + (mRawMaxShadowSize * SHADOW_MULTIPLIER + mInsetShadow) * 2 - } - - var color: ColorStateList? - get() = mBackground - set(color) { - setBackground(color) - invalidateSelf() - } - - constructor(resources: Resources, backgroundColor: ColorStateList, radius: Float, - shadowSize: Float, maxShadowSize: Float) { - mShadowStartColor = resources.getColor(R.color.cardview_shadow_start_color) - mShadowEndColor = resources.getColor(R.color.cardview_shadow_end_color) - mInsetShadow = resources.getDimensionPixelSize(R.dimen.cardview_compat_inset_shadow) - mPaint = Paint(Paint.ANTI_ALIAS_FLAG or Paint.DITHER_FLAG) - setBackground(backgroundColor) - mCornerShadowPaint = Paint(Paint.ANTI_ALIAS_FLAG or Paint.DITHER_FLAG) - mCornerShadowPaint!!.style = Paint.Style.FILL - mCornerRadius = (radius + .5f).toInt().toFloat() - mCardBounds = RectF() - mEdgeShadowPaint = Paint(mCornerShadowPaint) - mEdgeShadowPaint!!.isAntiAlias = false - setShadowSize(shadowSize, maxShadowSize) - } - - constructor(resources: Resources, backgroundColor: ColorStateList, - radius: Float, shadowSize: Float, maxShadowSize: Float, - startColor: Int, endColor: Int) { - mShadowStartColor = startColor - mShadowEndColor = endColor - mInsetShadow = resources.getDimensionPixelSize(R.dimen.cardview_compat_inset_shadow) - mPaint = Paint(Paint.ANTI_ALIAS_FLAG or Paint.DITHER_FLAG) - setBackground(backgroundColor) - mCornerShadowPaint = Paint(Paint.ANTI_ALIAS_FLAG or Paint.DITHER_FLAG) - mCornerShadowPaint!!.style = Paint.Style.FILL - mCornerRadius = (radius + .5f).toInt().toFloat() - mCardBounds = RectF() - mEdgeShadowPaint = Paint(mCornerShadowPaint) - mEdgeShadowPaint!!.isAntiAlias = false - setShadowSize(shadowSize, maxShadowSize) - } - - private fun setBackground(color: ColorStateList?) { - mBackground = color ?: ColorStateList.valueOf(Color.TRANSPARENT) - mPaint!!.color = mBackground!!.getColorForState(state, mBackground!!.defaultColor) - } - - /** - * Casts the value to an even integer. - */ - private fun toEven(value: Float): Int { - val i = (value + .5f).toInt() - return if (i % 2 == 1) { - i - 1 - } else i - } - - fun setAddPaddingForCorners(addPaddingForCorners: Boolean) { - mAddPaddingForCorners = addPaddingForCorners - invalidateSelf() - } - - override fun setAlpha(alpha: Int) { - mPaint!!.alpha = alpha - mCornerShadowPaint!!.alpha = alpha - mEdgeShadowPaint!!.alpha = alpha - } - - override fun onBoundsChange(bounds: Rect) { - super.onBoundsChange(bounds) - mDirty = true - } - - private fun setShadowSize(shadowSize: Float, maxShadowSize: Float) { - var shadowSize = shadowSize - var maxShadowSize = maxShadowSize - if (shadowSize < 0f) { - throw IllegalArgumentException("Invalid shadow size " + shadowSize - + ". Must be >= 0") - } - if (maxShadowSize < 0f) { - throw IllegalArgumentException("Invalid max shadow size " + maxShadowSize - + ". Must be >= 0") - } - shadowSize = toEven(shadowSize).toFloat() - maxShadowSize = toEven(maxShadowSize).toFloat() - if (shadowSize > maxShadowSize) { - shadowSize = maxShadowSize - if (!mPrintedShadowClipWarning) { - mPrintedShadowClipWarning = true - } - } - if (mRawShadowSize == shadowSize && mRawMaxShadowSize == maxShadowSize) { - return - } - mRawShadowSize = shadowSize - mRawMaxShadowSize = maxShadowSize - mShadowSize = (shadowSize * SHADOW_MULTIPLIER + mInsetShadow.toFloat() + .5f).toInt().toFloat() - mDirty = true - invalidateSelf() - } - - override fun getPadding(padding: Rect): Boolean { - val vOffset = Math.ceil(calculateVerticalPadding(mRawMaxShadowSize, mCornerRadius, - mAddPaddingForCorners).toDouble()).toInt() - val hOffset = Math.ceil(calculateHorizontalPadding(mRawMaxShadowSize, mCornerRadius, - mAddPaddingForCorners).toDouble()).toInt() - padding.set(hOffset, vOffset, hOffset, vOffset) - return true - } - - override fun onStateChange(stateSet: IntArray): Boolean { - val newColor = mBackground!!.getColorForState(stateSet, mBackground!!.defaultColor) - if (mPaint!!.color == newColor) { - return false - } - mPaint!!.color = newColor - mDirty = true - invalidateSelf() - return true - } - - override fun isStateful(): Boolean { - return mBackground != null && mBackground!!.isStateful || super.isStateful() - } - - override fun setColorFilter(cf: ColorFilter?) { - mPaint!!.colorFilter = cf - } - - override fun getOpacity(): Int { - return PixelFormat.TRANSLUCENT - } - - override fun draw(canvas: Canvas) { - if (mDirty) { - buildComponents(bounds) - mDirty = false - } - canvas.translate(0f, mRawShadowSize / 2) - drawShadow(canvas) - canvas.translate(0f, -mRawShadowSize / 2) - sRoundRectHelper!!.drawRoundRect(canvas, mCardBounds, mCornerRadius, mPaint) - } - - private fun drawShadow(canvas: Canvas) { - val edgeShadowTop = -mCornerRadius - mShadowSize - val inset = mCornerRadius + mInsetShadow.toFloat() + mRawShadowSize / 2 - val drawHorizontalEdges = mCardBounds.width() - 2 * inset > 0 - val drawVerticalEdges = mCardBounds.height() - 2 * inset > 0 - // LT - var saved = canvas.save() - canvas.translate(mCardBounds.left + inset, mCardBounds.top + inset) - canvas.drawPath(mCornerShadowPath!!, mCornerShadowPaint!!) - if (drawHorizontalEdges) { - canvas.drawRect(0f, edgeShadowTop, - mCardBounds.width() - 2 * inset, -mCornerRadius, - mEdgeShadowPaint!!) - } - canvas.restoreToCount(saved) - // RB - saved = canvas.save() - canvas.translate(mCardBounds.right - inset, mCardBounds.bottom - inset) - canvas.rotate(180f) - canvas.drawPath(mCornerShadowPath!!, mCornerShadowPaint!!) - if (drawHorizontalEdges) { - canvas.drawRect(0f, edgeShadowTop, - mCardBounds.width() - 2 * inset, -mCornerRadius + mShadowSize, - mEdgeShadowPaint!!) - } - canvas.restoreToCount(saved) - // LB - saved = canvas.save() - canvas.translate(mCardBounds.left + inset, mCardBounds.bottom - inset) - canvas.rotate(270f) - canvas.drawPath(mCornerShadowPath!!, mCornerShadowPaint!!) - if (drawVerticalEdges) { - canvas.drawRect(0f, edgeShadowTop, - mCardBounds.height() - 2 * inset, -mCornerRadius, mEdgeShadowPaint!!) - } - canvas.restoreToCount(saved) - // RT - saved = canvas.save() - canvas.translate(mCardBounds.right - inset, mCardBounds.top + inset) - canvas.rotate(90f) - canvas.drawPath(mCornerShadowPath!!, mCornerShadowPaint!!) - if (drawVerticalEdges) { - canvas.drawRect(0f, edgeShadowTop, - mCardBounds.height() - 2 * inset, -mCornerRadius, mEdgeShadowPaint!!) - } - canvas.restoreToCount(saved) - } - - private fun buildShadowCorners() { - val innerBounds = RectF(-mCornerRadius, -mCornerRadius, mCornerRadius, mCornerRadius) - val outerBounds = RectF(innerBounds) - outerBounds.inset(-mShadowSize, -mShadowSize) - - if (mCornerShadowPath == null) { - mCornerShadowPath = Path() - } else { - mCornerShadowPath!!.reset() - } - mCornerShadowPath!!.fillType = Path.FillType.EVEN_ODD - mCornerShadowPath!!.moveTo(-mCornerRadius, 0f) - mCornerShadowPath!!.rLineTo(-mShadowSize, 0f) - // outer arc - mCornerShadowPath!!.arcTo(outerBounds, 180f, 90f, false) - // inner arc - mCornerShadowPath!!.arcTo(innerBounds, 270f, -90f, false) - mCornerShadowPath!!.close() - val startRatio = mCornerRadius / (mCornerRadius + mShadowSize) - mCornerShadowPaint!!.shader = RadialGradient(0f, 0f, mCornerRadius + mShadowSize, - intArrayOf(mShadowStartColor, mShadowStartColor, mShadowEndColor), - floatArrayOf(0f, startRatio, 1f), - Shader.TileMode.CLAMP) - - // we offset the content shadowSize/2 pixels up to make it more realistic. - // this is why edge shadow shader has some extra space - // When drawing bottom edge shadow, we use that extra space. - mEdgeShadowPaint!!.shader = LinearGradient(0f, -mCornerRadius + mShadowSize, 0f, - -mCornerRadius - mShadowSize, - intArrayOf(mShadowStartColor, mShadowStartColor, mShadowEndColor), - floatArrayOf(0f, .5f, 1f), Shader.TileMode.CLAMP) - mEdgeShadowPaint!!.isAntiAlias = false - } - - private fun buildComponents(bounds: Rect) { - // Card is offset SHADOW_MULTIPLIER * maxShadowSize to account for the shadow shift. - // We could have different top-bottom offsets to avoid extra gap above but in that case - // center aligning Views inside the CardView would be problematic. - val verticalOffset = mRawMaxShadowSize * SHADOW_MULTIPLIER - mCardBounds.set(bounds.left + mRawMaxShadowSize, bounds.top + verticalOffset, - bounds.right - mRawMaxShadowSize, bounds.bottom - verticalOffset) - buildShadowCorners() - } - - fun getMaxShadowAndCornerPadding(into: Rect) { - getPadding(into) - } - - internal interface RoundRectHelper { - fun drawRoundRect(canvas: Canvas, bounds: RectF, cornerRadius: Float, paint: Paint?) - } - - companion object { - // used to calculate content padding - private val COS_45 = Math.cos(Math.toRadians(45.0)) - - private val SHADOW_MULTIPLIER = 1.5f - - /* - * This helper is set by CardView implementations. - *

- * Prior to API 17, canvas.drawRoundRect is expensive; which is why we need this interface - * to draw efficient rounded rectangles before 17. - * */ - var sRoundRectHelper: RoundRectHelper? = null - - fun calculateVerticalPadding(maxShadowSize: Float, cornerRadius: Float, - addPaddingForCorners: Boolean): Float { - return if (addPaddingForCorners) { - (maxShadowSize * SHADOW_MULTIPLIER + (1 - COS_45) * cornerRadius).toFloat() - } else { - maxShadowSize * SHADOW_MULTIPLIER - } - } - - fun calculateHorizontalPadding(maxShadowSize: Float, cornerRadius: Float, - addPaddingForCorners: Boolean): Float { - return if (addPaddingForCorners) { - (maxShadowSize + (1 - COS_45) * cornerRadius).toFloat() - } else { - maxShadowSize - } - } - } -} diff --git a/app/src/main/res/drawable-v24/green_bg.xml b/app/src/main/res/drawable-v24/green_bg.xml deleted file mode 100644 index a906e92..0000000 --- a/app/src/main/res/drawable-v24/green_bg.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - \ No newline at end of file diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml deleted file mode 100644 index c7bd21d..0000000 --- a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - diff --git a/app/src/main/res/drawable-v24/shape_round_orange_bg.xml b/app/src/main/res/drawable-v24/shape_round_orange_bg.xml deleted file mode 100644 index 1c831c8..0000000 --- a/app/src/main/res/drawable-v24/shape_round_orange_bg.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml deleted file mode 100644 index d5fccc5..0000000 --- a/app/src/main/res/drawable/ic_launcher_background.xml +++ /dev/null @@ -1,170 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml deleted file mode 100644 index e9925c3..0000000 --- a/app/src/main/res/layout/activity_main.xml +++ /dev/null @@ -1,340 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml deleted file mode 100644 index eca70cf..0000000 --- a/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml deleted file mode 100644 index eca70cf..0000000 --- a/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.png b/app/src/main/res/mipmap-hdpi/ic_launcher.png deleted file mode 100644 index a2f5908..0000000 Binary files a/app/src/main/res/mipmap-hdpi/ic_launcher.png and /dev/null differ diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_round.png b/app/src/main/res/mipmap-hdpi/ic_launcher_round.png deleted file mode 100644 index 1b52399..0000000 Binary files a/app/src/main/res/mipmap-hdpi/ic_launcher_round.png and /dev/null differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.png b/app/src/main/res/mipmap-mdpi/ic_launcher.png deleted file mode 100644 index ff10afd..0000000 Binary files a/app/src/main/res/mipmap-mdpi/ic_launcher.png and /dev/null differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher_round.png b/app/src/main/res/mipmap-mdpi/ic_launcher_round.png deleted file mode 100644 index 115a4c7..0000000 Binary files a/app/src/main/res/mipmap-mdpi/ic_launcher_round.png and /dev/null differ diff --git a/app/src/main/res/mipmap-xhdpi/Thumbs.db b/app/src/main/res/mipmap-xhdpi/Thumbs.db deleted file mode 100644 index b918f5d..0000000 Binary files a/app/src/main/res/mipmap-xhdpi/Thumbs.db and /dev/null differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/app/src/main/res/mipmap-xhdpi/ic_launcher.png deleted file mode 100644 index dcd3cd8..0000000 Binary files a/app/src/main/res/mipmap-xhdpi/ic_launcher.png and /dev/null differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png deleted file mode 100644 index 459ca60..0000000 Binary files a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png and /dev/null differ diff --git a/app/src/main/res/mipmap-xhdpi/icon_arrow_black.png b/app/src/main/res/mipmap-xhdpi/icon_arrow_black.png deleted file mode 100644 index 821359f..0000000 Binary files a/app/src/main/res/mipmap-xhdpi/icon_arrow_black.png and /dev/null differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png deleted file mode 100644 index 8ca12fe..0000000 Binary files a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png and /dev/null differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png deleted file mode 100644 index 8e19b41..0000000 Binary files a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png and /dev/null differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png deleted file mode 100644 index b824ebd..0000000 Binary files a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png and /dev/null differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png deleted file mode 100644 index 4c19a13..0000000 Binary files a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png and /dev/null differ diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml deleted file mode 100644 index d66192e..0000000 --- a/app/src/main/res/values/attrs.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml deleted file mode 100644 index 02a6105..0000000 --- a/app/src/main/res/values/colors.xml +++ /dev/null @@ -1,128 +0,0 @@ - - - #FF6602 - #F66100 - #FF6602 - #ffffff - @android:color/black - - #FF6602 - #EF5F00 - - @android:color/transparent - #2B2B2B - #C3C3C3 - #8F8F8F - #E5E5E5 - #F3F3F3 - - #DDDDDD - #FF1010 - #EF0000 - #444444 - #3C3C3C - - #333333 - #666666 - #E9E9E9 - #7C7B7B - #D8D8D8 - #999999 - #1F1F1F - #111111 - #979797 - #D4D4D4 - #CC9900 - #FEFBFB - #FF4F4F - #008FEB - #80000000 - #50000000 - #F7F7F7 - #4F4F4F - #55000000 - #CCCCCC - #FAFAFA - #576F6F6F - #A4A4A4 - #F8F8F8 - #515151 - #787878 - #D9D9D9 - #B9B9B9 - #ABABAB - #B0B0B0 - #FF3B30 - #7F7F7F - #969696 - #577699 - #8C8C8C - #F6F5F4 - #0F0F0F - #17AA1C - #40B4B4B4 - #959595 - #CECECE - #EDEDEE - #0E0E0E - #DCDCDC - #4A4A4A - #3D3D3D - #CDCDCD - #808080 - #F66100 - #FF8E44 - #89A4C9 - #F3F3F5 - #191919 - #F4F4F4 - #5378AB - #9EA8EA - #FF8535 - #10FF8535 - #FFB63F - #818181 - #838383 - #959FA6 - #0f0f0f - #3F3F3F - #FF552E - #99000000 - #66000000 - #5A5A5A - #FFA467 - #ff444444 - #73FF6602 - #E3E3EC - #5B5B5B - #7F4A90E2 - #4990E2 - #6d6d6d - #FF5252 - #38197A - #EECC76 - #1C0B3A - #281744 - #F0F0F0 - #ECB408 - #DDA66F - #1A1A1A - #14FFFFFF - #FCF5FA - #F3ECE4 - #FF1313 - #848484 - #D0D0D0 - #F7F4EA - #727272 - #FFE89C - #FFD571 - #FEDAE4 - #E1E1E1 - #FFAD44 - #8DBEC4 - #F6F6F6 - #D2d2d2 - #F6F6F6 - - diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml deleted file mode 100644 index 9241604..0000000 --- a/app/src/main/res/values/strings.xml +++ /dev/null @@ -1,4 +0,0 @@ - - CustomCardView - 课程修改 - diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml deleted file mode 100644 index 0eb88fe..0000000 --- a/app/src/main/res/values/styles.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - diff --git a/app/src/test/java/com/bigman/wmzx/customcardview/ExampleUnitTest.kt b/app/src/test/java/com/bigman/wmzx/customcardview/ExampleUnitTest.kt deleted file mode 100644 index 78d7297..0000000 --- a/app/src/test/java/com/bigman/wmzx/customcardview/ExampleUnitTest.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.bigman.wmzx.customcardview - -import org.junit.Test - -import org.junit.Assert.* - -/** - * Example local unit test, which will execute on the development machine (host). - * - * See [testing documentation](http://d.android.com/tools/testing). - */ -class ExampleUnitTest { - @Test - fun addition_isCorrect() { - assertEquals(4, 2 + 2) - } -}