├── settings.gradle
├── app
├── release
│ ├── app-release.apk
│ └── output.json
├── src
│ └── main
│ │ ├── res
│ │ ├── values
│ │ │ ├── strings.xml
│ │ │ ├── styles.xml
│ │ │ └── colors.xml
│ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── like_solid.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
│ │ ├── drawable
│ │ │ ├── reveal_layout_unchecked_bg.xml
│ │ │ ├── reveal_layout_checked_bg.xml
│ │ │ └── ic_launcher_background.xml
│ │ ├── mipmap-anydpi-v26
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.xml
│ │ ├── layout
│ │ │ ├── reveal_layout_like_unchecked.xml
│ │ │ ├── reveal_layout_like_checked.xml
│ │ │ ├── reveal_layout_follow_checked.xml
│ │ │ ├── reveal_layout_follow_unchecked.xml
│ │ │ ├── activity_main.xml
│ │ │ ├── layout_dark.xml
│ │ │ └── layout_light.xml
│ │ └── drawable-v24
│ │ │ └── ic_launcher_foreground.xml
│ │ ├── java
│ │ └── per
│ │ │ └── goweii
│ │ │ └── demo
│ │ │ └── reveallayout
│ │ │ └── MainActivity.java
│ │ └── AndroidManifest.xml
├── build.gradle
└── proguard-rules.pro
├── picture
└── reveal_layout_demo.gif
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── reveallayout
├── src
│ └── main
│ │ ├── AndroidManifest.xml
│ │ ├── res
│ │ └── values
│ │ │ └── attrs.xml
│ │ └── java
│ │ └── per
│ │ └── goweii
│ │ └── reveallayout
│ │ └── RevealLayout.java
├── build.gradle
└── proguard-rules.pro
├── gradle.properties
├── .gitignore
├── gradlew.bat
├── README.md
├── gradlew
└── LICENSE
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':reveallayout'
2 |
--------------------------------------------------------------------------------
/app/release/app-release.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goweii/RevealLayout/HEAD/app/release/app-release.apk
--------------------------------------------------------------------------------
/picture/reveal_layout_demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goweii/RevealLayout/HEAD/picture/reveal_layout_demo.gif
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | RevealLayout
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goweii/RevealLayout/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goweii/RevealLayout/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goweii/RevealLayout/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/like_solid.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goweii/RevealLayout/HEAD/app/src/main/res/mipmap-mdpi/like_solid.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goweii/RevealLayout/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goweii/RevealLayout/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goweii/RevealLayout/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goweii/RevealLayout/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/goweii/RevealLayout/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/goweii/RevealLayout/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/goweii/RevealLayout/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/goweii/RevealLayout/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/reveallayout/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/app/release/output.json:
--------------------------------------------------------------------------------
1 | [{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":1,"versionName":"1.0","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
--------------------------------------------------------------------------------
/app/src/main/res/drawable/reveal_layout_unchecked_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Sep 25 16:28:38 CST 2018
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 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 | #FFFFFF
7 |
8 |
--------------------------------------------------------------------------------
/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/drawable/reveal_layout_checked_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/reveal_layout_like_unchecked.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/reveal_layout_like_checked.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/java/per/goweii/demo/reveallayout/MainActivity.java:
--------------------------------------------------------------------------------
1 | package per.goweii.demo.reveallayout;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.util.Log;
6 | import android.view.View;
7 |
8 | public class MainActivity extends Activity {
9 |
10 | @Override
11 | protected void onCreate(Bundle savedInstanceState) {
12 | super.onCreate(savedInstanceState);
13 | setContentView(R.layout.activity_main);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/reveallayout/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | buildToolsVersion '29.0.2'
5 | compileSdkVersion 29
6 | defaultConfig {
7 | minSdkVersion 14
8 | targetSdkVersion 29
9 | versionCode 1
10 | versionName "1.0"
11 | }
12 | compileOptions {
13 | sourceCompatibility JavaVersion.VERSION_1_8
14 | targetCompatibility JavaVersion.VERSION_1_8
15 | }
16 | }
17 |
18 | dependencies {
19 | }
20 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | buildToolsVersion '29.0.2'
5 | compileSdkVersion 29
6 | defaultConfig {
7 | applicationId "per.goweii.demo.reveallayout"
8 | minSdkVersion 14
9 | targetSdkVersion 29
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | compileOptions {
14 | sourceCompatibility JavaVersion.VERSION_1_8
15 | targetCompatibility JavaVersion.VERSION_1_8
16 | }
17 | }
18 |
19 | dependencies {
20 | implementation fileTree(include: ['*.jar'], dir: 'libs')
21 | implementation project(':reveallayout')
22 | }
23 |
--------------------------------------------------------------------------------
/reveallayout/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/reveal_layout_follow_checked.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/reveal_layout_follow_unchecked.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
18 |
19 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/reveallayout/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/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
20 |
21 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by .ignore support plugin (hsz.mobi)
2 | ### Android template
3 | # Built application files
4 | *.ap_
5 |
6 | # Files for the ART/Dalvik VM
7 | *.dex
8 |
9 | # Java class files
10 | *.class
11 |
12 | # Generated files
13 | bin/
14 | gen/
15 | out/
16 |
17 | # Gradle files
18 | .gradle/
19 | build/
20 |
21 | # Local configuration file (sdk path, etc)
22 | local.properties
23 |
24 | # Proguard folder generated by Eclipse
25 | proguard/
26 |
27 | # Log Files
28 | *.log
29 |
30 | # Android Studio Navigation editor temp files
31 | .navigation/
32 |
33 | # Android Studio captures folder
34 | captures/
35 |
36 | # IntelliJ
37 | *.iml
38 | .idea/
39 | .idea/workspace.xml
40 | .idea/tasks.xml
41 | .idea/gradle.xml
42 | .idea/assetWizardSettings.xml
43 | .idea/dictionaries
44 | .idea/libraries
45 | .idea/caches
46 |
47 | # Keystore files
48 | # Uncomment the following line if you do not want to check your keystore files in.
49 | #*.jks
50 |
51 | # External native build folder generated in Android Studio 2.2 and later
52 | .externalNativeBuild
53 |
54 | # Google Services (e.g. APIs or Firebase)
55 | google-services.json
56 |
57 | # Freeline
58 | freeline.py
59 | freeline/
60 | freeline_project_description.json
61 |
62 | # fastlane
63 | fastlane/report.xml
64 | fastlane/Preview.html
65 | fastlane/screenshots
66 | fastlane/test_output
67 | fastlane/readme.md
68 |
69 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/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://github.com/goweii/job-wanted)
2 |
3 |
4 |
5 | # **RevealLayout**
6 |
7 | **揭示效果布局,可以指定2个子布局,以圆形揭示效果切换选中状态**
8 |
9 | [GitHub主页](https://github.com/goweii/RevealLayout)
10 |
11 | [Demo下载](https://github.com/goweii/RevealLayout/raw/master/app/release/app-release.apk)
12 |
13 |
14 |
15 | ## 截图
16 |
17 | 
18 |
19 |
20 |
21 | ## 集成方式 [](https://www.jitpack.io/#goweii/RevealLayout)
22 |
23 | ### 添加依赖
24 |
25 | 1. 在项目根目录的**build.gradle**添加仓库地址
26 |
27 | ```java
28 | allprojects {
29 | repositories {
30 | ...
31 | maven { url 'https://www.jitpack.io' }
32 | }
33 | }
34 | ```
35 |
36 | 2. 在项目app目录的**build.gradle**添加依赖
37 |
38 | 从1.1.1版本开始,版本号前不加v,引用时需要注意。
39 |
40 | ```java
41 | dependencies {
42 | implementation 'com.github.goweii:RevealLayout:1.1.1'
43 | }
44 | ```
45 |
46 | ### 布局文件引用
47 |
48 | ```xml
49 |
60 | ```
61 |
62 | ### 代码中设置监听
63 |
64 | ```java
65 | revealLayout.setOnCheckedChangeListener(new RevealLayout.OnCheckedChangeListener() {
66 | @Override
67 | public void onCheckedChanged(RevealLayout revealLayout, boolean isChecked) {
68 | // TODO
69 | }
70 | });
71 | ```
72 |
73 |
74 |
75 | ## 自定义子类
76 |
77 | 如一个关注取消关注控件FollowView,只需要继承RevealLayout,然后复写以下3个方法:
78 |
79 | 1. **initAttr(AttributeSet attrs)**:获取子类的自定义属性
80 | 2. **createCheckedView()**:创建选中状态视图,并初始化自定义属性
81 | 3. **createUncheckedView()**:创建非选中状态视图,并初始化自定义属性
82 |
83 | ```java
84 | public class FollowView extends RevealLayout{
85 | private float mTvTextSize;
86 | private int mTvPaddingVertical = 0;
87 | private int mTvPaddingHorizontal = 0;
88 | private String mTvUnFollowText = "";
89 | private int mTvUnFollowBgColor;
90 | private int mTvUnFollowBgRes;
91 | private int mTvUnFollowTextColor;
92 | private String mTvFollowText = "";
93 | private int mTvFollowBgColor;
94 | private int mTvFollowBgRes;
95 | private int mTvFollowTextColor;
96 |
97 | public FollowView(Context context) {
98 | this(context, null);
99 | }
100 |
101 | public FollowView(Context context, AttributeSet attrs) {
102 | this(context, attrs, 0);
103 | }
104 |
105 | public FollowView(Context context, AttributeSet attrs, int defStyleAttr) {
106 | super(context, attrs, defStyleAttr);
107 | }
108 |
109 | @Override
110 | protected void initAttr(AttributeSet attrs) {
111 | super.initAttr(attrs);
112 | DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
113 | TypedArray array = getContext().obtainStyledAttributes(attrs, R.styleable.FollowView);
114 | mTvPaddingVertical = (int) array.getDimension(R.styleable.FollowView_fv_tv_padding_vertical, 0F);
115 | mTvPaddingHorizontal = (int) array.getDimension(R.styleable.FollowView_fv_tv_padding_horizontal, 0F);
116 | mTvTextSize = array.getDimension(R.styleable.FollowView_fv_text_size, metrics.scaledDensity * 14) / metrics.scaledDensity;
117 | mTvUnFollowText = array.getString(R.styleable.FollowView_fv_unfollowed_text);
118 | mTvUnFollowBgRes = array.getResourceId(R.styleable.FollowView_fv_unfollowed_bg_res, 0);
119 | mTvUnFollowBgColor = array.getColor(R.styleable.FollowView_fv_unfollowed_bg_color, 0);
120 | mTvUnFollowTextColor = array.getColor(R.styleable.FollowView_fv_unfollowed_text_color, 0);
121 | mTvFollowText = array.getString(R.styleable.FollowView_fv_followed_text);
122 | mTvFollowBgRes = array.getResourceId(R.styleable.FollowView_fv_followed_bg_res, 0);
123 | mTvFollowBgColor = array.getColor(R.styleable.FollowView_fv_followed_bg_color, 0);
124 | mTvFollowTextColor = array.getColor(R.styleable.FollowView_fv_followed_text_color, 0);
125 | array.recycle();
126 | }
127 |
128 | @Override
129 | protected View createCheckedView() {
130 | TextView tvFollow = new TextView(getContext());
131 | tvFollow.setTextSize(mTvTextSize);
132 | tvFollow.setText(mTvFollowText);
133 | tvFollow.setGravity(Gravity.CENTER);
134 | tvFollow.setSingleLine();
135 | if (mTvFollowBgRes > 0) {
136 | tvFollow.setBackgroundResource(mTvFollowBgRes);
137 | } else {
138 | tvFollow.setBackgroundColor(mTvFollowBgColor);
139 | }
140 | tvFollow.setTextColor(mTvFollowTextColor);
141 | tvFollow.setPadding(mTvPaddingHorizontal, mTvPaddingVertical, mTvPaddingHorizontal, mTvPaddingVertical);
142 | return tvFollow;
143 | }
144 |
145 | @Override
146 | protected View createUncheckedView() {
147 | TextView tvUnFollow = new TextView(getContext());
148 | tvUnFollow.setTextSize(mTvTextSize);
149 | tvUnFollow.setText(mTvUnFollowText);
150 | tvUnFollow.setGravity(Gravity.CENTER);
151 | tvUnFollow.setSingleLine();
152 | if (mTvUnFollowBgRes > 0) {
153 | tvUnFollow.setBackgroundResource(mTvUnFollowBgRes);
154 | } else {
155 | tvUnFollow.setBackgroundColor(mTvUnFollowBgColor);
156 | }
157 | tvUnFollow.setTextColor(mTvUnFollowTextColor);
158 | tvUnFollow.setPadding(mTvPaddingHorizontal, mTvPaddingVertical, mTvPaddingHorizontal, mTvPaddingVertical);
159 | return tvUnFollow;
160 | }
161 | }
162 | ```
163 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU LESSER GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 |
9 | This version of the GNU Lesser General Public License incorporates
10 | the terms and conditions of version 3 of the GNU General Public
11 | License, supplemented by the additional permissions listed below.
12 |
13 | 0. Additional Definitions.
14 |
15 | As used herein, "this License" refers to version 3 of the GNU Lesser
16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU
17 | General Public License.
18 |
19 | "The Library" refers to a covered work governed by this License,
20 | other than an Application or a Combined Work as defined below.
21 |
22 | An "Application" is any work that makes use of an interface provided
23 | by the Library, but which is not otherwise based on the Library.
24 | Defining a subclass of a class defined by the Library is deemed a mode
25 | of using an interface provided by the Library.
26 |
27 | A "Combined Work" is a work produced by combining or linking an
28 | Application with the Library. The particular version of the Library
29 | with which the Combined Work was made is also called the "Linked
30 | Version".
31 |
32 | The "Minimal Corresponding Source" for a Combined Work means the
33 | Corresponding Source for the Combined Work, excluding any source code
34 | for portions of the Combined Work that, considered in isolation, are
35 | based on the Application, and not on the Linked Version.
36 |
37 | The "Corresponding Application Code" for a Combined Work means the
38 | object code and/or source code for the Application, including any data
39 | and utility programs needed for reproducing the Combined Work from the
40 | Application, but excluding the System Libraries of the Combined Work.
41 |
42 | 1. Exception to Section 3 of the GNU GPL.
43 |
44 | You may convey a covered work under sections 3 and 4 of this License
45 | without being bound by section 3 of the GNU GPL.
46 |
47 | 2. Conveying Modified Versions.
48 |
49 | If you modify a copy of the Library, and, in your modifications, a
50 | facility refers to a function or data to be supplied by an Application
51 | that uses the facility (other than as an argument passed when the
52 | facility is invoked), then you may convey a copy of the modified
53 | version:
54 |
55 | a) under this License, provided that you make a good faith effort to
56 | ensure that, in the event an Application does not supply the
57 | function or data, the facility still operates, and performs
58 | whatever part of its purpose remains meaningful, or
59 |
60 | b) under the GNU GPL, with none of the additional permissions of
61 | this License applicable to that copy.
62 |
63 | 3. Object Code Incorporating Material from Library Header Files.
64 |
65 | The object code form of an Application may incorporate material from
66 | a header file that is part of the Library. You may convey such object
67 | code under terms of your choice, provided that, if the incorporated
68 | material is not limited to numerical parameters, data structure
69 | layouts and accessors, or small macros, inline functions and templates
70 | (ten or fewer lines in length), you do both of the following:
71 |
72 | a) Give prominent notice with each copy of the object code that the
73 | Library is used in it and that the Library and its use are
74 | covered by this License.
75 |
76 | b) Accompany the object code with a copy of the GNU GPL and this license
77 | document.
78 |
79 | 4. Combined Works.
80 |
81 | You may convey a Combined Work under terms of your choice that,
82 | taken together, effectively do not restrict modification of the
83 | portions of the Library contained in the Combined Work and reverse
84 | engineering for debugging such modifications, if you also do each of
85 | the following:
86 |
87 | a) Give prominent notice with each copy of the Combined Work that
88 | the Library is used in it and that the Library and its use are
89 | covered by this License.
90 |
91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license
92 | document.
93 |
94 | c) For a Combined Work that displays copyright notices during
95 | execution, include the copyright notice for the Library among
96 | these notices, as well as a reference directing the user to the
97 | copies of the GNU GPL and this license document.
98 |
99 | d) Do one of the following:
100 |
101 | 0) Convey the Minimal Corresponding Source under the terms of this
102 | License, and the Corresponding Application Code in a form
103 | suitable for, and under terms that permit, the user to
104 | recombine or relink the Application with a modified version of
105 | the Linked Version to produce a modified Combined Work, in the
106 | manner specified by section 6 of the GNU GPL for conveying
107 | Corresponding Source.
108 |
109 | 1) Use a suitable shared library mechanism for linking with the
110 | Library. A suitable mechanism is one that (a) uses at run time
111 | a copy of the Library already present on the user's computer
112 | system, and (b) will operate properly with a modified version
113 | of the Library that is interface-compatible with the Linked
114 | Version.
115 |
116 | e) Provide Installation Information, but only if you would otherwise
117 | be required to provide such information under section 6 of the
118 | GNU GPL, and only to the extent that such information is
119 | necessary to install and execute a modified version of the
120 | Combined Work produced by recombining or relinking the
121 | Application with a modified version of the Linked Version. (If
122 | you use option 4d0, the Installation Information must accompany
123 | the Minimal Corresponding Source and Corresponding Application
124 | Code. If you use option 4d1, you must provide the Installation
125 | Information in the manner specified by section 6 of the GNU GPL
126 | for conveying Corresponding Source.)
127 |
128 | 5. Combined Libraries.
129 |
130 | You may place library facilities that are a work based on the
131 | Library side by side in a single library together with other library
132 | facilities that are not Applications and are not covered by this
133 | License, and convey such a combined library under terms of your
134 | choice, if you do both of the following:
135 |
136 | a) Accompany the combined library with a copy of the same work based
137 | on the Library, uncombined with any other library facilities,
138 | conveyed under the terms of this License.
139 |
140 | b) Give prominent notice with the combined library that part of it
141 | is a work based on the Library, and explaining where to find the
142 | accompanying uncombined form of the same work.
143 |
144 | 6. Revised Versions of the GNU Lesser General Public License.
145 |
146 | The Free Software Foundation may publish revised and/or new versions
147 | of the GNU Lesser General Public License from time to time. Such new
148 | versions will be similar in spirit to the present version, but may
149 | differ in detail to address new problems or concerns.
150 |
151 | Each version is given a distinguishing version number. If the
152 | Library as you received it specifies that a certain numbered version
153 | of the GNU Lesser General Public License "or any later version"
154 | applies to it, you have the option of following the terms and
155 | conditions either of that published version or of any later version
156 | published by the Free Software Foundation. If the Library as you
157 | received it does not specify a version number of the GNU Lesser
158 | General Public License, you may choose any version of the GNU Lesser
159 | General Public License ever published by the Free Software Foundation.
160 |
161 | If the Library as you received it specifies that a proxy can decide
162 | whether future versions of the GNU Lesser General Public License shall
163 | apply, that proxy's public statement of acceptance of any version is
164 | permanent authorization for you to choose that version for the
165 | Library.
166 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_dark.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
21 |
22 |
29 |
30 |
41 |
42 |
54 |
55 |
66 |
67 |
78 |
79 |
90 |
91 |
102 |
103 |
114 |
115 |
126 |
127 |
128 |
129 |
135 |
136 |
143 |
144 |
155 |
156 |
168 |
169 |
180 |
181 |
192 |
193 |
204 |
205 |
216 |
217 |
228 |
229 |
240 |
241 |
242 |
243 |
244 |
245 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_light.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
21 |
22 |
29 |
30 |
41 |
42 |
54 |
55 |
66 |
67 |
78 |
79 |
90 |
91 |
102 |
103 |
114 |
115 |
126 |
127 |
128 |
129 |
135 |
136 |
143 |
144 |
155 |
156 |
168 |
169 |
180 |
181 |
192 |
193 |
204 |
205 |
216 |
217 |
228 |
229 |
240 |
241 |
242 |
243 |
244 |
245 |
--------------------------------------------------------------------------------
/reveallayout/src/main/java/per/goweii/reveallayout/RevealLayout.java:
--------------------------------------------------------------------------------
1 | package per.goweii.reveallayout;
2 |
3 | import android.animation.Animator;
4 | import android.animation.TimeInterpolator;
5 | import android.animation.ValueAnimator;
6 | import android.annotation.SuppressLint;
7 | import android.content.Context;
8 | import android.content.res.TypedArray;
9 | import android.graphics.Canvas;
10 | import android.graphics.Path;
11 | import android.util.AttributeSet;
12 | import android.view.GestureDetector;
13 | import android.view.Gravity;
14 | import android.view.LayoutInflater;
15 | import android.view.MotionEvent;
16 | import android.view.View;
17 | import android.view.ViewGroup;
18 | import android.view.animation.DecelerateInterpolator;
19 | import android.widget.Checkable;
20 | import android.widget.FrameLayout;
21 |
22 | /**
23 | * 揭示效果布局
24 | * 可以指定2个子布局,以圆形揭示效果切换选中状态
25 | *
26 | * @author Cuizhen
27 | * @date 2018/9/25
28 | */
29 | public class RevealLayout extends FrameLayout
30 | implements Checkable, ValueAnimator.AnimatorUpdateListener, Animator.AnimatorListener, GestureDetector.OnGestureListener {
31 |
32 | private final GestureDetector mGestureDetector;
33 |
34 | private View mCheckedView;
35 | private View mUncheckedView;
36 |
37 | private int mCheckedLayoutId = 0;
38 | private int mUncheckedLayoutId = 0;
39 | private int mAnimDuration = 500;
40 | private boolean mCheckWithExpand = true;
41 | private boolean mUncheckWithExpand = false;
42 | private boolean mAllowRevert = false;
43 | private boolean mHideBackView = true;
44 |
45 | private boolean mChecked = false;
46 |
47 | private float mCenterX = 0F;
48 | private float mCenterY = 0F;
49 | private float mRevealRadius = 0F;
50 | private final Path mPath = new Path();
51 | private ValueAnimator mAnimator;
52 | private TimeInterpolator mInterpolator = null;
53 |
54 | private OnCheckedChangeListener mOnCheckedChangeListener = null;
55 | private OnAnimStateChangeListener mOnAnimStateChangeListener = null;
56 |
57 | public RevealLayout(Context context) {
58 | this(context, null);
59 | }
60 |
61 | public RevealLayout(Context context, AttributeSet attrs) {
62 | this(context, attrs, 0);
63 | }
64 |
65 | public RevealLayout(Context context, AttributeSet attrs, int defStyleAttr) {
66 | super(context, attrs, defStyleAttr);
67 | mGestureDetector = new GestureDetector(context, this);
68 | initAttr(attrs);
69 | initView();
70 | }
71 |
72 | /**
73 | * 获取布局文件携带的属性,子类复写该方法,获取子类定义的属性。
74 | * 获取到子类属性后可以在{@link #createCheckedView()}和{@link #createUncheckedView()}中使用
75 | *
76 | * @param attrs AttributeSet
77 | */
78 | protected void initAttr(AttributeSet attrs) {
79 | TypedArray array = getContext().obtainStyledAttributes(attrs, R.styleable.RevealLayout);
80 | mCheckedLayoutId = array.getResourceId(R.styleable.RevealLayout_rl_checkedLayout, 0);
81 | mUncheckedLayoutId = array.getResourceId(R.styleable.RevealLayout_rl_uncheckedLayout, 0);
82 | mChecked = array.getBoolean(R.styleable.RevealLayout_rl_checked, mChecked);
83 | mAnimDuration = array.getInteger(R.styleable.RevealLayout_rl_animDuration, mAnimDuration);
84 | mCheckWithExpand = array.getBoolean(R.styleable.RevealLayout_rl_checkWithExpand, mCheckWithExpand);
85 | mUncheckWithExpand = array.getBoolean(R.styleable.RevealLayout_rl_uncheckWithExpand, mUncheckWithExpand);
86 | mAllowRevert = array.getBoolean(R.styleable.RevealLayout_rl_allowRevert, mAllowRevert);
87 | mHideBackView = array.getBoolean(R.styleable.RevealLayout_rl_hideBackView, mHideBackView);
88 | array.recycle();
89 | }
90 |
91 | /**
92 | * 初始化选中和未选中状态的控件,并设置默认状态
93 | */
94 | protected void initView() {
95 | removeAllViews();
96 | if (mCheckedView == null) {
97 | mCheckedView = createCheckedView();
98 | }
99 | if (mUncheckedView == null) {
100 | mUncheckedView = createUncheckedView();
101 | }
102 | ViewGroup.LayoutParams checkParams = mCheckedView.getLayoutParams();
103 | if (checkParams == null) {
104 | checkParams = getDefaultLayoutParams();
105 | }
106 | ViewGroup.LayoutParams uncheckParams = mUncheckedView.getLayoutParams();
107 | if (uncheckParams == null) {
108 | uncheckParams = getDefaultLayoutParams();
109 | }
110 | addViewInLayout(mCheckedView, getChildCount(), checkParams);
111 | addViewInLayout(mUncheckedView, getChildCount(), uncheckParams);
112 | showTwoView();
113 | bringFrontView();
114 | hideBackView();
115 | }
116 |
117 | @Override
118 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
119 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
120 | }
121 |
122 | @Override
123 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
124 | super.onLayout(changed, left, top, right, bottom);
125 | if (changed) {
126 | resetCenter();
127 | }
128 | }
129 |
130 | @Override
131 | protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
132 | if (mAnimator == null) {
133 | return super.drawChild(canvas, child, drawingTime);
134 | }
135 | if (isBackView(child)) {
136 | return super.drawChild(canvas, child, drawingTime);
137 | }
138 | canvas.save();
139 | canvas.clipPath(mPath);
140 | boolean drawChild = super.drawChild(canvas, child, drawingTime);
141 | canvas.restore();
142 | return drawChild;
143 | }
144 |
145 | private LayoutParams getDefaultLayoutParams() {
146 | LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
147 | params.gravity = Gravity.CENTER;
148 | return params;
149 | }
150 |
151 | /**
152 | * 创建选中状态的控件,子类可复写该方法,初始化自己的控件
153 | *
154 | * @return 选中状态的控件
155 | */
156 | protected View createCheckedView() {
157 | View checkedView;
158 | if (getCheckedLayoutId() > 0) {
159 | checkedView = LayoutInflater.from(getContext()).inflate(getCheckedLayoutId(), this, false);
160 | } else {
161 | checkedView = new View(getContext());
162 | }
163 | return checkedView;
164 | }
165 |
166 | protected int getCheckedLayoutId(){
167 | return mCheckedLayoutId;
168 | }
169 |
170 | /**
171 | * 创建非选中状态的控件,子类可复写该方法,初始化自己的控件
172 | *
173 | * @return 非选中状态的控件
174 | */
175 | protected View createUncheckedView() {
176 | View uncheckedView;
177 | if (getUncheckedLayoutId() > 0) {
178 | uncheckedView = LayoutInflater.from(getContext()).inflate(getUncheckedLayoutId(), this, false);
179 | } else {
180 | uncheckedView = new View(getContext());
181 | }
182 | return uncheckedView;
183 | }
184 |
185 | protected int getUncheckedLayoutId() {
186 | return mUncheckedLayoutId;
187 | }
188 |
189 | @SuppressLint("ClickableViewAccessibility")
190 | @Override
191 | public boolean onTouchEvent(MotionEvent event) {
192 | return mGestureDetector.onTouchEvent(event);
193 | }
194 |
195 | @Override
196 | public boolean onDown(MotionEvent e) {
197 | return isValidClick(e.getX(), e.getY());
198 | }
199 |
200 | @Override
201 | public void onShowPress(MotionEvent e) {
202 | }
203 |
204 | @Override
205 | public boolean onSingleTapUp(MotionEvent e) {
206 | float upX = e.getX();
207 | float upY = e.getY();
208 | if (mAnimator != null) {
209 | if (mAllowRevert) {
210 | performClick();
211 | return true;
212 | } else {
213 | return false;
214 | }
215 | } else {
216 | mRevealRadius = 0;
217 | mCenterX = upX;
218 | mCenterY = upY;
219 | performClick();
220 | return true;
221 | }
222 | }
223 |
224 | @Override
225 | public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
226 | return false;
227 | }
228 |
229 | @Override
230 | public void onLongPress(MotionEvent e) {
231 | }
232 |
233 | @Override
234 | public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
235 | return false;
236 | }
237 |
238 | @Override
239 | public boolean performClick() {
240 | toggle();
241 | return super.performClick();
242 | }
243 |
244 | /**
245 | * 判断触摸位置是否在view内部,是否是合法点击
246 | *
247 | * @param x 触摸点x坐标
248 | * @param y 触摸点y坐标
249 | * @return 点击是否合法
250 | */
251 | private boolean isValidClick(float x, float y) {
252 | return x >= 0 &&
253 | x <= getWidth()/* - getPaddingLeft() - getPaddingRight()*/ &&
254 | y >= 0 &&
255 | y <= getHeight()/* - getPaddingTop() - getPaddingBottom()*/;
256 | }
257 |
258 | /**
259 | * 创建揭示动画
260 | */
261 | private ValueAnimator createRevealAnim() {
262 | float[] value = calculateAnimOfFloat();
263 | mRevealRadius = value[0];
264 | ValueAnimator animator = ValueAnimator.ofFloat(value[0], value[1]);
265 | animator.setInterpolator(mInterpolator != null ? mInterpolator : new DecelerateInterpolator());
266 | animator.setDuration(mAnimDuration);
267 | animator.addUpdateListener(this);
268 | animator.addListener(this);
269 | return animator;
270 | }
271 |
272 | private void onCheckedChanged(boolean checked) {
273 | if (mOnCheckedChangeListener != null) {
274 | mOnCheckedChangeListener.onCheckedChanged(this, checked);
275 | }
276 | }
277 |
278 | @Override
279 | public void onAnimationUpdate(ValueAnimator animation) {
280 | mRevealRadius = (float) animation.getAnimatedValue();
281 | resetPath();
282 | invalidate();
283 | }
284 |
285 | @Override
286 | public void onAnimationStart(Animator animation) {
287 | resetPath();
288 | bringCurrentViewToFront();
289 | if (mOnAnimStateChangeListener != null) {
290 | mOnAnimStateChangeListener.onStart();
291 | }
292 | }
293 |
294 | public void onAnimationReverse() {
295 | if (mOnAnimStateChangeListener != null) {
296 | mOnAnimStateChangeListener.onReverse();
297 | }
298 | }
299 |
300 | @Override
301 | public void onAnimationEnd(Animator animation) {
302 | mAnimator = null;
303 | bringCurrentViewToFront();
304 | hideBackView();
305 | resetCenter();
306 | if (mOnAnimStateChangeListener != null) {
307 | mOnAnimStateChangeListener.onEnd();
308 | }
309 | }
310 |
311 | @Override
312 | public void onAnimationCancel(Animator animation) {
313 | }
314 |
315 | @Override
316 | public void onAnimationRepeat(Animator animation) {
317 | }
318 |
319 | /**
320 | * 根据选中状态和揭示动画的扩散效果计算动画开始和结束半径
321 | *
322 | * @return {起始半径,结束半径}
323 | */
324 | private float[] calculateAnimOfFloat() {
325 | float fromValue;
326 | float toValue;
327 | float minRadius = calculateMinRadius();
328 | float maxRadius = calculateMaxRadius();
329 | if (mChecked) {
330 | if (mCheckWithExpand) {
331 | fromValue = minRadius;
332 | toValue = maxRadius;
333 | } else {
334 | fromValue = maxRadius;
335 | toValue = minRadius;
336 | }
337 | } else {
338 | if (mUncheckWithExpand) {
339 | fromValue = minRadius;
340 | toValue = maxRadius;
341 | } else {
342 | fromValue = maxRadius;
343 | toValue = minRadius;
344 | }
345 | }
346 | return new float[]{fromValue, toValue};
347 | }
348 |
349 | private void resetPath() {
350 | mPath.reset();
351 | mPath.addCircle(mCenterX, mCenterY, mRevealRadius, Path.Direction.CW);
352 | }
353 |
354 | /**
355 | * 将当前状态的view显示在顶部
356 | */
357 | private void bringCurrentViewToFront() {
358 | showTwoView();
359 | float minRadius = calculateMinRadius();
360 | float maxRadius = calculateMaxRadius();
361 | if (mRevealRadius < (minRadius + maxRadius) / 2F) {
362 | bringFrontView();
363 | }
364 | }
365 |
366 | private void bringFrontView() {
367 | if (mChecked) {
368 | mCheckedView.bringToFront();
369 | } else {
370 | mUncheckedView.bringToFront();
371 | }
372 | }
373 |
374 | private void showTwoView() {
375 | mCheckedView.setVisibility(VISIBLE);
376 | mUncheckedView.setVisibility(VISIBLE);
377 | }
378 |
379 | private void hideBackView() {
380 | if (!mHideBackView) {
381 | return;
382 | }
383 | if (mChecked) {
384 | mUncheckedView.setVisibility(INVISIBLE);
385 | } else {
386 | mCheckedView.setVisibility(INVISIBLE);
387 | }
388 | }
389 |
390 | /**
391 | * 计算揭示效果做大圆形半径,及圆心到4个边角的最大距离
392 | *
393 | * @return 最小半径
394 | */
395 | private float calculateMinRadius() {
396 | float w = getMeasuredWidth();
397 | float h = getMeasuredHeight();
398 | float l = getPaddingLeft();
399 | float t = getPaddingTop();
400 | float r = getPaddingRight();
401 | float b = getPaddingBottom();
402 | float x = Math.max(l - mCenterX, mCenterX - (w - r));
403 | float y = Math.max(t - mCenterY, mCenterY - (h - b));
404 | x = Math.max(x, 0);
405 | y = Math.max(y, 0);
406 | return (float) Math.hypot(x, y);
407 | }
408 |
409 | /**
410 | * 计算揭示效果做大圆形半径,及圆心到4个边角的最大距离
411 | *
412 | * @return 最大半径
413 | */
414 | private float calculateMaxRadius() {
415 | float w = getMeasuredWidth();
416 | float h = getMeasuredHeight();
417 | float l = getPaddingLeft();
418 | float t = getPaddingTop();
419 | float r = getPaddingRight();
420 | float b = getPaddingBottom();
421 | float x = Math.max(mCenterX - l, w - r - mCenterX);
422 | float y = Math.max(mCenterY - t, h - b - mCenterY);
423 | x = Math.max(x, 0);
424 | y = Math.max(y, 0);
425 | return (float) Math.hypot(x, y);
426 | }
427 |
428 | private boolean isBackView(View child) {
429 | return getChildAt(0) == child;
430 | }
431 |
432 | @Override
433 | public void setOnClickListener(OnClickListener onClickListener) {
434 | super.setOnClickListener(onClickListener);
435 | }
436 |
437 | /**
438 | * 设置选中状态改变的监听器
439 | *
440 | * @param onCheckedChangeListener OnCheckedChangeListener
441 | */
442 | public void setOnCheckedChangeListener(OnCheckedChangeListener onCheckedChangeListener) {
443 | mOnCheckedChangeListener = onCheckedChangeListener;
444 | }
445 |
446 | /**
447 | * 设置动画状态改变的监听器
448 | *
449 | * @param onAnimStateChangeListener OnAnimStateChangeListener
450 | */
451 | public void setOnAnimStateChangeListener(OnAnimStateChangeListener onAnimStateChangeListener) {
452 | mOnAnimStateChangeListener = onAnimStateChangeListener;
453 | }
454 |
455 | /**
456 | * 获取当前选中状态
457 | *
458 | * @return 是否选中
459 | */
460 | @Override
461 | public boolean isChecked() {
462 | return mChecked;
463 | }
464 |
465 | /**
466 | * 设置选中状态
467 | *
468 | * @param checked 是否选中
469 | */
470 | @Override
471 | public void setChecked(boolean checked) {
472 | if (mChecked == checked) return;
473 | mChecked = checked;
474 | onCheckedChanged(mChecked);
475 | if (mAnimDuration > 0) {
476 | if (mAnimator != null) {
477 | mAnimator.reverse();
478 | onAnimationReverse();
479 | } else {
480 | mAnimator = createRevealAnim();
481 | mAnimator.start();
482 | }
483 | } else {
484 | if (mAnimator != null) {
485 | mAnimator.cancel();
486 | mAnimator = null;
487 | }
488 | showTwoView();
489 | bringFrontView();
490 | hideBackView();
491 | resetCenter();
492 | }
493 | }
494 |
495 | /**
496 | * 设置选中状态
497 | *
498 | * @param checked 是否选中
499 | * @param withAnim 是否有动画
500 | */
501 | public void setChecked(boolean checked, boolean withAnim) {
502 | if (mChecked == checked) return;
503 | mChecked = checked;
504 | onCheckedChanged(mChecked);
505 | if (withAnim && mAnimDuration > 0) {
506 | if (mAnimator != null) {
507 | mAnimator.reverse();
508 | onAnimationReverse();
509 | } else {
510 | mAnimator = createRevealAnim();
511 | mAnimator.start();
512 | }
513 | } else {
514 | if (mAnimator != null) {
515 | mAnimator.cancel();
516 | mAnimator = null;
517 | }
518 | showTwoView();
519 | bringFrontView();
520 | hideBackView();
521 | resetCenter();
522 | }
523 | }
524 |
525 | /**
526 | * 切换选中状态,带有动画效果
527 | */
528 | @Override
529 | public void toggle() {
530 | setChecked(!mChecked);
531 | }
532 |
533 | public void resetCenter() {
534 | float w = getMeasuredWidth();
535 | float h = getMeasuredHeight();
536 | float l = getPaddingLeft();
537 | float t = getPaddingTop();
538 | float r = getPaddingRight();
539 | float b = getPaddingBottom();
540 | mCenterX = l + ((w - l - r) / 2F);
541 | mCenterY = t + ((h - t - b) / 2F);
542 | }
543 |
544 | public void setCenterPercent(float centerPercentX, float centerPercentY) {
545 | float centerX = getWidth() * centerPercentX;
546 | float centerY = getHeight() * centerPercentY;
547 | setCenter(centerX, centerY);
548 | }
549 |
550 | public void setCenter(float centerX, float centerY) {
551 | mCenterX = centerX;
552 | mCenterY = centerY;
553 | }
554 |
555 | public float getCenterX() {
556 | return mCenterX;
557 | }
558 |
559 | public float getCenterY() {
560 | return mCenterY;
561 | }
562 |
563 | public void setAllowRevert(boolean allowRevert) {
564 | mAllowRevert = allowRevert;
565 | }
566 |
567 | public void setAnimDuration(int animDuration) {
568 | mAnimDuration = animDuration;
569 | }
570 |
571 | public void setInterpolator(TimeInterpolator interpolator) {
572 | mInterpolator = interpolator;
573 | }
574 |
575 | public void setCheckWithExpand(boolean checkWithExpand) {
576 | mCheckWithExpand = checkWithExpand;
577 | }
578 |
579 | public void setUncheckWithExpand(boolean uncheckWithExpand) {
580 | mUncheckWithExpand = uncheckWithExpand;
581 | }
582 |
583 | public void setCheckedView(View checkedView) {
584 | if (checkedView == null) {
585 | return;
586 | }
587 | if (mCheckedView == checkedView) {
588 | return;
589 | }
590 | removeViewInLayout(mCheckedView);
591 | mCheckedView = checkedView;
592 | ViewGroup.LayoutParams checkParams = mCheckedView.getLayoutParams();
593 | if (checkParams == null) {
594 | checkParams = getDefaultLayoutParams();
595 | }
596 | addViewInLayout(mCheckedView, getChildCount(), checkParams);
597 | showTwoView();
598 | bringFrontView();
599 | hideBackView();
600 | }
601 |
602 | public void setUncheckedView(View uncheckedView) {
603 | if (uncheckedView == null) {
604 | return;
605 | }
606 | if (mUncheckedView == uncheckedView) {
607 | return;
608 | }
609 | removeViewInLayout(mUncheckedView);
610 | mUncheckedView = uncheckedView;
611 | ViewGroup.LayoutParams uncheckParams = mUncheckedView.getLayoutParams();
612 | if (uncheckParams == null) {
613 | uncheckParams = getDefaultLayoutParams();
614 | }
615 | addViewInLayout(mUncheckedView, getChildCount(), uncheckParams);
616 | showTwoView();
617 | bringFrontView();
618 | hideBackView();
619 | }
620 |
621 | public void setCheckedLayoutId(int checkedLayoutId) {
622 | mCheckedLayoutId = checkedLayoutId;
623 | setCheckedView(createCheckedView());
624 | }
625 |
626 | public void setUncheckedLayoutId(int uncheckedLayoutId) {
627 | mUncheckedLayoutId = uncheckedLayoutId;
628 | setUncheckedView(createUncheckedView());
629 | }
630 |
631 | public interface OnCheckedChangeListener {
632 | /**
633 | * 选中状态改变
634 | *
635 | * @param revealLayout RevealLayout
636 | * @param isChecked 当前选中状态
637 | */
638 | void onCheckedChanged(RevealLayout revealLayout, boolean isChecked);
639 | }
640 |
641 | public interface OnAnimStateChangeListener {
642 | /**
643 | * 动画开始时调用
644 | */
645 | void onStart();
646 |
647 | /**
648 | * 动画回滚时调用。即上一个动画尚未结束时切换选中状态,动画回滚到之前状态
649 | */
650 | void onReverse();
651 |
652 | /**
653 | * 动画结束时调用
654 | */
655 | void onEnd();
656 | }
657 | }
658 |
--------------------------------------------------------------------------------