This is a preliminary work for local color extraction. In order to
apply local colors extracted from wallpaper to AppWidgetHostView
during drag, we need to hold a reference of the dragging
AppWidgetHostView.
In this CL, the following changes are made:
1. Instead of using bitmap image directly for icons, folders, shortcuts,
legacy widget drawable preview, a BitmapDrawable wrapper is
introduced.
2. Introduce a WidgetHostViewDraggableDrawable which draws
LauncherAppWidgetHostView directly to canvas. No more bitmap
generation overhead.
3. Remove drag outline from the drag logic because this will be replaced
by a new grid color hint UI: https://screenshot.googleplex.com/7jBEVeuxFecFKKT.png
Test: Add: add widgets, shortcuts from widgets tray.
add icons from all apps.
create folder.
Drag: drag existing widgets, shortcuts, folders and icons around
Bug: 182282587
Change-Id: Ia45ff756ea5bb80cf0761f0727a9453d50c204c0
80 lines
2.3 KiB
Java
80 lines
2.3 KiB
Java
/*
|
|
* Copyright (C) 2021 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.dragndrop;
|
|
|
|
import android.graphics.Canvas;
|
|
import android.graphics.ColorFilter;
|
|
import android.graphics.Paint;
|
|
import android.graphics.PixelFormat;
|
|
import android.graphics.drawable.Drawable;
|
|
|
|
import com.android.launcher3.widget.LauncherAppWidgetHostView;
|
|
|
|
/** A drawable which renders {@link LauncherAppWidgetHostView} to a canvas. */
|
|
public final class AppWidgetHostViewDrawable extends Drawable {
|
|
|
|
private final LauncherAppWidgetHostView mAppWidgetHostView;
|
|
private Paint mPaint = new Paint();
|
|
|
|
public AppWidgetHostViewDrawable(LauncherAppWidgetHostView appWidgetHostView) {
|
|
mAppWidgetHostView = appWidgetHostView;
|
|
}
|
|
|
|
@Override
|
|
public void draw(Canvas canvas) {
|
|
int saveCount = canvas.saveLayer(0, 0, getIntrinsicWidth(), getIntrinsicHeight(), mPaint);
|
|
mAppWidgetHostView.draw(canvas);
|
|
canvas.restoreToCount(saveCount);
|
|
}
|
|
|
|
@Override
|
|
public int getIntrinsicWidth() {
|
|
return mAppWidgetHostView.getMeasuredWidth();
|
|
}
|
|
|
|
@Override
|
|
public int getIntrinsicHeight() {
|
|
return mAppWidgetHostView.getMeasuredHeight();
|
|
}
|
|
|
|
@Override
|
|
public int getOpacity() {
|
|
// This is up to app widget provider. We don't know if the host view will cover anything
|
|
// behind the drawable.
|
|
return PixelFormat.UNKNOWN;
|
|
}
|
|
|
|
@Override
|
|
public void setAlpha(int alpha) {
|
|
mPaint.setAlpha(alpha);
|
|
}
|
|
|
|
@Override
|
|
public int getAlpha() {
|
|
return mPaint.getAlpha();
|
|
}
|
|
|
|
@Override
|
|
public void setColorFilter(ColorFilter colorFilter) {
|
|
mPaint.setColorFilter(colorFilter);
|
|
}
|
|
|
|
@Override
|
|
public ColorFilter getColorFilter() {
|
|
return mPaint.getColorFilter();
|
|
}
|
|
}
|