swipebutton

Additional

Language
Kotlin
Version
1.0.0 (Sep 30, 2023)
Created
Sep 30, 2023
Updated
Sep 30, 2023
Owner
Sub4ik (Sub4ikGG)
Contributor
Sub4ik (Sub4ikGG)
1
Activity
Badge
Generate
Download
Source code

swipebutton

Simple Android SwipeButton
Example: https://github.com/Sub4ikGG/swipebuttonexample

How it looks like

Installation

JitPack repository

Step 1. Add the JitPack repository to your build file

Groovy

allprojects {
  repositories {
    ...
    maven { url 'https://jitpack.io' }
  }
}

Kts

allprojects {
  repositories {
    ...
    maven(url = "https://jitpack.io")
  }
}

Dependency

Step 2. Add the dependency

Groovy

dependencies {
    ...
    // SwipeButton
    implementation 'com.github.Sub4ikGG:swipebutton:1.0.0'
}

Kts

dependencies {
    ...
    // SwipeButton
    implementation("com.github.Sub4ikGG:swipebutton:1.0.0")
}

Start

Add View to your layout

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <...>

    <ru.chatan.swipebutton.SwipeButton
        android:id="@+id/swipe_button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginEnd="16dp"
        android:layout_marginBottom="32dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:swipeDrawable="@drawable/arrow"
        app:swipeText="SWIPE ME!"
        app:swipeTextColor="@color/black"
        app:swipeTextSize="14sp"
        app:swipeThumbColor="@color/light_blue"
        app:swipeProgressColor="@color/light_blue" />

    <...>

</androidx.constraintlayout.widget.ConstraintLayout>
app:swipeDrawable - thumb drawable
app:swipeText - swipeButton text
app:swipeTextColor - color for your text
app:swipeTextSize - textSize for the text
app:swipeThumbColor - thumb color
app:swipeProgressColor - the color that will fill swipeButton

Options

OnSwipeButtonListener:

swipeButton.setListener(
    object : SwipeButton.OnSwipeButtonListener {
      override fun onSwiped() {
        // TODO: Do something here
      }
    }
)

Reloading:

// if you want to return default text use 'setDefaultText = true'
// defaultText is taken from app:swipeText
swipeButton.reload(setDefaultText = true)

Set text:

swipeButton.setText(text = "Text")

Set default text:

// Changing default text that represented in app:swipeText
swipeButton.setDefaultText(defaultText = "Text")

License

Copyright 2023 Kirill Efremov

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.