All Projects → BeppiMenozzi → Tristatetogglebutton

BeppiMenozzi / Tristatetogglebutton

Customizable tri-state toggle button (with three states, three state toggle) for Android

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Tristatetogglebutton

MGS.Electronics
Unity plugin for make button switch, knob switch and rocker element in scene.
Stars: ✭ 12 (-93.94%)
Mutual labels:  button, switch
Materialfavoritebutton
Animated favorite/star/like button
Stars: ✭ 586 (+195.96%)
Mutual labels:  android-ui, button
Examples Win32
Shows how to use Win32 controls by programming code (c++17).
Stars: ✭ 22 (-88.89%)
Mutual labels:  button, radio-buttons
btns
A collection of buttons with cool hover effects
Stars: ✭ 78 (-60.61%)
Mutual labels:  button, buttons
Fillingbutton
🔥Replace typical onLongClickListener with this library!
Stars: ✭ 31 (-84.34%)
Mutual labels:  android-ui, button
AMChoice
Radio Button and check box for iOS
Stars: ✭ 45 (-77.27%)
Mutual labels:  button, radio-buttons
Segmentedbutton
Segmented Control with animation for Android API 12+
Stars: ✭ 352 (+77.78%)
Mutual labels:  button, radio-buttons
PygameWidgets
A module for use with Pygame. Includes fully customisable buttons, textboxes, sliders and many more, as well as the ability to create and run animations on these widgets.
Stars: ✭ 34 (-82.83%)
Mutual labels:  buttons, switch
Iconswitch
🍭 Custom Android Switch widget
Stars: ✭ 874 (+341.41%)
Mutual labels:  switch, selector
Aiflatswitch
Nicely animated flat design switch alternative to UISwitch
Stars: ✭ 904 (+356.57%)
Mutual labels:  switch, button
Easybutton
Arduino library for debouncing momentary contact switches, detect press, release, long press and sequences with event definitions and callbacks.
Stars: ✭ 187 (-5.56%)
Mutual labels:  switch, button
Statebutton
一个可以用代码设置selector背景(按下去背景颜色更改,样式变化等等)的button, 再也不用写selector了
Stars: ✭ 1,276 (+544.44%)
Mutual labels:  button, selector
RevealLayout
揭示效果布局,可以指定2个子布局,以圆形揭示效果切换选中状态
Stars: ✭ 118 (-40.4%)
Mutual labels:  button, switch
homebridge-switcheroo
Simple on/off or multiswitch radio buttons for http reqs. Useful for lights, A/V systems, home automation, whatever
Stars: ✭ 38 (-80.81%)
Mutual labels:  radio-buttons, switch
react-native-radio-buttons-group
Simple, best and easy to use radio buttons for react native apps.
Stars: ✭ 145 (-26.77%)
Mutual labels:  button, radio-buttons
Jc button
Arduino library to debounce button switches, detect presses, releases, and long presses
Stars: ✭ 289 (+45.96%)
Mutual labels:  switch, button
Customfloatingactionbutton
This view is for replacement of standard Floating Action Button from Google Support Library. It is easy to use, customizable and you can also add text to button
Stars: ✭ 222 (+12.12%)
Mutual labels:  android-ui, button
liquid button
Liquify your buttons, web demo at website
Stars: ✭ 18 (-90.91%)
Mutual labels:  button, buttons
Vue Js Toggle Button
🍥 Vue.js 2 toggle / switch button - simple, pretty, customizable
Stars: ✭ 836 (+322.22%)
Mutual labels:  switch, button
Fitbutton
The button which can use with icon, text, divider, custom ripple effect, border, corner radius e.t.c.
Stars: ✭ 63 (-68.18%)
Mutual labels:  android-ui, button

TriState Toggle Button

A fully customizable and super-easy tri-state toggle button (switch button if you prefer) for Android, based on iOS look and feel. Can act with three independent states, or with two states like a standard checkbox, or with two states plus one undefined.


Android Arsenal

  • Out-of-the-box working 3-state toggle
  • Fully customizable and styleable
  • Can become a classic 2-state toggle returning booleans
  • Can become a 2.5-state toggle: on/off and an unselectable mid button
  • Can be enabled / disabled
  • Can be programmatically controlled
  • Works both with clicks and with swipes


Setup (Gradle)

In your project's build.gradle file:

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

In your Application's or Module's build.gradle file:

dependencies {
    ...
    compile 'com.github.BeppiMenozzi:TriStateToggleButton:1.1.4'
    ...
}

Setup (Eclipse)

Whaaaaat?

Minimal usage

Layout:

...
xmlns:app="http://schemas.android.com/apk/res-auto"
...
<it.beppi.tristatetogglebutton_library.TriStateToggleButton
        android:layout_width="80dp"
        android:layout_height="40dp"
        android:id="@+id/tstb_1"
 />

Listener:

...
TriStateToggleButton tstb_1 = (TriStateToggleButton) findViewById(R.id.tstb_1);
tstb_1.setOnToggleChanged(new TriStateToggleButton.OnToggleChanged() {
        @Override
        public void onToggle(TriStateToggleButton.ToggleStatus toggleStatus, boolean booleanToggleStatus, int toggleIntValue) {
            switch (toggleStatus) {
                case off: break;
                case mid: break;
                case on: break;
            }
        }
    });
...

Inside onToggle() you can use the ToggleStatus type values, or limit yourself to use booleans or integers (0, 1, 2) if you want it easy.

To have a two-states toggle button:

 <it.beppi.tristatetogglebutton_library.TriStateToggleButton
        android:layout_width="80dp"
        android:layout_height="40dp"
        android:id="@+id/tstb_1"
        app:tbIsMidSelectable="false"
 />

To have a two-states toggle button, with an undefined starting value:

 <it.beppi.tristatetogglebutton_library.TriStateToggleButton
        android:layout_width="80dp"
        android:layout_height="40dp"
        android:id="@+id/tstb_1"
        app:tbIsMidSelectable="false"
        app:tbDefaultStatus="mid"
 />

Browse the full example here: Example

Attributes description

List of attributes with description:

tbBorderWidth Width of the border of the widget
tdOffBorderColor Color of the width that appears with the button in state off. Used also for animations.
tbOffColor Color of the background of the toggle when off
tbMidColor Color of the background of the toggle with in mid position
tbOnColor Color of the background of the toggle when on
tbSpotColor Color of the handle of the toggle
tbAnimate True for animation
tbDefaultStatus Starting value for the toggle
tbIsMidSelectable If false, the toggle becomes a standard two-states toggle, but can still assume the mid value if forced programmatically or set as default
tbSwipeSensitivityPixels Number of pixels a swipe must travel to fire a toggle event. Default is 200. If set to zero, swipes are disabled

New in 1.1.3

  • Fixed: error drawing toggle in mid position when visibility passed from GONE to VISIBLE

New in 1.1.0

  • Added swipe gesture management together with normal click
  • Gradle update
  • More documentation

New in 1.0.5

  • Fixed: added super in setEnabled()

New in 1.0.4

  • Fixed: setting a boolean value programmatically sometimes didn't update status

New in 1.0.3

  • Toggle now can set and return integer values (0, 1, 2)
  • Warning: onToggle() changed to include integer values
  • Added static functions to convert from/to booleans and integers to/from toggleStatus

Used in

Credits

This project is strongly based on (and contains parts of code of) the very beautiful Toggle Button by zcweng.

Author

  • Beppi Menozzi

License

The MIT License (MIT)

Copyright (c) 2016 Beppi Menozzi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].