• Stars
    star
    1,179
  • Rank 39,665 (Top 0.8 %)
  • Language
    Kotlin
  • License
    MIT License
  • Created over 8 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A simple 'Slide to Unlock' Material widget for Android, written in Kotlin ๐Ÿ“ฑ๐ŸŽจ๐Ÿฆ„

Slide To Act

CircleCI Maven Central Android Weekly License Twitter Awesome Kotlin Badge

A simple Slide to Unlock Material widget for Android, written in Kotlin ๐Ÿ‡ฐ.

sample-slidetoact gif

Getting Started ๐Ÿ‘ฃ

Slide To Act is distributed through Maven Central. To use it you need to add the following Gradle dependency to your android app gradle file (NOT the root file):

dependencies {
   implementation "com.ncorti:slidetoact:0.10.0"
}

Or you can download the .AAR artifact directly from Maven Central.

Example ๐Ÿšธ

After setting up the Gradle dependency, you can use SlideToActView widgets inside your XML Layout files

<com.ncorti.slidetoact.SlideToActView
    android:id="@+id/example"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:text="Example" />

And bind them inside your Java/Kotlin code:

SlideToActView sta = (SlideToActView) findViewById(R.id.example);

Features ๐ŸŽจ

  • 100% Vectorial, no .png or other assets provided.
  • Fancy animations! ๐Ÿฆ„
  • API >= 14 compatible (since v0.2.0)
  • Easy to integrate (just a gradle compile line).
  • Integrated with your app theme ๐Ÿ–ผ.
  • Works out of the box, no customization needed.
  • Written in Kotlin (but you don't need Kotlin to use it)!
  • UX Friendly ๐Ÿฃ, button will bump to complete if it's over the 80% of the slider (see the following gif).

ux_friendly gif

Attributes

By the default, every SlideToActView widget fits to your app using the colorAccent and the colorBackground parameters from your theme. You can customize your SlideToActView using the following custom attributes.

<com.ncorti.slidetoact.SlideToActView
    android:id="@+id/example_gray_on_green"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:elevation="6dp"
    app:area_margin="4dp"
    app:animation_duration="250"
    app:outer_color="@color/green"
    app:inner_color="@color/grey"
    app:border_radius="2dp"
    app:text="Testing all the custom attributes"
    app:text_size="12sp"
    app:slider_height="80dp"
    app:slider_locked="false"
    app:bounce_on_start="true" />

area_margin

Use the area_marging attribute to control the margin of the inner circular button from the outside area. If not set, this attribute defaults to 8dp.

area_margin_1 area_margin_2

You can also use a negative value to have the inner circular button bigger than the slider. To achieve this effect you also need to set android:clipChildren="false" on the parent layout, like:

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:clipChildren="false">

    <com.ncorti.slidetoact.SlideToActView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:area_margin="-8dp"/>

to obtain this behavior:

area_margin_3

icon_margin

The attribute icon_margin let you control the margin of the icon inside the circular button. This makes the icon bigger because can take up more space in the button.

This is especially useful when you want to make the height of the slider smaller (see slider_height). In this case, if you don't adjust the icon_margin the image can be too much tiny. By default, the icon_margin is set to 16dp.

In next image you can see how it looks like:

icon_margin icon_margin

inner_color & outer_color

Use the outer_color attribute to control the color of the external area and the color of the arrow icon. If not set, this attribute defaults to colorAccent from your theme.

Use the inner_color attribute to control the color of the inner circular button, the color of the tick icon and the color of the text. If not set, this attribute defaults to colorBackground from your theme.

color_1 color_2

border_radius

Use the border_radius attribute to control the radius of the inner circular button and of the external area. A border_radius set to 0dp will result in a square slider. If not set, this attribute will render your slider as a circle (default behavior).

border_radius_1 border_radius_2

text, text_size, text_style, text_appearance

Use the text attribute to control the text of your slider. If not set, this attribute defaults to SlideToActView.

Use the text_size attribute to control the size of the text of your slider. A text_size set to 0sp will result in hiding the text. If not set, this attribute defaults to 16sp.

Use the text_style attribute to control the style of your text. Accepted values are normal, bold and italic.

Use the text_appearance attribute to provide an Android TextAppearance style to fully customize your Text. Please use this attribute if you want to use a custom font or set the text to be all caps.

slider_text slider_text_appearance

slider_height

Use the slider_height attribute to control the desired height of the widget. If not set, the widget will try to render with 72dp of height.

slider_height_1 slider_height_2

slider_locked

Use the slider_locked attribute to lock the slider (this is a boolean attribute). When a slider is locked, will always bump the button to the beginning (default is false).

locked_slider gif

You can also toggle this attribute programmatically with the provided setter.

SlideToActView sta = (SlideToActView) findViewById(R.id.slider);
sta.setLocked(true);

animation_duration

Use the animation_duration attribute to set the duration of the complete and reset animation (in milliseconds).

You can also set animation duration programmatically with the provided setter.

val sta = (SlideToActView) findViewById(R.id.slider);
sta.animDuration = 600

slider_reversed

Use the slider_reversed attribute to reverse the slider (this is a boolean attribute). When a slider is reversed, the cursor will appear on the right and will progress to the left. (default is false).

reversed_slider gif

You can also toggle this attribute programmatically with the provided setter.

SlideToActView sta = (SlideToActView) findViewById(R.id.slider);
sta.setReversed(true);

slider_icon

You can set a custom icon by setting the slider_iconattribute to a drawable resource.

custom_icon

app:slider_icon="@drawable/custom_icon"

You can also set a custom icon programmatically with the provided setter.

SlideToActView sta = findViewById(R.id.slider);
sta.setSliderIcon(R.drawable.custom_icon);

You can also disable the rotation by setting the rotate_icon attribute to false.

complete_icon

You can set a custom complete icon by setting the complete_iconattribute to a drawable resource.

custom_complete_iconcon

app:complete_icon="@drawable/slidetoact_ic_check"

You can also set a custom complete icon programmatically with the provided setter.

SlideToActView sta = findViewById(R.id.slider);
sta.setCompleteIcon(R.drawable.custom_complete_animated);

slider_icon_color

You can set a custom color for the icon by setting the slider_icon_color attribute.

custom_icon

This attribute defaults to the outer_color if set. If outer_color is not set, this attribute defaults to colorAccent from your theme.

bump_vibration

You can make the device vibrate when the cursor "bumps" to the end of the sliding path by setting the period of vibration through bump_vibration attribute in your layout XML (default is 0)

app:bump_vibration="50"

Note that the period of vibration is in milliseconds

You can achieve the same programmatically using the setter:

SlideToActView sta = (SlideToActView) findViewById(R.id.slider);
sta.setBumpVibration(50);

In order for this feature to work, you need have the permission android.permission.VIBRATE in your AndroidManifest.xml

<uses-permission android:name="android.permission.VIBRATE"/>

android:elevation

Use the android:elevation attribute to set the elevation of the widget. The widgets will take care of providing the proper ViewOutlineProvider during the whole animation (a.k.a. The shadow will be drawn properly).

elevation_1 elevation_2

state_complete

Use state_complete attribute to create SlideToActView in complete state.

app:state_complete="true"

Can be also set programmatically.

With full slide animation:

SlideToActView sta = (SlideToActView) findViewById(R.id.slider);
sta.setCompleted(completed: true, withAnimation: true);

Without slide animation:

SlideToActView sta = (SlideToActView) findViewById(R.id.slider);
sta.setCompleted(completed: true, withAnimation: false);

complete

bounce_on_start

You can enable a bounce animation for the slider when the view is first rendered by setting the bounce_on_start attribute to true (default is false) Also you can set the duration of the bounce animation by setting the bounce_duration attribute (default is 2000) and repeat count by setting the bounce_repeat_count attribute (default is INFINITE)

bounce on start gif

Event callbacks

You can use the OnSlideCompleteListener and the OnSlideResetListener to simply interact with the widget. If you need to perform operations during animations, you can provide an OnSlideToActAnimationEventListener. With the latter, you will be notified of every animation start/stop.

You can try the Event Callbacks in the Demo app to better understand where every callback is called.

event_log

Demo ๐Ÿ“ฒ

Wonna see the widget in action? Just give a try to the Example App, it's inside the example folder.

Otherwise, you can just download the APK from a CircleCI build, and try it on a real device/emulator.

example_app gif

Building/Testing โš™๏ธ

CircleCI CircleCI

This projects is built with Circle CI. The CI environment takes care of building the library .AAR, the example app and to run the Espresso tests. Artifacts are exposed at the end of every build (both the .AAR and the .APK of the example app).

TravisCI Build Status

TravisCI builds are also running but they are considered Legacy. I'm probably going to dismiss it soon or later.

Building locally

Before building, make sure you have the following updated components from the Android SDK:

  • tools
  • platform-tools
  • build-tools-25.0.3
  • android-25
  • extra-android-support
  • extra-android-m2repository
  • extra-google-m2repository

Then just clone the repo locally and build the .AAR with the following command:

git clone [email protected]:cortinico/slidetoact.git
cd slidetoact/
./gradlew slidetoact:assemble

The assembled .AAR will be inside the slidetoact/build/outputs/aar folder.

Testing

Once you're able to build successfully, you can run Espresso tests locally with the following command.

./gradlew clean build connectedCheck 

Make sure your tests are all green โœ… locally before submitting PRs.

Contributing ๐Ÿค

Looking for contributors! Don't be shy. ๐Ÿ˜ Feel free to open issues/pull requests to help me improve this project.

  • When reporting a new Issue, make sure to attach Screenshots, Videos or GIFs of the problem you are reporting.
  • When submitting a new PR, make sure tests are all green. Write new tests if necessary.

Honorable mentions ๐ŸŽ–

License ๐Ÿ“„

This project is licensed under the MIT License - see the License file for details

More Repositories

1

kotlin-android-template

Android + Kotlin + Github Actions + ktlint + Detekt + Gradle Kotlin DSL + buildSrc = โค๏ธ
Kotlin
1,707
star
2

kotlin-gradle-plugin-template

๐Ÿ˜ A template to let you started with custom Gradle Plugins + Kotlin in a few seconds
Kotlin
455
star
3

ktfmt-gradle

A Gradle plugin to apply ktfmt to your builds, and reformat you Kotlin source code like a glimpse ๐Ÿงน๐Ÿ˜
Kotlin
149
star
4

kscript-template

๐Ÿ“œ Get started with kscript in a few seconds... with colored logs, github actions and more!
Kotlin
35
star
5

myonnaise

๐Ÿฏ A RxJava library to access Raw EMG data from your Myo ๐Ÿ“ˆ (plus an Android companion App ๐Ÿ“ฑ)
Kotlin
29
star
6

tech-conferences-italy

A community-curated list of conferences around Italy ๐Ÿ‡ฎ๐Ÿ‡น
HTML
26
star
7

rules4android

A collection of JUnit 4 Rules for Android Developers ๐Ÿ”ฌ
Kotlin
25
star
8

thebakery

Website for The Developers' Bakery Podcast ๐Ÿ‘จโ€๐Ÿณ
HTML
25
star
9

alfred-looks

โ•ฐ(โ—•ใƒฎโ—•)ใคยค=[]โ€”โ€”โ€” A collection of Alfred 4 snippets from looks.wtf (โŒโ– _โ– )
Kotlin
9
star
10

telebot

A Telegram Bot skeleton written in Go (a.k.a. your bot in 20 lines)
Go
7
star
11

cortinico.github.io

Just my personal website โœˆ๏ธ
JavaScript
6
star
12

mno-notes

Public repository of MNO students' notes (University of Pisa)
TeX
5
star
13

adventofcode-2020

๐ŸŽ… Marry XMas ๐ŸŽ„ Kotlin solutions for my Advent of Code 2020 ๐Ÿคถ
Kotlin
5
star
14

adventofcode-2021

๐ŸŽ… Marry XMas ๐ŸŽ„ Kotlin solutions for my Advent of Code 2021 ๐Ÿคถ
Kotlin
5
star
15

space-unlimited-space

๐Ÿ“ฆ Unleash the power of Github Container Registry to store artifacts and consume them auth-free.
5
star
16

docker-redex

Docker file for Facebook ReDex container (zip your apks inside a container)
M4
4
star
17

gulp-letsencrypt

Slides of letsencrypt seminar - 2016 GULP (Pisa Linux User Group)
TeX
4
star
18

docker-java8-32bit

Dockerfile for creating a 32bit containter and Java8 JRE
3
star
19

p2p-gossipico

A simulation of Gossipico with Peersim - Final assignment of P2P course (unipi)
TeX
3
star
20

reproducer-grammarly-textinput

Reproducer for ANR on Samsung devices with Grammarly integration
Kotlin
3
star
21

p2p-pingpong

A simulation of Gnutella Ping Pong protocol - 1st assignment of P2P course (unipi)
Java
2
star
22

cortinico

2
star
23

adventofcode-2022

๐ŸŽ… Marry XMas ๐ŸŽ„ Kotlin solutions for my Advent of Code 2022 ๐Ÿคถ
Kotlin
2
star
24

sol-cars

A simple system for car sharing - Final project of operting system course SOL (unipi)
C
2
star
25

android-beginners-material

A list of material for wannabe Android developers
2
star
26

telebotgae

A Telegram Bot skeleton written in Go with App Engine super powers (deploy in several seconds!)
Go
2
star
27

repro-36296

Reproducer for https://github.com/facebook/react-native/issues/36296
Java
2
star
28

adventofcode-2023

๐ŸŽ… Marry XMas ๐ŸŽ„ Kotlin solutions for my Advent of Code 2023 ๐Ÿคถ
Kotlin
2
star
29

RnReproducer32595

Java
1
star
30

reproducer-rnscreens-bridgeless

Kotlin
1
star
31

gulp-raspi

Slides del seminario del Linux Day 2014 Pisa su Raspberry Pi
TeX
1
star
32

reproducer-strictmodeviolation

Reproducer for https://issuetracker.google.com/issues/270704908
Kotlin
1
star
33

ae-drisc

A DRISC intrepreter written in OCaml - Course of System Architecture AE (unipi)
OCaml
1
star
34

reproducer-private-maven-repo

TypeScript
1
star
35

reproducer-cxx-tm-autolinking

Example on how to use C++ TurboModules with Autolinking on Android
Ruby
1
star