Example usage for android.animation AnimatorSet addListener

List of usage examples for android.animation AnimatorSet addListener

Introduction

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

Prototype

public void addListener(AnimatorListener listener) 

Source Link

Document

Adds a listener to the set of listeners that are sent events through the life of an animation, such as start, repeat, and end.

Usage

From source file:com.aimfire.demo.CamcorderActivity.java

/**
 * Style 1 animation will simulate a determinate loading
 *
 * @return Animator/*from  w w w.ja  v a2s . com*/
 */
private Animator prepare3DAnimator() {
    final AnimatorSet animatorSet = new AnimatorSet();

    mScanProgDrawable.setIndeterminate(false);
    mScanProgDrawable.setUseRotation(false);
    mScanProgDrawable.setUseArc(false);
    mScanProgDrawable.setUseAlpha(false);
    mScanProgDrawable.setUseWifiBar(true);

    mScanProgDrawable.setMessageText(getString(R.string.scanning));
    mScanProgDrawable.setSuppText(getString(R.string.tap_to_stop));

    //if(!mScanProgDrawable.getMessageText().equals(getString(R.string.connecting)))
    //{
    //mScanProgDrawable.setMessageText(getString(R.string.scanning) + (mAnimCyclesCnt+1) + " of " + CONNECT_ANIM_CYCLES);
    //}

    Animator determinateAnimator = ObjectAnimator.ofFloat(mScanProgDrawable,
            CircularProgressDrawable.PROGRESS_PROPERTY, 0, 1);
    determinateAnimator.setDuration(CONNECT_ANIM_CYCLE_LENGTH_SECONDS * 1000);

    /*
     * wifi bar highlight changes 3 times a second
     */
    Animator wifiBarAnimator = ObjectAnimator.ofInt(mScanProgDrawable,
            CircularProgressDrawable.WIFI_BAR_PROPERTY, 0, 2 * CONNECT_ANIM_CYCLE_LENGTH_SECONDS);
    wifiBarAnimator.setDuration(CONNECT_ANIM_CYCLE_LENGTH_SECONDS * 1000);
    wifiBarAnimator.setInterpolator(new LinearInterpolator());

    animatorSet.playTogether(wifiBarAnimator, determinateAnimator);

    animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animator) {
            restartScanAnim();
        }
    });

    return animatorSet;
}

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

/**
 * Runs a new animation that scales up icons that were added while Launcher was in the
 * background.//w w w.  j av  a2  s.  c  om
 *
 * @param immediate whether to run the animation or show the results immediately
 */
private void runNewAppsAnimation(boolean immediate) {
    AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
    Collection<Animator> bounceAnims = new ArrayList<Animator>();

    // Order these new views spatially so that they animate in order
    Collections.sort(mNewShortcutAnimateViews, new Comparator<View>() {
        @Override
        public int compare(View a, View b) {
            CellLayout.LayoutParams alp = (CellLayout.LayoutParams) a.getLayoutParams();
            CellLayout.LayoutParams blp = (CellLayout.LayoutParams) b.getLayoutParams();
            int cellCountX = LauncherModel.getCellCountX();
            return (alp.cellY * cellCountX + alp.cellX) - (blp.cellY * cellCountX + blp.cellX);
        }
    });

    // Animate each of the views in place (or show them immediately if requested)
    if (immediate) {
        for (View v : mNewShortcutAnimateViews) {
            v.setAlpha(1f);
            v.setScaleX(1f);
            v.setScaleY(1f);
        }
    } else {
        for (int i = 0; i < mNewShortcutAnimateViews.size(); ++i) {
            View v = mNewShortcutAnimateViews.get(i);
            ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
                    PropertyValuesHolder.ofFloat("alpha", 1f), PropertyValuesHolder.ofFloat("scaleX", 1f),
                    PropertyValuesHolder.ofFloat("scaleY", 1f));
            bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
            bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
            bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
            bounceAnims.add(bounceAnim);
        }
        anim.playTogether(bounceAnims);
        anim.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                if (mWorkspace != null) {
                    mWorkspace.postDelayed(mBuildLayersRunnable, 500);
                }
            }
        });
        anim.start();
    }

    // Clean up
    mNewShortcutAnimatePage = -1;
    mNewShortcutAnimateViews.clear();
    new Thread("clearNewAppsThread") {
        public void run() {
            mSharedPrefs.edit().putInt(InstallShortcutReceiver.NEW_APPS_PAGE_KEY, -1)
                    .putStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, null).commit();
        }
    }.start();
}

From source file:org.telegram.ui.Components.ChatAttachAlert.java

