Example usage for android.animation AnimatorSet start

List of usage examples for android.animation AnimatorSet start

Introduction

In this page you can find the example usage for android.animation AnimatorSet start.

Prototype

@SuppressWarnings("unchecked")
@Override
public void start() 

Source Link

Document

Starting this AnimatorSet will, in turn, start the animations for which it is responsible.

Usage

From source file:net.bluehack.ui.PhotoViewer.java

private void switchToEditMode(final int mode) {
    if (currentEditMode == mode || centerImage.getBitmap() == null || changeModeAnimation != null
            || imageMoveAnimation != null || radialProgressViews[0].backgroundState != -1) {
        return;/*w  w  w. j av a  2  s  . c o  m*/
    }
    if (mode == 0) {
        if (currentEditMode == 2) {
            if (photoFilterView.getToolsView().getVisibility() != View.VISIBLE) {
                photoFilterView.switchToOrFromEditMode();
                return;
            }
        }
        Bitmap bitmap = centerImage.getBitmap();
        if (bitmap != null) {
            int bitmapWidth = centerImage.getBitmapWidth();
            int bitmapHeight = centerImage.getBitmapHeight();

            float scaleX = (float) getContainerViewWidth() / (float) bitmapWidth;
            float scaleY = (float) getContainerViewHeight() / (float) bitmapHeight;
            float newScaleX = (float) getContainerViewWidth(0) / (float) bitmapWidth;
            float newScaleY = (float) getContainerViewHeight(0) / (float) bitmapHeight;
            float scale = scaleX > scaleY ? scaleY : scaleX;
            float newScale = newScaleX > newScaleY ? newScaleY : newScaleX;

            animateToScale = newScale / scale;
            animateToX = 0;
            if (currentEditMode == 1) {
                animateToY = AndroidUtilities.dp(24);
            } else if (currentEditMode == 2) {
                animateToY = AndroidUtilities.dp(62);
            } else if (currentEditMode == 3) {
                animateToY = (AndroidUtilities.dp(48) - ActionBar.getCurrentActionBarHeight()) / 2;
            }
            if (Build.VERSION.SDK_INT >= 21) {
                animateToY -= AndroidUtilities.statusBarHeight / 2;
            }
            animationStartTime = System.currentTimeMillis();
            zoomAnimation = true;
        }

        imageMoveAnimation = new AnimatorSet();
        if (currentEditMode == 1) {
            imageMoveAnimation.playTogether(
                    ObjectAnimator.ofFloat(editorDoneLayout, "translationY", AndroidUtilities.dp(48)),
                    ObjectAnimator.ofFloat(PhotoViewer.this, "animationValue", 0, 1),
                    ObjectAnimator.ofFloat(photoCropView, "alpha", 0));
        } else if (currentEditMode == 2) {
            photoFilterView.shutdown();
            imageMoveAnimation.playTogether(
                    ObjectAnimator.ofFloat(photoFilterView.getToolsView(), "translationY",
                            AndroidUtilities.dp(126)),
                    ObjectAnimator.ofFloat(PhotoViewer.this, "animationValue", 0, 1));
        } else if (currentEditMode == 3) {
            photoPaintView.shutdown();
            imageMoveAnimation.playTogether(
                    ObjectAnimator.ofFloat(photoPaintView.getToolsView(), "translationY",
                            AndroidUtilities.dp(126)),
                    ObjectAnimator.ofFloat(photoPaintView.getColorPicker(), "translationX",
                            AndroidUtilities.dp(60)),
                    ObjectAnimator.ofFloat(photoPaintView.getActionBar(), "translationY",
                            -ActionBar.getCurrentActionBarHeight()
                                    - (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0)),
                    ObjectAnimator.ofFloat(PhotoViewer.this, "animationValue", 0, 1));
        }
        imageMoveAnimation.setDuration(200);
        imageMoveAnimation.addListener(new AnimatorListenerAdapterProxy() {
            @Override
            public void onAnimationEnd(Animator animation) {
                if (currentEditMode == 1) {
                    editorDoneLayout.setVisibility(View.GONE);
                    photoCropView.setVisibility(View.GONE);
                } else if (currentEditMode == 2) {
                    containerView.removeView(photoFilterView);
                    photoFilterView = null;
                } else if (currentEditMode == 3) {
                    containerView.removeView(photoPaintView);
                    photoPaintView = null;
                }
                imageMoveAnimation = null;
                currentEditMode = mode;
                animateToScale = 1;
                animateToX = 0;
                animateToY = 0;
                scale = 1;
                updateMinMax(scale);
                containerView.invalidate();

                AnimatorSet animatorSet = new AnimatorSet();
                ArrayList<Animator> arrayList = new ArrayList<>();
                arrayList.add(ObjectAnimator.ofFloat(pickerView, "translationY", 0));
                arrayList.add(ObjectAnimator.ofFloat(actionBar, "translationY", 0));
                if (needCaptionLayout) {
                    arrayList.add(ObjectAnimator.ofFloat(captionTextView, "translationY", 0));
                }
                if (sendPhotoType == 0) {
                    arrayList.add(ObjectAnimator.ofFloat(checkImageView, "alpha", 1));
                }
                animatorSet.playTogether(arrayList);
                animatorSet.setDuration(200);
                animatorSet.addListener(new AnimatorListenerAdapterProxy() {
                    @Override
                    public void onAnimationStart(Animator animation) {
                        pickerView.setVisibility(View.VISIBLE);
                        actionBar.setVisibility(View.VISIBLE);
                        if (needCaptionLayout) {
                            captionTextView.setVisibility(
                                    captionTextView.getTag() != null ? View.VISIBLE : View.INVISIBLE);
                        }
                        if (sendPhotoType == 0) {
                            checkImageView.setVisibility(View.VISIBLE);
                        }
                    }
                });
                animatorSet.start();
            }
        });
        imageMoveAnimation.start();
    } else if (mode == 1) {
        if (photoCropView == null) {
            photoCropView = new PhotoCropView(actvityContext);
            photoCropView.setVisibility(View.GONE);
            containerView.addView(photoCropView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
                    LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 0, 0, 0, 48));
            photoCropView.setDelegate(new PhotoCropView.PhotoCropViewDelegate() {
                @Override
                public void needMoveImageTo(float x, float y, float s, boolean animated) {
                    if (animated) {
                        animateTo(s, x, y, true);
                    } else {
                        translationX = x;
                        translationY = y;
                        scale = s;
                        containerView.invalidate();
                    }
                }

                @Override
                public Bitmap getBitmap() {
                    return centerImage.getBitmap();
                }
            });
        }

        editorDoneLayout.doneButton.setText(LocaleController.getString("Crop", R.string.Crop));
        changeModeAnimation = new AnimatorSet();
        ArrayList<Animator> arrayList = new ArrayList<>();
        arrayList.add(ObjectAnimator.ofFloat(pickerView, "translationY", 0, AndroidUtilities.dp(96)));
        arrayList.add(ObjectAnimator.ofFloat(actionBar, "translationY", 0, -actionBar.getHeight()));
        if (needCaptionLayout) {
            arrayList.add(ObjectAnimator.ofFloat(captionTextView, "translationY", 0, AndroidUtilities.dp(96)));
        }
        if (sendPhotoType == 0) {
            arrayList.add(ObjectAnimator.ofFloat(checkImageView, "alpha", 1, 0));
        }
        changeModeAnimation.playTogether(arrayList);
        changeModeAnimation.setDuration(200);
        changeModeAnimation.addListener(new AnimatorListenerAdapterProxy() {
            @Override
            public void onAnimationEnd(Animator animation) {
                changeModeAnimation = null;
                pickerView.setVisibility(View.GONE);
                if (needCaptionLayout) {
                    captionTextView.setVisibility(View.INVISIBLE);
                }
                if (sendPhotoType == 0) {
                    checkImageView.setVisibility(View.GONE);
                }

                Bitmap bitmap = centerImage.getBitmap();
                if (bitmap != null) {
                    photoCropView.setBitmap(bitmap, centerImage.getOrientation(), sendPhotoType != 1);
                    int bitmapWidth = centerImage.getBitmapWidth();
                    int bitmapHeight = centerImage.getBitmapHeight();

                    float scaleX = (float) getContainerViewWidth() / (float) bitmapWidth;
                    float scaleY = (float) getContainerViewHeight() / (float) bitmapHeight;
                    float newScaleX = (float) getContainerViewWidth(1) / (float) bitmapWidth;
                    float newScaleY = (float) getContainerViewHeight(1) / (float) bitmapHeight;
                    float scale = scaleX > scaleY ? scaleY : scaleX;
                    float newScale = newScaleX > newScaleY ? newScaleY : newScaleX;

                    animateToScale = newScale / scale;
                    animateToX = 0;
                    animateToY = -AndroidUtilities.dp(24)
                            + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight / 2 : 0);
                    animationStartTime = System.currentTimeMillis();
                    zoomAnimation = true;
                }

                imageMoveAnimation = new AnimatorSet();
                imageMoveAnimation.playTogether(
                        ObjectAnimator.ofFloat(editorDoneLayout, "translationY", AndroidUtilities.dp(48), 0),
                        ObjectAnimator.ofFloat(PhotoViewer.this, "animationValue", 0, 1),
                        ObjectAnimator.ofFloat(photoCropView, "alpha", 0, 1));
                imageMoveAnimation.setDuration(200);
                imageMoveAnimation.addListener(new AnimatorListenerAdapterProxy() {
                    @Override
                    public void onAnimationStart(Animator animation) {
                        editorDoneLayout.setVisibility(View.VISIBLE);
                        photoCropView.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        imageMoveAnimation = null;
                        currentEditMode = mode;
                        animateToScale = 1;
                        animateToX = 0;
                        animateToY = 0;
                        scale = 1;
                        updateMinMax(scale);
                        containerView.invalidate();
                    }
                });
                imageMoveAnimation.start();
            }
        });
        changeModeAnimation.start();
    } else if (mode == 2) {
        if (photoFilterView == null) {
            photoFilterView = new PhotoFilterView(parentActivity, centerImage.getBitmap(),
                    centerImage.getOrientation());
            containerView.addView(photoFilterView,
                    LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
            photoFilterView.getDoneTextView().setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    applyCurrentEditMode();
                    switchToEditMode(0);
                }
            });
            photoFilterView.getCancelTextView().setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (photoFilterView.hasChanges()) {
                        if (parentActivity == null) {
                            return;
                        }
                        AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
                        builder.setMessage(
                                LocaleController.getString("DiscardChanges", R.string.DiscardChanges));
                        builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                        builder.setPositiveButton(LocaleController.getString("OK", R.string.OK),
                                new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialogInterface, int i) {
                                        switchToEditMode(0);
                                    }
                                });
                        builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                        showAlertDialog(builder);
                    } else {
                        switchToEditMode(0);
                    }
                }
            });
            photoFilterView.getToolsView().setTranslationY(AndroidUtilities.dp(126));
        }

        changeModeAnimation = new AnimatorSet();
        ArrayList<Animator> arrayList = new ArrayList<>();
        arrayList.add(ObjectAnimator.ofFloat(pickerView, "translationY", 0, AndroidUtilities.dp(96)));
        arrayList.add(ObjectAnimator.ofFloat(actionBar, "translationY", 0, -actionBar.getHeight()));
        if (needCaptionLayout) {
            arrayList.add(ObjectAnimator.ofFloat(captionTextView, "translationY", 0, AndroidUtilities.dp(96)));
        }
        if (sendPhotoType == 0) {
            arrayList.add(ObjectAnimator.ofFloat(checkImageView, "alpha", 1, 0));
        }
        changeModeAnimation.playTogether(arrayList);
        changeModeAnimation.setDuration(200);
        changeModeAnimation.addListener(new AnimatorListenerAdapterProxy() {
            @Override
            public void onAnimationEnd(Animator animation) {
                changeModeAnimation = null;
                pickerView.setVisibility(View.GONE);
                actionBar.setVisibility(View.GONE);
                if (needCaptionLayout) {
                    captionTextView.setVisibility(View.INVISIBLE);
                }
                if (sendPhotoType == 0) {
                    checkImageView.setVisibility(View.GONE);
                }

                Bitmap bitmap = centerImage.getBitmap();
                if (bitmap != null) {
                    int bitmapWidth = centerImage.getBitmapWidth();
                    int bitmapHeight = centerImage.getBitmapHeight();

                    float scaleX = (float) getContainerViewWidth() / (float) bitmapWidth;
                    float scaleY = (float) getContainerViewHeight() / (float) bitmapHeight;
                    float newScaleX = (float) getContainerViewWidth(2) / (float) bitmapWidth;
                    float newScaleY = (float) getContainerViewHeight(2) / (float) bitmapHeight;
                    float scale = scaleX > scaleY ? scaleY : scaleX;
                    float newScale = newScaleX > newScaleY ? newScaleY : newScaleX;

                    animateToScale = newScale / scale;
                    animateToX = 0;
                    animateToY = -AndroidUtilities.dp(62)
                            + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight / 2 : 0);
                    animationStartTime = System.currentTimeMillis();
                    zoomAnimation = true;
                }

                imageMoveAnimation = new AnimatorSet();
                imageMoveAnimation.playTogether(
                        ObjectAnimator.ofFloat(PhotoViewer.this, "animationValue", 0, 1),
                        ObjectAnimator.ofFloat(photoFilterView.getToolsView(), "translationY",
                                AndroidUtilities.dp(126), 0));
                imageMoveAnimation.setDuration(200);
                imageMoveAnimation.addListener(new AnimatorListenerAdapterProxy() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        photoFilterView.init();
                        imageMoveAnimation = null;
                        currentEditMode = mode;
                        animateToScale = 1;
                        animateToX = 0;
                        animateToY = 0;
                        scale = 1;
                        updateMinMax(scale);
                        containerView.invalidate();
                    }
                });
                imageMoveAnimation.start();
            }
        });
        changeModeAnimation.start();
    } else if (mode == 3) {
        if (photoPaintView == null) {
            photoPaintView = new PhotoPaintView(parentActivity, centerImage.getBitmap(),
                    centerImage.getOrientation());
            containerView.addView(photoPaintView,
                    LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
            photoPaintView.getDoneTextView().setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    applyCurrentEditMode();
                    switchToEditMode(0);
                }
            });
            photoPaintView.getCancelTextView().setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    photoPaintView.maybeShowDismissalAlert(PhotoViewer.this, parentActivity, new Runnable() {
                        @Override
                        public void run() {
                            switchToEditMode(0);
                        }
                    });
                }
            });
            photoPaintView.getColorPicker().setTranslationX(AndroidUtilities.dp(60));
            photoPaintView.getToolsView().setTranslationY(AndroidUtilities.dp(126));
            photoPaintView.getActionBar().setTranslationY(-ActionBar.getCurrentActionBarHeight()
                    - (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0));
        }

        changeModeAnimation = new AnimatorSet();
        ArrayList<Animator> arrayList = new ArrayList<>();
        arrayList.add(ObjectAnimator.ofFloat(pickerView, "translationY", 0, AndroidUtilities.dp(96)));
        arrayList.add(ObjectAnimator.ofFloat(actionBar, "translationY", 0, -actionBar.getHeight()));

        if (needCaptionLayout) {
            arrayList.add(ObjectAnimator.ofFloat(captionTextView, "translationY", 0, AndroidUtilities.dp(96)));
        }
        if (sendPhotoType == 0) {
            arrayList.add(ObjectAnimator.ofFloat(checkImageView, "alpha", 1, 0));
        }
        changeModeAnimation.playTogether(arrayList);
        changeModeAnimation.setDuration(200);
        changeModeAnimation.addListener(new AnimatorListenerAdapterProxy() {
            @Override
            public void onAnimationEnd(Animator animation) {
                changeModeAnimation = null;
                pickerView.setVisibility(View.GONE);
                if (needCaptionLayout) {
                    captionTextView.setVisibility(View.INVISIBLE);
                }
                if (sendPhotoType == 0) {
                    checkImageView.setVisibility(View.GONE);
                }

                Bitmap bitmap = centerImage.getBitmap();
                if (bitmap != null) {
                    int bitmapWidth = centerImage.getBitmapWidth();
                    int bitmapHeight = centerImage.getBitmapHeight();

                    float scaleX = (float) getContainerViewWidth() / (float) bitmapWidth;
                    float scaleY = (float) getContainerViewHeight() / (float) bitmapHeight;
                    float newScaleX = (float) getContainerViewWidth(3) / (float) bitmapWidth;
                    float newScaleY = (float) getContainerViewHeight(3) / (float) bitmapHeight;
                    float scale = scaleX > scaleY ? scaleY : scaleX;
                    float newScale = newScaleX > newScaleY ? newScaleY : newScaleX;

                    animateToScale = newScale / scale;
                    animateToX = 0;
                    animateToY = (ActionBar.getCurrentActionBarHeight() - AndroidUtilities.dp(48)
                            + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0)) / 2;
                    animationStartTime = System.currentTimeMillis();
                    zoomAnimation = true;
                }

                imageMoveAnimation = new AnimatorSet();
                imageMoveAnimation.playTogether(
                        ObjectAnimator.ofFloat(PhotoViewer.this, "animationValue", 0, 1),
                        ObjectAnimator.ofFloat(photoPaintView.getColorPicker(), "translationX",
                                AndroidUtilities.dp(60), 0),
                        ObjectAnimator.ofFloat(photoPaintView.getToolsView(), "translationY",
                                AndroidUtilities.dp(126), 0),
                        ObjectAnimator.ofFloat(photoPaintView.getActionBar(), "translationY",
                                -ActionBar.getCurrentActionBarHeight()
                                        - (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0),
                                0));
                imageMoveAnimation.setDuration(200);
                imageMoveAnimation.addListener(new AnimatorListenerAdapterProxy() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        photoPaintView.init();
                        imageMoveAnimation = null;
                        currentEditMode = mode;
                        animateToScale = 1;
                        animateToX = 0;
                        animateToY = 0;
                        scale = 1;
                        updateMinMax(scale);
                        containerView.invalidate();
                    }
                });
                imageMoveAnimation.start();
            }
        });
        changeModeAnimation.start();
    }
}

