launcher切页

launcher切页动画

刚工作的时候,还是launcher4.4,好像有很多切页特效可以选,重写切页特效类可以自己实现切页效果。
太久不搞launcher,忘记在哪实现切页特效了,比如什么外盒子、内盒子、旋转、仿真等等
扯远了,这篇文章简单写一下launcher切页,launcher中左右滑动页面切换动画速度调整。

1、launcher页面切页

launcher切页处理在src/com/android/launcher3/PagedView.java中

public boolean onTouchEvent(MotionEvent ev) {
}

具体就不写啦,小伙伴自己打断点吧。
切页分为2中:
快速滑动抛出:会有一个速度,根据速度衰减计算切页动画时间

protected boolean snapToPageWithVelocity(int whichPage, int velocity)

缓慢拖拽到一定距离松手:根据距离计算当前页面切页进度,判断是返回上一页还是切到下一页。

public static final int PAGE_SNAP_ANIMATION_DURATION = 300;

可以自己修改动画时间,加快切页。

2、负一屏和launcher切页

负一屏和第0页的切换
1、从第0页切到负一屏
PagedView的onTouchEvent还是会走,但是mNextPage都是0,不管切页成功还是滑动太少还在第0页。
那是哪里控制是否切到负一屏呢???

2、从负一屏切到第0页
src/com/android/launcher3/Workspace.java中public void onOverlayScrollChanged(float scroll) {}
打印调用堆栈发现是负一屏主动回调的launcher,切页不受launcher控制,无法修改动画时间。

2022-06-14 16:37:22.993 1837-1837/com.tblenovo.launcher I/OverlayCallbackImpl: onOverlayScrollChanged scroll : 0.0
2022-06-14 16:37:22.993 1837-1837/com.tblenovo.launcher D/Launcher.Workspace: onOverlayScrollChanged scroll : 0.0 call: java.lang.Throwable
at com.android.launcher3.Workspace.onOverlayScrollChanged(Workspace.java:1043)
at com.android.launcher3.Launcher$LauncherOverlayCallbacksImpl.onScrollChanged(Launcher.java:1669)
at com.android.searchlauncher.OverlayCallbackImpl.onOverlayScrollChanged(OverlayCallbackImpl.java:297)
at com.google.android.mediahome.launcheroverlay.client.zzg.handleMessage(com.google.android.mediahome.launcheroverlay:mediahome-launcheroverlay@@1.1.0-eap:20)
3、桌面滑动

补充一下workspace左右滑动跟手的逻辑
在CellLayout的setScrollProgress 方法打印调用堆栈
有2中堆栈,一种是onTouchEvent触发,一种是draw回调。

