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
This commit is contained in:
Kevin 2019-02-25 12:04:02 -08:00
parent b04dabf7ef
commit 0fcd22fc66
3 changed files with 125 additions and 1 deletions

View File

@ -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<TaskHolder> {
private static final int MAX_TASKS_TO_DISPLAY = 6;
private static final String TAG = "TaskAdapter";
private final ArrayList<Task> mTaskList;
public TaskAdapter(@NonNull ArrayList<Task> 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);
}
}

View File

@ -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);
}
}

View File

@ -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<Task> 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));