@SuppressLint("NewApi")
private void startRevealAnimation(final boolean open) {
    containerView.setTranslationY(0);/*w w w.  ja  va2 s.co  m*/

    final AnimatorSet animatorSet = new AnimatorSet();

    View view = delegate.getRevealView();
    if (view.getVisibility() == View.VISIBLE
            && ((ViewGroup) view.getParent()).getVisibility() == View.VISIBLE) {
        final int coords[] = new int[2];
        view.getLocationInWindow(coords);
        float top;
        if (Build.VERSION.SDK_INT <= 19) {
            top = AndroidUtilities.displaySize.y - containerView.getMeasuredHeight()
                    - AndroidUtilities.statusBarHeight;
        } else {
            top = containerView.getY();
        }
        revealX = coords[0] + view.getMeasuredWidth() / 2;
        revealY = (int) (coords[1] + view.getMeasuredHeight() / 2 - top);
        if (Build.VERSION.SDK_INT <= 19) {
            revealY -= AndroidUtilities.statusBarHeight;
        }
    } else {
        revealX = AndroidUtilities.displaySize.x / 2 + backgroundPaddingLeft;
        revealY = (int) (AndroidUtilities.displaySize.y - containerView.getY());
    }

    int corners[][] = new int[][] { { 0, 0 }, { 0, AndroidUtilities.dp(304) },
            { containerView.getMeasuredWidth(), 0 },
            { containerView.getMeasuredWidth(), AndroidUtilities.dp(304) } };
    int finalRevealRadius = 0;
    int y = revealY - scrollOffsetY + backgroundPaddingTop;
    for (int a = 0; a < 4; a++) {
        finalRevealRadius = Math.max(finalRevealRadius,
                (int) Math.ceil(Math.sqrt((revealX - corners[a][0]) * (revealX - corners[a][0])
                        + (y - corners[a][1]) * (y - corners[a][1]))));
    }
    int finalRevealX = revealX <= containerView.getMeasuredWidth() ? revealX : containerView.getMeasuredWidth();

    ArrayList<Animator> animators = new ArrayList<>(3);
    animators.add(ObjectAnimator.ofFloat(this, "revealRadius", open ? 0 : finalRevealRadius,
            open ? finalRevealRadius : 0));
    animators.add(ObjectAnimator.ofInt(backDrawable, "alpha", open ? 51 : 0));
    if (Build.VERSION.SDK_INT >= 21) {
        try {
            animators.add(ViewAnimationUtils.createCircularReveal(containerView, finalRevealX, revealY,
                    open ? 0 : finalRevealRadius, open ? finalRevealRadius : 0));
        } catch (Exception e) {
            FileLog.e("tmessages", e);
        }
        animatorSet.setDuration(320);
    } else {
        if (!open) {
            animatorSet.setDuration(200);
            containerView.setPivotX(
                    revealX <= containerView.getMeasuredWidth() ? revealX : containerView.getMeasuredWidth());
            containerView.setPivotY(revealY);
            animators.add(ObjectAnimator.ofFloat(containerView, "scaleX", 0.0f));
            animators.add(ObjectAnimator.ofFloat(containerView, "scaleY", 0.0f));
            animators.add(ObjectAnimator.ofFloat(containerView, "alpha", 0.0f));
        } else {
            animatorSet.setDuration(250);
            containerView.setScaleX(1);
            containerView.setScaleY(1);
            containerView.setAlpha(1);
            if (Build.VERSION.SDK_INT <= 19) {
                animatorSet.setStartDelay(20);
            }
        }
    }
    animatorSet.playTogether(animators);
    animatorSet.addListener(new AnimatorListenerAdapter() {
        public void onAnimationEnd(Animator animation) {
            if (currentSheetAnimation != null && currentSheetAnimation.equals(animation)) {
                currentSheetAnimation = null;
                onRevealAnimationEnd(open);
                containerView.invalidate();
                containerView.setLayerType(View.LAYER_TYPE_NONE, null);
                if (!open) {
                    try {
                        dismissInternal();
                    } catch (Exception e) {
                        FileLog.e("tmessages", e);
                    }
                }
            }
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            if (currentSheetAnimation != null && animatorSet.equals(animation)) {
                currentSheetAnimation = null;
            }
        }
    });

    if (open) {
        innerAnimators.clear();
        NotificationCenter.getInstance()
                .setAllowedNotificationsDutingAnimation(new int[] { NotificationCenter.dialogsNeedReload });
        NotificationCenter.getInstance().setAnimationInProgress(true);
        revealAnimationInProgress = true;

        int count = Build.VERSION.SDK_INT <= 19 ? 11 : 8;
        for (int a = 0; a < count; a++) {
            if (Build.VERSION.SDK_INT <= 19) {
                if (a < 8) {
                    views[a].setScaleX(0.1f);
                    views[a].setScaleY(0.1f);
                }
                views[a].setAlpha(0.0f);
            } else {
                views[a].setScaleX(0.7f);
                views[a].setScaleY(0.7f);
            }

            InnerAnimator innerAnimator = new InnerAnimator();

            int buttonX = views[a].getLeft() + views[a].getMeasuredWidth() / 2;
            int buttonY = views[a].getTop() + attachView.getTop() + views[a].getMeasuredHeight() / 2;
            float dist = (float) Math.sqrt(
                    (revealX - buttonX) * (revealX - buttonX) + (revealY - buttonY) * (revealY - buttonY));
            float vecX = (revealX - buttonX) / dist;
            float vecY = (revealY - buttonY) / dist;
            views[a].setPivotX(views[a].getMeasuredWidth() / 2 + vecX * AndroidUtilities.dp(20));
            views[a].setPivotY(views[a].getMeasuredHeight() / 2 + vecY * AndroidUtilities.dp(20));
            innerAnimator.startRadius = dist - AndroidUtilities.dp(27 * 3);

            views[a].setTag(R.string.AppName, 1);
            animators = new ArrayList<>();
            final AnimatorSet animatorSetInner;
            if (a < 8) {
                animators.add(ObjectAnimator.ofFloat(views[a], "scaleX", 0.7f, 1.05f));
                animators.add(ObjectAnimator.ofFloat(views[a], "scaleY", 0.7f, 1.05f));

                animatorSetInner = new AnimatorSet();
                animatorSetInner.playTogether(ObjectAnimator.ofFloat(views[a], "scaleX", 1.0f),
                        ObjectAnimator.ofFloat(views[a], "scaleY", 1.0f));
                animatorSetInner.setDuration(100);
                animatorSetInner.setInterpolator(decelerateInterpolator);
            } else {
                animatorSetInner = null;
            }
            if (Build.VERSION.SDK_INT <= 19) {
                animators.add(ObjectAnimator.ofFloat(views[a], "alpha", 1.0f));
            }
            innerAnimator.animatorSet = new AnimatorSet();
            innerAnimator.animatorSet.playTogether(animators);
            innerAnimator.animatorSet.setDuration(150);
            innerAnimator.animatorSet.setInterpolator(decelerateInterpolator);
            innerAnimator.animatorSet.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    if (animatorSetInner != null) {
                        animatorSetInner.start();
                    }
                }
            });
            innerAnimators.add(innerAnimator);
        }
    }
    currentSheetAnimation = animatorSet;
    animatorSet.start();
}

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  a v  a 2s .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  ww w  . j av a2 s  . c om
    }
    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   ww w  .  j a  v a  2  s.co m
        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:org.telegram.ui.ArticleViewer.java