From source file:kr.wdream.ui.PhotoViewer.java

private void switchToEditMode(final int mode) {
    if (currentEditMode == mode || centerImage.getBitmap() == null || changeModeAnimation != null
            || imageMoveAnimation != null || radialProgressViews[0].backgroundState != -1) {
        return;/*from  w  ww .  ja  v  a  2  s.  co  m*/
    }
    if (mode == 0) {
        if (currentEditMode == 2) {
            if (photoFilterView.getToolsView().getVisibility() != View.VISIBLE) {
                photoFilterView.switchToOrFromEditMode();
                return;
            }
        }
        Bitmap bitmap = centerImage.getBitmap();
        if (bitmap != null) {
            int bitmapWidth = centerImage.getBitmapWidth();
            int bitmapHeight = centerImage.getBitmapHeight();

            float scaleX = (float) getContainerViewWidth() / (float) bitmapWidth;
            float scaleY = (float) getContainerViewHeight() / (float) bitmapHeight;
            float newScaleX = (float) getContainerViewWidth(0) / (float) bitmapWidth;
            float newScaleY = (float) getContainerViewHeight(0) / (float) bitmapHeight;
            float scale = scaleX > scaleY ? scaleY : scaleX;
            float newScale = newScaleX > newScaleY ? newScaleY : newScaleX;

            animateToScale = newScale / scale;
            animateToX = 0;
            if (currentEditMode == 1) {
                animateToY = AndroidUtilities.dp(24);
            } else if (currentEditMode == 2) {
                animateToY = AndroidUtilities.dp(62);
            } else if (currentEditMode == 3) {
                animateToY = (AndroidUtilities.dp(48) - ActionBar.getCurrentActionBarHeight()) / 2;
            }
            if (Build.VERSION.SDK_INT >= 21) {
                animateToY -= AndroidUtilities.statusBarHeight / 2;
            }
            animationStartTime = System.currentTimeMillis();
            zoomAnimation = true;
        }

        imageMoveAnimation = new AnimatorSet();
        if (currentEditMode == 1) {
            imageMoveAnimation.playTogether(
                    ObjectAnimator.ofFloat(editorDoneLayout, "translationY", AndroidUtilities.dp(48)),
                    ObjectAnimator.ofFloat(PhotoViewer.this, "animationValue", 0, 1),
                    ObjectAnimator.ofFloat(photoCropView, "alpha", 0));
        } else if (currentEditMode == 2) {
            photoFilterView.shutdown();
            imageMoveAnimation.playTogether(
                    ObjectAnimator.ofFloat(photoFilterView.getToolsView(), "translationY",
                            AndroidUtilities.dp(126)),
                    ObjectAnimator.ofFloat(PhotoViewer.this, "animationValue", 0, 1));
        } else if (currentEditMode == 3) {
            photoPaintView.shutdown();
            imageMoveAnimation.playTogether(
                    ObjectAnimator.ofFloat(photoPaintView.getToolsView(), "translationY",
                            AndroidUtilities.dp(126)),
                    ObjectAnimator.ofFloat(photoPaintView.getColorPicker(), "translationX",
                            AndroidUtilities.dp(60)),
                    ObjectAnimator.ofFloat(photoPaintView.getActionBar(), "translationY",
                            -ActionBar.getCurrentActionBarHeight()
                                    - (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0)),
                    ObjectAnimator.ofFloat(PhotoViewer.this, "animationValue", 0, 1));
        }
        imageMoveAnimation.setDuration(200);
        imageMoveAnimation.addListener(new AnimatorListenerAdapterProxy() {
            @Override
            public void onAnimationEnd(Animator animation) {
                if (currentEditMode == 1) {
                    editorDoneLayout.setVisibility(View.GONE);
                    photoCropView.setVisibility(View.GONE);
                } else if (currentEditMode == 2) {
                    containerView.removeView(photoFilterView);
                    photoFilterView = null;
                } else if (currentEditMode == 3) {
                    containerView.removeView(photoPaintView);
                    photoPaintView = null;
                }
                imageMoveAnimation = null;
                currentEditMode = mode;
                animateToScale = 1;
                animateToX = 0;
                animateToY = 0;
                scale = 1;
                updateMinMax(scale);
                containerView.invalidate();

                AnimatorSet animatorSet = new AnimatorSet();
                ArrayList<Animator> arrayList = new ArrayList<>();
                arrayList.add(ObjectAnimator.ofFloat(pickerView, "translationY", 0));
                arrayList.add(ObjectAnimator.ofFloat(actionBar, "translationY", 0));
                if (needCaptionLayout) {
                    arrayList.add(ObjectAnimator.ofFloat(captionTextView, "translationY", 0));
                }
                if (sendPhotoType == 0) {
                    arrayList.add(ObjectAnimator.ofFloat(checkImageView, "alpha", 1));
                }
                animatorSet.playTogether(arrayList);
                animatorSet.setDuration(200);
                animatorSet.addListener(new AnimatorListenerAdapterProxy() {
                    @Override
                    public void onAnimationStart(Animator animation) {
                        pickerView.setVisibility(View.VISIBLE);
                        actionBar.setVisibility(View.VISIBLE);
                        if (needCaptionLayout) {
                            captionTextView.setVisibility(
                                    captionTextView.getTag() != null ? View.VISIBLE : View.INVISIBLE);
                        }
                        if (sendPhotoType == 0) {
                            checkImageView.setVisibility(View.VISIBLE);
                        }
                    }
                });
                animatorSet.start();
            }
        });
        imageMoveAnimation.start();
    } else if (mode == 1) {
        if (photoCropView == null) {
            photoCropView = new PhotoCropView(actvityContext);
            photoCropView.setVisibility(View.GONE);
            containerView.addView(photoCropView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
                    LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 0, 0, 0, 48));
            photoCropView.setDelegate(new PhotoCropView.PhotoCropViewDelegate() {
                @Override
                public void needMoveImageTo(float x, float y, float s, boolean animated) {
                    if (animated) {
                        animateTo(s, x, y, true);
                    } else {
                        translationX = x;
                        translationY = y;
                        scale = s;
                        containerView.invalidate();
                    }
                }

                @Override
                public Bitmap getBitmap() {
                    return centerImage.getBitmap();
                }
            });
        }

        editorDoneLayout.doneButton
                .setText(LocaleController.getString("Crop", kr.wdream.storyshop.R.string.Crop));
        changeModeAnimation = new AnimatorSet();
        ArrayList<Animator> arrayList = new ArrayList<>();
        arrayList.add(ObjectAnimator.ofFloat(pickerView, "translationY", 0, AndroidUtilities.dp(96)));
        arrayList.add(ObjectAnimator.ofFloat(actionBar, "translationY", 0, -actionBar.getHeight()));
        if (needCaptionLayout) {
            arrayList.add(ObjectAnimator.ofFloat(captionTextView, "translationY", 0, AndroidUtilities.dp(96)));
        }
        if (sendPhotoType == 0) {
            arrayList.add(ObjectAnimator.ofFloat(checkImageView, "alpha", 1, 0));
        }
        changeModeAnimation.playTogether(arrayList);
        changeModeAnimation.setDuration(200);
        changeModeAnimation.addListener(new AnimatorListenerAdapterProxy() {
            @Override
            public void onAnimationEnd(Animator animation) {
                changeModeAnimation = null;
                pickerView.setVisibility(View.GONE);
                if (needCaptionLayout) {
                    captionTextView.setVisibility(View.INVISIBLE);
                }
                if (sendPhotoType == 0) {
                    checkImageView.setVisibility(View.GONE);
                }

                Bitmap bitmap = centerImage.getBitmap();
                if (bitmap != null) {
                    photoCropView.setBitmap(bitmap, centerImage.getOrientation(), sendPhotoType != 1);
                    int bitmapWidth = centerImage.getBitmapWidth();
                    int bitmapHeight = centerImage.getBitmapHeight();

                    float scaleX = (float) getContainerViewWidth() / (float) bitmapWidth;
                    float scaleY = (float) getContainerViewHeight() / (float) bitmapHeight;
                    float newScaleX = (float) getContainerViewWidth(1) / (float) bitmapWidth;
                    float newScaleY = (float) getContainerViewHeight(1) / (float) bitmapHeight;
                    float scale = scaleX > scaleY ? scaleY : scaleX;
                    float newScale = newScaleX > newScaleY ? newScaleY : newScaleX;

                    animateToScale = newScale / scale;
                    animateToX = 0;
                    animateToY = -AndroidUtilities.dp(24)
                            + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight / 2 : 0);
                    animationStartTime = System.currentTimeMillis();
                    zoomAnimation = true;
                }

                imageMoveAnimation = new AnimatorSet();
                imageMoveAnimation.playTogether(
                        ObjectAnimator.ofFloat(editorDoneLayout, "translationY", AndroidUtilities.dp(48), 0),
                        ObjectAnimator.ofFloat(PhotoViewer.this, "animationValue", 0, 1),
                        ObjectAnimator.ofFloat(photoCropView, "alpha", 0, 1));
                imageMoveAnimation.setDuration(200);
                imageMoveAnimation.addListener(new AnimatorListenerAdapterProxy() {
                    @Override
                    public void onAnimationStart(Animator animation) {
                        editorDoneLayout.setVisibility(View.VISIBLE);
                        photoCropView.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        imageMoveAnimation = null;
                        currentEditMode = mode;
                        animateToScale = 1;
                        animateToX = 0;
                        animateToY = 0;
                        scale = 1;
                        updateMinMax(scale);
                        containerView.invalidate();
                    }
                });
                imageMoveAnimation.start();
            }
        });
        changeModeAnimation.start();
    } else if (mode == 2) {
        if (photoFilterView == null) {
            photoFilterView = new PhotoFilterView(parentActivity, centerImage.getBitmap(),
                    centerImage.getOrientation());
            containerView.addView(photoFilterView,
                    LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
            photoFilterView.getDoneTextView().setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    applyCurrentEditMode();
                    switchToEditMode(0);
                }
            });
            photoFilterView.getCancelTextView().setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (photoFilterView.hasChanges()) {
                        if (parentActivity == null) {
                            return;
                        }
                        AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
                        builder.setMessage(LocaleController.getString("DiscardChanges",
                                kr.wdream.storyshop.R.string.DiscardChanges));
                        builder.setTitle(
                                LocaleController.getString("AppName", kr.wdream.storyshop.R.string.AppName));
                        builder.setPositiveButton(
                                LocaleController.getString("OK", kr.wdream.storyshop.R.string.OK),
                                new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialogInterface, int i) {
                                        switchToEditMode(0);
                                    }
                                });
                        builder.setNegativeButton(
                                LocaleController.getString("Cancel", kr.wdream.storyshop.R.string.Cancel),
                                null);
                        showAlertDialog(builder);
                    } else {
                        switchToEditMode(0);
                    }
                }
            });
            photoFilterView.getToolsView().setTranslationY(AndroidUtilities.dp(126));
        }

        changeModeAnimation = new AnimatorSet();
        ArrayList<Animator> arrayList = new ArrayList<>();
        arrayList.add(ObjectAnimator.ofFloat(pickerView, "translationY", 0, AndroidUtilities.dp(96)));
        arrayList.add(ObjectAnimator.ofFloat(actionBar, "translationY", 0, -actionBar.getHeight()));
        if (needCaptionLayout) {
            arrayList.add(ObjectAnimator.ofFloat(captionTextView, "translationY", 0, AndroidUtilities.dp(96)));
        }
        if (sendPhotoType == 0) {
            arrayList.add(ObjectAnimator.ofFloat(checkImageView, "alpha", 1, 0));
        }
        changeModeAnimation.playTogether(arrayList);
        changeModeAnimation.setDuration(200);
        changeModeAnimation.addListener(new AnimatorListenerAdapterProxy() {
            @Override
            public void onAnimationEnd(Animator animation) {
                changeModeAnimation = null;
                pickerView.setVisibility(View.GONE);
                actionBar.setVisibility(View.GONE);
                if (needCaptionLayout) {
                    captionTextView.setVisibility(View.INVISIBLE);
                }
                if (sendPhotoType == 0) {
                    checkImageView.setVisibility(View.GONE);
                }

                Bitmap bitmap = centerImage.getBitmap();
                if (bitmap != null) {
                    int bitmapWidth = centerImage.getBitmapWidth();
                    int bitmapHeight = centerImage.getBitmapHeight();

                    float scaleX = (float) getContainerViewWidth() / (float) bitmapWidth;
                    float scaleY = (float) getContainerViewHeight() / (float) bitmapHeight;
                    float newScaleX = (float) getContainerViewWidth(2) / (float) bitmapWidth;
                    float newScaleY = (float) getContainerViewHeight(2) / (float) bitmapHeight;
                    float scale = scaleX > scaleY ? scaleY : scaleX;
                    float newScale = newScaleX > newScaleY ? newScaleY : newScaleX;

                    animateToScale = newScale / scale;
                    animateToX = 0;
                    animateToY = -AndroidUtilities.dp(62)
                            + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight / 2 : 0);
                    animationStartTime = System.currentTimeMillis();
                    zoomAnimation = true;
                }

                imageMoveAnimation = new AnimatorSet();
                imageMoveAnimation.playTogether(
                        ObjectAnimator.ofFloat(PhotoViewer.this, "animationValue", 0, 1),
                        ObjectAnimator.ofFloat(photoFilterView.getToolsView(), "translationY",
                                AndroidUtilities.dp(126), 0));
                imageMoveAnimation.setDuration(200);
                imageMoveAnimation.addListener(new AnimatorListenerAdapterProxy() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        photoFilterView.init();
                        imageMoveAnimation = null;
                        currentEditMode = mode;
                        animateToScale = 1;
                        animateToX = 0;
                        animateToY = 0;
                        scale = 1;
                        updateMinMax(scale);
                        containerView.invalidate();
                    }
                });
                imageMoveAnimation.start();
            }
        });
        changeModeAnimation.start();
    } else if (mode == 3) {
        if (photoPaintView == null) {
            photoPaintView = new PhotoPaintView(parentActivity, centerImage.getBitmap(),
                    centerImage.getOrientation());
            containerView.addView(photoPaintView,
                    LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
            photoPaintView.getDoneTextView().setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    applyCurrentEditMode();
                    switchToEditMode(0);
                }
            });
            photoPaintView.getCancelTextView().setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    photoPaintView.maybeShowDismissalAlert(PhotoViewer.this, parentActivity, new Runnable() {
                        @Override
                        public void run() {
                            switchToEditMode(0);
                        }
                    });
                }
            });
            photoPaintView.getColorPicker().setTranslationX(AndroidUtilities.dp(60));
            photoPaintView.getToolsView().setTranslationY(AndroidUtilities.dp(126));
            photoPaintView.getActionBar().setTranslationY(-ActionBar.getCurrentActionBarHeight()
                    - (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0));
        }

        changeModeAnimation = new AnimatorSet();
        ArrayList<Animator> arrayList = new ArrayList<>();
        arrayList.add(ObjectAnimator.ofFloat(pickerView, "translationY", 0, AndroidUtilities.dp(96)));
        arrayList.add(ObjectAnimator.ofFloat(actionBar, "translationY", 0, -actionBar.getHeight()));

        if (needCaptionLayout) {
            arrayList.add(ObjectAnimator.ofFloat(captionTextView, "translationY", 0, AndroidUtilities.dp(96)));
        }
        if (sendPhotoType == 0) {
            arrayList.add(ObjectAnimator.ofFloat(checkImageView, "alpha", 1, 0));
        }
        changeModeAnimation.playTogether(arrayList);
        changeModeAnimation.setDuration(200);
        changeModeAnimation.addListener(new AnimatorListenerAdapterProxy() {
            @Override
            public void onAnimationEnd(Animator animation) {
                changeModeAnimation = null;
                pickerView.setVisibility(View.GONE);
                if (needCaptionLayout) {
                    captionTextView.setVisibility(View.INVISIBLE);
                }
                if (sendPhotoType == 0) {
                    checkImageView.setVisibility(View.GONE);
                }

                Bitmap bitmap = centerImage.getBitmap();
                if (bitmap != null) {
                    int bitmapWidth = centerImage.getBitmapWidth();
                    int bitmapHeight = centerImage.getBitmapHeight();

                    float scaleX = (float) getContainerViewWidth() / (float) bitmapWidth;
                    float scaleY = (float) getContainerViewHeight() / (float) bitmapHeight;
                    float newScaleX = (float) getContainerViewWidth(3) / (float) bitmapWidth;
                    float newScaleY = (float) getContainerViewHeight(3) / (float) bitmapHeight;
                    float scale = scaleX > scaleY ? scaleY : scaleX;
                    float newScale = newScaleX > newScaleY ? newScaleY : newScaleX;

                    animateToScale = newScale / scale;
                    animateToX = 0;
                    animateToY = (ActionBar.getCurrentActionBarHeight() - AndroidUtilities.dp(48)
                            + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0)) / 2;
                    animationStartTime = System.currentTimeMillis();
                    zoomAnimation = true;
                }

                imageMoveAnimation = new AnimatorSet();
                imageMoveAnimation.playTogether(
                        ObjectAnimator.ofFloat(PhotoViewer.this, "animationValue", 0, 1),
                        ObjectAnimator.ofFloat(photoPaintView.getColorPicker(), "translationX",
                                AndroidUtilities.dp(60), 0),
                        ObjectAnimator.ofFloat(photoPaintView.getToolsView(), "translationY",
                                AndroidUtilities.dp(126), 0),
                        ObjectAnimator.ofFloat(photoPaintView.getActionBar(), "translationY",
                                -ActionBar.getCurrentActionBarHeight()
                                        - (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0),
                                0));
                imageMoveAnimation.setDuration(200);
                imageMoveAnimation.addListener(new AnimatorListenerAdapterProxy() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        photoPaintView.init();
                        imageMoveAnimation = null;
                        currentEditMode = mode;
                        animateToScale = 1;
                        animateToX = 0;
                        animateToY = 0;
                        scale = 1;
                        updateMinMax(scale);
                        containerView.invalidate();
                    }
                });
                imageMoveAnimation.start();
            }
        });
        changeModeAnimation.start();
    }
}

