Socket
Book a DemoInstallSign in
Socket

one.xcorp.widget:swipe-picker

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

one.xcorp.widget:swipe-picker

A widget for Android that allows the user to enter different values, such as: time, date, number, without additional dialog windows using the swipe gestures.

Source
mavenMaven
Version
1.2.0
Version published
Maintainers
1
Source


License: MIT MinSdk: 14 write: Kotlin Download

SwipePicker - a widget for Android that allows the user to enter different values, such as: time, date, number, without additional dialog windows using the swipe gestures.

Setup

To use SwipePicker in your projects, simply add the library as a dependency to your module build.gradle.

Gradle
dependencies {
    implementation 'one.xcorp.widget:swipe-picker:1.2.0'
}
Maven
<dependency> 
    <groupId>one.xcorp.widget</groupId> 
    <artifactId>swipe-picker</artifactId> 
    <version>1.2.0</version> 
    <type>pom</type> 
</dependency>

Alternatively you can directly import the /swipepicker module or swipe-picker-1.2.0.aar file into your Android Studio project and add it as a dependency in your build.gradle.

Usage

SwipePicker can be added as a custom view to any layout. For more detailed code example to use the library, please refer to the /sample app.

 <one.xcorp.widget.swipepicker.SwipePicker
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="Hello"
        app:maxValue="10"
        app:minValue="1"
        app:value="5" />

You can then either set the xml parameters to configure the view or do it programmatically. You can also receive notifications of status changes:

 swipepicker.setOnStateChangeListener(object : SwipePicker.OnStateChangeListener {
            override fun onActivated(view: SwipePicker, isActivated: Boolean) {
                // called when view state is activated and show value.
            }
            override fun onPressed(view: SwipePicker, isPressed: Boolean) {
                // called when the user touches the view.
            }
            override fun onSelected(view: SwipePicker, isSelected: Boolean) {
                // called when the user activates keyboard input.
            }
        })

Or value changes:

swipepicker.setOnValueChangeListener(object : SwipePicker.OnValueChangeListener {
            override fun onValueChanged(view: SwipePicker, oldValue: Float, newValue: Float) {
                // is called when the value is changed.
            }
        })

You can also affect the currently displayed text for the value:

swipepicker.setValueTransformer(object : SwipePicker.ValueTransformer {
            override fun stringToFloat(view: SwipePicker, value: String): Float? {
                // convert the string to a value or in case of an error return
                // null in order not to disable the selection mode and leave
                // the keyboard active.
            }
            override fun floatToString(view: SwipePicker, value: Float): String? {
                // convert the value to a string, return null if you want
                // to display an empty value.
            }
        })

Finally, you can influence the calculation of values during the swipe gesture:

swipepicker.setScaleHandler(object : SwipePicker.ScaleHandler {
            override fun onStick(view: SwipePicker, value: Float): Float {
                // called when you want to stick a value to the scale,
                // return the value lying on the scale.
            }
            override fun onSwipe(view: SwipePicker, value: Float, division: Int): Float {
                // move from the specified value to the specified
                // number of divisions and return the result.
            }
        })

Customization

The following set of attributes is available to change the behavior of the swipe picker component:
NameTypeDescription
android:hintstringallows you to specify prompt text.
android:state_activatedbooleanallows you to specify the state of the component. In the active mode, the entered value is displayed and input is available by gesture.
allowDeactivatebooleanindicates whether the component can go into deactivate mode.
allowFlingbooleanallows you to enable/disable inertial scrolling gesture.
manualInputbooleanallows you to enable/disable free entry of values from the keyboard.
android:inputTypeflagallows you to specify the type for entering values from the keyboard. See description values on this link.
To control the behavior of the scale, use the following attributes:
NameTypeDescription
loopedbooleanallows you to enable/disable cycling of values on the scale. When the maximum value is reached, the motion starts again from the minimum to the maximum value and vice versa.
stickybooleanallows you to enable/disable the sticky scale. When the value is true, the user can specify only the values located on the scale.
scalereferencespecify an float array as a value. Use a scale with values when motion is required with non-uniform step. Above this scale, the movement continues with a fixed step.
anchorfloatspecifies a scale with a single value. Use when you want to have a fixed step relative to any value.
minValuefloatallows you to set a lower limit for a value.
maxValuefloatallows you to set the upper limit for the value.
stepfloatallows you to specify with which step to change the value when using a swipe gesture. Can be zero if only movement within the specified scale is necessary.
valuefloatspecify the initial value.
To change the style of a component, use the following attributes:
NameTypeDescription
android:minWidthdimensionallows you to specify minimum width for component.
android:maxLengthintegerallows you to set the maximum number of characters to display the value.
hintTextAppearancereferenceallows you to specify a style for the prompt text.
inputTextAppearancereferenceallows you to specify a style for the value text.
backgroundInputreference|colorlets you specify the color or image for the value input area.
backgroundInputTintcolorallows you to specify a color hue for the background image of the value input area.
backgroundInputTintModeenumallows you to specify the blending mode for the hue of the background image color. See description values on this link.
hoverViewStylestringallows you to specify a style for the pop-up value view.
To set the style of a pop-up window, use the following attributes:
NameTypeDescription
android:minWidthdimensionallows you to specify minimum width for pop-up value view.
android:paddingdimensionallows you to specify an indent for the pop-up value view.
android:textSizedimensionallows you to set the text size for the pop-up value.
android:textColorreference|colorallows you to set the text color for the pop-up value.
android:colorcolorallows you to set the background color for the pop-up value view.
colorTintstringallows you to set the background hue for the pop-up value view.

Demo

Download

Apps using the SwipePicker

Tell me if you're using my library in your application, I'll share it in this README.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

See also the list of contributors who participated in this project.

License

MIT License

Copyright (c) 2018 Dmitriy Makarov

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.

FAQs

Package last updated on 26 Jan 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts