Coder Social home page Coder Social logo

guilhe / seekbarrangedview Goto Github PK

View Code? Open in Web Editor NEW
63.0 2.0 15.0 2.72 MB

A SeekBarView restrained by a minimum and maximum value.

Home Page: https://guilhe.github.io/SeekbarRangedView

License: Apache License 2.0

Kotlin 100.00%
android seekbar-android android-view seekbar-ranged androidx android-stepsview

seekbarrangedview's Introduction

SeekbarRangedView

Android Arsenal Preview-Appetize.io

A SeekBar restrained by a minimum and maximum value.

Back in 2014 I contributed to this project by adding a few functionalities to RangeSeekBar.java. The repo had no activity since then, so I've decided to extend it and continue. Credits must be shared with Nick Knudson ;)

Installation

SeekbarRangedView is distributed through Maven Central and Jitpack.

implementation 'com.github.guilhe:seekbar-ranged-view:${LATEST_VERSION}'

Maven Central

Usage

Check out the sample module where you can find a few examples of how to create it by xml or java.

Attributes accepted in xml:

<resources>
        <attr name="min" format="float"/>
        <attr name="max" format="float"/>
        <attr name="currentMin" format="float"/>
        <attr name="currentMax" format="float"/>
        <attr name="rounded" format="boolean"/>
        <attr name="backgroundColor" format="color"/>
        <attr name="backgroundHeight" format="dimension"/>
        <attr name="progressColor" format="color"/>
        <attr name="progressHeight" format="dimension"/>
        <attr name="thumbsResource" format="reference"/>
        <attr name="thumbNormalResource" format="reference"/>
        <attr name="thumbPressedResource" format="reference"/>
</resources>

Example:

<com.github.guilhe.views.SeekBarRangedView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        custom:currentMin="10"
        custom:backgroundColor="#C0C0C0"
        custom:progressColor="@color/progress_bar_line"
        custom:backgroundHeight="10dp"
        custom:progressHeight="20dp"
        custom:rounded="true"/>

For android:layout_height you should use "wrap_content":

Sample1

otherwise you'll be adding "margins" to your view (ex, android:layout_height="200dp"):

Sample2

If you want to change its height, use the backgroundHeight and/or progressHeight attributes instead:

Sample3

There are many methods to help you customize this View by code. For more details checkout the sample app, javadocs or the code itself.

Sample

Sample

Animation last update on September, 2020

Get it on Google Play

Dependencies

Bugs and Feedback

For bugs, questions and discussions please use the Github Issues.

LICENSE

Copyright (c) 2017-present, GuilhE.

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.

seekbarrangedview's People

Contributors

gdelgadobliss avatar guilhe avatar sapuglha avatar

Stargazers

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

Watchers

 avatar  avatar

seekbarrangedview's Issues

Unable to use XML drawables for thumbs

I you try to use an XML defined drawable as the thumb image, it fails with an NPE.

