Fixing jank when transition from print dialog to generating one.

Initially we show the print dialog and when the user presses print
we show a generating dialog with an indefinite spinner and a cancel
button. The transition between the two UIs which are really different
layouts show in the print activity is animated. In the middle of
the animation from print to generating UI there was a jump of the
content and an undesired window animation kicking in. This is a
side effect of changing the activity to floating so now changing the
container size was causing window resize and hence animation. Fun!

bug:10983508

Change-Id: I7d88e073c55863b945cdb50822401592f32d44c3
This commit is contained in:
Svetoslav
2013-10-10 16:46:06 -07:00
parent e64d6a4e33
commit 3aa2e2b3ab
3 changed files with 53 additions and 15 deletions

View File

@@ -15,9 +15,12 @@
-->
<com.android.printspooler.PrintDialogFrame xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/content_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@color/container_background">
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:id="@+id/content_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/container_background">
</FrameLayout>
</com.android.printspooler.PrintDialogFrame>

View File

@@ -24,6 +24,8 @@ public class PrintDialogFrame extends FrameLayout {
public final int mMaxWidth;
public int mHeight;
public PrintDialogFrame(Context context, AttributeSet attrs) {
super(context, attrs);
mMaxWidth = context.getResources().getDimensionPixelSize(
@@ -32,13 +34,36 @@ public class PrintDialogFrame extends FrameLayout {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
if (widthMode == MeasureSpec.AT_MOST) {
final int receivedWidth = MeasureSpec.getSize(widthMeasureSpec);
final int computedWidth = Math.min(mMaxWidth, receivedWidth);
widthMeasureSpec = MeasureSpec.makeMeasureSpec(computedWidth,
MeasureSpec.EXACTLY);
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int measuredWidth = getMeasuredWidth();
final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
switch (widthMode) {
case MeasureSpec.UNSPECIFIED: {
measuredWidth = mMaxWidth;
} break;
case MeasureSpec.AT_MOST: {
final int receivedWidth = MeasureSpec.getSize(widthMeasureSpec);
measuredWidth = Math.min(mMaxWidth, receivedWidth);
} break;
}
mHeight = Math.max(mHeight, getMeasuredHeight());
int measuredHeight = getMeasuredHeight();
final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
switch (heightMode) {
case MeasureSpec.UNSPECIFIED: {
measuredHeight = mHeight;
} break;
case MeasureSpec.AT_MOST: {
final int receivedHeight = MeasureSpec.getSize(heightMeasureSpec);
measuredHeight = Math.min(mHeight, receivedHeight);
} break;
}
setMeasuredDimension(measuredWidth, measuredHeight);
}
}

View File

@@ -59,12 +59,14 @@ import android.text.TextWatcher;
import android.util.ArrayMap;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.MeasureSpec;
import android.view.View.OnAttachStateChangeListener;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.ViewPropertyAnimator;
@@ -75,6 +77,7 @@ import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;
@@ -1409,7 +1412,9 @@ public class PrintJobConfigActivity extends Activity {
postSwitchCallback.run();
}
}
});
},
new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER));
} break;
}
} break;
@@ -1426,7 +1431,9 @@ public class PrintJobConfigActivity extends Activity {
postSwitchCallback.run();
}
}
});
},
new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT, Gravity.CENTER));
} break;
}
} break;
@@ -1474,7 +1481,8 @@ public class PrintJobConfigActivity extends Activity {
getLayoutInflater().inflate(showLayoutId, contentContainer, true);
}
private void animateUiSwitch(int showLayoutId, final Runnable postAnimateCommand) {
private void animateUiSwitch(int showLayoutId, final Runnable postAnimateCommand,
final LayoutParams containerParams) {
// Find everything we will shuffle around.
final ViewGroup contentContainer = (ViewGroup) findViewById(R.id.content_container);
final View hidingView = contentContainer.getChildAt(0);
@@ -1511,6 +1519,8 @@ public class PrintJobConfigActivity extends Activity {
contentContainer.setScaleY(1.0f);
contentContainer.addView(showingView);
contentContainer.setLayoutParams(containerParams);
// Third animation - show the new content.
AutoCancellingAnimator.animate(showingView).withLayer().alpha(1.0f)
.withEndAction(new Runnable() {