Loading core/java/android/widget/AbsSeekBar.java +30 −0 Original line number Original line Diff line number Diff line Loading @@ -85,6 +85,16 @@ public abstract class AbsSeekBar extends ProgressBar { * @param thumb Drawable representing the thumb * @param thumb Drawable representing the thumb */ */ public void setThumb(Drawable thumb) { public void setThumb(Drawable thumb) { boolean needUpdate; // This way, calling setThumb again with the same bitmap will result in // it recalcuating mThumbOffset (if for example it the bounds of the // drawable changed) if (mThumb != null && thumb != mThumb) { mThumb.setCallback(null); needUpdate = true; } else { needUpdate = false; } if (thumb != null) { if (thumb != null) { thumb.setCallback(this); thumb.setCallback(this); Loading @@ -92,9 +102,25 @@ public abstract class AbsSeekBar extends ProgressBar { // such that the thumb will hang halfway off either edge of the // such that the thumb will hang halfway off either edge of the // progress bar. // progress bar. mThumbOffset = thumb.getIntrinsicWidth() / 2; mThumbOffset = thumb.getIntrinsicWidth() / 2; // If we're updating get the new states if (needUpdate && (thumb.getIntrinsicWidth() != mThumb.getIntrinsicWidth() || thumb.getIntrinsicHeight() != mThumb.getIntrinsicHeight())) { requestLayout(); } } } mThumb = thumb; mThumb = thumb; invalidate(); invalidate(); if (needUpdate) { updateThumbPos(getWidth(), getHeight()); if (thumb.isStateful()) { // Note that if the states are different this won't work. // For now, let's consider that an app bug. int[] state = getDrawableState(); thumb.setState(state); } } } } /** /** Loading Loading @@ -191,6 +217,10 @@ public abstract class AbsSeekBar extends ProgressBar { @Override @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { protected void onSizeChanged(int w, int h, int oldw, int oldh) { updateThumbPos(w, h); } private void updateThumbPos(int w, int h) { Drawable d = getCurrentDrawable(); Drawable d = getCurrentDrawable(); Drawable thumb = mThumb; Drawable thumb = mThumb; int thumbHeight = thumb == null ? 0 : thumb.getIntrinsicHeight(); int thumbHeight = thumb == null ? 0 : thumb.getIntrinsicHeight(); Loading Loading
core/java/android/widget/AbsSeekBar.java +30 −0 Original line number Original line Diff line number Diff line Loading @@ -85,6 +85,16 @@ public abstract class AbsSeekBar extends ProgressBar { * @param thumb Drawable representing the thumb * @param thumb Drawable representing the thumb */ */ public void setThumb(Drawable thumb) { public void setThumb(Drawable thumb) { boolean needUpdate; // This way, calling setThumb again with the same bitmap will result in // it recalcuating mThumbOffset (if for example it the bounds of the // drawable changed) if (mThumb != null && thumb != mThumb) { mThumb.setCallback(null); needUpdate = true; } else { needUpdate = false; } if (thumb != null) { if (thumb != null) { thumb.setCallback(this); thumb.setCallback(this); Loading @@ -92,9 +102,25 @@ public abstract class AbsSeekBar extends ProgressBar { // such that the thumb will hang halfway off either edge of the // such that the thumb will hang halfway off either edge of the // progress bar. // progress bar. mThumbOffset = thumb.getIntrinsicWidth() / 2; mThumbOffset = thumb.getIntrinsicWidth() / 2; // If we're updating get the new states if (needUpdate && (thumb.getIntrinsicWidth() != mThumb.getIntrinsicWidth() || thumb.getIntrinsicHeight() != mThumb.getIntrinsicHeight())) { requestLayout(); } } } mThumb = thumb; mThumb = thumb; invalidate(); invalidate(); if (needUpdate) { updateThumbPos(getWidth(), getHeight()); if (thumb.isStateful()) { // Note that if the states are different this won't work. // For now, let's consider that an app bug. int[] state = getDrawableState(); thumb.setState(state); } } } } /** /** Loading Loading @@ -191,6 +217,10 @@ public abstract class AbsSeekBar extends ProgressBar { @Override @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { protected void onSizeChanged(int w, int h, int oldw, int oldh) { updateThumbPos(w, h); } private void updateThumbPos(int w, int h) { Drawable d = getCurrentDrawable(); Drawable d = getCurrentDrawable(); Drawable thumb = mThumb; Drawable thumb = mThumb; int thumbHeight = thumb == null ? 0 : thumb.getIntrinsicHeight(); int thumbHeight = thumb == null ? 0 : thumb.getIntrinsicHeight(); Loading