├── .gitignore
├── .idea
├── misc.xml
├── modules.xml
└── runConfigurations.xml
├── LICENSE
├── README.md
├── README_CN.md
├── broccoli
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── me
│ │ └── samlss
│ │ └── broccoli
│ │ ├── Broccoli.java
│ │ ├── BroccoliGradientDrawable.java
│ │ ├── BroccoliInternalImpl.java
│ │ ├── PlaceholderParameter.java
│ │ ├── PlaceholderPreStateSaver.java
│ │ └── util
│ │ ├── LogUtil.java
│ │ └── Utils.java
│ └── res
│ └── values
│ └── strings.xml
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── sample
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── me
│ │ └── samlss
│ │ └── broccoli_demo
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── me
│ │ │ └── samlss
│ │ │ └── broccoli_demo
│ │ │ ├── App.java
│ │ │ ├── DingDingSampleActivity.java
│ │ │ ├── DrawableUtils.java
│ │ │ ├── LayoutAdvancedSampleActivity.java
│ │ │ ├── LayoutSimpleSampleActivity.java
│ │ │ ├── MainActivity.java
│ │ │ ├── PlaceholderHelper.java
│ │ │ └── RecyclerViewSampleActivity.java
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ ├── button_shape.xml
│ │ ├── drawable_dingding.xml
│ │ └── ic_samlss_head_photo.jpg
│ │ ├── layout
│ │ ├── activity_dingding.xml
│ │ ├── activity_layout_sample.xml
│ │ ├── activity_main.xml
│ │ ├── activity_recyclerview_sample.xml
│ │ └── recyclerview_sample_item.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ ├── icon_arrow_right.png
│ │ ├── icon_calendar.png
│ │ ├── icon_clock.png
│ │ ├── icon_events.png
│ │ ├── icon_fans.png
│ │ ├── icon_head.png
│ │ ├── icon_layout_pic.png
│ │ ├── icon_location.png
│ │ ├── icon_logo.png
│ │ ├── icon_retry.png
│ │ ├── icon_shopping_cart.png
│ │ ├── photo_1.jpg
│ │ ├── photo_2.jpg
│ │ ├── photo_3.jpg
│ │ ├── photo_4.jpg
│ │ └── photo_5.jpg
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── me
│ └── samlss
│ └── broccoli_demo
│ └── ExampleUnitTest.java
├── screenshots
├── Broccoli.png
├── screenshot1.gif
├── screenshot2.gif
├── screenshot3.gif
├── screenshot4.png
└── screenshot5.png
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # IntelliJ
36 | *.iml
37 | .idea/workspace.xml
38 | .idea/tasks.xml
39 | .idea/gradle.xml
40 | .idea/assetWizardSettings.xml
41 | .idea/dictionaries
42 | .idea/libraries
43 | .idea/caches
44 |
45 | # Keystore files
46 | # Uncomment the following line if you do not want to check your keystore files in.
47 | #*.jks
48 |
49 | # External native build folder generated in Android Studio 2.2 and later
50 | .externalNativeBuild
51 |
52 | # Google Services (e.g. APIs or Firebase)
53 | google-services.json
54 |
55 | # Freeline
56 | freeline.py
57 | freeline/
58 | freeline_project_description.json
59 |
60 | # fastlane
61 | fastlane/report.xml
62 | fastlane/Preview.html
63 | fastlane/screenshots
64 | fastlane/test_output
65 | fastlane/readme.md
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
16 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 | [](https://bintray.com/samlss/maven/broccoli/1.0.0/link) [](https://android-arsenal.com/api?level=11#l11) [](https://github.com/samlss/Broccoli/blob/master/LICENSE)
4 |
5 | [中文](https://github.com/samlss/Broccoli/blob/master/README_CN.md)
6 |
7 | Show the placeholder of view when you are loading something...
8 |
9 | ### Screenshots
10 | #### The default effect:
11 |
12 | 
13 |
14 |
15 | #### The advenced effect:
16 | 
17 |
18 | #### Use in RecyclerView
19 | 
20 |
21 |
22 | #### DingDing
23 | 
24 |
25 | 
26 | ------
27 | ### Dependency
28 |
29 | #### Gradle
30 | Add it in your module build.gradle at the end of repositories:
31 | ```java
32 | dependencies {
33 | implementation 'me.samlss:broccoli:1.0.0'
34 | }
35 | ```
36 |
37 | #### Maven
38 | ```java
39 |
40 | me.samlss
41 | broccoli
42 | 1.0.0
43 | pom
44 |
45 | ```
46 |
47 | ### Sample Usage
48 |
49 | ```java
50 | Broccoli broccoli = new Broccoli();
51 |
52 | //add the default style placeholder
53 | broccoli.addPlaceholders('activity', 'view_id', 'view_id');
54 |
55 | or
56 | //add the default style placeholder
57 | broccoli.addPlaceholders('view1', 'view2', 'view3');
58 |
59 | or
60 |
61 | //add the custom style placeholder
62 | broccoli.addPlaceholder(new PlaceholderParameter.Builder()
63 | .setView('view')
64 | .setAnimation('scaleAnimation');
65 | .setDrawable(DrawableUtils.createRectangleDrawable(placeHolderColor, 0))
66 | .build());
67 |
68 | or
69 | //add the custom style placeholder with gradient animation
70 | broccoli.addPlaceholder(new PlaceholderParameter.Builder()
71 | .setView('view')
72 | .setDrawable(new BroccoliGradientDrawable(Color.parseColor("#DDDDDD"),
73 | Color.parseColor("#CCCCCC"), 0, 1000, new LinearInterpolator())
74 | .build());
75 | broccoli.show();
76 | ```
77 |
78 |
79 |
80 | ### License
81 |
82 | ```
83 | Copyright 2018 samlss
84 |
85 | Licensed under the Apache License, Version 2.0 (the "License");
86 | you may not use this file except in compliance with the License.
87 | You may obtain a copy of the License at
88 |
89 | http://www.apache.org/licenses/LICENSE-2.0
90 |
91 | Unless required by applicable law or agreed to in writing, software
92 | distributed under the License is distributed on an "AS IS" BASIS,
93 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
94 | See the License for the specific language governing permissions and
95 | limitations under the License.
96 | ```
97 |
--------------------------------------------------------------------------------
/README_CN.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 | [](https://bintray.com/samlss/maven/broccoli/1.0.0/link) [](https://android-arsenal.com/api?level=11#l11) [](https://github.com/samlss/Broccoli/blob/master/LICENSE)
4 |
5 | 在预加载时显示view的占位符效果
6 |
7 | ### 截图
8 | #### 默认效果:
9 |
10 | 
11 |
12 |
13 | #### 自定义动画效果:
14 | 
15 |
16 | #### 在RecyclerView使用
17 | 
18 |
19 |
20 | #### 钉钉考勤
21 | 
22 |
23 | 
24 | ------
25 | ### 依赖
26 |
27 | #### Gradle
28 | 将其添加到你的module的build.gradle中:
29 |
30 | ```java
31 | dependencies {
32 | implementation 'me.samlss:broccoli:1.0.0'
33 | }
34 | ```
35 |
36 | #### Maven
37 | ```java
38 |
39 | me.samlss
40 | broccoli
41 | 1.0.0
42 | pom
43 |
44 | ```
45 |
46 | ### 代码使用
47 |
48 | ```java
49 | Broccoli broccoli = new Broccoli();
50 |
51 | //添加默认的占位符
52 | broccoli.addPlaceholders('activity', 'view_id', 'view_id');
53 |
54 | or
55 | //添加默认的占位符
56 | broccoli.addPlaceholders('view1', 'view2', 'view3');
57 |
58 | or
59 |
60 | //添加自定义的占位符
61 | broccoli.addPlaceholder(new PlaceholderParameter.Builder()
62 | .setView('view')
63 | .setAnimation('scaleAnimation');
64 | .setDrawable(DrawableUtils.createRectangleDrawable(placeHolderColor, 0))
65 | .build());
66 |
67 | or
68 | //添加带渐变动画的占位符
69 | broccoli.addPlaceholder(new PlaceholderParameter.Builder()
70 | .setView('view')
71 | .setDrawable(new BroccoliGradientDrawable(Color.parseColor("#DDDDDD"),
72 | Color.parseColor("#CCCCCC"), 0, 1000, new LinearInterpolator())
73 | .build());
74 | broccoli.show();
75 | ```
76 |
77 |
78 |
79 | ### License
80 |
81 | ```
82 | Copyright 2018 samlss
83 |
84 | Licensed under the Apache License, Version 2.0 (the "License");
85 | you may not use this file except in compliance with the License.
86 | You may obtain a copy of the License at
87 |
88 | http://www.apache.org/licenses/LICENSE-2.0
89 |
90 | Unless required by applicable law or agreed to in writing, software
91 | distributed under the License is distributed on an "AS IS" BASIS,
92 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
93 | See the License for the specific language governing permissions and
94 | limitations under the License.
95 | ```
96 |
--------------------------------------------------------------------------------
/broccoli/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/broccoli/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.novoda.bintray-release'
3 |
4 | android {
5 | compileSdkVersion 28
6 |
7 | defaultConfig {
8 | minSdkVersion 12
9 | targetSdkVersion 28
10 | versionCode 1
11 | versionName "1.0.0"
12 | }
13 |
14 | lintOptions {
15 | abortOnError false
16 | }
17 | }
18 |
19 | dependencies {
20 | }
21 |
22 | publish {
23 | userOrg = 'samlss'
24 | groupId = 'me.samlss'
25 | artifactId = 'broccoli'
26 | publishVersion = '1.0.0'
27 | desc = 'An Android library that shows the placeholder of the view.'
28 | website = 'https://github.com/samlss/Broccoli'
29 | }
30 |
--------------------------------------------------------------------------------
/broccoli/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 |
--------------------------------------------------------------------------------
/broccoli/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/broccoli/src/main/java/me/samlss/broccoli/Broccoli.java:
--------------------------------------------------------------------------------
1 | package me.samlss.broccoli;
2 |
3 | import android.app.Activity;
4 | import android.graphics.Color;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 |
8 | import java.util.List;
9 |
10 | import me.samlss.broccoli.util.LogUtil;
11 |
12 | /**
13 | * @author SamLeung
14 | * @e-mail samlssplus@gmail.com
15 | * @github https://github.com/samlss
16 | * @description An Android library that shows the placeholder of the view.
17 | */
18 | public class Broccoli {
19 | protected final static int DEFAULT_PLACEHOLDER_COLOR = Color.parseColor("#dddddd");
20 |
21 | private BroccoliInternalImpl mPlaceholderInternalImpl;
22 |
23 | public Broccoli(){
24 | mPlaceholderInternalImpl = new BroccoliInternalImpl();
25 | }
26 |
27 | /**
28 | * Add a array of {@link PlaceholderParameter} to show placeholders for view.
29 | *
30 | * @param activity The activity to which the view is attached
31 | * @param viewIds The view id array.
32 | * */
33 | public Broccoli addPlaceholders(Activity activity, int ... viewIds){
34 | if (activity == null){
35 | return this;
36 | }
37 | addPlaceholders((ViewGroup) activity.findViewById(android.R.id.content), viewIds);
38 | return this;
39 | }
40 |
41 | /**
42 | * Add a array of {@link PlaceholderParameter} to show placeholders for view.
43 | *
44 | * @param parent The views' parent.
45 | * @param viewIds The view id array.
46 | * */
47 | public Broccoli addPlaceholders(ViewGroup parent, int ... viewIds){
48 | if (parent == null
49 | || viewIds == null){
50 | return this;
51 | }
52 |
53 | for (int id : viewIds){
54 | addPlaceholder(createDefaultParameter(parent.findViewById(id)));
55 | }
56 |
57 | return this;
58 | }
59 |
60 | /**
61 | * Add a array of {@link PlaceholderParameter} to show placeholders for view.
62 | *
63 | * @param views The views' that you want to display their placeholder by default.
64 | * */
65 | public Broccoli addPlaceholders(View ... views){
66 | if (views == null){
67 | return this;
68 | }
69 |
70 | for (View view : views){
71 | addPlaceholder(createDefaultParameter(view));
72 | }
73 |
74 | return this;
75 | }
76 |
77 | /**
78 | * Get a default {@link PlaceholderParameter}
79 | *
80 | * @param view The view you want to display the placeholder.
81 | * */
82 | private PlaceholderParameter createDefaultParameter(View view){
83 | return new PlaceholderParameter.Builder()
84 | .setView(view)
85 | .setColor(DEFAULT_PLACEHOLDER_COLOR)
86 | .build();
87 | }
88 |
89 | /**
90 | * Add a {@link PlaceholderParameter} to show placeholder for view.
91 | *
92 | * @param parameter The parameter of the placeholder.
93 | * */
94 | public Broccoli addPlaceholder(PlaceholderParameter parameter){
95 | if (parameter == null
96 | || parameter.getView() == null){
97 | LogUtil.logE("If you want to display a placeholder for view, you can't pass a null parameter or view");
98 | return this;
99 | }
100 | mPlaceholderInternalImpl.addPlaceholder(parameter);
101 | return this;
102 | }
103 |
104 | /**
105 | * Add a list of {@link PlaceholderParameter} to show placeholders for view.
106 | *
107 | * @param placeholderParameters The placeholderParameter list.
108 | * */
109 | public Broccoli addPlaceholder(List placeholderParameters){
110 | if (placeholderParameters == null
111 | || placeholderParameters.isEmpty()){
112 | return this;
113 | }
114 |
115 | for (PlaceholderParameter parameter : placeholderParameters){
116 | addPlaceholder(parameter);
117 | }
118 | return this;
119 | }
120 |
121 | /**
122 | * Add a array of {@link PlaceholderParameter} to show placeholders for view.
123 | *
124 | * @param placeholderParameters The placeholderParameter array.
125 | * */
126 | public Broccoli addPlaceholders(PlaceholderParameter ... placeholderParameters){
127 | if (placeholderParameters == null
128 | || placeholderParameters.length == 0){
129 | return this;
130 | }
131 |
132 | for (PlaceholderParameter parameter : placeholderParameters){
133 | addPlaceholder(parameter);
134 | }
135 | return this;
136 | }
137 |
138 | /**
139 | * Remove the placeholder of view.
140 | * Will remove the record of the view from {@link Broccoli}.
141 | * Will restore the state of the view itself, such as view's background, TextView's textColor, ImageView's imageDrawable, etc.
142 | * @param view The placeholder of the view which needs to be removed.
143 | * */
144 | public Broccoli removePlaceholder(View view){
145 | mPlaceholderInternalImpl.removePlaceholder(view);
146 | return this;
147 | }
148 |
149 | /**
150 | * Will clear the placeholder of view. But unlike {@link #removePlaceholder(View)},
151 | * clear placeholder just clear the view's placeholder, but will not remove the record of the view from {@link Broccoli}.
152 | * Will restore the state of the view itself, such as view's background, TextView's textColor, ImageView's imageDrawable, etc.
153 | * @param view The placeholder of the view which needs to be cleared.
154 | * */
155 | public Broccoli clearPlaceholder(View view){
156 | mPlaceholderInternalImpl.clearPlaceholder(view);
157 | return this;
158 | }
159 |
160 | /**
161 | * Clear & remove all the placeholders for the view you have added.
162 | * Will restore the state of the view itself, such as view's background, TextView's textColor, ImageView's imageDrawable, etc.
163 | * If using {@link BroccoliGradientDrawable}, will cancel the gradient animation.
164 | * */
165 | public void removeAllPlaceholders(){
166 | mPlaceholderInternalImpl.hide(true);
167 | }
168 |
169 | /**
170 | * Clear all the placeholders for the view you have added.
171 | * Will restore the state of the view itself, such as view's background, TextView's textColor, ImageView's imageDrawable, etc.
172 | * If using {@link BroccoliGradientDrawable}, will cancel the gradient animation.
173 | * */
174 | public void clearAllPlaceholders(){
175 | mPlaceholderInternalImpl.hide(false);
176 | }
177 |
178 | /**
179 | * Start to show all placeholders for the view you have set.
180 | * */
181 | public void show(){
182 | mPlaceholderInternalImpl.show();
183 | }
184 | }
185 |
--------------------------------------------------------------------------------
/broccoli/src/main/java/me/samlss/broccoli/BroccoliGradientDrawable.java:
--------------------------------------------------------------------------------
1 | package me.samlss.broccoli;
2 |
3 | import android.animation.TimeInterpolator;
4 | import android.animation.ValueAnimator;
5 | import android.graphics.Bitmap;
6 | import android.graphics.Canvas;
7 | import android.graphics.LinearGradient;
8 | import android.graphics.Shader;
9 | import android.graphics.drawable.ShapeDrawable;
10 | import android.graphics.drawable.shapes.OvalShape;
11 | import android.graphics.drawable.shapes.RoundRectShape;
12 | import android.util.Log;
13 | import android.view.View;
14 |
15 | import java.lang.ref.WeakReference;
16 |
17 | import me.samlss.broccoli.util.LogUtil;
18 |
19 | /**
20 | * @author SamLeung
21 | * @e-mail samlssplus@gmail.com
22 | * @github https://github.com/samlss
23 | * @description The gradient animation drawable class for this library
24 | */
25 | public class BroccoliGradientDrawable extends ShapeDrawable {
26 | private int[] mColors;
27 | private int mNormalColor;
28 | private int mHighlightColor;
29 | private int mCanvasWidth;
30 | private int mCanvasHeight;
31 |
32 | private ValueAnimator valueAnimator ;
33 | private int mDuration;
34 | private TimeInterpolator mTimeInterpolator;
35 | private int mAnimatedValue;
36 |
37 | /**
38 | * @param xStartCoordinate The x-coordinate for the start of the gradient line
39 | * @param xEndCoordinate The y-coordinate for the start of the gradient line
40 | * */
41 | private float xStartCoordinate, xEndCoordinate;
42 | private Canvas mGradientCanvas;
43 | private Bitmap mGradientLayer;
44 |
45 | private Canvas mBackgroundCanvas;
46 | private Bitmap mBackgroundLayer;
47 |
48 | private WeakReference mViewRef;
49 |
50 | /**
51 | * Construct a rectangle drawable.
52 | *
53 | * @param color The color used to fill the shape.
54 | * @param highlightColor The color of gradient animation.
55 | * @param radius The radius in pixels of the corners of the rectangle shape.
56 | * @param duration The duration of the gradient animation.
57 | * @param timeInterpolator The interpolator of the gradient animation.
58 | * */
59 | public BroccoliGradientDrawable(int color, int highlightColor, float radius, int duration,
60 | TimeInterpolator timeInterpolator){
61 | setShape(getReboundRect(radius));
62 | init(color, highlightColor, duration, timeInterpolator);
63 | }
64 |
65 | /**
66 | * Construct an oval drawable.
67 | *
68 | * @param color The color used to fill the shape.
69 | * @param highlightColor The color of gradient animation.
70 | * @param duration The duration of the gradient animation.
71 | * @param timeInterpolator The interpolator of the gradient animation.
72 | * */
73 | public BroccoliGradientDrawable(int color, int highlightColor, int duration,
74 | TimeInterpolator timeInterpolator) {
75 | setShape(getOvalDrawable());
76 | init(color, highlightColor, duration, timeInterpolator);
77 | }
78 |
79 | private void init(int color, int highlightColor, int duration,
80 | TimeInterpolator timeInterpolator){
81 | mDuration = duration;
82 | mTimeInterpolator = timeInterpolator;
83 | mNormalColor = color;
84 | mHighlightColor = highlightColor;
85 |
86 | mColors = new int[]{mNormalColor, mHighlightColor, mNormalColor};
87 | }
88 |
89 | private RoundRectShape getReboundRect(float radius){
90 | return new RoundRectShape(new float[]{radius, radius, radius, radius, radius, radius, radius, radius},
91 | null, null);
92 | }
93 |
94 | private OvalShape getOvalDrawable(){
95 | return new OvalShape();
96 | }
97 |
98 | private void setupAnimator(){
99 | cancelAnimation();
100 | if (mCanvasWidth == 0
101 | || mCanvasHeight == 0){
102 | LogUtil.logE("width and height must be > 0");
103 | return;
104 | }
105 |
106 | mGradientLayer = Bitmap.createBitmap(mCanvasWidth, mCanvasHeight, Bitmap.Config.ALPHA_8);
107 | mGradientCanvas = new Canvas(mGradientLayer);
108 |
109 | mBackgroundLayer = Bitmap.createBitmap(mCanvasWidth, mCanvasHeight, Bitmap.Config.ARGB_8888);
110 | mBackgroundCanvas = new Canvas(mBackgroundLayer);
111 |
112 | xStartCoordinate = -mCanvasWidth;
113 | valueAnimator = ValueAnimator.ofInt(-mCanvasWidth, mCanvasWidth);
114 | valueAnimator.setDuration(mDuration);
115 | valueAnimator.setInterpolator(mTimeInterpolator);
116 | valueAnimator.setRepeatMode(ValueAnimator.RESTART);
117 | valueAnimator.setRepeatCount(ValueAnimator.INFINITE);
118 |
119 | valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
120 | @Override
121 | public void onAnimationUpdate(ValueAnimator animation) {
122 | mAnimatedValue = (int) animation.getAnimatedValue();
123 | invalidateSelf();
124 | }
125 | });
126 | valueAnimator.start();
127 | }
128 |
129 | @Override
130 | public void draw(Canvas canvas) {
131 | if (canvas.getWidth() <= 0
132 | || canvas.getHeight() <= 0
133 | || getShape() == null){
134 | super.draw(canvas);
135 | return;
136 | }
137 |
138 | if (mViewRef.get() == null
139 | || mViewRef.get().getBackground() != this){
140 | cancelAnimation();
141 | return;
142 | }
143 |
144 | if (valueAnimator == null){
145 | mCanvasWidth = canvas.getWidth();
146 | mCanvasHeight = canvas.getHeight();
147 |
148 | setupAnimator();
149 | }
150 |
151 | getPaint().setColor(mNormalColor);
152 | getShape().draw(mBackgroundCanvas, getPaint());
153 | canvas.drawBitmap(mBackgroundLayer, 0, 0, getPaint());
154 |
155 | xStartCoordinate = mAnimatedValue;
156 | xEndCoordinate = xStartCoordinate + mCanvasWidth;
157 | getPaint().setShader(new LinearGradient(xStartCoordinate, 0, xEndCoordinate, 0
158 | , mColors
159 | , new float[]{0f, 0.4f, 0.8f}
160 | , Shader.TileMode.CLAMP));
161 | getShape().draw(mGradientCanvas, getPaint());
162 | canvas.drawBitmap(mGradientLayer, 0, 0, getPaint());
163 | }
164 |
165 | /**
166 | * Attach the view to this drawable.
167 | *
168 | * @param view The view which use this drawable.
169 | * */
170 | protected void attachedView(View view){
171 | mViewRef = new WeakReference<>(view);
172 | view.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
173 | @Override
174 | public void onViewAttachedToWindow(View v) {
175 |
176 | }
177 |
178 | @Override
179 | public void onViewDetachedFromWindow(View v) {
180 | v.removeOnAttachStateChangeListener(this);
181 | cancelAnimation();
182 | }
183 | });
184 | }
185 |
186 | /**
187 | * Cancel the gradient animation.
188 | * */
189 | public void cancelAnimation(){
190 | if (valueAnimator != null){
191 | valueAnimator.cancel();
192 | valueAnimator = null;
193 | }
194 |
195 | if (mGradientLayer != null){
196 | if (!mGradientLayer.isRecycled()){
197 | mGradientLayer.recycle();
198 | }
199 |
200 | mGradientLayer = null;
201 | }
202 |
203 | if (mBackgroundLayer != null){
204 | if (!mBackgroundLayer.isRecycled()){
205 | mBackgroundLayer.recycle();
206 | }
207 |
208 | mGradientLayer = null;
209 | }
210 | }
211 | }
212 |
--------------------------------------------------------------------------------
/broccoli/src/main/java/me/samlss/broccoli/BroccoliInternalImpl.java:
--------------------------------------------------------------------------------
1 | package me.samlss.broccoli;
2 |
3 | import android.graphics.Color;
4 | import android.graphics.drawable.Drawable;
5 | import android.view.View;
6 | import android.widget.ImageView;
7 | import android.widget.TextView;
8 |
9 | import java.util.Collections;
10 | import java.util.HashMap;
11 | import java.util.Map;
12 |
13 | import me.samlss.broccoli.util.Utils;
14 |
15 | /**
16 | * @author SamLeung
17 | * @e-mail samlssplus@gmail.com
18 | * @github https://github.com/samlss
19 | * @description Mainly responsible for the show the all the placeholder of views.
20 | */
21 | class BroccoliInternalImpl {
22 | private Map mPlaceholderViewMap;
23 |
24 | public BroccoliInternalImpl() {
25 | synchronizedMap();
26 | }
27 |
28 | private void synchronizedMap(){
29 | mPlaceholderViewMap = Collections.synchronizedMap(new HashMap());
30 | }
31 |
32 | /**
33 | * Add a placeholder for view.
34 | *
35 | * @param parameter The parameter of the placeholder.
36 | * */
37 | protected void addPlaceholder(PlaceholderParameter parameter){
38 | if (mPlaceholderViewMap == null){
39 | synchronizedMap();
40 | }
41 |
42 | mPlaceholderViewMap.put(parameter.getView(), parameter);
43 | }
44 |
45 | /**
46 | * Remove the placeholder of view.
47 | *
48 | * @param view The placeholder of the view which needs to be removed.
49 | * */
50 | protected void removePlaceholder(View view){
51 | if (mPlaceholderViewMap == null){
52 | return;
53 | }
54 |
55 | if (mPlaceholderViewMap.containsKey(view)){
56 | clearPlaceholder(view);
57 | mPlaceholderViewMap.remove(view);
58 | }
59 | }
60 |
61 | protected void clearPlaceholder(View view){
62 | PlaceholderParameter parameter = mPlaceholderViewMap.get(view);
63 | if (view == null
64 | || parameter == null){
65 | return;
66 | }
67 |
68 | view.clearAnimation();
69 |
70 | if (view.getBackground() != null
71 | && view.getBackground() instanceof BroccoliGradientDrawable){
72 | ((BroccoliGradientDrawable)view.getBackground()).cancelAnimation();
73 | }
74 |
75 | if (view instanceof TextView){
76 | restoreTextViewState((TextView) view, parameter.getPlaceholderPreStateSaver());
77 | }else if (view instanceof ImageView){
78 | restoreImageState((ImageView) view, parameter.getPlaceholderPreStateSaver());
79 | }
80 |
81 | restoreBackgroundState(view, parameter.getPlaceholderPreStateSaver());
82 | }
83 |
84 | private void restoreTextViewState(TextView textView, PlaceholderPreStateSaver stateSaver){
85 | if (textView == null
86 | || stateSaver == null){
87 | return;
88 | }
89 |
90 | textView.setTextColor(stateSaver.getRestoredTextColor());
91 | textView.setCompoundDrawables(stateSaver.getRestoredTextLeftDrawable(),
92 | stateSaver.getRestoredTextTopDrawable(),
93 | stateSaver.getRestoredTextRightDrawable(),
94 | stateSaver.getRestoredTextBottomDrawable());
95 | }
96 |
97 | private void restoreImageState(ImageView imageView, PlaceholderPreStateSaver stateSaver){
98 | if (imageView == null
99 | || stateSaver == null){
100 | return;
101 | }
102 |
103 | imageView.setImageDrawable(stateSaver.getRestoredImageDrawable());
104 | Utils.setBackgroundDrawable(imageView, stateSaver.getRestoredBackgroundDrawable());
105 | }
106 |
107 | private void restoreBackgroundState(View view, PlaceholderPreStateSaver stateSaver){
108 | if (view == null
109 | || stateSaver == null){
110 | return;
111 | }
112 |
113 | Utils.setBackgroundDrawable(view, stateSaver.getRestoredBackgroundDrawable());
114 | }
115 |
116 | /**
117 | * Start to show all placeholders for the view you have set.
118 | * */
119 | protected void show(){
120 | if (mPlaceholderViewMap == null
121 | || mPlaceholderViewMap.isEmpty()){
122 | return;
123 | }
124 |
125 | for (PlaceholderParameter parameter : mPlaceholderViewMap.values()){
126 | showPlaceholder(parameter);
127 | showPlaceholderAnimation(parameter);
128 | showPlaceholderGradientDrawableAnimation(parameter);
129 | }
130 | }
131 |
132 | private void showPlaceholderGradientDrawableAnimation(PlaceholderParameter parameter){
133 | if (parameter == null
134 | || parameter.getView() == null
135 | || parameter.getView().getBackground() == null
136 | || parameter.getView().getBackground() instanceof BroccoliGradientDrawable == false){
137 | return;
138 | }
139 |
140 | ((BroccoliGradientDrawable)parameter.getView().getBackground()).attachedView(parameter.getView());
141 | }
142 |
143 | protected void hide(boolean removed){
144 | if (mPlaceholderViewMap == null
145 | || mPlaceholderViewMap.isEmpty()){
146 | return;
147 | }
148 | for (View view : mPlaceholderViewMap.keySet()) {
149 | clearPlaceholder(view);
150 | }
151 |
152 | if (removed) {
153 | mPlaceholderViewMap.clear();
154 | }
155 | }
156 |
157 | private PlaceholderPreStateSaver getOrNewPreStateSaver(PlaceholderParameter parameter){
158 | PlaceholderPreStateSaver placeholderPreStateSaver = parameter.getPlaceholderPreStateSaver();
159 | if (placeholderPreStateSaver == null){
160 | placeholderPreStateSaver = new PlaceholderPreStateSaver();
161 | parameter.setPlaceholderPreStateSaver(placeholderPreStateSaver);
162 | }
163 |
164 | return placeholderPreStateSaver;
165 | }
166 |
167 | private void recordTextViewOriginalState(TextView textView, PlaceholderParameter parameter){
168 | if (textView == null
169 | || parameter == null)
170 | return;
171 |
172 | PlaceholderPreStateSaver placeholderPreStateSaver = getOrNewPreStateSaver(parameter);
173 |
174 | Drawable[] drawables = textView.getCompoundDrawables();
175 | placeholderPreStateSaver.setRestoredTextLeftDrawable(drawables[0]);
176 | placeholderPreStateSaver.setRestoredTextTopDrawable(drawables[1]);
177 | placeholderPreStateSaver.setRestoredTextRightDrawable(drawables[2]);
178 | placeholderPreStateSaver.setRestoredTextBottomDrawable(drawables[3]);
179 |
180 | placeholderPreStateSaver.setRestoredTextColor(textView.getTextColors());
181 | placeholderPreStateSaver.setRestoredBackgroundDrawable(textView.getBackground());
182 |
183 | textView.setCompoundDrawables(null, null, null, null);
184 | textView.setTextColor(Color.TRANSPARENT);
185 | }
186 |
187 | private void recordImageViewOriginalState(ImageView imageView, PlaceholderParameter parameter){
188 | if (imageView == null
189 | || parameter == null)
190 | return;
191 |
192 | PlaceholderPreStateSaver placeholderPreStateSaver = getOrNewPreStateSaver(parameter);
193 | placeholderPreStateSaver.setRestoredImageDrawable(imageView.getDrawable());
194 |
195 | imageView.setImageDrawable(null);
196 | Utils.setBackgroundDrawable(imageView, null);
197 | }
198 |
199 | private void recordBackgroundState(View view, PlaceholderParameter parameter){
200 | if (view == null
201 | || parameter == null)
202 | return;
203 |
204 | PlaceholderPreStateSaver placeholderPreStateSaver = getOrNewPreStateSaver(parameter);
205 | placeholderPreStateSaver.setRestoredBackgroundDrawable(view.getBackground());
206 | }
207 |
208 | private void showPlaceholder(PlaceholderParameter parameter){
209 | if (parameter.getView() == null
210 | || parameter == null){
211 | return;
212 | }
213 | View view = parameter.getView();
214 |
215 |
216 | if (view instanceof ImageView){
217 | recordImageViewOriginalState((ImageView) view, parameter);
218 | } else if(view instanceof TextView){
219 | recordTextViewOriginalState((TextView) view, parameter);
220 | }
221 |
222 | recordBackgroundState(view, parameter);
223 |
224 | if (parameter.getDrawable() != null) {
225 | Utils.setBackgroundDrawable(view, parameter.getDrawable());
226 | return;
227 | }
228 |
229 | if (parameter.getDrawableRes() != 0){
230 | Utils.setBackgroundDrawable(view, Utils.getDrawable(view, parameter.getDrawableRes()));
231 | return;
232 | }
233 |
234 | if (parameter.getColor() != 0){
235 | view.setBackgroundColor(parameter.getColor());
236 | return;
237 | }
238 |
239 | if (parameter.getColorRes() != 0){
240 | view.setBackgroundColor(Utils.getColor(view, parameter.getColorRes()));
241 | return;
242 | }
243 |
244 | view.setBackgroundColor(Broccoli.DEFAULT_PLACEHOLDER_COLOR);
245 | }
246 |
247 | private void showPlaceholderAnimation(PlaceholderParameter parameter){
248 | if (parameter == null
249 | || parameter.getView() == null
250 | || parameter.getAnimation() == null){
251 | return;
252 | }
253 |
254 | parameter.getView().startAnimation(parameter.getAnimation());
255 | }
256 | }
257 |
--------------------------------------------------------------------------------
/broccoli/src/main/java/me/samlss/broccoli/PlaceholderParameter.java:
--------------------------------------------------------------------------------
1 | package me.samlss.broccoli;
2 |
3 | import android.graphics.drawable.Drawable;
4 | import android.view.View;
5 | import android.view.animation.Animation;
6 |
7 | /**
8 | * @author SamLeung
9 | * @e-mail samlssplus@gmail.com
10 | * @github https://github.com/samlss
11 | * @description The parameter of placeholder
12 | */
13 | public class PlaceholderParameter {
14 | private int color;
15 | private int colorRes;
16 | private Drawable drawable;
17 | private int drawableRes;
18 |
19 | private Animation animation;
20 | private View view;
21 | private PlaceholderPreStateSaver placeholderPreStateSaver;
22 |
23 | private PlaceholderParameter(){
24 | }
25 |
26 | public int getColor() {
27 | return color;
28 | }
29 |
30 | public void setColor(int color) {
31 | this.color = color;
32 | }
33 |
34 | public int getColorRes() {
35 | return colorRes;
36 | }
37 |
38 | public void setColorRes(int colorRes) {
39 | this.colorRes = colorRes;
40 | }
41 |
42 | public Drawable getDrawable() {
43 | return drawable;
44 | }
45 |
46 | public void setDrawable(Drawable drawable) {
47 | this.drawable = drawable;
48 | }
49 |
50 | public int getDrawableRes() {
51 | return drawableRes;
52 | }
53 |
54 | public void setDrawableRes(int drawableRes) {
55 | this.drawableRes = drawableRes;
56 | }
57 |
58 | public Animation getAnimation() {
59 | return animation;
60 | }
61 |
62 | public void setAnimation(Animation animation) {
63 | this.animation = animation;
64 | }
65 |
66 | public View getView() {
67 | return view;
68 | }
69 |
70 | public void setView(View view) {
71 | this.view = view;
72 | }
73 |
74 | protected void setPlaceholderPreStateSaver(PlaceholderPreStateSaver placeholderPreStateSaver) {
75 | this.placeholderPreStateSaver = placeholderPreStateSaver;
76 | }
77 |
78 | protected PlaceholderPreStateSaver getPlaceholderPreStateSaver() {
79 | return placeholderPreStateSaver;
80 | }
81 |
82 | public static class Builder{
83 | private PlaceholderParameter mPlaceholderParameter;
84 |
85 | public Builder(){
86 | mPlaceholderParameter = new PlaceholderParameter();
87 | }
88 |
89 | /**
90 | * Set the view which you want to display placeholder.
91 | * */
92 | public Builder setView(View view) {
93 | mPlaceholderParameter.view = view;
94 | return this;
95 | }
96 |
97 | /**
98 | * Set the color of the placeholder.
99 | *
100 | * @param color The color value.
101 | * */
102 | public Builder setColor(int color){
103 | mPlaceholderParameter.setColor(color);
104 | return this;
105 | }
106 |
107 | /**
108 | * Set the color of the placeholder.
109 | *
110 | * @param colorRes The color resource id.
111 | * */
112 | public Builder setColorRes(int colorRes){
113 | mPlaceholderParameter.setColorRes(colorRes);
114 | return this;
115 | }
116 |
117 | /**
118 | * Set the drawable of the placeholder.
119 | *
120 | * @param drawable The drawable.
121 | * */
122 | public Builder setDrawable(Drawable drawable) {
123 | mPlaceholderParameter.drawable = drawable;
124 | return this;
125 | }
126 |
127 | /**
128 | * Set the drawable of the placeholder.
129 | *
130 | * @param drawableRes The drawable resource id.
131 | * */
132 | public Builder setDrawableRes(int drawableRes) {
133 | mPlaceholderParameter.drawableRes = drawableRes;
134 | return this;
135 | }
136 |
137 | public Builder setAnimation(Animation animation){
138 | mPlaceholderParameter.animation = animation;
139 | return this;
140 | }
141 |
142 | /**
143 | * Now build a {@link PlaceholderParameter}
144 | * */
145 | public PlaceholderParameter build(){
146 | return mPlaceholderParameter;
147 | }
148 | }
149 | }
150 |
--------------------------------------------------------------------------------
/broccoli/src/main/java/me/samlss/broccoli/PlaceholderPreStateSaver.java:
--------------------------------------------------------------------------------
1 | package me.samlss.broccoli;
2 |
3 | import android.content.res.ColorStateList;
4 | import android.graphics.drawable.Drawable;
5 | import android.view.View;
6 |
7 | /**
8 | * @author SamLeung
9 | * @e-mail samlssplus@gmail.com
10 | * @github https://github.com/samlss
11 | * @description Used to restore the state of the original view when the placeholder is cleared.
12 | */
13 | class PlaceholderPreStateSaver {
14 | //for TextView.
15 | /**
16 | * This is for {@link android.widget.TextView}, when remove the placeholder of view by calling {@link Broccoli#removePlaceholder(View)}or
17 | * {@link Broccoli#clearPlaceholder(View)}, will set the text color as {@link #restoredTextColor} to {@link android.widget.TextView}
18 | * */
19 | private ColorStateList restoredTextColor;
20 | private Drawable restoredTextLeftDrawable;
21 | private Drawable restoredTextTopDrawable;
22 | private Drawable restoredTextRightDrawable;
23 | private Drawable restoredTextBottomDrawable;
24 |
25 | //for ImageView.
26 | /**
27 | * This is for {@link android.widget.ImageView}, when remove the placeholder of view by calling {@link Broccoli#removePlaceholder(View)} or
28 | * {@link Broccoli#clearPlaceholder(View)}, will set the text color as {@link #restoredTextColor} to {@link android.widget.TextView}
29 | * */
30 | private Drawable restoredImageDrawable;
31 |
32 | //for all views.
33 | private Drawable restoredBackgroundDrawable;
34 |
35 | public PlaceholderPreStateSaver(){
36 |
37 | }
38 |
39 | protected ColorStateList getRestoredTextColor() {
40 | return restoredTextColor;
41 | }
42 |
43 | protected void setRestoredTextColor(ColorStateList restoredTextColor) {
44 | this.restoredTextColor = restoredTextColor;
45 | }
46 |
47 | protected Drawable getRestoredTextLeftDrawable() {
48 | return restoredTextLeftDrawable;
49 | }
50 |
51 | protected void setRestoredTextLeftDrawable(Drawable restoredTextLeftDrawable) {
52 | this.restoredTextLeftDrawable = restoredTextLeftDrawable;
53 | }
54 |
55 | protected Drawable getRestoredTextTopDrawable() {
56 | return restoredTextTopDrawable;
57 | }
58 |
59 | protected void setRestoredTextTopDrawable(Drawable restoredTextTopDrawable) {
60 | this.restoredTextTopDrawable = restoredTextTopDrawable;
61 | }
62 |
63 | protected Drawable getRestoredTextRightDrawable() {
64 | return restoredTextRightDrawable;
65 | }
66 |
67 | protected void setRestoredTextRightDrawable(Drawable restoredTextRightDrawable) {
68 | this.restoredTextRightDrawable = restoredTextRightDrawable;
69 | }
70 |
71 | protected Drawable getRestoredTextBottomDrawable() {
72 | return restoredTextBottomDrawable;
73 | }
74 |
75 | protected void setRestoredTextBottomDrawable(Drawable restoredTextBottomDrawable) {
76 | this.restoredTextBottomDrawable = restoredTextBottomDrawable;
77 | }
78 |
79 | public Drawable getRestoredImageDrawable() {
80 | return restoredImageDrawable;
81 | }
82 |
83 | public void setRestoredImageDrawable(Drawable restoredImageDrawable) {
84 | this.restoredImageDrawable = restoredImageDrawable;
85 | }
86 |
87 | public Drawable getRestoredBackgroundDrawable() {
88 | return restoredBackgroundDrawable;
89 | }
90 |
91 | public void setRestoredBackgroundDrawable(Drawable restoredBackgroundDrawable) {
92 | this.restoredBackgroundDrawable = restoredBackgroundDrawable;
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/broccoli/src/main/java/me/samlss/broccoli/util/LogUtil.java:
--------------------------------------------------------------------------------
1 | package me.samlss.broccoli.util;
2 |
3 | import android.util.Log;
4 |
5 | /**
6 | * @author SamLeung
7 | * @e-mail samlssplus@gmail.com
8 | * @github https://github.com/samlss
9 | * @description util of log for this library.
10 | */
11 | public class LogUtil {
12 | private final static String TAG = "Cradle";
13 |
14 | private LogUtil(){
15 | throw new UnsupportedOperationException("Can not be instantiated.");
16 | }
17 |
18 | public static final void logI(String string){
19 | Log.i(TAG, string);
20 | }
21 |
22 | public static final void logE(String string){
23 | Log.e(TAG, string);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/broccoli/src/main/java/me/samlss/broccoli/util/Utils.java:
--------------------------------------------------------------------------------
1 | package me.samlss.broccoli.util;
2 |
3 | import android.graphics.drawable.Drawable;
4 | import android.os.Build;
5 | import android.view.View;
6 |
7 | /**
8 | * @author SamLeung
9 | * @e-mail samlssplus@gmail.com
10 | * @github https://github.com/samlss
11 | * @description utils of this library.
12 | */
13 | public class Utils {
14 | private Utils(){
15 | throw new UnsupportedOperationException("Can not be instantiated.");
16 | }
17 |
18 | public static void setBackgroundDrawable(View view, Drawable drawable) {
19 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
20 | view.setBackground(drawable);
21 | } else {
22 | view.setBackgroundDrawable(drawable);
23 | }
24 | }
25 |
26 | public static Drawable getDrawable(View view, int id) {
27 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
28 | return view.getResources().getDrawable(id, view.getContext().getTheme());
29 | } else {
30 | return view.getResources().getDrawable(id);
31 | }
32 | }
33 |
34 | public static int getColor(View view, int id) {
35 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
36 | return view.getResources().getColor(id, view.getContext().getTheme());
37 | } else {
38 | return view.getResources().getColor(id);
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/broccoli/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | broccoli
3 |
4 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.2.1'
11 | classpath 'com.novoda:bintray-release:0.8.1'
12 | // NOTE: Do not place your application dependencies here; they belong
13 | // in the individual module build.gradle files
14 | }
15 | }
16 |
17 | allprojects {
18 | repositories {
19 | maven{url "https://jitpack.io"}
20 | google()
21 | jcenter()
22 | }
23 |
24 | tasks.withType(Javadoc) {
25 | options.addStringOption('Xdoclint:none', '-quiet')
26 | options.addStringOption('encoding', 'UTF-8')
27 | }
28 | }
29 |
30 | task clean(type: Delete) {
31 | delete rootProject.buildDir
32 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 |
15 |
16 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhang779/Preloader/4cd3881eedefa291feb90be3d4500fa390b9619a/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/sample/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/sample/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 28
5 | defaultConfig {
6 | applicationId "me.samlss.broccoli_demo"
7 | minSdkVersion 14
8 | targetSdkVersion 28
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 |
20 | android {
21 | lintOptions {
22 | abortOnError false
23 | }
24 | }
25 | }
26 |
27 | dependencies {
28 | implementation fileTree(include: ['*.jar'], dir: 'libs')
29 | implementation 'com.android.support:appcompat-v7:28.0.0'
30 | implementation 'com.android.support:recyclerview-v7:28.0.0'
31 | implementation 'com.android.support:cardview-v7:28.0.0'
32 | implementation 'com.android.support.constraint:constraint-layout:1.1.3'
33 | testImplementation 'junit:junit:4.12'
34 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
35 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
36 | implementation project(':broccoli')
37 | debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.6.2'
38 | releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.2'
39 | implementation 'de.hdodenhof:circleimageview:2.2.0'
40 | }
41 |
--------------------------------------------------------------------------------
/sample/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 |
--------------------------------------------------------------------------------
/sample/src/androidTest/java/me/samlss/broccoli_demo/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package me.samlss.broccoli_demo;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("me.samlss.broccoli_demo", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/sample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/sample/src/main/java/me/samlss/broccoli_demo/App.java:
--------------------------------------------------------------------------------
1 | package me.samlss.broccoli_demo;
2 |
3 | import android.app.Application;
4 |
5 | import com.squareup.leakcanary.LeakCanary;
6 | import com.squareup.leakcanary.RefWatcher;
7 |
8 | /**
9 | * @author SamLeung
10 | * @e-mail samlssplus@gmail.com
11 | * @github https://github.com/samlss
12 | * @description
13 | */
14 | public class App extends Application {
15 | public static RefWatcher sRefWatcher;
16 |
17 | @Override public void onCreate() {
18 | super.onCreate();
19 | if (LeakCanary.isInAnalyzerProcess(this)) {
20 | // This process is dedicated to LeakCanary for heap analysis.
21 | // You should not init your app in this process.
22 | return;
23 | }
24 | sRefWatcher = LeakCanary.install(this);
25 | // Normal app init code...
26 | }
27 |
28 | public static RefWatcher getRefWatcher(){
29 | return sRefWatcher;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/sample/src/main/java/me/samlss/broccoli_demo/DingDingSampleActivity.java:
--------------------------------------------------------------------------------
1 | package me.samlss.broccoli_demo;
2 |
3 | import android.graphics.Color;
4 | import android.os.Bundle;
5 | import android.os.Handler;
6 | import android.support.annotation.Nullable;
7 | import android.support.v7.app.AppCompatActivity;
8 |
9 | import me.samlss.broccoli.Broccoli;
10 | import me.samlss.broccoli.PlaceholderParameter;
11 |
12 | /**
13 | * @author SamLeung
14 | * @e-mail samlssplus@gmail.com
15 | * @github https://github.com/samlss
16 | * @description ding ding check work sample.
17 | */
18 | public class DingDingSampleActivity extends AppCompatActivity {
19 | private Broccoli mBroccoli;
20 | private Handler mHandler = new Handler();
21 |
22 | @Override
23 | protected void onCreate(@Nullable Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 | setContentView(R.layout.activity_dingding);
26 |
27 | initPlaceholders();
28 | }
29 |
30 | private void initPlaceholders(){
31 | int placeholderColor = Color.parseColor("#DDDDDD");
32 |
33 | mBroccoli = new Broccoli();
34 | mBroccoli.addPlaceholders(
35 |
36 | new PlaceholderParameter.Builder()
37 | .setView(findViewById(R.id.iv_head))
38 | .setDrawable(DrawableUtils.createOvalDrawable(placeholderColor))
39 | .build(),
40 |
41 | new PlaceholderParameter.Builder()
42 | .setView(findViewById(R.id.tv_name))
43 | .setDrawable(DrawableUtils.createRectangleDrawable(placeholderColor, 0))
44 | .build(),
45 |
46 | new PlaceholderParameter.Builder()
47 | .setView(findViewById(R.id.tv_description))
48 | .setDrawable(DrawableUtils.createRectangleDrawable(placeholderColor, 0))
49 | .build(),
50 |
51 | new PlaceholderParameter.Builder()
52 | .setView(findViewById(R.id.tv_day_des))
53 | .setDrawable(DrawableUtils.createRectangleDrawable(placeholderColor, 0))
54 | .build(),
55 |
56 | new PlaceholderParameter.Builder()
57 | .setView(findViewById(R.id.v_shangban))
58 | .setDrawable(DrawableUtils.createOvalDrawable(placeholderColor))
59 | .build(),
60 |
61 | new PlaceholderParameter.Builder()
62 | .setView(findViewById(R.id.v_xiaban))
63 | .setDrawable(DrawableUtils.createOvalDrawable(placeholderColor))
64 | .build(),
65 |
66 | new PlaceholderParameter.Builder()
67 | .setView(findViewById(R.id.v_timeline))
68 | .setDrawable(DrawableUtils.createRectangleDrawable(placeholderColor, 0))
69 | .build(),
70 |
71 | new PlaceholderParameter.Builder()
72 | .setView(findViewById(R.id.tv_shangban))
73 | .setDrawable(DrawableUtils.createRectangleDrawable(placeholderColor, 0))
74 | .build(),
75 |
76 | new PlaceholderParameter.Builder()
77 | .setView(findViewById(R.id.tv_xiaban))
78 | .setDrawable(DrawableUtils.createRectangleDrawable(placeholderColor, 0))
79 | .build(),
80 |
81 | new PlaceholderParameter.Builder()
82 | .setView(findViewById(R.id.tv_daka))
83 | .setDrawable(DrawableUtils.createOvalDrawable(placeholderColor))
84 | .build(),
85 |
86 | new PlaceholderParameter.Builder()
87 | .setView(findViewById(R.id.tv_daka_des))
88 | .setDrawable(DrawableUtils.createRectangleDrawable(placeholderColor, 0))
89 | .build()
90 |
91 | );
92 |
93 | showPlaceholders();
94 | }
95 |
96 | private void showPlaceholders(){
97 | mBroccoli.show();
98 | mHandler.removeCallbacks(task);
99 | mHandler.postDelayed(task,2000);
100 | }
101 |
102 | private Runnable task = new Runnable() {
103 | @Override
104 | public void run() {
105 | mBroccoli.removeAllPlaceholders();
106 | }
107 | };
108 | }
109 |
--------------------------------------------------------------------------------
/sample/src/main/java/me/samlss/broccoli_demo/DrawableUtils.java:
--------------------------------------------------------------------------------
1 | package me.samlss.broccoli_demo;
2 |
3 | import android.annotation.TargetApi;
4 | import android.graphics.drawable.Drawable;
5 | import android.graphics.drawable.GradientDrawable;
6 | import android.os.Build;
7 | import android.view.View;
8 |
9 | /**
10 | * @author SamLeung
11 | * @e-mail samlssplus@gmail.com
12 | * @github https://github.com/samlss
13 | * @description The utils of drawable.
14 | */
15 | public class DrawableUtils {
16 | private DrawableUtils(){
17 | throw new UnsupportedOperationException("Can not be instantiated.");
18 | }
19 |
20 | public static GradientDrawable createRectangleDrawable(int color, float cornerRadius) {
21 | GradientDrawable gradientDrawable = new GradientDrawable();
22 | gradientDrawable.setShape(GradientDrawable.RECTANGLE);
23 | gradientDrawable.setCornerRadius(cornerRadius);
24 | gradientDrawable.setColor(color);
25 | return gradientDrawable;
26 | }
27 |
28 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
29 | public static GradientDrawable createRectangleDrawable(int[] colors, float cornerRadius) {
30 | GradientDrawable gradientDrawable = new GradientDrawable();
31 | gradientDrawable.setShape(GradientDrawable.RECTANGLE);
32 | gradientDrawable.setCornerRadius(cornerRadius);
33 | gradientDrawable.setColors(colors);
34 | return gradientDrawable;
35 | }
36 |
37 | public static GradientDrawable createOvalDrawable(int color) {
38 | GradientDrawable gradientDrawable = new GradientDrawable();
39 | gradientDrawable.setShape(GradientDrawable.OVAL);
40 | gradientDrawable.setColor(color);
41 | return gradientDrawable;
42 | }
43 |
44 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
45 | public static GradientDrawable createOvalDrawable(int[] colors) {
46 | GradientDrawable gradientDrawable = new GradientDrawable();
47 | gradientDrawable.setShape(GradientDrawable.OVAL);
48 | gradientDrawable.setColors(colors);
49 | return gradientDrawable;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/sample/src/main/java/me/samlss/broccoli_demo/LayoutAdvancedSampleActivity.java:
--------------------------------------------------------------------------------
1 | package me.samlss.broccoli_demo;
2 |
3 | import android.graphics.Color;
4 | import android.os.Build;
5 | import android.os.Bundle;
6 | import android.os.Handler;
7 | import android.support.annotation.Nullable;
8 | import android.support.v7.app.AppCompatActivity;
9 | import android.view.MotionEvent;
10 | import android.view.View;
11 | import android.view.animation.BounceInterpolator;
12 | import android.widget.ImageView;
13 | import android.widget.TextView;
14 |
15 | import me.samlss.broccoli.Broccoli;
16 |
17 |
18 | /**
19 | * @author SamLeung
20 | * @e-mail samlssplus@gmail.com
21 | * @github https://github.com/samlss
22 | * @description The layout sample.
23 | */
24 | public class LayoutAdvancedSampleActivity extends AppCompatActivity {
25 | private TextView tvViewTimes;
26 | private TextView tvCollectTimes;
27 | private TextView tvPrice;
28 | private ImageView ivClock;
29 | private TextView tvTime;
30 | private ImageView ivCalendar;
31 | private ImageView ivLocation;
32 | private TextView tvLocation;
33 | private ImageView ivRightArrow;
34 | private View vLine;
35 | private ImageView ivLogo;
36 | private TextView tvOrganizer;
37 | private TextView tvOrganizerDescription;
38 | private TextView tvFans;
39 | private TextView tvFansNumber;
40 | private TextView tvEvents;
41 | private TextView tvEventsNumber;
42 | private TextView tvFollow;
43 | private TextView tvStation;
44 |
45 | private Broccoli mBroccoli;
46 | private Handler mHandler = new Handler();
47 | @Override
48 | protected void onCreate(@Nullable Bundle savedInstanceState) {
49 | super.onCreate(savedInstanceState);
50 |
51 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
52 | getWindow().setStatusBarColor(Color.parseColor("#847465"));
53 | }
54 | setContentView(R.layout.activity_layout_sample);
55 |
56 | initViews();
57 | initPlaceholders();
58 | }
59 |
60 | private void initViews(){
61 | tvViewTimes = findViewById(R.id.tv_view_time);
62 | tvCollectTimes = findViewById(R.id.tv_collect_time);
63 | tvPrice = findViewById(R.id.tv_price);
64 | ivClock = findViewById(R.id.iv_clock);
65 | tvTime = findViewById(R.id.tv_time);
66 | ivCalendar = findViewById(R.id.iv_calendar);
67 | ivLocation = findViewById(R.id.iv_location);
68 | tvLocation = findViewById(R.id.tv_location);
69 | ivRightArrow = findViewById(R.id.iv_arrow_right);
70 | vLine = findViewById(R.id.view_line);
71 | ivLogo = findViewById(R.id.iv_logo);
72 | tvOrganizer = findViewById(R.id.tv_organizer_name);
73 | tvOrganizerDescription = findViewById(R.id.tv_organizer_description);
74 | tvFans = findViewById(R.id.tv_fans);
75 | tvFansNumber = findViewById(R.id.tv_fans_number);
76 | tvEvents = findViewById(R.id.tv_events);
77 | tvEventsNumber = findViewById(R.id.tv_events_number);
78 | tvFollow = findViewById(R.id.tv_follow);
79 | tvStation = findViewById(R.id.tv_station);
80 |
81 | findViewById(R.id.iv_retry).setOnTouchListener(new View.OnTouchListener() {
82 | @Override
83 | public boolean onTouch(View v, MotionEvent event) {
84 | v.setPivotX(v.getWidth() / 2);
85 | v.setPivotY(v.getHeight() / 2);
86 |
87 | if (event.getAction() == MotionEvent.ACTION_DOWN){
88 | v.animate()
89 | .scaleX(1.3f)
90 | .scaleY(1.3f)
91 | .setInterpolator(new BounceInterpolator())
92 | .setDuration(300)
93 | .start();
94 | }else if (event.getAction() == MotionEvent.ACTION_CANCEL
95 | || event.getAction() == MotionEvent.ACTION_UP){
96 | v.animate()
97 | .scaleX(1)
98 | .scaleY(1)
99 | .setInterpolator(new BounceInterpolator())
100 | .setDuration(300)
101 | .start();
102 | }
103 | return false;
104 | }
105 | });
106 | }
107 |
108 | private void initPlaceholders(){
109 | mBroccoli = new Broccoli();
110 | mBroccoli.addPlaceholders(PlaceholderHelper.getParameter(tvViewTimes),
111 | PlaceholderHelper.getParameter(tvCollectTimes),
112 | PlaceholderHelper.getParameter(tvPrice),
113 | PlaceholderHelper.getParameter(ivClock),
114 | PlaceholderHelper.getParameter(tvTime),
115 | PlaceholderHelper.getParameter(ivCalendar),
116 | PlaceholderHelper.getParameter(ivLocation),
117 | PlaceholderHelper.getParameter(tvLocation),
118 | PlaceholderHelper.getParameter(ivRightArrow),
119 | PlaceholderHelper.getParameter(ivLogo),
120 | PlaceholderHelper.getParameter(tvOrganizer),
121 | PlaceholderHelper.getParameter(tvOrganizerDescription),
122 | PlaceholderHelper.getParameter(tvFans),
123 | PlaceholderHelper.getParameter(tvFansNumber),
124 | PlaceholderHelper.getParameter(tvEvents),
125 | PlaceholderHelper.getParameter(tvEventsNumber),
126 | PlaceholderHelper.getParameter(tvFollow),
127 | PlaceholderHelper.getParameter(tvStation)
128 | );
129 |
130 | showPlaceholders();
131 | }
132 |
133 | private void showPlaceholders(){
134 | mBroccoli.show();
135 |
136 | mHandler.removeCallbacks(task);
137 | mHandler.postDelayed(task,3000);
138 | }
139 |
140 | private Runnable task = new Runnable() {
141 | @Override
142 | public void run() {
143 | showData();
144 | }
145 | };
146 |
147 | private void showData(){
148 | mBroccoli.clearAllPlaceholders();
149 | }
150 |
151 | public void onRetry(View view) {
152 | showPlaceholders();
153 | }
154 | }
155 |
--------------------------------------------------------------------------------
/sample/src/main/java/me/samlss/broccoli_demo/LayoutSimpleSampleActivity.java:
--------------------------------------------------------------------------------
1 | package me.samlss.broccoli_demo;
2 |
3 | import android.graphics.Color;
4 | import android.os.Build;
5 | import android.os.Bundle;
6 | import android.os.Handler;
7 | import android.support.annotation.Nullable;
8 | import android.support.v7.app.AppCompatActivity;
9 | import android.view.MotionEvent;
10 | import android.view.View;
11 | import android.view.animation.BounceInterpolator;
12 |
13 | import me.samlss.broccoli.Broccoli;
14 |
15 |
16 | /**
17 | * @author SamLeung
18 | * @e-mail samlssplus@gmail.com
19 | * @github https://github.com/samlss
20 | * @description The layout sample.
21 | */
22 | public class LayoutSimpleSampleActivity extends AppCompatActivity {
23 | public Broccoli mBroccoli;
24 | private Handler mHandler = new Handler();
25 | @Override
26 | protected void onCreate(@Nullable Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 |
29 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
30 | getWindow().setStatusBarColor(Color.parseColor("#847465"));
31 | }
32 | setContentView(R.layout.activity_layout_sample);
33 |
34 | initViews();
35 | initPlaceholders();
36 | }
37 |
38 | private void initViews(){
39 | findViewById(R.id.iv_retry).setOnTouchListener(new View.OnTouchListener() {
40 | @Override
41 | public boolean onTouch(View v, MotionEvent event) {
42 | v.setPivotX(v.getWidth() / 2);
43 | v.setPivotY(v.getHeight() / 2);
44 |
45 | if (event.getAction() == MotionEvent.ACTION_DOWN){
46 | v.animate()
47 | .scaleX(1.3f)
48 | .scaleY(1.3f)
49 | .setInterpolator(new BounceInterpolator())
50 | .setDuration(300)
51 | .start();
52 | }else if (event.getAction() == MotionEvent.ACTION_CANCEL
53 | || event.getAction() == MotionEvent.ACTION_UP){
54 | v.animate()
55 | .scaleX(1)
56 | .scaleY(1)
57 | .setInterpolator(new BounceInterpolator())
58 | .setDuration(300)
59 | .start();
60 | }
61 | return false;
62 | }
63 | });
64 | }
65 |
66 |
67 | private void initPlaceholders(){
68 | mBroccoli = new Broccoli();
69 | mBroccoli.addPlaceholders(this, R.id.tv_view_time, R.id.tv_collect_time,
70 | R.id.tv_price, R.id.iv_clock, R.id.tv_time, R.id.iv_calendar, R.id.iv_location,
71 | R.id.tv_location, R.id.iv_arrow_right, R.id.iv_logo, R.id.tv_organizer_name, R.id.tv_organizer_description,
72 | R.id.tv_fans, R.id.tv_fans_number, R.id.tv_events, R.id.tv_events_number, R.id.tv_follow, R.id.tv_station);
73 |
74 | showPlaceholders();
75 | }
76 |
77 | private void showPlaceholders(){
78 | mBroccoli.show();
79 | mHandler.removeCallbacks(task);
80 | mHandler.postDelayed(task,2000);
81 | }
82 |
83 | private Runnable task = new Runnable() {
84 | @Override
85 | public void run() {
86 | showData();
87 | }
88 | };
89 |
90 | private void showData() {
91 | mBroccoli.clearAllPlaceholders();
92 | }
93 |
94 | public void onRetry(View view) {
95 | showPlaceholders();
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/sample/src/main/java/me/samlss/broccoli_demo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package me.samlss.broccoli_demo;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 |
8 | public class MainActivity extends AppCompatActivity {
9 |
10 | @Override
11 | protected void onCreate(Bundle savedInstanceState) {
12 | super.onCreate(savedInstanceState);
13 | setContentView(R.layout.activity_main);
14 | }
15 |
16 | public void startLayoutSample(View view) {
17 | startActivity(new Intent(this, LayoutSimpleSampleActivity.class));
18 | }
19 |
20 | public void startRecyclerViewSample(View view) {
21 | startActivity(new Intent(this, RecyclerViewSampleActivity.class));
22 | }
23 |
24 | public void startAdvancedLayoutSample(View view) {
25 | startActivity(new Intent(this, LayoutAdvancedSampleActivity.class));
26 | }
27 |
28 | public void startDingDingSample(View view) {
29 | startActivity(new Intent(this, DingDingSampleActivity.class));
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/sample/src/main/java/me/samlss/broccoli_demo/PlaceholderHelper.java:
--------------------------------------------------------------------------------
1 | package me.samlss.broccoli_demo;
2 |
3 | import android.graphics.Color;
4 | import android.view.View;
5 | import android.view.animation.Animation;
6 | import android.view.animation.ScaleAnimation;
7 |
8 | import me.samlss.broccoli.PlaceholderParameter;
9 |
10 | /**
11 | * @author SamLeung
12 | * @e-mail samlssplus@gmail.com
13 | * @github https://github.com/samlss
14 | * @description helper of placeholder
15 | */
16 | public class PlaceholderHelper {
17 | private PlaceholderHelper() {
18 | throw new UnsupportedOperationException("Can not be instantiated.");
19 | }
20 |
21 | public static PlaceholderParameter getParameter(View view) {
22 | if (view == null) {
23 | return null;
24 | }
25 | int placeHolderColor = Color.parseColor("#dddddd");
26 |
27 | switch (view.getId()) {
28 | case R.id.tv_view_time:
29 | return new PlaceholderParameter.Builder()
30 | .setView(view)
31 | .setDrawable(DrawableUtils.createRectangleDrawable(placeHolderColor, 0))
32 | .build();
33 |
34 | case R.id.tv_collect_time:
35 | return new PlaceholderParameter.Builder()
36 | .setView(view)
37 | .setDrawable(DrawableUtils.createRectangleDrawable(placeHolderColor, 0))
38 | .build();
39 |
40 |
41 | case R.id.tv_price:
42 | return new PlaceholderParameter.Builder()
43 | .setView(view)
44 | .setDrawable(DrawableUtils.createRectangleDrawable(placeHolderColor, 5))
45 | .build();
46 |
47 | case R.id.iv_clock:
48 | return new PlaceholderParameter.Builder()
49 | .setView(view)
50 | .setDrawable(DrawableUtils.createOvalDrawable(placeHolderColor))
51 | .build();
52 |
53 | case R.id.tv_time:
54 | Animation timeAnimation = new ScaleAnimation(0.3f, 1, 1, 1);
55 | timeAnimation.setDuration(600);
56 | timeAnimation.setRepeatMode(Animation.REVERSE);
57 | timeAnimation.setRepeatCount(Animation.INFINITE);
58 | return new PlaceholderParameter.Builder()
59 | .setView(view)
60 | .setAnimation(timeAnimation)
61 | .setDrawable(DrawableUtils.createRectangleDrawable(placeHolderColor, 5))
62 | .build();
63 |
64 | case R.id.iv_calendar:
65 | return new PlaceholderParameter.Builder()
66 | .setView(view)
67 | .setDrawable(DrawableUtils.createOvalDrawable(placeHolderColor))
68 | .build();
69 |
70 | case R.id.iv_location:
71 | return new PlaceholderParameter.Builder()
72 | .setView(view)
73 | .setDrawable(DrawableUtils.createOvalDrawable(placeHolderColor))
74 | .build();
75 |
76 | case R.id.tv_location:
77 | Animation locationAnimation = new ScaleAnimation(0.4f, 1, 1, 1);
78 | locationAnimation.setDuration(800);
79 | locationAnimation.setRepeatMode(Animation.REVERSE);
80 | locationAnimation.setRepeatCount(Animation.INFINITE);
81 | return new PlaceholderParameter.Builder()
82 | .setView(view)
83 | .setAnimation(locationAnimation)
84 | .setDrawable(DrawableUtils.createRectangleDrawable(placeHolderColor, 5))
85 | .build();
86 |
87 | case R.id.iv_arrow_right:
88 | return new PlaceholderParameter.Builder()
89 | .setView(view)
90 | .setDrawable(DrawableUtils.createOvalDrawable(placeHolderColor))
91 | .build();
92 |
93 | case R.id.iv_logo:
94 | Animation scaleAnimation = new ScaleAnimation(0.5f, 1f, 0.5f, 1f, Animation.RELATIVE_TO_SELF ,0.5f,
95 | Animation.RELATIVE_TO_SELF, 0.5f);
96 | scaleAnimation.setDuration(800);
97 | scaleAnimation.setRepeatMode(Animation.REVERSE);
98 | scaleAnimation.setRepeatCount(Animation.INFINITE);
99 | return new PlaceholderParameter.Builder()
100 | .setView(view)
101 | .setAnimation(scaleAnimation)
102 | .setDrawable(DrawableUtils.createOvalDrawable(placeHolderColor))
103 | .build();
104 |
105 | case R.id.tv_organizer_name:
106 | Animation onAnimation = new ScaleAnimation(0.45f, 1, 1, 1);
107 | onAnimation.setDuration(550);
108 | onAnimation.setRepeatMode(Animation.REVERSE);
109 | onAnimation.setRepeatCount(Animation.INFINITE);
110 |
111 | return new PlaceholderParameter.Builder()
112 | .setView(view)
113 | .setAnimation(onAnimation)
114 | .setDrawable(DrawableUtils.createRectangleDrawable(placeHolderColor, 5))
115 | .build();
116 |
117 | case R.id.tv_organizer_description:
118 | Animation odAnimation = new ScaleAnimation(0.35f, 1, 1, 1);
119 | odAnimation.setDuration(650);
120 | odAnimation.setRepeatMode(Animation.REVERSE);
121 | odAnimation.setRepeatCount(Animation.INFINITE);
122 |
123 | return new PlaceholderParameter.Builder()
124 | .setView(view)
125 | .setAnimation(odAnimation)
126 | .setDrawable(DrawableUtils.createRectangleDrawable(placeHolderColor, 5))
127 | .build();
128 |
129 | case R.id.tv_fans:
130 | return new PlaceholderParameter.Builder()
131 | .setView(view)
132 | .setDrawable(DrawableUtils.createRectangleDrawable(placeHolderColor, 0))
133 | .build();
134 |
135 | case R.id.tv_fans_number:
136 | return new PlaceholderParameter.Builder()
137 | .setView(view)
138 | .setDrawable(DrawableUtils.createRectangleDrawable(placeHolderColor, 0))
139 | .build();
140 |
141 | case R.id.tv_events:
142 | return new PlaceholderParameter.Builder()
143 | .setView(view)
144 | .setDrawable(DrawableUtils.createRectangleDrawable(placeHolderColor, 0))
145 | .build();
146 |
147 | case R.id.tv_events_number:
148 | return new PlaceholderParameter.Builder()
149 | .setView(view)
150 | .setDrawable(DrawableUtils.createRectangleDrawable(placeHolderColor, 0))
151 | .build();
152 |
153 | case R.id.tv_follow:
154 | return new PlaceholderParameter.Builder()
155 | .setView(view)
156 | .setDrawable(DrawableUtils.createRectangleDrawable(placeHolderColor, 5))
157 | .build();
158 |
159 | case R.id.tv_station:
160 | return new PlaceholderParameter.Builder()
161 | .setView(view)
162 | .setDrawable(DrawableUtils.createRectangleDrawable(placeHolderColor, 5))
163 | .build();
164 |
165 | }
166 |
167 | return null;
168 | }
169 | }
170 |
--------------------------------------------------------------------------------
/sample/src/main/java/me/samlss/broccoli_demo/RecyclerViewSampleActivity.java:
--------------------------------------------------------------------------------
1 | package me.samlss.broccoli_demo;
2 |
3 | import android.graphics.Color;
4 | import android.os.Bundle;
5 | import android.support.annotation.NonNull;
6 | import android.support.annotation.Nullable;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.support.v7.widget.LinearLayoutManager;
9 | import android.support.v7.widget.RecyclerView;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 | import android.view.animation.BounceInterpolator;
13 | import android.view.animation.LinearInterpolator;
14 | import android.widget.ImageView;
15 | import android.widget.TextView;
16 |
17 | import java.util.ArrayList;
18 | import java.util.HashMap;
19 | import java.util.List;
20 | import java.util.Map;
21 |
22 | import me.samlss.broccoli.Broccoli;
23 | import me.samlss.broccoli.PlaceholderParameter;
24 | import me.samlss.broccoli.BroccoliGradientDrawable;
25 |
26 | /**
27 | * @author SamLeung
28 | * @e-mail samlssplus@gmail.com
29 | * @github https://github.com/samlss
30 | * @description Sample of RecyclerView.
31 | */
32 | public class RecyclerViewSampleActivity extends AppCompatActivity {
33 | private static int[] sImageIds = new int[]{
34 | R.mipmap.photo_1,R.mipmap.photo_2,
35 | R.mipmap.photo_3,R.mipmap.photo_4,
36 | R.mipmap.photo_5
37 | };
38 |
39 | private static int[] sPrices = new int[]{
40 | 549, 1499, 1199, 1699, 3388
41 | };
42 |
43 | private static String[] sTitles = new String[]{
44 | "honor/荣耀 畅玩7",
45 | "Huawei/华为 畅想MAX",
46 | "honor/荣耀 荣耀9i",
47 | "Huawei/华为 畅想9 PLUS",
48 | "Huawei/华为 P20",
49 | };
50 |
51 | private static String[] sDescriptions = new String[]{
52 | "2018.05上市 | 免举证退换货",
53 | "2018.10上市 | 免举证退换货",
54 | "2018.06上市 | 免举证退换货",
55 | "2018.10上市 | 免举证退换货",
56 | "2018.04上市 | 免举证退换货",
57 | };
58 | private RecyclerView mRecyclerView;
59 | private MyAdapter myAdapter;
60 | private List mDataList = new ArrayList<>();
61 |
62 |
63 | private Map mViewPlaceholderManager = new HashMap<>();
64 | private Map mTaskManager = new HashMap<>();
65 |
66 | @Override
67 | protected void onCreate(@Nullable Bundle savedInstanceState) {
68 | super.onCreate(savedInstanceState);
69 | setContentView(R.layout.activity_recyclerview_sample);
70 |
71 | initData();
72 | initRecyclerView();
73 | }
74 |
75 | @Override
76 | protected void onDestroy() {
77 | super.onDestroy();
78 | mDataList.clear();
79 |
80 | for (View view : mTaskManager.keySet()){
81 | view.removeCallbacks(mTaskManager.get(view));
82 | }
83 |
84 | //Prevent memory leaks when using BroccoliGradientDrawable
85 | //防止使用BroccoliGradientDrawable时内存泄露
86 | for (Broccoli broccoli : mViewPlaceholderManager.values()){
87 | broccoli.removeAllPlaceholders();
88 | }
89 |
90 | mViewPlaceholderManager.clear();
91 | mTaskManager.clear();
92 | }
93 |
94 | private void initData(){
95 | for (int i = 0; i < 20; i++){
96 | DataBean dataBean = new DataBean();
97 | dataBean.imageRes = sImageIds[i % sImageIds.length];
98 | dataBean.title = sTitles[i % sTitles.length];
99 | dataBean.description = sDescriptions[i % sDescriptions.length];
100 | dataBean.price = sPrices[i % sPrices.length];
101 |
102 | mDataList.add(dataBean);
103 | }
104 | }
105 |
106 | private void initRecyclerView(){
107 | mRecyclerView = findViewById(R.id.recyclerview);
108 | mRecyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
109 |
110 | myAdapter = new MyAdapter();
111 | mRecyclerView.setAdapter(myAdapter);
112 | }
113 |
114 |
115 | private class MyAdapter extends RecyclerView.Adapter{
116 |
117 | @NonNull
118 | @Override
119 | public MyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
120 | View view = getLayoutInflater().inflate(R.layout.recyclerview_sample_item, viewGroup, false);
121 | return new MyViewHolder(view);
122 | }
123 |
124 | @Override
125 | public void onBindViewHolder(@NonNull final MyViewHolder myViewHolder, final int i) {
126 | Broccoli broccoli = mViewPlaceholderManager.get(myViewHolder.itemView);
127 | if (broccoli == null){
128 | broccoli = new Broccoli();
129 | mViewPlaceholderManager.put(myViewHolder.itemView, broccoli);
130 | }
131 |
132 | broccoli.removeAllPlaceholders();
133 | broccoli.addPlaceholder(new PlaceholderParameter.Builder()
134 | .setView(myViewHolder.tvTitle)
135 | .setDrawable(new BroccoliGradientDrawable(Color.parseColor("#DDDDDD"),
136 | Color.parseColor("#CCCCCC"), 0, 1000, new LinearInterpolator()))
137 | .build());
138 | broccoli.addPlaceholder(new PlaceholderParameter.Builder()
139 | .setView(myViewHolder.imageView)
140 | .setDrawable(new BroccoliGradientDrawable(Color.parseColor("#DDDDDD"),
141 | Color.parseColor("#CCCCCC"), 0, 1000, new LinearInterpolator()))
142 | .build());
143 | broccoli.addPlaceholder(new PlaceholderParameter.Builder()
144 | .setView(myViewHolder.tvPrice)
145 | .setDrawable(new BroccoliGradientDrawable(Color.parseColor("#DDDDDD"),
146 | Color.parseColor("#CCCCCC"), 0, 1000, new LinearInterpolator()))
147 | .build());
148 | broccoli.addPlaceholder(new PlaceholderParameter.Builder()
149 | .setView(myViewHolder.tvDescription)
150 | .setDrawable(new BroccoliGradientDrawable(Color.parseColor("#DDDDDD"),
151 | Color.parseColor("#CCCCCC"), 0, 1000, new LinearInterpolator()))
152 | .build());
153 | broccoli.show();
154 |
155 |
156 | //delay to show the data
157 | Runnable task = mTaskManager.get(myViewHolder.itemView);
158 | if (task == null){
159 | final Broccoli finalBroccoli = broccoli;
160 | task = new Runnable() {
161 | @Override
162 | public void run() {
163 | //when you need to update data, you must to call the remove or the clear method.
164 | finalBroccoli.removeAllPlaceholders();
165 |
166 | if (mDataList.isEmpty()){
167 | return;
168 | }
169 |
170 | myViewHolder.imageView.setImageResource(mDataList.get(i).imageRes);
171 | myViewHolder.tvPrice.setText("¥ "+String.valueOf(mDataList.get(i).price));
172 | myViewHolder.tvTitle.setText(mDataList.get(i).title);
173 | myViewHolder.tvDescription.setText(mDataList.get(i).description);
174 | }
175 | };
176 | mTaskManager.put(myViewHolder.itemView, task);
177 | }else{
178 | myViewHolder.itemView.removeCallbacks(task);
179 | }
180 | myViewHolder.itemView.postDelayed(task, 3000);
181 | }
182 |
183 | @Override
184 | public int getItemCount() {
185 | return mDataList.size();
186 | }
187 | }
188 |
189 | private class MyViewHolder extends RecyclerView.ViewHolder{
190 | private ImageView imageView;
191 | private TextView tvTitle;
192 | private TextView tvDescription;
193 | private TextView tvPrice;
194 |
195 | public MyViewHolder(@NonNull View itemView) {
196 | super(itemView);
197 |
198 | imageView = itemView.findViewById(R.id.iv_image);
199 | tvTitle = itemView.findViewById(R.id.tv_title);
200 | tvDescription = itemView.findViewById(R.id.tv_description);
201 | tvPrice = itemView.findViewById(R.id.tv_price);
202 | }
203 | }
204 |
205 |
206 | private static class DataBean{
207 | int imageRes;
208 | private String title;
209 | private String description;
210 | private int price;
211 | }
212 | }
213 |
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/button_shape.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/drawable_dingding.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
8 |
9 |
12 |
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/ic_samlss_head_photo.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhang779/Preloader/4cd3881eedefa291feb90be3d4500fa390b9619a/sample/src/main/res/drawable/ic_samlss_head_photo.jpg
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_dingding.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
14 |
15 |
20 |
21 |
26 |
27 |
34 |
35 |
42 |
43 |
44 |
45 |
46 |
52 |
53 |
61 |
62 |
66 |
67 |
75 |
76 |
81 |
82 |
87 |
88 |
89 |
94 |
95 |
96 |
105 |
106 |
115 |
116 |
122 |
123 |
132 |
133 |
142 |
143 |
144 |
145 |
146 |
147 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_layout_sample.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
19 |
20 |
24 |
25 |
29 |
30 |
38 |
39 |
47 |
48 |
53 |
54 |
59 |
60 |
65 |
66 |
67 |
68 |
78 |
79 |
83 |
84 |
89 |
90 |
100 |
101 |
107 |
108 |
109 |
110 |
114 |
115 |
120 |
121 |
131 |
132 |
138 |
139 |
140 |
141 |
142 |
148 |
149 |
156 |
157 |
162 |
163 |
168 |
169 |
174 |
175 |
184 |
185 |
195 |
196 |
200 |
201 |
211 |
212 |
221 |
222 |
232 |
233 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
254 |
255 |
266 |
267 |
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 |
294 |
295 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
21 |
22 |
28 |
29 |
35 |
36 |
42 |
43 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_recyclerview_sample.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/recyclerview_sample_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
17 |
18 |
26 |
27 |
33 |
34 |
44 |
45 |
51 |
52 |
53 |
63 |
64 |
72 |
73 |
74 |
75 |
76 |
77 |
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhang779/Preloader/4cd3881eedefa291feb90be3d4500fa390b9619a/sample/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhang779/Preloader/4cd3881eedefa291feb90be3d4500fa390b9619a/sample/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhang779/Preloader/4cd3881eedefa291feb90be3d4500fa390b9619a/sample/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/icon_arrow_right.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhang779/Preloader/4cd3881eedefa291feb90be3d4500fa390b9619a/sample/src/main/res/mipmap-xhdpi/icon_arrow_right.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/icon_calendar.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhang779/Preloader/4cd3881eedefa291feb90be3d4500fa390b9619a/sample/src/main/res/mipmap-xhdpi/icon_calendar.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/icon_clock.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhang779/Preloader/4cd3881eedefa291feb90be3d4500fa390b9619a/sample/src/main/res/mipmap-xhdpi/icon_clock.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/icon_events.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhang779/Preloader/4cd3881eedefa291feb90be3d4500fa390b9619a/sample/src/main/res/mipmap-xhdpi/icon_events.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/icon_fans.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhang779/Preloader/4cd3881eedefa291feb90be3d4500fa390b9619a/sample/src/main/res/mipmap-xhdpi/icon_fans.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/icon_head.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhang779/Preloader/4cd3881eedefa291feb90be3d4500fa390b9619a/sample/src/main/res/mipmap-xhdpi/icon_head.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/icon_layout_pic.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhang779/Preloader/4cd3881eedefa291feb90be3d4500fa390b9619a/sample/src/main/res/mipmap-xhdpi/icon_layout_pic.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/icon_location.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhang779/Preloader/4cd3881eedefa291feb90be3d4500fa390b9619a/sample/src/main/res/mipmap-xhdpi/icon_location.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/icon_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhang779/Preloader/4cd3881eedefa291feb90be3d4500fa390b9619a/sample/src/main/res/mipmap-xhdpi/icon_logo.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/icon_retry.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhang779/Preloader/4cd3881eedefa291feb90be3d4500fa390b9619a/sample/src/main/res/mipmap-xhdpi/icon_retry.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/icon_shopping_cart.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhang779/Preloader/4cd3881eedefa291feb90be3d4500fa390b9619a/sample/src/main/res/mipmap-xhdpi/icon_shopping_cart.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/photo_1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhang779/Preloader/4cd3881eedefa291feb90be3d4500fa390b9619a/sample/src/main/res/mipmap-xhdpi/photo_1.jpg
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/photo_2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhang779/Preloader/4cd3881eedefa291feb90be3d4500fa390b9619a/sample/src/main/res/mipmap-xhdpi/photo_2.jpg
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/photo_3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhang779/Preloader/4cd3881eedefa291feb90be3d4500fa390b9619a/sample/src/main/res/mipmap-xhdpi/photo_3.jpg
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/photo_4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhang779/Preloader/4cd3881eedefa291feb90be3d4500fa390b9619a/sample/src/main/res/mipmap-xhdpi/photo_4.jpg
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/photo_5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhang779/Preloader/4cd3881eedefa291feb90be3d4500fa390b9619a/sample/src/main/res/mipmap-xhdpi/photo_5.jpg
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhang779/Preloader/4cd3881eedefa291feb90be3d4500fa390b9619a/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhang779/Preloader/4cd3881eedefa291feb90be3d4500fa390b9619a/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #333333
4 | #666666
5 | #D81B60
6 |
7 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Broccoli
3 |
4 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/sample/src/test/java/me/samlss/broccoli_demo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package me.samlss.broccoli_demo;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/screenshots/Broccoli.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhang779/Preloader/4cd3881eedefa291feb90be3d4500fa390b9619a/screenshots/Broccoli.png
--------------------------------------------------------------------------------
/screenshots/screenshot1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhang779/Preloader/4cd3881eedefa291feb90be3d4500fa390b9619a/screenshots/screenshot1.gif
--------------------------------------------------------------------------------
/screenshots/screenshot2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhang779/Preloader/4cd3881eedefa291feb90be3d4500fa390b9619a/screenshots/screenshot2.gif
--------------------------------------------------------------------------------
/screenshots/screenshot3.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhang779/Preloader/4cd3881eedefa291feb90be3d4500fa390b9619a/screenshots/screenshot3.gif
--------------------------------------------------------------------------------
/screenshots/screenshot4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhang779/Preloader/4cd3881eedefa291feb90be3d4500fa390b9619a/screenshots/screenshot4.png
--------------------------------------------------------------------------------
/screenshots/screenshot5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhang779/Preloader/4cd3881eedefa291feb90be3d4500fa390b9619a/screenshots/screenshot5.png
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':sample', ':broccoli'
2 |
--------------------------------------------------------------------------------