Skip to content

Commit 6299df1

Browse files
committed
minor cosmetic updates
1 parent 667d1d9 commit 6299df1

File tree

4 files changed

+73
-5
lines changed

4 files changed

+73
-5
lines changed

README.md

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,25 @@
33
=============
44
This repository contains post of Android `<ripple>` effect for pre lollipop devices with android 14 + (ICS+)
55

6+
(well, since NineOldAndroids is deprecated, this library become 14 + only, furthermore gingerbread devices is not spread now)
7+
68
### Features
7-
1. XML inflating (working on)
9+
1. XML inflating
810
2. Ripple supports different shapes
911
3. Custom drawable loader
1012
4. Define your custom drawable tags
1113

1214
#### Implementation
1315

14-
create this file in your drawables/ or drawables-v14/ folder
16+
Create your desirable ripple.xml in `drawable/` folder
17+
1518
```xml
1619
<?xml version="1.0" encoding="utf-8"?>
1720
<ripple
1821
xmlns:android="http://schemas.android.com/apk/res/android"
19-
android:color="@color/ripple_material_light">
22+
android:color="@color/ripple_material_light"> <!-- ripple color -->
2023

21-
<!-- for fab -->
24+
<!-- for Floating Action Button -->
2225
<item>
2326
<shape android:shape="oval">
2427
<solid android:color="@color/accent_material_dark"/>
@@ -29,6 +32,64 @@ create this file in your drawables/ or drawables-v14/ folder
2932

3033
```
3134

35+
Secondly we need to inflate `RippleDrawable` and intercept `View` touches
36+
see `LollipopDrawablesCompat` and `DrawableHotspotTouch` for inflating and interception sequently. Here is sample:
37+
38+
```java
39+
40+
public class SampleActivity extends AppCompatActivity {
41+
42+
private FloatingActionButton mActionButton;
43+
44+
@Override
45+
protected void onCreate(Bundle savedInstanceState) {
46+
super.onCreate(savedInstanceState);
47+
setContentView(R.layout.activity_sample);
48+
49+
mActionButton = (FloatingActionButton) findViewById(R.id.fab);
50+
mActionButton.setBackgroundDrawable(getDrawable2(R.drawable.fab_background));
51+
mActionButton.setClickable(true);// if we don't set it true, ripple will not be played
52+
mActionButton.setOnTouchListener(
53+
new DrawableHotspotTouch((LollipopDrawable) mActionButton.getBackground()));
54+
}
55+
56+
/**
57+
* {@link #getDrawable(int)} is already taken by Android API
58+
* and method is final, so we need to give another name :(
59+
*/
60+
public Drawable getDrawable2(int id){
61+
return LollipopDrawablesCompat.getDrawable(getResources(), id, getTheme());
62+
}
63+
}
64+
65+
```
66+
67+
**Thats it!**
68+
69+
#### a little bit more
70+
71+
you can inflate and create your own `Drawable`classes, here is tips & tricks
72+
73+
1 extend your Drawable from `LollipopDrawable`
74+
```java
75+
public class LayerDrawable extends LollipopDrawable {
76+
```
77+
78+
2 implement your own inflation
79+
```java
80+
public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs, Resources.Theme theme);
81+
```
82+
3 Register your `LollipopDrawable`
83+
```java
84+
static {
85+
LollipopDrawablesCompat.registerDrawable(RippleDrawable.class, "ripple");
86+
}
87+
```
88+
89+
4 inflate it!
90+
```java
91+
LollipopDrawablesCompat.getDrawable(getResources(), R.drawable.custom_drawable, getTheme());
92+
```
3293

3394
License
3495
--------
@@ -55,3 +116,4 @@ License
55116
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
56117
THE SOFTWARE.
57118

119+

app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
apply plugin: 'com.android.library'
2+
apply plugin: 'android-maven'
23

34
android {
45
compileSdkVersion 22

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ buildscript {
55
jcenter()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:1.1.0'
8+
classpath 'com.android.tools.build:gradle:1.2.3'
9+
classpath 'com.github.dcendents:android-maven-plugin:1.2'
910
}
1011
}
1112

sample/src/main/java/dreamers/sample/SampleActivity.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ protected void onCreate(Bundle savedInstanceState) {
3434
new DrawableHotspotTouch((LollipopDrawable) mActionButton.getBackground()));
3535
}
3636

37+
/**
38+
* {@link #getDrawable(int)} is already taken by Android API
39+
* and method is final, so we need to give another name :(
40+
*/
3741
public Drawable getDrawable2(int id){
3842
return LollipopDrawablesCompat.getDrawable(getResources(), id, getTheme());
3943
}

0 commit comments

Comments
 (0)