To work around this, I am currently converting my Drawable to a bitmap and then setting it. It would be nice if I could just specify the Drawable in the XML layout instead.

    filter_slider.setThumbsImage(getBitmap(requireContext(), R.drawable.slider_thumb))    /**

    fun getBitmap(context: Context, drawableResourceId: Int): Bitmap? {
        val drawable = AppCompatResources.getDrawable(context, drawableResourceId)
        return if (drawable == null) {
            null
        } else {
            val canvas = Canvas()
            val bitmap = Bitmap.createBitmap(drawable.intrinsicWidth, drawable.intrinsicHeight, Bitmap.Config.ARGB_8888)
            canvas.setBitmap(bitmap)
            drawable.setBounds(0, 0, drawable.intrinsicWidth, drawable.intrinsicHeight)
            drawable.draw(canvas)
            bitmap
        }
    }
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="oval">
            <size
                android:width="32dp"
                android:height="32dp" />
            <solid android:color="@color/blue" />
        </shape>
    </item>
    <item>
        <shape android:shape="oval">
            <size
                android:width="32dp"
                android:height="32dp" />
            <solid android:color="@color/white" />
            <stroke
                android:width="12dp"
                android:color="@android:color/transparent" />
        </shape>
    </item>
</layer-list>

Block overlap of Min and Max value at certain place

Is your feature request related to a problem? Please describe.

min in 100 and max in 500
when i scroll, min can reach to 500 and max can reach to 100 on sliding

Describe the solution you'd like

considering above case if the diff between min and max selection should to 100.
that is is min is 100 and max in 400 , when i slide min head it should stop at 300 after 300 min should not slide in similar way.

if max in 400 and min is 100 when i scroll/move max head it should stop at 200 so that difference between min max should be 100

Describe alternatives you've considered

A clear and concise description of any alternative solutions or features you've considered.

Additional context

Help me to achieve this enchantment.

Current min max

how to set current max min in java side
setSelectedValue not working

No virtual method getColor()

I'd like to report a bug that occured for Android 5 (motorola Moto X (1st Gen)) when using
setProgressColorResource

java.lang.NoSuchMethodError: No virtual method getColor(I)I in class Landroid/content/Context; or its super classes (declaration of 'android.content.Context' appears in /system/framework/framework.jar)
at com.github.guilhe.views.SeekBarRangedView.setProgressColorResource + 460(SeekBarRangedView.java:460)

Context.getColor(int) method is from SDK 23 so please switch to ContextCompat.getColor(this, colorId) :)

NullPointerException

When i use the custom:thumbsResource, i get a null pointer exception in the SeekBarRangedView class

Cast exception on onSaveInstanceState and onRestoreInstanceState

I have a screen with the component, rotate it and there is this exception.

W/Bundle: Attempt to cast generated internal exception:
    java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.Float
        at android.os.BaseBundle.getFloat(BaseBundle.java:1104)
        at android.os.Bundle.getFloat(Bundle.java:834)
        at android.os.BaseBundle.getFloat(BaseBundle.java:1086)
        at android.os.Bundle.getFloat(Bundle.java:821)
        at com.github.guilhe.rangeseekbar.SeekBarRangedView.onRestoreInstanceState(SeekBarRangedView.java:834)
        at android.view.View.dispatchRestoreInstanceState(View.java:18608)
        at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:3827)
        at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:3827)
        at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:3827)
        at android.view.View.restoreHierarchyState(View.java:18586)
        at androidx.fragment.app.Fragment.restoreViewState(Fragment.java:576)
        at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1349)
        at androidx.fragment.app.FragmentManager.moveFragmentToExpectedState(FragmentManager.java:1686)
        at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1750)
        at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:3074)
        at androidx.fragment.app.FragmentManager.dispatchActivityCreated(FragmentManager.java:3028)
        at androidx.fragment.app.Fragment.performActivityCreated(Fragment.java:2693)
        at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1346)
        at androidx.fragment.app.FragmentManager.moveFragmentToExpectedState(FragmentManager.java:1686)
        at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1750)
        at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:3074)
        at androidx.fragment.app.FragmentManager.dispatchActivityCreated(FragmentManager.java:3028)
        at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:247)
        at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:541)
        at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:201)
        at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1391)
        at android.app.Activity.performStart(Activity.java:7157)
        at android.app.ActivityThread.handleStartActivity(ActivityThread.java:2937)
        at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:180)
        at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:165)
        at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:142)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

W/Bundle: Key MAX expected Float but value was a java.lang.Double.  The default value 0.0 was returned.
W/Bundle: Attempt to cast generated internal exception:
    java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.Float
        at android.os.BaseBundle.getFloat(BaseBundle.java:1104)
        at android.os.Bundle.getFloat(Bundle.java:834)
        at android.os.BaseBundle.getFloat(BaseBundle.java:1086)
        at android.os.Bundle.getFloat(Bundle.java:821)
        at com.github.guilhe.rangeseekbar.SeekBarRangedView.onRestoreInstanceState(SeekBarRangedView.java:835)
        at android.view.View.dispatchRestoreInstanceState(View.java:18608)
        at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:3827)
        at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:3827)
        at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:3827)
        at android.view.View.restoreHierarchyState(View.java:18586)
        at androidx.fragment.app.Fragment.restoreViewState(Fragment.java:576)
        at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1349)
        at androidx.fragment.app.FragmentManager.moveFragmentToExpectedState(FragmentManager.java:1686)
        at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1750)
        at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:3074)
        at androidx.fragment.app.FragmentManager.dispatchActivityCreated(FragmentManager.java:3028)
        at androidx.fragment.app.Fragment.performActivityCreated(Fragment.java:2693)
        at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1346)
        at androidx.fragment.app.FragmentManager.moveFragmentToExpectedState(FragmentManager.java:1686)
        at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1750)
        at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:3074)
        at androidx.fragment.app.FragmentManager.dispatchActivityCreated(FragmentManager.java:3028)
        at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:247)
        at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:541)
        at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:201)
        at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1391)
        at android.app.Activity.performStart(Activity.java:7157)
        at android.app.ActivityThread.handleStartActivity(ActivityThread.java:2937)
        at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:180)
        at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:165)
        at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:142)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

The block of code saves a double and tries to restore a float. Shouldn't it be the same type on save and on restore?

    @Override
    protected Parcelable onSaveInstanceState() {
        final Bundle bundle = new Bundle();
        bundle.putParcelable("SUPER", super.onSaveInstanceState());
        bundle.putDouble("MIN", mNormalizedMinValue);
        bundle.putDouble("MAX", mNormalizedMaxValue);
        return bundle;
    }

    @Override
    protected void onRestoreInstanceState(Parcelable parcel) {
        final Bundle bundle = (Bundle) parcel;
        super.onRestoreInstanceState(bundle.getParcelable("SUPER"));
        mNormalizedMinValue = bundle.getFloat("MIN");
        mNormalizedMaxValue = bundle.getFloat("MAX");
        onChangedValues();
        onChangingValues();
    }

CHANGELOG

Hey, I really like the lib and I use it on production ! :)

Could you indicate some changelog? What changed in version 2.0.3 e.g. ?

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.