Add activity interface to Recents Go view

Add an interface for recents to activity logic that can be set on the Go
recents view. This CL includes a method for the logic that should occur
when leaving recents due to having no tasks remaining.

As the view has no knowledge of the containing activity (could be
Launcher or could be a separate activity), this interface must be set
externally.

Bug: 114136250
Test: Remove all tasks, see that it goes to home when l3goIconRecents is
the default launcher
Change-Id: I110abab49c22e245b98a1f9b91b0b0f052886098
This commit is contained in:
Kevin 2019-03-14 11:28:36 -07:00
parent aaffa2385f
commit 5163b58d52
6 changed files with 118 additions and 1 deletions

View File

@ -0,0 +1,38 @@
/*
* 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.launcher3;
import static com.android.launcher3.LauncherState.NORMAL;
import com.android.quickstep.RecentsToActivityHelper;
/**
* {@link RecentsToActivityHelper} for when the recents implementation is contained in
* {@link Launcher}.
*/
public final class LauncherRecentsToActivityHelper implements RecentsToActivityHelper {
private final Launcher mLauncher;
public LauncherRecentsToActivityHelper(Launcher launcher) {
mLauncher = launcher;
}
@Override
public void leaveRecents() {
mLauncher.getStateManager().goToState(NORMAL);
}
}

View File

@ -23,6 +23,7 @@ import android.util.FloatProperty;
import androidx.annotation.NonNull;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherRecentsToActivityHelper;
import com.android.quickstep.views.IconRecentsView;
/**
@ -33,6 +34,8 @@ public final class RecentsViewStateController extends
public RecentsViewStateController(@NonNull Launcher launcher) {
super(launcher);
launcher.<IconRecentsView>getOverviewPanel().setRecentsToActivityHelper(
new LauncherRecentsToActivityHelper(launcher));
}
@Override

View File

@ -0,0 +1,34 @@
/*
* 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;
/**
* {@link RecentsToActivityHelper} for when we are using the fallback recents in
* {@link BaseRecentsActivity}.
*/
public final class FallbackRecentsToActivityHelper implements RecentsToActivityHelper {
BaseRecentsActivity mActivity;
public FallbackRecentsToActivityHelper(BaseRecentsActivity activity) {
mActivity = activity;
}
@Override
public void leaveRecents() {
mActivity.startHome();
}
}

View File

@ -36,6 +36,7 @@ public final class RecentsActivity extends BaseRecentsActivity {
setContentView(R.layout.fallback_recents_activity);
mRecentsRootView = findViewById(R.id.drag_layer);
mIconRecentsView = findViewById(R.id.overview_panel);
mIconRecentsView.setRecentsToActivityHelper(new FallbackRecentsToActivityHelper(this));
}
@Override

View File

@ -0,0 +1,29 @@
/*
* 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;
/**
* Generic interface providing methods to the recents implementation that allow it to callback to
* the containing activity.
*/
public interface RecentsToActivityHelper {
/**
* The default action to take when leaving/closing recents. In general, this should be used to
* go to the appropriate home state.
*/
void leaveRecents();
}

View File

@ -26,12 +26,14 @@ import android.view.View;
import android.view.ViewDebug;
import android.widget.FrameLayout;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView.AdapterDataObserver;
import com.android.launcher3.R;
import com.android.quickstep.RecentsToActivityHelper;
import com.android.quickstep.TaskAdapter;
import com.android.quickstep.TaskInputController;
import com.android.quickstep.TaskListLoader;
@ -87,6 +89,7 @@ public final class IconRecentsView extends FrameLayout {
private final TaskAdapter mTaskAdapter;
private final TaskInputController mTaskInputController;
private RecentsToActivityHelper mActivityHelper;
private float mTranslationYFactor;
private RecyclerView mTaskRecyclerView;
private View mEmptyView;
@ -127,6 +130,15 @@ public final class IconRecentsView extends FrameLayout {
}
}
/**
* Set activity helper for the view to callback to.
*
* @param helper the activity helper
*/
public void setRecentsToActivityHelper(@NonNull RecentsToActivityHelper helper) {
mActivityHelper = helper;
}
/**
* Logic for when we know we are going to overview/recents and will be putting up the recents
* view. This should be used to prepare recents (e.g. load any task data, etc.) before it
@ -160,7 +172,7 @@ public final class IconRecentsView extends FrameLayout {
int taskListSize = mTaskLoader.getCurrentTaskList().size();
if (mEmptyView.getVisibility() != VISIBLE && taskListSize == 0) {
crossfadeViews(mEmptyView, mTaskRecyclerView);
// TODO: Go to home.
mActivityHelper.leaveRecents();
}
if (mTaskRecyclerView.getVisibility() != VISIBLE && taskListSize > 0) {
crossfadeViews(mTaskRecyclerView, mEmptyView);