A widget you can slide it to open or close something

Related tags

Button SlideSwitch
Overview

SlideSwitch

About SlideSwitch

A button that you can slide on or off

How to import into your project

Android Studio

use gradle.

Gradle dependency:

Add the below codes in the module gradle file, which module use this widget.

compile 'com.leaking.slideswitch:slideswitch:1.0.0'

Add the below codes in you project gradle file

allprojects {
    repositories {
        jcenter()
        maven {
            url 'https://dl.bintray.com/leaking/maven'
        }
    }
}

Eclipse

import it as a library project.

How to use it

you can define a slideswitch in xml like the following example

    <com.leaking.slideswitch.SlideSwitch
        android:layout_width="100dip"
        android:layout_height="120dip"
        slideswitch:isOpen="false"
        slideswitch:shape="circle"
        slideswitch:themeColor="#f200aa96" >
    </com.leaking.slideswitch.SlideSwitch>

you can initial the state(on or off) in jave code in this way

	bulletSwitch.setState(true);

and you can listen to the change of the slideswitch like this

    updateSwitch.setSlideListener(new SlideListener() {

            @Override
            public void open() {
                // Do something ,,,
            }

            @Override
            public void close() {
                // Do something ,,,
            }
        });

you even can forbid the widget to change its state(open or close) like this

    slide.setSlideable(false);
    slide.setSlideable(true);

What does it look like

##Author

Quinn Chen

[email protected]

LICENSE

Copyright 2015 Quinn Chen

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.

