Giter Site home page Giter Site logo

rippledrawable's Introduction

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.

rippledrawable's People

Contributors

achep avatar groxx avatar kirussell avatar ozodrukh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rippledrawable's Issues

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 😞

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

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

enter ripple animation play twice.

Long press and release finger before ripple animation ended, the enter animation will play twice.
In Ripple.java method enter(), called animation start twice here.
Comment the three line may fix it.
// radius.start();
// cX.start();
// cY.start();

    AnimatorsCompat.startWithAutoCancel(radius);
    AnimatorsCompat.startWithAutoCancel(cX);
    AnimatorsCompat.startWithAutoCancel(cY);

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.

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.

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.

disables onItemClick Listner when setClickable to Ripple View

I've list view listView.setOnItemClickListener(this)

and

I've ripple code in base adapter extending class
View view = layoutInflater.inflate(R.layout.quick_search_property_row, null);
LinearLayout propertyTypeLayout = (LinearLayout) view.findViewById(R.id.property_type_layout);
//ripple effect..
propertyTypeLayout.setBackground(getRippleDrawable(R.drawable.ripple_effect));
propertyTypeLayout.setClickable(true);
propertyTypeLayout.setOnTouchListener(new DrawableHotspotTouch((LollipopDrawable) propertyTypeLayout.getBackground()));

but this clickable removes onItemClickLisner on LIstView

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.

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).

<ripple> 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.

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.

Invaild drawable tag ripple

When I try to build app with this liblary I have error: invaild drawable tag ripple
I based on the samples and I dont know what is wrong 😢😢

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.