Ripple effect for Android 14+

Overview

RippleDrawable

Port of Android <ripple> effect for pre lollipop devices with android 14 + (ICS+)

(well, since NineOldAndroids is deprecated, this library become 14 + only)

Features

  1. XML inflating
  2. Ripple supports different shapes
  3. Custom drawable loader
  4. Define your custom drawable tags

Implementation

Create your desirable ripple.xml in drawable/ folder

<?xml version="1.0" encoding="utf-8"?>
<ripple
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="@color/ripple_material_light">     <!-- ripple color -->

    <!-- for Floating Action Button -->
    <item>
        <shape android:shape="oval">
            <solid android:color="@color/accent_material_dark"/>
        </shape>
    </item>

</ripple>

Secondly we need to inflate RippleDrawable and intercept View touches see LollipopDrawablesCompat and DrawableHotspotTouch for inflating and interception sequently. Here is sample:

public class SampleActivity extends AppCompatActivity {

    private FloatingActionButton mActionButton;

      @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sample);
        
        mActionButton = (FloatingActionButton) findViewById(R.id.fab);
        mActionButton.setBackgroundDrawable(getDrawable2(R.drawable.fab_background));
        mActionButton.setClickable(true);// if we don't set it true, ripple will not be played
        mActionButton.setOnTouchListener(
                new DrawableHotspotTouch((LollipopDrawable) mActionButton.getBackground()));
    }
    
/**
     * {@link #getDrawable(int)} is already taken by Android API
     * and method is final, so we need to give another name :(
     */
    public Drawable getDrawable2(int id){
        return LollipopDrawablesCompat.getDrawable(getResources(), id, getTheme());
    }
}

Thats it!

##Dependency

root build.gradle add a repository

    repositories {
        maven {
            url "https://jitpack.io"
        }
    }

and in application module just add

    dependencies {
            compile 'com.github.ozodrukh:RippleDrawable:2.0.0'
    }

a little bit more

you can inflate and create your own Drawableclasses, here is tips & tricks

1 extend your Drawable from LollipopDrawable

    public class LayerDrawable extends LollipopDrawable {

2 implement your own inflation

    public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs, Resources.Theme theme);

3 Register your LollipopDrawable

static {   
    LollipopDrawablesCompat.registerDrawable(RippleDrawable.class, "ripple");
}

4 inflate it!

    LollipopDrawablesCompat.getDrawable(getResources(), R.drawable.custom_drawable, getTheme());

License

The MIT License (MIT)