Comments
  • 提个建议

    提个建议

    在moveToDest方法里面判断手势回调时增加当前状态的判断,如果当前是open状态,则继续重复右滑就不在回调,反之亦然。

    public void moveToDest(final boolean toRight) {
            final Handler handler = new Handler() {
                @Override
                public void handleMessage(Message msg) {
                    if (msg.what == 1) {
                        listener.open();
                    } else {
                        listener.close();
                    }
                }
            };
            new Thread(new Runnable() {
                @Override
                public void run() {
                    if (toRight) {
                        while (frontRect_left <= max_left) {
                            alpha = (int) (255 * (float) frontRect_left / (float) max_left);
                            invalidateView();
                            frontRect_left += 3;
                            try {
                                Thread.sleep(3);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                        }
                        alpha = 255;
                        frontRect_left = max_left;
                        if (!isOpen) {
                            isOpen = true;
                            if (listener != null)
                                handler.sendEmptyMessage(1);
                            frontRect_left_begin = max_left;
                        }
                    } else {
                        while (frontRect_left >= min_left) {
                            alpha = (int) (255 * (float) frontRect_left / (float) max_left);
                            invalidateView();
                            frontRect_left -= 3;
                            try {
                                Thread.sleep(3);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                        }
                        alpha = 0;
                        frontRect_left = min_left;
                        if (isOpen) {
                            isOpen = false;
                            if (listener != null)
                                handler.sendEmptyMessage(0);
                            frontRect_left_begin = min_left;
                        }
                    }
                }
            }).start();
        }
    
    opened by zzy0990 3
  • Animation stops inside ScrollView

    Animation stops inside ScrollView

    Hi, thank you for sharing this widget, I really liked it. I was using it and making some particular adaptations when I encountered an issue. If I use the widget inside a ScrollView, starting the move to any side and then moving down or up, the ScrollView intercepts the MotionEvent and the switch stops the animation in the middle.

    I found a solution and I want to share with you. When ScrollView handle the event, its children Views triggers the MotionEvent ACTION_CANCEL. So I copied the code inside inside ACTION_UP (line 188) and added another case ACTION_CANCEL, like this:

           <rest of code> ...
    
                break;
            case MotionEvent.ACTION_MOVE:
                eventMovingY = (int) event.getY();
                diffY = eventMovingY - eventStartY;
    
                eventLastX = (int) event.getRawX();
                diffX = eventLastX - eventStartX;
                int tempX = diffX + frontRect_left_begin;
                tempX = (tempX > max_left ? max_left : tempX);
                tempX = (tempX < min_left ? min_left : tempX);
                if (tempX >= min_left && tempX <= max_left) {
                    frontRect_left = tempX;
                    alpha = (int) (255 * (float) tempX / (float) max_left);
                    invalidateView();
                }
    
                break;
            case MotionEvent.ACTION_UP:
                moveToDest(isToRight(event));
                break;
            case MotionEvent.ACTION_CANCEL:
                moveToDest(isToRight(event));
                break;
            default:
                break;
        }
    
    private boolean isToRight(MotionEvent event) {
        int wholeX = (int) (event.getRawX() - eventStartX);
        frontRect_left_begin = frontRect_left;
        boolean toRight;
        toRight = (frontRect_left_begin > max_left / 2 ? true : false);
        if (Math.abs(wholeX) < 3) {
            toRight = !toRight;
        }
        return toRight;
    }
    

    I'm sorry for my english and thank you again!

    opened by rafaelneiva 2
  • The background doesn't show as expected when I set it to circle.

    The background doesn't show as expected when I set it to circle.

    When you set RIM_SIZE larger, you will find it obviously.

    The radius of the background rounded rectangle maybe not big enough.

    I found this problem due to this code in onDraw method:

    radius = backRect.height() / 2 - RIM_SIZE;
    

    Maybe you should remove the RIM_SIZE.

    opened by Lee-swifter 0
  • Memory leak

    Memory leak

    OOM exception -> drag the slider one way, then back again. The app will crash. I can reproduce this 100%. Commenting out line 205 moveToDest(toRight) stops the OOM. However leaves the functionality undesirable as the thumb can be left in whatever position you left it in.

    opened by serenskye 0
  • Add Percentage Offset attribute

    Add Percentage Offset attribute

    The percentage offset attribute allows the user control of the slider switch to be drawn as a percentage of the overall control.

    The valid values for this attribute are floats greater than 0 and less than 1.

    opened by ed-george 0
Owner
Quinn
Quinn
Circle button widget for Android

DEPRECATED This library is deprecated and no new development is taking place. Consider using a FAB(Floating action button) instead. E.g. the Android D

Markus Hintersteiner 1.5k Dec 9, 2022
ToggleButton Widget For Android Dev

ToggleButton ToggleButton Widget For Android Developers @Deprecated !!!项目已经停止维护,新项目移至https://github.com/zcweng/SwitchButton !!! How To Use xml

suke 2.1k Dec 19, 2022
⭐️ beautiful switch widget with sticky animation ⭐️

StickySwitch StickySwitch library for android this library is beautiful switch widget with sticky animation Requirements Android SDK 15+ Usage Add it

GwonHyeok 767 Dec 6, 2022
Sometimes, we need to show a label above an ImageView or any other views. Well, LabelView will be able to help you. It's easy to implement as well!

LabelView Sometimes, we need to show a label above an ImageView or any other views. Well, LabelXXView will be able to help you. It's easy to implement

Jingwei 1.9k Dec 6, 2022
comtomize view submit button which you use for submit operation or download operation and so on.

This is library project with a custom view that implements concept of Submit Button (https://dribbble.com/shots/1426764-Submit-Button?list=likes&offse

ZhangLei 129 Feb 5, 2021
SquircleView is a library which provides you with Squircle views to use for buttons, views, etc.

SquircleView is a library which provides you with Squircle views to use for buttons, views, etc.

Juky 96 Dec 15, 2022
A multicard menu that can open and close with animation on android

MultiCardMenu A multicard menu that can open and close with animation on android,require API level >= 11 Demo ##Usage <net.wujingchao.android.view.

null 562 Nov 10, 2022
An Android library that allows you to easily create applications with slide-in menus. You may use it in your Android apps provided that you cite this project and include the license in your app. Thanks!

SlidingMenu (Play Store Demo) SlidingMenu is an Open Source Android library that allows developers to easily create applications with sliding menus li

Jeremy Feinstein 11.1k Dec 27, 2022
An Android library that allows you to easily create applications with slide-in menus. You may use it in your Android apps provided that you cite this project and include the license in your app. Thanks!

SlidingMenu (Play Store Demo) SlidingMenu is an Open Source Android library that allows developers to easily create applications with sliding menus li

Jeremy Feinstein 11.1k Dec 21, 2022
A simple 'Slide to Unlock' Material widget for Android, written in Kotlin 📱🎨🦄

Slide To Act A simple Slide to Unlock Material widget for Android, written in Kotlin ??. Getting Started Example Features Attributes area_margin inner

Nicola Corti 984 Jan 2, 2023
A simple 'Slide to Unlock' Material widget for Android, written in Jetpack Compose

SlideTodo A simple 'Slide to Unlock' Material widget for Android, written in Jetpack Compose you can find source code here Getting Started allprojects

Nthily 7 Aug 8, 2022
Android library which allows you to swipe down from an activity to close it.

Android Sliding Activity Library Easily create activities that can slide vertically on the screen and fit well into the Material Design age. Features

Jake Klinker 1.3k Nov 25, 2022
Android library which allows you to swipe down from an activity to close it.

Android Sliding Activity Library Easily create activities that can slide vertically on the screen and fit well into the Material Design age. Features

Jake Klinker 1.3k Nov 25, 2022
Toster - Small test dsl based on adb commands that allows you to test the mobile application close to user actions

toster Small test dsl based on adb commands that allows you to test the mobile a

Alexander Kulikovskiy 31 Sep 1, 2022
Slide is an open sourced, ad free Reddit browser for Android

Slide Slide is an open source, ad free Reddit browser for Android. It is based around the Java Reddit API Wrapper. Slide is available on the Google Pl

Carlos Crane 1.7k Jan 9, 2023
Slide is an open sourced, ad free Reddit browser for Android

Slide Slide is an open source, ad free Reddit browser for Android. It is based around the Java Reddit API Wrapper. Slide is available on the Google Pl

Carlos Crane 1.7k Dec 27, 2022
Simple library which enable you to add a drawer(slide-out) navigation to your android application

SimpleSideDrawer is an android library to add a drawer navigation into your android application. This library has high affinity with other libraries l

null 217 Nov 25, 2022
*** WARNING: This library is no longer maintained *** An easy way to add a simple 'swipe-and-do-something' behavior to your `RecyclerView` items. Just like in Gmail or Inbox apps.

SwipeToAction An easy way to add a simple 'swipe-and-do-something' behavior to your RecyclerView items. Just like in Gmail or Inbox apps. Integration

Victor Calvello 223 Nov 16, 2022
A SeekBar suited for showing a preview of something. As seen in Google Play Movies.

PreviewSeekBar A SeekBar suited for showing a video preview. As seen in Google Play Movies Google Play Movies PreviewSeekBar's sample Build Add the fo

Rúben Sousa 3.3k Jan 3, 2023