use of com.android.launcher3.PagedView in project android_packages_apps_Launcher3 by crdroidandroid.
the class KeyboardDragAndDropView method setCurrentSelection.
private void setCurrentSelection(VirtualNodeInfo nodeInfo) {
mCurrentSelection = nodeInfo;
((TextView) findViewById(R.id.label)).setText(nodeInfo.populate(mTempNodeInfo).getContentDescription());
Rect bounds = new Rect();
mTempNodeInfo.getBoundsInParent(bounds);
View host = nodeInfo.delegate.getHost();
ViewParent parent = host.getParent();
if (parent instanceof PagedView) {
PagedView pv = (PagedView) parent;
int pageIndex = pv.indexOfChild(host);
pv.setCurrentPage(pageIndex);
bounds.offset(pv.getScrollX() - pv.getScrollForPage(pageIndex), 0);
}
float[] pos = new float[] { bounds.left, bounds.top, bounds.right, bounds.bottom };
Utilities.getDescendantCoordRelativeToAncestor(host, mLauncher.getDragLayer(), pos, true);
new RectF(pos[0], pos[1], pos[2], pos[3]).roundOut(bounds);
mFocusIndicator.changeFocus(bounds, true);
}
use of com.android.launcher3.PagedView in project android_packages_apps_Launcher3 by crdroidandroid.
the class KeyboardDragAndDropView method getNextSelection.
/**
* Focus finding logic:
* Collect all virtual nodes in reading order (used for forward and backwards).
* Then find the closest view by comparing the distances spatially. Since it is a move
* operation. consider all cell sizes to be approximately of the same size.
*/
private VirtualNodeInfo getNextSelection(int direction) {
// Collect all virtual nodes
mDelegates.clear();
mNodes.clear();
Folder openFolder = Folder.getOpen(mLauncher);
PagedView pv = openFolder == null ? mLauncher.getWorkspace() : openFolder.getContent();
int count = pv.getPageCount();
for (int i = 0; i < count; i++) {
mDelegates.add(((CellLayout) pv.getChildAt(i)).getDragAndDropAccessibilityDelegate());
}
if (openFolder == null) {
mDelegates.add(pv.getNextPage() + 1, mLauncher.getHotseat().getDragAndDropAccessibilityDelegate());
}
mDelegates.forEach(delegate -> {
mIntList.clear();
delegate.getVisibleVirtualViews(mIntList);
mIntList.forEach(id -> mNodes.add(new VirtualNodeInfo(delegate, id)));
});
if (mNodes.isEmpty()) {
return null;
}
int index = mNodes.indexOf(mCurrentSelection);
if (mCurrentSelection == null || index < 0) {
return null;
}
int totalNodes = mNodes.size();
final ToIntBiFunction<Rect, Rect> majorAxis;
final ToIntFunction<Rect> minorAxis;
switch(direction) {
case View.FOCUS_RIGHT:
majorAxis = (source, dest) -> dest.left - source.left;
minorAxis = Rect::centerY;
break;
case View.FOCUS_LEFT:
majorAxis = (source, dest) -> source.left - dest.left;
minorAxis = Rect::centerY;
break;
case View.FOCUS_UP:
majorAxis = (source, dest) -> source.top - dest.top;
minorAxis = Rect::centerX;
break;
case View.FOCUS_DOWN:
majorAxis = (source, dest) -> dest.top - source.top;
minorAxis = Rect::centerX;
break;
case View.FOCUS_FORWARD:
return mNodes.get((index + 1) % totalNodes);
case View.FOCUS_BACKWARD:
return mNodes.get((index + totalNodes - 1) % totalNodes);
default:
// Unknown direction
return null;
}
mCurrentSelection.populate(mTempNodeInfo).getBoundsInScreen(mTempRect);
float minWeight = Float.MAX_VALUE;
VirtualNodeInfo match = null;
for (int i = 0; i < totalNodes; i++) {
VirtualNodeInfo node = mNodes.get(i);
node.populate(mTempNodeInfo).getBoundsInScreen(mTempRect2);
int majorAxisWeight = majorAxis.applyAsInt(mTempRect, mTempRect2);
if (majorAxisWeight <= 0) {
continue;
}
int minorAxisWeight = minorAxis.applyAsInt(mTempRect2) - minorAxis.applyAsInt(mTempRect);
float weight = majorAxisWeight * majorAxisWeight + minorAxisWeight * minorAxisWeight * MINOR_AXIS_WEIGHT;
if (weight < minWeight) {
minWeight = weight;
match = node;
}
}
return match;
}
use of com.android.launcher3.PagedView in project android_packages_apps_Launcher3 by crdroidandroid.
the class ViewGroupFocusHelper method computeLocationRelativeToContainer.
private void computeLocationRelativeToContainer(View child, Rect outRect) {
View parent = (View) child.getParent();
outRect.left += child.getX();
outRect.top += child.getY();
if (parent != mContainer) {
if (parent instanceof PagedView) {
PagedView page = (PagedView) parent;
outRect.left -= page.getScrollForPage(page.indexOfChild(child));
}
computeLocationRelativeToContainer(parent, outRect);
}
}
use of com.android.launcher3.PagedView in project android_packages_apps_Launcher3 by crdroidandroid.
the class SDWorkModeTest method testAllAppsList_workProfile.
@Test
public void testAllAppsList_workProfile() throws Exception {
ShadowUserManager sum = Shadow.extract(mTargetContext.getSystemService(UserManager.class));
sum.addUser(SYSTEM_USER, "me", FLAG_SYSTEM);
sum.addProfile(SYSTEM_USER, WORK_PROFILE_ID, "work", FLAG_PROFILE);
SecondaryDisplayLauncher launcher = loadLauncher();
launcher.showAppDrawer(true);
doLayout(launcher);
AllAppsRecyclerView rv1 = launcher.getAppsView().getActiveRecyclerView();
verifyRecyclerViewCount(rv1);
assertNotNull(launcher.getAppsView().getWorkModeSwitch());
assertTrue(launcher.getAppsView().getRecyclerViewContainer() instanceof AllAppsPagedView);
AllAppsPagedView pagedView = (AllAppsPagedView) launcher.getAppsView().getRecyclerViewContainer();
pagedView.snapToPageImmediately(1);
doLayout(launcher);
AllAppsRecyclerView rv2 = launcher.getAppsView().getActiveRecyclerView();
verifyRecyclerViewCount(rv2);
assertNotSame(rv1, rv2);
}
use of com.android.launcher3.PagedView in project android_packages_apps_Launcher3 by crdroidandroid.
the class WorkTabTest method testWorkEduIntermittent.
@Ignore("b/182844465")
@Test
public void testWorkEduIntermittent() {
mDevice.pressHome();
waitForLauncherCondition("Launcher didn't start", Objects::nonNull);
executeOnLauncher(launcher -> launcher.getSharedPrefs().edit().remove(WorkEduView.KEY_WORK_EDU_STEP).remove(WorkEduView.KEY_LEGACY_WORK_EDU_SEEN).commit());
waitForLauncherCondition("Work tab not setup", launcher -> launcher.getAppsView().getContentView() instanceof AllAppsPagedView, 60000);
executeOnLauncher(launcher -> launcher.getStateManager().goToState(ALL_APPS));
// verify personal app edu is seen
getEduView();
// dismiss personal edu
mDevice.pressHome();
waitForState("Launcher did not go home", () -> NORMAL);
// open work tab
executeOnLauncher(launcher -> launcher.getStateManager().goToState(ALL_APPS));
waitForState("Launcher did not switch to all apps", () -> ALL_APPS);
waitForLauncherCondition("Work tab not setup", launcher -> launcher.getAppsView().getContentView() instanceof AllAppsPagedView, 60000);
executeOnLauncher(launcher -> {
AllAppsPagedView pagedView = (AllAppsPagedView) launcher.getAppsView().getContentView();
pagedView.setCurrentPage(WORK_PAGE);
});
WorkEduView workEduView = getEduView();
// verify work tab edu is shown
waitForLauncherCondition("Launcher did not show the next edu screen", l -> ((TextView) workEduView.findViewById(R.id.content_text)).getText().equals(l.getResources().getString(R.string.work_profile_edu_work_apps)));
}
Aggregations