Changing RecentsView layout based on the split screen task size

Bug: 155816922
Change-Id: I33f69d72f8a27e3621d029c6ee4045c3664f3ac9
This commit is contained in:
Sunny Goyal
2020-05-07 00:07:14 -07:00
parent 7dcd4d6ed6
commit b78ea4b4fc
6 changed files with 190 additions and 33 deletions

View File

@@ -51,6 +51,7 @@ import com.android.launcher3.DeviceProfile;
import com.android.launcher3.Utilities;
import com.android.launcher3.testing.TestProtocol;
import com.android.launcher3.touch.PagedOrientationHandler;
import com.android.launcher3.util.WindowBounds;
import java.lang.annotation.Retention;
import java.util.function.IntConsumer;
@@ -361,7 +362,8 @@ public final class RecentsOrientedState implements SharedPreferences.OnSharedPre
float fullHeight = dp.heightPx - insets.top - insets.bottom;
if (dp.isMultiWindowMode) {
mSizeStrategy.getMultiWindowSize(mContext, dp, outPivot);
WindowBounds bounds = SplitScreenBounds.INSTANCE.getSecondaryWindowBounds(mContext);
outPivot.set(bounds.availableSize.x, bounds.availableSize.y);
} else {
outPivot.set(fullWidth, fullHeight);
}

View File

@@ -0,0 +1,112 @@
/*
* Copyright (C) 2020 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.util;
import static android.view.Surface.ROTATION_0;
import static android.view.Surface.ROTATION_180;
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Insets;
import android.graphics.Rect;
import android.os.Build;
import android.view.WindowInsets.Type;
import android.view.WindowManager;
import android.view.WindowMetrics;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.UiThread;
import com.android.launcher3.R;
import com.android.launcher3.util.DefaultDisplay;
import com.android.launcher3.util.WindowBounds;
import java.util.ArrayList;
/**
* Utility class to hold the information abound a window bounds for split screen
*/
@TargetApi(Build.VERSION_CODES.R)
public class SplitScreenBounds {
public static final SplitScreenBounds INSTANCE = new SplitScreenBounds();
private final ArrayList<OnChangeListener> mListeners = new ArrayList<>();
@Nullable
private WindowBounds mBounds;
private SplitScreenBounds() { }
@UiThread
public void setSecondaryWindowBounds(@NonNull WindowBounds bounds) {
if (!bounds.equals(mBounds)) {
mBounds = bounds;
for (OnChangeListener listener : mListeners) {
listener.onSecondaryWindowBoundsChanged();
}
}
}
public @NonNull WindowBounds getSecondaryWindowBounds(Context context) {
if (mBounds == null) {
mBounds = createDefaultWindowBounds(context);
}
return mBounds;
}
/**
* Creates window bounds as 50% of device size
*/
private static WindowBounds createDefaultWindowBounds(Context context) {
WindowMetrics wm = context.getSystemService(WindowManager.class).getMaximumWindowMetrics();
Insets insets = wm.getWindowInsets().getInsets(Type.systemBars());
WindowBounds bounds = new WindowBounds(wm.getBounds(),
new Rect(insets.left, insets.top, insets.right, insets.bottom));
int rotation = DefaultDisplay.INSTANCE.get(context).getInfo().rotation;
int halfDividerSize = context.getResources()
.getDimensionPixelSize(R.dimen.multi_window_task_divider_size) / 2;
if (rotation == ROTATION_0 || rotation == ROTATION_180) {
bounds.bounds.top = bounds.insets.top + bounds.availableSize.y / 2 + halfDividerSize;
bounds.insets.top = 0;
} else {
bounds.bounds.left = bounds.insets.left + bounds.availableSize.x / 2 + halfDividerSize;
bounds.insets.left = 0;
}
return new WindowBounds(bounds.bounds, bounds.insets);
}
public void addOnChangeListener(OnChangeListener listener) {
mListeners.add(listener);
}
public void removeOnChangeListener(OnChangeListener listener) {
mListeners.remove(listener);
}
/**
* Interface to receive window bounds changes
*/
public interface OnChangeListener {
/**
* Called when window bounds for secondary window changes
*/
void onSecondaryWindowBoundsChanged();
}
}

View File

@@ -20,13 +20,15 @@ import static com.android.quickstep.SysUINavigationMode.getMode;
import static com.android.quickstep.SysUINavigationMode.removeShelfFromOverview;
import static com.android.quickstep.util.LayoutUtils.getDefaultSwipeHeight;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.PointF;
import android.graphics.Rect;
import android.os.Build;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.R;
import com.android.launcher3.util.WindowBounds;
import com.android.quickstep.SysUINavigationMode.Mode;
/**
@@ -34,20 +36,15 @@ import com.android.quickstep.SysUINavigationMode.Mode;
* TODO: Merge is with {@link com.android.quickstep.BaseActivityInterface} once we remove the
* state dependent members from {@link com.android.quickstep.LauncherActivityInterface}
*/
@TargetApi(Build.VERSION_CODES.R)
public abstract class WindowSizeStrategy {
private final PointF mTempPoint = new PointF();
public final boolean rotationSupportedByActivity;
private WindowSizeStrategy(boolean rotationSupportedByActivity) {
this.rotationSupportedByActivity = rotationSupportedByActivity;
}
/**
* Sets the expected window size in multi-window mode
*/
public abstract void getMultiWindowSize(Context context, DeviceProfile dp, PointF out);
/**
* Calculates the taskView size for the provided device configuration
*/
@@ -65,9 +62,9 @@ public abstract class WindowSizeStrategy {
final boolean showLargeTaskSize = showOverviewActions(context);
if (dp.isMultiWindowMode) {
getMultiWindowSize(context, dp, mTempPoint);
taskWidth = mTempPoint.x;
taskHeight = mTempPoint.y;
WindowBounds bounds = SplitScreenBounds.INSTANCE.getSecondaryWindowBounds(context);
taskWidth = bounds.availableSize.x;
taskHeight = bounds.availableSize.y;
paddingHorz = res.getDimension(R.dimen.multi_window_task_card_horz_space);
} else {
taskWidth = dp.availableWidthPx;
@@ -113,22 +110,6 @@ public abstract class WindowSizeStrategy {
public static final WindowSizeStrategy LAUNCHER_ACTIVITY_SIZE_STRATEGY =
new WindowSizeStrategy(true) {
@Override
public void getMultiWindowSize(Context context, DeviceProfile dp, PointF out) {
DeviceProfile fullDp = dp.getFullScreenProfile();
// Use availableWidthPx and availableHeightPx instead of widthPx and heightPx to
// account for system insets
out.set(fullDp.availableWidthPx, fullDp.availableHeightPx);
float halfDividerSize = context.getResources()
.getDimension(R.dimen.multi_window_task_divider_size) / 2;
if (fullDp.isLandscape) {
out.x = out.x / 2 - halfDividerSize;
} else {
out.y = out.y / 2 - halfDividerSize;
}
}
@Override
float getExtraSpace(Context context, DeviceProfile dp) {
if (dp.isVerticalBarLayout()) {
@@ -164,10 +145,6 @@ public abstract class WindowSizeStrategy {
public static final WindowSizeStrategy FALLBACK_RECENTS_SIZE_STRATEGY =
new WindowSizeStrategy(false) {
@Override
public void getMultiWindowSize(Context context, DeviceProfile dp, PointF out) {
out.set(dp.widthPx, dp.heightPx);
}
@Override
float getExtraSpace(Context context, DeviceProfile dp) {