public void close(boolean byBackPress, boolean force) {
    if (parentActivity == null || !isVisible || checkAnimation()) {
        return;//from  w  w  w. j  a  va 2 s . co 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:org.telegram.ui.ArticleViewer.java

private boolean open(final MessageObject messageObject, boolean first) {
    if (parentActivity == null || isVisible && !collapsed || messageObject == null) {
        return false;
    }/*from   w  w w. j  a va2 s. c o m*/

    if (first) {
        TLRPC.TL_messages_getWebPage req = new TLRPC.TL_messages_getWebPage();
        req.url = messageObject.messageOwner.media.webpage.url;
        if (messageObject.messageOwner.media.webpage.cached_page instanceof TLRPC.TL_pagePart) {
            req.hash = 0;
        } else {
            req.hash = messageObject.messageOwner.media.webpage.hash;
        }
        ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
            @Override
            public void run(TLObject response, TLRPC.TL_error error) {
                if (response instanceof TLRPC.TL_webPage) {
                    final TLRPC.TL_webPage webPage = (TLRPC.TL_webPage) response;
                    if (webPage.cached_page == null) {
                        return;
                    }
                    AndroidUtilities.runOnUIThread(new Runnable() {
                        @Override
                        public void run() {
                            if (!pagesStack.isEmpty()
                                    && pagesStack.get(0) == messageObject.messageOwner.media.webpage
                                    && webPage.cached_page != null) {
                                messageObject.messageOwner.media.webpage = webPage;
                                pagesStack.set(0, webPage);
                                if (pagesStack.size() == 1) {
                                    currentPage = webPage;
                                    ApplicationLoader.applicationContext
                                            .getSharedPreferences("articles", Activity.MODE_PRIVATE).edit()
                                            .remove("article" + currentPage.id).commit();
                                    updateInterfaceForCurrentPage(false);
                                }
                            }
                        }
                    });
                    HashMap<Long, TLRPC.WebPage> webpages = new HashMap<>();
                    webpages.put(webPage.id, webPage);
                    MessagesStorage.getInstance().putWebPages(webpages);
                }
            }
        });
    }

    pagesStack.clear();
    collapsed = false;
    backDrawable.setRotation(0, false);
    containerView.setTranslationX(0);
    containerView.setTranslationY(0);
    listView.setTranslationY(0);
    listView.setAlpha(1.0f);
    windowView.setInnerTranslationX(0);

    actionBar.setVisibility(View.GONE);
    bottomLayout.setVisibility(View.GONE);
    captionTextViewNew.setVisibility(View.GONE);
    captionTextViewOld.setVisibility(View.GONE);
    shareContainer.setAlpha(0.0f);
    backButton.setAlpha(0.0f);
    layoutManager.scrollToPositionWithOffset(0, 0);
    checkScroll(-AndroidUtilities.dp(56));

    TLRPC.WebPage webPage = messageObject.messageOwner.media.webpage;
    String webPageUrl = webPage.url.toLowerCase();
    int index;
    String anchor = null;
    for (int a = 0; a < messageObject.messageOwner.entities.size(); a++) {
        TLRPC.MessageEntity entity = messageObject.messageOwner.entities.get(a);
        if (entity instanceof TLRPC.TL_messageEntityUrl) {
            try {
                String url = messageObject.messageOwner.message
                        .substring(entity.offset, entity.offset + entity.length).toLowerCase();
                if (url.contains(webPageUrl) || webPageUrl.contains(url)) {
                    if ((index = url.lastIndexOf('#')) != -1) {
                        anchor = url.substring(index + 1);
                    }
                    break;
                }
            } catch (Exception e) {
                FileLog.e(e);
            }
        }
    }
    addPageToStack(webPage, anchor);

    lastInsets = null;
    if (!isVisible) {
        WindowManager wm = (WindowManager) parentActivity.getSystemService(Context.WINDOW_SERVICE);
        if (attachedToWindow) {
            try {
                wm.removeView(windowView);
            } catch (Exception e) {
                //ignore
            }
        }
        try {
            if (Build.VERSION.SDK_INT >= 21) {
                windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                        | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
                        | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
            }
            windowLayoutParams.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN
                    | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
            windowView.setFocusable(false);
            containerView.setFocusable(false);
            wm.addView(windowView, windowLayoutParams);
        } catch (Exception e) {
            FileLog.e(e);
            return false;
        }
    } else {
        windowLayoutParams.flags &= ~WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
        WindowManager wm = (WindowManager) parentActivity.getSystemService(Context.WINDOW_SERVICE);
        wm.updateViewLayout(windowView, windowLayoutParams);
    }
    isVisible = true;
    animationInProgress = 1;
    windowView.setAlpha(0);
    containerView.setAlpha(0);

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(ObjectAnimator.ofFloat(windowView, "alpha", 0, 1.0f),
            ObjectAnimator.ofFloat(containerView, "alpha", 0.0f, 1.0f),
            ObjectAnimator.ofFloat(windowView, "translationX", AndroidUtilities.dp(56), 0));

    animationEndRunnable = new Runnable() {
        @Override
        public void run() {
            if (containerView == null || windowView == null) {
                return;
            }
            if (Build.VERSION.SDK_INT >= 18) {
                containerView.setLayerType(View.LAYER_TYPE_NONE, null);
            }
            animationInProgress = 0;
        }
    };

    animatorSet.setDuration(150);
    animatorSet.setInterpolator(interpolator);
    animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public void run() {
                    NotificationCenter.getInstance().setAnimationInProgress(false);
                    if (animationEndRunnable != null) {
                        animationEndRunnable.run();
                        animationEndRunnable = null;
                    }
                }
            });
        }
    });
    transitionAnimationStartTime = System.currentTimeMillis();
    AndroidUtilities.runOnUIThread(new Runnable() {
        @Override
        public void run() {
            NotificationCenter.getInstance()
                    .setAllowedNotificationsDutingAnimation(new int[] { NotificationCenter.dialogsNeedReload,
                            NotificationCenter.closeChats, NotificationCenter.mediaCountDidLoaded,
                            NotificationCenter.mediaDidLoaded, NotificationCenter.dialogPhotosLoaded });
            NotificationCenter.getInstance().setAnimationInProgress(true);
            animatorSet.start();
        }
    });
    if (Build.VERSION.SDK_INT >= 18) {
        containerView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    }
    showActionBar(200);
    return true;
}

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

