{"id":23960968,"url":"https://github.com/davidmigloz/multi-state-switch","last_synced_at":"2025-04-13T10:08:00.378Z","repository":{"id":37017301,"uuid":"160809612","full_name":"davidmigloz/multi-state-switch","owner":"davidmigloz","description":"Android library that provides a multi state switch view.","archived":false,"fork":false,"pushed_at":"2022-06-29T17:14:28.000Z","size":7590,"stargazers_count":39,"open_issues_count":0,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-27T01:35:29.052Z","etag":null,"topics":["android","switch"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/davidmigloz.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-12-07T10:33:04.000Z","updated_at":"2025-01-12T04:28:55.000Z","dependencies_parsed_at":"2022-08-18T22:00:49.260Z","dependency_job_id":null,"html_url":"https://github.com/davidmigloz/multi-state-switch","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidmigloz%2Fmulti-state-switch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidmigloz%2Fmulti-state-switch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidmigloz%2Fmulti-state-switch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidmigloz%2Fmulti-state-switch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/davidmigloz","download_url":"https://codeload.github.com/davidmigloz/multi-state-switch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248695452,"owners_count":21146955,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","switch"],"created_at":"2025-01-06T19:58:33.304Z","updated_at":"2025-04-13T10:08:00.357Z","avatar_url":"https://github.com/davidmigloz.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Multi State Switch  [![](https://jitpack.io/v/davidmigloz/multi-state-switch.svg)](https://jitpack.io/#davidmigloz/multi-state-switch)\n\nAndroid library that provides a multi state switch view.\n\n![screenshot](docs/multi-state-switch.gif)\n\n## Usage\n\nTake a look at [the sample app](https://github.com/davidmigloz/multi-state-switch/tree/master/sample) to see a live example of the capabilities of the library.\n\n#### Step 1\n\nAdd the JitPack repository to your `build.gradle ` file:\n\n```gradle\nallprojects {\n\trepositories {\n\t\t...\n\t\tmaven { url \"https://jitpack.io\" }\n\t}\n}\n```\n\n#### Step 2\n\nAdd the dependency:\n\n```gradle\ndependencies {\n\tcompile 'com.github.davidmigloz:multi-state-switch:2.0.1'\n}\n```\n\n[CHANGELOG](https://github.com/davidmigloz/multi-state-switch/blob/master/CHANGELOG.md)\n\n#### Step 3\n\nUse `MultiStateSwitch` view in your layout:\n\n```xml\n\u003ccom.davidmiguel.multistateswitch.MultiStateSwitch\n    android:id=\"@+id/switch\"\n    ... /\u003e\n```\n\nAdd states:\n\n```kotlin\nswitch.addStatesFromStrings(listOf(\"One\", \"Two\", \"Three\"))\n```\n\nUse `StateStyle` to customize the style of the states:\n\n```kotlin\nswitch.addStateFromString(\n        \"Cold\",\n        StateStyle.Builder()\n                .withSelectedBackgroundColor(Color.BLUE)\n                .withDisabledTextColor(Color.WHITE)\n                .build()\n)\n```\n\nUse `State` object if you need to display different text depending on the state's state:\n\n```kotlin\nswitch.addState(\n    State(\n        text = \"ON\",\n        selectedText = \"OFF\",\n        disabledText = \"OFF\"\n    )\n)\n```\n\n#### Attributes\n\n- `app:multistateswitch_background_color=[color|reference]`\n- `app:multistateswitch_background_radius=[float|reference]`\n- `app:multistateswitch_text_color=[color|reference]`\n- `app:multistateswitch_text_size=[dimension|reference]`\n- `app:multistateswitch_selected_state_index=[integer|reference]`\n- `app:multistateswitch_selected_background_color=[color|reference]`\n- `app:multistateswitch_selected_text_color=[color|reference]`\n- `app:multistateswitch_selected_text_size=[dimension|reference]`\n- `app:multistateswitch_disabled_state_enabled=[boolean|reference]`\n- `app:multistateswitch_disabled_state_index=[integer|reference]`\n- `app:multistateswitch_disabled_background_color=[color|reference]`\n- `app:multistateswitch_disabled_text_color=[color|reference]`\n- `app:multistateswitch_disabled_text_size=[dimension|reference]`\n- `app:multistateswitch_max_number_states=[integer|reference]`\n\n#### API\n\n- `addState(state: State, stateStyle: StateStyle? = null)`: adds state to the switch.\n- `addStates(states: List\u003cState\u003e, stateStyles: List\u003cStateStyle\u003e? = null)`: adds states to the switch and the displaying styles. If you provide styles, you have to provide them for every state.\n- `addStateFromString(stateText: String, stateStyle: StateStyle? = null)`: adds state to the switch directly from a string. The text will be used for normal, selected and disabled state.\n- `addStatesFromStrings(statesTexts: List\u003cString\u003e, stateStyles: List\u003cStateStyle\u003e? = null)`: adds states to the switch directly from a string and the displaying styles. If you provide styles, you have to provide them for every state. The texts will be used for normal, selected and disabled states.\n- `replaceState(stateIndex: Int, state: State, stateStyle: StateStyle? = null)`: replaces state.\n- `replaceStateFromString(stateIndex: Int, stateText: String)`: replaces state directly from a string. The text will be used for normal, selected and disabled states.\n- `removeState(stateIndex: Int)`: removes an state.\n- `selectState(index: Int, notifyStateListeners: Boolean = true)`: selects state in given index. If `notifyStateListeners` is `true` all the listeners will be notified about the new selected state.\n- `getNumberStates(): Int`: returns number of states of the switch.\n- `setMaxNumberStates(maxNumberStates: Int)`: Sets the max number of states. If you try to add a new state but the number of states is already `maxNumberStates` the state will be ignored. By default is `-1` which means that there is no restriction. This parameter is also used to determine how many states to show in the editor preview. If it is set to no limit, `3` will be rendered by default, if not the number of states drawn will match `maxNumberStates`.\n- `getMaxNumberStates(): Int`: returns max number of states. By default is -1 which means that there is no restriction.\n- `hasMaxNumberStates(): Boolean`: checks whether there is a limit in the number of states or not.\n- `setTextTypeface(textTypeface: Typeface)`: sets typeface.\n- `setPadding(left: Int, top: Int, right: Int, bottom: Int)`\n\n\n#### Listener\n\nTo listen to state changes, you have to register a `StateListener`:\n\n```kotlin\nbinding.defaultSwitch.addStateListener { stateIndex, state -\u003e\n    // ...\n}\n```\n\n## Contributing\n\nIf you find any issues or you have any questions, ideas... feel free to [open an issue](https://github.com/davidmigloz/multi-state-switch/issues/new).\nPull request are very appreciated.\n\n## License\n\nCopyright (c) 2022 David Miguel Lozano\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\nhttp://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidmigloz%2Fmulti-state-switch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavidmigloz%2Fmulti-state-switch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidmigloz%2Fmulti-state-switch/lists"}