From source file:org.telegram.ui.ProfileActivity.java

@Override
protected AnimatorSet onCustomTransitionAnimation(final boolean isOpen, final Runnable callback) {
    if (playProfileAnimation && allowProfileAnimation) {
        final AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.setDuration(180);//from  w w  w  .  j  av  a2s . c  om
        if (Build.VERSION.SDK_INT > 15) {
            listView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        }
        ActionBarMenu menu = actionBar.createMenu();
        if (menu.getItem(10) == null) {
            if (animatingItem == null) {
                animatingItem = menu.addItem(10, R.drawable.ic_ab_other);
            }
        }
        if (isOpen) {
            FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) onlineTextView[1]
                    .getLayoutParams();
            layoutParams.rightMargin = (int) (-21 * AndroidUtilities.density + AndroidUtilities.dp(8));
            onlineTextView[1].setLayoutParams(layoutParams);

            int width = (int) Math.ceil(AndroidUtilities.displaySize.x - AndroidUtilities.dp(118 + 8)
                    + 21 * AndroidUtilities.density);
            float width2 = nameTextView[1].getPaint().measureText(nameTextView[1].getText().toString()) * 1.12f
                    + getSideDrawablesSize(nameTextView[1]);
            layoutParams = (FrameLayout.LayoutParams) nameTextView[1].getLayoutParams();
            if (width < width2) {
                layoutParams.width = (int) Math.ceil(width / 1.12f);
            } else {
                layoutParams.width = LayoutHelper.WRAP_CONTENT;
            }
            nameTextView[1].setLayoutParams(layoutParams);

            initialAnimationExtraHeight = AndroidUtilities.dp(88);
            fragmentView.setBackgroundColor(0);
            setAnimationProgress(0);
            ArrayList<Animator> animators = new ArrayList<>();
            animators.add(ObjectAnimator.ofFloat(this, "animationProgress", 0.0f, 1.0f));
            if (writeButton != null) {
                writeButton.setScaleX(0.2f);
                writeButton.setScaleY(0.2f);
                writeButton.setAlpha(0.0f);
                animators.add(ObjectAnimator.ofFloat(writeButton, "scaleX", 1.0f));
                animators.add(ObjectAnimator.ofFloat(writeButton, "scaleY", 1.0f));
                animators.add(ObjectAnimator.ofFloat(writeButton, "alpha", 1.0f));
            }
            for (int a = 0; a < 2; a++) {
                onlineTextView[a].setAlpha(a == 0 ? 1.0f : 0.0f);
                nameTextView[a].setAlpha(a == 0 ? 1.0f : 0.0f);
                animators.add(ObjectAnimator.ofFloat(onlineTextView[a], "alpha", a == 0 ? 0.0f : 1.0f));
                animators.add(ObjectAnimator.ofFloat(nameTextView[a], "alpha", a == 0 ? 0.0f : 1.0f));
            }
            if (animatingItem != null) {
                animatingItem.setAlpha(1.0f);
                animators.add(ObjectAnimator.ofFloat(animatingItem, "alpha", 0.0f));
            }
            animatorSet.playTogether(animators);
        } else {
            initialAnimationExtraHeight = extraHeight;
            ArrayList<Animator> animators = new ArrayList<>();
            animators.add(ObjectAnimator.ofFloat(this, "animationProgress", 1.0f, 0.0f));
            if (writeButton != null) {
                animators.add(ObjectAnimator.ofFloat(writeButton, "scaleX", 0.2f));
                animators.add(ObjectAnimator.ofFloat(writeButton, "scaleY", 0.2f));
                animators.add(ObjectAnimator.ofFloat(writeButton, "alpha", 0.0f));
            }
            for (int a = 0; a < 2; a++) {
                animators.add(ObjectAnimator.ofFloat(onlineTextView[a], "alpha", a == 0 ? 1.0f : 0.0f));
                animators.add(ObjectAnimator.ofFloat(nameTextView[a], "alpha", a == 0 ? 1.0f : 0.0f));
            }
            if (animatingItem != null) {
                animatingItem.setAlpha(0.0f);
                animators.add(ObjectAnimator.ofFloat(animatingItem, "alpha", 1.0f));
            }
            animatorSet.playTogether(animators);
        }
        animatorSet.addListener(new AnimatorListenerAdapterProxy() {
            @Override
            public void onAnimationEnd(Animator animation) {
                if (Build.VERSION.SDK_INT > 15) {
                    listView.setLayerType(View.LAYER_TYPE_NONE, null);
                }
                if (animatingItem != null) {
                    ActionBarMenu menu = actionBar.createMenu();
                    menu.clearItems();
                    animatingItem = null;
                }
                callback.run();
            }
        });
        animatorSet.setInterpolator(new DecelerateInterpolator());

        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public void run() {
                animatorSet.start();
            }
        }, 50);
        return animatorSet;
    }
    return null;
}