public boolean openPhoto(final MessageObject messageObject, final TLRPC.FileLocation fileLocation,
        final ArrayList<MessageObject> messages, final ArrayList<Object> photos, final int index,
        final PhotoViewerProvider provider, ChatActivity chatActivity, long dialogId, long mDialogId) {
    if (parentActivity == null || isVisible || provider == null && checkAnimation()
            || messageObject == null && fileLocation == null && messages == null && photos == null) {
        return false;
    }/*  w  w  w. j ava2  s  .c  o  m*/

    final PlaceProviderObject object = provider.getPlaceForPhoto(messageObject, fileLocation, index);
    if (object == null && photos == null) {
        return false;
    }

    WindowManager wm = (WindowManager) parentActivity.getSystemService(Context.WINDOW_SERVICE);
    if (attachedToWindow) {
        try {
            wm.removeView(windowView);
        } catch (Exception e) {
            //don't promt
        }
    }

    try {
        windowLayoutParams.type = WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
        if (Build.VERSION.SDK_INT >= 21) {
            windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                    | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
                    | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                    | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
        } else {
            windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
        }
        windowLayoutParams.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
                | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION;
        windowView.setFocusable(false);
        containerView.setFocusable(false);
        wm.addView(windowView, windowLayoutParams);
    } catch (Exception e) {
        FileLog.e("tmessages", e);
        return false;
    }

    parentChatActivity = chatActivity;

    actionBar.setTitle(LocaleController.formatString("Of", R.string.Of, 1, 1));
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileDidFailedLoad);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileDidLoaded);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileLoadProgressChanged);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.mediaCountDidLoaded);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.mediaDidLoaded);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.dialogPhotosLoaded);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.emojiDidLoaded);

    placeProvider = provider;
    mergeDialogId = mDialogId;
    currentDialogId = dialogId;

    if (velocityTracker == null) {
        velocityTracker = VelocityTracker.obtain();
    }

    isVisible = true;
    toggleActionBar(true, false);

    if (object != null) {
        disableShowCheck = true;
        animationInProgress = 1;
        if (messageObject != null) {
            currentAnimation = object.imageReceiver.getAnimation();
        }

        onPhotoShow(messageObject, fileLocation, messages, photos, index, object);

        final Rect drawRegion = object.imageReceiver.getDrawRegion();
        int orientation = object.imageReceiver.getOrientation();
        int animatedOrientation = object.imageReceiver.getAnimatedOrientation();
        if (animatedOrientation != 0) {
            orientation = animatedOrientation;
        }

        animatingImageView.setVisibility(View.VISIBLE);
        animatingImageView.setRadius(object.radius);
        animatingImageView.setOrientation(orientation);
        animatingImageView.setNeedRadius(object.radius != 0);
        animatingImageView.setImageBitmap(object.thumb);

        animatingImageView.setAlpha(1.0f);
        animatingImageView.setPivotX(0.0f);
        animatingImageView.setPivotY(0.0f);
        animatingImageView.setScaleX(object.scale);
        animatingImageView.setScaleY(object.scale);
        animatingImageView.setTranslationX(object.viewX + drawRegion.left * object.scale);
        animatingImageView.setTranslationY(object.viewY + drawRegion.top * object.scale);
        final ViewGroup.LayoutParams layoutParams = animatingImageView.getLayoutParams();
        layoutParams.width = (drawRegion.right - drawRegion.left);
        layoutParams.height = (drawRegion.bottom - drawRegion.top);
        animatingImageView.setLayoutParams(layoutParams);

        float scaleX = (float) AndroidUtilities.displaySize.x / layoutParams.width;
        float scaleY = (float) (AndroidUtilities.displaySize.y
                + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0)) / layoutParams.height;
        float scale = scaleX > scaleY ? scaleY : scaleX;
        float width = layoutParams.width * scale;
        float height = layoutParams.height * scale;
        float xPos = (AndroidUtilities.displaySize.x - width) / 2.0f;
        float yPos = ((AndroidUtilities.displaySize.y
                + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0)) - height) / 2.0f;
        int clipHorizontal = Math.abs(drawRegion.left - object.imageReceiver.getImageX());
        int clipVertical = Math.abs(drawRegion.top - object.imageReceiver.getImageY());

        int coords2[] = new int[2];
        object.parentView.getLocationInWindow(coords2);
        int clipTop = coords2[1] - (Build.VERSION.SDK_INT >= 21 ? 0 : AndroidUtilities.statusBarHeight)
                - (object.viewY + drawRegion.top) + object.clipTopAddition;
        if (clipTop < 0) {
            clipTop = 0;
        }
        int clipBottom = (object.viewY + drawRegion.top + layoutParams.height)
                - (coords2[1] + object.parentView.getHeight()
                        - (Build.VERSION.SDK_INT >= 21 ? 0 : AndroidUtilities.statusBarHeight))
                + object.clipBottomAddition;
        if (clipBottom < 0) {
            clipBottom = 0;
        }
        clipTop = Math.max(clipTop, clipVertical);
        clipBottom = Math.max(clipBottom, clipVertical);

        animationValues[0][0] = animatingImageView.getScaleX();
        animationValues[0][1] = animatingImageView.getScaleY();
        animationValues[0][2] = animatingImageView.getTranslationX();
        animationValues[0][3] = animatingImageView.getTranslationY();
        animationValues[0][4] = clipHorizontal * object.scale;
        animationValues[0][5] = clipTop * object.scale;
        animationValues[0][6] = clipBottom * object.scale;
        animationValues[0][7] = animatingImageView.getRadius();

        animationValues[1][0] = scale;
        animationValues[1][1] = scale;
        animationValues[1][2] = xPos;
        animationValues[1][3] = yPos;
        animationValues[1][4] = 0;
        animationValues[1][5] = 0;
        animationValues[1][6] = 0;
        animationValues[1][7] = 0;

        animatingImageView.setAnimationProgress(0);
        backgroundDrawable.setAlpha(0);
        containerView.setAlpha(0);

        final AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playTogether(ObjectAnimator.ofFloat(animatingImageView, "animationProgress", 0.0f, 1.0f),
                ObjectAnimator.ofInt(backgroundDrawable, "alpha", 0, 255),
                ObjectAnimator.ofFloat(containerView, "alpha", 0.0f, 1.0f));

        animationEndRunnable = new Runnable() {
            @Override
            public void run() {
                if (containerView == null || windowView == null) {
                    return;
                }
                if (Build.VERSION.SDK_INT >= 18) {
                    containerView.setLayerType(View.LAYER_TYPE_NONE, null);
                }
                animationInProgress = 0;
                transitionAnimationStartTime = 0;
                setImages();
                containerView.invalidate();
                animatingImageView.setVisibility(View.GONE);
                if (showAfterAnimation != null) {
                    showAfterAnimation.imageReceiver.setVisible(true, true);
                }
                if (hideAfterAnimation != null) {
                    hideAfterAnimation.imageReceiver.setVisible(false, true);
                }
                if (photos != null && sendPhotoType != 3) {
                    if (Build.VERSION.SDK_INT >= 21) {
                        windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                                | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
                                | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
                    } else {
                        windowLayoutParams.flags = 0;
                    }
                    windowLayoutParams.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
                            | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION;
                    WindowManager wm = (WindowManager) parentActivity.getSystemService(Context.WINDOW_SERVICE);
                    wm.updateViewLayout(windowView, windowLayoutParams);
                    windowView.setFocusable(true);
                    containerView.setFocusable(true);
                }
            }
        };

        animatorSet.setDuration(200);
        animatorSet.addListener(new AnimatorListenerAdapterProxy() {
            @Override
            public void onAnimationEnd(Animator animation) {
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public void run() {
                        NotificationCenter.getInstance().setAnimationInProgress(false);
                        if (animationEndRunnable != null) {
                            animationEndRunnable.run();
                            animationEndRunnable = null;
                        }
                    }
                });
            }
        });
        transitionAnimationStartTime = System.currentTimeMillis();
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public void run() {
                NotificationCenter.getInstance()
                        .setAllowedNotificationsDutingAnimation(new int[] {
                                NotificationCenter.dialogsNeedReload, NotificationCenter.closeChats,
                                NotificationCenter.mediaCountDidLoaded, NotificationCenter.mediaDidLoaded,
                                NotificationCenter.dialogPhotosLoaded });
                NotificationCenter.getInstance().setAnimationInProgress(true);
                animatorSet.start();
            }
        });
        if (Build.VERSION.SDK_INT >= 18) {
            containerView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        }
        backgroundDrawable.drawRunnable = new Runnable() {
            @Override
            public void run() {
                disableShowCheck = false;
                object.imageReceiver.setVisible(false, true);
            }
        };
    } else {
        if (photos != null && sendPhotoType != 3) {
            if (Build.VERSION.SDK_INT >= 21) {
                windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                        | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
                        | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
            } else {
                windowLayoutParams.flags = 0;
            }
            windowLayoutParams.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
                    | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION;
            wm.updateViewLayout(windowView, windowLayoutParams);
            windowView.setFocusable(true);
            containerView.setFocusable(true);
        }

        backgroundDrawable.setAlpha(255);
        containerView.setAlpha(1.0f);
        onPhotoShow(messageObject, fileLocation, messages, photos, index, object);
    }
    return true;
}

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