Copyright (c) 2015 Abdullaev Ozodrukh

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Comments
  • Ripple applied on listview item when scrolling

    Ripple applied on listview item when scrolling

    I applied your library on listview item, whenever I scroll every listview item I touch while scrolling will get the ripple is applied to it.

    Thanks in advance.

    opened by OmarBizreh 6
  • Attribute conflict with other libraries (srcCompat).

    Attribute conflict with other libraries (srcCompat).

    Would you consider prefixing custom attributes so they don't conflict with other dependencies? I'm noticing srcCompat is being used in this library and a few others without any prefixing and could cause attribute already defined errors.

    opened by DejanRistic 5
  • ACTION_UP and ACTION_CANCEL not fired.

    ACTION_UP and ACTION_CANCEL not fired.

    I use RippleDrawable in ListView Adapter's getView method, when I pressed and hold, it work normally, but if I pressed and hold and then scroll, onFingerUp() do not get fired.

    opened by kyze8439690 4
  • Ripple is not support oval background

    Ripple is not support oval background

    If I set up background like

    <shape
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="oval">
        <solid android:color="@color/wl_blue"/>
    </shape>
    

    I see "square" effect

    opened by IstiN 4
  • <ripple> does not get overridden

    does not get overridden

    When following instructions, when I include the library and use in /drawable I still get the error message saying that it only works on v21+, so it gets the old one.

    opened by BartNijland91 1
  • Add library to project

    Add library to project

    Hi im really a noob. Could somebody explain me how to add this library to my project without gradle? Started with Android Studio and never needed exporting Git dependencies so far.

    opened by philipgiuliani 1
  • Reverting the dev branch merge

    Reverting the dev branch merge

    Choice 1: Reverting a merge can be accomplished using:

    http://git-scm.com/blog/2010/03/02/undoing-merges.html

    Choice 2: use git reset "HEAD^" on master till you reaches the stable commit, clean up, and push -f

    Choice 3:

    • checkout to the last stable commit, say, git check COMMIT_ID
    • remove the master branch by git brand -d master
    • create a master branch base on the commit, say, git checkout -b master
    • push to remote: git push -u origin/master -f

    All these method requires to rewrite the master header(except Choice 1 which produces a reverse commit). I haven't tried in github, but these methods work on some other remote repos. I assume they should be the same.

    Good Luck.

    opened by qezt 1
  • Replace resources in whole application

    Replace resources in whole application

    Have someone experience in replacing Resources in whole application, i need to intercept getDrawable method everywhere

    Testing on Genymotion, Android 4.1.1

    i need some ideas how to work around

    1. Approach to wrap context when attachBaseContext method called, failed. When inflating views it doesn't works :(
    2. I found really strange behavior that the original(android) views and custom views are getting different types of Context. Cause i made efforts to set background via XML on ImageButton and get Exception, but when i create custom view extended from ImageButton it worked update on approach 2 hmm, looks like if i define background as an attribute it falls, if do it by code it works

    i found what is going on after all, the views calls TypedArray#getDrawable method

    
        public Drawable getDrawable(int index) {
            if (mRecycled) {
                throw new RuntimeException("Cannot make calls to a recycled instance!");
            }
    
            final TypedValue value = mValue;
            if (getValueAt(index*AssetManager.STYLE_NUM_ENTRIES, value)) {
                if (value.type == TypedValue.TYPE_ATTRIBUTE) {
                    throw new RuntimeException("Failed to resolve attribute at index " + index);
                }
                return mResources.loadDrawable(value, value.resourceId, mTheme);
            }
            return null;
        }
    
    

    Now i need to think how to replace loadDrawable method :disappointed:

    New plan, going to replace LayoutInflater with custom one and create custom attributes like Calligraphy did

    enhancement help wanted question 
    opened by ozodrukh 1
  • CardView inside RycyclerView on devices < L

    CardView inside RycyclerView on devices < L

    Error occurs when I try to use your library on CardView inside RecyclerView on devices older then L, but on Lollipop devices everything is fine. Throws java.lang.ClassCastException: dreamers.graphics.RippleDrawable cannot be cast to android.support.v7.widget.RoundRectDrawableWithShadow. What is wrong? Thanks in advance.

    opened by guguza 1
  • Undoing bad merge, reset to 3512988

    Undoing bad merge, reset to 3512988

    Assuming the last intended-for-master commit was 3512988, this reverts the intervening commits.

    Let me know if I picked the wrong commit! Or feel free to tackle that yourself: I just used git checkout 3512988 . and then add / remove files as necessary to get git diff 3512988 to be empty. It's a bit coarse perhaps, but it gets the job done, and works no matter what the history looks like.

    opened by Groxx 0
  • Dirty fix for click handling on half-empty scrollable container

    Dirty fix for click handling on half-empty scrollable container

    If you press an item of half-empty scrollable container (which is obliviously not scrollable now) and move your finger away out of the item's bounds and then release... view is being clicked. This is probably not perfect solution, but it solves the issue.

    opened by AChep 0
  • Update the code

    Update the code

    Hello, The RippleDrawable of the Android 9.0 Pie, is very better than the Lollipop one. Please update the codes to backport Android 9.0 ripples to the older version (back to API 14 or 17).

    opened by ghost 1
  • Up-to-date fork

    Up-to-date fork

    Since there hasn't been much activity on this repository, I created a fork and cleaned up the code. My library can be found here, I hope to keep it up-to-date and maintained: https://github.com/addisonElliott/RippleDrawable

    Check out the README for instructions on installing.

    opened by addisonElliott 0
  • LayerDrawable.updateStateFromTypedArray (state.mPaddingMode) Can't convert to integer

    LayerDrawable.updateStateFromTypedArray (state.mPaddingMode) Can't convert to integer

    in LayerDrawable.class privated method updateStateFromTypedArray() state.mPaddingMode=a.getInteger() . Can't convert to Integer TYPE= 0x3 . Samsung,android 4.4.2, API 19(KITKAT)

    opened by SupinePandora43 0
  • Is there a way to get bounds outside of the view in pre-Lollipop?

    Is there a way to get bounds outside of the view in pre-Lollipop?

    On KitKat the ripple is rectangular and only extends inside the view's margin unlike on Lollipop which can extend into a full circle outside the available margins.

    opened by cmalex23 0
  • Fix NoSuchMethodError on super.getDirtyBounds()

    Fix NoSuchMethodError on super.getDirtyBounds()

    RippleDrawable#getDirtyBounds() calls super. It is API >= 21 method but is missing from LollipopDrawable. This exception only happens on pre-lollipop Androids.

    opened by ypresto 3
Releases(2.0.1)
Owner
Ozodrukh
Do-er
Ozodrukh
Ripple effect for Android 14+

