am c8361ba7: am 0a310c99: Merge "Revert "Animates AbsSeekBar progress movement from key presses."" into lmp-mr1-dev
* commit 'c8361ba78eac66c49d92ff4be36ef23889846ea9': Revert "Animates AbsSeekBar progress movement from key presses."
This commit is contained in:
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package android.widget;
|
package android.widget;
|
||||||
|
|
||||||
import android.animation.ObjectAnimator;
|
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.ColorStateList;
|
import android.content.res.ColorStateList;
|
||||||
@@ -65,9 +64,6 @@ public abstract class AbsSeekBar extends ProgressBar {
|
|||||||
* progress.
|
* progress.
|
||||||
*/
|
*/
|
||||||
private int mKeyProgressIncrement = 1;
|
private int mKeyProgressIncrement = 1;
|
||||||
private ObjectAnimator mPositionAnimator;
|
|
||||||
private static final int PROGRESS_ANIMATION_DURATION = 250;
|
|
||||||
|
|
||||||
|
|
||||||
private static final int NO_ALPHA = 0xFF;
|
private static final int NO_ALPHA = 0xFF;
|
||||||
private float mDisabledAlpha;
|
private float mDisabledAlpha;
|
||||||
@@ -388,14 +384,15 @@ public abstract class AbsSeekBar extends ProgressBar {
|
|||||||
void onProgressRefresh(float scale, boolean fromUser) {
|
void onProgressRefresh(float scale, boolean fromUser) {
|
||||||
super.onProgressRefresh(scale, fromUser);
|
super.onProgressRefresh(scale, fromUser);
|
||||||
|
|
||||||
if (!isAnimationRunning()) {
|
final Drawable thumb = mThumb;
|
||||||
setThumbPos(scale);
|
if (thumb != null) {
|
||||||
}
|
setThumbPos(getWidth(), thumb, scale, Integer.MIN_VALUE);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
// Since we draw translated, the drawable's bounds that it signals
|
||||||
void onAnimatePosition(float scale, boolean fromUser) {
|
// for invalidation won't be the actual bounds we want invalidated,
|
||||||
setThumbPos(scale);
|
// so just invalidate this whole view.
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -440,18 +437,6 @@ public abstract class AbsSeekBar extends ProgressBar {
|
|||||||
return max > 0 ? getProgress() / (float) max : 0;
|
return max > 0 ? getProgress() / (float) max : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setThumbPos(float scale) {
|
|
||||||
final Drawable thumb = mThumb;
|
|
||||||
if (thumb != null) {
|
|
||||||
setThumbPos(getWidth(), thumb, scale, Integer.MIN_VALUE);
|
|
||||||
// Since we draw translated, the drawable's bounds that it signals
|
|
||||||
// for invalidation won't be the actual bounds we want invalidated,
|
|
||||||
// so just invalidate this whole view.
|
|
||||||
invalidate();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the thumb drawable bounds.
|
* Updates the thumb drawable bounds.
|
||||||
*
|
*
|
||||||
@@ -714,13 +699,13 @@ public abstract class AbsSeekBar extends ProgressBar {
|
|||||||
switch (keyCode) {
|
switch (keyCode) {
|
||||||
case KeyEvent.KEYCODE_DPAD_LEFT:
|
case KeyEvent.KEYCODE_DPAD_LEFT:
|
||||||
if (progress <= 0) break;
|
if (progress <= 0) break;
|
||||||
animateSetProgress(progress - mKeyProgressIncrement);
|
setProgress(progress - mKeyProgressIncrement, true);
|
||||||
onKeyChange();
|
onKeyChange();
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case KeyEvent.KEYCODE_DPAD_RIGHT:
|
case KeyEvent.KEYCODE_DPAD_RIGHT:
|
||||||
if (progress >= getMax()) break;
|
if (progress >= getMax()) break;
|
||||||
animateSetProgress(progress + mKeyProgressIncrement);
|
setProgress(progress + mKeyProgressIncrement, true);
|
||||||
onKeyChange();
|
onKeyChange();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -729,38 +714,6 @@ public abstract class AbsSeekBar extends ProgressBar {
|
|||||||
return super.onKeyDown(keyCode, event);
|
return super.onKeyDown(keyCode, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isAnimationRunning() {
|
|
||||||
return mPositionAnimator != null && mPositionAnimator.isRunning();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void setProgress(int progress, boolean fromUser) {
|
|
||||||
if (isAnimationRunning()) {
|
|
||||||
mPositionAnimator.cancel();
|
|
||||||
}
|
|
||||||
super.setProgress(progress, fromUser);
|
|
||||||
}
|
|
||||||
|
|
||||||
void animateSetProgress(int progress) {
|
|
||||||
float curProgress = isAnimationRunning() ? getAnimationPosition() : getProgress();
|
|
||||||
|
|
||||||
if (progress < 0) {
|
|
||||||
progress = 0;
|
|
||||||
} else if (progress > getMax()) {
|
|
||||||
progress = getMax();
|
|
||||||
}
|
|
||||||
setProgressValueOnly(progress);
|
|
||||||
|
|
||||||
mPositionAnimator = ObjectAnimator.ofFloat(this, "animationPosition", curProgress,
|
|
||||||
progress);
|
|
||||||
mPositionAnimator.setDuration(PROGRESS_ANIMATION_DURATION);
|
|
||||||
mPositionAnimator.setAutoCancel(true);
|
|
||||||
mPositionAnimator.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
|
public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
|
||||||
super.onInitializeAccessibilityEvent(event);
|
super.onInitializeAccessibilityEvent(event);
|
||||||
|
|||||||
@@ -227,8 +227,6 @@ public class ProgressBar extends View {
|
|||||||
private long mUiThreadId;
|
private long mUiThreadId;
|
||||||
private boolean mShouldStartAnimationDrawable;
|
private boolean mShouldStartAnimationDrawable;
|
||||||
|
|
||||||
private float mAnimationPosition;
|
|
||||||
|
|
||||||
private boolean mInDrawing;
|
private boolean mInDrawing;
|
||||||
private boolean mAttached;
|
private boolean mAttached;
|
||||||
private boolean mRefreshIsPosted;
|
private boolean mRefreshIsPosted;
|
||||||
@@ -1188,7 +1186,7 @@ public class ProgressBar extends View {
|
|||||||
final int count = mRefreshData.size();
|
final int count = mRefreshData.size();
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
final RefreshData rd = mRefreshData.get(i);
|
final RefreshData rd = mRefreshData.get(i);
|
||||||
doRefreshProgress(rd.id, rd.progress, rd.fromUser, true, rd.animate);
|
doRefreshProgress(rd.id, rd.progress, rd.fromUser, true);
|
||||||
rd.recycle();
|
rd.recycle();
|
||||||
}
|
}
|
||||||
mRefreshData.clear();
|
mRefreshData.clear();
|
||||||
@@ -1203,12 +1201,10 @@ public class ProgressBar extends View {
|
|||||||
new SynchronizedPool<RefreshData>(POOL_MAX);
|
new SynchronizedPool<RefreshData>(POOL_MAX);
|
||||||
|
|
||||||
public int id;
|
public int id;
|
||||||
public float progress;
|
public int progress;
|
||||||
public boolean fromUser;
|
public boolean fromUser;
|
||||||
public boolean animate;
|
|
||||||
|
|
||||||
public static RefreshData obtain(int id, float progress, boolean fromUser,
|
public static RefreshData obtain(int id, int progress, boolean fromUser) {
|
||||||
boolean animate) {
|
|
||||||
RefreshData rd = sPool.acquire();
|
RefreshData rd = sPool.acquire();
|
||||||
if (rd == null) {
|
if (rd == null) {
|
||||||
rd = new RefreshData();
|
rd = new RefreshData();
|
||||||
@@ -1216,7 +1212,6 @@ public class ProgressBar extends View {
|
|||||||
rd.id = id;
|
rd.id = id;
|
||||||
rd.progress = progress;
|
rd.progress = progress;
|
||||||
rd.fromUser = fromUser;
|
rd.fromUser = fromUser;
|
||||||
rd.animate = animate;
|
|
||||||
return rd;
|
return rd;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1243,19 +1238,9 @@ public class ProgressBar extends View {
|
|||||||
layer.setTintMode(tintMode);
|
layer.setTintMode(tintMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
private float getScale(float progress) {
|
private synchronized void doRefreshProgress(int id, int progress, boolean fromUser,
|
||||||
return mMax > 0 ? progress / (float) mMax : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private synchronized void doRefreshProgress(int id, float progress, boolean fromUser,
|
|
||||||
boolean callBackToApp) {
|
boolean callBackToApp) {
|
||||||
doRefreshProgress(id, progress, fromUser, callBackToApp, false);
|
float scale = mMax > 0 ? (float) progress / (float) mMax : 0;
|
||||||
}
|
|
||||||
|
|
||||||
private synchronized void doRefreshProgress(int id, float progress, boolean fromUser,
|
|
||||||
boolean callBackToApp, boolean animate) {
|
|
||||||
float scale = getScale(progress);
|
|
||||||
|
|
||||||
final Drawable d = mCurrentDrawable;
|
final Drawable d = mCurrentDrawable;
|
||||||
if (d != null) {
|
if (d != null) {
|
||||||
Drawable progressDrawable = null;
|
Drawable progressDrawable = null;
|
||||||
@@ -1273,64 +1258,26 @@ public class ProgressBar extends View {
|
|||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id == R.id.progress) {
|
if (callBackToApp && id == R.id.progress) {
|
||||||
if (animate) {
|
onProgressRefresh(scale, fromUser);
|
||||||
onAnimatePosition(scale, fromUser);
|
|
||||||
} else if (callBackToApp) {
|
|
||||||
onProgressRefresh(scale, fromUser);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when a ProgressBar is animating its position.
|
|
||||||
*
|
|
||||||
* @param scale Current position/progress between 0 and 1.
|
|
||||||
* @param fromUser True if the progress change was initiated by the user.
|
|
||||||
*/
|
|
||||||
void onAnimatePosition(float scale, boolean fromUser) {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the progress value without going through the entire refresh process.
|
|
||||||
*
|
|
||||||
* @see #setProgress(int, boolean)
|
|
||||||
* @param progress The new progress, between 0 and {@link #getMax()}
|
|
||||||
*/
|
|
||||||
void setProgressValueOnly(int progress) {
|
|
||||||
mProgress = progress;
|
|
||||||
onProgressRefresh(getScale(progress), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setAnimationPosition(float position) {
|
|
||||||
mAnimationPosition = position;
|
|
||||||
refreshProgress(R.id.progress, position, true, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
float getAnimationPosition() {
|
|
||||||
return mAnimationPosition;
|
|
||||||
}
|
|
||||||
|
|
||||||
void onProgressRefresh(float scale, boolean fromUser) {
|
void onProgressRefresh(float scale, boolean fromUser) {
|
||||||
if (AccessibilityManager.getInstance(mContext).isEnabled()) {
|
if (AccessibilityManager.getInstance(mContext).isEnabled()) {
|
||||||
scheduleAccessibilityEventSender();
|
scheduleAccessibilityEventSender();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void refreshProgress(int id, float progress, boolean fromUser) {
|
private synchronized void refreshProgress(int id, int progress, boolean fromUser) {
|
||||||
refreshProgress(id, progress, fromUser, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private synchronized void refreshProgress(int id, float progress, boolean fromUser,
|
|
||||||
boolean animate) {
|
|
||||||
if (mUiThreadId == Thread.currentThread().getId()) {
|
if (mUiThreadId == Thread.currentThread().getId()) {
|
||||||
doRefreshProgress(id, progress, fromUser, true, animate);
|
doRefreshProgress(id, progress, fromUser, true);
|
||||||
} else {
|
} else {
|
||||||
if (mRefreshProgressRunnable == null) {
|
if (mRefreshProgressRunnable == null) {
|
||||||
mRefreshProgressRunnable = new RefreshProgressRunnable();
|
mRefreshProgressRunnable = new RefreshProgressRunnable();
|
||||||
}
|
}
|
||||||
|
|
||||||
final RefreshData rd = RefreshData.obtain(id, progress, fromUser, animate);
|
final RefreshData rd = RefreshData.obtain(id, progress, fromUser);
|
||||||
mRefreshData.add(rd);
|
mRefreshData.add(rd);
|
||||||
if (mAttached && !mRefreshIsPosted) {
|
if (mAttached && !mRefreshIsPosted) {
|
||||||
post(mRefreshProgressRunnable);
|
post(mRefreshProgressRunnable);
|
||||||
@@ -1849,7 +1796,7 @@ public class ProgressBar extends View {
|
|||||||
final int count = mRefreshData.size();
|
final int count = mRefreshData.size();
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
final RefreshData rd = mRefreshData.get(i);
|
final RefreshData rd = mRefreshData.get(i);
|
||||||
doRefreshProgress(rd.id, rd.progress, rd.fromUser, rd.animate);
|
doRefreshProgress(rd.id, rd.progress, rd.fromUser, true);
|
||||||
rd.recycle();
|
rd.recycle();
|
||||||
}
|
}
|
||||||
mRefreshData.clear();
|
mRefreshData.clear();
|
||||||
|
|||||||
@@ -314,10 +314,6 @@ public class RatingBar extends AbsSeekBar {
|
|||||||
dispatchRatingChange(true);
|
dispatchRatingChange(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
void animateSetProgress(int progress) {
|
|
||||||
}
|
|
||||||
|
|
||||||
void dispatchRatingChange(boolean fromUser) {
|
void dispatchRatingChange(boolean fromUser) {
|
||||||
if (mOnRatingBarChangeListener != null) {
|
if (mOnRatingBarChangeListener != null) {
|
||||||
mOnRatingBarChangeListener.onRatingChanged(this, getRating(),
|
mOnRatingBarChangeListener.onRatingChanged(this, getRating(),
|
||||||
|
|||||||
Reference in New Issue
Block a user