https://github.com/stfalcon-studio/swipeable-button
Android Swipeable button like in iOS unlock screen. Made by Stfalcon
https://github.com/stfalcon-studio/swipeable-button
custom-button swipe swipebutton
Last synced: about 1 year ago
JSON representation
Android Swipeable button like in iOS unlock screen. Made by Stfalcon
- Host: GitHub
- URL: https://github.com/stfalcon-studio/swipeable-button
- Owner: stfalcon-studio
- License: apache-2.0
- Created: 2018-07-26T12:01:22.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-07-02T09:58:39.000Z (almost 7 years ago)
- Last Synced: 2025-04-10T18:06:45.784Z (about 1 year ago)
- Topics: custom-button, swipe, swipebutton
- Language: Kotlin
- Homepage: https://stfalcon.com
- Size: 4.15 MB
- Stars: 87
- Watchers: 6
- Forks: 8
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# swipeable-button

## Who we are
Need iOS and Android apps, MVP development or prototyping? Contact us via info@stfalcon.com. We develop software since 2009, and we're known experts in this field. Check out our [portfolio](https://stfalcon.com/en/portfolio) and see more libraries from [stfalcon-studio](https://stfalcon-studio.github.io/).
## Download
Download via Gradle:
```compile 'com.github.stfalcon:swipeable-button:0.1.0'```
## Usage
Just put this code into your layout:
```
```
You can use many attributes for more flexibility and convenience of use. Here's the full list:
- isChecked - Initial state. Boolean. False by default
- isEnabled - Is button enabled. Boolean. True by default
- textChecked - Text for checked state
- textUnchecked - Text for unchecked state
- textColorChecked - Text color when button is checked
- textColorUnchecked - Text color when button is unchecked
- textSize - Text size
- thresholdStart - Value in range [0..1] indicates how much user needs to swipe to change status from unchecked to checked. 0.5 by default
- thresholdEnd - Value in range [0..1] indicates how much user needs to swipe to change status from checked to unchecked. 0.5 by default
- checkedBackground - Button background drawable for checked state.
- uncheckedBackground - Button background drawable for unchecked state.
- checkedToggleBackground - Toggle background drawable when button is checked.
- uncheckedToggleBackground - Toggle background drawable when button is unchecked.
- checkedIcon - Toggle icon drawable when button is checked
- uncheckedIcon - Toggle icon drawable when button is unchecked
For example:
```
```
Also you can set them programmatically:
```
swipeableButton.isChecked = true
swipeableButton.isEnable = true
swipeableButton.checkedText = "Checked text"
swipeableButton.uncheckedText = "Unchecked text"
swipeableButton.textSize = resources.getDimensionPixelSize(R.dimen.default_text_size).toFloat()
swipeableButton.swipeProgressToFinish = 0.1
swipeableButton.swipeProgressToStart = 0.3
swipeableButton.checkedTextColor = ContextCompat.getColor(this,R.color.checkedTextColor)
swipeableButton.uncheckedTextColor = ContextCompat.getColor(this,R.color.uncheckedTextColor)
swipeableButton.checkedBackground = ContextCompat.getDrawable(this, R.drawable.shape_sample_scrolling_view_checked)
swipeableButton.uncheckedBackground = ContextCompat.getDrawable(this, R.drawable.shape_sample_scrolling_view_unchecked)
swipeableButton.checkedToggleBackground = ContextCompat.getDrawable(this, R.drawable.shape_sample_checked_toggle)
swipeableButton.uncheckedToggleBackground = ContextCompat.getDrawable(this, R.drawable.shape_sample_unchecked_toggle)
swipeableButton.checkedIcon = ContextCompat.getDrawable(this, R.drawable.ic_done_black)
swipeableButton.uncheckedIcon = ContextCompat.getDrawable(this, R.drawable.ic_pause_black)
```
If you want to change the state programmatically with animation you should use `setSwipeButtonState` method:
```
animateBtn.setOnClickListener {
swipeButton.setSwipeButtonState(!swipeableButton.isChecked)
}
```
If you want to get event from swipable-button you need to add next listeners:
- `onSwipedListener`
- `onSwipedOnListener`
- `onSwipedOffListener`
Let's take look a small sample:
```
customSwipeButton.onSwipedListener = {
Log.d(TAG, "onSwiped")
}
customSwipeButton.onSwipedOnListener = {
Log.d(TAG, "onSwipedOn")
}
customSwipeButton.onSwipedOffListener = {
Log.d(TAG, "onSwipedOff")
}
```
## License
```
Copyright 2018 stfalcon.com
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.
```