Search in sources :

Example 31 with Workspace

use of com.android.launcher3.Workspace in project android_packages_apps_Launcher3 by crdroidandroid.

the class SpringLoadedState method getWorkspaceScaleAndTranslation.

@Override
public ScaleAndTranslation getWorkspaceScaleAndTranslation(Launcher launcher) {
    DeviceProfile grid = launcher.getDeviceProfile();
    Workspace ws = launcher.getWorkspace();
    if (ws.getChildCount() == 0) {
        return super.getWorkspaceScaleAndTranslation(launcher);
    }
    if (grid.isVerticalBarLayout()) {
        float scale = grid.workspaceSpringLoadShrinkFactor;
        return new ScaleAndTranslation(scale, 0, 0);
    }
    float scale = grid.workspaceSpringLoadShrinkFactor;
    Rect insets = launcher.getDragLayer().getInsets();
    int insetsBottom = grid.isTaskbarPresent ? grid.taskbarSize : insets.bottom;
    float scaledHeight = scale * ws.getNormalChildHeight();
    float shrunkTop = insets.top + grid.dropTargetBarSizePx;
    float shrunkBottom = ws.getMeasuredHeight() - insetsBottom - grid.workspacePadding.bottom - grid.workspaceSpringLoadedBottomSpace;
    float totalShrunkSpace = shrunkBottom - shrunkTop;
    float desiredCellTop = shrunkTop + (totalShrunkSpace - scaledHeight) / 2;
    float halfHeight = ws.getHeight() / 2;
    float myCenter = ws.getTop() + halfHeight;
    float cellTopFromCenter = halfHeight - ws.getChildAt(0).getTop();
    float actualCellTop = myCenter - cellTopFromCenter * scale;
    return new ScaleAndTranslation(scale, 0, (desiredCellTop - actualCellTop) / scale);
}
Also used : DeviceProfile(com.android.launcher3.DeviceProfile) Rect(android.graphics.Rect) Workspace(com.android.launcher3.Workspace)

Example 32 with Workspace

use of com.android.launcher3.Workspace in project android_packages_apps_Launcher3 by crdroidandroid.

the class ArrowPopup method setupColorExtraction.

@TargetApi(Build.VERSION_CODES.S)
private void setupColorExtraction() {
    Workspace workspace = mLauncher.findViewById(R.id.workspace);
    if (workspace == null) {
        return;
    }
    mColorExtractor = LocalColorExtractor.newInstance(mLauncher);
    mColorExtractor.setListener((rect, extractedColors) -> {
        String rectString = rect.toShortString();
        View v = mViewForRect.get(rectString);
        AnimatorSet colors = new AnimatorSet();
        if (v != null) {
            int newColor = getExtractedColor(extractedColors);
            setChildColor(v, newColor, colors);
            int numChildren = v instanceof ViewGroup ? ((ViewGroup) v).getChildCount() : 0;
            for (int i = 0; i < numChildren; ++i) {
                View childView = ((ViewGroup) v).getChildAt(i);
                setChildColor(childView, newColor, colors);
            }
            if (rectString.equals(mArrowColorRectString)) {
                mArrowColor = newColor;
                updateArrowColor();
            }
        }
        colors.setDuration(150);
        v.post(colors::start);
    });
}
Also used : ViewGroup(android.view.ViewGroup) AnimatorSet(android.animation.AnimatorSet) View(android.view.View) DeepShortcutView(com.android.launcher3.shortcuts.DeepShortcutView) AbstractFloatingView(com.android.launcher3.AbstractFloatingView) Workspace(com.android.launcher3.Workspace) TargetApi(android.annotation.TargetApi)

Example 33 with Workspace

use of com.android.launcher3.Workspace in project android_packages_apps_Launcher3 by crdroidandroid.

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(dragObject.dragView.getContext());
        Workspace workspace = launcher.getWorkspace();
        int screenId = workspace.getIdForScreen(this);
        int pageId = workspace.getPageIndexForScreenId(screenId);
        cellToRect(targetCell[0], targetCell[1], spanX, spanY, mTempRect);
        // Now get the rect in drag layer coordinates.
        getBoundsForViewInDragLayer(launcher.getDragLayer(), this, mTempRect, true, mTmpFloatArray, mTempRectF);
        Utilities.setRect(mTempRectF, mTempRect);
        ((LauncherAppWidgetHostView) view).handleDrag(mTempRect, pageId);
    }
}
Also used : LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) View(android.view.View) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point)

Example 34 with Workspace

use of com.android.launcher3.Workspace in project android_packages_apps_Launcher3 by crdroidandroid.

the class AddWorkspaceItemsTaskTest method testAddItem_some_items_added.

