use of com.android.launcher3.tapl.Widget in project android_packages_apps_Trebuchet by LineageOS.
the class Workspace method removeAllWorkspaceScreens.
public void removeAllWorkspaceScreens() {
// Disable all layout transitions before removing all pages to ensure that we don't get the
// transition animations competing with us changing the scroll when we add pages
disableLayoutTransitions();
// Recycle the QSB widget
View qsb = findViewById(R.id.search_container_workspace);
if (qsb != null) {
((ViewGroup) qsb.getParent()).removeView(qsb);
}
// Remove the pages and clear the screen models
removeFolderListeners();
removeAllViews();
mScreenOrder.clear();
mWorkspaceScreens.clear();
// Remove any deferred refresh callbacks
mLauncher.mHandler.removeCallbacksAndMessages(DeferredWidgetRefresh.class);
// Ensure that the first page is always present
bindAndInitFirstWorkspaceScreen(qsb);
// Re-enable the layout transitions
enableLayoutTransitions();
}
use of com.android.launcher3.tapl.Widget in project android_packages_apps_Trebuchet by LineageOS.
the class WorkspaceAccessibilityHelper method intersectsValidDropTarget.
/**
* Find the virtual view id corresponding to the top left corner of any drop region by which
* the passed id is contained. For an icon, this is simply
*/
@Override
protected int intersectsValidDropTarget(int id) {
int mCountX = mView.getCountX();
int mCountY = mView.getCountY();
int x = id % mCountX;
int y = id / mCountX;
LauncherAccessibilityDelegate.DragInfo dragInfo = mDelegate.getDragInfo();
if (dragInfo.dragType == DragType.WIDGET && !mView.acceptsWidget()) {
return INVALID_POSITION;
}
if (dragInfo.dragType == DragType.WIDGET) {
// For a widget, every cell must be vacant. In addition, we will return any valid
// drop target by which the passed id is contained.
boolean fits = false;
// These represent the amount that we can back off if we hit a problem. They
// get consumed as we move up and to the right, trying new regions.
int spanX = dragInfo.info.spanX;
int spanY = dragInfo.info.spanY;
for (int m = 0; m < spanX; m++) {
for (int n = 0; n < spanY; n++) {
fits = true;
int x0 = x - m;
int y0 = y - n;
if (x0 < 0 || y0 < 0)
continue;
for (int i = x0; i < x0 + spanX; i++) {
if (!fits)
break;
for (int j = y0; j < y0 + spanY; j++) {
if (i >= mCountX || j >= mCountY || mView.isOccupied(i, j)) {
fits = false;
break;
}
}
}
if (fits) {
return x0 + mCountX * y0;
}
}
}
return INVALID_POSITION;
} else {
// For an icon, we simply check the view directly below
View child = mView.getChildAt(x, y);
if (child == null || child == dragInfo.item) {
// Empty cell. Good for an icon or folder.
return id;
} else if (dragInfo.dragType != DragType.FOLDER) {
// For icons, we can consider cells that have another icon or a folder.
ItemInfo info = (ItemInfo) child.getTag();
if (info instanceof AppInfo || info instanceof FolderInfo || info instanceof WorkspaceItemInfo) {
return id;
}
}
return INVALID_POSITION;
}
}
use of com.android.launcher3.tapl.Widget in project android_packages_apps_Trebuchet by LineageOS.
the class LauncherAppWidgetHost method createView.
public AppWidgetHostView createView(Context context, int appWidgetId, LauncherAppWidgetProviderInfo appWidget) {
if (appWidget.isCustomWidget()) {
LauncherAppWidgetHostView lahv = new LauncherAppWidgetHostView(context);
lahv.setAppWidget(0, appWidget);
CustomWidgetManager.INSTANCE.get(context).onViewCreated(lahv);
return lahv;
} else if ((mFlags & FLAG_LISTENING) == 0) {
DeferredAppWidgetHostView view = new DeferredAppWidgetHostView(context);
view.setAppWidget(appWidgetId, appWidget);
mViews.put(appWidgetId, view);
return view;
} else {
try {
return super.createView(context, appWidgetId, appWidget);
} catch (Exception e) {
if (!Utilities.isBinderSizeError(e)) {
throw new RuntimeException(e);
}
// If the exception was thrown while fetching the remote views, let the view stay.
// This will ensure that if the widget posts a valid update later, the view
// will update.
LauncherAppWidgetHostView view = mViews.get(appWidgetId);
if (view == null) {
view = onCreateView(mContext, appWidgetId, appWidget);
}
view.setAppWidget(appWidgetId, appWidget);
view.switchToErrorView();
return view;
}
}
}
use of com.android.launcher3.tapl.Widget in project android_packages_apps_Trebuchet by LineageOS.
the class AddConfigWidgetTest method runTest.
/**
* @param acceptConfig accept the config activity
*/
private void runTest(boolean acceptConfig) throws Throwable {
clearHomescreen();
mDevice.pressHome();
final Widgets widgets = mLauncher.getWorkspace().openAllWidgets();
// Drag widget to homescreen
WidgetConfigStartupMonitor monitor = new WidgetConfigStartupMonitor();
widgets.getWidget(mWidgetInfo.getLabel(mTargetContext.getPackageManager())).dragToWorkspace(true, false);
// Widget id for which the config activity was opened
mWidgetId = monitor.getWidgetId();
// Verify that the widget id is valid and bound
assertNotNull(mAppWidgetManager.getAppWidgetInfo(mWidgetId));
setResult(acceptConfig);
if (acceptConfig) {
Wait.atMost("", new WidgetSearchCondition(), DEFAULT_ACTIVITY_TIMEOUT, mLauncher);
assertNotNull(mAppWidgetManager.getAppWidgetInfo(mWidgetId));
} else {
// Verify that the widget id is deleted.
Wait.atMost("", () -> mAppWidgetManager.getAppWidgetInfo(mWidgetId) == null, DEFAULT_ACTIVITY_TIMEOUT, mLauncher);
}
}
use of com.android.launcher3.tapl.Widget in project android_packages_apps_Trebuchet by LineageOS.
the class BindWidgetTest method verifyWidgetPresent.
private void verifyWidgetPresent(LauncherAppWidgetProviderInfo info) {
final Widget widget = mLauncher.getWorkspace().tryGetWidget(info.label, DEFAULT_UI_TIMEOUT);
assertTrue("Widget is not present", widget != null);
}
Aggregations