From source file:com.android.soma.Launcher.java

/**
 * Bind the items start-end from the list.
 *
 * Implementation of the method from LauncherModel.Callbacks.
 *//*from w  w w. j a  va2s .c om*/
public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
        final boolean forceAnimateIcons) {
    Runnable r = new Runnable() {
        public void run() {
            bindItems(shortcuts, start, end, forceAnimateIcons);
        }
    };
    if (waitUntilResume(r)) {
        return;
    }

    // Get the list of added shortcuts and intersect them with the set of shortcuts here
    final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
    final Collection<Animator> bounceAnims = new ArrayList<Animator>();
    final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
    Workspace workspace = mWorkspace;
    long newShortcutsScreenId = -1;
    for (int i = start; i < end; i++) {
        final ItemInfo item = shortcuts.get(i);

        // Short circuit if we are loading dock items for a configuration which has no dock
        if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT && mHotseat == null) {
            continue;
        }

        switch (item.itemType) {
        case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
        case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
            ShortcutInfo info = (ShortcutInfo) item;
            View shortcut = createShortcut(info);

            /*
             * TODO: FIX collision case
             */
            if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
                CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
                if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
                    throw new RuntimeException("OCCUPIED");
                }
            }

            workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX, item.cellY, 1,
                    1);
            if (animateIcons) {
                // Animate all the applications up now
                shortcut.setAlpha(0f);
                shortcut.setScaleX(0f);
                shortcut.setScaleY(0f);
                bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
                newShortcutsScreenId = item.screenId;
            }
            break;
        case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
            FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
                    (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()), (FolderInfo) item,
                    mIconCache);
            workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX, item.cellY, 1,
                    1);
            break;
        default:
            throw new RuntimeException("Invalid Item Type");
        }
    }

    if (animateIcons) {
        // Animate to the correct page
        if (newShortcutsScreenId > -1) {
            long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
            final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
            final Runnable startBounceAnimRunnable = new Runnable() {
                public void run() {
                    anim.playTogether(bounceAnims);
                    anim.start();
                }
            };
            if (newShortcutsScreenId != currentScreenId) {
                // We post the animation slightly delayed to prevent slowdowns
                // when we are loading right after we return to launcher.
                mWorkspace.postDelayed(new Runnable() {
                    public void run() {
                        mWorkspace.snapToPage(newScreenIndex);
                        mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
                    }
                }, NEW_APPS_PAGE_MOVE_DELAY);
            } else {
                mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
            }
        }
    }
    workspace.requestLayout();
}

