List of usage examples for android.animation AnimatorSet setDuration
@Override public AnimatorSet setDuration(long duration)
From source file:org.telegram.ui.ArticleViewer.java
public boolean openPhoto(TLRPC.PageBlock block) { if (parentActivity == null || isPhotoVisible || checkPhotoAnimation() || block == null) { return false; }/*from w w w . j av a 2s . c o m*/ final PlaceProviderObject object = getPlaceForPhoto(block); if (object == null) { return false; } NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileDidFailedLoad); NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileDidLoaded); NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileLoadProgressChanged); NotificationCenter.getInstance().addObserver(this, NotificationCenter.emojiDidLoaded); if (velocityTracker == null) { velocityTracker = VelocityTracker.obtain(); } isPhotoVisible = true; toggleActionBar(true, false); actionBar.setAlpha(0.0f); bottomLayout.setAlpha(0.0f); captionTextView.setAlpha(0.0f); photoBackgroundDrawable.setAlpha(0); disableShowCheck = true; photoAnimationInProgress = 1; if (block != null) { currentAnimation = object.imageReceiver.getAnimation(); } int index = photoBlocks.indexOf(block); imagesArr.clear(); if (!(block instanceof TLRPC.TL_pageBlockVideo) || isVideoBlock(block)) { imagesArr.addAll(photoBlocks); } else { imagesArr.add(block); index = 0; } onPhotoShow(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 + AndroidUtilities.statusBarHeight) / 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; if (Build.VERSION.SDK_INT >= 21 && lastInsets != null) { xPos += ((WindowInsets) lastInsets).getSystemWindowInsetLeft(); } float yPos = ((AndroidUtilities.displaySize.y + AndroidUtilities.statusBarHeight) - 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] - (object.viewY + drawRegion.top) + object.clipTopAddition; if (clipTop < 0) { clipTop = 0; } int clipBottom = (object.viewY + drawRegion.top + layoutParams.height) - (coords2[1] + object.parentView.getHeight()) + 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; photoContainerView.setVisibility(View.VISIBLE); photoContainerBackground.setVisibility(View.VISIBLE); animatingImageView.setAnimationProgress(0); final AnimatorSet animatorSet = new AnimatorSet(); animatorSet.playTogether(ObjectAnimator.ofFloat(animatingImageView, "animationProgress", 0.0f, 1.0f), ObjectAnimator.ofInt(photoBackgroundDrawable, "alpha", 0, 255), ObjectAnimator.ofFloat(actionBar, "alpha", 0, 1.0f), ObjectAnimator.ofFloat(bottomLayout, "alpha", 0, 1.0f), ObjectAnimator.ofFloat(captionTextView, "alpha", 0, 1.0f)); photoAnimationEndRunnable = new Runnable() { @Override public void run() { if (photoContainerView == null) { return; } if (Build.VERSION.SDK_INT >= 18) { photoContainerView.setLayerType(View.LAYER_TYPE_NONE, null); } photoAnimationInProgress = 0; photoTransitionAnimationStartTime = 0; setImages(); photoContainerView.invalidate(); animatingImageView.setVisibility(View.GONE); if (showAfterAnimation != null) { showAfterAnimation.imageReceiver.setVisible(true, true); } if (hideAfterAnimation != null) { hideAfterAnimation.imageReceiver.setVisible(false, true); } } }; animatorSet.setDuration(200); animatorSet.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { NotificationCenter.getInstance().setAnimationInProgress(false); if (photoAnimationEndRunnable != null) { photoAnimationEndRunnable.run(); photoAnimationEndRunnable = null; } } }); } }); photoTransitionAnimationStartTime = 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) { photoContainerView.setLayerType(View.LAYER_TYPE_HARDWARE, null); } photoBackgroundDrawable.drawRunnable = new Runnable() { @Override public void run() { disableShowCheck = false; object.imageReceiver.setVisible(false, true); } }; return true; }
From source file:com.xhr.launcher.Workspace.java
Animator getChangeStateAnimation(final State state, boolean animated, int delay, int snapPage) { if (mState == state) { return null; }// w w w.j a v a 2s . com // Initialize animation arrays for the first time if necessary initAnimationArrays(); AnimatorSet anim = animated ? LauncherAnimUtils.createAnimatorSet() : null; final State oldState = mState; final boolean oldStateIsNormal = (oldState == State.NORMAL); final boolean oldStateIsSpringLoaded = (oldState == State.SPRING_LOADED); final boolean oldStateIsSmall = (oldState == State.SMALL); final boolean oldStateIsOverview = (oldState == State.OVERVIEW); setState(state); final boolean stateIsNormal = (state == State.NORMAL); final boolean stateIsSpringLoaded = (state == State.SPRING_LOADED); final boolean stateIsSmall = (state == State.SMALL); final boolean stateIsOverview = (state == State.OVERVIEW); float finalBackgroundAlpha = (stateIsSpringLoaded || stateIsOverview) ? 1.0f : 0f; float finalHotseatAndPageIndicatorAlpha = (stateIsOverview || stateIsSmall) ? 0f : 1f; float finalOverviewPanelAlpha = stateIsOverview ? 1f : 0f; float finalSearchBarAlpha = !stateIsNormal ? 0f : 1f; float finalWorkspaceTranslationY = stateIsOverview ? getOverviewModeTranslationY() : 0; boolean workspaceToAllApps = (oldStateIsNormal && stateIsSmall); boolean allAppsToWorkspace = (oldStateIsSmall && stateIsNormal); boolean workspaceToOverview = (oldStateIsNormal && stateIsOverview); boolean overviewToWorkspace = (oldStateIsOverview && stateIsNormal); mNewScale = 1.0f; if (oldStateIsOverview) { disableFreeScroll(snapPage); } else if (stateIsOverview) { enableFreeScroll(); } if (state != State.NORMAL) { if (stateIsSpringLoaded) { mNewScale = mSpringLoadedShrinkFactor; } else if (stateIsOverview) { mNewScale = mOverviewModeShrinkFactor; } else if (stateIsSmall) { mNewScale = mOverviewModeShrinkFactor - 0.3f; } if (workspaceToAllApps) { updateChildrenLayersEnabled(false); } } final int duration; if (workspaceToAllApps) { duration = getResources().getInteger(R.integer.config_workspaceUnshrinkTime); } else if (workspaceToOverview || overviewToWorkspace) { duration = getResources().getInteger(R.integer.config_overviewTransitionTime); } else { duration = getResources().getInteger(R.integer.config_appsCustomizeWorkspaceShrinkTime); } for (int i = 0; i < getChildCount(); i++) { final CellLayout cl = (CellLayout) getChildAt(i); boolean isCurrentPage = (i == getNextPage()); float initialAlpha = cl.getShortcutsAndWidgets().getAlpha(); float finalAlpha = stateIsSmall ? 0f : 1f; // If we are animating to/from the small state, then hide the side pages and fade the // current page in if (!mIsSwitchingState) { if (workspaceToAllApps || allAppsToWorkspace) { if (allAppsToWorkspace && isCurrentPage) { initialAlpha = 0f; } else if (!isCurrentPage) { initialAlpha = finalAlpha = 0f; } cl.setShortcutAndWidgetAlpha(initialAlpha); } } mOldAlphas[i] = initialAlpha; mNewAlphas[i] = finalAlpha; if (animated) { mOldBackgroundAlphas[i] = cl.getBackgroundAlpha(); mNewBackgroundAlphas[i] = finalBackgroundAlpha; } else { cl.setBackgroundAlpha(finalBackgroundAlpha); cl.setShortcutAndWidgetAlpha(finalAlpha); } } final View searchBar = mLauncher.getQsbBar(); final View overviewPanel = mLauncher.getOverviewPanel(); final View hotseat = mLauncher.getHotseat(); if (animated) { anim.setDuration(duration); LauncherViewPropertyAnimator scale = new LauncherViewPropertyAnimator(this); scale.scaleX(mNewScale).scaleY(mNewScale).translationY(finalWorkspaceTranslationY) .setInterpolator(mZoomInInterpolator); anim.play(scale); for (int index = 0; index < getChildCount(); index++) { final int i = index; final CellLayout cl = (CellLayout) getChildAt(i); float currentAlpha = cl.getShortcutsAndWidgets().getAlpha(); if (mOldAlphas[i] == 0 && mNewAlphas[i] == 0) { cl.setBackgroundAlpha(mNewBackgroundAlphas[i]); cl.setShortcutAndWidgetAlpha(mNewAlphas[i]); } else { if (mOldAlphas[i] != mNewAlphas[i] || currentAlpha != mNewAlphas[i]) { LauncherViewPropertyAnimator alphaAnim = new LauncherViewPropertyAnimator( cl.getShortcutsAndWidgets()); alphaAnim.alpha(mNewAlphas[i]).setInterpolator(mZoomInInterpolator); anim.play(alphaAnim); } if (mOldBackgroundAlphas[i] != 0 || mNewBackgroundAlphas[i] != 0) { ValueAnimator bgAnim = LauncherAnimUtils.ofFloat(cl, 0f, 1f); bgAnim.setInterpolator(mZoomInInterpolator); bgAnim.addUpdateListener(new LauncherAnimatorUpdateListener() { public void onAnimationUpdate(float a, float b) { cl.setBackgroundAlpha(a * mOldBackgroundAlphas[i] + b * mNewBackgroundAlphas[i]); } }); anim.play(bgAnim); } } } ObjectAnimator pageIndicatorAlpha = null; if (getPageIndicator() != null) { pageIndicatorAlpha = ObjectAnimator.ofFloat(getPageIndicator(), "alpha", finalHotseatAndPageIndicatorAlpha); } ObjectAnimator hotseatAlpha = ObjectAnimator.ofFloat(hotseat, "alpha", finalHotseatAndPageIndicatorAlpha); ObjectAnimator searchBarAlpha = ObjectAnimator.ofFloat(searchBar, "alpha", finalSearchBarAlpha); ObjectAnimator overviewPanelAlpha = ObjectAnimator.ofFloat(overviewPanel, "alpha", finalOverviewPanelAlpha); overviewPanelAlpha.addListener(new AlphaUpdateListener(overviewPanel)); hotseatAlpha.addListener(new AlphaUpdateListener(hotseat)); searchBarAlpha.addListener(new AlphaUpdateListener(searchBar)); if (workspaceToOverview) { hotseatAlpha.setInterpolator(new DecelerateInterpolator(2)); } else if (overviewToWorkspace) { overviewPanelAlpha.setInterpolator(new DecelerateInterpolator(2)); } if (getPageIndicator() != null) { pageIndicatorAlpha.addListener(new AlphaUpdateListener(getPageIndicator())); } anim.play(overviewPanelAlpha); anim.play(hotseatAlpha); anim.play(searchBarAlpha); anim.play(pageIndicatorAlpha); anim.setStartDelay(delay); } else { overviewPanel.setAlpha(finalOverviewPanelAlpha); AlphaUpdateListener.updateVisibility(overviewPanel); hotseat.setAlpha(finalHotseatAndPageIndicatorAlpha); AlphaUpdateListener.updateVisibility(hotseat); if (getPageIndicator() != null) { getPageIndicator().setAlpha(finalHotseatAndPageIndicatorAlpha); AlphaUpdateListener.updateVisibility(getPageIndicator()); } searchBar.setAlpha(finalSearchBarAlpha); AlphaUpdateListener.updateVisibility(searchBar); updateCustomContentVisibility(); setScaleX(mNewScale); setScaleY(mNewScale); setTranslationY(finalWorkspaceTranslationY); } // mLauncher.updateVoiceButtonProxyVisible(false); if (stateIsSpringLoaded) { // Right now we're covered by Apps Customize // Show the background gradient immediately, so the gradient will // be showing once AppsCustomize disappears animateBackgroundGradient( getResources().getInteger(R.integer.config_appsCustomizeSpringLoadedBgAlpha) / 100f, false); } else if (stateIsOverview) { animateBackgroundGradient( getResources().getInteger(R.integer.config_appsCustomizeSpringLoadedBgAlpha) / 100f, true); } else { // Fade the background gradient away animateBackgroundGradient(0f, animated); } return anim; }
From source file:cc.flydev.launcher.Workspace.java
Animator getChangeStateAnimation(final State state, boolean animated, int delay, int snapPage) { if (mState == state) { return null; }// w ww. j ava 2s.com // Initialize animation arrays for the first time if necessary initAnimationArrays(); AnimatorSet anim = animated ? LauncherAnimUtils.createAnimatorSet() : null; final State oldState = mState; final boolean oldStateIsNormal = (oldState == State.NORMAL); final boolean oldStateIsSpringLoaded = (oldState == State.SPRING_LOADED); final boolean oldStateIsSmall = (oldState == State.SMALL); final boolean oldStateIsOverview = (oldState == State.OVERVIEW); setState(state); final boolean stateIsNormal = (state == State.NORMAL); final boolean stateIsSpringLoaded = (state == State.SPRING_LOADED); final boolean stateIsSmall = (state == State.SMALL); final boolean stateIsOverview = (state == State.OVERVIEW); float finalBackgroundAlpha = (stateIsSpringLoaded || stateIsOverview) ? 1.0f : 0f; float finalHotseatAndPageIndicatorAlpha = (stateIsOverview || stateIsSmall) ? 0f : 1f; float finalOverviewPanelAlpha = stateIsOverview ? 1f : 0f; float finalSearchBarAlpha = !stateIsNormal ? 0f : 1f; float finalWorkspaceTranslationY = stateIsOverview ? getOverviewModeTranslationY() : 0; boolean workspaceToAllApps = (oldStateIsNormal && stateIsSmall); boolean allAppsToWorkspace = (oldStateIsSmall && stateIsNormal); boolean workspaceToOverview = (oldStateIsNormal && stateIsOverview); boolean overviewToWorkspace = (oldStateIsOverview && stateIsNormal); mNewScale = 1.0f; if (oldStateIsOverview) { disableFreeScroll(snapPage); } else if (stateIsOverview) { enableFreeScroll(); } if (state != State.NORMAL) { if (stateIsSpringLoaded) { mNewScale = mSpringLoadedShrinkFactor; } else if (stateIsOverview) { mNewScale = mOverviewModeShrinkFactor; } else if (stateIsSmall) { mNewScale = mOverviewModeShrinkFactor - 0.3f; } if (workspaceToAllApps) { updateChildrenLayersEnabled(false); } } final int duration; if (workspaceToAllApps) { duration = getResources().getInteger(R.integer.config_workspaceUnshrinkTime); } else if (workspaceToOverview || overviewToWorkspace) { duration = getResources().getInteger(R.integer.config_overviewTransitionTime); } else { duration = getResources().getInteger(R.integer.config_appsCustomizeWorkspaceShrinkTime); } for (int i = 0; i < getChildCount(); i++) { final CellLayout cl = (CellLayout) getChildAt(i); boolean isCurrentPage = (i == getNextPage()); float initialAlpha = cl.getShortcutsAndWidgets().getAlpha(); float finalAlpha = stateIsSmall ? 0f : 1f; // If we are animating to/from the small state, then hide the side pages and fade the // current page in if (!mIsSwitchingState) { if (workspaceToAllApps || allAppsToWorkspace) { if (allAppsToWorkspace && isCurrentPage) { initialAlpha = 0f; } else if (!isCurrentPage) { initialAlpha = finalAlpha = 0f; } cl.setShortcutAndWidgetAlpha(initialAlpha); } } mOldAlphas[i] = initialAlpha; mNewAlphas[i] = finalAlpha; if (animated) { mOldBackgroundAlphas[i] = cl.getBackgroundAlpha(); mNewBackgroundAlphas[i] = finalBackgroundAlpha; } else { cl.setBackgroundAlpha(finalBackgroundAlpha); cl.setShortcutAndWidgetAlpha(finalAlpha); } } final View searchBar = mLauncher.getQsbBar(); final View overviewPanel = mLauncher.getOverviewPanel(); final View hotseat = mLauncher.getHotseat(); if (animated) { anim.setDuration(duration); LauncherViewPropertyAnimator scale = new LauncherViewPropertyAnimator(this); scale.scaleX(mNewScale).scaleY(mNewScale).translationY(finalWorkspaceTranslationY) .setInterpolator(mZoomInInterpolator); anim.play(scale); for (int index = 0; index < getChildCount(); index++) { final int i = index; final CellLayout cl = (CellLayout) getChildAt(i); float currentAlpha = cl.getShortcutsAndWidgets().getAlpha(); if (mOldAlphas[i] == 0 && mNewAlphas[i] == 0) { cl.setBackgroundAlpha(mNewBackgroundAlphas[i]); cl.setShortcutAndWidgetAlpha(mNewAlphas[i]); } else { if (mOldAlphas[i] != mNewAlphas[i] || currentAlpha != mNewAlphas[i]) { LauncherViewPropertyAnimator alphaAnim = new LauncherViewPropertyAnimator( cl.getShortcutsAndWidgets()); alphaAnim.alpha(mNewAlphas[i]).setInterpolator(mZoomInInterpolator); anim.play(alphaAnim); } if (mOldBackgroundAlphas[i] != 0 || mNewBackgroundAlphas[i] != 0) { ValueAnimator bgAnim = LauncherAnimUtils.ofFloat(cl, 0f, 1f); bgAnim.setInterpolator(mZoomInInterpolator); bgAnim.addUpdateListener(new LauncherAnimatorUpdateListener() { public void onAnimationUpdate(float a, float b) { cl.setBackgroundAlpha(a * mOldBackgroundAlphas[i] + b * mNewBackgroundAlphas[i]); } }); anim.play(bgAnim); } } } ObjectAnimator pageIndicatorAlpha = null; if (getPageIndicator() != null) { pageIndicatorAlpha = ObjectAnimator.ofFloat(getPageIndicator(), "alpha", finalHotseatAndPageIndicatorAlpha); } ObjectAnimator hotseatAlpha = ObjectAnimator.ofFloat(hotseat, "alpha", finalHotseatAndPageIndicatorAlpha); ObjectAnimator searchBarAlpha = ObjectAnimator.ofFloat(searchBar, "alpha", finalSearchBarAlpha); ObjectAnimator overviewPanelAlpha = ObjectAnimator.ofFloat(overviewPanel, "alpha", finalOverviewPanelAlpha); overviewPanelAlpha.addListener(new AlphaUpdateListener(overviewPanel)); hotseatAlpha.addListener(new AlphaUpdateListener(hotseat)); searchBarAlpha.addListener(new AlphaUpdateListener(searchBar)); if (workspaceToOverview) { hotseatAlpha.setInterpolator(new DecelerateInterpolator(2)); } else if (overviewToWorkspace) { overviewPanelAlpha.setInterpolator(new DecelerateInterpolator(2)); } if (getPageIndicator() != null) { pageIndicatorAlpha.addListener(new AlphaUpdateListener(getPageIndicator())); } anim.play(overviewPanelAlpha); anim.play(hotseatAlpha); anim.play(searchBarAlpha); anim.play(pageIndicatorAlpha); anim.setStartDelay(delay); } else { overviewPanel.setAlpha(finalOverviewPanelAlpha); AlphaUpdateListener.updateVisibility(overviewPanel); hotseat.setAlpha(finalHotseatAndPageIndicatorAlpha); AlphaUpdateListener.updateVisibility(hotseat); if (getPageIndicator() != null) { getPageIndicator().setAlpha(finalHotseatAndPageIndicatorAlpha); AlphaUpdateListener.updateVisibility(getPageIndicator()); } searchBar.setAlpha(finalSearchBarAlpha); AlphaUpdateListener.updateVisibility(searchBar); updateCustomContentVisibility(); setScaleX(mNewScale); setScaleY(mNewScale); setTranslationY(finalWorkspaceTranslationY); } mLauncher.updateVoiceButtonProxyVisible(false); if (stateIsSpringLoaded) { // Right now we're covered by Apps Customize // Show the background gradient immediately, so the gradient will // be showing once AppsCustomize disappears animateBackgroundGradient( getResources().getInteger(R.integer.config_appsCustomizeSpringLoadedBgAlpha) / 100f, false); } else if (stateIsOverview) { animateBackgroundGradient( getResources().getInteger(R.integer.config_appsCustomizeSpringLoadedBgAlpha) / 100f, true); } else { // Fade the background gradient away animateBackgroundGradient(0f, animated); } return anim; }
From source file:us.shandian.launcher.Workspace.java
Animator getChangeStateAnimation(final State state, boolean animated, int delay, int snapPage) { if (mState == state) { return null; }/*from w w w .j av a2 s. com*/ // Initialize animation arrays for the first time if necessary initAnimationArrays(); AnimatorSet anim = animated ? LauncherAnimUtils.createAnimatorSet() : null; final State oldState = mState; final boolean oldStateIsNormal = (oldState == State.NORMAL); final boolean oldStateIsSpringLoaded = (oldState == State.SPRING_LOADED); final boolean oldStateIsSmall = (oldState == State.SMALL); final boolean oldStateIsOverview = (oldState == State.OVERVIEW); setState(state); final boolean stateIsNormal = (state == State.NORMAL); final boolean stateIsSpringLoaded = (state == State.SPRING_LOADED); final boolean stateIsSmall = (state == State.SMALL); final boolean stateIsOverview = (state == State.OVERVIEW); float finalBackgroundAlpha = (stateIsSpringLoaded || stateIsOverview) ? 1.0f : 0f; float finalHotseatAndPageIndicatorAlpha = (stateIsOverview || stateIsSmall) ? 0f : 1f; float finalOverviewPanelAlpha = stateIsOverview ? 1f : 0f; float finalSearchBarAlpha = !stateIsNormal ? 0f : 1f; float finalWorkspaceTranslationY = stateIsOverview ? getOverviewModeTranslationY() : 0; boolean workspaceToAllApps = (oldStateIsNormal && stateIsSmall); boolean allAppsToWorkspace = (oldStateIsSmall && stateIsNormal); boolean workspaceToOverview = (oldStateIsNormal && stateIsOverview); boolean overviewToWorkspace = (oldStateIsOverview && stateIsNormal); mNewScale = 1.0f; if (oldStateIsOverview) { disableFreeScroll(snapPage); } else if (stateIsOverview) { enableFreeScroll(); } if (state != State.NORMAL) { if (stateIsSpringLoaded) { mNewScale = mSpringLoadedShrinkFactor; } else if (stateIsOverview) { mNewScale = mOverviewModeShrinkFactor; } else if (stateIsSmall) { mNewScale = mOverviewModeShrinkFactor - 0.3f; } if (workspaceToAllApps) { updateChildrenLayersEnabled(false); } } final int duration; if (workspaceToAllApps) { duration = getResources().getInteger(R.integer.config_workspaceUnshrinkTime); } else if (workspaceToOverview || overviewToWorkspace) { duration = getResources().getInteger(R.integer.config_overviewTransitionTime); } else { duration = getResources().getInteger(R.integer.config_appsCustomizeWorkspaceShrinkTime); } for (int i = 0; i < getChildCount(); i++) { final CellLayout cl = (CellLayout) getChildAt(i); boolean isCurrentPage = (i == getNextPage()); float initialAlpha = cl.getShortcutsAndWidgets().getAlpha(); float finalAlpha = stateIsSmall ? 0f : 1f; // If we are animating to/from the small state, then hide the side pages and fade the // current page in if (!mIsSwitchingState) { if (workspaceToAllApps || allAppsToWorkspace) { if (allAppsToWorkspace && isCurrentPage) { initialAlpha = 0f; } else if (!isCurrentPage) { initialAlpha = finalAlpha = 0f; } cl.setShortcutAndWidgetAlpha(initialAlpha); } } mOldAlphas[i] = initialAlpha; mNewAlphas[i] = finalAlpha; if (animated) { mOldBackgroundAlphas[i] = cl.getBackgroundAlpha(); mNewBackgroundAlphas[i] = finalBackgroundAlpha; } else { cl.setBackgroundAlpha(finalBackgroundAlpha); cl.setShortcutAndWidgetAlpha(finalAlpha); } } final View searchBar = mLauncher.getQsbBar(); final View overviewPanel = mLauncher.getOverviewPanel(); final View hotseat = mLauncher.getHotseat(); if (animated) { anim.setDuration(duration); LauncherViewPropertyAnimator scale = new LauncherViewPropertyAnimator(this); scale.scaleX(mNewScale).scaleY(mNewScale).translationY(finalWorkspaceTranslationY) .setInterpolator(mZoomInInterpolator); anim.play(scale); for (int index = 0; index < getChildCount(); index++) { final int i = index; final CellLayout cl = (CellLayout) getChildAt(i); float currentAlpha = cl.getShortcutsAndWidgets().getAlpha(); if (mOldAlphas[i] == 0 && mNewAlphas[i] == 0) { cl.setBackgroundAlpha(mNewBackgroundAlphas[i]); cl.setShortcutAndWidgetAlpha(mNewAlphas[i]); } else { if (mOldAlphas[i] != mNewAlphas[i] || currentAlpha != mNewAlphas[i]) { LauncherViewPropertyAnimator alphaAnim = new LauncherViewPropertyAnimator( cl.getShortcutsAndWidgets()); alphaAnim.alpha(mNewAlphas[i]).setInterpolator(mZoomInInterpolator); anim.play(alphaAnim); } if (mOldBackgroundAlphas[i] != 0 || mNewBackgroundAlphas[i] != 0) { ValueAnimator bgAnim = LauncherAnimUtils.ofFloat(cl, 0f, 1f); bgAnim.setInterpolator(mZoomInInterpolator); bgAnim.addUpdateListener(new LauncherAnimatorUpdateListener() { public void onAnimationUpdate(float a, float b) { cl.setBackgroundAlpha(a * mOldBackgroundAlphas[i] + b * mNewBackgroundAlphas[i]); } }); anim.play(bgAnim); } } } ObjectAnimator pageIndicatorAlpha = null; if (getPageIndicator() != null) { pageIndicatorAlpha = ObjectAnimator.ofFloat(getPageIndicator(), "alpha", finalHotseatAndPageIndicatorAlpha); } ObjectAnimator hotseatAlpha = ObjectAnimator.ofFloat(hotseat, "alpha", finalHotseatAndPageIndicatorAlpha); ObjectAnimator searchBarAlpha = ObjectAnimator.ofFloat(searchBar, "alpha", finalSearchBarAlpha); ObjectAnimator overviewPanelAlpha = ObjectAnimator.ofFloat(overviewPanel, "alpha", finalOverviewPanelAlpha); overviewPanelAlpha.addListener(new AlphaUpdateListener(overviewPanel)); hotseatAlpha.addListener(new AlphaUpdateListener(hotseat)); searchBarAlpha.addListener(new AlphaUpdateListener(searchBar)); if (workspaceToOverview) { hotseatAlpha.setInterpolator(new DecelerateInterpolator(2)); } else if (overviewToWorkspace) { overviewPanelAlpha.setInterpolator(new DecelerateInterpolator(2)); } if (getPageIndicator() != null) { pageIndicatorAlpha.addListener(new AlphaUpdateListener(getPageIndicator())); } anim.play(overviewPanelAlpha); anim.play(hotseatAlpha); if (searchBar.getVisibility() != View.GONE) { anim.play(searchBarAlpha); } anim.play(pageIndicatorAlpha); anim.setStartDelay(delay); } else { overviewPanel.setAlpha(finalOverviewPanelAlpha); AlphaUpdateListener.updateVisibility(overviewPanel); hotseat.setAlpha(finalHotseatAndPageIndicatorAlpha); AlphaUpdateListener.updateVisibility(hotseat); if (getPageIndicator() != null) { getPageIndicator().setAlpha(finalHotseatAndPageIndicatorAlpha); AlphaUpdateListener.updateVisibility(getPageIndicator()); } searchBar.setAlpha(finalSearchBarAlpha); AlphaUpdateListener.updateVisibility(searchBar); updateCustomContentVisibility(); setScaleX(mNewScale); setScaleY(mNewScale); setTranslationY(finalWorkspaceTranslationY); } mLauncher.updateVoiceButtonProxyVisible(false); if (stateIsSpringLoaded) { // Right now we're covered by Apps Customize // Show the background gradient immediately, so the gradient will // be showing once AppsCustomize disappears animateBackgroundGradient( getResources().getInteger(R.integer.config_appsCustomizeSpringLoadedBgAlpha) / 100f, false); } else if (stateIsOverview) { animateBackgroundGradient( getResources().getInteger(R.integer.config_appsCustomizeSpringLoadedBgAlpha) / 100f, true); } else { // Fade the background gradient away animateBackgroundGradient(0f, animated); } return anim; }
From source file:com.example.launcher3.Workspace.java
Animator getChangeStateAnimation(final State state, boolean animated, int delay, int snapPage) { if (mState == state) { return null; }/*from ww w .ja v a 2 s . com*/ // Initialize animation arrays for the first time if necessary initAnimationArrays(); AnimatorSet anim = animated ? LauncherAnimUtils.createAnimatorSet() : null; final State oldState = mState; final boolean oldStateIsNormal = (oldState == State.NORMAL); final boolean oldStateIsSpringLoaded = (oldState == State.SPRING_LOADED); final boolean oldStateIsSmall = (oldState == State.SMALL); final boolean oldStateIsOverview = (oldState == State.OVERVIEW); setState(state); final boolean stateIsNormal = (state == State.NORMAL); final boolean stateIsSpringLoaded = (state == State.SPRING_LOADED); final boolean stateIsSmall = (state == State.SMALL); final boolean stateIsOverview = (state == State.OVERVIEW); float finalBackgroundAlpha = (stateIsSpringLoaded || stateIsOverview) ? 1.0f : 0f; float finalHotseatAndPageIndicatorAlpha = (stateIsOverview || stateIsSmall) ? 0f : 1f; float finalOverviewPanelAlpha = stateIsOverview ? 1f : 0f; float finalSearchBarAlpha = !stateIsNormal ? 0f : 1f; float finalWorkspaceTranslationY = stateIsOverview ? getOverviewModeTranslationY() : 0; boolean workspaceToAllApps = (oldStateIsNormal && stateIsSmall); boolean allAppsToWorkspace = (oldStateIsSmall && stateIsNormal); boolean workspaceToOverview = (oldStateIsNormal && stateIsOverview); boolean overviewToWorkspace = (oldStateIsOverview && stateIsNormal); mNewScale = 1.0f; if (oldStateIsOverview) { disableFreeScroll(snapPage); } else if (stateIsOverview) { enableFreeScroll(); } if (state != State.NORMAL) { if (stateIsSpringLoaded) { mNewScale = mSpringLoadedShrinkFactor; } else if (stateIsOverview) { mNewScale = mOverviewModeShrinkFactor; } else if (stateIsSmall) { mNewScale = mOverviewModeShrinkFactor - 0.3f; } if (workspaceToAllApps) { updateChildrenLayersEnabled(false); } } final int duration; if (workspaceToAllApps) { duration = getResources().getInteger(R.integer.config_workspaceUnshrinkTime); } else if (workspaceToOverview || overviewToWorkspace) { duration = getResources().getInteger(R.integer.config_overviewTransitionTime); } else { duration = getResources().getInteger(R.integer.config_appsCustomizeWorkspaceShrinkTime); } for (int i = 0; i < getChildCount(); i++) { final CellLayout cl = (CellLayout) getChildAt(i); boolean isCurrentPage = (i == getNextPage()); float initialAlpha = cl.getShortcutsAndWidgets().getAlpha(); float finalAlpha = stateIsSmall ? 0f : 1f; // If we are animating to/from the small state, then hide the side // pages and fade the // current page in if (!mIsSwitchingState) { if (workspaceToAllApps || allAppsToWorkspace) { if (allAppsToWorkspace && isCurrentPage) { initialAlpha = 0f; } else if (!isCurrentPage) { initialAlpha = finalAlpha = 0f; } cl.setShortcutAndWidgetAlpha(initialAlpha); } } mOldAlphas[i] = initialAlpha; mNewAlphas[i] = finalAlpha; if (animated) { mOldBackgroundAlphas[i] = cl.getBackgroundAlpha(); mNewBackgroundAlphas[i] = finalBackgroundAlpha; } else { cl.setBackgroundAlpha(finalBackgroundAlpha); cl.setShortcutAndWidgetAlpha(finalAlpha); } } final View searchBar = mLauncher.getQsbBar(); final View overviewPanel = mLauncher.getOverviewPanel(); final View hotseat = mLauncher.getHotseat(); if (animated) { anim.setDuration(duration); LauncherViewPropertyAnimator scale = new LauncherViewPropertyAnimator(this); scale.scaleX(mNewScale).scaleY(mNewScale).translationY(finalWorkspaceTranslationY) .setInterpolator(mZoomInInterpolator); anim.play(scale); for (int index = 0; index < getChildCount(); index++) { final int i = index; final CellLayout cl = (CellLayout) getChildAt(i); float currentAlpha = cl.getShortcutsAndWidgets().getAlpha(); if (mOldAlphas[i] == 0 && mNewAlphas[i] == 0) { cl.setBackgroundAlpha(mNewBackgroundAlphas[i]); cl.setShortcutAndWidgetAlpha(mNewAlphas[i]); } else { if (mOldAlphas[i] != mNewAlphas[i] || currentAlpha != mNewAlphas[i]) { LauncherViewPropertyAnimator alphaAnim = new LauncherViewPropertyAnimator( cl.getShortcutsAndWidgets()); alphaAnim.alpha(mNewAlphas[i]).setInterpolator(mZoomInInterpolator); anim.play(alphaAnim); } if (mOldBackgroundAlphas[i] != 0 || mNewBackgroundAlphas[i] != 0) { ValueAnimator bgAnim = LauncherAnimUtils.ofFloat(cl, 0f, 1f); bgAnim.setInterpolator(mZoomInInterpolator); bgAnim.addUpdateListener(new LauncherAnimatorUpdateListener() { public void onAnimationUpdate(float a, float b) { cl.setBackgroundAlpha(a * mOldBackgroundAlphas[i] + b * mNewBackgroundAlphas[i]); } }); anim.play(bgAnim); } } } ObjectAnimator pageIndicatorAlpha = null; if (getPageIndicator() != null) { pageIndicatorAlpha = ObjectAnimator.ofFloat(getPageIndicator(), "alpha", finalHotseatAndPageIndicatorAlpha); } ObjectAnimator hotseatAlpha = ObjectAnimator.ofFloat(hotseat, "alpha", finalHotseatAndPageIndicatorAlpha); ObjectAnimator searchBarAlpha = ObjectAnimator.ofFloat(searchBar, "alpha", finalSearchBarAlpha); ObjectAnimator overviewPanelAlpha = ObjectAnimator.ofFloat(overviewPanel, "alpha", finalOverviewPanelAlpha); overviewPanelAlpha.addListener(new AlphaUpdateListener(overviewPanel)); hotseatAlpha.addListener(new AlphaUpdateListener(hotseat)); searchBarAlpha.addListener(new AlphaUpdateListener(searchBar)); if (workspaceToOverview) { hotseatAlpha.setInterpolator(new DecelerateInterpolator(2)); } else if (overviewToWorkspace) { overviewPanelAlpha.setInterpolator(new DecelerateInterpolator(2)); } if (getPageIndicator() != null) { pageIndicatorAlpha.addListener(new AlphaUpdateListener(getPageIndicator())); } anim.play(overviewPanelAlpha); anim.play(hotseatAlpha); anim.play(searchBarAlpha); anim.play(pageIndicatorAlpha); anim.setStartDelay(delay); } else { overviewPanel.setAlpha(finalOverviewPanelAlpha); AlphaUpdateListener.updateVisibility(overviewPanel); hotseat.setAlpha(finalHotseatAndPageIndicatorAlpha); AlphaUpdateListener.updateVisibility(hotseat); if (getPageIndicator() != null) { getPageIndicator().setAlpha(finalHotseatAndPageIndicatorAlpha); AlphaUpdateListener.updateVisibility(getPageIndicator()); } searchBar.setAlpha(finalSearchBarAlpha); AlphaUpdateListener.updateVisibility(searchBar); updateCustomContentVisibility(); setScaleX(mNewScale); setScaleY(mNewScale); setTranslationY(finalWorkspaceTranslationY); } mLauncher.updateVoiceButtonProxyVisible(false); if (stateIsSpringLoaded) { // Right now we're covered by Apps Customize // Show the background gradient immediately, so the gradient will // be showing once AppsCustomize disappears animateBackgroundGradient( getResources().getInteger(R.integer.config_appsCustomizeSpringLoadedBgAlpha) / 100f, false); } else if (stateIsOverview) { animateBackgroundGradient( getResources().getInteger(R.integer.config_appsCustomizeSpringLoadedBgAlpha) / 100f, true); } else { // Fade the background gradient away animateBackgroundGradient(0f, animated); } return anim; }
From source file:com.aidy.launcher3.ui.workspace.Workspace.java
public Animator getChangeStateAnimation(final State state, boolean animated, int delay, int snapPage) { if (mState == state) { return null; }/*from www.ja va 2s . c o m*/ // Initialize animation arrays for the first time if necessary initAnimationArrays(); AnimatorSet anim = animated ? LauncherAnimUtils.createAnimatorSet() : null; final State oldState = mState; final boolean oldStateIsNormal = (oldState == State.NORMAL); final boolean oldStateIsSpringLoaded = (oldState == State.SPRING_LOADED); final boolean oldStateIsSmall = (oldState == State.SMALL); final boolean oldStateIsOverview = (oldState == State.OVERVIEW); setState(state); final boolean stateIsNormal = (state == State.NORMAL); final boolean stateIsSpringLoaded = (state == State.SPRING_LOADED); final boolean stateIsSmall = (state == State.SMALL); final boolean stateIsOverview = (state == State.OVERVIEW); float finalBackgroundAlpha = (stateIsSpringLoaded || stateIsOverview) ? 1.0f : 0f; float finalHotseatAndPageIndicatorAlpha = (stateIsOverview || stateIsSmall) ? 0f : 1f; float finalOverviewPanelAlpha = stateIsOverview ? 1f : 0f; float finalSearchBarAlpha = !stateIsNormal ? 0f : 1f; float finalWorkspaceTranslationY = stateIsOverview ? getOverviewModeTranslationY() : 0; boolean workspaceToAllApps = (oldStateIsNormal && stateIsSmall); boolean allAppsToWorkspace = (oldStateIsSmall && stateIsNormal); boolean workspaceToOverview = (oldStateIsNormal && stateIsOverview); boolean overviewToWorkspace = (oldStateIsOverview && stateIsNormal); mNewScale = 1.0f; if (oldStateIsOverview) { disableFreeScroll(snapPage); } else if (stateIsOverview) { enableFreeScroll(); } if (state != State.NORMAL) { if (stateIsSpringLoaded) { mNewScale = mSpringLoadedShrinkFactor; } else if (stateIsOverview) { mNewScale = mOverviewModeShrinkFactor; } else if (stateIsSmall) { mNewScale = mOverviewModeShrinkFactor - 0.3f; } if (workspaceToAllApps) { updateChildrenLayersEnabled(false); } } final int duration; if (workspaceToAllApps) { duration = getResources().getInteger(R.integer.config_workspaceUnshrinkTime); } else if (workspaceToOverview || overviewToWorkspace) { duration = getResources().getInteger(R.integer.config_overviewTransitionTime); } else { duration = getResources().getInteger(R.integer.config_appsCustomizeWorkspaceShrinkTime); } for (int i = 0; i < getChildCount(); i++) { final CellLayout cl = (CellLayout) getChildAt(i); boolean isCurrentPage = (i == getNextPage()); float initialAlpha = cl.getShortcutsAndWidgets().getAlpha(); float finalAlpha = stateIsSmall ? 0f : 1f; // If we are animating to/from the small state, then hide the side // pages and fade the // current page in if (!mIsSwitchingState) { if (workspaceToAllApps || allAppsToWorkspace) { if (allAppsToWorkspace && isCurrentPage) { initialAlpha = 0f; } else if (!isCurrentPage) { initialAlpha = finalAlpha = 0f; } cl.setShortcutAndWidgetAlpha(initialAlpha); } } mOldAlphas[i] = initialAlpha; mNewAlphas[i] = finalAlpha; if (animated) { mOldBackgroundAlphas[i] = cl.getBackgroundAlpha(); mNewBackgroundAlphas[i] = finalBackgroundAlpha; } else { cl.setBackgroundAlpha(finalBackgroundAlpha); cl.setShortcutAndWidgetAlpha(finalAlpha); } } final View searchBar = mLauncher.getQsbBar(); final View overviewPanel = mLauncher.getOverviewPanel(); final View hotseat = mLauncher.getHotseat(); if (animated) { anim.setDuration(duration); LauncherViewPropertyAnimator scale = new LauncherViewPropertyAnimator(this); scale.scaleX(mNewScale).scaleY(mNewScale).translationY(finalWorkspaceTranslationY) .setInterpolator(mZoomInInterpolator); anim.play(scale); for (int index = 0; index < getChildCount(); index++) { final int i = index; final CellLayout cl = (CellLayout) getChildAt(i); float currentAlpha = cl.getShortcutsAndWidgets().getAlpha(); if (mOldAlphas[i] == 0 && mNewAlphas[i] == 0) { cl.setBackgroundAlpha(mNewBackgroundAlphas[i]); cl.setShortcutAndWidgetAlpha(mNewAlphas[i]); } else { if (mOldAlphas[i] != mNewAlphas[i] || currentAlpha != mNewAlphas[i]) { LauncherViewPropertyAnimator alphaAnim = new LauncherViewPropertyAnimator( cl.getShortcutsAndWidgets()); alphaAnim.alpha(mNewAlphas[i]).setInterpolator(mZoomInInterpolator); anim.play(alphaAnim); } if (mOldBackgroundAlphas[i] != 0 || mNewBackgroundAlphas[i] != 0) { ValueAnimator bgAnim = LauncherAnimUtils.ofFloat(cl, 0f, 1f); bgAnim.setInterpolator(mZoomInInterpolator); bgAnim.addUpdateListener(new LauncherAnimatorUpdateListener() { public void onAnimationUpdate(float a, float b) { cl.setBackgroundAlpha(a * mOldBackgroundAlphas[i] + b * mNewBackgroundAlphas[i]); } }); anim.play(bgAnim); } } } ObjectAnimator pageIndicatorAlpha = null; if (getPageIndicator() != null) { pageIndicatorAlpha = ObjectAnimator.ofFloat(getPageIndicator(), "alpha", finalHotseatAndPageIndicatorAlpha); } ObjectAnimator hotseatAlpha = ObjectAnimator.ofFloat(hotseat, "alpha", finalHotseatAndPageIndicatorAlpha); ObjectAnimator searchBarAlpha = ObjectAnimator.ofFloat(searchBar, "alpha", finalSearchBarAlpha); ObjectAnimator overviewPanelAlpha = ObjectAnimator.ofFloat(overviewPanel, "alpha", finalOverviewPanelAlpha); overviewPanelAlpha.addListener(new AlphaUpdateListener(overviewPanel)); hotseatAlpha.addListener(new AlphaUpdateListener(hotseat)); searchBarAlpha.addListener(new AlphaUpdateListener(searchBar)); if (workspaceToOverview) { hotseatAlpha.setInterpolator(new DecelerateInterpolator(2)); } else if (overviewToWorkspace) { overviewPanelAlpha.setInterpolator(new DecelerateInterpolator(2)); } if (getPageIndicator() != null) { pageIndicatorAlpha.addListener(new AlphaUpdateListener(getPageIndicator())); } anim.play(overviewPanelAlpha); anim.play(hotseatAlpha); anim.play(searchBarAlpha); anim.play(pageIndicatorAlpha); anim.setStartDelay(delay); } else { overviewPanel.setAlpha(finalOverviewPanelAlpha); AlphaUpdateListener.updateVisibility(overviewPanel); hotseat.setAlpha(finalHotseatAndPageIndicatorAlpha); AlphaUpdateListener.updateVisibility(hotseat); if (getPageIndicator() != null) { getPageIndicator().setAlpha(finalHotseatAndPageIndicatorAlpha); AlphaUpdateListener.updateVisibility(getPageIndicator()); } searchBar.setAlpha(finalSearchBarAlpha); AlphaUpdateListener.updateVisibility(searchBar); updateCustomContentVisibility(); setScaleX(mNewScale); setScaleY(mNewScale); setTranslationY(finalWorkspaceTranslationY); } mLauncher.updateVoiceButtonProxyVisible(false); if (stateIsSpringLoaded) { // Right now we're covered by Apps Customize // Show the background gradient immediately, so the gradient will // be showing once AppsCustomize disappears animateBackgroundGradient( getResources().getInteger(R.integer.config_appsCustomizeSpringLoadedBgAlpha) / 100f, false); } else if (stateIsOverview) { animateBackgroundGradient( getResources().getInteger(R.integer.config_appsCustomizeSpringLoadedBgAlpha) / 100f, true); } else { // Fade the background gradient away animateBackgroundGradient(0f, animated); } return anim; }
From source file:org.telegram.ui.PassportActivity.java
public void setPage(int page, boolean animated, Bundle params) { if (page == 3) { doneItem.setVisibility(View.GONE); }/*from w w w . j a v a2 s. c o m*/ final SlideView outView = views[currentViewNum]; final SlideView newView = views[page]; currentViewNum = page; newView.setParams(params, false); newView.onShow(); if (animated) { newView.setTranslationX(AndroidUtilities.displaySize.x); AnimatorSet animatorSet = new AnimatorSet(); animatorSet.setInterpolator(new AccelerateDecelerateInterpolator()); animatorSet.setDuration(300); animatorSet.playTogether( ObjectAnimator.ofFloat(outView, "translationX", -AndroidUtilities.displaySize.x), ObjectAnimator.ofFloat(newView, "translationX", 0)); animatorSet.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { newView.setVisibility(View.VISIBLE); } @Override public void onAnimationEnd(Animator animation) { outView.setVisibility(View.GONE); outView.setX(0); } }); animatorSet.start(); } else { newView.setTranslationX(0); newView.setVisibility(View.VISIBLE); if (outView != newView) { outView.setVisibility(View.GONE); } } }
From source file:com.wb.launcher3.Workspace.java
Animator getChangeStateAnimation(final State state, boolean animated, int delay, int snapPage) { if (mState == state) { return null; }/*from ww w . j a va2 s . co m*/ // Initialize animation arrays for the first time if necessary initAnimationArrays(); AnimatorSet anim = animated ? LauncherAnimUtils.createAnimatorSet() : null; final State oldState = mState; final boolean oldStateIsNormal = (oldState == State.NORMAL); final boolean oldStateIsSpringLoaded = (oldState == State.SPRING_LOADED); final boolean oldStateIsSmall = (oldState == State.SMALL); final boolean oldStateIsOverview = (oldState == State.OVERVIEW); setState(state); final boolean stateIsNormal = (state == State.NORMAL); final boolean stateIsSpringLoaded = (state == State.SPRING_LOADED); final boolean stateIsSmall = (state == State.SMALL); final boolean stateIsOverview = (state == State.OVERVIEW); float finalBackgroundAlpha = (stateIsSpringLoaded || stateIsOverview) ? 1.0f : 0f; float finalHotseatAndPageIndicatorAlpha = (stateIsOverview || stateIsSmall) ? 0f : 1f; float finalOverviewPanelAlpha = stateIsOverview ? 1f : 0f; float finalSearchBarAlpha = !stateIsNormal ? 0f : 1f; float finalWorkspaceTranslationY = stateIsOverview ? getOverviewModeTranslationY() : 0; boolean workspaceToAllApps = (oldStateIsNormal && stateIsSmall); boolean allAppsToWorkspace = (oldStateIsSmall && stateIsNormal); boolean workspaceToOverview = (oldStateIsNormal && stateIsOverview); boolean overviewToWorkspace = (oldStateIsOverview && stateIsNormal); mNewScale = 1.0f; if (oldStateIsOverview) { disableFreeScroll(snapPage); } else if (stateIsOverview) { enableFreeScroll(); } if (state != State.NORMAL) { if (stateIsSpringLoaded) { mNewScale = mSpringLoadedShrinkFactor; } else if (stateIsOverview) { mNewScale = mOverviewModeShrinkFactor; } else if (stateIsSmall) { mNewScale = mOverviewModeShrinkFactor - 0.3f; } if (workspaceToAllApps) { updateChildrenLayersEnabled(false); } } final int duration; if (workspaceToAllApps) { duration = getResources().getInteger(R.integer.config_workspaceUnshrinkTime); } else if (workspaceToOverview || overviewToWorkspace) { duration = getResources().getInteger(R.integer.config_overviewTransitionTime); } else { duration = getResources().getInteger(R.integer.config_appsCustomizeWorkspaceShrinkTime); } for (int i = 0; i < getChildCount(); i++) { final CellLayout cl = (CellLayout) getChildAt(i); boolean isCurrentPage = (i == getNextPage()); float initialAlpha = cl.getShortcutsAndWidgets().getAlpha(); float finalAlpha = stateIsSmall ? 0f : 1f; // If we are animating to/from the small state, then hide the side pages and fade the // current page in if (!mIsSwitchingState) { if (workspaceToAllApps || allAppsToWorkspace) { if (allAppsToWorkspace && isCurrentPage) { initialAlpha = 0f; } else if (!isCurrentPage) { initialAlpha = finalAlpha = 0f; } cl.setShortcutAndWidgetAlpha(initialAlpha); } } mOldAlphas[i] = initialAlpha; mNewAlphas[i] = finalAlpha; if (animated) { mOldBackgroundAlphas[i] = cl.getBackgroundAlpha(); mNewBackgroundAlphas[i] = finalBackgroundAlpha; } else { cl.setBackgroundAlpha(finalBackgroundAlpha); cl.setShortcutAndWidgetAlpha(finalAlpha); } } final View searchBar = mLauncher.getQsbBar(); final View overviewPanel = mLauncher.getOverviewPanel(); final View hotseat = mLauncher.getHotseat(); if (animated) { anim.setDuration(duration); LauncherViewPropertyAnimator scale = new LauncherViewPropertyAnimator(this); scale.scaleX(mNewScale).scaleY(mNewScale).translationY(finalWorkspaceTranslationY) .setInterpolator(mZoomInInterpolator); anim.play(scale); for (int index = 0; index < getChildCount(); index++) { final int i = index; final CellLayout cl = (CellLayout) getChildAt(i); float currentAlpha = cl.getShortcutsAndWidgets().getAlpha(); if (mOldAlphas[i] == 0 && mNewAlphas[i] == 0) { cl.setBackgroundAlpha(mNewBackgroundAlphas[i]); cl.setShortcutAndWidgetAlpha(mNewAlphas[i]); } else { if (mOldAlphas[i] != mNewAlphas[i] || currentAlpha != mNewAlphas[i]) { LauncherViewPropertyAnimator alphaAnim = new LauncherViewPropertyAnimator( cl.getShortcutsAndWidgets()); alphaAnim.alpha(mNewAlphas[i]).setInterpolator(mZoomInInterpolator); anim.play(alphaAnim); } if (mOldBackgroundAlphas[i] != 0 || mNewBackgroundAlphas[i] != 0) { ValueAnimator bgAnim = LauncherAnimUtils.ofFloat(cl, 0f, 1f); bgAnim.setInterpolator(mZoomInInterpolator); bgAnim.addUpdateListener(new LauncherAnimatorUpdateListener() { public void onAnimationUpdate(float a, float b) { cl.setBackgroundAlpha(a * mOldBackgroundAlphas[i] + b * mNewBackgroundAlphas[i]); } }); anim.play(bgAnim); } } } ObjectAnimator pageIndicatorAlpha = null; if (getPageIndicator() != null) { pageIndicatorAlpha = ObjectAnimator.ofFloat(getPageIndicator(), "alpha", finalHotseatAndPageIndicatorAlpha); } ObjectAnimator hotseatAlpha = ObjectAnimator.ofFloat(hotseat, "alpha", finalHotseatAndPageIndicatorAlpha); ObjectAnimator searchBarAlpha = ObjectAnimator.ofFloat(searchBar, "alpha", finalSearchBarAlpha); ObjectAnimator overviewPanelAlpha = ObjectAnimator.ofFloat(overviewPanel, "alpha", finalOverviewPanelAlpha); overviewPanelAlpha.addListener(new AlphaUpdateListener(overviewPanel)); hotseatAlpha.addListener(new AlphaUpdateListener(hotseat)); searchBarAlpha.addListener(new AlphaUpdateListener(searchBar)); if (workspaceToOverview) { hotseatAlpha.setInterpolator(new DecelerateInterpolator(2)); } else if (overviewToWorkspace) { overviewPanelAlpha.setInterpolator(new DecelerateInterpolator(2)); } if (getPageIndicator() != null) { pageIndicatorAlpha.addListener(new AlphaUpdateListener(getPageIndicator())); } anim.play(overviewPanelAlpha); anim.play(hotseatAlpha); ///added by zxa for uninstall app if (!TydtechConfig.TYDTECH_UNINSTALL_MIUI_FLAG) { anim.play(searchBarAlpha); } /// anim.play(pageIndicatorAlpha); anim.setStartDelay(delay); } else { overviewPanel.setAlpha(finalOverviewPanelAlpha); AlphaUpdateListener.updateVisibility(overviewPanel); hotseat.setAlpha(finalHotseatAndPageIndicatorAlpha); AlphaUpdateListener.updateVisibility(hotseat); if (getPageIndicator() != null) { getPageIndicator().setAlpha(finalHotseatAndPageIndicatorAlpha); AlphaUpdateListener.updateVisibility(getPageIndicator()); } //*/added by zxa for uninstall app if (!TydtechConfig.TYDTECH_UNINSTALL_MIUI_FLAG) { searchBar.setAlpha(finalSearchBarAlpha); AlphaUpdateListener.updateVisibility(searchBar); } //*/ updateCustomContentVisibility(); setScaleX(mNewScale); setScaleY(mNewScale); setTranslationY(finalWorkspaceTranslationY); } mLauncher.updateVoiceButtonProxyVisible(false); if (stateIsSpringLoaded) { // Right now we're covered by Apps Customize // Show the background gradient immediately, so the gradient will // be showing once AppsCustomize disappears animateBackgroundGradient( getResources().getInteger(R.integer.config_appsCustomizeSpringLoadedBgAlpha) / 100f, false); } else if (stateIsOverview) { animateBackgroundGradient( getResources().getInteger(R.integer.config_appsCustomizeSpringLoadedBgAlpha) / 100f, true); } else { // Fade the background gradient away animateBackgroundGradient(0f, animated); } return anim; }
From source file:org.telegram.ui.ArticleViewer.java
public void collapse() { if (parentActivity == null || !isVisible || checkAnimation()) { return;/*www. j a v a 2s .c om*/ } 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 (isPhotoVisible) { closePhoto(false); } try { if (visibleDialog != null) { visibleDialog.dismiss(); visibleDialog = null; } } catch (Exception e) { FileLog.e(e); } AnimatorSet animatorSet = new AnimatorSet(); animatorSet.playTogether( ObjectAnimator.ofFloat(containerView, "translationX", containerView.getMeasuredWidth() - AndroidUtilities.dp(56)), ObjectAnimator.ofFloat(containerView, "translationY", ActionBar.getCurrentActionBarHeight() + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0)), ObjectAnimator.ofFloat(windowView, "alpha", 0.0f), ObjectAnimator.ofFloat(listView, "alpha", 0.0f), ObjectAnimator.ofFloat(listView, "translationY", -AndroidUtilities.dp(56)), ObjectAnimator.ofFloat(headerView, "translationY", 0), ObjectAnimator.ofFloat(backButton, "scaleX", 1.0f), ObjectAnimator.ofFloat(backButton, "scaleY", 1.0f), ObjectAnimator.ofFloat(backButton, "translationY", 0), ObjectAnimator.ofFloat(shareContainer, "scaleX", 1.0f), ObjectAnimator.ofFloat(shareContainer, "translationY", 0), ObjectAnimator.ofFloat(shareContainer, "scaleY", 1.0f)); collapsed = true; 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; //windowLayoutParams.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; WindowManager wm = (WindowManager) parentActivity.getSystemService(Context.WINDOW_SERVICE); wm.updateViewLayout(windowView, windowLayoutParams); //onClosed(); //containerView.setScaleX(1.0f); //containerView.setScaleY(1.0f); } }; animatorSet.setInterpolator(new DecelerateInterpolator()); animatorSet.setDuration(250); animatorSet.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (animationEndRunnable != null) { animationEndRunnable.run(); animationEndRunnable = null; } } }); transitionAnimationStartTime = System.currentTimeMillis(); if (Build.VERSION.SDK_INT >= 18) { containerView.setLayerType(View.LAYER_TYPE_HARDWARE, null); } backDrawable.setRotation(1, true); animatorSet.start(); }
From source file:com.auratech.launcher.Workspace.java
Animator getChangeStateAnimation(final State state, boolean animated, int delay, int snapPage) { if (mState == state) { return null; }//from w w w. j a v a 2 s .c om // Initialize animation arrays for the first time if necessary initAnimationArrays(); AnimatorSet anim = animated ? LauncherAnimUtils.createAnimatorSet() : null; final State oldState = mState; final boolean oldStateIsNormal = (oldState == State.NORMAL); final boolean oldStateIsSpringLoaded = (oldState == State.SPRING_LOADED); final boolean oldStateIsSmall = (oldState == State.SMALL); final boolean oldStateIsOverview = (oldState == State.OVERVIEW); setState(state); final boolean stateIsNormal = (state == State.NORMAL); final boolean stateIsSpringLoaded = (state == State.SPRING_LOADED); final boolean stateIsSmall = (state == State.SMALL); final boolean stateIsOverview = (state == State.OVERVIEW); float finalBackgroundAlpha = (stateIsSpringLoaded || stateIsOverview) ? 1.0f : 0f; float finalHotseatAndPageIndicatorAlpha = (stateIsOverview || stateIsSmall) ? 0f : 1f; float finalOverviewPanelAlpha = stateIsOverview ? 1f : 0f; float finalSearchBarAlpha = !stateIsNormal ? 0f : 1f; float finalWorkspaceTranslationY = stateIsOverview ? getOverviewModeTranslationY() : 0; boolean workspaceToAllApps = (oldStateIsNormal && stateIsSmall); boolean allAppsToWorkspace = (oldStateIsSmall && stateIsNormal); boolean workspaceToOverview = (oldStateIsNormal && stateIsOverview); boolean overviewToWorkspace = (oldStateIsOverview && stateIsNormal); mNewScale = 1.0f; if (oldStateIsOverview) { disableFreeScroll(); } else if (stateIsOverview) { enableFreeScroll(); } if (state != State.NORMAL) { if (stateIsSpringLoaded) { mNewScale = mSpringLoadedShrinkFactor; } else if (stateIsOverview) { mNewScale = mOverviewModeShrinkFactor; } else if (stateIsSmall) { mNewScale = mOverviewModeShrinkFactor - 0.3f; } if (workspaceToAllApps) { updateChildrenLayersEnabled(false); } } final int duration; if (workspaceToAllApps) { duration = getResources().getInteger(R.integer.config_workspaceUnshrinkTime); } else if (workspaceToOverview || overviewToWorkspace) { duration = getResources().getInteger(R.integer.config_overviewTransitionTime); } else { duration = getResources().getInteger(R.integer.config_appsCustomizeWorkspaceShrinkTime); } if (snapPage == -1) { snapPage = getPageNearestToCenterOfScreen(); } snapToPage(snapPage, duration, mZoomInInterpolator); for (int i = 0; i < getChildCount(); i++) { final CellLayout cl = (CellLayout) getChildAt(i); boolean isCurrentPage = (i == snapPage); float initialAlpha = cl.getShortcutsAndWidgets().getAlpha(); float finalAlpha; if (stateIsSmall) { finalAlpha = 0f; } else if (stateIsNormal && mWorkspaceFadeInAdjacentScreens) { finalAlpha = (i == snapPage || i < numCustomPages()) ? 1f : 0f; } else { finalAlpha = 1f; } // If we are animating to/from the small state, then hide the side pages and fade the // current page in if (!mIsSwitchingState) { if (workspaceToAllApps || allAppsToWorkspace) { if (allAppsToWorkspace && isCurrentPage) { initialAlpha = 0f; } else if (!isCurrentPage) { initialAlpha = finalAlpha = 0f; } cl.setShortcutAndWidgetAlpha(initialAlpha); } } mOldAlphas[i] = initialAlpha; mNewAlphas[i] = finalAlpha; if (animated) { mOldBackgroundAlphas[i] = cl.getBackgroundAlpha(); mNewBackgroundAlphas[i] = finalBackgroundAlpha; } else { cl.setBackgroundAlpha(finalBackgroundAlpha); cl.setShortcutAndWidgetAlpha(finalAlpha); } } final View searchBar = mLauncher.getQsbBar(); final View overviewPanel = mLauncher.getOverviewPanel(); final View hotseat = mLauncher.getHotseat(); final View pageIndicator = getPageIndicator(); if (animated) { anim.setDuration(duration); LauncherViewPropertyAnimator scale = new LauncherViewPropertyAnimator(this); scale.scaleX(mNewScale).scaleY(mNewScale).translationY(finalWorkspaceTranslationY) .setInterpolator(mZoomInInterpolator); anim.play(scale); for (int index = 0; index < getChildCount(); index++) { final int i = index; final CellLayout cl = (CellLayout) getChildAt(i); float currentAlpha = cl.getShortcutsAndWidgets().getAlpha(); if (mOldAlphas[i] == 0 && mNewAlphas[i] == 0) { cl.setBackgroundAlpha(mNewBackgroundAlphas[i]); cl.setShortcutAndWidgetAlpha(mNewAlphas[i]); } else { if (mOldAlphas[i] != mNewAlphas[i] || currentAlpha != mNewAlphas[i]) { LauncherViewPropertyAnimator alphaAnim = new LauncherViewPropertyAnimator( cl.getShortcutsAndWidgets()); alphaAnim.alpha(mNewAlphas[i]).setInterpolator(mZoomInInterpolator); anim.play(alphaAnim); } if (mOldBackgroundAlphas[i] != 0 || mNewBackgroundAlphas[i] != 0) { ValueAnimator bgAnim = LauncherAnimUtils.ofFloat(cl, 0f, 1f); bgAnim.setInterpolator(mZoomInInterpolator); bgAnim.addUpdateListener(new LauncherAnimatorUpdateListener() { public void onAnimationUpdate(float a, float b) { cl.setBackgroundAlpha(a * mOldBackgroundAlphas[i] + b * mNewBackgroundAlphas[i]); } }); anim.play(bgAnim); } } } Animator pageIndicatorAlpha = null; if (pageIndicator != null) { pageIndicatorAlpha = new LauncherViewPropertyAnimator(pageIndicator) .alpha(finalHotseatAndPageIndicatorAlpha).withLayer(); pageIndicatorAlpha.addListener(new AlphaUpdateListener(pageIndicator)); } else { // create a dummy animation so we don't need to do null checks later pageIndicatorAlpha = ValueAnimator.ofFloat(0, 0); } Animator hotseatAlpha = new LauncherViewPropertyAnimator(hotseat) .alpha(finalHotseatAndPageIndicatorAlpha).withLayer(); hotseatAlpha.addListener(new AlphaUpdateListener(hotseat)); Animator searchBarAlpha = new LauncherViewPropertyAnimator(searchBar).alpha(finalSearchBarAlpha) .withLayer(); searchBarAlpha.addListener(new AlphaUpdateListener(searchBar)); Animator overviewPanelAlpha = new LauncherViewPropertyAnimator(overviewPanel) .alpha(finalOverviewPanelAlpha).withLayer(); overviewPanelAlpha.addListener(new AlphaUpdateListener(overviewPanel)); if (workspaceToOverview) { pageIndicatorAlpha.setInterpolator(new DecelerateInterpolator(2)); hotseatAlpha.setInterpolator(new DecelerateInterpolator(2)); overviewPanelAlpha.setInterpolator(null); } else if (overviewToWorkspace) { pageIndicatorAlpha.setInterpolator(null); hotseatAlpha.setInterpolator(null); overviewPanelAlpha.setInterpolator(new DecelerateInterpolator(2)); } searchBarAlpha.setInterpolator(null); anim.play(overviewPanelAlpha); anim.play(hotseatAlpha); anim.play(searchBarAlpha); anim.play(pageIndicatorAlpha); anim.setStartDelay(delay); } else { overviewPanel.setAlpha(finalOverviewPanelAlpha); AlphaUpdateListener.updateVisibility(overviewPanel); hotseat.setAlpha(finalHotseatAndPageIndicatorAlpha); AlphaUpdateListener.updateVisibility(hotseat); if (pageIndicator != null) { pageIndicator.setAlpha(finalHotseatAndPageIndicatorAlpha); AlphaUpdateListener.updateVisibility(pageIndicator); } searchBar.setAlpha(finalSearchBarAlpha); AlphaUpdateListener.updateVisibility(searchBar); updateCustomContentVisibility(); setScaleX(mNewScale); setScaleY(mNewScale); setTranslationY(finalWorkspaceTranslationY); } mLauncher.updateVoiceButtonProxyVisible(false); if (stateIsSpringLoaded) { // Right now we're covered by Apps Customize // Show the background gradient immediately, so the gradient will // be showing once AppsCustomize disappears animateBackgroundGradient( getResources().getInteger(R.integer.config_appsCustomizeSpringLoadedBgAlpha) / 100f, false); } else if (stateIsOverview) { animateBackgroundGradient( getResources().getInteger(R.integer.config_appsCustomizeSpringLoadedBgAlpha) / 100f, true); } else { // Fade the background gradient away animateBackgroundGradient(0f, animated); } return anim; }