TransitionUtilspublic class TransitionUtils extends Object Static utility methods for Transitions. |
Fields Summary |
---|
private static int | MAX_IMAGE_SIZE |
Methods Summary |
---|
public static android.view.View | copyViewImage(android.view.ViewGroup sceneRoot, android.view.View view, android.view.View parent)Creates a View using the bitmap copy of view . If view is large,
the copy will use a scaled bitmap of the given view.
Matrix matrix = new Matrix();
matrix.setTranslate(-parent.getScrollX(), -parent.getScrollY());
view.transformMatrixToGlobal(matrix);
sceneRoot.transformMatrixToLocal(matrix);
RectF bounds = new RectF(0, 0, view.getWidth(), view.getHeight());
matrix.mapRect(bounds);
int left = Math.round(bounds.left);
int top = Math.round(bounds.top);
int right = Math.round(bounds.right);
int bottom = Math.round(bounds.bottom);
ImageView copy = new ImageView(view.getContext());
copy.setScaleType(ImageView.ScaleType.CENTER_CROP);
Bitmap bitmap = createViewBitmap(view, matrix, bounds);
if (bitmap != null) {
copy.setImageBitmap(bitmap);
}
int widthSpec = View.MeasureSpec.makeMeasureSpec(right - left, View.MeasureSpec.EXACTLY);
int heightSpec = View.MeasureSpec.makeMeasureSpec(bottom - top, View.MeasureSpec.EXACTLY);
copy.measure(widthSpec, heightSpec);
copy.layout(left, top, right, bottom);
return copy;
| public static android.graphics.Bitmap | createDrawableBitmap(android.graphics.drawable.Drawable drawable)Get a copy of bitmap of given drawable, return null if intrinsic size is zero
int width = drawable.getIntrinsicWidth();
int height = drawable.getIntrinsicHeight();
if (width <= 0 || height <= 0) {
return null;
}
float scale = Math.min(1f, ((float)MAX_IMAGE_SIZE) / (width * height));
if (drawable instanceof BitmapDrawable && scale == 1f) {
// return same bitmap if scale down not needed
return ((BitmapDrawable) drawable).getBitmap();
}
int bitmapWidth = (int) (width * scale);
int bitmapHeight = (int) (height * scale);
Bitmap bitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
Rect existingBounds = drawable.getBounds();
int left = existingBounds.left;
int top = existingBounds.top;
int right = existingBounds.right;
int bottom = existingBounds.bottom;
drawable.setBounds(0, 0, bitmapWidth, bitmapHeight);
drawable.draw(canvas);
drawable.setBounds(left, top, right, bottom);
return bitmap;
| public static android.graphics.Bitmap | createViewBitmap(android.view.View view, android.graphics.Matrix matrix, android.graphics.RectF bounds)Creates a Bitmap of the given view, using the Matrix matrix to transform to the local
coordinates. matrix will be modified during the bitmap creation.
If the bitmap is large, it will be scaled uniformly down to at most 1MB size.
Bitmap bitmap = null;
int bitmapWidth = Math.round(bounds.width());
int bitmapHeight = Math.round(bounds.height());
if (bitmapWidth > 0 && bitmapHeight > 0) {
float scale = Math.min(1f, ((float)MAX_IMAGE_SIZE) / (bitmapWidth * bitmapHeight));
bitmapWidth *= scale;
bitmapHeight *= scale;
matrix.postTranslate(-bounds.left, -bounds.top);
matrix.postScale(scale, scale);
bitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.concat(matrix);
view.draw(canvas);
}
return bitmap;
| static android.animation.Animator | mergeAnimators(android.animation.Animator animator1, android.animation.Animator animator2)
if (animator1 == null) {
return animator2;
} else if (animator2 == null) {
return animator1;
} else {
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playTogether(animator1, animator2);
return animatorSet;
}
| public static Transition | mergeTransitions(Transition transitions)
int count = 0;
int nonNullIndex = -1;
for (int i = 0; i < transitions.length; i++) {
if (transitions[i] != null) {
count++;
nonNullIndex = i;
}
}
if (count == 0) {
return null;
}
if (count == 1) {
return transitions[nonNullIndex];
}
TransitionSet transitionSet = new TransitionSet();
for (int i = 0; i < transitions.length; i++) {
if (transitions[i] != null) {
transitionSet.addTransition(transitions[i]);
}
}
return transitionSet;
|
|