From source file:com.android.launcher3.Launcher.java

/**
 * Bind the items start-end from the list.
 *
 * Implementation of the method from LauncherModel.Callbacks.
 *//*w ww  .j a va2  s.  c o m*/
@Override
public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
        final boolean forceAnimateIcons) {
    Runnable r = new Runnable() {
        public void run() {
            bindItems(shortcuts, start, end, forceAnimateIcons);
        }
    };
    if (waitUntilResume(r)) {
        return;
    }

    // Get the list of added shortcuts and intersect them with the set of shortcuts here
    final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
    final Collection<Animator> bounceAnims = new ArrayList<Animator>();
    final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
    Workspace workspace = mWorkspace;
    long newShortcutsScreenId = -1;
    for (int i = start; i < end; i++) {
        final ItemInfo item = shortcuts.get(i);

        // Short circuit if we are loading dock items for a configuration which has no dock
        if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT && mHotseat == null) {
            continue;
        }

        final View view;
        switch (item.itemType) {
        case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
        case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
        case LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT:
            ShortcutInfo info = (ShortcutInfo) item;
            view = createShortcut(info);
            break;
        case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
            view = FolderIcon.fromXml(R.layout.folder_icon, this,
                    (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()), (FolderInfo) item,
                    mIconCache);
            break;
        default:
            throw new RuntimeException("Invalid Item Type");
        }

        /*
        * Remove colliding items.
        */
        if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
            CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
            if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
                View v = cl.getChildAt(item.cellX, item.cellY);
                Object tag = v.getTag();
                String desc = "Collision while binding workspace item: " + item + ". Collides with " + tag;
                if (ProviderConfig.IS_DOGFOOD_BUILD) {
                    throw (new RuntimeException(desc));
                } else {
                    Log.d(TAG, desc);
                    LauncherModel.deleteItemFromDatabase(this, item);
                    continue;
                }
            }
        }
        workspace.addInScreenFromBind(view, item.container, item.screenId, item.cellX, item.cellY, 1, 1);
        if (animateIcons) {
            // Animate all the applications up now
            view.setAlpha(0f);
            view.setScaleX(0f);
            view.setScaleY(0f);
            bounceAnims.add(createNewAppBounceAnimation(view, i));
            newShortcutsScreenId = item.screenId;
        }
    }

    if (animateIcons) {
        // Animate to the correct page
        if (newShortcutsScreenId > -1) {
            long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
            final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
            final Runnable startBounceAnimRunnable = new Runnable() {
                public void run() {
                    anim.playTogether(bounceAnims);
                    anim.start();
                }
            };
            if (newShortcutsScreenId != currentScreenId) {
                // We post the animation slightly delayed to prevent slowdowns
                // when we are loading right after we return to launcher.
                mWorkspace.postDelayed(new Runnable() {
                    public void run() {
                        if (mWorkspace != null) {
                            mWorkspace.snapToPage(newScreenIndex);
                            mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
                        }
                    }
                }, NEW_APPS_PAGE_MOVE_DELAY);
            } else {
                mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
            }
        }
    }
    workspace.requestLayout();
}