@Test
public void testAddItem_some_items_added() throws Exception {
    Callbacks callbacks = mock(Callbacks.class);
    mModelHelper.getModel().addCallbacks(callbacks);
    WorkspaceItemInfo info = new WorkspaceItemInfo();
    info.intent = new Intent().setComponent(mComponent1);
    WorkspaceItemInfo info2 = new WorkspaceItemInfo();
    info2.intent = new Intent().setComponent(mComponent2);
    // Setup a screen with a hole
    setupWorkspaceWithHoles(1, 1, new Rect(2, 2, 3, 3));
    mModelHelper.executeTaskForTest(newTask(info, info2)).get(0).run();
    ArgumentCaptor<ArrayList> notAnimated = ArgumentCaptor.forClass(ArrayList.class);
    ArgumentCaptor<ArrayList> animated = ArgumentCaptor.forClass(ArrayList.class);
    // only info2 should be added because info was already added to the workspace
    // in setupWorkspaceWithHoles()
    verify(callbacks).bindAppsAdded(any(IntArray.class), notAnimated.capture(), animated.capture());
    assertTrue(notAnimated.getValue().isEmpty());
    assertEquals(1, animated.getValue().size());
    assertTrue(animated.getValue().contains(info2));
}
Also used : Rect(android.graphics.Rect) Callbacks(com.android.launcher3.model.BgDataModel.Callbacks) IntArray(com.android.launcher3.util.IntArray) ArrayList(java.util.ArrayList) Intent(android.content.Intent) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) Test(org.junit.Test)

Example 35 with Workspace

use of com.android.launcher3.Workspace in project android_packages_apps_Launcher3 by crdroidandroid.

the class Launcher method dump.

/**
 * $ adb shell dumpsys activity com.android.launcher3.Launcher [--all]
 */
@Override
public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
    super.dump(prefix, fd, writer, args);
    if (args.length > 0 && TextUtils.equals(args[0], "--all")) {
        writer.println(prefix + "Workspace Items");
        for (int i = 0; i < mWorkspace.getPageCount(); i++) {
            writer.println(prefix + "  Homescreen " + i);
            ViewGroup layout = ((CellLayout) mWorkspace.getPageAt(i)).getShortcutsAndWidgets();
            for (int j = 0; j < layout.getChildCount(); j++) {
                Object tag = layout.getChildAt(j).getTag();
                if (tag != null) {
                    writer.println(prefix + "    " + tag.toString());
                }
            }
        }
        writer.println(prefix + "  Hotseat");
        ViewGroup layout = mHotseat.getShortcutsAndWidgets();
        for (int j = 0; j < layout.getChildCount(); j++) {
            Object tag = layout.getChildAt(j).getTag();
            if (tag != null) {
                writer.println(prefix + "    " + tag.toString());
            }
        }
    }
    writer.println(prefix + "Misc:");
    dumpMisc(prefix + "\t", writer);
    writer.println(prefix + "\tmWorkspaceLoading=" + mWorkspaceLoading);
    writer.println(prefix + "\tmPendingRequestArgs=" + mPendingRequestArgs + " mPendingActivityResult=" + mPendingActivityResult);
    writer.println(prefix + "\tmRotationHelper: " + mRotationHelper);
    writer.println(prefix + "\tmAppWidgetHost.isListening: " + mAppWidgetHost.isListening());
    // Extra logging for general debugging
    mDragLayer.dump(prefix, writer);
    mStateManager.dump(prefix, writer);
    mPopupDataProvider.dump(prefix, writer);
    mDeviceProfile.dump(prefix, writer);
    try {
        FileLog.flushAll(writer);
    } catch (Exception e) {
    // Ignore
    }
    mModel.dumpState(prefix, fd, writer, args);
    if (mLauncherCallbacks != null) {
        mLauncherCallbacks.dump(prefix, fd, writer, args);
    }
    mOverlayManager.dump(prefix, writer);
}
Also used : ViewGroup(android.view.ViewGroup) DragObject(com.android.launcher3.DropTarget.DragObject) ActivityNotFoundException(android.content.ActivityNotFoundException)

Aggregations

View (android.view.View)143 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)124 Point (android.graphics.Point)115 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)97 Rect (android.graphics.Rect)93 ArrayList (java.util.ArrayList)91 ItemInfo (com.android.launcher3.model.data.ItemInfo)86 DragView (com.android.launcher3.dragndrop.DragView)77 PendingAppWidgetHostView (com.android.launcher3.widget.PendingAppWidgetHostView)73 AppWidgetHostView (android.appwidget.AppWidgetHostView)72 Workspace (com.android.launcher3.Workspace)63 SuppressLint (android.annotation.SuppressLint)58 DraggableView (com.android.launcher3.dragndrop.DraggableView)58 Test (org.junit.Test)57 FolderInfo (com.android.launcher3.model.data.FolderInfo)55 CellLayout (com.android.launcher3.CellLayout)51 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)47 IntArray (com.android.launcher3.util.IntArray)45 Intent (android.content.Intent)43 ValueAnimator (android.animation.ValueAnimator)41