Merge "Better transition interruption and TextChange fixes" into klp-dev

This commit is contained in:
Chet Haase
2013-08-28 23:55:10 +00:00
committed by Android (Google) Code Review
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_WINDOW_X = "android:move:windowX";
private static final String PROPNAME_WINDOW_Y = "android:move:windowY";
private static String[] sTransitionProperties = {
private static final String[] sTransitionProperties = {
PROPNAME_BOUNDS,
PROPNAME_PARENT,
PROPNAME_WINDOW_X,

View File

@@ -78,6 +78,10 @@ public class TextChange extends Transition {
*/
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
* {@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
protected void captureValues(TransitionValues values, boolean start) {
if (values.view instanceof TextView) {
@@ -111,7 +120,7 @@ public class TextChange extends Transition {
final TextView view = (TextView) endValues.view;
Map<String, Object> startVals = startValues.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);
if (!startText.equals(endText)) {
view.setText(startText);
@@ -121,7 +130,10 @@ public class TextChange extends Transition {
anim.addListener(new AnimatorListenerAdapter() {
@Override
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 {
@@ -143,7 +155,10 @@ public class TextChange extends Transition {
outAnim.addListener(new AnimatorListenerAdapter() {
@Override
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;
}
}
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 null;

View File

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

View File

@@ -183,9 +183,12 @@ public class TransitionManager {
final ArrayMap<ViewGroup, ArrayList<Transition>> runningTransitions =
getRunningTransitions();
ArrayList<Transition> currentTransitions = runningTransitions.get(sceneRoot);
ArrayList<Transition> previousRunningTransitions = null;
if (currentTransitions == null) {
currentTransitions = new ArrayList<Transition>();
runningTransitions.put(sceneRoot, currentTransitions);
} else if (currentTransitions.size() > 0) {
previousRunningTransitions = new ArrayList<Transition>(currentTransitions);
}
currentTransitions.add(transition);
transition.addListener(new Transition.TransitionListenerAdapter() {
@@ -197,6 +200,11 @@ public class TransitionManager {
}
});
transition.captureValues(sceneRoot, false);
if (previousRunningTransitions != null) {
for (Transition runningTransition : previousRunningTransitions) {
runningTransition.resume();
}
}
transition.playTransition(sceneRoot);
// 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_PARENT = "android:visibility:parent";
private static String[] sTransitionProperties = {
private static final String[] sTransitionProperties = {
PROPNAME_VISIBILITY,
PROPNAME_PARENT,
};