├── .gitignore
├── CHANGELOG.md
├── LICENSE
├── README.md
├── art
└── demo.gif
├── build.gradle
├── demo
├── .gitignore
├── build.gradle
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── balysv
│ │ └── materialripple
│ │ └── demo
│ │ ├── DemoActivity.java
│ │ ├── DemoListActivity.java
│ │ └── DemoRecyclerActivity.java
│ └── res
│ ├── drawable-hdpi
│ └── ic_launcher.png
│ ├── drawable-mdpi
│ └── ic_launcher.png
│ ├── drawable-xhdpi
│ └── ic_launcher.png
│ ├── drawable-xxhdpi
│ └── ic_launcher.png
│ ├── drawable
│ └── selector.xml
│ ├── layout
│ ├── demo.xml
│ ├── demo_list.xml
│ ├── demo_list_item.xml
│ ├── demo_recycler.xml
│ └── demo_recycler_item.xml
│ ├── menu
│ ├── menu_button.xml
│ ├── menu_list.xml
│ └── menu_recycler.xml
│ └── values
│ ├── dimens.xml
│ ├── drawables.xml
│ ├── strings.xml
│ └── styles.xml
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── library
├── .gitignore
├── build.gradle
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── balysv
│ │ └── materialripple
│ │ └── MaterialRippleLayout.java
│ └── res
│ └── values
│ ├── attributes.xml
│ └── colors.xml
├── maven_push.gradle
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /local.properties
3 | .DS_Store
4 | .idea
5 | *.iml
6 | /build
7 |
8 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | Change Log
2 | ==========
3 |
4 | Version 1.0.2 (2015-04-30)
5 | ----------------------------
6 |
7 | - Fix `OnLongClickListener` will not trigger `OnClickListener` if event is consumed
8 |
9 | Version 1.0.1 (2015-02-16)
10 | ----------------------------
11 |
12 | - Prefix all `MaterialRippleLayout` attributes with `mrl_` to remove possible ambiguity when using with other libraries.
13 |
14 |
15 | Version 1.0.0 (2015-02-01)
16 | ----------------------------
17 |
18 | Initial release.
--------------------------------------------------------------------------------
/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 2014 Lemon Labs
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 |
203 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ⚠️ The project is deprecated ⚠️
2 |
3 | Any issues or pull requests will not be addressed. Please consider forking your own version if changes are needed.
4 |
5 | Material Ripple Layout
6 | ===============
7 |
8 | Ripple effect wrapper for Android Views
9 |
10 | ![Demo Image][1]
11 |
12 | Including in your project
13 | -------------------------
14 |
15 | ```groovy
16 | compile 'com.balysv:material-ripple:1.0.2'
17 | ```
18 |
19 | Check for latest version number on the widget below or visit [Releases](https://github.com/balysv/material-ripple/releases)
20 |
21 | [](http://mvnrepository.com/artifact/com.balysv/material-ripple)
22 |
23 | Usage
24 | -----
25 |
26 | Use static initializer on your `View` (see `xml` attributes below for customization)
27 |
28 | ```java
29 | MaterialRippleLayout.on(view)
30 | .rippleColor(Color.BLACK)
31 | .create();
32 | ```
33 |
34 | Or wrap your `View` with `MaterialRippleLayout` in your layout file:
35 |
36 | ```xml
37 |
41 |
42 |
47 |
48 |
49 | ```
50 |
51 | If using in an `AdapterView` you must set `rippleInAdapter` to `true`
52 |
53 |
54 | Configure using xml attributes or setters in code:
55 |
56 | ```java
57 | app:mrl_rippleOverlay="true" // if true, ripple is drawn in foreground; false - background
58 | app:mrl_rippleColor="#ff0000" // color of ripple
59 | app:mrl_rippleAlpha="0.1" // alpha of ripple
60 | app:mrl_rippleDimension="10dp" // radius of hover and starting ripple
61 | app:mrl_rippleHover="true" // if true, a hover effect is drawn when view is touched
62 | app:mrl_rippleRoundedCorners="10dp" // radius of corners of ripples. Note: it uses software rendering pipeline for API 17 and below
63 | app:mrl_rippleInAdapter="true" // if true, MaterialRippleLayout will optimize for use in AdapterViews
64 | app:mrl_rippleDuration="350" // duration of ripple animation
65 | app:mrl_rippleFadeDuration="75" // duration of fade out effect on ripple
66 | app:mrl_rippleDelayClick="true" // if true, delays calls to OnClickListeners until ripple effect ends
67 | app:mrl_rippleBackground="#FFFFFF" // background under ripple drawable; used with rippleOverlay="false"
68 | app:mrl_ripplePersistent="true" // if true, ripple background color persists after animation, until setRadius(0) is called
69 | ```
70 |
71 | Set an `OnClickListener` to `MaterialRippleLayout`:
72 |
73 | ```java
74 | findViewById(R.id.ripple).setOnClickListener(new View.OnClickListener() {
75 | @Override public void onClick(View v) {
76 | // handle me
77 | }
78 | });
79 | ```
80 |
81 | Or if using in an `AdapterView`, simply use `OnItemClickListener`
82 |
83 | Support for Android api versions < 14
84 | -----
85 |
86 | For those unlucky developers that need to support older versions than 14, there's a way to do it.
87 |
88 | You can use this library in addition with Jake Wharton's animation backport (http://nineoldandroids.com/) changing the imports from ` import android.animation.*;` to: ` import com.nineoldandroids.animation.*;` ,
89 | `import android.util.Property`; to `import com.nineoldandroids.util.Property;` and in MaterialRippleLayout.java file, calling function `shouldDelayChildPressedState()` only if you're using api greater than 14.
90 |
91 |
92 | Developed By
93 | --------------------
94 | Balys Valentukevicius
95 |
96 | License
97 | -----------
98 |
99 | ```
100 | Copyright 2015 Balys Valentukevicius
101 |
102 | Licensed under the Apache License, Version 2.0 (the "License");
103 | you may not use this file except in compliance with the License.
104 | You may obtain a copy of the License at
105 |
106 | http://www.apache.org/licenses/LICENSE-2.0
107 |
108 | Unless required by applicable law or agreed to in writing, software
109 | distributed under the License is distributed on an "AS IS" BASIS,
110 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
111 | See the License for the specific language governing permissions and
112 | limitations under the License.
113 | ```
114 |
115 | [1]: https://raw.github.com/balysv/material-ripple/master/art/demo.gif
116 |
--------------------------------------------------------------------------------
/art/demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/balysv/material-ripple/67d4bc80bc27d50298c71ee83907eab96dfb8fea/art/demo.gif
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.1.3'
9 | }
10 | }
11 |
12 | allprojects {
13 | repositories {
14 | jcenter()
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/demo/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 | *.iml
3 |
--------------------------------------------------------------------------------
/demo/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 24
5 | buildToolsVersion "24.0.2"
6 |
7 | defaultConfig {
8 | applicationId "com.balysv.materialripple.demo"
9 | minSdkVersion 14
10 | targetSdkVersion 24
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 |
15 | compileOptions {
16 | sourceCompatibility JavaVersion.VERSION_1_7
17 | targetCompatibility JavaVersion.VERSION_1_7
18 | }
19 | }
20 |
21 | dependencies {
22 | compile project(':library')
23 |
24 | compile 'com.android.support:support-v4:24.2.1'
25 | compile "com.android.support:design:24.2.1"
26 | }
27 |
--------------------------------------------------------------------------------
/demo/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
10 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
22 |
23 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/demo/src/main/java/com/balysv/materialripple/demo/DemoActivity.java:
--------------------------------------------------------------------------------
1 | package com.balysv.materialripple.demo;
2 |
3 | import android.content.Intent;
4 | import android.graphics.Color;
5 | import android.os.Bundle;
6 | import android.support.v7.app.ActionBarActivity;
7 | import android.view.Menu;
8 | import android.view.MenuItem;
9 | import android.view.View;
10 | import android.widget.Toast;
11 |
12 | import com.balysv.materialripple.MaterialRippleLayout;
13 |
14 |
15 | public class DemoActivity extends ActionBarActivity implements View.OnClickListener, View.OnLongClickListener {
16 |
17 | @Override
18 | protected void onCreate(Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.demo);
21 |
22 | // xml initialization
23 | findViewById(R.id.ripple_layout_1).setOnClickListener(this);
24 | findViewById(R.id.ripple_layout_1).setOnLongClickListener(this);
25 |
26 | // static initialization
27 | View view = findViewById(R.id.ripple_layout_2);
28 | MaterialRippleLayout.on(view)
29 | .rippleColor(Color.parseColor("#FF0000"))
30 | .rippleAlpha(0.2f)
31 | .rippleHover(true)
32 | .create();
33 |
34 | view.setOnLongClickListener(this);
35 | view.setOnClickListener(this);
36 | }
37 |
38 | @Override public void onClick(View v) {
39 | Toast.makeText(this, "Short click", Toast.LENGTH_SHORT).show();
40 | }
41 |
42 | @Override public boolean onLongClick(View v) {
43 | if (v.getId() == R.id.ripple_layout_1) {
44 | Toast.makeText(this, "Long click not consumed", Toast.LENGTH_SHORT).show();
45 | return false;
46 | }
47 | Toast.makeText(this, "Long click and consumed", Toast.LENGTH_SHORT).show();
48 | return true;
49 | }
50 |
51 | @Override
52 | public boolean onCreateOptionsMenu(Menu menu) {
53 | getMenuInflater().inflate(R.menu.menu_button, menu);
54 | return true;
55 | }
56 |
57 | @Override
58 | public boolean onOptionsItemSelected(MenuItem item) {
59 | int id = item.getItemId();
60 | if (id == R.id.switch_list) {
61 | startActivity(new Intent(this, DemoListActivity.class));
62 | finish();
63 | return true;
64 | } else if (id == R.id.switch_recycler) {
65 | startActivity(new Intent(this, DemoRecyclerActivity.class));
66 | finish();
67 | return true;
68 | }
69 | return super.onOptionsItemSelected(item);
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/demo/src/main/java/com/balysv/materialripple/demo/DemoListActivity.java:
--------------------------------------------------------------------------------
1 | package com.balysv.materialripple.demo;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.ActionBarActivity;
6 | import android.view.Menu;
7 | import android.view.MenuItem;
8 | import android.view.View;
9 | import android.widget.AdapterView;
10 | import android.widget.ArrayAdapter;
11 | import android.widget.ListView;
12 | import android.widget.Toast;
13 |
14 | import java.util.UUID;
15 |
16 | public class DemoListActivity extends ActionBarActivity implements AdapterView.OnItemClickListener {
17 |
18 | private final static String[] data;
19 |
20 | static {
21 | data = new String[50];
22 | for (int i = 0; i < data.length; i++) {
23 | data[i] = UUID.randomUUID().toString();
24 | }
25 | }
26 |
27 | @Override
28 | protected void onCreate(Bundle savedInstanceState) {
29 | super.onCreate(savedInstanceState);
30 | setContentView(R.layout.demo_list);
31 | ListView listView = (ListView) findViewById(R.id.list);
32 | listView.setAdapter(new ArrayAdapter<>(this, R.layout.demo_list_item, android.R.id.text1, data));
33 | listView.setOnItemClickListener(this);
34 | listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
35 | @Override public boolean onItemLongClick(AdapterView> parent, View view, int position, long id) {
36 | if(position%2==0){
37 | Toast.makeText(DemoListActivity.this, "long item: " + position +" and not consumed", Toast.LENGTH_SHORT).show();
38 | return false;
39 | }
40 | Toast.makeText(DemoListActivity.this, "long item: " + position +" and consumed", Toast.LENGTH_SHORT).show();
41 | return true;
42 | }
43 | });
44 | }
45 |
46 | @Override public void onItemClick(AdapterView> parent, View view, int position, long id) {
47 | Toast.makeText(this, "Rippled item: " + position, Toast.LENGTH_SHORT).show();
48 | }
49 |
50 | @Override
51 | public boolean onCreateOptionsMenu(Menu menu) {
52 | getMenuInflater().inflate(R.menu.menu_list, menu);
53 | return true;
54 | }
55 |
56 | @Override
57 | public boolean onOptionsItemSelected(MenuItem item) {
58 | int id = item.getItemId();
59 | if (id == R.id.switch_button) {
60 | startActivity(new Intent(this, DemoActivity.class));
61 | finish();
62 | return true;
63 | } else if (id == R.id.switch_recycler) {
64 | startActivity(new Intent(this, DemoRecyclerActivity.class));
65 | finish();
66 | return true;
67 | }
68 | return super.onOptionsItemSelected(item);
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/demo/src/main/java/com/balysv/materialripple/demo/DemoRecyclerActivity.java:
--------------------------------------------------------------------------------
1 | package com.balysv.materialripple.demo;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.ActionBarActivity;
6 | import android.support.v7.widget.LinearLayoutManager;
7 | import android.support.v7.widget.RecyclerView;
8 | import android.view.LayoutInflater;
9 | import android.view.Menu;
10 | import android.view.MenuItem;
11 | import android.view.View;
12 | import android.view.ViewGroup;
13 | import android.widget.TextView;
14 | import android.widget.Toast;
15 |
16 | import com.balysv.materialripple.MaterialRippleLayout;
17 |
18 | import java.util.UUID;
19 |
20 | public class DemoRecyclerActivity extends ActionBarActivity {
21 |
22 | private final static String[] data;
23 |
24 | static {
25 | data = new String[50];
26 | for (int i = 0; i < data.length; i++) {
27 | data[i] = UUID.randomUUID().toString();
28 | }
29 | }
30 |
31 | @Override
32 | protected void onCreate(Bundle savedInstanceState) {
33 | super.onCreate(savedInstanceState);
34 | setContentView(R.layout.demo_recycler);
35 | RecyclerView recyclerView = (RecyclerView) findViewById(R.id.list);
36 | recyclerView.setLayoutManager(new LinearLayoutManager(this));
37 | recyclerView.setAdapter(new MyAdapter());
38 | }
39 |
40 | @Override
41 | public boolean onCreateOptionsMenu(Menu menu) {
42 | getMenuInflater().inflate(R.menu.menu_recycler, menu);
43 | return true;
44 | }
45 |
46 | @Override
47 | public boolean onOptionsItemSelected(MenuItem item) {
48 | int id = item.getItemId();
49 | if (id == R.id.switch_button) {
50 | startActivity(new Intent(this, DemoActivity.class));
51 | finish();
52 | return true;
53 | } else if (id == R.id.switch_list) {
54 | startActivity(new Intent(this, DemoListActivity.class));
55 | finish();
56 | return true;
57 | }
58 | return super.onOptionsItemSelected(item);
59 | }
60 |
61 | private static class MyAdapter extends RecyclerView.Adapter {
62 |
63 | @Override
64 | public MyViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
65 | final LayoutInflater inflater = LayoutInflater.from(viewGroup.getContext());
66 | return new MyViewHolder(
67 | MaterialRippleLayout.on(inflater.inflate(R.layout.demo_recycler_item, viewGroup, false))
68 | .rippleOverlay(true)
69 | .rippleAlpha(0.2f)
70 | .rippleColor(0xFF585858)
71 | .rippleHover(true)
72 | .create()
73 | );
74 | }
75 |
76 | @Override
77 | public void onBindViewHolder(MyViewHolder viewHolder, int i) {
78 | viewHolder.text.setText(data[i]);
79 | }
80 |
81 | @Override
82 | public int getItemCount() {
83 | return data.length;
84 | }
85 | }
86 |
87 | private static class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener,
88 | View.OnLongClickListener {
89 |
90 | TextView text;
91 |
92 | public MyViewHolder(View itemView) {
93 | super(itemView);
94 | text = (TextView) itemView.findViewById(android.R.id.text1);
95 | itemView.setOnClickListener(this);
96 | itemView.setOnLongClickListener(this);
97 | }
98 |
99 | @Override
100 | public void onClick(View v) {
101 | Toast.makeText(v.getContext(), "Rippled item: " + getAdapterPosition(), Toast.LENGTH_SHORT).show();
102 | }
103 |
104 | @Override
105 | public boolean onLongClick(View v) {
106 | if (getAdapterPosition() % 2 == 0) {
107 | Toast.makeText(v.getContext(), "long item: " + getAdapterPosition() + " and not consumed",
108 | Toast.LENGTH_SHORT)
109 | .show();
110 | return false;
111 | }
112 | Toast.makeText(v.getContext(), "long item: " + getAdapterPosition() + " and consumed", Toast.LENGTH_SHORT)
113 | .show();
114 | return true;
115 | }
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/demo/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/balysv/material-ripple/67d4bc80bc27d50298c71ee83907eab96dfb8fea/demo/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/demo/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/balysv/material-ripple/67d4bc80bc27d50298c71ee83907eab96dfb8fea/demo/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/demo/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/balysv/material-ripple/67d4bc80bc27d50298c71ee83907eab96dfb8fea/demo/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/demo/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/balysv/material-ripple/67d4bc80bc27d50298c71ee83907eab96dfb8fea/demo/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/demo/src/main/res/drawable/selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/demo/src/main/res/layout/demo.xml:
--------------------------------------------------------------------------------
1 |
15 |
16 |
26 |
27 |
34 |
35 |
36 |
37 |
38 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/demo/src/main/res/layout/demo_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/demo/src/main/res/layout/demo_list_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
11 |
12 |
23 |
24 |
--------------------------------------------------------------------------------
/demo/src/main/res/layout/demo_recycler.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/demo/src/main/res/layout/demo_recycler_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/demo/src/main/res/menu/menu_button.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/demo/src/main/res/menu/menu_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/demo/src/main/res/menu/menu_recycler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/demo/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 | 16dp
3 | 16dp
4 |
5 |
--------------------------------------------------------------------------------
/demo/src/main/res/values/drawables.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #00FFFFFF
4 | #10000000
5 |
--------------------------------------------------------------------------------
/demo/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Material Ripple Demo
4 | ListView
5 | Buttons
6 | RecyclerView
7 |
8 |
--------------------------------------------------------------------------------
/demo/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | VERSION_NAME=1.0.2
2 | VERSION_CODE=1
3 | GROUP=com.balysv
4 |
5 | POM_NAME=Material Ripple Layout
6 | POM_ARTIFACT_ID=material-ripple
7 | POM_PACKAGING=aar
8 | POM_DESCRIPTION=Ripple effect wrapper for Android views
9 | POM_URL=https://github.com/balysv/material-ripple
10 | POM_SCM_URL=https://github.com/balysv/material-ripple
11 | POM_SCM_CONNECTION=scm:git@github.com:balysv/material-ripple.git
12 | POM_SCM_DEV_CONNECTION=scm:git@github.com:balysv/material-ripple.git
13 | POM_LICENCE_NAME=The Apache Software License, Version 2.0
14 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
15 | POM_LICENCE_DIST=repo
16 | POM_DEVELOPER_ID=balysv
17 | POM_DEVELOPER_NAME=Balys Valentukevicius
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/balysv/material-ripple/67d4bc80bc27d50298c71ee83907eab96dfb8fea/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Sep 17 13:10:06 BST 2016
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
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 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 | *.iml
3 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 24
5 | buildToolsVersion "24.0.2"
6 |
7 | defaultConfig {
8 | minSdkVersion 14
9 | targetSdkVersion 24
10 | }
11 |
12 | compileOptions {
13 | sourceCompatibility JavaVersion.VERSION_1_7
14 | targetCompatibility JavaVersion.VERSION_1_7
15 | }
16 | }
17 |
18 | apply from: '../maven_push.gradle'
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/library/src/main/java/com/balysv/materialripple/MaterialRippleLayout.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Balys Valentukevicius
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.balysv.materialripple;
18 |
19 | import android.animation.Animator;
20 | import android.animation.AnimatorListenerAdapter;
21 | import android.animation.AnimatorSet;
22 | import android.animation.ObjectAnimator;
23 | import android.content.Context;
24 | import android.content.res.Resources;
25 | import android.content.res.TypedArray;
26 | import android.graphics.Canvas;
27 | import android.graphics.Color;
28 | import android.graphics.Paint;
29 | import android.graphics.Path;
30 | import android.graphics.Point;
31 | import android.graphics.Rect;
32 | import android.graphics.RectF;
33 | import android.graphics.drawable.ColorDrawable;
34 | import android.graphics.drawable.Drawable;
35 | import android.os.Build;
36 | import android.util.AttributeSet;
37 | import android.util.Property;
38 | import android.util.TypedValue;
39 | import android.view.GestureDetector;
40 | import android.view.MotionEvent;
41 | import android.view.View;
42 | import android.view.ViewConfiguration;
43 | import android.view.ViewGroup;
44 | import android.view.ViewParent;
45 | import android.view.animation.AccelerateInterpolator;
46 | import android.view.animation.DecelerateInterpolator;
47 | import android.view.animation.LinearInterpolator;
48 | import android.widget.AdapterView;
49 | import android.widget.FrameLayout;
50 |
51 | import static android.view.GestureDetector.SimpleOnGestureListener;
52 | import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
53 |
54 | public class MaterialRippleLayout extends FrameLayout {
55 |
56 | private static final int DEFAULT_DURATION = 350;
57 | private static final int DEFAULT_FADE_DURATION = 75;
58 | private static final float DEFAULT_DIAMETER_DP = 35;
59 | private static final float DEFAULT_ALPHA = 0.2f;
60 | private static final int DEFAULT_COLOR = Color.BLACK;
61 | private static final int DEFAULT_BACKGROUND = Color.TRANSPARENT;
62 | private static final boolean DEFAULT_HOVER = true;
63 | private static final boolean DEFAULT_DELAY_CLICK = true;
64 | private static final boolean DEFAULT_PERSISTENT = false;
65 | private static final boolean DEFAULT_SEARCH_ADAPTER = false;
66 | private static final boolean DEFAULT_RIPPLE_OVERLAY = false;
67 | private static final int DEFAULT_ROUNDED_CORNERS = 0;
68 |
69 | private static final int FADE_EXTRA_DELAY = 50;
70 | private static final long HOVER_DURATION = 2500;
71 |
72 | private final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
73 | private final Rect bounds = new Rect();
74 |
75 | private int rippleColor;
76 | private boolean rippleOverlay;
77 | private boolean rippleHover;
78 | private int rippleDiameter;
79 | private int rippleDuration;
80 | private int rippleAlpha;
81 | private boolean rippleDelayClick;
82 | private int rippleFadeDuration;
83 | private boolean ripplePersistent;
84 | private Drawable rippleBackground;
85 | private boolean rippleInAdapter;
86 | private float rippleRoundedCorners;
87 |
88 | private float radius;
89 |
90 | private AdapterView parentAdapter;
91 | private View childView;
92 |
93 | private AnimatorSet rippleAnimator;
94 | private ObjectAnimator hoverAnimator;
95 |
96 | private Point currentCoords = new Point();
97 | private Point previousCoords = new Point();
98 |
99 | private int layerType;
100 |
101 | private boolean eventCancelled;
102 | private boolean prepressed;
103 | private int positionInAdapter;
104 |
105 | private GestureDetector gestureDetector;
106 | private PerformClickEvent pendingClickEvent;
107 | private PressedEvent pendingPressEvent;
108 |
109 | public static RippleBuilder on(View view) {
110 | return new RippleBuilder(view);
111 | }
112 |
113 | public MaterialRippleLayout(Context context) {
114 | this(context, null, 0);
115 | }
116 |
117 | public MaterialRippleLayout(Context context, AttributeSet attrs) {
118 | this(context, attrs, 0);
119 | }
120 |
121 | public MaterialRippleLayout(Context context, AttributeSet attrs, int defStyle) {
122 | super(context, attrs, defStyle);
123 |
124 | setWillNotDraw(false);
125 | gestureDetector = new GestureDetector(context, longClickListener);
126 |
127 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MaterialRippleLayout);
128 | rippleColor = a.getColor(R.styleable.MaterialRippleLayout_mrl_rippleColor, DEFAULT_COLOR);
129 | rippleDiameter = a.getDimensionPixelSize(
130 | R.styleable.MaterialRippleLayout_mrl_rippleDimension,
131 | (int) dpToPx(getResources(), DEFAULT_DIAMETER_DP)
132 | );
133 | rippleOverlay = a.getBoolean(R.styleable.MaterialRippleLayout_mrl_rippleOverlay, DEFAULT_RIPPLE_OVERLAY);
134 | rippleHover = a.getBoolean(R.styleable.MaterialRippleLayout_mrl_rippleHover, DEFAULT_HOVER);
135 | rippleDuration = a.getInt(R.styleable.MaterialRippleLayout_mrl_rippleDuration, DEFAULT_DURATION);
136 | rippleAlpha = (int) (255 * a.getFloat(R.styleable.MaterialRippleLayout_mrl_rippleAlpha, DEFAULT_ALPHA));
137 | rippleDelayClick = a.getBoolean(R.styleable.MaterialRippleLayout_mrl_rippleDelayClick, DEFAULT_DELAY_CLICK);
138 | rippleFadeDuration = a.getInteger(R.styleable.MaterialRippleLayout_mrl_rippleFadeDuration, DEFAULT_FADE_DURATION);
139 | rippleBackground = new ColorDrawable(a.getColor(R.styleable.MaterialRippleLayout_mrl_rippleBackground, DEFAULT_BACKGROUND));
140 | ripplePersistent = a.getBoolean(R.styleable.MaterialRippleLayout_mrl_ripplePersistent, DEFAULT_PERSISTENT);
141 | rippleInAdapter = a.getBoolean(R.styleable.MaterialRippleLayout_mrl_rippleInAdapter, DEFAULT_SEARCH_ADAPTER);
142 | rippleRoundedCorners = a.getDimensionPixelSize(R.styleable.MaterialRippleLayout_mrl_rippleRoundedCorners, DEFAULT_ROUNDED_CORNERS);
143 |
144 | a.recycle();
145 |
146 | paint.setColor(rippleColor);
147 | paint.setAlpha(rippleAlpha);
148 |
149 | enableClipPathSupportIfNecessary();
150 | }
151 |
152 |
153 | @SuppressWarnings("unchecked")
154 | public T getChildView() {
155 | return (T) childView;
156 | }
157 |
158 | @Override
159 | public final void addView(View child, int index, ViewGroup.LayoutParams params) {
160 | if (getChildCount() > 0) {
161 | throw new IllegalStateException("MaterialRippleLayout can host only one child");
162 | }
163 | //noinspection unchecked
164 | childView = child;
165 | super.addView(child, index, params);
166 | }
167 |
168 | @Override
169 | public void setOnClickListener(OnClickListener onClickListener) {
170 | if (childView == null) {
171 | throw new IllegalStateException("MaterialRippleLayout must have a child view to handle clicks");
172 | }
173 | childView.setOnClickListener(onClickListener);
174 | }
175 |
176 | @Override
177 | public void setOnLongClickListener(OnLongClickListener onClickListener) {
178 | if (childView == null) {
179 | throw new IllegalStateException("MaterialRippleLayout must have a child view to handle clicks");
180 | }
181 | childView.setOnLongClickListener(onClickListener);
182 | }
183 |
184 | @Override
185 | public boolean onInterceptTouchEvent(MotionEvent event) {
186 | return !findClickableViewInChild(childView, (int) event.getX(), (int) event.getY());
187 | }
188 |
189 | @Override
190 | public boolean onTouchEvent(MotionEvent event) {
191 | boolean superOnTouchEvent = super.onTouchEvent(event);
192 |
193 | if (!isEnabled() || !childView.isEnabled()) return superOnTouchEvent;
194 |
195 | boolean isEventInBounds = bounds.contains((int) event.getX(), (int) event.getY());
196 |
197 | if (isEventInBounds) {
198 | previousCoords.set(currentCoords.x, currentCoords.y);
199 | currentCoords.set((int) event.getX(), (int) event.getY());
200 | }
201 |
202 | boolean gestureResult = gestureDetector.onTouchEvent(event);
203 | if (gestureResult || hasPerformedLongPress) {
204 | return true;
205 | } else {
206 | int action = event.getActionMasked();
207 | switch (action) {
208 | case MotionEvent.ACTION_UP:
209 | pendingClickEvent = new PerformClickEvent();
210 |
211 | if (prepressed) {
212 | childView.setPressed(true);
213 | postDelayed(
214 | new Runnable() {
215 | @Override public void run() {
216 | childView.setPressed(false);
217 | }
218 | }, ViewConfiguration.getPressedStateDuration());
219 | }
220 |
221 | if (isEventInBounds) {
222 | startRipple(pendingClickEvent);
223 | } else if (!rippleHover) {
224 | setRadius(0);
225 | }
226 | if (!rippleDelayClick && isEventInBounds) {
227 | pendingClickEvent.run();
228 | }
229 | cancelPressedEvent();
230 | break;
231 | case MotionEvent.ACTION_DOWN:
232 | setPositionInAdapter();
233 | eventCancelled = false;
234 | pendingPressEvent = new PressedEvent(event);
235 | if (isInScrollingContainer()) {
236 | cancelPressedEvent();
237 | prepressed = true;
238 | postDelayed(pendingPressEvent, ViewConfiguration.getTapTimeout());
239 | } else {
240 | pendingPressEvent.run();
241 | }
242 | break;
243 | case MotionEvent.ACTION_CANCEL:
244 | if (rippleInAdapter) {
245 | // dont use current coords in adapter since they tend to jump drastically on scroll
246 | currentCoords.set(previousCoords.x, previousCoords.y);
247 | previousCoords = new Point();
248 | }
249 | childView.onTouchEvent(event);
250 | if (rippleHover) {
251 | if (!prepressed) {
252 | startRipple(null);
253 | }
254 | } else {
255 | childView.setPressed(false);
256 | }
257 | cancelPressedEvent();
258 | break;
259 | case MotionEvent.ACTION_MOVE:
260 | if (rippleHover) {
261 | if (isEventInBounds && !eventCancelled) {
262 | invalidate();
263 | } else if (!isEventInBounds) {
264 | startRipple(null);
265 | }
266 | }
267 |
268 | if (!isEventInBounds) {
269 | cancelPressedEvent();
270 | if (hoverAnimator != null) {
271 | hoverAnimator.cancel();
272 | }
273 | childView.onTouchEvent(event);
274 | eventCancelled = true;
275 | }
276 | break;
277 | }
278 | return true;
279 | }
280 | }
281 |
282 | private void cancelPressedEvent() {
283 | if (pendingPressEvent != null) {
284 | removeCallbacks(pendingPressEvent);
285 | prepressed = false;
286 | }
287 | }
288 |
289 | private boolean hasPerformedLongPress;
290 | private SimpleOnGestureListener longClickListener = new GestureDetector.SimpleOnGestureListener() {
291 | public void onLongPress(MotionEvent e) {
292 | hasPerformedLongPress = childView.performLongClick();
293 | if (hasPerformedLongPress) {
294 | if (rippleHover) {
295 | startRipple(null);
296 | }
297 | cancelPressedEvent();
298 | }
299 | }
300 |
301 | @Override
302 | public boolean onDown(MotionEvent e) {
303 | hasPerformedLongPress = false;
304 | return super.onDown(e);
305 | }
306 | };
307 |
308 | private void startHover() {
309 | if (eventCancelled) return;
310 |
311 | if (hoverAnimator != null) {
312 | hoverAnimator.cancel();
313 | }
314 | final float radius = (float) (Math.sqrt(Math.pow(getWidth(), 2) + Math.pow(getHeight(), 2)) * 1.2f);
315 | hoverAnimator = ObjectAnimator.ofFloat(this, radiusProperty, rippleDiameter, radius)
316 | .setDuration(HOVER_DURATION);
317 | hoverAnimator.setInterpolator(new LinearInterpolator());
318 | hoverAnimator.start();
319 | }
320 |
321 | private void startRipple(final Runnable animationEndRunnable) {
322 | if (eventCancelled) return;
323 |
324 | float endRadius = getEndRadius();
325 |
326 | cancelAnimations();
327 |
328 | rippleAnimator = new AnimatorSet();
329 | rippleAnimator.addListener(new AnimatorListenerAdapter() {
330 | @Override public void onAnimationEnd(Animator animation) {
331 | if (!ripplePersistent) {
332 | setRadius(0);
333 | setRippleAlpha(rippleAlpha);
334 | }
335 | if (animationEndRunnable != null && rippleDelayClick) {
336 | animationEndRunnable.run();
337 | }
338 | childView.setPressed(false);
339 | }
340 | });
341 |
342 | ObjectAnimator ripple = ObjectAnimator.ofFloat(this, radiusProperty, radius, endRadius);
343 | ripple.setDuration(rippleDuration);
344 | ripple.setInterpolator(new DecelerateInterpolator());
345 | ObjectAnimator fade = ObjectAnimator.ofInt(this, circleAlphaProperty, rippleAlpha, 0);
346 | fade.setDuration(rippleFadeDuration);
347 | fade.setInterpolator(new AccelerateInterpolator());
348 | fade.setStartDelay(rippleDuration - rippleFadeDuration - FADE_EXTRA_DELAY);
349 |
350 | if (ripplePersistent) {
351 | rippleAnimator.play(ripple);
352 | } else if (getRadius() > endRadius) {
353 | fade.setStartDelay(0);
354 | rippleAnimator.play(fade);
355 | } else {
356 | rippleAnimator.playTogether(ripple, fade);
357 | }
358 | rippleAnimator.start();
359 | }
360 |
361 | private void cancelAnimations() {
362 | if (rippleAnimator != null) {
363 | rippleAnimator.cancel();
364 | rippleAnimator.removeAllListeners();
365 | }
366 |
367 | if (hoverAnimator != null) {
368 | hoverAnimator.cancel();
369 | }
370 | }
371 |
372 | private float getEndRadius() {
373 | final int width = getWidth();
374 | final int height = getHeight();
375 |
376 | final int halfWidth = width / 2;
377 | final int halfHeight = height / 2;
378 |
379 | final float radiusX = halfWidth > currentCoords.x ? width - currentCoords.x : currentCoords.x;
380 | final float radiusY = halfHeight > currentCoords.y ? height - currentCoords.y : currentCoords.y;
381 |
382 | return (float) Math.sqrt(Math.pow(radiusX, 2) + Math.pow(radiusY, 2)) * 1.2f;
383 | }
384 |
385 | private boolean isInScrollingContainer() {
386 | ViewParent p = getParent();
387 | while (p != null && p instanceof ViewGroup) {
388 | if (((ViewGroup) p).shouldDelayChildPressedState()) {
389 | return true;
390 | }
391 | p = p.getParent();
392 | }
393 | return false;
394 | }
395 |
396 | private AdapterView findParentAdapterView() {
397 | if (parentAdapter != null) {
398 | return parentAdapter;
399 | }
400 | ViewParent current = getParent();
401 | while (true) {
402 | if (current instanceof AdapterView) {
403 | parentAdapter = (AdapterView) current;
404 | return parentAdapter;
405 | } else {
406 | try {
407 | current = current.getParent();
408 | } catch (NullPointerException npe) {
409 | throw new RuntimeException("Could not find a parent AdapterView");
410 | }
411 | }
412 | }
413 | }
414 |
415 | private void setPositionInAdapter() {
416 | if (rippleInAdapter) {
417 | positionInAdapter = findParentAdapterView().getPositionForView(MaterialRippleLayout.this);
418 | }
419 | }
420 |
421 | private boolean adapterPositionChanged() {
422 | if (rippleInAdapter) {
423 | int newPosition = findParentAdapterView().getPositionForView(MaterialRippleLayout.this);
424 | final boolean changed = newPosition != positionInAdapter;
425 | positionInAdapter = newPosition;
426 | if (changed) {
427 | cancelPressedEvent();
428 | cancelAnimations();
429 | childView.setPressed(false);
430 | setRadius(0);
431 | }
432 | return changed;
433 | }
434 | return false;
435 | }
436 |
437 | private boolean findClickableViewInChild(View view, int x, int y) {
438 | if (view instanceof ViewGroup) {
439 | ViewGroup viewGroup = (ViewGroup) view;
440 | for (int i = 0; i < viewGroup.getChildCount(); i++) {
441 | View child = viewGroup.getChildAt(i);
442 | final Rect rect = new Rect();
443 | child.getHitRect(rect);
444 |
445 | final boolean contains = rect.contains(x, y);
446 | if (contains) {
447 | return findClickableViewInChild(child, x - rect.left, y - rect.top);
448 | }
449 | }
450 | } else if (view != childView) {
451 | return (view.isEnabled() && (view.isClickable() || view.isLongClickable() || view.isFocusableInTouchMode()));
452 | }
453 |
454 | return view.isFocusableInTouchMode();
455 | }
456 |
457 | @Override
458 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
459 | super.onSizeChanged(w, h, oldw, oldh);
460 | bounds.set(0, 0, w, h);
461 | rippleBackground.setBounds(bounds);
462 | }
463 |
464 | @Override
465 | public boolean isInEditMode() {
466 | return true;
467 | }
468 |
469 | /*
470 | * Drawing
471 | */
472 | @Override
473 | public void draw(Canvas canvas) {
474 | final boolean positionChanged = adapterPositionChanged();
475 | if (rippleOverlay) {
476 | if (!positionChanged) {
477 | rippleBackground.draw(canvas);
478 | }
479 | super.draw(canvas);
480 | if (!positionChanged) {
481 | if (rippleRoundedCorners != 0) {
482 | Path clipPath = new Path();
483 | RectF rect = new RectF(0, 0, canvas.getWidth(), canvas.getHeight());
484 | clipPath.addRoundRect(rect, rippleRoundedCorners, rippleRoundedCorners, Path.Direction.CW);
485 | canvas.clipPath(clipPath);
486 | }
487 | canvas.drawCircle(currentCoords.x, currentCoords.y, radius, paint);
488 | }
489 | } else {
490 | if (!positionChanged) {
491 | rippleBackground.draw(canvas);
492 | canvas.drawCircle(currentCoords.x, currentCoords.y, radius, paint);
493 | }
494 | super.draw(canvas);
495 | }
496 | }
497 |
498 | /*
499 | * Animations
500 | */
501 | private Property radiusProperty
502 | = new Property(Float.class, "radius") {
503 | @Override
504 | public Float get(MaterialRippleLayout object) {
505 | return object.getRadius();
506 | }
507 |
508 | @Override
509 | public void set(MaterialRippleLayout object, Float value) {
510 | object.setRadius(value);
511 | }
512 | };
513 |
514 | private float getRadius() {
515 | return radius;
516 | }
517 |
518 |
519 | public void setRadius(float radius) {
520 | this.radius = radius;
521 | invalidate();
522 | }
523 |
524 | private Property circleAlphaProperty
525 | = new Property(Integer.class, "rippleAlpha") {
526 | @Override
527 | public Integer get(MaterialRippleLayout object) {
528 | return object.getRippleAlpha();
529 | }
530 |
531 | @Override
532 | public void set(MaterialRippleLayout object, Integer value) {
533 | object.setRippleAlpha(value);
534 | }
535 | };
536 |
537 | public int getRippleAlpha() {
538 | return paint.getAlpha();
539 | }
540 |
541 | public void setRippleAlpha(Integer rippleAlpha) {
542 | paint.setAlpha(rippleAlpha);
543 | invalidate();
544 | }
545 |
546 | /*
547 | * Accessor
548 | */
549 | public void setRippleColor(int rippleColor) {
550 | this.rippleColor = rippleColor;
551 | paint.setColor(rippleColor);
552 | paint.setAlpha(rippleAlpha);
553 | invalidate();
554 | }
555 |
556 | public void setRippleOverlay(boolean rippleOverlay) {
557 | this.rippleOverlay = rippleOverlay;
558 | }
559 |
560 | public void setRippleDiameter(int rippleDiameter) {
561 | this.rippleDiameter = rippleDiameter;
562 | }
563 |
564 | public void setRippleDuration(int rippleDuration) {
565 | this.rippleDuration = rippleDuration;
566 | }
567 |
568 | public void setRippleBackground(int color) {
569 | rippleBackground = new ColorDrawable(color);
570 | rippleBackground.setBounds(bounds);
571 | invalidate();
572 | }
573 |
574 | public void setRippleHover(boolean rippleHover) {
575 | this.rippleHover = rippleHover;
576 | }
577 |
578 | public void setRippleDelayClick(boolean rippleDelayClick) {
579 | this.rippleDelayClick = rippleDelayClick;
580 | }
581 |
582 | public void setRippleFadeDuration(int rippleFadeDuration) {
583 | this.rippleFadeDuration = rippleFadeDuration;
584 | }
585 |
586 | public void setRipplePersistent(boolean ripplePersistent) {
587 | this.ripplePersistent = ripplePersistent;
588 | }
589 |
590 | public void setRippleInAdapter(boolean rippleInAdapter) {
591 | this.rippleInAdapter = rippleInAdapter;
592 | }
593 |
594 | public void setRippleRoundedCorners(int rippleRoundedCorner) {
595 | this.rippleRoundedCorners = rippleRoundedCorner;
596 | enableClipPathSupportIfNecessary();
597 | }
598 |
599 | public void setDefaultRippleAlpha(float alpha) {
600 | this.rippleAlpha = (int) (255 * alpha);
601 | paint.setAlpha(rippleAlpha);
602 | invalidate();
603 | }
604 |
605 | public void performRipple() {
606 | currentCoords = new Point(getWidth() / 2, getHeight() / 2);
607 | startRipple(null);
608 | }
609 |
610 | public void performRipple(Point anchor) {
611 | currentCoords = new Point(anchor.x, anchor.y);
612 | startRipple(null);
613 | }
614 |
615 | /**
616 | * {@link Canvas#clipPath(Path)} is not supported in hardware accelerated layers
617 | * before API 18. Use software layer instead
618 | *
619 | * https://developer.android.com/guide/topics/graphics/hardware-accel.html#unsupported
620 | */
621 | private void enableClipPathSupportIfNecessary() {
622 | if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN_MR1) {
623 | if (rippleRoundedCorners != 0) {
624 | layerType = getLayerType();
625 | setLayerType(LAYER_TYPE_SOFTWARE, null);
626 | } else {
627 | setLayerType(layerType, null);
628 | }
629 | }
630 | }
631 |
632 | /*
633 | * Helper
634 | */
635 | private class PerformClickEvent implements Runnable {
636 |
637 | @Override public void run() {
638 | if (hasPerformedLongPress) return;
639 |
640 | // if parent is an AdapterView, try to call its ItemClickListener
641 | if (getParent() instanceof AdapterView) {
642 | // try clicking direct child first
643 | if (!childView.performClick())
644 | // if it did not handle it dispatch to adapterView
645 | clickAdapterView((AdapterView) getParent());
646 | } else if (rippleInAdapter) {
647 | // find adapter view
648 | clickAdapterView(findParentAdapterView());
649 | } else {
650 | // otherwise, just perform click on child
651 | childView.performClick();
652 | }
653 | }
654 |
655 | private void clickAdapterView(AdapterView parent) {
656 | final int position = parent.getPositionForView(MaterialRippleLayout.this);
657 | final long itemId = parent.getAdapter() != null
658 | ? parent.getAdapter().getItemId(position)
659 | : 0;
660 | if (position != AdapterView.INVALID_POSITION) {
661 | parent.performItemClick(MaterialRippleLayout.this, position, itemId);
662 | }
663 | }
664 | }
665 |
666 | private final class PressedEvent implements Runnable {
667 |
668 | private final MotionEvent event;
669 |
670 | public PressedEvent(MotionEvent event) {
671 | this.event = event;
672 | }
673 |
674 | @Override
675 | public void run() {
676 | prepressed = false;
677 | childView.setLongClickable(false);//prevent the child's long click,let's the ripple layout call it's performLongClick
678 | childView.onTouchEvent(event);
679 | childView.setPressed(true);
680 | if (rippleHover) {
681 | startHover();
682 | }
683 | }
684 | }
685 |
686 | static float dpToPx(Resources resources, float dp) {
687 | return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, resources.getDisplayMetrics());
688 | }
689 |
690 | /*
691 | * Builder
692 | */
693 |
694 | public static class RippleBuilder {
695 |
696 | private final Context context;
697 | private final View child;
698 |
699 | private int rippleColor = DEFAULT_COLOR;
700 | private boolean rippleOverlay = DEFAULT_RIPPLE_OVERLAY;
701 | private boolean rippleHover = DEFAULT_HOVER;
702 | private float rippleDiameter = DEFAULT_DIAMETER_DP;
703 | private int rippleDuration = DEFAULT_DURATION;
704 | private float rippleAlpha = DEFAULT_ALPHA;
705 | private boolean rippleDelayClick = DEFAULT_DELAY_CLICK;
706 | private int rippleFadeDuration = DEFAULT_FADE_DURATION;
707 | private boolean ripplePersistent = DEFAULT_PERSISTENT;
708 | private int rippleBackground = DEFAULT_BACKGROUND;
709 | private boolean rippleSearchAdapter = DEFAULT_SEARCH_ADAPTER;
710 | private float rippleRoundedCorner = DEFAULT_ROUNDED_CORNERS;
711 |
712 | public RippleBuilder(View child) {
713 | this.child = child;
714 | this.context = child.getContext();
715 | }
716 |
717 | public RippleBuilder rippleColor(int color) {
718 | this.rippleColor = color;
719 | return this;
720 | }
721 |
722 | public RippleBuilder rippleOverlay(boolean overlay) {
723 | this.rippleOverlay = overlay;
724 | return this;
725 | }
726 |
727 | public RippleBuilder rippleHover(boolean hover) {
728 | this.rippleHover = hover;
729 | return this;
730 | }
731 |
732 | public RippleBuilder rippleDiameterDp(int diameterDp) {
733 | this.rippleDiameter = diameterDp;
734 | return this;
735 | }
736 |
737 | public RippleBuilder rippleDuration(int duration) {
738 | this.rippleDuration = duration;
739 | return this;
740 | }
741 |
742 | public RippleBuilder rippleAlpha(float alpha) {
743 | this.rippleAlpha = alpha;
744 | return this;
745 | }
746 |
747 | public RippleBuilder rippleDelayClick(boolean delayClick) {
748 | this.rippleDelayClick = delayClick;
749 | return this;
750 | }
751 |
752 | public RippleBuilder rippleFadeDuration(int fadeDuration) {
753 | this.rippleFadeDuration = fadeDuration;
754 | return this;
755 | }
756 |
757 | public RippleBuilder ripplePersistent(boolean persistent) {
758 | this.ripplePersistent = persistent;
759 | return this;
760 | }
761 |
762 | public RippleBuilder rippleBackground(int color) {
763 | this.rippleBackground = color;
764 | return this;
765 | }
766 |
767 | public RippleBuilder rippleInAdapter(boolean inAdapter) {
768 | this.rippleSearchAdapter = inAdapter;
769 | return this;
770 | }
771 |
772 | public RippleBuilder rippleRoundedCorners(int radiusDp) {
773 | this.rippleRoundedCorner = radiusDp;
774 | return this;
775 | }
776 |
777 | public MaterialRippleLayout create() {
778 | MaterialRippleLayout layout = new MaterialRippleLayout(context);
779 | layout.setRippleColor(rippleColor);
780 | layout.setDefaultRippleAlpha(rippleAlpha);
781 | layout.setRippleDelayClick(rippleDelayClick);
782 | layout.setRippleDiameter((int) dpToPx(context.getResources(), rippleDiameter));
783 | layout.setRippleDuration(rippleDuration);
784 | layout.setRippleFadeDuration(rippleFadeDuration);
785 | layout.setRippleHover(rippleHover);
786 | layout.setRipplePersistent(ripplePersistent);
787 | layout.setRippleOverlay(rippleOverlay);
788 | layout.setRippleBackground(rippleBackground);
789 | layout.setRippleInAdapter(rippleSearchAdapter);
790 | layout.setRippleRoundedCorners((int) dpToPx(context.getResources(), rippleRoundedCorner));
791 |
792 | ViewGroup.LayoutParams params = child.getLayoutParams();
793 | ViewGroup parent = (ViewGroup) child.getParent();
794 | int index = 0;
795 |
796 | if (parent != null && parent instanceof MaterialRippleLayout) {
797 | throw new IllegalStateException("MaterialRippleLayout could not be created: parent of the view already is a MaterialRippleLayout");
798 | }
799 |
800 | if (parent != null) {
801 | index = parent.indexOfChild(child);
802 | parent.removeView(child);
803 | }
804 |
805 | layout.addView(child, new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT));
806 |
807 | if (parent != null) {
808 | parent.addView(layout, index, params);
809 | }
810 |
811 | return layout;
812 | }
813 | }
814 | }
815 |
--------------------------------------------------------------------------------
/library/src/main/res/values/attributes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/library/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #00FFFFFF
4 |
--------------------------------------------------------------------------------
/maven_push.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Chris Banes
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | apply plugin: 'maven'
18 | apply plugin: 'signing'
19 |
20 | def isReleaseBuild() {
21 | return version.contains("SNAPSHOT") == false
22 | }
23 |
24 | def getReleaseRepositoryUrl() {
25 | return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL
26 | : "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
27 | }
28 |
29 | def getSnapshotRepositoryUrl() {
30 | return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL
31 | : "https://oss.sonatype.org/content/repositories/snapshots/"
32 | }
33 |
34 | def getRepositoryUsername() {
35 | return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : ""
36 | }
37 |
38 | def getRepositoryPassword() {
39 | return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : ""
40 | }
41 |
42 | afterEvaluate { project ->
43 | uploadArchives {
44 | //noinspection GradleMisplacedStatement
45 | repositories {
46 | mavenDeployer {
47 | beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
48 |
49 | pom.artifactId = POM_ARTIFACT_ID
50 | pom.groupId = GROUP
51 | pom.version = VERSION_NAME
52 |
53 | repository(url: getReleaseRepositoryUrl()) {
54 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
55 | }
56 | snapshotRepository(url: getSnapshotRepositoryUrl()) {
57 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
58 | }
59 |
60 | pom.project {
61 | name POM_NAME
62 | packaging POM_PACKAGING
63 | description POM_DESCRIPTION
64 | url POM_URL
65 |
66 | scm {
67 | url POM_SCM_URL
68 | connection POM_SCM_CONNECTION
69 | developerConnection POM_SCM_DEV_CONNECTION
70 | }
71 |
72 | licenses {
73 | license {
74 | name POM_LICENCE_NAME
75 | url POM_LICENCE_URL
76 | distribution POM_LICENCE_DIST
77 | }
78 | }
79 |
80 | developers {
81 | developer {
82 | id POM_DEVELOPER_ID
83 | name POM_DEVELOPER_NAME
84 | }
85 | }
86 | }
87 | }
88 | }
89 | }
90 |
91 | signing {
92 | required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") }
93 | sign configurations.archives
94 | }
95 |
96 | task androidJavadocs(type: Javadoc) {
97 | source = android.sourceSets.main.java.source
98 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
99 | }
100 |
101 | task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
102 | classifier = 'javadoc'
103 | from androidJavadocs.destinationDir
104 | }
105 |
106 | task androidSourcesJar(type: Jar) {
107 | classifier = 'sources'
108 | from android.sourceSets.main.java.source
109 | }
110 |
111 | artifacts {
112 | archives androidSourcesJar
113 | archives androidJavadocsJar
114 | }
115 | }
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':library', ':demo'
2 |
--------------------------------------------------------------------------------