AnderWeb / discreteSeekBar

Apache License 2.0
2.11k stars 400 forks source link

Cutting bubble on screen rotate #53

Closed lewkka closed 8 years ago

lewkka commented 8 years ago

https://i.gyazo.com/0765c4c94eb04a16335b1fc1880f9bea.gif

Have changed screen orientation to horizontal: bubble hides on a half way. But if app starts in horizontal – it's OK.

mrfix1t commented 8 years ago

I found solution. This problem is caused by old display metrics values in PopupIndicator class after screen rotation. I moved initialization of DisplayMetrics in onSizeChanged method:

public void onSizeChanged() {
        DisplayMetrics displayMetrics = mContext.getResources().getDisplayMetrics();
        screenSize.set(displayMetrics.widthPixels, displayMetrics.heightPixels);
}

Then simply call this method for PopupIndicator instance in onSizeChanged() method for DiscreteSeekBar class:

@Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        Log.i("www", "onSizeChanged");
        int thumbWidth = mThumb.getIntrinsicWidth();
        int thumbHeight = mThumb.getIntrinsicHeight();
        int addedThumb = mAddedTouchBounds;
        int halfThumb = thumbWidth / 2;
        int paddingLeft = getPaddingLeft() + addedThumb;
        int paddingRight = getPaddingRight();
        int bottom = getHeight() - getPaddingBottom() - addedThumb;
        mThumb.setBounds(paddingLeft, bottom - thumbHeight, paddingLeft + thumbWidth, bottom);
        int trackHeight = Math.max(mTrackHeight / 2, 1);
        mTrack.setBounds(paddingLeft + halfThumb, bottom - halfThumb - trackHeight,
                getWidth() - halfThumb - paddingRight - addedThumb, bottom - halfThumb + trackHeight);
        int scrubberHeight = Math.max(mScrubberHeight / 2, 2);
        mScrubber.setBounds(paddingLeft + halfThumb, bottom - halfThumb - scrubberHeight,
                paddingLeft + halfThumb, bottom - halfThumb + scrubberHeight);

        //Update the thumb position after size changed
        updateThumbPosFromCurrentProgress();
        mIndicator.onSizeChanged();
}
AnderWeb commented 8 years ago

I can't reproduce the issue. Could you reproduce it with the sample app? I've tried adding "configchanges:orientation" to the sample app's MainActivity but the popup was properly shown.

Does it happen on every android version?

If you manage to reproduce it for the sample app, I've created a (I think) better solution but I'd need to reproduce the issue to see if it works.

Thanks.

mrfix1t commented 8 years ago

Hi! I tested on 5.1 Android Galaxy S6 phone. Also this issue reproduce on Htc One Android 5.0 and Huawei P6 Android 4.2. Try this set of flags android:configChanges="keyboardHidden|orientation|screenSize" to MainActivity in manifest. This problem ussually appears when activity first created on Portrait mode.PS. You can see attached screenshot from Huawei. Thanks. screenshot_2016-01-26-16-32-49