├── .gitignore
├── LICENSE
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── wanjian
│ │ └── shadow
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── wanjian
│ │ │ └── shadow
│ │ │ ├── MainActivity.java
│ │ │ └── RadiusView.java
│ └── res
│ │ ├── layout
│ │ └── activity_main.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
│ │ ├── erha.jpg
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── wanjian
│ └── shadow
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── settings.gradle
└── shadowlib
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
├── androidTest
└── java
│ └── com
│ └── wanjian
│ └── shadowlib
│ └── ExampleInstrumentedTest.java
├── main
├── AndroidManifest.xml
├── java
│ └── com
│ │ └── wanjian
│ │ └── shadowlib
│ │ ├── Check.java
│ │ ├── Config.java
│ │ └── ShadowHelper.java
└── res
│ └── values
│ └── strings.xml
└── test
└── java
└── com
└── wanjian
└── shadowlib
└── ExampleUnitTest.java
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 | .idea
11 |
12 | # Created by .ignore support plugin (hsz.mobi)
13 | ### macOS template
14 | *.DS_Store
15 | .AppleDouble
16 | .LSOverride
17 |
18 | # Icon must end with two \r
19 | Icon
20 |
21 |
22 | # Thumbnails
23 | ._*
24 |
25 | # Files that might appear in the root of a volume
26 | .DocumentRevisions-V100
27 | .fseventsd
28 | .Spotlight-V100
29 | .TemporaryItems
30 | .Trashes
31 | .VolumeIcon.icns
32 | .com.apple.timemachine.donotpresent
33 |
34 | # Directories potentially created on remote AFP share
35 | .AppleDB
36 | .AppleDesktop
37 | Network Trash Folder
38 | Temporary Items
39 | .apdisk
40 | ### Android template
41 | # Built application files
42 | *.apk
43 | *.ap_
44 |
45 | # Files for the ART/Dalvik VM
46 | *.dex
47 |
48 | # Java class files
49 | *.class
50 |
51 | # Generated files
52 | bin/
53 | gen/
54 | out/
55 |
56 | # Gradle files
57 | .gradle/
58 | build/
59 |
60 | # Local configuration file (sdk path, etc)
61 | local.properties
62 |
63 | # Proguard folder generated by Eclipse
64 | proguard/
65 |
66 | # Log Files
67 | *.log
68 |
69 | # Android Studio Navigation editor temp files
70 | .navigation/
71 |
72 | # Android Studio captures folder
73 | captures/
74 |
75 | # Intellij
76 | *.iml
77 | .idea/workspace.xml
78 | .idea/tasks.xml
79 | .idea/gradle.xml
80 | .idea/dictionaries
81 | .idea/libraries
82 |
83 | # Keystore files
84 | *.jks
85 |
86 | # External native build folder generated in Android Studio 2.2 and later
87 | .externalNativeBuild
88 |
89 | # Google Services (e.g. APIs or Firebase)
90 | google-services.json
91 |
92 | # Freeline
93 | freeline.py
94 | freeline/
95 | freeline_project_description.json
96 | ### Linux template
97 | *~
98 |
99 | # temporary files which can be created if a process still has a handle open of a deleted file
100 | .fuse_hidden*
101 |
102 | # KDE directory preferences
103 | .directory
104 |
105 | # Linux trash folder which might appear on any partition or disk
106 | .Trash-*
107 |
108 | # .nfs files are created when an open file is removed but is still being accessed
109 | .nfs*
110 | ### Windows template
111 | # Windows thumbnail cache files
112 | Thumbs.db
113 | ehthumbs.db
114 | ehthumbs_vista.db
115 |
116 | # Folder config file
117 | Desktop.ini
118 |
119 | # Recycle Bin used on file shares
120 | $RECYCLE.BIN/
121 |
122 | # Windows Installer files
123 | *.cab
124 | *.msi
125 | *.msm
126 | *.msp
127 |
128 | # Windows shortcuts
129 | *.lnk
130 | ### JetBrains template
131 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
132 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
133 |
134 | # User-specific stuff:
135 | .idea/**/workspace.xml
136 | .idea/**/tasks.xml
137 | .idea/dictionaries
138 |
139 | # Sensitive or high-churn files:
140 | .idea/**/dataSources/
141 | .idea/**/dataSources.ids
142 | .idea/**/dataSources.xml
143 | .idea/**/dataSources.local.xml
144 | .idea/**/sqlDataSources.xml
145 | .idea/**/dynamic.xml
146 | .idea/**/uiDesigner.xml
147 |
148 | # Gradle:
149 | .idea/**/gradle.xml
150 | .idea/**/libraries
151 |
152 | # Mongo Explorer plugin:
153 | .idea/**/mongoSettings.xml
154 |
155 | ## File-based project format:
156 | *.iws
157 |
158 | ## Plugin-specific files:
159 |
160 | # IntelliJ
161 | /out/
162 |
163 | # mpeltonen/sbt-idea plugin
164 | .idea_modules/
165 |
166 | # JIRA plugin
167 | atlassian-ide-plugin.xml
168 |
169 | # Crashlytics plugin (for Android Studio and IntelliJ)
170 | com_crashlytics_export_strings.xml
171 | crashlytics.properties
172 | crashlytics-build.properties
173 | fabric.properties
174 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 wanjian
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | #### Android实现和web中一样的阴影效果
2 |
3 | 阴影是画在view外面的,不是画在view上的
4 |
5 | ##### 使用方式:
6 | 自定义view,并在onDraw中执行如下代码
7 |
8 | ```java
9 |
10 | ShadowHelper.draw(canvas, this,
11 | Config.obtain()
12 | .color(color)
13 | .leftTopCorner((int) lt)
14 | .rightTopCorner((int) rt)
15 | .leftBottomCorner((int) lb)
16 | .rightBottomCorner((int) rb)
17 | .radius(radius)
18 | .xOffset(xOffset)
19 | .yOffset(yOffset)
20 | );
21 |
22 | ```
23 |
24 | 具体用法参考 `RadiusView.java`
25 |
26 | ##### 效果
27 |
28 | 
29 | 
30 | 
31 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.3"
6 | defaultConfig {
7 | applicationId "com.wanjian.shadow"
8 | minSdkVersion 14
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(include: ['*.jar'], dir: 'libs')
24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | compile 'com.android.support:appcompat-v7:25.3.1'
28 | compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha9'
29 | testCompile 'junit:junit:4.12'
30 | compile project(':shadowlib')
31 | compile 'com.squareup.okhttp3:okhttp:3.9.0'
32 | }
33 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/wanjian/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/wanjian/shadow/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.wanjian.shadow;
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 | * Instrumentation 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() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.wanjian.shadow", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/java/com/wanjian/shadow/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.wanjian.shadow;
2 |
3 | import android.graphics.Color;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 | import android.widget.EditText;
8 |
9 | public class MainActivity extends AppCompatActivity {
10 |
11 | @Override
12 | protected void onCreate(Bundle savedInstanceState) {
13 | super.onCreate(savedInstanceState);
14 | setContentView(R.layout.activity_main);
15 |
16 | final EditText lt = (EditText) findViewById(R.id.lt);
17 | final EditText rt = (EditText) findViewById(R.id.rt);
18 | final EditText rb = (EditText) findViewById(R.id.rb);
19 | final EditText lb = (EditText) findViewById(R.id.lb);
20 | final EditText x = (EditText) findViewById(R.id.xoffset);
21 | final EditText y = (EditText) findViewById(R.id.yoffset);
22 | final EditText r = (EditText) findViewById(R.id.radius);
23 | final EditText color = (EditText) findViewById(R.id.color);
24 | final RadiusView radiusView = (RadiusView) findViewById(R.id.rv);
25 |
26 | View ok = findViewById(R.id.ok);
27 | ok.setOnClickListener(new View.OnClickListener() {
28 | @Override
29 | public void onClick(View v) {
30 | float ltRadius = parseFloat(lt.getText().toString());
31 | float rtRadius = parseFloat(rt.getText().toString());
32 | float rbRadius = parseFloat(rb.getText().toString());
33 | float lbRadius = parseFloat(lb.getText().toString());
34 | radiusView.setRadius(ltRadius, rtRadius, rbRadius, lbRadius);
35 |
36 |
37 | int xOffset = parseInt(x.getText().toString());
38 | int yOffset = parseInt(y.getText().toString());
39 | int radius = parseInt(r.getText().toString());
40 | int c = Color.parseColor("#" + color.getText().toString().trim());
41 | radiusView.setShadow(xOffset, yOffset, radius, c);
42 | }
43 | });
44 |
45 | View container = findViewById(R.id.container);
46 | container.setOnClickListener(new View.OnClickListener() {
47 | @Override
48 | public void onClick(View v) {
49 | v.setBackgroundColor((int) (Math.random() * Integer.MAX_VALUE));
50 | }
51 | });
52 |
53 | ok.performClick();
54 |
55 | }
56 |
57 | private float parseFloat(String s) {
58 | try {
59 | return Float.parseFloat(s);
60 | } catch (Exception e) {
61 | return 0;
62 | }
63 | }
64 |
65 | private int parseInt(String s) {
66 | try {
67 | return Integer.parseInt(s);
68 | } catch (Exception e) {
69 | return 0;
70 | }
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/app/src/main/java/com/wanjian/shadow/RadiusView.java:
--------------------------------------------------------------------------------
1 | package com.wanjian.shadow;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Canvas;
7 | import android.graphics.Matrix;
8 | import android.graphics.Path;
9 | import android.graphics.RectF;
10 | import android.util.AttributeSet;
11 | import android.view.View;
12 |
13 | import com.wanjian.shadowlib.Config;
14 | import com.wanjian.shadowlib.ShadowHelper;
15 |
16 | /**
17 | * Created by wanjian on 2017/9/15.
18 | *
19 | * 圆角+阴影 Demo
20 | */
21 |
22 | public class RadiusView extends View {
23 | private float lt, rt, rb, lb, radius;
24 | private int xOffset, yOffset;
25 | private Path path = new Path();
26 | private int color;
27 |
28 | private Bitmap bitmap;
29 |
30 | public RadiusView(Context context) {
31 | super(context);
32 | init();
33 | }
34 |
35 | public RadiusView(Context context, AttributeSet attrs) {
36 | super(context, attrs);
37 | init();
38 | }
39 |
40 | private void init() {
41 | bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.erha);
42 |
43 | setOnClickListener(new OnClickListener() {
44 | @Override
45 | public void onClick(View v) {
46 | invalidate();
47 | }
48 | });
49 | }
50 |
51 |
52 | public void setRadius(float lt, float rt, float rb, float lb) {
53 | this.lt = lt;
54 | this.rt = rt;
55 | this.rb = rb;
56 | this.lb = lb;
57 | invalidate();
58 | }
59 |
60 | public void setShadow(int xoffset, int yoffset, float radius, int color) {
61 | this.xOffset = xoffset;
62 | this.yOffset = yoffset;
63 | this.radius = radius;
64 | this.color = color;
65 | this.radius = radius;
66 | invalidate();
67 | }
68 |
69 | @Override
70 | protected void onDraw(Canvas canvas) {
71 | super.onDraw(canvas);
72 | drawImage(canvas);
73 |
74 | //实现阴影
75 | ShadowHelper.draw(canvas, this,
76 | Config.obtain()
77 | .color(color)
78 | .leftTopCorner((int) lt)
79 | .rightTopCorner((int) rt)
80 | .leftBottomCorner((int) lb)
81 | .rightBottomCorner((int) rb)
82 | .radius(radius)
83 | .xOffset(xOffset)
84 | .yOffset(yOffset)
85 | );
86 | }
87 |
88 | private void drawImage(Canvas canvas) {
89 | canvas.save();
90 | clipBorder(canvas);
91 |
92 | float scale = Math.max(1f * getWidth() / bitmap.getWidth(), 1f * getHeight() / bitmap.getHeight());
93 | Matrix matrix = new Matrix();
94 | matrix.setScale(scale, scale);
95 | canvas.drawBitmap(bitmap, matrix, null);
96 |
97 | canvas.restore();
98 |
99 | }
100 |
101 | private void clipBorder(Canvas canvas) {
102 | int w = getWidth();
103 | int h = getHeight();
104 | if (lt + rt > w) {
105 | float scale = w / (lt + rt);
106 | lt *= scale;
107 | rt *= scale;
108 | rb *= scale;
109 | lb *= scale;
110 | }
111 | if (rt + rb > h) {
112 | float scale = h / (rt + rb);
113 | lt *= scale;
114 | rt *= scale;
115 | rb *= scale;
116 | lb *= scale;
117 | }
118 |
119 | if (rb + lb > h) {
120 | float scale = w / (rb + lb);
121 | lt *= scale;
122 | rt *= scale;
123 | rb *= scale;
124 | lb *= scale;
125 | }
126 |
127 | if (lt + lb > h) {
128 | float scale = w / (lt + lb);
129 | lt *= scale;
130 | rt *= scale;
131 | rb *= scale;
132 | lb *= scale;
133 | }
134 |
135 | path.reset();
136 | path.arcTo(new RectF(0, 0, lt * 2, lt * 2), 180, 90, false);
137 | path.arcTo(new RectF(w - rt * 2, 0, w, rt * 2), -90, 90, false);
138 | path.arcTo(new RectF(w - rb * 2, h - rb * 2, w, h), 0, 90, false);
139 | path.arcTo(new RectF(0, h - lb * 2, lb * 2, h), 90, 90, false);
140 |
141 | path.close();
142 | try {
143 | canvas.clipPath(path);
144 | } catch (Exception e) {
145 | e.printStackTrace();
146 | }
147 | }
148 | }
149 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
16 |
17 |
22 |
23 |
24 |
29 |
30 |
31 |
36 |
37 |
41 |
42 |
50 |
51 |
59 |
60 |
61 |
62 |
66 |
67 |
68 |
76 |
77 |
85 |
86 |
87 |
88 |
89 |
90 |
94 |
95 |
99 |
100 |
108 |
109 |
117 |
118 |
126 |
127 |
135 |
136 |
137 |
138 |
139 |
146 |
147 |
148 |
149 |
150 |
151 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android-notes/shadow/e60c9f669680a726a675032174a3c42d14e74856/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android-notes/shadow/e60c9f669680a726a675032174a3c42d14e74856/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android-notes/shadow/e60c9f669680a726a675032174a3c42d14e74856/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android-notes/shadow/e60c9f669680a726a675032174a3c42d14e74856/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android-notes/shadow/e60c9f669680a726a675032174a3c42d14e74856/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android-notes/shadow/e60c9f669680a726a675032174a3c42d14e74856/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android-notes/shadow/e60c9f669680a726a675032174a3c42d14e74856/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android-notes/shadow/e60c9f669680a726a675032174a3c42d14e74856/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/erha.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android-notes/shadow/e60c9f669680a726a675032174a3c42d14e74856/app/src/main/res/mipmap-xxxhdpi/erha.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android-notes/shadow/e60c9f669680a726a675032174a3c42d14e74856/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android-notes/shadow/e60c9f669680a726a675032174a3c42d14e74856/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | shadow
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/wanjian/shadow/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.wanjian.shadow;
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() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.3.3'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/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 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android-notes/shadow/e60c9f669680a726a675032174a3c42d14e74856/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Sep 13 15:28:20 CST 2017
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-3.3-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/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 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
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 Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':shadowlib'
2 |
--------------------------------------------------------------------------------
/shadowlib/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/shadowlib/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.3"
6 |
7 | defaultConfig {
8 | minSdkVersion 14
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 |
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 |
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | }
23 |
24 | dependencies {
25 | compile fileTree(dir: 'libs', include: ['*.jar'])
26 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
27 | exclude group: 'com.android.support', module: 'support-annotations'
28 | })
29 | compile 'com.android.support:appcompat-v7:25.3.1'
30 | testCompile 'junit:junit:4.12'
31 | }
32 |
--------------------------------------------------------------------------------
/shadowlib/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/wanjian/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/shadowlib/src/androidTest/java/com/wanjian/shadowlib/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.wanjian.shadowlib;
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 | * Instrumentation 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() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.wanjian.shadowlib.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/shadowlib/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/shadowlib/src/main/java/com/wanjian/shadowlib/Check.java:
--------------------------------------------------------------------------------
1 | package com.wanjian.shadowlib;
2 |
3 | /**
4 | * Created by wanjian on 2017/9/14.
5 | */
6 |
7 | class Check {
8 | static void ifNull(Object o) {
9 | if (o == null) {
10 | throw new RuntimeException("can not be null !");
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/shadowlib/src/main/java/com/wanjian/shadowlib/Config.java:
--------------------------------------------------------------------------------
1 | package com.wanjian.shadowlib;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | /**
7 | * Created by wanjian on 2017/9/14.
8 | */
9 |
10 | public class Config {
11 | private static List sConfigs = new ArrayList<>();
12 |
13 | private Config() {
14 | }
15 |
16 | public static Config obtain() {
17 | if (sConfigs.isEmpty()) {
18 | return new Config();
19 | }
20 | return sConfigs.remove(sConfigs.size() - 1);
21 | }
22 |
23 | public static Config obtain(Config config) {
24 | Config b = obtain();
25 | b.color = config.color;
26 | b.xOffset = config.xOffset;
27 | b.yOffset = config.yOffset;
28 | b.radius = config.radius;
29 | b.leftTopCorner = config.leftTopCorner;
30 | b.rightTopCorner = config.rightTopCorner;
31 | b.rightBottomCorner = config.rightBottomCorner;
32 | b.leftBottomCorner = config.leftBottomCorner;
33 | return b;
34 | }
35 |
36 | int color;
37 | int xOffset;
38 | int yOffset;
39 | float radius;
40 | int leftTopCorner;
41 | int rightTopCorner;
42 | int rightBottomCorner;
43 | int leftBottomCorner;
44 |
45 | /**
46 | * @param color 阴影颜色
47 | * @return this
48 | */
49 | public Config color(int color) {
50 | this.color = color;
51 | return this;
52 | }
53 |
54 | /**
55 | * @param xOffset x轴偏移量
56 | * @return this
57 | */
58 | public Config xOffset(int xOffset) {
59 | this.xOffset = xOffset;
60 | return this;
61 | }
62 |
63 | /**
64 | * @param yOffset y轴偏移量
65 | * @return this
66 | */
67 | public Config yOffset(int yOffset) {
68 | this.yOffset = yOffset;
69 | return this;
70 | }
71 |
72 | /**
73 | * @param radius 模糊半径
74 | * @return this
75 | */
76 | public Config radius(float radius) {
77 | if (radius < 1e-6) {
78 | radius = 0.01f;
79 | }
80 | this.radius = radius;
81 | return this;
82 | }
83 |
84 | public Config leftTopCorner(int leftTopCorner) {
85 | this.leftTopCorner = leftTopCorner;
86 | return this;
87 | }
88 |
89 | public Config rightTopCorner(int rightTopCorner) {
90 | this.rightTopCorner = rightTopCorner;
91 | return this;
92 | }
93 |
94 | public Config rightBottomCorner(int rightBottomCorner) {
95 | this.rightBottomCorner = rightBottomCorner;
96 | return this;
97 | }
98 |
99 | public Config leftBottomCorner(int leftBottomCorner) {
100 | this.leftBottomCorner = leftBottomCorner;
101 | return this;
102 | }
103 |
104 | void recycle() {
105 | if (sConfigs.contains(this)) {
106 | throw new RuntimeException("build has been recycled!");
107 | }
108 | color = 0;
109 | xOffset = 0;
110 | yOffset = 0;
111 | radius = 0;
112 | leftTopCorner = 0;
113 | rightTopCorner = 0;
114 | rightBottomCorner = 0;
115 | leftBottomCorner = 0;
116 | if (sConfigs.size() < 50) {
117 | sConfigs.add(this);
118 | }
119 | }
120 |
121 | @Override
122 | public boolean equals(Object obj) {
123 | if (!(obj instanceof Config)) {
124 | return false;
125 | }
126 | Config b = ((Config) obj);
127 | if (obj == this ||
128 | b.color == color &&
129 | b.xOffset == xOffset &&
130 | b.yOffset == yOffset &&
131 | b.radius == radius &&
132 | b.leftTopCorner == leftTopCorner &&
133 | b.rightTopCorner == rightTopCorner &&
134 | b.rightBottomCorner == rightBottomCorner &&
135 | b.leftBottomCorner == leftBottomCorner
136 | ) {
137 | return true;
138 | }
139 |
140 | return false;
141 | }
142 | }
--------------------------------------------------------------------------------
/shadowlib/src/main/java/com/wanjian/shadowlib/ShadowHelper.java:
--------------------------------------------------------------------------------
1 | package com.wanjian.shadowlib;
2 |
3 | import android.graphics.BlurMaskFilter;
4 | import android.graphics.Canvas;
5 | import android.graphics.Paint;
6 | import android.graphics.Path;
7 | import android.graphics.RectF;
8 | import android.graphics.Region;
9 | import android.util.Log;
10 | import android.view.View;
11 |
12 |
13 | public class ShadowHelper {
14 | private static final float RATIO = 1.3f;//绘制矩形的区域至少要距离view边框Ratio倍blur,否定导致裁剪掉
15 |
16 | private static Path sPath = new Path();
17 | private static Paint sPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
18 | private static RectF sRectF = new RectF();
19 |
20 |
21 | public static void draw(Canvas canvas, View view, Config config) {
22 | Check.ifNull(canvas);
23 | Check.ifNull(view);
24 | Check.ifNull(config);
25 |
26 | View parent = (View) view.getParent();
27 | if (parent.getLayerType() != View.LAYER_TYPE_SOFTWARE) {
28 | parent.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
29 | return;
30 | }
31 |
32 | int count = canvas.save();
33 | int viewHeight = view.getHeight();
34 | int viewWidth = view.getWidth();
35 | float padding = config.radius * RATIO;
36 | int xOffset = config.xOffset;
37 | int yOffset = config.yOffset;
38 |
39 | initPath(viewWidth, viewHeight, config);
40 |
41 | try {
42 | /*
43 | clipPath时部分4.0 手机会抛出如下异常, 比如
44 | OPPO X907 cpu高通骁龙Snapdragon MSM8260 内存1GB 系统版本4.0.3 分辨率800x480
45 | FATAL EXCEPTION:main
46 | java.lang.UnsupportedOperationException
47 | at android.view.GLES20Canvas.clipPath(GLES20Canvas.java:429)
48 | */
49 | canvas.clipPath(sPath, Region.Op.REPLACE);
50 | } catch (Exception e) {
51 | Log.e("shadow", "不支持clipPath");
52 | e.printStackTrace();
53 | canvas.restoreToCount(count);
54 | config.recycle();
55 | return;
56 |
57 | }
58 |
59 | sRectF.left = xOffset - padding;
60 | sRectF.top = yOffset - padding;
61 | sRectF.right = viewWidth + xOffset + padding;
62 | sRectF.bottom = viewHeight + yOffset + padding;
63 |
64 | canvas.clipRect(sRectF, Region.Op.REVERSE_DIFFERENCE);
65 |
66 | canvas.translate(xOffset, yOffset);
67 |
68 | sPaint.setColor(config.color);
69 | sPaint.setMaskFilter(new BlurMaskFilter(config.radius, BlurMaskFilter.Blur.NORMAL));
70 |
71 | canvas.drawPath(sPath, sPaint);
72 |
73 | canvas.restoreToCount(count);
74 | config.recycle();
75 | }
76 |
77 |
78 | /**
79 | * 圆角path
80 | */
81 | private static void initPath(int w, int h, Config config) {
82 |
83 | float lt = config.leftTopCorner;
84 | float rt = config.rightTopCorner;
85 | float rb = config.rightBottomCorner;
86 | float lb = config.leftBottomCorner;
87 | if (lt + rt > w) {
88 | float scale = w / (lt + rt);
89 | lt *= scale;
90 | rt *= scale;
91 | rb *= scale;
92 | lb *= scale;
93 | }
94 | if (rt + rb > h) {
95 | float scale = h / (rt + rb);
96 | lt *= scale;
97 | rt *= scale;
98 | rb *= scale;
99 | lb *= scale;
100 | }
101 |
102 | if (rb + lb > h) {
103 | float scale = w / (rb + lb);
104 | lt *= scale;
105 | rt *= scale;
106 | rb *= scale;
107 | lb *= scale;
108 | }
109 |
110 | if (lt + lb > h) {
111 | float scale = w / (lt + lb);
112 | lt *= scale;
113 | rt *= scale;
114 | rb *= scale;
115 | lb *= scale;
116 | }
117 |
118 | sPath.reset();
119 |
120 | sRectF.left = 0;
121 | sRectF.top = 0;
122 | sRectF.right = lt * 2;
123 | sRectF.bottom = lt * 2;
124 | sPath.arcTo(sRectF, 180, 90, false);
125 |
126 | sRectF.left = w - rt * 2;
127 | sRectF.top = 0;
128 | sRectF.right = w;
129 | sRectF.bottom = rt * 2;
130 | sPath.arcTo(sRectF, -90, 90, false);
131 |
132 | sRectF.left = w - rb * 2;
133 | sRectF.top = h - rb * 2;
134 | sRectF.right = w;
135 | sRectF.bottom = h;
136 | sPath.arcTo(sRectF, 0, 90, false);
137 |
138 | sRectF.left = 0;
139 | sRectF.top = h - lb * 2;
140 | sRectF.right = lb * 2;
141 | sRectF.bottom = h;
142 | sPath.arcTo(sRectF, 90, 90, false);
143 |
144 | sPath.close();
145 |
146 | }
147 |
148 |
149 | }
150 |
--------------------------------------------------------------------------------
/shadowlib/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | shadowlib
3 |
4 |
--------------------------------------------------------------------------------
/shadowlib/src/test/java/com/wanjian/shadowlib/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.wanjian.shadowlib;
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() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------