前文
Android U 多任务启动分屏——Launcher流程(上分屏)
最近任务onClick事件的监听
在最近任务中每个任务都是一个TaskView,对TaskView操作,就是每个任务的操作。
代码路径:packages/apps/Launcher3/quickstep/src/com/android/quickstep/views/TaskView.java
public TaskView(
Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
//从给定的context获取当前的StatefulActivity实例
//绑定TaskView和Activity之间的关系
mActivity = StatefulActivity.fromContext(context);
//监听当前TaskView的点击事件
setOnClickListener(this::onClick);
//初始化绘制相关参数
mCurrentFullscreenParams = new FullscreenDrawParams(context);
//把当前的Activity以及其对应的TaskView传递给DigitalWellBeingToast
mDigitalWellBeingToast = new DigitalWellBeingToast(mActivity, this);
//判断是否需要启用键盘焦点高亮
boolean keyboardFocusHighlightEnabled = FeatureFlags.ENABLE_KEYBOARD_QUICK_SWITCH.get()
|| DesktopTaskView.DESKTOP_MODE_SUPPORTED;
//如果不需要启用键盘焦点高亮,则setWillNotDraw(true),表示这个视图不需要绘制
setWillNotDraw(!keyboardFocusHighlightEnabled);
//使用TypedArray从XML属性中读取TaskView的自定义属性
TypedArray ta = context.obtainStyledAttributes(
attrs, R.styleable.TaskView, defStyleAttr, defStyleRes);
//如果启用了键盘焦点高亮,则创建一个BorderAnimator实例。
mBorderAnimator = !keyboardFocusHighlightEnabled
? null
: new BorderAnimator(
/* borderRadiusPx= */ (int) mCurrentFullscreenParams.mCornerRadius,
/* borderColor= */ ta.getColor(
R.styleable.TaskView_borderColor, DEFAULT_BORDER_COLOR),
/* borderAnimationParams= */ new BorderAnimator.SimpleParams(
/* borderWidthPx= */ context.getResources().getDimensionPixelSize(
R.dimen.keyboard_quick_switch_border_width),
/* boundsBuilder= */ this::updateBorderBounds,
/* targetView= */ this));
//回收TypedArray对象以避免内存泄漏。
ta.recycle();
}
选择下分屏
确定选择下分屏,播放相关动画,调用SytemUI接口进入到真正分屏
代码路径:packages/apps/Launcher3/quickstep/src/com/android/quickstep/views/TaskView.java
private void onClick(View view) {
if (getTask() == null) {
return;
}
if (confirmSecondSplitSelectApp()) {
return;
}
launchTasks();
mActivity.getStatsLogManager().logger().withItemInfo(getItemInfo())
.log(LAUNCHER_TASK_LAUNCH_TAP);
}
/**
* @return {@code true} if user is already in split select mode and this tap was to choose the
* second app. {@code false} otherwise
*/
protected boolean confirmSecondSplitSelectApp() {
int index = getLastSelectedChildTaskIndex();
TaskIdAttributeContainer container = mTaskIdAttributeContainer[index];
if (container != null) {
return getRecentsView().confirmSplitSelect(this, container.getTask(),
container.getIconView().getDrawable(), container.getThumbnailView(),
container.getThumbnailView().getThumbnail(), /* intent */ null,
/* user */ null);
}
return false;
}