Android Question Problem with ValueBar 1.0.1

bigbadfred

Member
Licensed User
Longtime User
Hi,

I love DonManFred's work and stumbled on this beauty:
https://www.b4x.com/android/forum/threads/valuebar-v1-0-1.51584/#content

All is working well, BUT, the valuebar refuses to show decimals.
If you program it to show decimals, it will, as well as the min en max values.
But, as soon as you start sliding, the decimal is thrown over board ;-)
I think it's a bug in either the original library, or in the port to b4a.
I think the culprit is the interval property.
If you position your cursor over the interval keyword, it will show you 'Invalid description'.
If you do the same during debugging, it shows you:'Error: Property: Interval is writeonly'

Can anybody help me with that?
I used the original examples, which show the problem, and if you have a look at the videos, you can see it as well.
Thanx.
 

MarcoRome

Expert
Licensed User
Longtime User
Hi,

I love DonManFred's work and stumbled on this beauty:
https://www.b4x.com/android/forum/threads/valuebar-v1-0-1.51584/#content

All is working well, BUT, the valuebar refuses to show decimals.
If you program it to show decimals, it will, as well as the min en max values.
But, as soon as you start sliding, the decimal is thrown over board ;-)
I think it's a bug in either the original library, or in the port to b4a.
I think the culprit is the interval property.
If you position your cursor over the interval keyword, it will show you 'Invalid description'.
If you do the same during debugging, it shows you:'Error: Property: Interval is writeonly'

Can anybody help me with that?
I used the original examples, which show the problem, and if you have a look at the videos, you can see it as well.
Thanx.
Dont worry . Don will answer you soon
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
All is working well, BUT, the valuebar refuses to show decimals.
It is able....

ValueBar.png

But you are right when saying
But, as soon as you start sliding, the decimal is thrown over board ;-)

This is the code from the 3rd party jar
B4X:
   @Override
    public boolean onTouchEvent(MotionEvent e) {
        if (mTouchEnabled) {

            if (mSelectionListener == null)
                Log.w("ValueBar",
                        "No SelectionListener specified. Use setSelectionListener(...) to set a listener for callbacks when selecting values.");

            // if the detector recognized a gesture, consume it
            if (mGestureDetector != null && mGestureDetector.onTouchEvent(e))
                return true;

            float x = e.getX();
            float y = e.getY();

            switch (e.getAction()) {

                case MotionEvent.ACTION_DOWN:
                    updateValue(x, y);
                    invalidate();
                case MotionEvent.ACTION_MOVE:
                    updateValue(x, y);
                    invalidate();
                    if (mSelectionListener != null)
                        mSelectionListener.onSelectionUpdate(mValue, mMaxVal, mMinVal, this);
                    break;
                case MotionEvent.ACTION_UP:
                    updateValue(x, y);
                    invalidate();
                    if (mSelectionListener != null)
                        mSelectionListener.onValueSelected(mValue, mMaxVal, mMinVal, this);
                    break;
            }

            return true;
        }
        else
            return super.onTouchEvent(e);
    }

    /**
     * Updates the value on the ValueBar depending on the touch position.
     *
     * @param x
     * @param y
     */
    private void updateValue(float x, float y) {

        float newVal = 0f;

        if (x <= 0)
            newVal = mMinVal;
        else if (x > getWidth())
            newVal = mMaxVal;
        else {
            float factor = x / getWidth();

            newVal = (mMaxVal - mMinVal) * factor + mMinVal;
        }

        if (mInterval > 0f) {

            float remainder = newVal % mInterval;

            // check if the new value is closer to the next, or the previous
            if (remainder <= mInterval / 2f) {

                newVal = newVal - remainder;
            } else {
                newVal = newVal - remainder + mInterval;
            }
        }

        mValue = newVal;
    }

So, on touching the value are set based on the touchpoint. Not using the formatter which was set initially.
 
Upvote 0

bigbadfred

Member
Licensed User
Longtime User
OK, could you by any chance change that 3rd party jar, so it will produce the correct values?
I have no idea how to do that.
Thanks for your quick reply.
 
Upvote 0
Top