All Projects → Abushawish → MultiStateToggleButton

Abushawish / MultiStateToggleButton

Licence: other
Android's ToggleButton offers only two states, MultiStateToggleButton fixes this by offering as many states depending on the number of drawable resources passed in.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to MultiStateToggleButton

FigmaConvertXib
FigmaConvertXib is a tool for exporting design elements from figma.com and generating files to a projects iOS .xib / Android .xml
Stars: ✭ 111 (+455%)
Mutual labels:  view, xml
Expansionpanel
Android - Expansion panels contain creation flows and allow lightweight editing of an element.
Stars: ✭ 1,984 (+9820%)
Mutual labels:  view, toggle
Shapeofview
Give a custom shape to any android view, Material Design 2 ready
Stars: ✭ 2,977 (+14785%)
Mutual labels:  view, xml
Riot
Simple and elegant component-based UI library
Stars: ✭ 14,596 (+72880%)
Mutual labels:  simple, view
Kanvas
Make canvas easier to use in Kotlin 😊
Stars: ✭ 93 (+365%)
Mutual labels:  view, xml
css-toggle-component
Pure CSS Toggle Buttons as a Web component
Stars: ✭ 69 (+245%)
Mutual labels:  toggle, togglebutton
RegulatorView
Intelligent furniture remote control
Stars: ✭ 20 (+0%)
Mutual labels:  view
xast
Extensible Abstract Syntax Tree
Stars: ✭ 32 (+60%)
Mutual labels:  xml
kirby-blade
Enable Laravel Blade Template Engine for Kirby 3
Stars: ✭ 20 (+0%)
Mutual labels:  view
magic-api-spring-boot-starter
magic-api的spring-boot-starter版本
Stars: ✭ 30 (+50%)
Mutual labels:  xml
munich-scripts
Some useful scripts simplifying bureaucracy
Stars: ✭ 105 (+425%)
Mutual labels:  simple
php-unit-conversion
A library providing full PSR-4 compatible unit conversions
Stars: ✭ 47 (+135%)
Mutual labels:  states
onixcheck
ONIX validation library and commandline tool
Stars: ✭ 20 (+0%)
Mutual labels:  xml
granitic
Web/micro-services and IoC framework for Golang developers
Stars: ✭ 32 (+60%)
Mutual labels:  xml
ministaller
Lightweight installer/updater for portable desktop applications
Stars: ✭ 15 (-25%)
Mutual labels:  simple
simple-blog-engine-for-asp-net-core
A simple blog engine for ASP.NET Core developers.
Stars: ✭ 15 (-25%)
Mutual labels:  simple
react-native-responsive-image-view
React Native component for scaling an Image within the parent View
Stars: ✭ 152 (+660%)
Mutual labels:  view
spring-mvc3-javaconfig
A Java Spring MVC 3 app configured without XML. Also uses Servlet 3 API to bypass web.xml
Stars: ✭ 23 (+15%)
Mutual labels:  xml
fiet
Fiết is a RSS feed parser in Elixir, which focuses on extensibility, speed, and standard compliance
Stars: ✭ 23 (+15%)
Mutual labels:  xml
asl
A C++ cross-platform library including JSON, XML, HTTP, Sockets, WebSockets, threads, processes, logs, file system, CSV, INI files, etc.
Stars: ✭ 44 (+120%)
Mutual labels:  xml

MultiState Toggle Button

Android's ToggleButton offers only two states, MultiStateToggleButton fixes this by offering as many states depending on the number of drawable resources passed in.

Including in your project

compile 'ca.abushawish.multistatetogglebutton:multistatetogglebutton:1.0'

Check here for the latest Releases.

Usage

Create an integer-array of drawable resource IDs in your arrays.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <integer-array name="flash_images_array">
        <item>@drawable/ic_flash_auto_black_24px</item>
        <item>@drawable/ic_flash_on_black_24px</item>
        <item>@drawable/ic_flash_off_black_24px</item>
    </integer-array>
</resources>

Then, in your layout file, add the 'MultiStateToggleButton' with the 'app:drawable_resource_list' attribute and the reference to the above created integer-array as it's value.

<ca.abushawish.multistatetogglebutton.MultiStateToggleButton
            android:id="@+id/mstb_sample_button"
            android:layout_width="@dimen/mstib_size_30"
            android:layout_height="@dimen/mstib_size_30"
            android:background="@android:color/transparent"
            app:drawable_resource_list="@array/flash_images_array"/>

Alternativaly, programatically:

Initialize the MultiStateToggleButton and populate a List<Integer> of your drawable resource IDs.

private MultiStateToggleButton mMultiStateToggleButton = (MultiStateToggleButton) findViewById(R.id.mstb_sample_button);

private List<Integer> mDrawableResourceIDs; = new ArrayList<>();
mDrawableResourceIDs.add(R.drawable.ic_filter_1_black_24px);
mDrawableResourceIDs.add(R.drawable.ic_filter_2_black_24px);
...
mDrawableResourceIDs.add(R.drawable.ic_filter_7_black_24px);

Then, set the populated drawable resource ID list to the multiStateToggleButton object as so:

mMultiStateToggleButton.setDrawableResourceList(mDrawableResourceIDs);

Implement the MultiStateToggleButton.OnStateChangeListener.

public class SampleActivity extends Activity implements MultiStateToggleButton.OnStateChangeListener{

    ...

    @Override
    public void onStateChanged(View view, int newState) {
        switch (view.getId()) {
            case R.id.mstb_sample_button:
                // Do something on state changed or with the int newState
                break;
        }
    }
}

Developed By

Moe Abushawish

License

Copyright 2017 Mohammed Abushawish

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.
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].