summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorke Lee <yorkelee@google.com>2015-03-26 16:33:15 -0700
committerYorke Lee <yorkelee@google.com>2015-03-27 14:13:16 -0700
commit7e9763e4b3806c9edaf3df4f59a3d5a6452a361c (patch)
tree4ba27ffb5dc405cd018e0ea972b850c75f526234
parent753fae1bfe34ac79b96648b17dcd8498b1a6a974 (diff)
Fix some jank during shrink animation
* Prevent call updates while animation is running * Create hardware layers for animating views before animation starts. Alpha animations on the text elements require a hardware layer to be built beforehand. Do this before the animation starts instead of after the first frame is drawn. Change-Id: I21a8a9096f36adc4688597f7469a2f05a1b5234c
-rw-r--r--InCallUI/src/com/android/incallui/Call.java3
-rw-r--r--InCallUI/src/com/android/incallui/CallCardFragment.java30
-rw-r--r--InCallUI/src/com/android/incallui/CallList.java5
-rw-r--r--InCallUI/src/com/android/incallui/InCallPresenter.java16
4 files changed, 46 insertions, 8 deletions
diff --git a/InCallUI/src/com/android/incallui/Call.java b/InCallUI/src/com/android/incallui/Call.java
index 9a5228f7e..d8e76c7b5 100644
--- a/InCallUI/src/com/android/incallui/Call.java
+++ b/InCallUI/src/com/android/incallui/Call.java
@@ -22,6 +22,7 @@ import com.android.contacts.common.testing.NeededForTesting;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
+import android.os.Trace;
import android.telecom.CallProperties;
import android.telecom.DisconnectCause;
import android.telecom.GatewayInfo;
@@ -212,6 +213,7 @@ public class Call {
}
private void update() {
+ Trace.beginSection("Update");
int oldState = getState();
updateFromTelecommCall();
if (oldState != getState() && getState() == Call.State.DISCONNECTED) {
@@ -219,6 +221,7 @@ public class Call {
} else {
CallList.getInstance().onUpdate(this);
}
+ Trace.endSection();
}
private void updateFromTelecommCall() {
diff --git a/InCallUI/src/com/android/incallui/CallCardFragment.java b/InCallUI/src/com/android/incallui/CallCardFragment.java
index 5f5146e19..56c099053 100644
--- a/InCallUI/src/com/android/incallui/CallCardFragment.java
+++ b/InCallUI/src/com/android/incallui/CallCardFragment.java
@@ -21,6 +21,8 @@ import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.LayoutTransition;
import android.animation.ObjectAnimator;
+import android.animation.ValueAnimator;
+import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
@@ -110,6 +112,8 @@ public class CallCardFragment extends BaseFragment<CallCardPresenter, CallCardPr
private Animation mPulseAnimation;
private int mVideoAnimationDuration;
+ // Whether or not the call card is currently in the process of an animation
+ private boolean mIsAnimating;
private MaterialPalette mCurrentThemeColors;
@@ -596,6 +600,10 @@ public class CallCardFragment extends BaseFragment<CallCardPresenter, CallCardPr
mInCallMessageLabel.setVisibility(View.VISIBLE);
}
+ public boolean isAnimating() {
+ return mIsAnimating;
+ }
+
private void showInternetCallLabel(boolean show) {
if (show) {
final String label = getView().getContext().getString(
@@ -856,6 +864,8 @@ public class CallCardFragment extends BaseFragment<CallCardPresenter, CallCardPr
final LayoutTransition transition = mPrimaryCallInfo.getLayoutTransition();
transition.disableTransitionType(LayoutTransition.CHANGING);
+ mIsAnimating = true;
+
observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
@@ -884,6 +894,13 @@ public class CallCardFragment extends BaseFragment<CallCardPresenter, CallCardPr
mCallTypeLabel.setAlpha(0);
mCallNumberAndLabel.setAlpha(0);
+ assignTranslateAnimation(mCallStateLabel, 1);
+ assignTranslateAnimation(mCallStateIcon, 1);
+ assignTranslateAnimation(mPrimaryName, 2);
+ assignTranslateAnimation(mCallNumberAndLabel, 3);
+ assignTranslateAnimation(mCallTypeLabel, 4);
+ assignTranslateAnimation(mCallButtonsContainer, 5);
+
final Animator animator = getShrinkAnimator(parent.getHeight(), originalHeight);
animator.addListener(new AnimatorListenerAdapter() {
@@ -892,6 +909,8 @@ public class CallCardFragment extends BaseFragment<CallCardPresenter, CallCardPr
mPrimaryCallCardContainer.setTag(R.id.view_tag_callcard_actual_height,
null);
setViewStatePostAnimation(listener);
+ mIsAnimating = false;
+ InCallPresenter.getInstance().onShrinkAnimationComplete();
}
});
animator.start();
@@ -980,19 +999,12 @@ public class CallCardFragment extends BaseFragment<CallCardPresenter, CallCardPr
* and then translated upwards together with the scrim.
*/
private Animator getShrinkAnimator(int startHeight, int endHeight) {
- final Animator shrinkAnimator =
+ final ObjectAnimator shrinkAnimator =
ObjectAnimator.ofInt(mPrimaryCallCardContainer, "bottom", startHeight, endHeight);
shrinkAnimator.setDuration(mShrinkAnimationDuration);
shrinkAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
- assignTranslateAnimation(mCallStateLabel, 1);
- assignTranslateAnimation(mCallStateIcon, 1);
- assignTranslateAnimation(mPrimaryName, 2);
- assignTranslateAnimation(mCallNumberAndLabel, 3);
- assignTranslateAnimation(mCallTypeLabel, 4);
- assignTranslateAnimation(mCallButtonsContainer, 5);
-
mFloatingActionButton.setEnabled(true);
}
});
@@ -1001,6 +1013,8 @@ public class CallCardFragment extends BaseFragment<CallCardPresenter, CallCardPr
}
private void assignTranslateAnimation(View view, int offset) {
+ view.setLayerType(View.LAYER_TYPE_HARDWARE, null);
+ view.buildLayer();
view.setTranslationY(mTranslationOffset * offset);
view.animate().translationY(0).alpha(1).withLayer()
.setDuration(mShrinkAnimationDuration).setInterpolator(AnimUtils.EASE_IN);
diff --git a/InCallUI/src/com/android/incallui/CallList.java b/InCallUI/src/com/android/incallui/CallList.java
index db43b1657..111d48d2e 100644
--- a/InCallUI/src/com/android/incallui/CallList.java
+++ b/InCallUI/src/com/android/incallui/CallList.java
@@ -21,6 +21,7 @@ import com.google.common.base.Preconditions;
import android.os.Handler;
import android.os.Message;
+import android.os.Trace;
import android.telecom.DisconnectCause;
import android.telecom.Phone;
@@ -71,12 +72,14 @@ public class CallList implements InCallPhoneListener {
private Phone.Listener mPhoneListener = new Phone.Listener() {
@Override
public void onCallAdded(Phone phone, android.telecom.Call telecommCall) {
+ Trace.beginSection("onCallAdded");
Call call = new Call(telecommCall);
if (call.getState() == Call.State.INCOMING) {
onIncoming(call, call.getCannedSmsResponses());
} else {
onUpdate(call);
}
+ Trace.endSection();
}
@Override
public void onCallRemoved(Phone phone, android.telecom.Call telecommCall) {
@@ -139,8 +142,10 @@ public class CallList implements InCallPhoneListener {
* Called when a single call has changed.
*/
public void onUpdate(Call call) {
+ Trace.beginSection("onUpdate");
onUpdateCall(call);
notifyGenericListeners();
+ Trace.endSection();
}
public void notifyCallUpdateListeners(Call call) {
diff --git a/InCallUI/src/com/android/incallui/InCallPresenter.java b/InCallUI/src/com/android/incallui/InCallPresenter.java
index 225b1a259..b98eadaa1 100644
--- a/InCallUI/src/com/android/incallui/InCallPresenter.java
+++ b/InCallUI/src/com/android/incallui/InCallPresenter.java
@@ -388,6 +388,8 @@ public class InCallPresenter implements CallList.Listener, InCallPhoneListener,
}
}
+ private boolean mAwaitingCallListUpdate = false;
+
/**
* Called when there is a change to the call list.
* Sets the In-Call state for the entire in-call app based on the information it gets from
@@ -396,9 +398,17 @@ public class InCallPresenter implements CallList.Listener, InCallPhoneListener,
*/
@Override
public void onCallListChange(CallList callList) {
+ if (mInCallActivity != null && mInCallActivity.getCallCardFragment() != null &&
+ mInCallActivity.getCallCardFragment().isAnimating()) {
+ mAwaitingCallListUpdate = true;
+ return;
+ }
if (callList == null) {
return;
}
+
+ mAwaitingCallListUpdate = false;
+
InCallState newState = getPotentialStateFromCallList(callList);
InCallState oldState = mInCallState;
newState = startOrFinishUi(newState);
@@ -514,6 +524,12 @@ public class InCallPresenter implements CallList.Listener, InCallPhoneListener,
}
}
+ public void onShrinkAnimationComplete() {
+ if (mAwaitingCallListUpdate) {
+ onCallListChange(mCallList);
+ }
+ }
+
public void addIncomingCallListener(IncomingCallListener listener) {
Preconditions.checkNotNull(listener);
mIncomingCallListeners.add(listener);