use of com.android.launcher3.Launcher in project android_packages_apps_Launcher3 by AOSPA.
the class NavigationModeSwitchRule method setActiveOverlay.
public static boolean setActiveOverlay(LauncherInstrumentation launcher, String overlayPackage, LauncherInstrumentation.NavigationModel expectedMode, Description description) throws Exception {
if (!packageExists(overlayPackage)) {
Log.d(TAG, "setActiveOverlay: " + overlayPackage + " pkg does not exist");
return false;
}
Log.d(TAG, "setActiveOverlay: " + overlayPackage + "...");
UiDevice.getInstance(getInstrumentation()).executeShellCommand("cmd overlay enable-exclusive --category " + overlayPackage);
if (currentSysUiNavigationMode() != expectedMode) {
final CountDownLatch latch = new CountDownLatch(1);
final Context targetContext = getInstrumentation().getTargetContext();
final SysUINavigationMode.NavigationModeChangeListener listener = newMode -> {
if (LauncherInstrumentation.getNavigationModel(newMode.resValue) == expectedMode) {
latch.countDown();
}
};
targetContext.getMainExecutor().execute(() -> SYS_UI_NAVIGATION_MODE.addModeChangeListener(listener));
latch.await(60, TimeUnit.SECONDS);
targetContext.getMainExecutor().execute(() -> SYS_UI_NAVIGATION_MODE.removeModeChangeListener(listener));
assertTrue(launcher, "Navigation mode didn't change to " + expectedMode, currentSysUiNavigationMode() == expectedMode, description);
}
Wait.atMost("Couldn't switch to " + overlayPackage, () -> launcher.getNavigationModel() == expectedMode, WAIT_TIME_MS, launcher);
Wait.atMost(() -> "Switching nav mode: " + launcher.getNavigationModeMismatchError(false), () -> launcher.getNavigationModeMismatchError(false) == null, WAIT_TIME_MS, launcher);
AbstractLauncherUiTest.checkDetectedLeaks(launcher);
return true;
}
use of com.android.launcher3.Launcher in project android_packages_apps_Launcher3 by AOSPA.
the class StartLauncherViaGestureTests method runTest.
private void runTest(String... eventSequence) {
final RaceConditionReproducer eventProcessor = new RaceConditionReproducer(eventSequence);
// Destroy Launcher activity.
closeLauncherActivity();
// The test action.
eventProcessor.startIteration();
mLauncher.pressHome();
eventProcessor.finishIteration();
}
use of com.android.launcher3.Launcher in project android_packages_apps_Launcher3 by AOSPA.
the class CellLayout method applyColorExtractionOnWidget.
/**
* Applies the local color extraction to a dragging widget object.
*/
private void applyColorExtractionOnWidget(DropTarget.DragObject dragObject, int[] targetCell, int spanX, int spanY) {
// Apply local extracted color if the DragView is an AppWidgetHostViewDrawable.
View view = dragObject.dragView.getContentView();
if (view instanceof LauncherAppWidgetHostView) {
Launcher launcher = Launcher.getLauncher(getContext());
Workspace workspace = launcher.getWorkspace();
int screenId = workspace.getIdForScreen(this);
cellToRect(targetCell[0], targetCell[1], spanX, spanY, mTempRect);
((LauncherAppWidgetHostView) view).handleDrag(mTempRect, this, screenId);
}
}
use of com.android.launcher3.Launcher in project android_packages_apps_Launcher3 by AOSPA.
the class TaplTestsQuickstep method testBackground.
@Test
@NavigationModeSwitch
@PortraitLandscape
public void testBackground() throws Exception {
startAppFast(resolveSystemApp(Intent.CATEGORY_APP_CALCULATOR));
final Background background = getAndAssertBackground();
assertNotNull("Background.switchToOverview() returned null", background.switchToOverview());
assertTrue("Launcher internal state didn't switch to Overview", isInState(() -> LauncherState.OVERVIEW));
}
use of com.android.launcher3.Launcher in project android_packages_apps_Launcher3 by AOSPA.
the class DatabaseWidgetPreviewLoader method generateWidgetPreview.
/**
* Generates the widget preview from either the {@link WidgetManagerHelper} or cache
* and add badge at the bottom right corner.
*
* @param info information about the widget
* @param maxPreviewWidth width of the preview on either workspace or tray
* @param preScaledWidthOut return the width of the returned bitmap
*/
public Bitmap generateWidgetPreview(LauncherAppWidgetProviderInfo info, int maxPreviewWidth, int[] preScaledWidthOut) {
// Load the preview image if possible
if (maxPreviewWidth < 0)
maxPreviewWidth = Integer.MAX_VALUE;
Drawable drawable = null;
if (info.previewImage != 0) {
try {
drawable = info.loadPreviewImage(mContext, 0);
} catch (OutOfMemoryError e) {
Log.w(TAG, "Error loading widget preview for: " + info.provider, e);
// During OutOfMemoryError, the previous heap stack is not affected. Catching
// an OOM error here should be safe & not affect other parts of launcher.
drawable = null;
}
if (drawable != null) {
drawable = mutateOnMainThread(drawable);
} else {
Log.w(TAG, "Can't load widget preview drawable 0x" + Integer.toHexString(info.previewImage) + " for provider: " + info.provider);
}
}
final boolean widgetPreviewExists = (drawable != null);
final int spanX = info.spanX;
final int spanY = info.spanY;
int previewWidth;
int previewHeight;
DeviceProfile dp = ActivityContext.lookupContext(mContext).getDeviceProfile();
if (widgetPreviewExists && drawable.getIntrinsicWidth() > 0 && drawable.getIntrinsicHeight() > 0) {
previewWidth = drawable.getIntrinsicWidth();
previewHeight = drawable.getIntrinsicHeight();
} else {
Size widgetSize = WidgetSizes.getWidgetPaddedSizePx(mContext, info.provider, dp, spanX, spanY);
previewWidth = widgetSize.getWidth();
previewHeight = widgetSize.getHeight();
}
if (preScaledWidthOut != null) {
preScaledWidthOut[0] = previewWidth;
}
// Scale to fit width only - let the widget preview be clipped in the
// vertical dimension
final float scale = previewWidth > maxPreviewWidth ? (maxPreviewWidth / (float) (previewWidth)) : 1f;
if (scale != 1f) {
previewWidth = Math.max((int) (scale * previewWidth), 1);
previewHeight = Math.max((int) (scale * previewHeight), 1);
}
final int previewWidthF = previewWidth;
final int previewHeightF = previewHeight;
final Drawable drawableF = drawable;
return BitmapRenderer.createHardwareBitmap(previewWidth, previewHeight, c -> {
// Draw the scaled preview into the final bitmap
if (widgetPreviewExists) {
drawableF.setBounds(0, 0, previewWidthF, previewHeightF);
drawableF.draw(c);
} else {
RectF boxRect;
// Draw horizontal and vertical lines to represent individual columns.
final Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
if (Utilities.ATLEAST_S) {
boxRect = new RectF(/* left= */
0, /* top= */
0, /* right= */
previewWidthF, /* bottom= */
previewHeightF);
p.setStyle(Paint.Style.FILL);
p.setColor(Color.WHITE);
float roundedCorner = mContext.getResources().getDimension(android.R.dimen.system_app_widget_background_radius);
c.drawRoundRect(boxRect, roundedCorner, roundedCorner, p);
} else {
boxRect = drawBoxWithShadow(c, previewWidthF, previewHeightF);
}
p.setStyle(Paint.Style.STROKE);
p.setStrokeWidth(mContext.getResources().getDimension(R.dimen.widget_preview_cell_divider_width));
p.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
float t = boxRect.left;
float tileSize = boxRect.width() / spanX;
for (int i = 1; i < spanX; i++) {
t += tileSize;
c.drawLine(t, 0, t, previewHeightF, p);
}
t = boxRect.top;
tileSize = boxRect.height() / spanY;
for (int i = 1; i < spanY; i++) {
t += tileSize;
c.drawLine(0, t, previewWidthF, t, p);
}
// Draw icon in the center.
try {
Drawable icon = LauncherAppState.getInstance(mContext).getIconCache().getFullResIcon(info.provider.getPackageName(), info.icon);
if (icon != null) {
int appIconSize = dp.iconSizePx;
int iconSize = (int) Math.min(appIconSize * scale, Math.min(boxRect.width(), boxRect.height()));
icon = mutateOnMainThread(icon);
int hoffset = (previewWidthF - iconSize) / 2;
int yoffset = (previewHeightF - iconSize) / 2;
icon.setBounds(hoffset, yoffset, hoffset + iconSize, yoffset + iconSize);
icon.draw(c);
}
} catch (Resources.NotFoundException e) {
}
}
});
}
Aggregations