├── lib
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ └── values
│ │ │ │ ├── strings.xml
│ │ │ │ └── attrs.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── mosect
│ │ │ └── ashadow
│ │ │ ├── UnsupportedKeyException.java
│ │ │ ├── ShadowFactory.java
│ │ │ ├── RoundShadowFactory.java
│ │ │ ├── Shadow.java
│ │ │ ├── UnsupportedRoundShadow.java
│ │ │ ├── ShadowManager.java
│ │ │ ├── ShadowHelper.java
│ │ │ ├── ShadowRelativeLayout.java
│ │ │ ├── ShadowLinearLayout.java
│ │ │ ├── RoundShadow.java
│ │ │ └── ShadowLayout.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── mosect
│ │ │ └── ashadow
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── mosect
│ │ └── ashadow
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── example
├── .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
│ │ │ ├── xml
│ │ │ │ └── backup_descriptor.xml
│ │ │ ├── drawable
│ │ │ │ ├── item_bg.xml
│ │ │ │ ├── shape_bg.xml
│ │ │ │ └── ic_launcher_background.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── layout
│ │ │ │ ├── activity_main.xml
│ │ │ │ ├── item_main.xml
│ │ │ │ ├── activity_shadowrelativelayout.xml
│ │ │ │ ├── activity_shadowlinerlayout.xml
│ │ │ │ └── activity_shadowlayout.xml
│ │ │ └── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── mosect
│ │ │ │ └── ashadow
│ │ │ │ └── example
│ │ │ │ ├── ShadowLayoutActivity.java
│ │ │ │ ├── ShadowLinearLayoutActivity.java
│ │ │ │ ├── ShadowRelativeLayoutActivity.java
│ │ │ │ ├── GridSpacingItemDecoration.java
│ │ │ │ ├── ShadowItemDecoration.java
│ │ │ │ └── MainActivity.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── mosect
│ │ │ └── ashadow
│ │ │ └── example
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── mosect
│ │ └── ashadow
│ │ └── example
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── img
├── 01.jpg
├── 02.jpg
└── 03.jpg
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
├── gradlew.bat
├── gradlew
└── README.md
/lib/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/example/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':lib', ':example'
2 |
--------------------------------------------------------------------------------
/img/01.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Mosect/AShadow2/HEAD/img/01.jpg
--------------------------------------------------------------------------------
/img/02.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Mosect/AShadow2/HEAD/img/02.jpg
--------------------------------------------------------------------------------
/img/03.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Mosect/AShadow2/HEAD/img/03.jpg
--------------------------------------------------------------------------------
/lib/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | lib
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Mosect/AShadow2/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/example/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AShadow2
3 |
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | .idea
5 | .DS_Store
6 | /build
7 | /captures
8 | .externalNativeBuild
9 |
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Mosect/AShadow2/HEAD/example/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Mosect/AShadow2/HEAD/example/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/lib/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Mosect/AShadow2/HEAD/example/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Mosect/AShadow2/HEAD/example/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Mosect/AShadow2/HEAD/example/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Mosect/AShadow2/HEAD/example/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Mosect/AShadow2/HEAD/example/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Mosect/AShadow2/HEAD/example/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Mosect/AShadow2/HEAD/example/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Mosect/AShadow2/HEAD/example/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/example/src/main/res/xml/backup_descriptor.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/example/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Apr 02 14:20:15 CST 2021
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-5.6.4-all.zip
7 |
--------------------------------------------------------------------------------
/example/src/main/res/drawable/item_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/example/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/example/src/main/res/drawable/shape_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
12 |
--------------------------------------------------------------------------------
/lib/src/test/java/com/mosect/ashadow/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.mosect.ashadow;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/example/src/test/java/com/mosect/ashadow/example/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.mosect.ashadow.example;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/example/src/main/java/com/mosect/ashadow/example/ShadowLayoutActivity.java:
--------------------------------------------------------------------------------
1 | package com.mosect.ashadow.example;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v7.app.AppCompatActivity;
6 |
7 | public class ShadowLayoutActivity extends AppCompatActivity {
8 | @Override
9 | protected void onCreate(@Nullable Bundle savedInstanceState) {
10 | super.onCreate(savedInstanceState);
11 | setContentView(R.layout.activity_shadowlayout);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/example/src/main/java/com/mosect/ashadow/example/ShadowLinearLayoutActivity.java:
--------------------------------------------------------------------------------
1 | package com.mosect.ashadow.example;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v7.app.AppCompatActivity;
6 |
7 | public class ShadowLinearLayoutActivity extends AppCompatActivity {
8 |
9 | @Override
10 | protected void onCreate(@Nullable Bundle savedInstanceState) {
11 | super.onCreate(savedInstanceState);
12 | setContentView(R.layout.activity_shadowlinerlayout);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/example/src/main/java/com/mosect/ashadow/example/ShadowRelativeLayoutActivity.java:
--------------------------------------------------------------------------------
1 | package com.mosect.ashadow.example;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v7.app.AppCompatActivity;
6 |
7 | public class ShadowRelativeLayoutActivity extends AppCompatActivity {
8 |
9 | @Override
10 | protected void onCreate(@Nullable Bundle savedInstanceState) {
11 | super.onCreate(savedInstanceState);
12 | setContentView(R.layout.activity_shadowrelativelayout);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/lib/src/main/java/com/mosect/ashadow/UnsupportedKeyException.java:
--------------------------------------------------------------------------------
1 | package com.mosect.ashadow;
2 |
3 | public class UnsupportedKeyException extends RuntimeException {
4 |
5 | public UnsupportedKeyException() {
6 | }
7 |
8 | public UnsupportedKeyException(String message) {
9 | super(message);
10 | }
11 |
12 | public UnsupportedKeyException(String message, Throwable cause) {
13 | super(message, cause);
14 | }
15 |
16 | public UnsupportedKeyException(Throwable cause) {
17 | super(cause);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 |
15 |
--------------------------------------------------------------------------------
/lib/src/main/java/com/mosect/ashadow/ShadowFactory.java:
--------------------------------------------------------------------------------
1 | package com.mosect.ashadow;
2 |
3 | /**
4 | * 阴影工厂
5 | */
6 | public interface ShadowFactory {
7 |
8 | /**
9 | * 判断是否支持此阴影key
10 | *
11 | * @param key 阴影key
12 | * @return true,支持此阴影key
13 | */
14 | boolean supportKey(Object key);
15 |
16 | /**
17 | * 复制阴影key
18 | *
19 | * @param key 阴影key
20 | * @return key的备份
21 | * @throws UnsupportedKeyException 不支持的阴影key
22 | */
23 | Object copyKey(Object key) throws UnsupportedKeyException;
24 |
25 | /**
26 | * 创建阴影
27 | *
28 | * @param key 阴影key
29 | * @return 阴影
30 | * @throws UnsupportedKeyException 不支持的阴影key
31 | */
32 | Shadow create(Object key) throws UnsupportedKeyException;
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/example/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/lib/src/androidTest/java/com/mosect/ashadow/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.mosect.ashadow;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.mosect.ashadow.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/example/src/androidTest/java/com/mosect/ashadow/example/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.mosect.ashadow.example;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.mosect.ashadow.example", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/lib/src/main/java/com/mosect/ashadow/RoundShadowFactory.java:
--------------------------------------------------------------------------------
1 | package com.mosect.ashadow;
2 |
3 | /**
4 | * 圆角矩形阴影工厂
5 | */
6 | public class RoundShadowFactory implements ShadowFactory {
7 |
8 | @Override
9 | public boolean supportKey(Object key) {
10 | return key instanceof RoundShadow.Key;
11 | }
12 |
13 | @Override
14 | public Object copyKey(Object key) throws UnsupportedKeyException {
15 | if (!supportKey(key)) {
16 | throw new UnsupportedKeyException("Key:" + key);
17 | }
18 | return ((RoundShadow.Key) key).clone();
19 | }
20 |
21 | @Override
22 | public Shadow create(Object key) throws UnsupportedKeyException {
23 | if (!supportKey(key)) {
24 | throw new UnsupportedKeyException("Key:" + key);
25 | }
26 | if (key instanceof UnsupportedRoundShadow.Key) {
27 | return new UnsupportedRoundShadow((UnsupportedRoundShadow.Key) key);
28 | }
29 | return new RoundShadow((RoundShadow.Key) key);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/example/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 28
5 |
6 |
7 |
8 | defaultConfig {
9 | applicationId "com.mosect.ashadow.example"
10 | minSdkVersion 19
11 | targetSdkVersion 28
12 | versionCode 1
13 | versionName "1.0"
14 |
15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
16 |
17 | }
18 |
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 |
26 | }
27 |
28 | dependencies {
29 | implementation fileTree(dir: 'libs', include: ['*.jar'])
30 |
31 | implementation 'com.android.support:appcompat-v7:28.0.0'
32 | implementation 'com.android.support:recyclerview-v7:28.0.0'
33 | testImplementation 'junit:junit:4.12'
34 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
35 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
36 | implementation project(':lib')
37 | implementation 'com.github.Mosect:ViewUtils:1.0.8'
38 | }
39 |
--------------------------------------------------------------------------------
/example/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
20 |
21 |
27 |
28 |
33 |
--------------------------------------------------------------------------------
/example/src/main/res/layout/item_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
22 |
23 |
33 |
--------------------------------------------------------------------------------
/example/src/main/res/layout/activity_shadowrelativelayout.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
20 |
21 |
31 |
32 |
--------------------------------------------------------------------------------
/lib/src/main/java/com/mosect/ashadow/Shadow.java:
--------------------------------------------------------------------------------
1 | package com.mosect.ashadow;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 | import android.graphics.Rect;
6 |
7 | /**
8 | * 表示一种阴影
9 | */
10 | public abstract class Shadow {
11 |
12 | private int usedCount;
13 | protected Object key;
14 |
15 | /**
16 | * 如果有地方引用此对象,需要调用此方法
17 | *
18 | * @deprecated 已过时,不用主动绑定
19 | */
20 | public void bind() {
21 | synchronized (this) {
22 | usedCount++;
23 | }
24 | }
25 |
26 | /**
27 | * 如果不需要引用此对象,调用此方法
28 | *
29 | * @deprecated 已过时,不用主动释放对象
30 | */
31 | public void unbind() {
32 | synchronized (this) {
33 | if (usedCount > 0) {
34 | usedCount--;
35 | }
36 | if (usedCount == 0) {
37 | onDestroy();
38 | }
39 | }
40 | }
41 |
42 | /**
43 | * 判断此阴影对象是否被引用
44 | *
45 | * @return true,被引用
46 | * @deprecated 已失效,主要对象存在,就可用
47 | */
48 | public boolean isUsed() {
49 | return usedCount > 0;
50 | }
51 |
52 | /**
53 | * 获取阴影key
54 | *
55 | * @return 阴影key
56 | */
57 | public Object getKey() {
58 | return key;
59 | }
60 |
61 | /**
62 | * 释放阴影对象
63 | */
64 | protected abstract void onDestroy();
65 |
66 | /**
67 | * 将阴影对象画在画布上
68 | *
69 | * @param canvas 画布
70 | * @param rect 位置和大小
71 | * @param paint 额外画笔
72 | */
73 | public abstract void draw(Canvas canvas, Rect rect, Paint paint);
74 | }
75 |
--------------------------------------------------------------------------------
/example/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
14 |
18 |
19 |
20 |
21 |
22 |
23 |
27 |
31 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/example/src/main/res/layout/activity_shadowlinerlayout.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
15 |
16 |
28 |
29 |
39 |
40 |
47 |
48 |
--------------------------------------------------------------------------------
/example/src/main/java/com/mosect/ashadow/example/GridSpacingItemDecoration.java:
--------------------------------------------------------------------------------
1 | package com.mosect.ashadow.example;
2 |
3 |
4 | import android.graphics.Rect;
5 | import android.support.annotation.NonNull;
6 | import android.support.v7.widget.RecyclerView;
7 | import android.view.View;
8 |
9 | public class GridSpacingItemDecoration extends RecyclerView.ItemDecoration {
10 |
11 | private int spanCount;
12 | private int spacing;
13 | private boolean includeEdge;
14 |
15 | public GridSpacingItemDecoration(int spanCount, int spacing, boolean includeEdge) {
16 | this.spanCount = spanCount;
17 | this.spacing = spacing;
18 | this.includeEdge = includeEdge;
19 | }
20 |
21 | @Override
22 | public void getItemOffsets(
23 | @NonNull Rect outRect,
24 | @NonNull View view,
25 | @NonNull RecyclerView parent,
26 | @NonNull RecyclerView.State state) {
27 | int position = parent.getChildAdapterPosition(view); // item position
28 | int column = position % spanCount; // item column
29 |
30 | if (includeEdge) {
31 | outRect.left = spacing - column * spacing / spanCount; // spacing - column * ((1f / spanCount) * spacing)
32 | outRect.right = (column + 1) * spacing / spanCount; // (column + 1) * ((1f / spanCount) * spacing)
33 |
34 | if (position < spanCount) { // top edge
35 | outRect.top = spacing;
36 | }
37 | outRect.bottom = spacing; // item bottom
38 | } else {
39 | outRect.left = column * spacing / spanCount; // column * ((1f / spanCount) * spacing)
40 | outRect.right = spacing - (column + 1) * spacing / spanCount; // spacing - (column + 1) * ((1f / spanCount) * spacing)
41 | if (position >= spanCount) {
42 | outRect.top = spacing; // item top
43 | }
44 | }
45 | }
46 | }
--------------------------------------------------------------------------------
/lib/src/main/java/com/mosect/ashadow/UnsupportedRoundShadow.java:
--------------------------------------------------------------------------------
1 | package com.mosect.ashadow;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Color;
5 | import android.graphics.Paint;
6 | import android.graphics.Path;
7 | import android.graphics.Rect;
8 | import android.graphics.RectF;
9 |
10 | public class UnsupportedRoundShadow extends Shadow {
11 |
12 | private Paint paint;
13 | private Key key;
14 | private Path path;
15 | private RectF pathRect;
16 |
17 | public UnsupportedRoundShadow(Key key) {
18 | key.check();
19 | this.key = key.clone();
20 | this.paint = new Paint();
21 | this.path = new Path();
22 | this.pathRect = new RectF();
23 | }
24 |
25 | @Override
26 | protected void onDestroy() {
27 | }
28 |
29 | @Override
30 | public void draw(Canvas canvas, Rect rect, Paint paint) {
31 | this.paint.reset();
32 | if (null != paint) {
33 | this.paint.set(paint);
34 | }
35 | this.paint.setColor(key.noSolid ? Color.TRANSPARENT : key.solidColor);
36 | this.paint.setStyle(Paint.Style.FILL);
37 | this.paint.setAntiAlias(true);
38 |
39 | if (key.hasRound()) { // 有圆角
40 | path.reset();
41 | pathRect.set(rect);
42 | path.addRoundRect(pathRect, key.radii, Path.Direction.CW);
43 | canvas.drawPath(path, this.paint);
44 | } else { // 无圆角
45 | canvas.drawRect(rect, this.paint);
46 | }
47 | }
48 |
49 | public static class Key extends RoundShadow.Key {
50 |
51 | @Override
52 | public Key clone() {
53 | return (Key) super.clone();
54 | }
55 |
56 | public void set(RoundShadow.Key src) {
57 | this.solidColor = src.solidColor;
58 | this.shadowRadius = src.shadowRadius;
59 | this.shadowColor = src.shadowColor;
60 | this.radii = src.radii;
61 | this.noSolid = src.noSolid;
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/example/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/lib/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'maven-publish'
3 |
4 | android {
5 | compileSdkVersion 28
6 |
7 |
8 | defaultConfig {
9 | minSdkVersion 19
10 | targetSdkVersion 28
11 | versionCode 1
12 | versionName "1.0"
13 |
14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15 |
16 | }
17 |
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 |
25 | }
26 |
27 | tasks.withType(Javadoc).all {
28 | enabled = false
29 | }
30 |
31 | dependencies {
32 | implementation fileTree(dir: 'libs', include: ['*.jar'])
33 |
34 | testImplementation 'junit:junit:4.12'
35 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
36 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
37 | implementation 'com.github.Mosect:ViewUtils:1.0.8'
38 | }
39 |
40 | // Because the components are created only during the afterEvaluate phase, you must
41 | // configure your publications using the afterEvaluate() lifecycle method.
42 | afterEvaluate {
43 | publishing {
44 | publications {
45 | // Creates a Maven publication called "release".
46 | release(MavenPublication) {
47 | // Applies the component for the release build variant.
48 | from components.release
49 |
50 | // You can then customize attributes of the publication as shown below.
51 | groupId = 'com.github.mosect'
52 | artifactId = 'AShadow2'
53 | version = '2.0.6'
54 | }
55 | // Creates a Maven publication called “debug”.
56 | debug(MavenPublication) {
57 | // Applies the component for the debug build variant.
58 | from components.debug
59 |
60 | groupId = 'com.github.mosect'
61 | artifactId = 'AShadow2'
62 | version = '2.0.6'
63 | }
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/example/src/main/res/layout/activity_shadowlayout.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
26 |
27 |
40 |
41 |
52 |
53 |
63 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/example/src/main/java/com/mosect/ashadow/example/ShadowItemDecoration.java:
--------------------------------------------------------------------------------
1 | package com.mosect.ashadow.example;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Rect;
5 | import android.support.annotation.NonNull;
6 | import android.support.v7.widget.RecyclerView;
7 | import android.view.View;
8 |
9 | import com.mosect.ashadow.Shadow;
10 | import com.mosect.ashadow.ShadowManager;
11 | import com.mosect.ashadow.UnsupportedKeyException;
12 |
13 | import java.io.Closeable;
14 | import java.util.HashMap;
15 | import java.util.Map;
16 |
17 | /**
18 | * item阴影
19 | */
20 | public abstract class ShadowItemDecoration
21 | extends RecyclerView.ItemDecoration
22 | implements Closeable {
23 |
24 | private Map