Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/opensooq/pluto

Pluto is an Easy, lightweight and high performance slider view library for Android. You have the flexibility to customize it to any view since it based RecyclerView.
https://github.com/opensooq/pluto

android image kotlin library slider

Last synced: 2 days ago
JSON representation

Pluto is an Easy, lightweight and high performance slider view library for Android. You have the flexibility to customize it to any view since it based RecyclerView.

Awesome Lists containing this project

README

        


OpenSooq logo

Pluto [Android Slider View Library]
======================
![API](https://img.shields.io/badge/API-17%2B-green.svg?style=flat) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Pluto-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/7641)

:star: Star us on GitHub — it helps!

[![forthebadge](https://forthebadge.com/images/badges/built-with-love.svg)](https://forthebadge.com)

##### Pluto is an Easy, lightweight and high performance slider view library for Android! You can customize it to any view since it based RecyclerView. The differnce of this library, we are not following the concept of images model. Pluto is not depending on any Image loading library

Demo
======================

## Table of content

* [Download](#download)
* [Sample Project](#sample-project)
* [Usage](#usage)
* [Event Listeners](#event-listeners)
* [Custom indicator](#Custom-indicator)
- [License](#license)

# Download

This library is available in **jCenter** which is the default Maven repository used in Android Studio. You can also import this library from source as a module.

```groovy
dependencies {
// other dependencies here
implementation 'com.opensooq.android:pluto:1.6'
}
```

# Sample Project
We have a sample project demonstrating how to use the library.

Checkout the demo [here](https://github.com/OpenSooq/Pluto/tree/master/app/src/main/java/com/opensooq/plutodemo)

# Usage
#### First create your own adapter extending the ``PlutoAdapter``

### Kotlin
```kotlin
class YourAdapter(items: MutableList , onItemClickListener: OnItemClickListener? = null)
: PlutoAdapter(items,onItemClickListener) {

override fun getViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return ViewHolder(parent, R.layout.item_your_layout)
}

class YourViewHolder(parent: ViewGroup, itemLayoutId: Int) : PlutoViewHolder(parent, itemLayoutId) {
private var ivPoster: ImageView = getView(R.id.iv_poster)
private var tvRating: TextView = getView(R.id.tv_rating)

override fun set(item: YourModel, position: Int) {
// yourImageLoader.with(mContext).load(item.getPosterId()).into(ivPoster);
tvRating.text = item.imdbRating
}
}
}
```
### Java

```java
public class YourAdapter extends PlutoAdapter {

public YourAdapter(List items) {
super(items);
}

@Override
public ViewHolder getViewHolder(ViewGroup parent, int viewType) {
return new YourViewHolder(parent, R.layout.item_your_layout);
}

public static class YourViewHolder extends PlutoViewHolder {
ImageView ivPoster;
TextView tvRating;

public YourViewHolder(ViewGroup parent, int itemLayoutId) {
super(parent, itemLayoutId);
ivPoster = getView(R.id.iv_poster);
tvRating = getView(R.id.tv_rating);
}

@Override
public void set(YourModel item, int pos) {
// yourImageLoader.with(mContext).load(item.getPosterId()).into(ivPoster);
tvRating.setText(item.getImdbRating());
}
}
}
```
#### Then in your xml
```XML

```
### finaly attach the adapter to Pluto
### Kotlin
```kotlin
val pluto = findViewById(R.id.slider_view)
val yourAdapter = YourAdapter(yourModelList, object : OnItemClickListener {
override fun onItemClicked(item: yourModel?, position: Int) {
}
})

pluto.create(adapter, lifecycle = lifecycle)//pass the lifecycle to make the slider aware of lifecycle to avoid memory leak and handling the pause/destroy/resume

```
### Java
```java
PlutoView pluto = findViewById(R.id.slider_view);
YourAdapter adapter = new YourAdapter(yourModelsList);
pluto.create(adapter,getLifecycle()); //pass the lifecycle to make the slider aware of lifecycle to avoid memory leak and handling the pause/destroy/resume
```
| Method | usage |
| ------ | ------ |
| ``` create(PlutoAdapter adapter, long duration,Lifecycle lifecyle)``` | it is the initialization method it take your adapter and the duration of waiting between each slide and lifecycle to make slider lifecylce-aware |
| ``` startAutoCycle() ``` | by default the value of autocycle is true, it determine to start autocycling or not |
| ``` stopAutoCycle() ``` | it stops the auto cycling of the view |
| ``` moveNextPosition() ``` | if you are the auto cylce is off you can manually move next with this method |
| ``` movePrevPosition() ``` | if you are the auto cylce is off you can manually move to the previus item with this method |
| ``` setIndicatorPosition(IndicatorPosition presetIndicator) ``` | to set the position of the indicator where values are ```CENTER_BOTTOM``` ```RIGHT_BOTTOM``` ```LEFT_BOTTOM``` ```CENTER_TOP``` ```RIGHT_TOP``` ```LEFT_TOP```|
| ``` setCustomIndicator(PlutoIndicator indicator) ``` | if you want to custom the indicator use this method for custom indicators check [Custom indicators](#indicator) |

# Event Listeners
### for item click listener its the responsibility of the ```PlutoAdapter``` to handle it,
#### Example
### Kotlin
```kotlin
val adapter = SliderAdapter(getAvenger(), object : OnItemClickListener {
override fun onItemClicked(item: Movie?, position: Int) {
//handle click
}

})
//or
adapter.setOnItemClickListener(object : OnItemClickListener {
override fun onItemClicked(item: Movie?, position: Int) {
//handle click
}
})

```
### Java
```java

SliderAdapter adapter = new SliderAdapter(getAvengers(), (item, position) -> {
//handle clickhere
});
//or
adapter.setOnItemClickListener((item, position) -> {
//handle click here
});
```
### you can attach listener to the ```PlutoView``` to listen for sliding event
#### Example

### Kotlin
```kotlin

pluto.setOnSlideChangeListener(object : OnSlideChangeListener {
override fun onSlideChange(adapter: PlutoAdapter<*, *>, position: Int) {

}
})
```
### Java

```java

pluto.setOnSlideChangeListener(new OnSlideChangeListener() {
@Override
public void onSlideChange(PlutoAdapter adapter, int position) {

}
});
```

# Custom indicator
Add the following xml to your layout:

```xml

```
### Customizable Properties

| Property | Description |
|:----------------------|:---------------------:|
| `shape` | `oval` | `rect` |
| `visibility` | `visible` | `invisible` |
| `selected_drawable unselected_drawable` | You can use an image or custom drawable as the indicator. If you decide to use your own drawable, then the built-in drawable and the properties associated with the built-in drawable will not work. |
| `selected_color` `unselected_color` | the color of the indicator |
| `selected_width` `unselected_width` | the width of the shape |
| `selected_height` `unselected_height` | the height of the shape |
|`selected_padding_left` `unselected_padding_left` `selected_padding_right` `unselected_padding_right` `selected_padding_top` `unselected_padding_top` `selected_padding_bottom` `unselected_padding_bottom` | the padding of the indicator |

#### Examples

![Demo-1](http://ww3.sinaimg.cn/mw690/610dc034jw1eh7metysj6j201y0150jn.jpg)
```xml

```

***

![Demo-2](http://ww2.sinaimg.cn/mw690/610dc034jw1eh7ml8me63j203h00z3y9.jpg)

```xml

```

***

![Demo-3](http://ww4.sinaimg.cn/mw690/610dc034jw1eh7mp7q3fxj202900y3y9.jpg)
```xml

```

***

![Demo-4](http://ww4.sinaimg.cn/mw690/610dc034jw1eh7n82vqk3j203401e0sh.jpg)
```xml

```

**NOTE**: Because a custom image is used for the indicator, following properties will not work:

- `custom:selected_color`
- `custom:selected_width`
- `custom:selected_height`
- `custom:shape`
- `custom:color`
- `custom:width`
- `custom:height`

### Preset Styles

Source is [here](https://github.com/OpenSooq/Pluto/blob/master/pluto/src/main/res/values/styles.xml).

Preset-1:

![](http://ww3.sinaimg.cn/mw690/610dc034jw1ehdhc9drczj202l0160p7.jpg)
```xml

```
***
Preset-2:

![](http://ww4.sinaimg.cn/mw690/610dc034jw1ehdhc5zj9gj203a019jr5.jpg)
```xml

```
***
Preset-3:

![](http://ww2.sinaimg.cn/mw690/610dc034jw1ehdhc0hzb1j202g01aa9t.jpg)
```xml

```

### Using the View

Bind it with a `PlutoView` instance.

```java
pluto.setCustomIndicator(findViewById(R.id.custom_indicator));
```

# License

```
Copyright 2019 OpenSooq

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.