Code Monkey home page Code Monkey logo

rotary-seekbar's Introduction

RotarySeekbar

RotarySeekbar (aka. a knob) is an interactive View for Android that upon touch enlarges the view (overlay zooming) thus making it easy to adjust the value of the knob while actually seeing what you are doing. The view responds to any touch within its' bounds, i.e. not relying on a precise touch of a tiny knob handle widget (c.f. Fitt's law). The rotation of the knob is based on amplifying the finger movement based on the distance from the center of the knob, giving the user both fine and coarse control of the value selection. The overlay zooming and movement amplification makes it possible to put compact rotary seekbars (e.g. 48dp x 48dp) in your gui, while still providing sufficient visual feedback and control granularity to the end user.

Usage

  • Step 1. Add jitpack to your root build.gradle, at the end of the repositories list:

    allprojects {
        repositories {
            ...
        maven { url 'https://jitpack.io' }
        }
    }
    
  • Step 2. Add the dependency

    dependencies {
        // either choose a release (TAG) from github:
        implementation 'com.github.akapelrud:Rotary-Seekbar:TAG'
    // where TAG = 'vMajor.Minor,Micro'
    
        // or use the current HEAD of a branch e.g. branch:
        // implementation 'com.github.akapelrud:Rotary-Seekbar:master-SNAPSHOT'
        // implementation 'com.github.akapelrud:Rotary-Seekbar:develop-SNAPSHOT'
    }
    
  • Step 3. Make sure that your app theme is based on one of the material design themes, e.g. values/styles.xml:

    <style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryVariant">@color/colorPrimaryVariant</item>
        <item name="colorOnPrimary">@color/colorOnPrimary</item>
        <item name="colorSecondary">@color/colorSecondary</item>
        <item name="colorSecondaryVariant">@color/colorSecondaryVariant</item>
        <item name="colorOnSecondary">@color/colorOnSecondary</item>
    </style>
    
  • Step 4. Add the RotarySeekbar to your layout file, c.f. the attribute definition and the demo app's layout file: DEMO layout

  • Step 5. Implement the RotarySeekbar.OnValueChangeListener interface, and register using setOnValueChangeListener().

    public interface OnValueChangedListener {
        void onValueChanged(RotarySeekbar sourceSeekbar, float value);
    }
    

Example

The first image shows the demo application with 16 differently styled RotarySeekbars. All of these have been customized through the .xml layout file.

Pressing either of the widgets will enlarge the view of the component, making it easier to choose a value while still having the component visible.

rotary-seekbar's People

Contributors

akapelrud avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

solunadigital

rotary-seekbar's Issues

numSteps attr is weird

For instance, if minValue=0 and maxValue=10 and numSteps=10, the selectable values become `[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10].

If, on the other hand, we choose numSteps=11, we would get 12 possible values to select from in the range [0, 10]

Consider replacing this attribute with a numValues>=2 attribute.

Fix shape around zoomed view

The current outline of the zoomed view (rounded rectangle, with 4dp stroked border) doesn't look that good. I think Rotary-Seekbar should strive towards fulfilling certain aspects of the material design paradigm. Thus, add dropshadow using elevation and maybe a custom outline shape/drawable that better defines the view.

Map display value to hidden range

For instance, the seekbar shows the range [a,b] in N steps within the range [c,d]. Let the user retrieve either the value or the current mapped number.

Needle min radius

Current needle always starts in the center. Add an attribute for setting the minimum radius.

attributes naming is inconsistent

Some of the xml attributes are camelCased while others are snake_cased. We should adapt the same formatting as the standard android views' attributes.

Margin between value text and knob

When valuePosition==bottom or valuePosition==top and sector_openAngle is small, then the ticks or sector might touch/kiss the value text.

Error inflating class

Added the repo to gradle and the implementation as implementation 'com.github.akapelrud:Rotary-Seekbar:v1.0.0'. Copy-pasted any one of the 16 controls from your example XML and on build I get :

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ca13b.blackdroid/com.ca13b.blackdroid.MainActivity}: android.view.InflateException: Binary XML file line #13: Binary XML file line #13: Error inflating class no.kapelrud.RotarySeekbar
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6494)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
     Caused by: android.view.InflateException: Binary XML file line #13: Binary XML file line #13: Error inflating class no.kapelrud.RotarySeekbar
     Caused by: android.view.InflateException: Binary XML file line #13: Error inflating class no.kapelrud.RotarySeekbar
     Caused by: java.lang.reflect.InvocationTargetException

SDK: 29

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.