Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/skydoves/elasticviews

:sparkles: An easy way to implement an elastic touch effect for Android.
https://github.com/skydoves/elasticviews

action android-animation android-library animation elastic elaticviews skydoves touch-animation

Last synced: about 1 month ago
JSON representation

:sparkles: An easy way to implement an elastic touch effect for Android.

Awesome Lists containing this project

README

        

# ElasticViews


License
API
Build Status
Android Weekly
Javadoc


✨ An easy way to implement an elastic touch effect for Android.




## Including in your project
[![Maven Central](https://img.shields.io/maven-central/v/com.github.skydoves/elasticviews.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22com.github.skydoves%22%20AND%20a:%22elasticviews%22)
[![Kitpack](https://jitpack.io/v/skydoves/ElasticViews.svg)](https://jitpack.io/#skydoves/ElasticViews)

#### Gradle
Add codes below to your **root** `build.gradle` file (not your module build.gradle file).
```gradle
allprojects {
repositories {
mavenCentral()
}
}
```
And add a dependency code to your **module**'s `build.gradle` file.
```gradle
dependencies {
implementation "com.github.skydoves:elasticviews:2.1.0"
}
```
## SNAPSHOT
[![ElasticViews](https://img.shields.io/static/v1?label=snapshot&message=elasticviews&logo=apache%20maven&color=C71A36)](https://oss.sonatype.org/content/repositories/snapshots/com/github/skydoves/elasticviews/)

Snapshots of the current development version of ElasticViews are available, which track [the latest versions](https://oss.sonatype.org/content/repositories/snapshots/com/github/skydoves/elasticviews/).
```Gradle
repositories {
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
}
```

## Usage
`ElasticViews` lets we use like using normal views and gives all of the Views or GroupViews touch effect very simply.

#### Add XML Namespace
First add below XML Namespace inside your XML layout file.

```gradle
xmlns:app="http://schemas.android.com/apk/res-auto"
```

#### OnClick Method
All of ElasticViews should be set `OnClickListener` or `onClick` method. If not, nothing happens.
```java
ElasticButton elasticButton = (ElasticButton)findViewById(R.id.elasticbutton);
elasticButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// do something
}
});
```

### ElasticButton
```gradle

```

### ElasticCheckButton
```gradle

```

### ElasticImageView
```gradle

```

### ElasticFloatingActionButton
```gradle

```

### ElasticCardView
```gradle

...

```

### ElasticLayout
ElasticLayout gives elastic animation to all child views.

```gradle

```

### ElasticAnimation
ElasticAnimation implements elastic animations for android views and view groups.

```java
new ElasticAnimation(clickedView).setScaleX(0.9f).setScaleY(0.9f).setDuration(400)
.setOnFinishListener(onFinishListener).doAction();
```

#### ViewPropertyAnimatorListener
we can set `ViewPropertyAnimatorListener` using `setListener` method and detect animation's status.
```java
.setListener(new ViewPropertyAnimatorListener() {
@Override
public void onAnimationStart(View view) {
// do something
}

Override
public void onAnimationEnd(View view) {
finishListener.onFinished();
}

Override
public void onAnimationCancel(View view) {
// do something
}
});
```

#### Kotlin Extension
ElasticAnimation supports kotlin extension `elasticAnimation`.
```kotlin
val anim = textView.elasticAnimation(0.8f, 0.8f, 400, object: ElasticFinishListener {
override fun onFinished() {
// do anything
}
})
anim.doAction()
```

#### Kotlin dsl
```kotlin
elasticAnimation(this) {
setDuration(duration)
setScaleX(scale)
setScaleY(scale)
setOnFinishListener(object : ElasticFinishListener {
override fun onFinished() {
onClick()
}
})
}.doAction()
```

#### Example : Normal Button
we can implement animation on all of the views like below.
```java
@OnClick(R.id.button)
public void addNewAlarm(View v){
// implements animation uising ElasticAnimation
new ElasticAnimation(v).setScaleX(0.85f).setScaleY(0.85f).setDuration(500)
.setOnFinishListener(new ElasticFinishListener() {
@Override
public void onFinished() {
// Do something after duration time
}
}).doAction();
}
}
```

#### Example : ListView Item
So also we can implement animation on listView's items like below.
```java
private class ListViewItemClickListener implements AdapterView.OnItemClickListener {
@Override
public void onItemClick(AdapterView> adapterView, View clickedView, final int pos, long id) {
new ElasticAnimation(clickedView).setScaleX(0.9f).setScaleY(0.9f).setDuration(400)
.setOnFinishListener(new ElasticFinishListener() {
@Override
public void onFinished() {
// Do something after duration time
Toast.makeText(getBaseContext(), "ListViewItem" + pos, Toast.LENGTH_SHORT).show();
}
}).doAction();
}
};
```

## Find this library useful? :heart:
Support it by joining __[stargazers](https://github.com/skydoves/ElasticViews/stargazers)__ for this repository. :star:

And __[follow](https://github.com/skydoves)__ me for my next creations! 🤩

# License
```xml
The MIT License (MIT)

Copyright (c) 2017 skydoves

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