RippleDrawable Port of Android <ripple> effect for pre lollipop devices with android 14 + (ICS+) (well, since NineOldAndroids is deprecated, this libr

Ozodrukh 516 Nov 25, 2022
This is a library with components of Android L to you use in android 2.2

Material Design Android Library How to use Components Buttons Flat Button Rectangle Button Float Button Float small button Switches CheckBox Switch Pr

Ivan Navas 9.1k Jan 5, 2023
📱Android Library to implement animated, 😍beautiful, 🎨stylish Material Dialog in android apps easily.

Material Dialogs for Android ?? ?? Android Library to implement animated, ?? beautiful, ?? stylish Material Dialog in android apps easily. 1. Material

Shreyas Patil 875 Dec 28, 2022
MaterialPickers-in-android - A simple android project that shows how to create material pickers for date and time

MaterialPickers-in-android A simple android project that shows how to create mat

Segun Francis 2 Apr 28, 2022
Material Shadows for android : A library for supporting convex material shadows

MaterialShadows A library for seamlessly integrating Material shadows. The library takes existing material shadows to next level by adding the followi

Harjot Singh Oberai 2.2k Dec 19, 2022
A library to bring fully animated Material Design components to pre-Lolipop Android.

Material MaterialLibrary is an Open Source Android library that back-port Material Design components to pre-Lolipop Android. MaterialLibrary's origina

Rey Pham 6k Dec 21, 2022
😍 A beautiful, fluid, and extensible dialogs API for Kotlin & Android.

Material Dialogs View Releases and Changelogs Modules The core module is the fundamental module that you need in order to use this library. The others

Aidan Follestad 19.5k Dec 31, 2022
The flexible, easy to use, all in one drawer library for your Android project. Now brand new with material 2 design.

MaterialDrawer ... the flexible, easy to use, all in one drawer library for your Android project. What's included ?? • Setup ??️ • Migration Guide ??

Mike Penz 11.6k Dec 27, 2022
Floating Action Button for Android based on Material Design specification

FloatingActionButton Yet another library for drawing Material Design promoted actions. Features Support for normal 56dp and mini 40dp buttons. Customi

Zendesk 6.4k Dec 26, 2022
Material Design implementation for Android 4.0+. Shadows, ripples, vectors, fonts, animations, widgets, rounded corners and more.

Carbon Material Design implementation for Android 4.0 and newer. This is not the exact copy of the Lollipop's API and features. It's a custom implemen

null 3k Jan 9, 2023
Animations for Android L drawer, back, dismiss and check icons

Material Menu Morphing Android menu, back, dismiss and check buttons Have full control of the animation: Including in your project compile 'com.balysv

Balys Valentukevicius 2.5k Jan 3, 2023
An Android library aimed to get the beautiful CardViews that Google shows at its official design specifications

MaterialList Discontinued This library will not receive any updates, as I do not have the time or knowledge to improve it. If anyone forks it and want

null 1.6k Nov 29, 2022
Android widget for selecting a range of values.

MaterialRangeBar MaterialRangeBar is a fork from https://github.com/edmodo/range-bar that adds some basic material styling, as well as start and end v

null 1.7k Dec 30, 2022
Android drawer icon with material design animation

LDrawer Android drawer icon with material design animation Note Basically same as appcompat_v7 version 21, you can use appcompat_v7 compile 'com.andro

Hasan Keklik 1.4k Dec 25, 2022
[] Android Library that implements Snackbars from Google's Material Design documentation.

DEPRECATED This lib is deprecated in favor of Google's Design Support Library which includes a Snackbar and is no longer being developed. Thanks for a

null 1.5k Dec 16, 2022
A material horizontal calendar view for Android based on RecyclerView

Horizontal Calendar A material horizontal calendar view for Android based on RecyclerView. Installation The library is hosted on jcenter, add this to

Mulham Raee 1.2k Dec 15, 2022
Android Sample Project with Material Design and Toolbar.

AndroidMaterialDesignToolbar -- PROJECT IS NOT SUPPORTED Android Sample Project with Material Design and Toolbar. Project use Appcompat library for ma

kemal selim tekinarslan 713 Nov 11, 2022
Material style circular progress bar for Android

Material CircularProgressView Indeterminate Determinate Description This CircularProgressView is a (surprisingly) circular progress bar Android View t

Rahat Ahmed 760 Nov 30, 2022
Android - draw z-depth shadow of MaterialDesign

ZDepthShadowLayout Android - draw z-depth shadow of MaterialDesign Demo Screen Capture Download apply plugin: 'com.android.application' repositories

sho5nn 573 Nov 28, 2022