From 0fcd22fc66ef544c2e082b7a5aa406edc78e22a9 Mon Sep 17 00:00:00 2001 From: Kevin Date: Mon, 25 Feb 2019 12:04:02 -0800 Subject: [PATCH] Add TaskAdapter to recents Go. This CL adds a recycler view adapter for tasks to manage the item control logic. The data source itself and view hierarchy is planned to be added in future CLs. Bug: 114136250 Test: Build l3GoIconRecents Change-Id: I72d4f9df68d17fd745947d36522cde342ea58317 --- .../com/android/quickstep/TaskAdapter.java | 58 +++++++++++++++++++ .../src/com/android/quickstep/TaskHolder.java | 48 +++++++++++++++ .../quickstep/views/IconRecentsView.java | 20 ++++++- 3 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 go/quickstep/src/com/android/quickstep/TaskAdapter.java create mode 100644 go/quickstep/src/com/android/quickstep/TaskHolder.java diff --git a/go/quickstep/src/com/android/quickstep/TaskAdapter.java b/go/quickstep/src/com/android/quickstep/TaskAdapter.java new file mode 100644 index 0000000000..77c3f33b04 --- /dev/null +++ b/go/quickstep/src/com/android/quickstep/TaskAdapter.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.quickstep; + +import android.view.ViewGroup; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView.Adapter; + +import com.android.systemui.shared.recents.model.Task; + +import java.util.ArrayList; + +/** + * Recycler view adapter that dynamically inflates and binds {@link TaskHolder} instances with the + * appropriate {@link Task} from the recents task list. + */ +public final class TaskAdapter extends Adapter { + + private static final int MAX_TASKS_TO_DISPLAY = 6; + private static final String TAG = "TaskAdapter"; + private final ArrayList mTaskList; + + public TaskAdapter(@NonNull ArrayList taskList) { + mTaskList = taskList; + } + + @Override + public TaskHolder onCreateViewHolder(ViewGroup parent, int viewType) { + // TODO: Swap in an actual task view here (view w/ icon, label, etc.) + TextView stubView = new TextView(parent.getContext()); + return new TaskHolder(stubView); + } + + @Override + public void onBindViewHolder(TaskHolder holder, int position) { + holder.bindTask(mTaskList.get(position)); + } + + @Override + public int getItemCount() { + return Math.min(mTaskList.size(), MAX_TASKS_TO_DISPLAY); + } +} diff --git a/go/quickstep/src/com/android/quickstep/TaskHolder.java b/go/quickstep/src/com/android/quickstep/TaskHolder.java new file mode 100644 index 0000000000..1ea6d7610f --- /dev/null +++ b/go/quickstep/src/com/android/quickstep/TaskHolder.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.quickstep; + +import android.widget.TextView; + +import androidx.recyclerview.widget.RecyclerView.ViewHolder; + +import com.android.systemui.shared.recents.model.Task; + +/** + * A recycler view holder that holds the task view and binds {@link Task} content (app title, icon, + * etc.) to the view. + */ +final class TaskHolder extends ViewHolder { + + // TODO: Implement the actual task view to be held. + // For now, we just use a simple text view. + private final TextView mStubView; + + public TaskHolder(TextView stubView) { + super(stubView); + mStubView = stubView; + } + + /** + * Bind task content to the view. This includes the task icon and title as well as binding + * input handlers such as which task to launch/remove. + * + * @param task the task to bind to the view this + */ + public void bindTask(Task task) { + mStubView.setText("Stub task view: " + task.titleDescription); + } +} diff --git a/go/quickstep/src/com/android/quickstep/views/IconRecentsView.java b/go/quickstep/src/com/android/quickstep/views/IconRecentsView.java index e4741e9d50..ae8166c236 100644 --- a/go/quickstep/src/com/android/quickstep/views/IconRecentsView.java +++ b/go/quickstep/src/com/android/quickstep/views/IconRecentsView.java @@ -21,8 +21,14 @@ import android.util.FloatProperty; import android.view.ViewDebug; import android.widget.FrameLayout; +import com.android.quickstep.TaskAdapter; +import com.android.systemui.shared.recents.model.Task; + +import java.util.ArrayList; + /** - * Root view for the icon recents view. + * Root view for the icon recents view. Acts as the main interface to the rest of the Launcher code + * base. */ public final class IconRecentsView extends FrameLayout { @@ -58,12 +64,24 @@ public final class IconRecentsView extends FrameLayout { * is top aligned and 0.5 is centered vertically. */ @ViewDebug.ExportedProperty(category = "launcher") + + // TODO: Write a recents task list observer that creates/updates tasks and signals task adapter. + private static final ArrayList DUMMY_TASK_LIST = new ArrayList<>(); + private float mTranslationYFactor; + private TaskAdapter mTaskAdapter; public IconRecentsView(Context context, AttributeSet attrs) { super(context, attrs); } + @Override + protected void onFinishInflate() { + super.onFinishInflate(); + mTaskAdapter = new TaskAdapter(DUMMY_TASK_LIST); + // TODO: Hook task adapter up to recycler view. + } + public void setTranslationYFactor(float translationFactor) { mTranslationYFactor = translationFactor; setTranslationY(computeTranslationYForFactor(mTranslationYFactor));