├── app ├── .gitignore ├── src │ └── main │ │ ├── res │ │ ├── values │ │ │ ├── strings.xml │ │ │ ├── colors.xml │ │ │ └── styles.xml │ │ ├── mipmap-hdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-anydpi-v26 │ │ │ ├── ic_launcher.xml │ │ │ └── ic_launcher_round.xml │ │ ├── drawable-v24 │ │ │ └── ic_launcher_foreground.xml │ │ ├── layout │ │ │ └── activity_main.xml │ │ └── drawable │ │ │ └── ic_launcher_background.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── top │ │ └── limuyang2 │ │ └── lshadowlayout │ │ └── MainActivity.kt ├── proguard-rules.pro └── build.gradle ├── shadowlayout-lib ├── .gitignore ├── src │ └── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ └── top │ │ │ └── limuyang2 │ │ │ └── shadowlayoutlib │ │ │ ├── ILayout.java │ │ │ ├── ShadowLinearLayout.java │ │ │ ├── ShadowConstraintLayout.java │ │ │ ├── ShadowFrameLayout.java │ │ │ ├── ShadowRelativeLayout.java │ │ │ └── LayoutHelper.java │ │ └── res │ │ └── values │ │ └── attrs.xml ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── screen └── demo.gif ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradle.properties ├── README_CN.md ├── .gitignore ├── gradlew.bat ├── README.md ├── gradlew └── LICENSE /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /shadowlayout-lib/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':shadowlayout-lib' 2 | -------------------------------------------------------------------------------- /screen/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/limuyang2/LShadowLayout/HEAD/screen/demo.gif -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | LShadowLayout 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/limuyang2/LShadowLayout/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/limuyang2/LShadowLayout/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/limuyang2/LShadowLayout/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/limuyang2/LShadowLayout/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/limuyang2/LShadowLayout/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/limuyang2/LShadowLayout/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/limuyang2/LShadowLayout/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/limuyang2/LShadowLayout/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/limuyang2/LShadowLayout/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/limuyang2/LShadowLayout/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/limuyang2/LShadowLayout/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /shadowlayout-lib/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #F29CB1 4 | #da8c9f 5 | #F19EC2 6 | 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri May 29 23:18:08 CST 2020 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /shadowlayout-lib/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-android-extensions' 4 | 5 | android { 6 | compileSdkVersion 28 7 | defaultConfig { 8 | applicationId "top.limuyang2.lshadowlayout" 9 | minSdkVersion 16 10 | targetSdkVersion 28 11 | versionCode 1 12 | versionName "1.0" 13 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 14 | } 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | } 22 | 23 | dependencies { 24 | implementation fileTree(dir: 'libs', include: ['*.jar']) 25 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" 26 | implementation 'androidx.constraintlayout:constraintlayout:2.0.0' 27 | implementation 'androidx.appcompat:appcompat:1.2.0' 28 | 29 | 30 | implementation project(path: ':shadowlayout-lib') 31 | } 32 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | org.gradle.daemon=true 20 | org.gradle.configureondemand=true 21 | org.gradle.parallel=true 22 | #android.useDeprecatedNdk=true 23 | #android.enableD8=true 24 | #android.enableD8.desugaring = false 25 | #android.enableR8=false 26 | # javaMaxHeapSize+512m 27 | org.gradle.jvmargs=-Xmx3072m 28 | org.gradle.caching=true 29 | android.useAndroidX=true 30 | android.enableJetifier=true 31 | 32 | kotlin.incremental=true -------------------------------------------------------------------------------- /shadowlayout-lib/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 28 5 | 6 | defaultConfig { 7 | minSdkVersion 16 8 | targetSdkVersion 28 9 | versionCode 1 10 | versionName "1.0.1" 11 | 12 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 13 | 14 | } 15 | 16 | buildTypes { 17 | release { 18 | minifyEnabled false 19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 20 | } 21 | } 22 | 23 | } 24 | 25 | dependencies { 26 | implementation fileTree(dir: 'libs', include: ['*.jar']) 27 | compileOnly 'androidx.constraintlayout:constraintlayout:2.0.0' 28 | 29 | compileOnly 'androidx.appcompat:appcompat:1.2.0' 30 | } 31 | 32 | // 打包源码jar 33 | task sourcesJar(type: Jar) { 34 | from android.sourceSets.main.java.srcDirs 35 | classifier = 'sources' 36 | } 37 | task javadoc(type: Javadoc) { 38 | failOnError false 39 | source = android.sourceSets.main.java.sourceFiles 40 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 41 | classpath += configurations.compile 42 | } 43 | 44 | // 打包文档jar 45 | task javadocJar(type: Jar, dependsOn: javadoc) { 46 | classifier = 'javadoc' 47 | from javadoc.destinationDir 48 | } 49 | 50 | artifacts { 51 | archives sourcesJar 52 | archives javadocJar 53 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/java/top/limuyang2/lshadowlayout/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package top.limuyang2.lshadowlayout 2 | 3 | import android.os.Bundle 4 | import android.widget.SeekBar 5 | import androidx.appcompat.app.AppCompatActivity 6 | import kotlinx.android.synthetic.main.activity_main.* 7 | 8 | class MainActivity : AppCompatActivity() { 9 | 10 | override fun onCreate(savedInstanceState: Bundle?) { 11 | super.onCreate(savedInstanceState) 12 | setContentView(R.layout.activity_main) 13 | 14 | alphaSeekBar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { 15 | override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { 16 | val value = progress / 100f 17 | shadowLinearLayout.shadowAlpha = value 18 | alphaValueTv.text = value.toString() 19 | } 20 | 21 | override fun onStartTrackingTouch(seekBar: SeekBar?) { 22 | } 23 | 24 | override fun onStopTrackingTouch(seekBar: SeekBar?) { 25 | } 26 | }) 27 | 28 | 29 | elevationSeekBar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { 30 | override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { 31 | shadowLinearLayout.shadowElevation = progress 32 | elevationValueTv.text = progress.toString() 33 | } 34 | 35 | override fun onStartTrackingTouch(seekBar: SeekBar?) { 36 | } 37 | 38 | override fun onStopTrackingTouch(seekBar: SeekBar?) { 39 | } 40 | }) 41 | 42 | 43 | radiusSeekBar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { 44 | override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { 45 | shadowLinearLayout.radius = progress 46 | radiusValueTv.text = progress.toString() 47 | } 48 | 49 | override fun onStartTrackingTouch(seekBar: SeekBar?) { 50 | } 51 | 52 | override fun onStopTrackingTouch(seekBar: SeekBar?) { 53 | } 54 | }) 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /README_CN.md: -------------------------------------------------------------------------------- 1 | [![](https://jitpack.io/v/limuyang2/LShadowLayout.svg)](https://jitpack.io/#limuyang2/LShadowLayout) 2 | [![License](https://img.shields.io/badge/license-Apache%202-4EB1BA.svg)](https://www.apache.org/licenses/LICENSE-2.0.html) 3 | # LShadowLayout 4 | 本控件提取自[QMUI](https://github.com/QMUI/QMUI_Android),可以调整控件阴影的 深浅、面积、以及圆角 5 | >在Android 4.4及以下版本,阴影无效 6 | 7 | ## 预览 8 | ![](https://github.com/limuyang2/LShadowLayout/blob/master/screen/demo.gif) 9 | 10 | ### demo下载地址 11 | [demo apk](https://www.lanzous.com/i1smf4f) 12 | 13 | ## 获取 14 | 先在 build.gradle 的 repositories 添加: 15 | ```gradle 16 | allprojects { 17 | repositories { 18 | ... 19 | maven { url 'https://jitpack.io' } 20 | } 21 | } 22 | ``` 23 | 24 | 再在dependencies添加: 25 | ```gradle 26 | dependencies { 27 | // AndroidX 28 | implementation 'com.github.limuyang2:LShadowLayout:1.0.6' 29 | } 30 | ``` 31 | 32 | **如果你使用 Android support,请使用以下添加:** 33 | 34 | ```gradle 35 | dependencies { 36 | implementation 'com.github.limuyang2:LShadowLayout:1.0.3' 37 | } 38 | ``` 39 | 40 | 41 | ## 使用 42 | 43 | 本库中已包含的控件有: 44 | ```ShadowLinearLayout```线性布局 45 | ```ShadowRelativeLayout```相对布局 46 | ```ShadowConstraintLayout```约束布局 47 | ```ShadowFrameLayout``` 48 | 仅需替换项目中对应的布局即可。 49 | 例如: 50 | ```xml 51 | 58 | 59 | 60 | ``` 61 | 更多属性请查看源码 62 | 63 | 64 | ## License 65 | ``` 66 | 2018 limuyang 67 | Licensed under the Apache License, Version 2.0 (the "License"); 68 | you may not use this file except in compliance with the License. 69 | You may obtain a copy of the License at 70 | 71 | http://www.apache.org/licenses/LICENSE-2.0 72 | 73 | Unless required by applicable law or agreed to in writing, software 74 | distributed under the License is distributed on an "AS IS" BASIS, 75 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 76 | See the License for the specific language governing permissions and 77 | limitations under the License. 78 | ``` 79 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | .DS_Store 3 | 4 | 5 | # Built application files 6 | *.apk 7 | *.ap_ 8 | gradle.properties 9 | 10 | # Files for the Dalvik VM 11 | *.dex 12 | 13 | # Java class files 14 | *.class 15 | 16 | # Generated files 17 | bin/ 18 | gen/ 19 | 20 | # Gradle files 21 | .gradle/ 22 | build/ 23 | /*/build/ 24 | 25 | # Local configuration file (sdk path, etc) 26 | local.properties 27 | 28 | # Proguard folder generated by Eclipse 29 | proguard/ 30 | 31 | # Log Files 32 | *.log 33 | 34 | 35 | 36 | # Built application files 37 | 38 | *.apk 39 | 40 | *.ap_ 41 | 42 | 43 | 44 | # Files for the ART/Dalvik VM 45 | 46 | *.dex 47 | 48 | 49 | 50 | # Java class files 51 | 52 | *.class 53 | 54 | 55 | 56 | # Generated files 57 | 58 | bin/ 59 | 60 | gen/ 61 | 62 | out/ 63 | 64 | 65 | 66 | # Gradle files 67 | 68 | .gradle/ 69 | 70 | build/ 71 | 72 | 73 | 74 | # Local configuration file (sdk path, etc) 75 | 76 | local.properties 77 | 78 | 79 | 80 | # Proguard folder generated by Eclipse 81 | 82 | proguard/ 83 | 84 | 85 | 86 | # Log Files 87 | 88 | *.log 89 | 90 | 91 | 92 | # Android Studio Navigation editor temp files 93 | 94 | .navigation/ 95 | 96 | 97 | 98 | # Android Studio captures folder 99 | 100 | captures/ 101 | 102 | 103 | 104 | # IntelliJ 105 | 106 | *.iml 107 | 108 | .idea/workspace.xml 109 | 110 | .idea/tasks.xml 111 | 112 | .idea/gradle.xml 113 | 114 | .idea/assetWizardSettings.xml 115 | 116 | .idea/dictionaries 117 | 118 | .idea/libraries 119 | 120 | .idea/caches 121 | 122 | 123 | 124 | # Keystore files 125 | 126 | # Uncomment the following line if you do not want to check your keystore files in. 127 | 128 | #*.jks 129 | 130 | 131 | 132 | # External native build folder generated in Android Studio 2.2 and later 133 | 134 | .externalNativeBuild 135 | 136 | 137 | 138 | # Google Services (e.g. APIs or Firebase) 139 | 140 | google-services.json 141 | 142 | 143 | 144 | # Freeline 145 | 146 | freeline.py 147 | 148 | freeline/ 149 | 150 | freeline_project_description.json 151 | 152 | 153 | 154 | # fastlane 155 | 156 | fastlane/report.xml 157 | 158 | fastlane/Preview.html 159 | 160 | fastlane/screenshots 161 | 162 | fastlane/test_output 163 | 164 | fastlane/readme.md 165 | .idea/ 166 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![](https://jitpack.io/v/limuyang2/LShadowLayout.svg)](https://jitpack.io/#limuyang2/LShadowLayout) 2 | [![License](https://img.shields.io/badge/license-Apache%202-4EB1BA.svg)](https://www.apache.org/licenses/LICENSE-2.0.html) 3 | # LShadowLayout 4 | ### [中文](https://github.com/limuyang2/LShadowLayout/blob/master/README_CN.md) 5 | This control is extracted from[QMUI](https://github.com/QMUI/QMUI_Android),You can adjust the depth, area, and fillet of the control's shadow 6 | >Invalid shadows in Android 4.4 and below 7 | 8 | ## Preview 9 | ![](https://github.com/limuyang2/LShadowLayout/blob/master/screen/demo.gif) 10 | 11 | ### Demo download link 12 | [demo apk](https://www.lanzous.com/i1smf4f) 13 | 14 | ## Obtain 15 | First add in the repositories of build.gradle : 16 | ```gradle 17 | allprojects { 18 | repositories { 19 | ... 20 | maven { url 'https://jitpack.io' } 21 | } 22 | } 23 | ``` 24 | 25 | Then add in dependencies: 26 | ```gradle 27 | dependencies { 28 | // AndroidX 29 | implementation 'com.github.limuyang2:LShadowLayout:1.0.7' 30 | 31 | 32 | implementation 'androidx.constraintlayout:constraintlayout:2.0.0' 33 | implementation 'androidx.appcompat:appcompat:1.2.0' 34 | } 35 | ``` 36 | **if you use `Android Support`,Please use the following:** 37 | 38 | ```gradle 39 | dependencies { 40 | implementation 'com.github.limuyang2:LShadowLayout:1.0.3' 41 | } 42 | ``` 43 | 44 | ## Use 45 | The controls already included in this library are: 46 | `ShadowLinearLayout` 47 | `ShadowRelativeLayout` 48 | `ShadowConstraintLayout` 49 | `ShadowFrameLayout` 50 | 51 | Simply replace the corresponding layout in the project. 52 | E.g: 53 | ```xml 54 | 61 | 62 | 63 | ``` 64 | More properties, please see the source code 65 | 66 | 67 | ## License 68 | ``` 69 | 2018 limuyang 70 | Licensed under the Apache License, Version 2.0 (the "License"); 71 | you may not use this file except in compliance with the License. 72 | You may obtain a copy of the License at 73 | 74 | http://www.apache.org/licenses/LICENSE-2.0 75 | 76 | Unless required by applicable law or agreed to in writing, software 77 | distributed under the License is distributed on an "AS IS" BASIS, 78 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 79 | See the License for the specific language governing permissions and 80 | limitations under the License. 81 | ``` 82 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 20 | 21 | 26 | 27 | 28 | 29 | 38 | 39 | 49 | 50 | 65 | 66 | 67 | 77 | 78 | 88 | 89 | 103 | 104 | 105 | 115 | 116 | 126 | 127 | 141 | 142 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /shadowlayout-lib/src/main/java/top/limuyang2/shadowlayoutlib/ILayout.java: -------------------------------------------------------------------------------- 1 | package top.limuyang2.shadowlayoutlib; 2 | 3 | 4 | import androidx.annotation.ColorInt; 5 | import androidx.annotation.IntDef; 6 | import androidx.annotation.IntRange; 7 | 8 | import java.lang.annotation.Retention; 9 | import java.lang.annotation.RetentionPolicy; 10 | 11 | /** 12 | * @author limuyang 13 | * @date 2018/8/14 14 | * @class describe 15 | */ 16 | public interface ILayout { 17 | int HIDE_RADIUS_SIDE_NONE = 0; 18 | int HIDE_RADIUS_SIDE_TOP = 1; 19 | int HIDE_RADIUS_SIDE_RIGHT = 2; 20 | int HIDE_RADIUS_SIDE_BOTTOM = 3; 21 | int HIDE_RADIUS_SIDE_LEFT = 4; 22 | 23 | @IntDef(value = { 24 | HIDE_RADIUS_SIDE_NONE, 25 | HIDE_RADIUS_SIDE_TOP, 26 | HIDE_RADIUS_SIDE_RIGHT, 27 | HIDE_RADIUS_SIDE_BOTTOM, 28 | HIDE_RADIUS_SIDE_LEFT}) 29 | @Retention(RetentionPolicy.SOURCE) 30 | @interface HideRadiusSide { 31 | } 32 | 33 | /** 34 | * limit the width of a layout 35 | * 36 | * @param widthLimit 37 | * @return 38 | */ 39 | boolean setWidthLimit(int widthLimit); 40 | 41 | /** 42 | * limit the height of a layout 43 | * 44 | * @param heightLimit 45 | * @return 46 | */ 47 | boolean setHeightLimit(int heightLimit); 48 | 49 | /** 50 | * use the shadow elevation from the theme 51 | */ 52 | void setUseThemeGeneralShadowElevation(); 53 | 54 | /** 55 | * determine if the outline contain the padding area, usually false 56 | * 57 | * @param outlineExcludePadding 58 | */ 59 | void setOutlineExcludePadding(boolean outlineExcludePadding); 60 | 61 | /** 62 | * See {@link android.view.View#setElevation(float)} 63 | * 64 | * @param elevation 65 | */ 66 | void setShadowElevation(int elevation); 67 | 68 | /** 69 | * @return 70 | */ 71 | int getShadowElevation(); 72 | 73 | /** 74 | * set the outline alpha, which will change the shadow 75 | * 76 | * @param shadowAlpha 77 | */ 78 | void setShadowAlpha(float shadowAlpha); 79 | 80 | /** 81 | * get the outline alpha we set 82 | * 83 | * @return 84 | */ 85 | float getShadowAlpha(); 86 | 87 | /** 88 | * set the layout radius 89 | * 90 | * @param radius 91 | */ 92 | void setRadius(int radius); 93 | 94 | /** 95 | * set the layout radius with one or none side been hidden 96 | * 97 | * @param radius 98 | * @param hideRadiusSide 99 | */ 100 | void setRadius(int radius, @LayoutHelper.HideRadiusSide int hideRadiusSide); 101 | 102 | /** 103 | * get the layout radius 104 | * 105 | * @return 106 | */ 107 | int getRadius(); 108 | 109 | /** 110 | * inset the outline if needed 111 | * 112 | * @param left 113 | * @param top 114 | * @param right 115 | * @param bottom 116 | */ 117 | void setOutlineInset(int left, int top, int right, int bottom); 118 | 119 | /** 120 | * the shadow elevation only work after L, so we provide a downgrading compatible solutions for android 4.x 121 | * usually we use border, but the border may be redundant for android L+. so will not show border default, 122 | * if your designer like the border exists with shadow, you can call setShowBorderOnlyBeforeL(false) 123 | * 124 | * @param showBorderOnlyBeforeL 125 | */ 126 | void setShowBorderOnlyBeforeL(boolean showBorderOnlyBeforeL); 127 | 128 | /** 129 | * in some case, we maybe hope the layout only have radius in one side. 130 | * but there is no convenient way to write the code like canvas.drawPath, 131 | * so we take another way that hide one radius side 132 | * 133 | * @param hideRadiusSide 134 | */ 135 | void setHideRadiusSide(@HideRadiusSide int hideRadiusSide); 136 | 137 | /** 138 | * get the side that we have hidden the radius 139 | * 140 | * @return 141 | */ 142 | int getHideRadiusSide(); 143 | 144 | /** 145 | * this method will determine the radius and shadow. 146 | * 147 | * @param radius 148 | * @param shadowElevation 149 | * @param shadowAlpha 150 | */ 151 | void setRadiusAndShadow(int radius, int shadowElevation, float shadowAlpha); 152 | 153 | /** 154 | * this method will determine the radius and shadow with one or none side be hidden 155 | * 156 | * @param radius 157 | * @param hideRadiusSide 158 | * @param shadowElevation 159 | * @param shadowAlpha 160 | */ 161 | void setRadiusAndShadow(int radius, @HideRadiusSide int hideRadiusSide, int shadowElevation, float shadowAlpha); 162 | 163 | /** 164 | * border color, if you don not set it, the layout will not draw the border 165 | * 166 | * @param borderColor 167 | */ 168 | void setBorderColor(@ColorInt int borderColor); 169 | 170 | /** 171 | * border width, default is 1px, usually no need to set 172 | * 173 | * @param borderWidth 174 | */ 175 | void setBorderWidth(int borderWidth); 176 | 177 | /** 178 | * config the top divider 179 | * 180 | * @param topInsetLeft 181 | * @param topInsetRight 182 | * @param topDividerHeight 183 | * @param topDividerColor 184 | */ 185 | void updateTopDivider(int topInsetLeft, int topInsetRight, int topDividerHeight, @ColorInt int topDividerColor); 186 | 187 | /** 188 | * config the bottom divider 189 | * 190 | * @param bottomInsetLeft 191 | * @param bottomInsetRight 192 | * @param bottomDividerHeight 193 | * @param bottomDividerColor 194 | */ 195 | void updateBottomDivider(int bottomInsetLeft, int bottomInsetRight, int bottomDividerHeight, @ColorInt int bottomDividerColor); 196 | 197 | /** 198 | * config the left divider 199 | * 200 | * @param leftInsetTop 201 | * @param leftInsetBottom 202 | * @param leftDividerWidth 203 | * @param leftDividerColor 204 | */ 205 | void updateLeftDivider(int leftInsetTop, int leftInsetBottom, int leftDividerWidth, @ColorInt int leftDividerColor); 206 | 207 | /** 208 | * config the right divider 209 | * 210 | * @param rightInsetTop 211 | * @param rightInsetBottom 212 | * @param rightDividerWidth 213 | * @param rightDividerColor 214 | */ 215 | void updateRightDivider(int rightInsetTop, int rightInsetBottom, int rightDividerWidth, @ColorInt int rightDividerColor); 216 | 217 | /** 218 | * show top divider, and hide others 219 | * 220 | * @param topInsetLeft 221 | * @param topInsetRight 222 | * @param topDividerHeight 223 | * @param topDividerColor 224 | */ 225 | void onlyShowTopDivider(int topInsetLeft, int topInsetRight, int topDividerHeight, @ColorInt int topDividerColor); 226 | 227 | /** 228 | * show bottom divider, and hide others 229 | * 230 | * @param bottomInsetLeft 231 | * @param bottomInsetRight 232 | * @param bottomDividerHeight 233 | * @param bottomDividerColor 234 | */ 235 | void onlyShowBottomDivider(int bottomInsetLeft, int bottomInsetRight, int bottomDividerHeight, @ColorInt int bottomDividerColor); 236 | 237 | /** 238 | * show left divider, and hide others 239 | * 240 | * @param leftInsetTop 241 | * @param leftInsetBottom 242 | * @param leftDividerWidth 243 | * @param leftDividerColor 244 | */ 245 | void onlyShowLeftDivider(int leftInsetTop, int leftInsetBottom, int leftDividerWidth, @ColorInt int leftDividerColor); 246 | 247 | /** 248 | * show right divider, and hide others 249 | * 250 | * @param rightInsetTop 251 | * @param rightInsetBottom 252 | * @param rightDividerWidth 253 | * @param rightDividerColor 254 | */ 255 | void onlyShowRightDivider(int rightInsetTop, int rightInsetBottom, int rightDividerWidth, @ColorInt int rightDividerColor); 256 | 257 | /** 258 | * after config the border, sometimes we need change the alpha of divider with animation, 259 | * so we provide a method to individually change the alpha 260 | * 261 | * @param dividerAlpha [0, 255] 262 | */ 263 | void setTopDividerAlpha(@IntRange(from = 0, to = 255) int dividerAlpha); 264 | 265 | /** 266 | * @param dividerAlpha [0, 255] 267 | */ 268 | void setBottomDividerAlpha(@IntRange(from = 0, to = 255) int dividerAlpha); 269 | 270 | /** 271 | * @param dividerAlpha [0, 255] 272 | */ 273 | void setLeftDividerAlpha(@IntRange(from = 0, to = 255) int dividerAlpha); 274 | 275 | /** 276 | * @param dividerAlpha [0, 255] 277 | */ 278 | void setRightDividerAlpha(@IntRange(from = 0, to = 255) int dividerAlpha); 279 | } 280 | -------------------------------------------------------------------------------- /shadowlayout-lib/src/main/java/top/limuyang2/shadowlayoutlib/ShadowLinearLayout.java: -------------------------------------------------------------------------------- 1 | package top.limuyang2.shadowlayoutlib; 2 | 3 | import android.content.Context; 4 | import android.graphics.Canvas; 5 | import android.util.AttributeSet; 6 | import android.widget.LinearLayout; 7 | 8 | import androidx.annotation.ColorInt; 9 | import androidx.annotation.IntRange; 10 | 11 | /** 12 | * @author limuyang 13 | * @date 2018/8/14 14 | * @class describe 15 | */ 16 | public class ShadowLinearLayout extends LinearLayout implements ILayout { 17 | private LayoutHelper mLayoutHelper; 18 | 19 | public ShadowLinearLayout(Context context) { 20 | this(context, null); 21 | } 22 | 23 | public ShadowLinearLayout(Context context, AttributeSet attrs) { 24 | this(context, attrs, 0); 25 | } 26 | 27 | public ShadowLinearLayout(Context context, AttributeSet attrs, int defStyleAttr) { 28 | super(context, attrs, defStyleAttr); 29 | init(context, attrs, defStyleAttr); 30 | } 31 | 32 | private void init(Context context, AttributeSet attrs, int defStyleAttr) { 33 | mLayoutHelper = new LayoutHelper(context, attrs, defStyleAttr, this); 34 | } 35 | 36 | @Override 37 | public void updateTopDivider(int topInsetLeft, int topInsetRight, int topDividerHeight, @ColorInt int topDividerColor) { 38 | mLayoutHelper.updateTopDivider(topInsetLeft, topInsetRight, topDividerHeight, topDividerColor); 39 | invalidate(); 40 | } 41 | 42 | @Override 43 | public void updateBottomDivider(int bottomInsetLeft, int bottomInsetRight, int bottomDividerHeight, @ColorInt int bottomDividerColor) { 44 | mLayoutHelper.updateBottomDivider(bottomInsetLeft, bottomInsetRight, bottomDividerHeight, bottomDividerColor); 45 | invalidate(); 46 | } 47 | 48 | @Override 49 | public void updateLeftDivider(int leftInsetTop, int leftInsetBottom, int leftDividerWidth, @ColorInt int leftDividerColor) { 50 | mLayoutHelper.updateLeftDivider(leftInsetTop, leftInsetBottom, leftDividerWidth, leftDividerColor); 51 | invalidate(); 52 | } 53 | 54 | @Override 55 | public void updateRightDivider(int rightInsetTop, int rightInsetBottom, int rightDividerWidth, @ColorInt int rightDividerColor) { 56 | mLayoutHelper.updateRightDivider(rightInsetTop, rightInsetBottom, rightDividerWidth, rightDividerColor); 57 | invalidate(); 58 | } 59 | 60 | @Override 61 | public void onlyShowTopDivider(int topInsetLeft, int topInsetRight, 62 | int topDividerHeight, @ColorInt int topDividerColor) { 63 | mLayoutHelper.onlyShowTopDivider(topInsetLeft, topInsetRight, topDividerHeight, topDividerColor); 64 | invalidate(); 65 | } 66 | 67 | @Override 68 | public void onlyShowBottomDivider(int bottomInsetLeft, int bottomInsetRight, 69 | int bottomDividerHeight, @ColorInt int bottomDividerColor) { 70 | mLayoutHelper.onlyShowBottomDivider(bottomInsetLeft, bottomInsetRight, bottomDividerHeight, bottomDividerColor); 71 | invalidate(); 72 | } 73 | 74 | @Override 75 | public void onlyShowLeftDivider(int leftInsetTop, int leftInsetBottom, int leftDividerWidth, @ColorInt int leftDividerColor) { 76 | mLayoutHelper.onlyShowLeftDivider(leftInsetTop, leftInsetBottom, leftDividerWidth, leftDividerColor); 77 | invalidate(); 78 | } 79 | 80 | @Override 81 | public void onlyShowRightDivider(int rightInsetTop, int rightInsetBottom, int rightDividerWidth, @ColorInt int rightDividerColor) { 82 | mLayoutHelper.onlyShowRightDivider(rightInsetTop, rightInsetBottom, rightDividerWidth, rightDividerColor); 83 | invalidate(); 84 | } 85 | 86 | @Override 87 | public void setTopDividerAlpha(@IntRange(from = 0, to = 255) int dividerAlpha) { 88 | mLayoutHelper.setTopDividerAlpha(dividerAlpha); 89 | invalidate(); 90 | } 91 | 92 | @Override 93 | public void setBottomDividerAlpha(@IntRange(from = 0, to = 255) int dividerAlpha) { 94 | mLayoutHelper.setBottomDividerAlpha(dividerAlpha); 95 | invalidate(); 96 | } 97 | 98 | @Override 99 | public void setLeftDividerAlpha(@IntRange(from = 0, to = 255) int dividerAlpha) { 100 | mLayoutHelper.setLeftDividerAlpha(dividerAlpha); 101 | invalidate(); 102 | } 103 | 104 | @Override 105 | public void setRightDividerAlpha(@IntRange(from = 0, to = 255) int dividerAlpha) { 106 | mLayoutHelper.setRightDividerAlpha(dividerAlpha); 107 | invalidate(); 108 | } 109 | 110 | @Override 111 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 112 | widthMeasureSpec = mLayoutHelper.getMeasuredWidthSpec(widthMeasureSpec); 113 | heightMeasureSpec = mLayoutHelper.getMeasuredHeightSpec(heightMeasureSpec); 114 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 115 | int minW = mLayoutHelper.handleMiniWidth(widthMeasureSpec, getMeasuredWidth()); 116 | int minH = mLayoutHelper.handleMiniHeight(heightMeasureSpec, getMeasuredHeight()); 117 | if (widthMeasureSpec != minW || heightMeasureSpec != minH) { 118 | super.onMeasure(minW, minH); 119 | } 120 | } 121 | 122 | @Override 123 | public void setRadiusAndShadow(int radius, int shadowElevation, float shadowAlpha) { 124 | mLayoutHelper.setRadiusAndShadow(radius, shadowElevation, shadowAlpha); 125 | } 126 | 127 | @Override 128 | public void setRadiusAndShadow(int radius, @LayoutHelper.HideRadiusSide int hideRadiusSide, int shadowElevation, float shadowAlpha) { 129 | mLayoutHelper.setRadiusAndShadow(radius, hideRadiusSide, shadowElevation, shadowAlpha); 130 | } 131 | 132 | @Override 133 | public void setRadius(int radius) { 134 | mLayoutHelper.setRadius(radius); 135 | } 136 | 137 | @Override 138 | public void setRadius(int radius, @LayoutHelper.HideRadiusSide int hideRadiusSide) { 139 | mLayoutHelper.setRadius(radius, hideRadiusSide); 140 | } 141 | 142 | @Override 143 | public int getRadius() { 144 | return mLayoutHelper.getRadius(); 145 | } 146 | 147 | @Override 148 | public void setOutlineInset(int left, int top, int right, int bottom) { 149 | mLayoutHelper.setOutlineInset(left, top, right, bottom); 150 | } 151 | 152 | @Override 153 | public void setBorderColor(@ColorInt int borderColor) { 154 | mLayoutHelper.setBorderColor(borderColor); 155 | invalidate(); 156 | } 157 | 158 | @Override 159 | public void setBorderWidth(int borderWidth) { 160 | mLayoutHelper.setBorderWidth(borderWidth); 161 | invalidate(); 162 | } 163 | 164 | @Override 165 | public void setShowBorderOnlyBeforeL(boolean showBorderOnlyBeforeL) { 166 | mLayoutHelper.setShowBorderOnlyBeforeL(showBorderOnlyBeforeL); 167 | invalidate(); 168 | } 169 | 170 | @Override 171 | public void setHideRadiusSide(@HideRadiusSide int hideRadiusSide) { 172 | mLayoutHelper.setHideRadiusSide(hideRadiusSide); 173 | } 174 | 175 | @Override 176 | public int getHideRadiusSide() { 177 | return mLayoutHelper.getHideRadiusSide(); 178 | } 179 | 180 | @Override 181 | public boolean setWidthLimit(int widthLimit) { 182 | if (mLayoutHelper.setWidthLimit(widthLimit)) { 183 | requestLayout(); 184 | invalidate(); 185 | } 186 | return true; 187 | } 188 | 189 | @Override 190 | public boolean setHeightLimit(int heightLimit) { 191 | if (mLayoutHelper.setHeightLimit(heightLimit)) { 192 | requestLayout(); 193 | invalidate(); 194 | } 195 | return true; 196 | } 197 | 198 | @Override 199 | public void setUseThemeGeneralShadowElevation() { 200 | mLayoutHelper.setUseThemeGeneralShadowElevation(); 201 | } 202 | 203 | @Override 204 | public void setOutlineExcludePadding(boolean outlineExcludePadding) { 205 | mLayoutHelper.setOutlineExcludePadding(outlineExcludePadding); 206 | } 207 | 208 | @Override 209 | public void setShadowElevation(int elevation) { 210 | mLayoutHelper.setShadowElevation(elevation); 211 | } 212 | 213 | @Override 214 | public int getShadowElevation() { 215 | return mLayoutHelper.getShadowElevation(); 216 | } 217 | 218 | @Override 219 | public void setShadowAlpha(float shadowAlpha) { 220 | mLayoutHelper.setShadowAlpha(shadowAlpha); 221 | } 222 | 223 | public void setOuterNormalColor(@ColorInt int color) { 224 | mLayoutHelper.setOuterNormalColor(color); 225 | } 226 | 227 | @Override 228 | public float getShadowAlpha() { 229 | return mLayoutHelper.getShadowAlpha(); 230 | } 231 | 232 | @Override 233 | protected void dispatchDraw(Canvas canvas) { 234 | super.dispatchDraw(canvas); 235 | mLayoutHelper.drawDividers(canvas, getWidth(), getHeight()); 236 | mLayoutHelper.dispatchRoundBorderDraw(canvas); 237 | } 238 | } 239 | -------------------------------------------------------------------------------- /shadowlayout-lib/src/main/java/top/limuyang2/shadowlayoutlib/ShadowConstraintLayout.java: -------------------------------------------------------------------------------- 1 | package top.limuyang2.shadowlayoutlib; 2 | 3 | import android.content.Context; 4 | import android.graphics.Canvas; 5 | import android.util.AttributeSet; 6 | 7 | import androidx.annotation.ColorInt; 8 | import androidx.annotation.IntRange; 9 | import androidx.constraintlayout.widget.ConstraintLayout; 10 | 11 | /** 12 | * @author limuyang 13 | * @date 2018/8/14 14 | * @class describe 15 | */ 16 | public class ShadowConstraintLayout extends ConstraintLayout implements ILayout { 17 | 18 | private LayoutHelper mLayoutHelper; 19 | 20 | public ShadowConstraintLayout(Context context) { 21 | this(context, null); 22 | } 23 | 24 | public ShadowConstraintLayout(Context context, AttributeSet attrs) { 25 | this(context, attrs, 0); 26 | } 27 | 28 | public ShadowConstraintLayout(Context context, AttributeSet attrs, int defStyleAttr) { 29 | super(context, attrs, defStyleAttr); 30 | init(context, attrs, defStyleAttr); 31 | } 32 | 33 | private void init(Context context, AttributeSet attrs, int defStyleAttr) { 34 | mLayoutHelper = new LayoutHelper(context, attrs, defStyleAttr, this); 35 | } 36 | 37 | @Override 38 | public void updateTopDivider(int topInsetLeft, int topInsetRight, int topDividerHeight, @ColorInt int topDividerColor) { 39 | mLayoutHelper.updateTopDivider(topInsetLeft, topInsetRight, topDividerHeight, topDividerColor); 40 | invalidate(); 41 | } 42 | 43 | @Override 44 | public void updateBottomDivider(int bottomInsetLeft, int bottomInsetRight, int bottomDividerHeight, @ColorInt int bottomDividerColor) { 45 | mLayoutHelper.updateBottomDivider(bottomInsetLeft, bottomInsetRight, bottomDividerHeight, bottomDividerColor); 46 | invalidate(); 47 | } 48 | 49 | @Override 50 | public void updateLeftDivider(int leftInsetTop, int leftInsetBottom, int leftDividerWidth, @ColorInt int leftDividerColor) { 51 | mLayoutHelper.updateLeftDivider(leftInsetTop, leftInsetBottom, leftDividerWidth, leftDividerColor); 52 | invalidate(); 53 | } 54 | 55 | @Override 56 | public void updateRightDivider(int rightInsetTop, int rightInsetBottom, int rightDividerWidth, @ColorInt int rightDividerColor) { 57 | mLayoutHelper.updateRightDivider(rightInsetTop, rightInsetBottom, rightDividerWidth, rightDividerColor); 58 | invalidate(); 59 | } 60 | 61 | @Override 62 | public void onlyShowTopDivider(int topInsetLeft, int topInsetRight, 63 | int topDividerHeight, @ColorInt int topDividerColor) { 64 | mLayoutHelper.onlyShowTopDivider(topInsetLeft, topInsetRight, topDividerHeight, topDividerColor); 65 | invalidate(); 66 | } 67 | 68 | public void onlyShowBottomDivider(int bottomInsetLeft, int bottomInsetRight, 69 | int bottomDividerHeight, @ColorInt int bottomDividerColor) { 70 | mLayoutHelper.onlyShowBottomDivider(bottomInsetLeft, bottomInsetRight, bottomDividerHeight, bottomDividerColor); 71 | invalidate(); 72 | } 73 | 74 | public void onlyShowLeftDivider(int leftInsetTop, int leftInsetBottom, int leftDividerWidth, @ColorInt int leftDividerColor) { 75 | mLayoutHelper.onlyShowLeftDivider(leftInsetTop, leftInsetBottom, leftDividerWidth, leftDividerColor); 76 | invalidate(); 77 | } 78 | 79 | public void onlyShowRightDivider(int rightInsetTop, int rightInsetBottom, int rightDividerWidth, @ColorInt int rightDividerColor) { 80 | mLayoutHelper.onlyShowRightDivider(rightInsetTop, rightInsetBottom, rightDividerWidth, rightDividerColor); 81 | invalidate(); 82 | } 83 | 84 | @Override 85 | public void setTopDividerAlpha(@IntRange(from = 0, to = 255) int dividerAlpha) { 86 | mLayoutHelper.setTopDividerAlpha(dividerAlpha); 87 | invalidate(); 88 | } 89 | 90 | @Override 91 | public void setBottomDividerAlpha(@IntRange(from = 0, to = 255) int dividerAlpha) { 92 | mLayoutHelper.setBottomDividerAlpha(dividerAlpha); 93 | invalidate(); 94 | } 95 | 96 | @Override 97 | public void setLeftDividerAlpha(@IntRange(from = 0, to = 255) int dividerAlpha) { 98 | mLayoutHelper.setLeftDividerAlpha(dividerAlpha); 99 | invalidate(); 100 | } 101 | 102 | @Override 103 | public void setRightDividerAlpha(@IntRange(from = 0, to = 255) int dividerAlpha) { 104 | mLayoutHelper.setRightDividerAlpha(dividerAlpha); 105 | invalidate(); 106 | } 107 | 108 | @Override 109 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 110 | widthMeasureSpec = mLayoutHelper.getMeasuredWidthSpec(widthMeasureSpec); 111 | heightMeasureSpec = mLayoutHelper.getMeasuredHeightSpec(heightMeasureSpec); 112 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 113 | int minW = mLayoutHelper.handleMiniWidth(widthMeasureSpec, getMeasuredWidth()); 114 | int minH = mLayoutHelper.handleMiniHeight(heightMeasureSpec, getMeasuredHeight()); 115 | if (widthMeasureSpec != minW || heightMeasureSpec != minH) { 116 | super.onMeasure(minW, minH); 117 | } 118 | } 119 | 120 | @Override 121 | public void setRadiusAndShadow(int topRadius, int shadowElevation, float shadowAlpha) { 122 | mLayoutHelper.setRadiusAndShadow(topRadius, shadowElevation, shadowAlpha); 123 | } 124 | 125 | @Override 126 | public void setRadiusAndShadow(int topRadius, @LayoutHelper.HideRadiusSide int hideRadiusSide, int shadowElevation, float shadowAlpha) { 127 | mLayoutHelper.setRadiusAndShadow(topRadius, hideRadiusSide, shadowElevation, shadowAlpha); 128 | } 129 | 130 | @Override 131 | public void setRadius(int radius) { 132 | mLayoutHelper.setRadius(radius); 133 | } 134 | 135 | @Override 136 | public void setRadius(int radius, @LayoutHelper.HideRadiusSide int hideRadiusSide) { 137 | mLayoutHelper.setRadius(radius, hideRadiusSide); 138 | } 139 | 140 | @Override 141 | public int getRadius() { 142 | return mLayoutHelper.getRadius(); 143 | } 144 | 145 | @Override 146 | public void setOutlineInset(int left, int top, int right, int bottom) { 147 | mLayoutHelper.setOutlineInset(left, top, right, bottom); 148 | } 149 | 150 | @Override 151 | public void setHideRadiusSide(@HideRadiusSide int hideRadiusSide) { 152 | mLayoutHelper.setHideRadiusSide(hideRadiusSide); 153 | } 154 | 155 | @Override 156 | public int getHideRadiusSide() { 157 | return mLayoutHelper.getHideRadiusSide(); 158 | } 159 | 160 | @Override 161 | public void setBorderColor(@ColorInt int borderColor) { 162 | mLayoutHelper.setBorderColor(borderColor); 163 | invalidate(); 164 | } 165 | 166 | @Override 167 | public void setBorderWidth(int borderWidth) { 168 | mLayoutHelper.setBorderWidth(borderWidth); 169 | invalidate(); 170 | } 171 | 172 | @Override 173 | public void setShowBorderOnlyBeforeL(boolean showBorderOnlyBeforeL) { 174 | mLayoutHelper.setShowBorderOnlyBeforeL(showBorderOnlyBeforeL); 175 | invalidate(); 176 | } 177 | 178 | @Override 179 | public boolean setWidthLimit(int widthLimit) { 180 | if (mLayoutHelper.setWidthLimit(widthLimit)) { 181 | requestLayout(); 182 | invalidate(); 183 | } 184 | return true; 185 | } 186 | 187 | @Override 188 | public boolean setHeightLimit(int heightLimit) { 189 | if (mLayoutHelper.setHeightLimit(heightLimit)) { 190 | requestLayout(); 191 | invalidate(); 192 | } 193 | return true; 194 | } 195 | 196 | @Override 197 | public void setUseThemeGeneralShadowElevation() { 198 | mLayoutHelper.setUseThemeGeneralShadowElevation(); 199 | } 200 | 201 | @Override 202 | public void setOutlineExcludePadding(boolean outlineExcludePadding) { 203 | mLayoutHelper.setOutlineExcludePadding(outlineExcludePadding); 204 | } 205 | 206 | @Override 207 | public void setShadowElevation(int elevation) { 208 | mLayoutHelper.setShadowElevation(elevation); 209 | } 210 | 211 | @Override 212 | public int getShadowElevation() { 213 | return mLayoutHelper.getShadowElevation(); 214 | } 215 | 216 | @Override 217 | public void setShadowAlpha(float shadowAlpha) { 218 | mLayoutHelper.setShadowAlpha(shadowAlpha); 219 | } 220 | 221 | public void setOuterNormalColor(@ColorInt int color) { 222 | mLayoutHelper.setOuterNormalColor(color); 223 | } 224 | 225 | @Override 226 | public float getShadowAlpha() { 227 | return mLayoutHelper.getShadowAlpha(); 228 | } 229 | 230 | @Override 231 | public void dispatchDraw(Canvas canvas) { 232 | super.dispatchDraw(canvas); 233 | mLayoutHelper.drawDividers(canvas, getWidth(), getHeight()); 234 | mLayoutHelper.dispatchRoundBorderDraw(canvas); 235 | } 236 | } 237 | -------------------------------------------------------------------------------- /shadowlayout-lib/src/main/java/top/limuyang2/shadowlayoutlib/ShadowFrameLayout.java: -------------------------------------------------------------------------------- 1 | package top.limuyang2.shadowlayoutlib; 2 | 3 | import android.content.Context; 4 | import android.graphics.Canvas; 5 | import android.util.AttributeSet; 6 | import android.widget.FrameLayout; 7 | 8 | import androidx.annotation.ColorInt; 9 | import androidx.annotation.IntRange; 10 | import androidx.annotation.NonNull; 11 | import androidx.annotation.Nullable; 12 | 13 | /** 14 | * @author 李沐阳 15 | * @date: 2020/5/28 16 | * @description: 17 | */ 18 | public class ShadowFrameLayout extends FrameLayout implements ILayout { 19 | 20 | private LayoutHelper mLayoutHelper; 21 | 22 | public ShadowFrameLayout(@NonNull Context context) { 23 | this(context, null); 24 | } 25 | 26 | public ShadowFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs) { 27 | this(context, attrs, 0); 28 | } 29 | 30 | public ShadowFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 31 | super(context, attrs, defStyleAttr); 32 | init(context, attrs, defStyleAttr); 33 | } 34 | 35 | private void init(Context context, AttributeSet attrs, int defStyleAttr) { 36 | mLayoutHelper = new LayoutHelper(context, attrs, defStyleAttr, this); 37 | } 38 | 39 | @Override 40 | public boolean setWidthLimit(int widthLimit) { 41 | if (mLayoutHelper.setWidthLimit(widthLimit)) { 42 | requestLayout(); 43 | invalidate(); 44 | } 45 | return true; 46 | } 47 | 48 | @Override 49 | public boolean setHeightLimit(int heightLimit) { 50 | if (mLayoutHelper.setHeightLimit(heightLimit)) { 51 | requestLayout(); 52 | invalidate(); 53 | } 54 | return true; 55 | } 56 | 57 | @Override 58 | public void setUseThemeGeneralShadowElevation() { 59 | mLayoutHelper.setUseThemeGeneralShadowElevation(); 60 | } 61 | 62 | @Override 63 | public void setOutlineExcludePadding(boolean outlineExcludePadding) { 64 | mLayoutHelper.setOutlineExcludePadding(outlineExcludePadding); 65 | } 66 | 67 | @Override 68 | public void setShadowElevation(int elevation) { 69 | mLayoutHelper.setShadowElevation(elevation); 70 | } 71 | 72 | @Override 73 | public int getShadowElevation() { 74 | return mLayoutHelper.getShadowElevation(); 75 | } 76 | 77 | @Override 78 | public void setShadowAlpha(float shadowAlpha) { 79 | mLayoutHelper.setShadowAlpha(shadowAlpha); 80 | } 81 | 82 | @Override 83 | public float getShadowAlpha() { 84 | return mLayoutHelper.getShadowAlpha(); 85 | } 86 | 87 | @Override 88 | public void setRadius(int radius) { 89 | mLayoutHelper.setRadius(radius); 90 | } 91 | 92 | @Override 93 | public void setRadius(int radius, @LayoutHelper.HideRadiusSide int hideRadiusSide) { 94 | mLayoutHelper.setRadius(radius, hideRadiusSide); 95 | } 96 | 97 | @Override 98 | public int getRadius() { 99 | return mLayoutHelper.getRadius(); 100 | } 101 | 102 | @Override 103 | public void setOutlineInset(int left, int top, int right, int bottom) { 104 | mLayoutHelper.setOutlineInset(left, top, right, bottom); 105 | } 106 | 107 | @Override 108 | public void setShowBorderOnlyBeforeL(boolean showBorderOnlyBeforeL) { 109 | mLayoutHelper.setShowBorderOnlyBeforeL(showBorderOnlyBeforeL); 110 | invalidate(); 111 | } 112 | 113 | @Override 114 | public void setHideRadiusSide(@HideRadiusSide int hideRadiusSide) { 115 | mLayoutHelper.setHideRadiusSide(hideRadiusSide); 116 | } 117 | 118 | @Override 119 | public int getHideRadiusSide() { 120 | return mLayoutHelper.getHideRadiusSide(); 121 | } 122 | 123 | @Override 124 | public void setRadiusAndShadow(int radius, int shadowElevation, float shadowAlpha) { 125 | mLayoutHelper.setRadiusAndShadow(radius, shadowElevation, shadowAlpha); 126 | } 127 | 128 | @Override 129 | public void setRadiusAndShadow(int radius, @ILayout.HideRadiusSide int hideRadiusSide, int shadowElevation, float shadowAlpha) { 130 | mLayoutHelper.setRadiusAndShadow(radius, hideRadiusSide, shadowElevation, shadowAlpha); 131 | } 132 | 133 | @Override 134 | public void setBorderColor(@ColorInt int borderColor) { 135 | mLayoutHelper.setBorderColor(borderColor); 136 | invalidate(); 137 | } 138 | 139 | @Override 140 | public void setBorderWidth(int borderWidth) { 141 | mLayoutHelper.setBorderWidth(borderWidth); 142 | invalidate(); 143 | } 144 | 145 | @Override 146 | public void updateTopDivider(int topInsetLeft, int topInsetRight, int topDividerHeight, @ColorInt int topDividerColor) { 147 | mLayoutHelper.updateTopDivider(topInsetLeft, topInsetRight, topDividerHeight, topDividerColor); 148 | invalidate(); 149 | } 150 | 151 | @Override 152 | public void updateBottomDivider(int bottomInsetLeft, int bottomInsetRight, int bottomDividerHeight, @ColorInt int bottomDividerColor) { 153 | mLayoutHelper.updateBottomDivider(bottomInsetLeft, bottomInsetRight, bottomDividerHeight, bottomDividerColor); 154 | invalidate(); 155 | } 156 | 157 | @Override 158 | public void updateLeftDivider(int leftInsetTop, int leftInsetBottom, int leftDividerWidth, @ColorInt int leftDividerColor) { 159 | mLayoutHelper.updateLeftDivider(leftInsetTop, leftInsetBottom, leftDividerWidth, leftDividerColor); 160 | invalidate(); 161 | } 162 | 163 | @Override 164 | public void updateRightDivider(int rightInsetTop, int rightInsetBottom, int rightDividerWidth, @ColorInt int rightDividerColor) { 165 | mLayoutHelper.updateRightDivider(rightInsetTop, rightInsetBottom, rightDividerWidth, rightDividerColor); 166 | invalidate(); 167 | } 168 | 169 | @Override 170 | public void onlyShowTopDivider(int topInsetLeft, int topInsetRight, int topDividerHeight, @ColorInt int topDividerColor) { 171 | mLayoutHelper.onlyShowTopDivider(topInsetLeft, topInsetRight, topDividerHeight, topDividerColor); 172 | invalidate(); 173 | } 174 | 175 | @Override 176 | public void onlyShowBottomDivider(int bottomInsetLeft, int bottomInsetRight, int bottomDividerHeight, @ColorInt int bottomDividerColor) { 177 | mLayoutHelper.onlyShowBottomDivider(bottomInsetLeft, bottomInsetRight, bottomDividerHeight, bottomDividerColor); 178 | invalidate(); 179 | } 180 | 181 | @Override 182 | public void onlyShowLeftDivider(int leftInsetTop, int leftInsetBottom, int leftDividerWidth, @ColorInt int leftDividerColor) { 183 | mLayoutHelper.onlyShowLeftDivider(leftInsetTop, leftInsetBottom, leftDividerWidth, leftDividerColor); 184 | invalidate(); 185 | } 186 | 187 | @Override 188 | public void onlyShowRightDivider(int rightInsetTop, int rightInsetBottom, int rightDividerWidth, @ColorInt int rightDividerColor) { 189 | mLayoutHelper.onlyShowRightDivider(rightInsetTop, rightInsetBottom, rightDividerWidth, rightDividerColor); 190 | invalidate(); 191 | } 192 | 193 | @Override 194 | public void setTopDividerAlpha(@IntRange(from = 0, to = 255) int dividerAlpha) { 195 | mLayoutHelper.setTopDividerAlpha(dividerAlpha); 196 | invalidate(); 197 | } 198 | 199 | @Override 200 | public void setBottomDividerAlpha(@IntRange(from = 0, to = 255) int dividerAlpha) { 201 | mLayoutHelper.setBottomDividerAlpha(dividerAlpha); 202 | invalidate(); 203 | } 204 | 205 | @Override 206 | public void setLeftDividerAlpha(@IntRange(from = 0, to = 255) int dividerAlpha) { 207 | mLayoutHelper.setLeftDividerAlpha(dividerAlpha); 208 | invalidate(); 209 | } 210 | 211 | @Override 212 | public void setRightDividerAlpha(@IntRange(from = 0, to = 255) int dividerAlpha) { 213 | mLayoutHelper.setRightDividerAlpha(dividerAlpha); 214 | invalidate(); 215 | } 216 | 217 | public void setOuterNormalColor(@ColorInt int color) { 218 | mLayoutHelper.setOuterNormalColor(color); 219 | } 220 | 221 | @Override 222 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 223 | widthMeasureSpec = mLayoutHelper.getMeasuredWidthSpec(widthMeasureSpec); 224 | heightMeasureSpec = mLayoutHelper.getMeasuredHeightSpec(heightMeasureSpec); 225 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 226 | int minW = mLayoutHelper.handleMiniWidth(widthMeasureSpec, getMeasuredWidth()); 227 | int minH = mLayoutHelper.handleMiniHeight(heightMeasureSpec, getMeasuredHeight()); 228 | if (widthMeasureSpec != minW || heightMeasureSpec != minH) { 229 | super.onMeasure(minW, minH); 230 | } 231 | } 232 | 233 | @Override 234 | protected void dispatchDraw(Canvas canvas) { 235 | super.dispatchDraw(canvas); 236 | mLayoutHelper.drawDividers(canvas, getWidth(), getHeight()); 237 | mLayoutHelper.dispatchRoundBorderDraw(canvas); 238 | } 239 | } 240 | -------------------------------------------------------------------------------- /shadowlayout-lib/src/main/java/top/limuyang2/shadowlayoutlib/ShadowRelativeLayout.java: -------------------------------------------------------------------------------- 1 | package top.limuyang2.shadowlayoutlib; 2 | 3 | import android.content.Context; 4 | import android.graphics.Canvas; 5 | import android.util.AttributeSet; 6 | import android.widget.RelativeLayout; 7 | 8 | import androidx.annotation.ColorInt; 9 | import androidx.annotation.IntRange; 10 | 11 | /** 12 | * @author limuyang 13 | * @date 2018/8/14 14 | * @class describe 15 | */ 16 | public class ShadowRelativeLayout extends RelativeLayout implements ILayout { 17 | 18 | private LayoutHelper mLayoutHelper; 19 | 20 | public ShadowRelativeLayout(Context context) { 21 | this(context, null); 22 | } 23 | 24 | public ShadowRelativeLayout(Context context, AttributeSet attrs) { 25 | this(context, attrs, 0); 26 | } 27 | 28 | public ShadowRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr) { 29 | super(context, attrs, defStyleAttr); 30 | init(context, attrs, defStyleAttr); 31 | } 32 | 33 | private void init(Context context, AttributeSet attrs, int defStyleAttr) { 34 | mLayoutHelper = new LayoutHelper(context, attrs, defStyleAttr, this); 35 | } 36 | 37 | @Override 38 | public void updateTopDivider(int topInsetLeft, int topInsetRight, int topDividerHeight, @ColorInt int topDividerColor) { 39 | mLayoutHelper.updateTopDivider(topInsetLeft, topInsetRight, topDividerHeight, topDividerColor); 40 | invalidate(); 41 | } 42 | 43 | @Override 44 | public void updateBottomDivider(int bottomInsetLeft, int bottomInsetRight, int bottomDividerHeight, @ColorInt int bottomDividerColor) { 45 | mLayoutHelper.updateBottomDivider(bottomInsetLeft, bottomInsetRight, bottomDividerHeight, bottomDividerColor); 46 | invalidate(); 47 | } 48 | 49 | @Override 50 | public void updateLeftDivider(int leftInsetTop, int leftInsetBottom, int leftDividerWidth, @ColorInt int leftDividerColor) { 51 | mLayoutHelper.updateLeftDivider(leftInsetTop, leftInsetBottom, leftDividerWidth, leftDividerColor); 52 | invalidate(); 53 | } 54 | 55 | @Override 56 | public void updateRightDivider(int rightInsetTop, int rightInsetBottom, int rightDividerWidth, @ColorInt int rightDividerColor) { 57 | mLayoutHelper.updateRightDivider(rightInsetTop, rightInsetBottom, rightDividerWidth, rightDividerColor); 58 | invalidate(); 59 | } 60 | 61 | @Override 62 | public void onlyShowTopDivider(int topInsetLeft, int topInsetRight, 63 | int topDividerHeight, @ColorInt int topDividerColor) { 64 | mLayoutHelper.onlyShowTopDivider(topInsetLeft, topInsetRight, topDividerHeight, topDividerColor); 65 | invalidate(); 66 | } 67 | 68 | @Override 69 | public void onlyShowBottomDivider(int bottomInsetLeft, int bottomInsetRight, 70 | int bottomDividerHeight, @ColorInt int bottomDividerColor) { 71 | mLayoutHelper.onlyShowBottomDivider(bottomInsetLeft, bottomInsetRight, bottomDividerHeight, bottomDividerColor); 72 | invalidate(); 73 | } 74 | 75 | @Override 76 | public void onlyShowLeftDivider(int leftInsetTop, int leftInsetBottom, int leftDividerWidth, @ColorInt int leftDividerColor) { 77 | mLayoutHelper.onlyShowLeftDivider(leftInsetTop, leftInsetBottom, leftDividerWidth, leftDividerColor); 78 | invalidate(); 79 | } 80 | 81 | @Override 82 | public void onlyShowRightDivider(int rightInsetTop, int rightInsetBottom, int rightDividerWidth, @ColorInt int rightDividerColor) { 83 | mLayoutHelper.onlyShowRightDivider(rightInsetTop, rightInsetBottom, rightDividerWidth, rightDividerColor); 84 | invalidate(); 85 | } 86 | 87 | @Override 88 | public void setTopDividerAlpha(@IntRange(from = 0, to = 255) int dividerAlpha) { 89 | mLayoutHelper.setTopDividerAlpha(dividerAlpha); 90 | invalidate(); 91 | } 92 | 93 | @Override 94 | public void setBottomDividerAlpha(@IntRange(from = 0, to = 255) int dividerAlpha) { 95 | mLayoutHelper.setBottomDividerAlpha(dividerAlpha); 96 | invalidate(); 97 | } 98 | 99 | @Override 100 | public void setLeftDividerAlpha(@IntRange(from = 0, to = 255) int dividerAlpha) { 101 | mLayoutHelper.setLeftDividerAlpha(dividerAlpha); 102 | invalidate(); 103 | } 104 | 105 | @Override 106 | public void setRightDividerAlpha(@IntRange(from = 0, to = 255) int dividerAlpha) { 107 | mLayoutHelper.setRightDividerAlpha(dividerAlpha); 108 | invalidate(); 109 | } 110 | 111 | @Override 112 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 113 | widthMeasureSpec = mLayoutHelper.getMeasuredWidthSpec(widthMeasureSpec); 114 | heightMeasureSpec = mLayoutHelper.getMeasuredHeightSpec(heightMeasureSpec); 115 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 116 | int minW = mLayoutHelper.handleMiniWidth(widthMeasureSpec, getMeasuredWidth()); 117 | int minH = mLayoutHelper.handleMiniHeight(heightMeasureSpec, getMeasuredHeight()); 118 | if (widthMeasureSpec != minW || heightMeasureSpec != minH) { 119 | super.onMeasure(minW, minH); 120 | } 121 | } 122 | 123 | @Override 124 | public void setRadiusAndShadow(int topRadius, int shadowElevation, float shadowAlpha) { 125 | mLayoutHelper.setRadiusAndShadow(topRadius, shadowElevation, shadowAlpha); 126 | } 127 | 128 | @Override 129 | public void setRadiusAndShadow(int topRadius, @LayoutHelper.HideRadiusSide int hideRadiusSide, int shadowElevation, float shadowAlpha) { 130 | mLayoutHelper.setRadiusAndShadow(topRadius, hideRadiusSide, shadowElevation, shadowAlpha); 131 | } 132 | 133 | @Override 134 | public void setRadius(int radius) { 135 | mLayoutHelper.setRadius(radius); 136 | } 137 | 138 | @Override 139 | public void setRadius(int radius, @LayoutHelper.HideRadiusSide int hideRadiusSide) { 140 | mLayoutHelper.setRadius(radius, hideRadiusSide); 141 | } 142 | 143 | @Override 144 | public int getRadius() { 145 | return mLayoutHelper.getRadius(); 146 | } 147 | 148 | @Override 149 | public void setOutlineInset(int left, int top, int right, int bottom) { 150 | mLayoutHelper.setOutlineInset(left, top, right, bottom); 151 | } 152 | 153 | @Override 154 | public void setHideRadiusSide(@HideRadiusSide int hideRadiusSide) { 155 | mLayoutHelper.setHideRadiusSide(hideRadiusSide); 156 | } 157 | 158 | @Override 159 | public int getHideRadiusSide() { 160 | return mLayoutHelper.getHideRadiusSide(); 161 | } 162 | 163 | @Override 164 | public void setBorderColor(@ColorInt int borderColor) { 165 | mLayoutHelper.setBorderColor(borderColor); 166 | invalidate(); 167 | } 168 | 169 | @Override 170 | public void setBorderWidth(int borderWidth) { 171 | mLayoutHelper.setBorderWidth(borderWidth); 172 | invalidate(); 173 | } 174 | 175 | @Override 176 | public void setShowBorderOnlyBeforeL(boolean showBorderOnlyBeforeL) { 177 | mLayoutHelper.setShowBorderOnlyBeforeL(showBorderOnlyBeforeL); 178 | invalidate(); 179 | } 180 | 181 | @Override 182 | public boolean setWidthLimit(int widthLimit) { 183 | if (mLayoutHelper.setWidthLimit(widthLimit)) { 184 | requestLayout(); 185 | invalidate(); 186 | } 187 | return true; 188 | } 189 | 190 | @Override 191 | public boolean setHeightLimit(int heightLimit) { 192 | if (mLayoutHelper.setHeightLimit(heightLimit)) { 193 | requestLayout(); 194 | invalidate(); 195 | } 196 | return true; 197 | } 198 | 199 | @Override 200 | public void setUseThemeGeneralShadowElevation() { 201 | mLayoutHelper.setUseThemeGeneralShadowElevation(); 202 | } 203 | 204 | @Override 205 | public void setOutlineExcludePadding(boolean outlineExcludePadding) { 206 | mLayoutHelper.setOutlineExcludePadding(outlineExcludePadding); 207 | } 208 | 209 | @Override 210 | public void setShadowElevation(int elevation) { 211 | mLayoutHelper.setShadowElevation(elevation); 212 | } 213 | 214 | @Override 215 | public int getShadowElevation() { 216 | return mLayoutHelper.getShadowElevation(); 217 | } 218 | 219 | @Override 220 | public void setShadowAlpha(float shadowAlpha) { 221 | mLayoutHelper.setShadowAlpha(shadowAlpha); 222 | } 223 | 224 | public void setOuterNormalColor(@ColorInt int color) { 225 | mLayoutHelper.setOuterNormalColor(color); 226 | } 227 | 228 | @Override 229 | public float getShadowAlpha() { 230 | return mLayoutHelper.getShadowAlpha(); 231 | } 232 | 233 | @Override 234 | protected void dispatchDraw(Canvas canvas) { 235 | super.dispatchDraw(canvas); 236 | mLayoutHelper.drawDividers(canvas, getWidth(), getHeight()); 237 | mLayoutHelper.dispatchRoundBorderDraw(canvas); 238 | } 239 | } 240 | -------------------------------------------------------------------------------- /shadowlayout-lib/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /shadowlayout-lib/src/main/java/top/limuyang2/shadowlayoutlib/LayoutHelper.java: -------------------------------------------------------------------------------- 1 | package top.limuyang2.shadowlayoutlib; 2 | 3 | import android.annotation.TargetApi; 4 | import android.content.Context; 5 | import android.content.res.TypedArray; 6 | import android.graphics.Canvas; 7 | import android.graphics.Color; 8 | import android.graphics.Outline; 9 | import android.graphics.Paint; 10 | import android.graphics.Path; 11 | import android.graphics.PorterDuff; 12 | import android.graphics.PorterDuffXfermode; 13 | import android.graphics.RectF; 14 | import android.os.Build; 15 | import android.util.AttributeSet; 16 | import android.view.View; 17 | import android.view.ViewOutlineProvider; 18 | 19 | import androidx.annotation.ColorInt; 20 | import androidx.annotation.IntRange; 21 | 22 | import java.lang.ref.WeakReference; 23 | 24 | 25 | /** 26 | * @author limuyang 27 | * @date 2018/8/14 28 | * @class describe 29 | */ 30 | public class LayoutHelper implements ILayout { 31 | 32 | // size 33 | private int mWidthLimit = 0; 34 | private int mHeightLimit = 0; 35 | private int mWidthMini = 0; 36 | private int mHeightMini = 0; 37 | 38 | 39 | // divider 40 | private int mTopDividerHeight = 0; 41 | private int mTopDividerInsetLeft = 0; 42 | private int mTopDividerInsetRight = 0; 43 | private int mTopDividerColor; 44 | private int mTopDividerAlpha = 255; 45 | 46 | private int mBottomDividerHeight = 0; 47 | private int mBottomDividerInsetLeft = 0; 48 | private int mBottomDividerInsetRight = 0; 49 | private int mBottomDividerColor; 50 | private int mBottomDividerAlpha = 255; 51 | 52 | private int mLeftDividerWidth = 0; 53 | private int mLeftDividerInsetTop = 0; 54 | private int mLeftDividerInsetBottom = 0; 55 | private int mLeftDividerColor; 56 | private int mLeftDividerAlpha = 255; 57 | 58 | private int mRightDividerWidth = 0; 59 | private int mRightDividerInsetTop = 0; 60 | private int mRightDividerInsetBottom = 0; 61 | private int mRightDividerColor; 62 | private int mRightDividerAlpha = 255; 63 | private Paint mDividerPaint; 64 | 65 | // round 66 | private Paint mClipPaint; 67 | private PorterDuffXfermode mMode; 68 | private int mRadius; 69 | private @ILayout.HideRadiusSide 70 | int mHideRadiusSide = HIDE_RADIUS_SIDE_NONE; 71 | private float[] mRadiusArray; 72 | private RectF mBorderRect; 73 | private int mBorderColor = 0; 74 | private int mBorderWidth = 1; 75 | private int mOuterNormalColor = 0; 76 | private WeakReference mOwner; 77 | private boolean mIsOutlineExcludePadding = false; 78 | private Path mPath = new Path(); 79 | 80 | // shadow 81 | private boolean mIsShowBorderOnlyBeforeL = true; 82 | private int mShadowElevation = 0; 83 | private float mShadowAlpha = 0f; 84 | 85 | // outline inset 86 | private int mOutlineInsetLeft = 0; 87 | private int mOutlineInsetRight = 0; 88 | private int mOutlineInsetTop = 0; 89 | private int mOutlineInsetBottom = 0; 90 | 91 | LayoutHelper(Context context, AttributeSet attrs, int defAttr, View owner) { 92 | mOwner = new WeakReference<>(owner); 93 | // mBottomDividerColor = mTopDividerColor = ContextCompat.getColor(context, R.color.qmui_config_color_separator); 94 | mBottomDividerColor = mTopDividerColor = Color.BLUE; 95 | 96 | mMode = new PorterDuffXfermode(PorterDuff.Mode.DST_OUT); 97 | mClipPaint = new Paint(); 98 | mClipPaint.setAntiAlias(true); 99 | // mShadowAlpha = QMUIResHelper.getAttrFloatValue(context, R.attr.qmui_general_shadow_alpha); 100 | mBorderRect = new RectF(); 101 | 102 | int radius = 0, shadow = 0; 103 | if (null != attrs || defAttr != 0) { 104 | TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.ShadowLayout, defAttr, 0); 105 | int count = ta.getIndexCount(); 106 | for (int i = 0; i < count; ++i) { 107 | int index = ta.getIndex(i); 108 | if (index == R.styleable.ShadowLayout_android_maxHeight) { 109 | mWidthLimit = ta.getDimensionPixelSize(index, mWidthLimit); 110 | } else if (index == R.styleable.ShadowLayout_android_maxHeight) { 111 | mHeightLimit = ta.getDimensionPixelSize(index, mHeightLimit); 112 | } else if (index == R.styleable.ShadowLayout_android_minWidth) { 113 | mWidthMini = ta.getDimensionPixelSize(index, mWidthMini); 114 | } else if (index == R.styleable.ShadowLayout_android_minHeight) { 115 | mHeightMini = ta.getDimensionPixelSize(index, mHeightMini); 116 | } else if (index == R.styleable.ShadowLayout_l_topDividerColor) { 117 | mTopDividerColor = ta.getColor(index, mTopDividerColor); 118 | } else if (index == R.styleable.ShadowLayout_l_topDividerHeight) { 119 | mTopDividerHeight = ta.getDimensionPixelSize(index, mTopDividerHeight); 120 | } else if (index == R.styleable.ShadowLayout_l_topDividerInsetLeft) { 121 | mTopDividerInsetLeft = ta.getDimensionPixelSize(index, mTopDividerInsetLeft); 122 | } else if (index == R.styleable.ShadowLayout_l_topDividerInsetRight) { 123 | mTopDividerInsetRight = ta.getDimensionPixelSize(index, mTopDividerInsetRight); 124 | } else if (index == R.styleable.ShadowLayout_l_bottomDividerColor) { 125 | mBottomDividerColor = ta.getColor(index, mBottomDividerColor); 126 | } else if (index == R.styleable.ShadowLayout_l_bottomDividerHeight) { 127 | mBottomDividerHeight = ta.getDimensionPixelSize(index, mBottomDividerHeight); 128 | } else if (index == R.styleable.ShadowLayout_l_bottomDividerInsetLeft) { 129 | mBottomDividerInsetLeft = ta.getDimensionPixelSize(index, mBottomDividerInsetLeft); 130 | } else if (index == R.styleable.ShadowLayout_l_bottomDividerInsetRight) { 131 | mBottomDividerInsetRight = ta.getDimensionPixelSize(index, mBottomDividerInsetRight); 132 | } else if (index == R.styleable.ShadowLayout_l_leftDividerColor) { 133 | mLeftDividerColor = ta.getColor(index, mLeftDividerColor); 134 | } else if (index == R.styleable.ShadowLayout_l_leftDividerWidth) { 135 | mLeftDividerWidth = ta.getDimensionPixelSize(index, mBottomDividerHeight); 136 | } else if (index == R.styleable.ShadowLayout_l_leftDividerInsetTop) { 137 | mLeftDividerInsetTop = ta.getDimensionPixelSize(index, mLeftDividerInsetTop); 138 | } else if (index == R.styleable.ShadowLayout_l_leftDividerInsetBottom) { 139 | mLeftDividerInsetBottom = ta.getDimensionPixelSize(index, mLeftDividerInsetBottom); 140 | } else if (index == R.styleable.ShadowLayout_l_rightDividerColor) { 141 | mRightDividerColor = ta.getColor(index, mRightDividerColor); 142 | } else if (index == R.styleable.ShadowLayout_l_rightDividerWidth) { 143 | mRightDividerWidth = ta.getDimensionPixelSize(index, mRightDividerWidth); 144 | } else if (index == R.styleable.ShadowLayout_l_rightDividerInsetTop) { 145 | mRightDividerInsetTop = ta.getDimensionPixelSize(index, mRightDividerInsetTop); 146 | } else if (index == R.styleable.ShadowLayout_l_rightDividerInsetBottom) { 147 | mRightDividerInsetBottom = ta.getDimensionPixelSize(index, mRightDividerInsetBottom); 148 | } else if (index == R.styleable.ShadowLayout_l_borderColor) { 149 | mBorderColor = ta.getColor(index, mBorderColor); 150 | } else if (index == R.styleable.ShadowLayout_l_borderWidth) { 151 | mBorderWidth = ta.getDimensionPixelSize(index, mBorderWidth); 152 | } else if (index == R.styleable.ShadowLayout_l_radius) { 153 | radius = ta.getDimensionPixelSize(index, 0); 154 | } else if (index == R.styleable.ShadowLayout_l_outerNormalColor) { 155 | mOuterNormalColor = ta.getColor(index, mOuterNormalColor); 156 | } else if (index == R.styleable.ShadowLayout_l_hideRadiusSide) { 157 | mHideRadiusSide = ta.getColor(index, mHideRadiusSide); 158 | } else if (index == R.styleable.ShadowLayout_l_showBorderOnlyBeforeL) { 159 | mIsShowBorderOnlyBeforeL = ta.getBoolean(index, mIsShowBorderOnlyBeforeL); 160 | } else if (index == R.styleable.ShadowLayout_l_shadowElevation) { 161 | shadow = ta.getDimensionPixelSize(index, shadow); 162 | } else if (index == R.styleable.ShadowLayout_l_shadowAlpha) { 163 | mShadowAlpha = ta.getFloat(index, mShadowAlpha); 164 | } else if (index == R.styleable.ShadowLayout_l_outlineInsetLeft) { 165 | mOutlineInsetLeft = ta.getDimensionPixelSize(index, 0); 166 | } else if (index == R.styleable.ShadowLayout_l_outlineInsetRight) { 167 | mOutlineInsetRight = ta.getDimensionPixelSize(index, 0); 168 | } else if (index == R.styleable.ShadowLayout_l_outlineInsetTop) { 169 | mOutlineInsetTop = ta.getDimensionPixelSize(index, 0); 170 | } else if (index == R.styleable.ShadowLayout_l_outlineInsetBottom) { 171 | mOutlineInsetBottom = ta.getDimensionPixelSize(index, 0); 172 | } else if (index == R.styleable.ShadowLayout_l_outlineExcludePadding) { 173 | mIsOutlineExcludePadding = ta.getBoolean(index, false); 174 | } 175 | } 176 | ta.recycle(); 177 | } 178 | 179 | setRadiusAndShadow(radius, mHideRadiusSide, shadow, mShadowAlpha); 180 | } 181 | 182 | @Override 183 | public void setUseThemeGeneralShadowElevation() { 184 | // mShadowElevation = QMUIResHelper.getAttrDimen(mContext, R.attr.qmui_general_shadow_elevation); 185 | setRadiusAndShadow(mRadius, mHideRadiusSide, mShadowElevation, mShadowAlpha); 186 | } 187 | 188 | @Override 189 | public void setOutlineExcludePadding(boolean outlineExcludePadding) { 190 | if (useFeature()) { 191 | View owner = mOwner.get(); 192 | if (owner == null) { 193 | return; 194 | } 195 | mIsOutlineExcludePadding = outlineExcludePadding; 196 | owner.invalidateOutline(); 197 | } 198 | 199 | } 200 | 201 | @Override 202 | public boolean setWidthLimit(int widthLimit) { 203 | if (mWidthLimit != widthLimit) { 204 | mWidthLimit = widthLimit; 205 | return true; 206 | } 207 | return false; 208 | } 209 | 210 | @Override 211 | public boolean setHeightLimit(int heightLimit) { 212 | if (mHeightLimit != heightLimit) { 213 | mHeightLimit = heightLimit; 214 | return true; 215 | } 216 | return false; 217 | } 218 | 219 | @Override 220 | public int getShadowElevation() { 221 | return mShadowElevation; 222 | } 223 | 224 | @Override 225 | public float getShadowAlpha() { 226 | return mShadowAlpha; 227 | } 228 | 229 | @Override 230 | public void setOutlineInset(int left, int top, int right, int bottom) { 231 | if (useFeature()) { 232 | View owner = mOwner.get(); 233 | if (owner == null) { 234 | return; 235 | } 236 | mOutlineInsetLeft = left; 237 | mOutlineInsetRight = right; 238 | mOutlineInsetTop = top; 239 | mOutlineInsetBottom = bottom; 240 | owner.invalidateOutline(); 241 | } 242 | } 243 | 244 | 245 | @Override 246 | public void setShowBorderOnlyBeforeL(boolean showBorderOnlyBeforeL) { 247 | mIsShowBorderOnlyBeforeL = showBorderOnlyBeforeL; 248 | invalidate(); 249 | } 250 | 251 | @Override 252 | public void setShadowElevation(int elevation) { 253 | if (mShadowElevation == elevation) { 254 | return; 255 | } 256 | mShadowElevation = elevation; 257 | invalidate(); 258 | } 259 | 260 | @Override 261 | public void setShadowAlpha(float shadowAlpha) { 262 | if (mShadowAlpha == shadowAlpha) { 263 | return; 264 | } 265 | mShadowAlpha = shadowAlpha; 266 | invalidate(); 267 | } 268 | 269 | private void invalidate() { 270 | if (useFeature()) { 271 | View owner = mOwner.get(); 272 | if (owner == null) { 273 | return; 274 | } 275 | if (mShadowElevation == 0) { 276 | owner.setElevation(0); 277 | } else { 278 | owner.setElevation(mShadowElevation); 279 | } 280 | owner.invalidateOutline(); 281 | } 282 | } 283 | 284 | @Override 285 | public void setHideRadiusSide(@HideRadiusSide int hideRadiusSide) { 286 | if (mHideRadiusSide == hideRadiusSide) { 287 | return; 288 | } 289 | setRadiusAndShadow(mRadius, hideRadiusSide, mShadowElevation, mShadowAlpha); 290 | } 291 | 292 | @Override 293 | public int getHideRadiusSide() { 294 | return mHideRadiusSide; 295 | } 296 | 297 | @Override 298 | public void setRadius(int radius) { 299 | if (mRadius != radius) { 300 | setRadiusAndShadow(radius, mShadowElevation, mShadowAlpha); 301 | } 302 | } 303 | 304 | @Override 305 | public void setRadius(int radius, @ILayout.HideRadiusSide int hideRadiusSide) { 306 | if (mRadius == radius && hideRadiusSide == mHideRadiusSide) { 307 | return; 308 | } 309 | setRadiusAndShadow(radius, hideRadiusSide, mShadowElevation, mShadowAlpha); 310 | } 311 | 312 | @Override 313 | public int getRadius() { 314 | return mRadius; 315 | } 316 | 317 | @Override 318 | public void setRadiusAndShadow(int radius, int shadowElevation, float shadowAlpha) { 319 | setRadiusAndShadow(radius, mHideRadiusSide, shadowElevation, shadowAlpha); 320 | } 321 | 322 | @Override 323 | public void setRadiusAndShadow(int radius, @ILayout.HideRadiusSide int hideRadiusSide, int shadowElevation, float shadowAlpha) { 324 | View owner = mOwner.get(); 325 | if (owner == null) { 326 | return; 327 | } 328 | 329 | mRadius = radius; 330 | mHideRadiusSide = hideRadiusSide; 331 | 332 | if (mRadius > 0) { 333 | if (hideRadiusSide == HIDE_RADIUS_SIDE_TOP) { 334 | mRadiusArray = new float[]{0, 0, 0, 0, mRadius, mRadius, mRadius, mRadius}; 335 | } else if (hideRadiusSide == HIDE_RADIUS_SIDE_RIGHT) { 336 | mRadiusArray = new float[]{mRadius, mRadius, 0, 0, 0, 0, mRadius, mRadius}; 337 | } else if (hideRadiusSide == HIDE_RADIUS_SIDE_BOTTOM) { 338 | mRadiusArray = new float[]{mRadius, mRadius, mRadius, mRadius, 0, 0, 0, 0}; 339 | } else if (hideRadiusSide == HIDE_RADIUS_SIDE_LEFT) { 340 | mRadiusArray = new float[]{0, 0, mRadius, mRadius, mRadius, mRadius, 0, 0}; 341 | } else { 342 | mRadiusArray = null; 343 | } 344 | } 345 | 346 | mShadowElevation = shadowElevation; 347 | mShadowAlpha = shadowAlpha; 348 | if (useFeature()) { 349 | if (mShadowElevation == 0 || isRadiusWithSideHidden()) { 350 | owner.setElevation(0); 351 | } else { 352 | owner.setElevation(mShadowElevation); 353 | } 354 | 355 | owner.setOutlineProvider(new ViewOutlineProvider() { 356 | @Override 357 | @TargetApi(21) 358 | public void getOutline(View view, Outline outline) { 359 | int w = view.getWidth(), h = view.getHeight(); 360 | if (w == 0 || h == 0) { 361 | return; 362 | } 363 | if (isRadiusWithSideHidden()) { 364 | int left = 0, top = 0, right = w, bottom = h; 365 | if (mHideRadiusSide == HIDE_RADIUS_SIDE_LEFT) { 366 | left -= mRadius; 367 | } else if (mHideRadiusSide == HIDE_RADIUS_SIDE_TOP) { 368 | top -= mRadius; 369 | } else if (mHideRadiusSide == HIDE_RADIUS_SIDE_RIGHT) { 370 | right += mRadius; 371 | } else if (mHideRadiusSide == HIDE_RADIUS_SIDE_BOTTOM) { 372 | bottom += mRadius; 373 | } 374 | outline.setRoundRect(left, top, 375 | right, bottom, mRadius); 376 | return; 377 | } 378 | 379 | int top = mOutlineInsetTop, bottom = Math.max(top + 1, h - mOutlineInsetBottom), 380 | left = mOutlineInsetLeft, right = w - mOutlineInsetRight; 381 | if (mIsOutlineExcludePadding) { 382 | left += view.getPaddingLeft(); 383 | top += view.getPaddingTop(); 384 | right = Math.max(left + 1, right - view.getPaddingRight()); 385 | bottom = Math.max(top + 1, bottom - view.getPaddingBottom()); 386 | } 387 | outline.setAlpha(mShadowAlpha); 388 | if (mRadius <= 0) { 389 | outline.setRect(left, top, 390 | right, bottom); 391 | } else { 392 | outline.setRoundRect(left, top, 393 | right, bottom, mRadius); 394 | } 395 | } 396 | }); 397 | 398 | owner.setClipToOutline(mRadius > 0); 399 | 400 | } 401 | owner.invalidate(); 402 | } 403 | 404 | /** 405 | * 有radius, 但是有一边不显示radius。 406 | */ 407 | public boolean isRadiusWithSideHidden() { 408 | return mRadius > 0 && mHideRadiusSide != HIDE_RADIUS_SIDE_NONE; 409 | } 410 | 411 | @Override 412 | public void updateTopDivider(int topInsetLeft, int topInsetRight, int topDividerHeight, @ColorInt int topDividerColor) { 413 | mTopDividerInsetLeft = topInsetLeft; 414 | mTopDividerInsetRight = topInsetRight; 415 | mTopDividerHeight = topDividerHeight; 416 | mTopDividerColor = topDividerColor; 417 | } 418 | 419 | @Override 420 | public void updateBottomDivider(int bottomInsetLeft, int bottomInsetRight, int bottomDividerHeight, @ColorInt int bottomDividerColor) { 421 | mBottomDividerInsetLeft = bottomInsetLeft; 422 | mBottomDividerInsetRight = bottomInsetRight; 423 | mBottomDividerColor = bottomDividerColor; 424 | mBottomDividerHeight = bottomDividerHeight; 425 | } 426 | 427 | @Override 428 | public void updateLeftDivider(int leftInsetTop, int leftInsetBottom, int leftDividerWidth, @ColorInt int leftDividerColor) { 429 | mLeftDividerInsetTop = leftInsetTop; 430 | mLeftDividerInsetBottom = leftInsetBottom; 431 | mLeftDividerWidth = leftDividerWidth; 432 | mLeftDividerColor = leftDividerColor; 433 | } 434 | 435 | @Override 436 | public void updateRightDivider(int rightInsetTop, int rightInsetBottom, int rightDividerWidth, @ColorInt int rightDividerColor) { 437 | mRightDividerInsetTop = rightInsetTop; 438 | mRightDividerInsetBottom = rightInsetBottom; 439 | mRightDividerWidth = rightDividerWidth; 440 | mRightDividerColor = rightDividerColor; 441 | } 442 | 443 | @Override 444 | public void onlyShowTopDivider(int topInsetLeft, int topInsetRight, 445 | int topDividerHeight, @ColorInt int topDividerColor) { 446 | updateTopDivider(topInsetLeft, topInsetRight, topDividerHeight, topDividerColor); 447 | mLeftDividerWidth = 0; 448 | mRightDividerWidth = 0; 449 | mBottomDividerHeight = 0; 450 | } 451 | 452 | @Override 453 | public void onlyShowBottomDivider(int bottomInsetLeft, int bottomInsetRight, 454 | int bottomDividerHeight, @ColorInt int bottomDividerColor) { 455 | updateBottomDivider(bottomInsetLeft, bottomInsetRight, bottomDividerHeight, bottomDividerColor); 456 | mLeftDividerWidth = 0; 457 | mRightDividerWidth = 0; 458 | mTopDividerHeight = 0; 459 | } 460 | 461 | @Override 462 | public void onlyShowLeftDivider(int leftInsetTop, int leftInsetBottom, int leftDividerWidth, @ColorInt int leftDividerColor) { 463 | updateLeftDivider(leftInsetTop, leftInsetBottom, leftDividerWidth, leftDividerColor); 464 | mRightDividerWidth = 0; 465 | mTopDividerHeight = 0; 466 | mBottomDividerHeight = 0; 467 | } 468 | 469 | @Override 470 | public void onlyShowRightDivider(int rightInsetTop, int rightInsetBottom, int rightDividerWidth, @ColorInt int rightDividerColor) { 471 | updateRightDivider(rightInsetTop, rightInsetBottom, rightDividerWidth, rightDividerColor); 472 | mLeftDividerWidth = 0; 473 | mTopDividerHeight = 0; 474 | mBottomDividerHeight = 0; 475 | } 476 | 477 | @Override 478 | public void setTopDividerAlpha(@IntRange(from = 0, to = 255) int dividerAlpha) { 479 | mTopDividerAlpha = dividerAlpha; 480 | } 481 | 482 | @Override 483 | public void setBottomDividerAlpha(@IntRange(from = 0, to = 255) int dividerAlpha) { 484 | mBottomDividerAlpha = dividerAlpha; 485 | } 486 | 487 | @Override 488 | public void setLeftDividerAlpha(@IntRange(from = 0, to = 255) int dividerAlpha) { 489 | mLeftDividerAlpha = dividerAlpha; 490 | } 491 | 492 | @Override 493 | public void setRightDividerAlpha(@IntRange(from = 0, to = 255) int dividerAlpha) { 494 | mRightDividerAlpha = dividerAlpha; 495 | } 496 | 497 | 498 | public int handleMiniWidth(int widthMeasureSpec, int measuredWidth) { 499 | if (View.MeasureSpec.getMode(widthMeasureSpec) != View.MeasureSpec.EXACTLY 500 | && measuredWidth < mWidthMini) { 501 | return View.MeasureSpec.makeMeasureSpec(mWidthMini, View.MeasureSpec.EXACTLY); 502 | } 503 | return widthMeasureSpec; 504 | } 505 | 506 | public int handleMiniHeight(int heightMeasureSpec, int measuredHeight) { 507 | if (View.MeasureSpec.getMode(heightMeasureSpec) != View.MeasureSpec.EXACTLY 508 | && measuredHeight < mHeightMini) { 509 | return View.MeasureSpec.makeMeasureSpec(mHeightMini, View.MeasureSpec.EXACTLY); 510 | } 511 | return heightMeasureSpec; 512 | } 513 | 514 | public int getMeasuredWidthSpec(int widthMeasureSpec) { 515 | if (mWidthLimit > 0) { 516 | int size = View.MeasureSpec.getSize(widthMeasureSpec); 517 | if (size > mWidthLimit) { 518 | int mode = View.MeasureSpec.getMode(widthMeasureSpec); 519 | if (mode == View.MeasureSpec.AT_MOST) { 520 | widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(mWidthLimit, View.MeasureSpec.AT_MOST); 521 | } else { 522 | widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(mWidthLimit, View.MeasureSpec.EXACTLY); 523 | } 524 | 525 | } 526 | } 527 | return widthMeasureSpec; 528 | } 529 | 530 | public int getMeasuredHeightSpec(int heightMeasureSpec) { 531 | if (mHeightLimit > 0) { 532 | int size = View.MeasureSpec.getSize(heightMeasureSpec); 533 | if (size > mHeightLimit) { 534 | int mode = View.MeasureSpec.getMode(heightMeasureSpec); 535 | if (mode == View.MeasureSpec.AT_MOST) { 536 | heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(mWidthLimit, View.MeasureSpec.AT_MOST); 537 | } else { 538 | heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(mWidthLimit, View.MeasureSpec.EXACTLY); 539 | } 540 | } 541 | } 542 | return heightMeasureSpec; 543 | } 544 | 545 | @Override 546 | public void setBorderColor(@ColorInt int borderColor) { 547 | mBorderColor = borderColor; 548 | } 549 | 550 | @Override 551 | public void setBorderWidth(int borderWidth) { 552 | mBorderWidth = borderWidth; 553 | } 554 | 555 | public void drawDividers(Canvas canvas, int w, int h) { 556 | if (mDividerPaint == null && 557 | (mTopDividerHeight > 0 || mBottomDividerHeight > 0 || mLeftDividerWidth > 0 || mRightDividerWidth > 0)) { 558 | mDividerPaint = new Paint(); 559 | } 560 | if (mTopDividerHeight > 0) { 561 | mDividerPaint.setStrokeWidth(mTopDividerHeight); 562 | mDividerPaint.setColor(mTopDividerColor); 563 | if (mTopDividerAlpha < 255) { 564 | mDividerPaint.setAlpha(mTopDividerAlpha); 565 | } 566 | float y = mTopDividerHeight * 1f / 2; 567 | canvas.drawLine(mTopDividerInsetLeft, y, w - mTopDividerInsetRight, y, mDividerPaint); 568 | } 569 | 570 | if (mBottomDividerHeight > 0) { 571 | mDividerPaint.setStrokeWidth(mBottomDividerHeight); 572 | mDividerPaint.setColor(mBottomDividerColor); 573 | if (mTopDividerAlpha < 255) { 574 | mDividerPaint.setAlpha(mBottomDividerAlpha); 575 | } 576 | float y = (float) Math.floor(h - mBottomDividerHeight * 1f / 2); 577 | canvas.drawLine(mBottomDividerInsetLeft, y, w - mBottomDividerInsetRight, y, mDividerPaint); 578 | } 579 | 580 | if (mLeftDividerWidth > 0) { 581 | mDividerPaint.setStrokeWidth(mLeftDividerWidth); 582 | mDividerPaint.setColor(mLeftDividerColor); 583 | if (mLeftDividerAlpha < 255) { 584 | mDividerPaint.setAlpha(mLeftDividerAlpha); 585 | } 586 | canvas.drawLine(0, mLeftDividerInsetTop, 0, h - mLeftDividerInsetBottom, mDividerPaint); 587 | } 588 | 589 | if (mRightDividerWidth > 0) { 590 | mDividerPaint.setStrokeWidth(mRightDividerWidth); 591 | mDividerPaint.setColor(mRightDividerColor); 592 | if (mRightDividerAlpha < 255) { 593 | mDividerPaint.setAlpha(mRightDividerAlpha); 594 | } 595 | canvas.drawLine(w, mRightDividerInsetTop, w, h - mRightDividerInsetBottom, mDividerPaint); 596 | } 597 | } 598 | 599 | 600 | public void dispatchRoundBorderDraw(Canvas canvas) { 601 | View owner = mOwner.get(); 602 | if (owner == null) { 603 | return; 604 | } 605 | if (mBorderColor == 0 && (mRadius == 0 || mOuterNormalColor == 0)) { 606 | return; 607 | } 608 | 609 | if (mIsShowBorderOnlyBeforeL && useFeature() && mShadowElevation != 0) { 610 | return; 611 | } 612 | 613 | int width = canvas.getWidth(), height = canvas.getHeight(); 614 | 615 | // react 616 | if (mIsOutlineExcludePadding) { 617 | mBorderRect.set(1 + owner.getPaddingLeft(), 1 + owner.getPaddingTop(), 618 | width - 1 - owner.getPaddingRight(), height - 1 - owner.getPaddingBottom()); 619 | } else { 620 | mBorderRect.set(1, 1, width - 1, height - 1); 621 | } 622 | 623 | if (mRadius == 0 || (!useFeature() && mOuterNormalColor == 0)) { 624 | mClipPaint.setStyle(Paint.Style.STROKE); 625 | canvas.drawRect(mBorderRect, mClipPaint); 626 | return; 627 | } 628 | 629 | // 圆角矩形 630 | if (!useFeature()) { 631 | int layerId = canvas.saveLayer(0, 0, width, height, null, Canvas.ALL_SAVE_FLAG); 632 | canvas.drawColor(mOuterNormalColor); 633 | mClipPaint.setColor(mOuterNormalColor); 634 | mClipPaint.setStyle(Paint.Style.FILL); 635 | mClipPaint.setXfermode(mMode); 636 | if (mRadiusArray == null) { 637 | canvas.drawRoundRect(mBorderRect, mRadius, mRadius, mClipPaint); 638 | } else { 639 | drawRoundRect(canvas, mBorderRect, mRadiusArray, mClipPaint); 640 | } 641 | mClipPaint.setXfermode(null); 642 | canvas.restoreToCount(layerId); 643 | } 644 | 645 | mClipPaint.setColor(mBorderColor); 646 | mClipPaint.setStrokeWidth(mBorderWidth); 647 | mClipPaint.setStyle(Paint.Style.STROKE); 648 | if (mRadiusArray == null) { 649 | canvas.drawRoundRect(mBorderRect, mRadius, mRadius, mClipPaint); 650 | } else { 651 | drawRoundRect(canvas, mBorderRect, mRadiusArray, mClipPaint); 652 | } 653 | } 654 | 655 | private void drawRoundRect(Canvas canvas, RectF rect, float[] radiusArray, Paint paint) { 656 | mPath.reset(); 657 | mPath.addRoundRect(rect, radiusArray, Path.Direction.CW); 658 | canvas.drawPath(mPath, paint); 659 | 660 | } 661 | 662 | public void setOuterNormalColor(int color) { 663 | mOuterNormalColor = color; 664 | View owner = mOwner.get(); 665 | if (owner != null) { 666 | owner.invalidate(); 667 | } 668 | } 669 | 670 | private static boolean useFeature() { 671 | return Build.VERSION.SDK_INT >= 21; 672 | } 673 | } 674 | --------------------------------------------------------------------------------