am 52485b0b: Merge "Better transition interruption and TextChange fixes" into klp-dev

* commit '52485b0b7ef066241371393dc6060bccd090a222':
  Better transition interruption and TextChange fixes
This commit is contained in:
Chet Haase
2013-08-28 16:57:31 -07:00
committed by Android Git Automerger
5 changed files with 59 additions and 20 deletions

View File

@@ -40,7 +40,7 @@ public class Move extends Transition {
private static final String PROPNAME_PARENT = "android:move:parent"; private static final String PROPNAME_PARENT = "android:move:parent";
private static final String PROPNAME_WINDOW_X = "android:move:windowX"; private static final String PROPNAME_WINDOW_X = "android:move:windowX";
private static final String PROPNAME_WINDOW_Y = "android:move:windowY"; private static final String PROPNAME_WINDOW_Y = "android:move:windowY";
private static String[] sTransitionProperties = { private static final String[] sTransitionProperties = {
PROPNAME_BOUNDS, PROPNAME_BOUNDS,
PROPNAME_PARENT, PROPNAME_PARENT,
PROPNAME_WINDOW_X, PROPNAME_WINDOW_X,

View File

@@ -78,6 +78,10 @@ public class TextChange extends Transition {
*/ */
public static final int CHANGE_BEHAVIOR_OUT_IN = 3; public static final int CHANGE_BEHAVIOR_OUT_IN = 3;
private static final String[] sTransitionProperties = {
PROPNAME_TEXT
};
/** /**
* Sets the type of changing animation that will be run, one of * Sets the type of changing animation that will be run, one of
* {@link #CHANGE_BEHAVIOR_KEEP} and {@link #CHANGE_BEHAVIOR_OUT_IN}. * {@link #CHANGE_BEHAVIOR_KEEP} and {@link #CHANGE_BEHAVIOR_OUT_IN}.
@@ -91,6 +95,11 @@ public class TextChange extends Transition {
} }
} }
@Override
public String[] getTransitionProperties() {
return sTransitionProperties;
}
@Override @Override
protected void captureValues(TransitionValues values, boolean start) { protected void captureValues(TransitionValues values, boolean start) {
if (values.view instanceof TextView) { if (values.view instanceof TextView) {
@@ -111,7 +120,7 @@ public class TextChange extends Transition {
final TextView view = (TextView) endValues.view; final TextView view = (TextView) endValues.view;
Map<String, Object> startVals = startValues.values; Map<String, Object> startVals = startValues.values;
Map<String, Object> endVals = endValues.values; Map<String, Object> endVals = endValues.values;
String startText = (String) startVals.get(PROPNAME_TEXT); final String startText = (String) startVals.get(PROPNAME_TEXT);
final String endText = (String) endVals.get(PROPNAME_TEXT); final String endText = (String) endVals.get(PROPNAME_TEXT);
if (!startText.equals(endText)) { if (!startText.equals(endText)) {
view.setText(startText); view.setText(startText);
@@ -121,7 +130,10 @@ public class TextChange extends Transition {
anim.addListener(new AnimatorListenerAdapter() { anim.addListener(new AnimatorListenerAdapter() {
@Override @Override
public void onAnimationEnd(Animator animation) { public void onAnimationEnd(Animator animation) {
view.setText(endText); if (startText.equals(view.getText())) {
// Only set if it hasn't been changed since anim started
view.setText(endText);
}
} }
}); });
} else { } else {
@@ -143,7 +155,10 @@ public class TextChange extends Transition {
outAnim.addListener(new AnimatorListenerAdapter() { outAnim.addListener(new AnimatorListenerAdapter() {
@Override @Override
public void onAnimationEnd(Animator animation) { public void onAnimationEnd(Animator animation) {
view.setText(endText); if (startText.equals(view.getText())) {
// Only set if it hasn't been changed since anim started
view.setText(endText);
}
} }
}); });
} }
@@ -169,6 +184,20 @@ public class TextChange extends Transition {
anim = inAnim; anim = inAnim;
} }
} }
TransitionListener transitionListener = new TransitionListenerAdapter() {
boolean mCanceled = false;
@Override
public void onTransitionPause(Transition transition) {
view.setText(endText);
}
@Override
public void onTransitionResume(Transition transition) {
view.setText(startText);
}
};
addListener(transitionListener);
return anim; return anim;
} }
return null; return null;

View File

@@ -843,7 +843,6 @@ public abstract class Transition implements Cloneable {
for (int i = numOldAnims - 1; i >= 0; i--) { for (int i = numOldAnims - 1; i >= 0; i--) {
Animator anim = runningAnimators.keyAt(i); Animator anim = runningAnimators.keyAt(i);
if (anim != null) { if (anim != null) {
anim.resume();
AnimationInfo oldInfo = runningAnimators.get(anim); AnimationInfo oldInfo = runningAnimators.get(anim);
if (oldInfo != null) { if (oldInfo != null) {
boolean cancel = false; boolean cancel = false;
@@ -851,22 +850,25 @@ public abstract class Transition implements Cloneable {
View oldView = oldInfo.view; View oldView = oldInfo.view;
TransitionValues newValues = mEndValues.viewValues != null ? TransitionValues newValues = mEndValues.viewValues != null ?
mEndValues.viewValues.get(oldView) : null; mEndValues.viewValues.get(oldView) : null;
if (oldValues == null || newValues == null) { if (oldValues != null) {
if (oldValues != null || newValues != null) { // if oldValues null, then transition didn't care to stash values,
// and won't get canceled
if (newValues == null) {
cancel = true; cancel = true;
} } else {
} else { for (String key : oldValues.values.keySet()) {
for (String key : oldValues.values.keySet()) { Object oldValue = oldValues.values.get(key);
Object oldValue = oldValues.values.get(key); Object newValue = newValues.values.get(key);
Object newValue = newValues.values.get(key); if (oldValue != null && newValue != null &&
if ((oldValue == null && newValue != null) || !oldValue.equals(newValue)) {
(oldValue != null && !oldValue.equals(newValue))) { cancel = true;
cancel = true; if (DBG) {
if (DBG) { Log.d(LOG_TAG, "Transition.playTransition: " +
Log.d(LOG_TAG, "Transition.play: oldValue != newValue for " + "oldValue != newValue for " + key +
key + ": old, new = " + oldValue + ", " + newValue); ": old, new = " + oldValue + ", " + newValue);
}
break;
} }
break;
} }
} }
} }

View File

@@ -183,9 +183,12 @@ public class TransitionManager {
final ArrayMap<ViewGroup, ArrayList<Transition>> runningTransitions = final ArrayMap<ViewGroup, ArrayList<Transition>> runningTransitions =
getRunningTransitions(); getRunningTransitions();
ArrayList<Transition> currentTransitions = runningTransitions.get(sceneRoot); ArrayList<Transition> currentTransitions = runningTransitions.get(sceneRoot);
ArrayList<Transition> previousRunningTransitions = null;
if (currentTransitions == null) { if (currentTransitions == null) {
currentTransitions = new ArrayList<Transition>(); currentTransitions = new ArrayList<Transition>();
runningTransitions.put(sceneRoot, currentTransitions); runningTransitions.put(sceneRoot, currentTransitions);
} else if (currentTransitions.size() > 0) {
previousRunningTransitions = new ArrayList<Transition>(currentTransitions);
} }
currentTransitions.add(transition); currentTransitions.add(transition);
transition.addListener(new Transition.TransitionListenerAdapter() { transition.addListener(new Transition.TransitionListenerAdapter() {
@@ -197,6 +200,11 @@ public class TransitionManager {
} }
}); });
transition.captureValues(sceneRoot, false); transition.captureValues(sceneRoot, false);
if (previousRunningTransitions != null) {
for (Transition runningTransition : previousRunningTransitions) {
runningTransition.resume();
}
}
transition.playTransition(sceneRoot); transition.playTransition(sceneRoot);
// Returning false from onPreDraw() skips the current frame. This is // Returning false from onPreDraw() skips the current frame. This is

View File

@@ -53,7 +53,7 @@ public abstract class Visibility extends Transition {
private static final String PROPNAME_VISIBILITY = "android:visibility:visibility"; private static final String PROPNAME_VISIBILITY = "android:visibility:visibility";
private static final String PROPNAME_PARENT = "android:visibility:parent"; private static final String PROPNAME_PARENT = "android:visibility:parent";
private static String[] sTransitionProperties = { private static final String[] sTransitionProperties = {
PROPNAME_VISIBILITY, PROPNAME_VISIBILITY,
PROPNAME_PARENT, PROPNAME_PARENT,
}; };