11-17 10:48:19.845 14405 14405 D CellLayout:  setScrollProgress mScrollProgress: 0.74932617 StackTrace java.lang.Throwable
11-17 10:48:19.845 14405 14405 D CellLayout: 	at com.android.launcher3.CellLayout.setScrollProgress(CellLayout.java:579)
11-17 10:48:19.845 14405 14405 D CellLayout: 	at com.android.launcher3.Workspace.updatePageScrollValues(Workspace.java:1425)
11-17 10:48:19.845 14405 14405 D CellLayout: 	at com.android.launcher3.Workspace.onScrollChanged(Workspace.java:1197)
11-17 10:48:19.845 14405 14405 D CellLayout: 	at android.view.View.scrollTo(View.java:19066)
11-17 10:48:19.845 14405 14405 D CellLayout: 	at com.android.launcher3.PagedView.scrollTo(PagedView.java:523)
11-17 10:48:19.845 14405 14405 D CellLayout: 	at com.android.launcher3.touch.PagedOrientationHandler$$ExternalSyntheticLambda1.call(Unknown Source:2)
11-17 10:48:19.845 14405 14405 D CellLayout: 	at com.android.launcher3.touch.PortraitPagedViewHandler.setPrimary(PortraitPagedViewHandler.java:115)
11-17 10:48:19.845 14405 14405 D CellLayout: 	at com.android.launcher3.PagedView.computeScrollHelper(PagedView.java:553)
11-17 10:48:19.845 14405 14405 D CellLayout: 	at com.android.launcher3.PagedView.computeScroll(PagedView.java:601)
11-17 10:48:19.845 14405 14405 D CellLayout: 	at com.android.launcher3.Workspace.computeScroll(Workspace.java:1382)
11-17 10:48:19.845 14405 14405 D CellLayout: 	at android.view.View.updateDisplayListIfDirty(View.java:22130)
11-17 10:48:19.845 14405 14405 D CellLayout: 	at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4619)
11-17 10:48:19.845 14405 14405 D CellLayout: 	at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4592)
11-17 10:48:19.845 14405 14405 D CellLayout: 	at android.view.View.updateDisplayListIfDirty(View.java:22097)
11-17 10:48:19.845 14405 14405 D CellLayout: 	at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4619)
11-17 10:48:19.845 14405 14405 D CellLayout: 	at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4592)
11-17 10:48:19.845 14405 14405 D CellLayout: 	at android.view.View.updateDisplayListIfDirty(View.java:22097)
11-17 10:48:19.845 14405 14405 D CellLayout: 	at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4619)
11-17 10:48:19.845 14405 14405 D CellLayout: 	at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4592)
11-17 10:48:19.845 14405 14405 D CellLayout: 	at android.view.View.updateDisplayListIfDirty(View.java:22097)
11-17 10:48:19.845 14405 14405 D CellLayout: 	at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4619)
11-17 10:48:19.845 14405 14405 D CellLayout: 	at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4592)
11-17 10:48:19.845 14405 14405 D CellLayout: 	at android.view.View.updateDisplayListIfDirty(View.java:22097)
11-17 10:48:19.845 14405 14405 D CellLayout: 	at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4619)
11-17 10:48:19.845 14405 14405 D CellLayout: 	at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4592)
11-17 10:48:19.845 14405 14405 D CellLayout: 	at android.view.View.updateDisplayListIfDirty(View.java:22097)
11-17 10:48:19.845 14405 14405 D CellLayout: 	at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:682)
11-17 10:48:19.845 14405 14405 D CellLayout: 	at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:688)
11-17 10:48:19.845 14405 14405 D CellLayout: 	at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:786)
11-17 10:48:19.845 14405 14405 D CellLayout: 	at android.view.ViewRootImpl.draw(ViewRootImpl.java:4810)


11-17 10:48:19.837 14405 14405 D CellLayout:  setScrollProgress mScrollProgress: 0.24797843 StackTrace java.lang.Throwable
11-17 10:48:19.837 14405 14405 D CellLayout: 	at com.android.launcher3.CellLayout.setScrollProgress(CellLayout.java:579)
11-17 10:48:19.837 14405 14405 D CellLayout: 	at com.android.launcher3.Workspace.updatePageScrollValues(Workspace.java:1425)
11-17 10:48:19.837 14405 14405 D CellLayout: 	at com.android.launcher3.Workspace.onScrollChanged(Workspace.java:1197)
11-17 10:48:19.837 14405 14405 D CellLayout: 	at android.view.View.scrollTo(View.java:19066)
11-17 10:48:19.837 14405 14405 D CellLayout: 	at com.android.launcher3.PagedView.scrollTo(PagedView.java:523)
11-17 10:48:19.837 14405 14405 D CellLayout: 	at android.view.View.scrollBy(View.java:19081)
11-17 10:48:19.837 14405 14405 D CellLayout: 	at com.android.launcher3.touch.PagedOrientationHandler$$ExternalSyntheticLambda0.call(Unknown Source:2)
11-17 10:48:19.837 14405 14405 D CellLayout: 	at com.android.launcher3.touch.PortraitPagedViewHandler.setPrimary(PortraitPagedViewHandler.java:115)
11-17 10:48:19.837 14405 14405 D CellLayout: 	at com.android.launcher3.PagedView.onTouchEvent(PagedView.java:1321)
11-17 10:48:19.837 14405 14405 D CellLayout: 	at android.view.View.dispatchTouchEvent(View.java:15035)
11-17 10:48:19.837 14405 14405 D CellLayout: 	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3206)
11-17 10:48:19.837 14405 14405 D CellLayout: 	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2845)

我们手动触摸滑动,页面跟手的事件应该是从PagedView.onTouchEvent方法下去,move的时候计算movedDelta进行View.scrollBy。

你可能感兴趣的:(launcher,android,java)