From source file:xyz.klinker.blur.launcher3.Launcher.java

/**
 * Bind the items start-end from the list.
 *
 * Implementation of the method from LauncherModel.Callbacks.
 */// w  ww. java2 s . c  o m
@Override
public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
        final boolean forceAnimateIcons) {
    Runnable r = new Runnable() {
        public void run() {
            bindItems(shortcuts, start, end, forceAnimateIcons);
        }
    };
    if (waitUntilResume(r)) {
        return;
    }

    // Get the list of added shortcuts and intersect them with the set of shortcuts here
    final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
    final Collection<Animator> bounceAnims = new ArrayList<Animator>();
    final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
    Workspace workspace = mWorkspace;
    long newShortcutsScreenId = -1;
    for (int i = start; i < end; i++) {
        final ItemInfo item = shortcuts.get(i);

        // Short circuit if we are loading dock items for a configuration which has no dock
        if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT && mHotseat == null) {
            continue;
        }

        final View view;
        switch (item.itemType) {
        case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
        case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
            ShortcutInfo info = (ShortcutInfo) item;
            view = createShortcut(info);

            /*
             * TODO: FIX collision case
             */
            if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
                CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
                if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
                    View v = cl.getChildAt(item.cellX, item.cellY);
                    Object tag = v.getTag();
                    String desc = "Collision while binding workspace item: " + item + ". Collides with " + tag;
                    if (LauncherAppState.isDogfoodBuild()) {
                        throw (new RuntimeException(desc));
                    } else {
                        Log.d(TAG, desc);
                    }
                }
            }
            break;
        case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
            view = FolderIcon.fromXml(R.layout.folder_icon, this,
                    (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()), (FolderInfo) item,
                    mIconCache);
            break;
        default:
            throw new RuntimeException("Invalid Item Type");
        }

        workspace.addInScreenFromBind(view, item.container, item.screenId, item.cellX, item.cellY, 1, 1);
        if (animateIcons) {
            // Animate all the applications up now
            view.setAlpha(0f);
            view.setScaleX(0f);
            view.setScaleY(0f);
            bounceAnims.add(createNewAppBounceAnimation(view, i));
            newShortcutsScreenId = item.screenId;
        }
    }

    if (animateIcons) {
        // Animate to the correct page
        if (newShortcutsScreenId > -1) {
            long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
            final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
            final Runnable startBounceAnimRunnable = new Runnable() {
                public void run() {
                    anim.playTogether(bounceAnims);
                    anim.start();
                }
            };
            if (newShortcutsScreenId != currentScreenId) {
                // We post the animation slightly delayed to prevent slowdowns
                // when we are loading right after we return to launcher.
                mWorkspace.postDelayed(new Runnable() {
                    public void run() {
                        if (mWorkspace != null) {
                            mWorkspace.snapToPage(newScreenIndex);
                            mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
                        }
                    }
                }, NEW_APPS_PAGE_MOVE_DELAY);
            } else {
                mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
            }
        }
    }
    workspace.requestLayout();
}

