private void updateThumbPosFromCurrentProgress() { int thumbWidth = mThumb.getIntrinsicWidth(); int addedThumb = mAddedTouchBounds; int halfThumb = thumbWidth / 2; float scaleDraw = (mValue - mMin) / (float) (mMax - mMin); // This doesn't matter if RTL, as we just need the "avaiable" area int left = getPaddingLeft() + halfThumb + addedThumb; int right = getWidth() - (getPaddingRight() + halfThumb + addedThumb); int available = right - left; final int thumbPos = (int) (scaleDraw * available + 0.5f); updateThumbPos(thumbPos); }
private void updateProgressFromAnimation(float scale) { Rect bounds = mThumb.getBounds(); int halfThumb = bounds.width() / 2; int addedThumb = mAddedTouchBounds; int left = getPaddingLeft() + halfThumb + addedThumb; int right = getWidth() - (getPaddingRight() + halfThumb + addedThumb); int available = right - left; int progress = Math.round((scale * (mMax - mMin)) + mMin); // we don't want to just call setProgress here to avoid the animation // being cancelled, // and this position is not bound to a real progress value but // interpolated if (progress != getProgress()) { mValue = progress; notifyProgress(mValue, true); updateProgressMessage(progress); } final int thumbPos = (int) (scale * available + 0.5f); updateThumbPos(thumbPos); }