List of usage examples for android.view View LAYER_TYPE_HARDWARE
int LAYER_TYPE_HARDWARE
To view the source code for android.view View LAYER_TYPE_HARDWARE.
Click Source Link
Indicates that the view has a hardware layer.
From source file:com.google.android.apps.santatracker.rocketsleigh.RocketSleighActivity.java
private void addFinalPresentRun() { // Two spacers at the begining. View view = new View(this); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(mSlotWidth, mScreenHeight); mObstacleLayout.addView(view, lp);/*w w w . j a v a 2 s . c o m*/ view = new View(this); mObstacleLayout.addView(view, lp); // All of these presents are 500 points (but only if you're awesome) if (mElfState == 0) { mRainingPresents = true; } // SIN wave of presents in the middle float center = (float) (mScreenHeight / 2); float amplitude = (float) (mScreenHeight / 4); int count = (3 * SLOTS_PER_SCREEN) - 4; for (int i = 0; i < count; i++) { float x = (float) ((mSlotWidth - mGiftBoxes[0].getWidth()) / 2); float y = center + (amplitude * (float) Math.sin(2.0 * Math.PI * (double) i / (double) count)); Bitmap bmp = mGiftBoxes[mRandom.nextInt(mGiftBoxes.length)]; ImageView iv = new ImageView(this); iv.setImageBitmap(bmp); iv.setLayerType(View.LAYER_TYPE_HARDWARE, null); FrameLayout frame = new FrameLayout(this); LayoutParams flp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); frame.addView(iv, flp); iv.setTranslationX(x); iv.setTranslationY(y); mObstacleLayout.addView(frame, lp); } // Two spacers at the end. view = new View(this); mObstacleLayout.addView(view, lp); view = new View(this); mObstacleLayout.addView(view, lp); // Account for rounding errors in mSlotWidth int extra = ((3 * mScreenWidth) - (3 * SLOTS_PER_SCREEN * mSlotWidth)); if (extra > 0) { // Add filler to ensure sync with background/foreground scrolls! lp = new LinearLayout.LayoutParams(extra, LinearLayout.LayoutParams.MATCH_PARENT); view = new View(this); mObstacleLayout.addView(view, lp); } }
From source file:org.telegram.ui.ChannelAdminLogActivity.java
private TextureView createTextureView(boolean add) { if (parentLayout == null) { return null; }/*from ww w . ja v a2s. c o m*/ if (roundVideoContainer == null) { if (Build.VERSION.SDK_INT >= 21) { roundVideoContainer = new FrameLayout(getParentActivity()) { @Override public void setTranslationY(float translationY) { super.setTranslationY(translationY); contentView.invalidate(); } }; roundVideoContainer.setOutlineProvider(new ViewOutlineProvider() { @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public void getOutline(View view, Outline outline) { outline.setOval(0, 0, AndroidUtilities.roundMessageSize, AndroidUtilities.roundMessageSize); } }); roundVideoContainer.setClipToOutline(true); } else { roundVideoContainer = new FrameLayout(getParentActivity()) { @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); aspectPath.reset(); aspectPath.addCircle(w / 2, h / 2, w / 2, Path.Direction.CW); aspectPath.toggleInverseFillType(); } @Override public void setTranslationY(float translationY) { super.setTranslationY(translationY); contentView.invalidate(); } @Override public void setVisibility(int visibility) { super.setVisibility(visibility); if (visibility == VISIBLE) { setLayerType(View.LAYER_TYPE_HARDWARE, null); } } @Override protected void dispatchDraw(Canvas canvas) { super.dispatchDraw(canvas); canvas.drawPath(aspectPath, aspectPaint); } }; aspectPath = new Path(); aspectPaint = new Paint(Paint.ANTI_ALIAS_FLAG); aspectPaint.setColor(0xff000000); aspectPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); } roundVideoContainer.setWillNotDraw(false); roundVideoContainer.setVisibility(View.INVISIBLE); aspectRatioFrameLayout = new AspectRatioFrameLayout(getParentActivity()); aspectRatioFrameLayout.setBackgroundColor(0); if (add) { roundVideoContainer.addView(aspectRatioFrameLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); } videoTextureView = new TextureView(getParentActivity()); videoTextureView.setOpaque(false); aspectRatioFrameLayout.addView(videoTextureView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); } if (roundVideoContainer.getParent() == null) { contentView.addView(roundVideoContainer, 1, new FrameLayout.LayoutParams( AndroidUtilities.roundMessageSize, AndroidUtilities.roundMessageSize)); } roundVideoContainer.setVisibility(View.INVISIBLE); aspectRatioFrameLayout.setDrawingReady(false); return videoTextureView; }
From source file:com.lambergar.verticalviewpager.VerticalViewPager.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) private void enableLayers(boolean enable) { final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final int layerType = enable ? View.LAYER_TYPE_HARDWARE : View.LAYER_TYPE_NONE; getChildAt(i).setLayerType(layerType, null); }//from w ww . j a va 2 s .c o m }
From source file:com.google.android.apps.santatracker.rocketsleigh.RocketSleighActivity.java
private void addFactoryObstacles(int screens) { int totalSlots = screens * SLOTS_PER_SCREEN; for (int i = 0; i < totalSlots;) { // Any given "slot" has a 1 in 3 chance of having an obstacle if (mRandom.nextInt(2) == 0) { View view = mInflater.inflate(R.layout.obstacle_layout, null); ImageView top = (ImageView) view.findViewById(R.id.top_view); ImageView bottom = (ImageView) view.findViewById(R.id.bottom_view); ImageView back = (ImageView) view.findViewById(R.id.back_view); // Which obstacle? int width = 0; // int obstacle = mRandom.nextInt((FACTORY_OBSTACLES.length/2)); if ((mFactoryObstacleIndex % 20) == 0) { ObstacleLoadTask task = new ObstacleLoadTask(getResources(), FACTORY_OBSTACLES, mFactoryObstacles, mFactoryObstacleList, mFactoryObstacleIndex + 20, 2, mScaleX, mScaleY);//from ww w . jav a 2 s . com task.execute(); } int obstacle = mFactoryObstacleList.get(mFactoryObstacleIndex++); if (mFactoryObstacleIndex >= mFactoryObstacleList.size()) { mFactoryObstacleIndex = 0; } int topIndex = obstacle * 2; int bottomIndex = topIndex + 1; back.setVisibility(View.GONE); int currentObstacle = 0; // Same values as mLastObstacle if (FACTORY_OBSTACLES[topIndex] != -1) { currentObstacle |= 1; Bitmap bmp = null; synchronized (mFactoryObstacles) { bmp = mFactoryObstacles.get(FACTORY_OBSTACLES[topIndex]); } while (bmp == null) { synchronized (mFactoryObstacles) { bmp = mFactoryObstacles.get(FACTORY_OBSTACLES[topIndex]); if (bmp == null) { try { mFactoryObstacles.wait(); } catch (InterruptedException e) { } } } } width = bmp.getWidth(); top.setImageBitmap(bmp); } else { top.setVisibility(View.GONE); } if (FACTORY_OBSTACLES[bottomIndex] != -1) { currentObstacle |= 2; Bitmap bmp = null; synchronized (mFactoryObstacles) { bmp = mFactoryObstacles.get(FACTORY_OBSTACLES[bottomIndex]); } while (bmp == null) { synchronized (mFactoryObstacles) { bmp = mFactoryObstacles.get(FACTORY_OBSTACLES[bottomIndex]); if (bmp == null) { try { mFactoryObstacles.wait(); } catch (InterruptedException e) { } } } } if (bmp.getWidth() > width) { width = bmp.getWidth(); } bottom.setImageBitmap(bmp); } else { bottom.setVisibility(View.GONE); } int slots = (width / mSlotWidth); if ((width % mSlotWidth) != 0) { slots++; } // If last obstacle had a top and this is a bottom or vice versa, insert a space if ((mLastObstacle & 0x1) > 0) { if ((currentObstacle & 0x2) > 0) { addSpaceOrPresent(mSlotWidth); i++; } } else if ((mLastObstacle & 0x2) > 0) { if ((currentObstacle & 0x1) > 0) { addSpaceOrPresent(mSlotWidth); i++; } } // If the new obstacle is too wide for the remaining space, skip it and fill spacer instead if ((i + slots) > totalSlots) { addSpaceOrPresent(mSlotWidth * (totalSlots - i)); i = totalSlots; } else { mLastObstacle = currentObstacle; LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(slots * mSlotWidth, LinearLayout.LayoutParams.WRAP_CONTENT); view.setLayoutParams(lp); mObstacleLayout.addView(view); i += slots; } } else { addSpaceOrPresent(mSlotWidth); i++; } } // Account for rounding errors in mSlotWidth int extra = ((screens * mScreenWidth) - (totalSlots * mSlotWidth)); if (extra > 0) { // Add filler to ensure sync with background/foreground scrolls! LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(extra, LinearLayout.LayoutParams.MATCH_PARENT); View view = new View(this); view.setLayerType(View.LAYER_TYPE_HARDWARE, null); mObstacleLayout.addView(view, lp); } }
From source file:com.google.android.apps.santatracker.rocketsleigh.RocketSleighActivity.java
private void addSpaceOrPresent(int width) { if (width > 0) { mLastObstacle = 0;/*w ww. ja va2 s .c om*/ // 1/3 chance of a present. LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(width, LinearLayout.LayoutParams.MATCH_PARENT); if (mRandom.nextInt(3) == 0) { // Present! // Which one? Bitmap bmp = mGiftBoxes[mRandom.nextInt(mGiftBoxes.length)]; ImageView iv = new ImageView(this); iv.setLayerType(View.LAYER_TYPE_HARDWARE, null); iv.setImageBitmap(bmp); // Position the present int left = mRandom.nextInt(width / 2) + (width / 4) - ((int) ((float) bmp.getWidth() * mScaleX) / 2); int top = mRandom.nextInt(mScreenHeight / 2) + (mScreenHeight / 4) - ((int) ((float) bmp.getHeight() * mScaleY) / 2); FrameLayout frame = new FrameLayout(this); LayoutParams flp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); frame.addView(iv, flp); iv.setTranslationX(left); iv.setTranslationY(top); mObstacleLayout.addView(frame, lp); } else { // Space View view = new View(this); mObstacleLayout.addView(view, lp); } } }
From source file:com.google.android.apps.santatracker.rocketsleigh.RocketSleighActivity.java
private void addNextImages(int level, boolean recycle) { if (level < BACKGROUNDS.length) { // Add the background image ImageView iv = new ImageView(this); iv.setLayerType(View.LAYER_TYPE_HARDWARE, null); // This is being background loaded. Should already be loaded, but if not, wait. while (mBackgrounds[level] == null) { synchronized (mBackgrounds) { if (mBackgrounds[level] == null) { try { mBackgrounds.wait(); } catch (InterruptedException e) { }/*from w w w . jav a 2 s.c o m*/ } } } iv.setImageBitmap(mBackgrounds[level]); if (recycle) { iv.setTag(new Pair<Integer, Integer>(0, level)); } LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); mBackgroundLayout.addView(iv, lp); iv = new ImageView(this); iv.setLayerType(View.LAYER_TYPE_HARDWARE, null); if (recycle) { iv.setTag(new Pair<Integer, Integer>(0, level)); } iv.setImageBitmap(mBackgrounds2[level]); mBackgroundLayout.addView(iv, lp); // Add the foreground image if (FOREGROUNDS[level] == -1) { View view = new View(this); lp = new LinearLayout.LayoutParams(mScreenWidth * 2, 10); mForegroundLayout.addView(view, lp); } else { iv = new ImageView(this); iv.setBackgroundResource(R.drawable.img_snow_ground_tiles); if (recycle) { iv.setTag(level); } lp = new LinearLayout.LayoutParams(mScreenWidth * 2, LinearLayout.LayoutParams.WRAP_CONTENT); mForegroundLayout.addView(iv, lp); iv = new ImageView(this); if (recycle) { iv.setTag(level); } iv.setBackgroundResource(R.drawable.img_snow_ground_tiles); mForegroundLayout.addView(iv, lp); } } }
From source file:com.android.leanlauncher.LauncherTransitionable.java
private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded, final AppsCustomizePagedView.ContentType contentType) { if (mStateAnimation != null) { mStateAnimation.setDuration(0);/*from ww w .j a v a 2s . c o m*/ mStateAnimation.cancel(); mStateAnimation = null; } boolean material = Utilities.isLmpOrAbove(); final Resources res = getResources(); final int revealDuration = res.getInteger(R.integer.config_appsCustomizeRevealTime); final int itemsAlphaStagger = res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger); final View fromView = mWorkspace; final AppsCustomizeTabHost toView = mAppsCustomizeTabHost; final ArrayList<View> layerViews = new ArrayList<View>(); Workspace.State workspaceState = contentType == AppsCustomizePagedView.ContentType.Widgets ? Workspace.State.OVERVIEW_HIDDEN : Workspace.State.NORMAL_HIDDEN; Animator workspaceAnim = mWorkspace.getChangeStateAnimation(workspaceState, animated, layerViews); // Set the content type for the all apps/widgets space mAppsCustomizeTabHost.setContentTypeImmediate(contentType); // If for some reason our views aren't initialized, don't animate boolean initialized = getAllAppsButton() != null; if (animated && initialized) { mStateAnimation = LauncherAnimUtils.createAnimatorSet(); final AppsCustomizePagedView content = (AppsCustomizePagedView) toView .findViewById(R.id.apps_customize_pane_content); final View page = content.getPageAt(content.getCurrentPage()); final View revealView = toView.findViewById(R.id.fake_page); final boolean isWidgetTray = contentType == AppsCustomizePagedView.ContentType.Widgets; revealView.setBackgroundColor(getResources().getColor(R.color.widget_text_panel)); // Hide the real page background, and swap in the fake one content.setPageBackgroundsVisible(false); revealView.setVisibility(View.VISIBLE); // We need to hide this view as the animation start will be posted. revealView.setAlpha(0); int width = revealView.getMeasuredWidth(); int height = revealView.getMeasuredHeight(); float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4); revealView.setTranslationY(0); revealView.setTranslationX(0); // Get the y delta between the center of the page and the center of the all apps button int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView, getAllAppsButton(), null); float alpha = 0; float xDrift = 0; float yDrift = 0; if (material) { alpha = isWidgetTray ? 0.3f : 1f; yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1]; xDrift = isWidgetTray ? 0 : allAppsToPanelDelta[0]; } else { yDrift = 2 * height / 3; xDrift = 0; } final float initAlpha = alpha; revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null); layerViews.add(revealView); PropertyValuesHolder panelAlpha = PropertyValuesHolder.ofFloat("alpha", initAlpha, 1f); PropertyValuesHolder panelDriftY = PropertyValuesHolder.ofFloat("translationY", yDrift, 0); PropertyValuesHolder panelDriftX = PropertyValuesHolder.ofFloat("translationX", xDrift, 0); ObjectAnimator panelAlphaAndDrift = ObjectAnimator.ofPropertyValuesHolder(revealView, panelAlpha, panelDriftY, panelDriftX); panelAlphaAndDrift.setDuration(revealDuration); panelAlphaAndDrift.setInterpolator(new LogDecelerateInterpolator(100, 0)); mStateAnimation.play(panelAlphaAndDrift); if (page != null) { page.setVisibility(View.VISIBLE); page.setLayerType(View.LAYER_TYPE_HARDWARE, null); layerViews.add(page); ObjectAnimator pageDrift = ObjectAnimator.ofFloat(page, "translationY", yDrift, 0); page.setTranslationY(yDrift); pageDrift.setDuration(revealDuration); pageDrift.setInterpolator(new LogDecelerateInterpolator(100, 0)); pageDrift.setStartDelay(itemsAlphaStagger); mStateAnimation.play(pageDrift); page.setAlpha(0f); ObjectAnimator itemsAlpha = ObjectAnimator.ofFloat(page, "alpha", 0f, 1f); itemsAlpha.setDuration(revealDuration); itemsAlpha.setInterpolator(new AccelerateInterpolator(1.5f)); itemsAlpha.setStartDelay(itemsAlphaStagger); mStateAnimation.play(itemsAlpha); } View pageIndicators = toView.findViewById(R.id.apps_customize_page_indicator); pageIndicators.setAlpha(0.01f); ObjectAnimator indicatorsAlpha = ObjectAnimator.ofFloat(pageIndicators, "alpha", 1f); indicatorsAlpha.setDuration(revealDuration); mStateAnimation.play(indicatorsAlpha); if (material) { final View allApps = getAllAppsButton(); int allAppsButtonSize = LauncherAppState.getInstance().getDynamicGrid() .getDeviceProfile().allAppsButtonVisualSize; float startRadius = isWidgetTray ? 0 : allAppsButtonSize / 2; Animator reveal = ViewAnimationUtils.createCircularReveal(revealView, width / 2, height / 2, startRadius, revealRadius); reveal.setDuration(revealDuration); reveal.setInterpolator(new LogDecelerateInterpolator(100, 0)); reveal.addListener(new AnimatorListenerAdapter() { public void onAnimationStart(Animator animation) { if (!isWidgetTray) { allApps.setVisibility(View.INVISIBLE); } } public void onAnimationEnd(Animator animation) { if (!isWidgetTray) { allApps.setVisibility(View.VISIBLE); } } }); mStateAnimation.play(reveal); } mStateAnimation.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { dispatchOnLauncherTransitionEnd(fromView, animated, false); dispatchOnLauncherTransitionEnd(toView, animated, false); revealView.setVisibility(View.INVISIBLE); revealView.setLayerType(View.LAYER_TYPE_NONE, null); if (page != null) { page.setLayerType(View.LAYER_TYPE_NONE, null); } content.setPageBackgroundsVisible(true); // This can hold unnecessary references to views. mStateAnimation = null; } }); if (workspaceAnim != null) { mStateAnimation.play(workspaceAnim); } dispatchOnLauncherTransitionPrepare(fromView, animated, false); dispatchOnLauncherTransitionPrepare(toView, animated, false); final AnimatorSet stateAnimation = mStateAnimation; final Runnable startAnimRunnable = new Runnable() { public void run() { // Check that mStateAnimation hasn't changed while // we waited for a layout/draw pass if (mStateAnimation != stateAnimation) return; dispatchOnLauncherTransitionStart(fromView, animated, false); dispatchOnLauncherTransitionStart(toView, animated, false); revealView.setAlpha(initAlpha); if (Utilities.isLmpOrAbove()) { for (int i = 0; i < layerViews.size(); i++) { View v = layerViews.get(i); if (v != null) { if (Utilities.isViewAttachedToWindow(v)) v.buildLayer(); } } } mStateAnimation.start(); } }; toView.bringToFront(); toView.setVisibility(View.VISIBLE); toView.post(startAnimRunnable); } else { toView.setTranslationX(0.0f); toView.setTranslationY(0.0f); toView.setScaleX(1.0f); toView.setScaleY(1.0f); toView.setVisibility(View.VISIBLE); toView.bringToFront(); dispatchOnLauncherTransitionPrepare(fromView, animated, false); dispatchOnLauncherTransitionStart(fromView, animated, false); dispatchOnLauncherTransitionEnd(fromView, animated, false); dispatchOnLauncherTransitionPrepare(toView, animated, false); dispatchOnLauncherTransitionStart(toView, animated, false); dispatchOnLauncherTransitionEnd(toView, animated, false); } }
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);/* w ww .j a v a 2s.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:com.android.leanlauncher.LauncherTransitionable.java
/** * Zoom the camera back into the workspace, hiding 'fromView'. * This is the opposite of showAppsCustomizeHelper. * * @param animated If true, the transition will be animated. */// w w w .j a va 2 s . c o m private void hideAppsCustomizeHelper(Workspace.State toState, final boolean animated, final boolean springLoaded, final Runnable onCompleteRunnable) { if (mStateAnimation != null) { mStateAnimation.setDuration(0); mStateAnimation.cancel(); mStateAnimation = null; } boolean material = Utilities.isLmpOrAbove(); Resources res = getResources(); final int revealDuration = res.getInteger(R.integer.config_appsCustomizeConcealTime); final int itemsAlphaStagger = res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger); final View fromView = mAppsCustomizeTabHost; final View toView = mWorkspace; Animator workspaceAnim = null; final ArrayList<View> layerViews = new ArrayList<View>(); if (toState == Workspace.State.NORMAL) { workspaceAnim = mWorkspace.getChangeStateAnimation(toState, animated, layerViews); } else if (toState == Workspace.State.SPRING_LOADED || toState == Workspace.State.OVERVIEW) { workspaceAnim = mWorkspace.getChangeStateAnimation(toState, animated, layerViews); } // If for some reason our views aren't initialized, don't animate boolean initialized = getAllAppsButton() != null; if (animated && initialized) { mStateAnimation = LauncherAnimUtils.createAnimatorSet(); if (workspaceAnim != null) { mStateAnimation.play(workspaceAnim); } final AppsCustomizePagedView content = (AppsCustomizePagedView) fromView .findViewById(R.id.apps_customize_pane_content); final View page = content.getPageAt(content.getNextPage()); // We need to hide side pages of the Apps / Widget tray to avoid some ugly edge cases int count = content.getChildCount(); for (int i = 0; i < count; i++) { View child = content.getChildAt(i); if (child != page) { child.setVisibility(View.INVISIBLE); } } final View revealView = fromView.findViewById(R.id.fake_page); // hideAppsCustomizeHelper is called in some cases when it is already hidden // don't perform all these no-op animations. In particularly, this was causing // the all-apps button to pop in and out. if (fromView.getVisibility() == View.VISIBLE) { AppsCustomizePagedView.ContentType contentType = content.getContentType(); final boolean isWidgetTray = contentType == AppsCustomizePagedView.ContentType.Widgets; revealView.setBackgroundColor(getResources().getColor(R.color.widget_text_panel)); int width = revealView.getMeasuredWidth(); int height = revealView.getMeasuredHeight(); float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4); // Hide the real page background, and swap in the fake one revealView.setVisibility(View.VISIBLE); content.setPageBackgroundsVisible(false); final View allAppsButton = getAllAppsButton(); revealView.setTranslationY(0); int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView, allAppsButton, null); float xDrift = 0; float yDrift = 0; if (material) { yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1]; xDrift = isWidgetTray ? 0 : allAppsToPanelDelta[0]; } else { yDrift = 2 * height / 3; xDrift = 0; } revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null); TimeInterpolator decelerateInterpolator = material ? new LogDecelerateInterpolator(100, 0) : new DecelerateInterpolator(1f); // The vertical motion of the apps panel should be delayed by one frame // from the conceal animation in order to give the right feel. We correpsondingly // shorten the duration so that the slide and conceal end at the same time. ObjectAnimator panelDriftY = LauncherAnimUtils.ofFloat(revealView, "translationY", 0, yDrift); panelDriftY.setDuration(revealDuration - SINGLE_FRAME_DELAY); panelDriftY.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY); panelDriftY.setInterpolator(decelerateInterpolator); mStateAnimation.play(panelDriftY); ObjectAnimator panelDriftX = LauncherAnimUtils.ofFloat(revealView, "translationX", 0, xDrift); panelDriftX.setDuration(revealDuration - SINGLE_FRAME_DELAY); panelDriftX.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY); panelDriftX.setInterpolator(decelerateInterpolator); mStateAnimation.play(panelDriftX); if (isWidgetTray || !material) { float finalAlpha = material ? 0.4f : 0f; revealView.setAlpha(1f); ObjectAnimator panelAlpha = LauncherAnimUtils.ofFloat(revealView, "alpha", 1f, finalAlpha); panelAlpha.setDuration(material ? revealDuration : 150); panelAlpha.setInterpolator(decelerateInterpolator); panelAlpha.setStartDelay(material ? 0 : itemsAlphaStagger + SINGLE_FRAME_DELAY); mStateAnimation.play(panelAlpha); } if (page != null) { page.setLayerType(View.LAYER_TYPE_HARDWARE, null); ObjectAnimator pageDrift = LauncherAnimUtils.ofFloat(page, "translationY", 0, yDrift); page.setTranslationY(0); pageDrift.setDuration(revealDuration - SINGLE_FRAME_DELAY); pageDrift.setInterpolator(decelerateInterpolator); pageDrift.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY); mStateAnimation.play(pageDrift); page.setAlpha(1f); ObjectAnimator itemsAlpha = LauncherAnimUtils.ofFloat(page, "alpha", 1f, 0f); itemsAlpha.setDuration(100); itemsAlpha.setInterpolator(decelerateInterpolator); mStateAnimation.play(itemsAlpha); } View pageIndicators = fromView.findViewById(R.id.apps_customize_page_indicator); pageIndicators.setAlpha(1f); ObjectAnimator indicatorsAlpha = LauncherAnimUtils.ofFloat(pageIndicators, "alpha", 0f); indicatorsAlpha.setDuration(revealDuration); indicatorsAlpha.setInterpolator(new DecelerateInterpolator(1.5f)); mStateAnimation.play(indicatorsAlpha); width = revealView.getMeasuredWidth(); if (material) { if (!isWidgetTray) { allAppsButton.setVisibility(View.INVISIBLE); } int allAppsButtonSize = LauncherAppState.getInstance().getDynamicGrid() .getDeviceProfile().allAppsButtonVisualSize; float finalRadius = isWidgetTray ? 0 : allAppsButtonSize / 2; Animator reveal = LauncherAnimUtils.createCircularReveal(revealView, width / 2, height / 2, revealRadius, finalRadius); reveal.setInterpolator(new LogDecelerateInterpolator(100, 0)); reveal.setDuration(revealDuration); reveal.setStartDelay(itemsAlphaStagger); reveal.addListener(new AnimatorListenerAdapter() { public void onAnimationEnd(Animator animation) { revealView.setVisibility(View.INVISIBLE); if (!isWidgetTray) { allAppsButton.setVisibility(View.VISIBLE); } } }); mStateAnimation.play(reveal); } dispatchOnLauncherTransitionPrepare(fromView, animated, true); dispatchOnLauncherTransitionPrepare(toView, animated, true); mAppsCustomizeContent.stopScrolling(); } mStateAnimation.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { fromView.setVisibility(View.GONE); dispatchOnLauncherTransitionEnd(fromView, animated, true); dispatchOnLauncherTransitionEnd(toView, animated, true); if (onCompleteRunnable != null) { onCompleteRunnable.run(); } revealView.setLayerType(View.LAYER_TYPE_NONE, null); if (page != null) { page.setLayerType(View.LAYER_TYPE_NONE, null); } content.setPageBackgroundsVisible(true); // Unhide side pages int count = content.getChildCount(); for (int i = 0; i < count; i++) { View child = content.getChildAt(i); child.setVisibility(View.VISIBLE); } // Reset page transforms if (page != null) { page.setTranslationX(0); page.setTranslationY(0); page.setAlpha(1); } content.setCurrentPage(content.getNextPage()); mAppsCustomizeContent.updateCurrentPageScroll(); // This can hold unnecessary references to views. mStateAnimation = null; } }); final AnimatorSet stateAnimation = mStateAnimation; final Runnable startAnimRunnable = new Runnable() { public void run() { // Check that mStateAnimation hasn't changed while // we waited for a layout/draw pass if (mStateAnimation != stateAnimation) return; dispatchOnLauncherTransitionStart(fromView, animated, false); dispatchOnLauncherTransitionStart(toView, animated, false); if (Utilities.isLmpOrAbove()) { for (int i = 0; i < layerViews.size(); i++) { View v = layerViews.get(i); if (v != null) { if (Utilities.isViewAttachedToWindow(v)) v.buildLayer(); } } } mStateAnimation.start(); } }; fromView.post(startAnimRunnable); } else { fromView.setVisibility(View.GONE); dispatchOnLauncherTransitionPrepare(fromView, animated, true); dispatchOnLauncherTransitionStart(fromView, animated, true); dispatchOnLauncherTransitionEnd(fromView, animated, true); dispatchOnLauncherTransitionPrepare(toView, animated, true); dispatchOnLauncherTransitionStart(toView, animated, true); dispatchOnLauncherTransitionEnd(toView, animated, true); } }
From source file:com.upchannel.launcher3.Workspace.java
Animator getChangeStateAnimation(final State state, boolean animated, int delay, int snapPage, ArrayList<View> layerViews) { if (mState == state) { return null; }/*from w ww . j a v a 2 s . 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 oldStateIsNormalHidden = (oldState == State.NORMAL_HIDDEN); final boolean oldStateIsOverviewHidden = (oldState == State.OVERVIEW_HIDDEN); final boolean oldStateIsOverview = (oldState == State.OVERVIEW); setState(state); final boolean stateIsNormal = (state == State.NORMAL); final boolean stateIsSpringLoaded = (state == State.SPRING_LOADED); final boolean stateIsNormalHidden = (state == State.NORMAL_HIDDEN); final boolean stateIsOverviewHidden = (state == State.OVERVIEW_HIDDEN); final boolean stateIsOverview = (state == State.OVERVIEW); float finalBackgroundAlpha = (stateIsSpringLoaded || stateIsOverview) ? 1.0f : 0f; float finalHotseatAndPageIndicatorAlpha = (stateIsNormal || stateIsSpringLoaded) ? 1f : 0f; float finalOverviewPanelAlpha = stateIsOverview ? 1f : 0f; float finalSearchBarAlpha = !stateIsNormal ? 0f : 1f; float finalWorkspaceTranslationY = stateIsOverview || stateIsOverviewHidden ? getOverviewModeTranslationY() : 0; boolean workspaceToAllApps = (oldStateIsNormal && stateIsNormalHidden); boolean overviewToAllApps = (oldStateIsOverview && stateIsOverviewHidden); boolean allAppsToWorkspace = (stateIsNormalHidden && 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 || stateIsOverviewHidden) { mNewScale = mOverviewModeShrinkFactor; } } final int duration; if (workspaceToAllApps || overviewToAllApps) { duration = HIDE_WORKSPACE_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 (stateIsNormalHidden || stateIsOverviewHidden) { 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) { LauncherViewPropertyAnimator scale = new LauncherViewPropertyAnimator(this); scale.scaleX(mNewScale).scaleY(mNewScale).translationY(finalWorkspaceTranslationY).setDuration(duration) .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 (layerViews != null) { layerViews.add(cl); } if (mOldAlphas[i] != mNewAlphas[i] || currentAlpha != mNewAlphas[i]) { LauncherViewPropertyAnimator alphaAnim = new LauncherViewPropertyAnimator( cl.getShortcutsAndWidgets()); alphaAnim.alpha(mNewAlphas[i]).setDuration(duration).setInterpolator(mZoomInInterpolator); anim.play(alphaAnim); } if (mOldBackgroundAlphas[i] != 0 || mNewBackgroundAlphas[i] != 0) { ValueAnimator bgAnim = LauncherAnimUtils.ofFloat(cl, 0f, 1f); bgAnim.setInterpolator(mZoomInInterpolator); bgAnim.setDuration(duration); 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)); // For animation optimations, we may need to provide the Launcher transition // with a set of views on which to force build layers in certain scenarios. hotseat.setLayerType(View.LAYER_TYPE_HARDWARE, null); searchBar.setLayerType(View.LAYER_TYPE_HARDWARE, null); overviewPanel.setLayerType(View.LAYER_TYPE_HARDWARE, null); if (layerViews != null) { layerViews.add(hotseat); layerViews.add(searchBar); layerViews.add(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)); } overviewPanelAlpha.setDuration(duration); pageIndicatorAlpha.setDuration(duration); hotseatAlpha.setDuration(duration); searchBarAlpha.setDuration(duration); 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 (stateIsNormal) { animateBackgroundGradient(0f, animated); } else { animateBackgroundGradient(getResources().getInteger(R.integer.config_workspaceScrimAlpha) / 100f, animated); } return anim; }