From source file:org.telegram.ui.ArticleViewer.java

public void close(boolean byBackPress, boolean force) {
    if (parentActivity == null || !isVisible || checkAnimation()) {
        return;/*w  w w . j ava 2s.  c o m*/
    }
    if (fullscreenVideoContainer.getVisibility() == View.VISIBLE) {
        if (customView != null) {
            fullscreenVideoContainer.setVisibility(View.INVISIBLE);
            customViewCallback.onCustomViewHidden();
            fullscreenVideoContainer.removeView(customView);
            customView = null;
        } else if (fullscreenedVideo != null) {
            fullscreenedVideo.exitFullscreen();
        }
        if (!force) {
            return;
        }
    }
    if (isPhotoVisible) {
        closePhoto(!force);
        if (!force) {
            return;
        }
    }
    if (openUrlReqId != 0) {
        ConnectionsManager.getInstance().cancelRequest(openUrlReqId, true);
        openUrlReqId = 0;
        showProgressView(false);
    }
    if (previewsReqId != 0) {
        ConnectionsManager.getInstance().cancelRequest(previewsReqId, true);
        previewsReqId = 0;
        showProgressView(false);
    }
    saveCurrentPagePosition();
    if (byBackPress && !force) {
        if (removeLastPageFromStack()) {
            return;
        }
    }

    try {
        if (visibleDialog != null) {
            visibleDialog.dismiss();
            visibleDialog = null;
        }
    } catch (Exception e) {
        FileLog.e(e);
    }

    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(ObjectAnimator.ofFloat(windowView, "alpha", 0),
            ObjectAnimator.ofFloat(containerView, "alpha", 0.0f),
            ObjectAnimator.ofFloat(windowView, "translationX", 0, AndroidUtilities.dp(56)));
    animationInProgress = 2;
    animationEndRunnable = new Runnable() {
        @Override
        public void run() {
            if (containerView == null) {
                return;
            }
            if (Build.VERSION.SDK_INT >= 18) {
                containerView.setLayerType(View.LAYER_TYPE_NONE, null);
            }
            animationInProgress = 0;
            onClosed();
        }
    };
    animatorSet.setDuration(150);
    animatorSet.setInterpolator(interpolator);
    animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (animationEndRunnable != null) {
                animationEndRunnable.run();
                animationEndRunnable = null;
            }
        }
    });
    transitionAnimationStartTime = System.currentTimeMillis();
    if (Build.VERSION.SDK_INT >= 18) {
        containerView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    }
    animatorSet.start();
}

From source file:com.klinker.android.launcher.launcher3.Launcher.java

/**
 * Bind the items start-end from the list.
 *
 * Implementation of the method from LauncherModel.Callbacks.
 *//*w w w .  j  av a 2  s  .  c o  m*/