public boolean openPhoto(final MessageObject messageObject, final TLRPC.FileLocation fileLocation,
        final ArrayList<MessageObject> messages, final ArrayList<Object> photos, final int index,
        final PhotoViewerProvider provider, ChatActivity chatActivity, long dialogId, long mDialogId) {
    if (parentActivity == null || isVisible || provider == null && checkAnimation()
            || messageObject == null && fileLocation == null && messages == null && photos == null) {
        return false;
    }/* ww w .java  2  s  . c om*/

    final PlaceProviderObject object = provider.getPlaceForPhoto(messageObject, fileLocation, index);
    if (object == null && photos == null) {
        return false;
    }

    WindowManager wm = (WindowManager) parentActivity.getSystemService(Context.WINDOW_SERVICE);
    if (attachedToWindow) {
        try {
            wm.removeView(windowView);
        } catch (Exception e) {
            //don't promt
        }
    }

    try {
        windowLayoutParams.type = WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
        if (Build.VERSION.SDK_INT >= 21) {
            windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                    | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
                    | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                    | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
        } else {
            windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
        }
        windowLayoutParams.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
                | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION;
        windowView.setFocusable(false);
        containerView.setFocusable(false);
        wm.addView(windowView, windowLayoutParams);
    } catch (Exception e) {
        FileLog.e("tmessages", e);
        return false;
    }

    parentChatActivity = chatActivity;

    actionBar.setTitle(LocaleController.formatString("Of", kr.wdream.storyshop.R.string.Of, 1, 1));
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileDidFailedLoad);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileDidLoaded);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileLoadProgressChanged);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.mediaCountDidLoaded);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.mediaDidLoaded);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.dialogPhotosLoaded);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.emojiDidLoaded);

    placeProvider = provider;
    mergeDialogId = mDialogId;
    currentDialogId = dialogId;

    if (velocityTracker == null) {
        velocityTracker = VelocityTracker.obtain();
    }

    isVisible = true;
    toggleActionBar(true, false);

    if (object != null) {
        disableShowCheck = true;
        animationInProgress = 1;
        if (messageObject != null) {
            currentAnimation = object.imageReceiver.getAnimation();
        }

        onPhotoShow(messageObject, fileLocation, messages, photos, index, object);

        final Rect drawRegion = object.imageReceiver.getDrawRegion();
        int orientation = object.imageReceiver.getOrientation();
        int animatedOrientation = object.imageReceiver.getAnimatedOrientation();
        if (animatedOrientation != 0) {
            orientation = animatedOrientation;
        }

        animatingImageView.setVisibility(View.VISIBLE);
        animatingImageView.setRadius(object.radius);
        animatingImageView.setOrientation(orientation);
        animatingImageView.setNeedRadius(object.radius != 0);
        animatingImageView.setImageBitmap(object.thumb);

        animatingImageView.setAlpha(1.0f);
        animatingImageView.setPivotX(0.0f);
        animatingImageView.setPivotY(0.0f);
        animatingImageView.setScaleX(object.scale);
        animatingImageView.setScaleY(object.scale);
        animatingImageView.setTranslationX(object.viewX + drawRegion.left * object.scale);
        animatingImageView.setTranslationY(object.viewY + drawRegion.top * object.scale);
        final ViewGroup.LayoutParams layoutParams = animatingImageView.getLayoutParams();
        layoutParams.width = (drawRegion.right - drawRegion.left);
        layoutParams.height = (drawRegion.bottom - drawRegion.top);
        animatingImageView.setLayoutParams(layoutParams);

        float scaleX = (float) AndroidUtilities.displaySize.x / layoutParams.width;
        float scaleY = (float) (AndroidUtilities.displaySize.y
                + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0)) / layoutParams.height;
        float scale = scaleX > scaleY ? scaleY : scaleX;
        float width = layoutParams.width * scale;
        float height = layoutParams.height * scale;
        float xPos = (AndroidUtilities.displaySize.x - width) / 2.0f;
        float yPos = ((AndroidUtilities.displaySize.y
                + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0)) - height) / 2.0f;
        int clipHorizontal = Math.abs(drawRegion.left - object.imageReceiver.getImageX());
        int clipVertical = Math.abs(drawRegion.top - object.imageReceiver.getImageY());

        int coords2[] = new int[2];
        object.parentView.getLocationInWindow(coords2);
        int clipTop = coords2[1] - (Build.VERSION.SDK_INT >= 21 ? 0 : AndroidUtilities.statusBarHeight)
                - (object.viewY + drawRegion.top) + object.clipTopAddition;
        if (clipTop < 0) {
            clipTop = 0;
        }
        int clipBottom = (object.viewY + drawRegion.top + layoutParams.height)
                - (coords2[1] + object.parentView.getHeight()
                        - (Build.VERSION.SDK_INT >= 21 ? 0 : AndroidUtilities.statusBarHeight))
                + object.clipBottomAddition;
        if (clipBottom < 0) {
            clipBottom = 0;
        }
        clipTop = Math.max(clipTop, clipVertical);
        clipBottom = Math.max(clipBottom, clipVertical);

        animationValues[0][0] = animatingImageView.getScaleX();
        animationValues[0][1] = animatingImageView.getScaleY();
        animationValues[0][2] = animatingImageView.getTranslationX();
        animationValues[0][3] = animatingImageView.getTranslationY();
        animationValues[0][4] = clipHorizontal * object.scale;
        animationValues[0][5] = clipTop * object.scale;
        animationValues[0][6] = clipBottom * object.scale;
        animationValues[0][7] = animatingImageView.getRadius();

        animationValues[1][0] = scale;
        animationValues[1][1] = scale;
        animationValues[1][2] = xPos;
        animationValues[1][3] = yPos;
        animationValues[1][4] = 0;
        animationValues[1][5] = 0;
        animationValues[1][6] = 0;
        animationValues[1][7] = 0;

        animatingImageView.setAnimationProgress(0);
        backgroundDrawable.setAlpha(0);
        containerView.setAlpha(0);

        final AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playTogether(ObjectAnimator.ofFloat(animatingImageView, "animationProgress", 0.0f, 1.0f),
                ObjectAnimator.ofInt(backgroundDrawable, "alpha", 0, 255),
                ObjectAnimator.ofFloat(containerView, "alpha", 0.0f, 1.0f));

        animationEndRunnable = new Runnable() {
            @Override
            public void run() {
                if (containerView == null || windowView == null) {
                    return;
                }
                if (Build.VERSION.SDK_INT >= 18) {
                    containerView.setLayerType(View.LAYER_TYPE_NONE, null);
                }
                animationInProgress = 0;
                transitionAnimationStartTime = 0;
                setImages();
                containerView.invalidate();
                animatingImageView.setVisibility(View.GONE);
                if (showAfterAnimation != null) {
                    showAfterAnimation.imageReceiver.setVisible(true, true);
                }
                if (hideAfterAnimation != null) {
                    hideAfterAnimation.imageReceiver.setVisible(false, true);
                }
                if (photos != null && sendPhotoType != 3) {
                    if (Build.VERSION.SDK_INT >= 21) {
                        windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                                | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
                                | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
                    } else {
                        windowLayoutParams.flags = 0;
                    }
                    windowLayoutParams.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
                            | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION;
                    WindowManager wm = (WindowManager) parentActivity.getSystemService(Context.WINDOW_SERVICE);
                    wm.updateViewLayout(windowView, windowLayoutParams);
                    windowView.setFocusable(true);
                    containerView.setFocusable(true);
                }
            }
        };

        animatorSet.setDuration(200);
        animatorSet.addListener(new AnimatorListenerAdapterProxy() {
            @Override
            public void onAnimationEnd(Animator animation) {
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public void run() {
                        NotificationCenter.getInstance().setAnimationInProgress(false);
                        if (animationEndRunnable != null) {
                            animationEndRunnable.run();
                            animationEndRunnable = null;
                        }
                    }
                });
            }
        });
        transitionAnimationStartTime = System.currentTimeMillis();
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public void run() {
                NotificationCenter.getInstance()
                        .setAllowedNotificationsDutingAnimation(new int[] {
                                NotificationCenter.dialogsNeedReload, NotificationCenter.closeChats,
                                NotificationCenter.mediaCountDidLoaded, NotificationCenter.mediaDidLoaded,
                                NotificationCenter.dialogPhotosLoaded });
                NotificationCenter.getInstance().setAnimationInProgress(true);
                animatorSet.start();
            }
        });
        if (Build.VERSION.SDK_INT >= 18) {
            containerView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        }
        backgroundDrawable.drawRunnable = new Runnable() {
            @Override
            public void run() {
                disableShowCheck = false;
                object.imageReceiver.setVisible(false, true);
            }
        };
    } else {
        if (photos != null && sendPhotoType != 3) {
            if (Build.VERSION.SDK_INT >= 21) {
                windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                        | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
                        | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
            } else {
                windowLayoutParams.flags = 0;
            }
            windowLayoutParams.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
                    | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION;
            wm.updateViewLayout(windowView, windowLayoutParams);
            windowView.setFocusable(true);
            containerView.setFocusable(true);
        }

        backgroundDrawable.setAlpha(255);
        containerView.setAlpha(1.0f);
        onPhotoShow(messageObject, fileLocation, messages, photos, index, object);
    }
    return true;
}