Add icon to desktop tile in overview

Copied over icon from caption desktop button in WMShell. Temporary icon
for now.
Refactored some logic in TaskView to better support for custom
orientation handling in subclasses. Subclasses can override setting
orientation for icon or thumbnail.

Bug: 267326722
Test: manual, enable desktop windowing proto 2 and go to overview
Change-Id: Id66d48fa52a418a07b954a384b2c3ea22f091b1f
This commit is contained in:
Ats Jenk
2023-02-10 10:16:31 -08:00
parent f5f3a80959
commit 78b614f555
4 changed files with 80 additions and 23 deletions
@@ -24,6 +24,8 @@ import static com.android.launcher3.util.SplitConfigurationOptions.STAGE_POSITIO
import android.content.Context;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.RoundRectShape;
import android.os.SystemProperties;
@@ -31,14 +33,16 @@ import android.util.AttributeSet;
import android.util.Log;
import android.util.SparseArray;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.Launcher;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.touch.PagedOrientationHandler;
import com.android.launcher3.util.RunnableList;
import com.android.quickstep.RecentsModel;
import com.android.quickstep.SystemUiProxy;
@@ -87,7 +91,7 @@ public class DesktopTaskView extends TaskView {
private final ArrayList<CancellableTask<?>> mPendingThumbnailRequests = new ArrayList<>();
private ShapeDrawable mBackground;
private View mBackgroundView;
public DesktopTaskView(Context context) {
this(context, null);
@@ -104,14 +108,28 @@ public class DesktopTaskView extends TaskView {
@Override
protected void onFinishInflate() {
super.onFinishInflate();
mBackgroundView = findViewById(R.id.background);
int topMarginPx =
mActivity.getDeviceProfile().overviewTaskThumbnailTopMarginPx;
FrameLayout.LayoutParams params = (LayoutParams) mBackgroundView.getLayoutParams();
params.topMargin = topMarginPx;
mBackgroundView.setLayoutParams(params);
float[] outerRadii = new float[8];
Arrays.fill(outerRadii, getTaskCornerRadius());
RoundRectShape shape = new RoundRectShape(outerRadii, null, null);
mBackground = new ShapeDrawable(shape);
mBackground.setTint(getResources().getColor(android.R.color.system_neutral2_300,
ShapeDrawable background = new ShapeDrawable(shape);
background.setTint(getResources().getColor(android.R.color.system_neutral2_300,
getContext().getTheme()));
// TODO(b/244348395): this should be wallpaper
setBackground(mBackground);
mBackgroundView.setBackground(background);
Drawable icon = getResources().getDrawable(R.drawable.ic_desktop, getContext().getTheme());
Drawable iconBackground = getResources().getDrawable(R.drawable.bg_circle,
getContext().getTheme());
mIconView.setDrawable(new LayerDrawable(new Drawable[]{iconBackground, icon}));
}
@Override
@@ -252,20 +270,9 @@ public class DesktopTaskView extends TaskView {
}
@Override
public void setOrientationState(RecentsOrientedState orientationState) {
// TODO(b/249371338): this copies logic from TaskView
PagedOrientationHandler orientationHandler = orientationState.getOrientationHandler();
boolean isRtl = getLayoutDirection() == LAYOUT_DIRECTION_RTL;
protected void setThumbnailOrientation(RecentsOrientedState orientationState) {
DeviceProfile deviceProfile = mActivity.getDeviceProfile();
LayoutParams iconParams = (LayoutParams) mIconView.getLayoutParams();
int thumbnailTopMargin = deviceProfile.overviewTaskThumbnailTopMarginPx;
int taskIconHeight = deviceProfile.overviewTaskIconSizePx;
int taskMargin = deviceProfile.overviewTaskMarginPx;
orientationHandler.setTaskIconParams(iconParams, taskMargin, taskIconHeight,
thumbnailTopMargin, isRtl);
LayoutParams snapshotParams = (LayoutParams) mSnapshotView.getLayoutParams();
snapshotParams.topMargin = thumbnailTopMargin;
@@ -374,6 +381,9 @@ public class DesktopTaskView extends TaskView {
setMeasuredDimension(containerWidth, containerHeight);
int thumbnailTopMarginPx = mActivity.getDeviceProfile().overviewTaskThumbnailTopMarginPx;
containerHeight -= thumbnailTopMarginPx;
int thumbnails = mSnapshotViewMap.size();
if (thumbnails == 0) {
return;
@@ -416,6 +426,8 @@ public class DesktopTaskView extends TaskView {
}
int taskX = (int) (positionInParent.x * scaleWidth);
int taskY = (int) (positionInParent.y * scaleHeight);
// move task down by margin size
taskY += thumbnailTopMarginPx;
thumbnailView.setX(taskX);
thumbnailView.setY(taskY);
@@ -439,9 +451,9 @@ public class DesktopTaskView extends TaskView {
mFullscreenProgress = progress;
if (mFullscreenProgress > 0) {
// Don't show background while we are transitioning to/from fullscreen
setBackground(null);
mBackgroundView.setVisibility(INVISIBLE);
} else {
setBackground(mBackground);
mBackgroundView.setVisibility(VISIBLE);
}
for (int i = 0; i < mSnapshotViewMap.size(); i++) {
TaskThumbnailView thumbnailView = mSnapshotViewMap.valueAt(i);
@@ -996,6 +996,11 @@ public class TaskView extends FrameLayout implements Reusable {
}
public void setOrientationState(RecentsOrientedState orientationState) {
setIconOrientation(orientationState);
setThumbnailOrientation(orientationState);
}
protected void setIconOrientation(RecentsOrientedState orientationState) {
PagedOrientationHandler orientationHandler = orientationState.getOrientationHandler();
boolean isRtl = getLayoutDirection() == LAYOUT_DIRECTION_RTL;
DeviceProfile deviceProfile = mActivity.getDeviceProfile();
@@ -1016,6 +1021,11 @@ public class TaskView extends FrameLayout implements Reusable {
int iconDrawableSize = isGridTask ? deviceProfile.overviewTaskIconDrawableSizeGridPx
: deviceProfile.overviewTaskIconDrawableSizePx;
mIconView.setDrawableSize(iconDrawableSize, iconDrawableSize);
}
protected void setThumbnailOrientation(RecentsOrientedState orientationState) {
DeviceProfile deviceProfile = mActivity.getDeviceProfile();
int thumbnailTopMargin = deviceProfile.overviewTaskThumbnailTopMarginPx;
LayoutParams snapshotParams = (LayoutParams) mSnapshotView.getLayoutParams();
snapshotParams.topMargin = thumbnailTopMargin;