public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
        final boolean forceAnimateIcons) {
    Runnable r = new Runnable() {
        public void run() {
            bindItems(shortcuts, start, end, forceAnimateIcons);
        }
    };
    if (waitUntilResume(r)) {
        return;
    }

    // Get the list of added shortcuts and intersect them with the set of shortcuts here
    final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
    final Collection<Animator> bounceAnims = new ArrayList<Animator>();
    final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
    Workspace workspace = mWorkspace;
    long newShortcutsScreenId = -1;
    for (int i = start; i < end; i++) {
        final ItemInfo item = shortcuts.get(i);

        // Short circuit if we are loading dock items for a configuration which has no dock
        if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT && mHotseat == null) {
            continue;
        }

        switch (item.itemType) {
        case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
        case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
            ShortcutInfo info = (ShortcutInfo) item;
            View shortcut = createShortcut(info);

            /*
             * TODO: FIX collision case
             */
            if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
                CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
                if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
                    View v = cl.getChildAt(item.cellX, item.cellY);
                    Object tag = v.getTag();
                    String desc = "Collision while binding workspace item: " + item + ". Collides with " + tag;
                    if (LauncherAppState.isDogfoodBuild()) {
                        throw (new RuntimeException(desc));
                    } else {
                        Log.d(TAG, desc);
                    }
                }
            }

            workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX, item.cellY, 1,
                    1);
            if (animateIcons) {
                // Animate all the applications up now
                shortcut.setAlpha(0f);
                shortcut.setScaleX(0f);
                shortcut.setScaleY(0f);
                bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
                newShortcutsScreenId = item.screenId;
            }
            break;
        case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
            FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
                    (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()), (FolderInfo) item,
                    mIconCache);
            workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX, item.cellY, 1,
                    1);
            break;
        default:
            throw new RuntimeException("Invalid Item Type");
        }
    }

    if (animateIcons) {
        // Animate to the correct page
        if (newShortcutsScreenId > -1) {
            long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
            final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
            final Runnable startBounceAnimRunnable = new Runnable() {
                public void run() {
                    anim.playTogether(bounceAnims);
                    anim.start();
                }
            };
            if (newShortcutsScreenId != currentScreenId) {
                // We post the animation slightly delayed to prevent slowdowns
                // when we are loading right after we return to launcher.
                mWorkspace.postDelayed(new Runnable() {
                    public void run() {
                        if (mWorkspace != null) {
                            mWorkspace.snapToPage(newScreenIndex);
                            mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
                        }
                    }
                }, NEW_APPS_PAGE_MOVE_DELAY);
            } else {
                mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
            }
        }
    }
    workspace.requestLayout();
}

From source file:org.telegram.ui.ArticleViewer.java

public void uncollapse() {
    if (parentActivity == null || !isVisible || checkAnimation()) {
        return;/*w w  w. j  a v a  2  s  .c o  m*/
    }

    /*windowLayoutParams.flags &= ~WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
    WindowManager wm = (WindowManager) parentActivity.getSystemService(Context.WINDOW_SERVICE);
    wm.updateViewLayout(windowView, windowLayoutParams);*/

    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(ObjectAnimator.ofFloat(containerView, "translationX", 0),
            ObjectAnimator.ofFloat(containerView, "translationY", 0),
            ObjectAnimator.ofFloat(windowView, "alpha", 1.0f), ObjectAnimator.ofFloat(listView, "alpha", 1.0f),
            ObjectAnimator.ofFloat(listView, "translationY", 0),
            ObjectAnimator.ofFloat(headerView, "translationY", 0),

            ObjectAnimator.ofFloat(backButton, "scaleX", 1.0f),
            ObjectAnimator.ofFloat(backButton, "scaleY", 1.0f),
            ObjectAnimator.ofFloat(backButton, "translationY", 0),
            ObjectAnimator.ofFloat(shareContainer, "scaleX", 1.0f),
            ObjectAnimator.ofFloat(shareContainer, "translationY", 0),
            ObjectAnimator.ofFloat(shareContainer, "scaleY", 1.0f));
    collapsed = false;
    animationInProgress = 2;
    animationEndRunnable = new Runnable() {
        @Override
        public void run() {
            if (containerView == null) {
                return;
            }
            if (Build.VERSION.SDK_INT >= 18) {
                containerView.setLayerType(View.LAYER_TYPE_NONE, null);
            }
            animationInProgress = 0;
            //onClosed();
        }
    };
    animatorSet.setDuration(250);
    animatorSet.setInterpolator(new DecelerateInterpolator());
    animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (animationEndRunnable != null) {
                animationEndRunnable.run();
                animationEndRunnable = null;
            }
        }
    });
    transitionAnimationStartTime = System.currentTimeMillis();
    if (Build.VERSION.SDK_INT >= 18) {
        containerView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    }
    backDrawable.setRotation(0, true);
    animatorSet.start();
}

From source file:g7.bluesky.launcher3.Launcher.java

/**
 * Bind the items start-end from the list.
 *
 * Implementation of the method from LauncherModel.Callbacks.
 *///from  w  w  w  .  j a v  a 2 s. c  o m
public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
        final boolean forceAnimateIcons) {

    List<ShortcutInfo> shortcutInfos = new ArrayList<>();
    for (ItemInfo itemInfo : shortcuts) {
        if (itemInfo instanceof ShortcutInfo) {
            shortcutInfos.add((ShortcutInfo) itemInfo);
        }
    }
    loadIconPack(shortcutInfos);
    Runnable r = new Runnable() {
        public void run() {
            bindItems(shortcuts, start, end, forceAnimateIcons);
        }
    };
    if (waitUntilResume(r)) {
        return;
    }

    // Get the list of added shortcuts and intersect them with the set of shortcuts here
    final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
    final Collection<Animator> bounceAnims = new ArrayList<Animator>();
    final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
    Workspace workspace = mWorkspace;
    long newShortcutsScreenId = -1;
    for (int i = start; i < end; i++) {
        final ItemInfo item = shortcuts.get(i);

        // Short circuit if we are loading dock items for a configuration which has no dock
        if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT && mHotseat == null) {
            continue;
        }

        switch (item.itemType) {
        case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
        case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
            ShortcutInfo info = (ShortcutInfo) item;
            View shortcut = createShortcut(info);

            /*
             * TODO: FIX collision case
             */
            if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
                CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
                if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
                    View v = cl.getChildAt(item.cellX, item.cellY);
                    Object tag = v.getTag();
                    String desc = "Collision while binding workspace item: " + item + ". Collides with " + tag;
                    if (LauncherAppState.isDogfoodBuild()) {
                        throw (new RuntimeException(desc));
                    } else {
                        Log.d(TAG, desc);
                    }
                }
            }

            workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX, item.cellY, 1,
                    1);
            if (animateIcons) {
                // Animate all the applications up now
                shortcut.setAlpha(0f);
                shortcut.setScaleX(0f);
                shortcut.setScaleY(0f);
                bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
                newShortcutsScreenId = item.screenId;
            }
            break;
        case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
            FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
                    (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()), (FolderInfo) item,
                    mIconCache);
            workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX, item.cellY, 1,
                    1);
            break;
        default:
            throw new RuntimeException("Invalid Item Type");
        }
    }

    if (animateIcons) {
        // Animate to the correct page
        if (newShortcutsScreenId > -1) {
            long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
            final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
            final Runnable startBounceAnimRunnable = new Runnable() {
                public void run() {
                    anim.playTogether(bounceAnims);
                    anim.start();
                }
            };
            if (newShortcutsScreenId != currentScreenId) {
                // We post the animation slightly delayed to prevent slowdowns
                // when we are loading right after we return to launcher.
                mWorkspace.postDelayed(new Runnable() {
                    public void run() {
                        if (mWorkspace != null) {
                            mWorkspace.snapToPage(newScreenIndex);
                            mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
                        }
                    }
                }, NEW_APPS_PAGE_MOVE_DELAY);
            } else {
                mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
            }
        }
    }
    workspace.requestLayout();
}