Search in sources :

Example 36 with CellLayout

use of com.android.launcher3.CellLayout in project android_packages_apps_Launcher3 by AOSPA.

the class LauncherAccessibilityDelegate method findSpaceOnWorkspace.

/**
 * Find empty space on the workspace and returns the screenId.
 */
protected int findSpaceOnWorkspace(ItemInfo info, int[] outCoordinates) {
    Workspace workspace = mLauncher.getWorkspace();
    IntArray workspaceScreens = workspace.getScreenOrder();
    int screenId;
    // First check if there is space on the current screen.
    int screenIndex = workspace.getCurrentPage();
    screenId = workspaceScreens.get(screenIndex);
    CellLayout layout = (CellLayout) workspace.getPageAt(screenIndex);
    boolean found = layout.findCellForSpan(outCoordinates, info.spanX, info.spanY);
    screenIndex = 0;
    while (!found && screenIndex < workspaceScreens.size()) {
        screenId = workspaceScreens.get(screenIndex);
        layout = (CellLayout) workspace.getPageAt(screenIndex);
        found = layout.findCellForSpan(outCoordinates, info.spanX, info.spanY);
        screenIndex++;
    }
    if (found) {
        return screenId;
    }
    workspace.addExtraEmptyScreens();
    IntSet emptyScreenIds = workspace.commitExtraEmptyScreens();
    if (emptyScreenIds.isEmpty()) {
        // Couldn't create extra empty screens for some reason (e.g. Workspace is loading)
        return -1;
    }
    screenId = emptyScreenIds.getArray().get(0);
    layout = workspace.getScreenWithId(screenId);
    found = layout.findCellForSpan(outCoordinates, info.spanX, info.spanY);
    if (!found) {
        Log.wtf(TAG, "Not enough space on an empty screen");
    }
    return screenId;
}
Also used : IntArray(com.android.launcher3.util.IntArray) CellLayout(com.android.launcher3.CellLayout) IntSet(com.android.launcher3.util.IntSet) Point(android.graphics.Point) Workspace(com.android.launcher3.Workspace)

Example 37 with CellLayout

use of com.android.launcher3.CellLayout in project android_packages_apps_Launcher3 by AOSPA.

the class Launcher method ensurePendingDropLayoutExists.

/**
 * Check to see if a given screen id exists. If not, create it at the end, return the new id.
 *
 * @param screenId the screen id to check
 * @return the new screen, or screenId if it exists
 */
private int ensurePendingDropLayoutExists(int screenId) {
    CellLayout dropLayout = mWorkspace.getScreenWithId(screenId);
    if (dropLayout == null) {
        // it's possible that the add screen was removed because it was
        // empty and a re-bind occurred
        mWorkspace.addExtraEmptyScreens();
        IntSet emptyPagesAdded = mWorkspace.commitExtraEmptyScreens();
        return emptyPagesAdded.isEmpty() ? -1 : emptyPagesAdded.getArray().get(0);
    }
    return screenId;
}
Also used : IntSet(com.android.launcher3.util.IntSet)

Example 38 with CellLayout

use of com.android.launcher3.CellLayout in project android_packages_apps_Launcher3 by AOSPA.

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)

Example 39 with CellLayout

use of com.android.launcher3.CellLayout in project android_packages_apps_Launcher3 by AOSPA.

the class Launcher method handleActivityResult.

private void handleActivityResult(final int requestCode, final int resultCode, final Intent data) {
    if (isWorkspaceLoading()) {
        // process the result once the workspace has loaded.
        mPendingActivityResult = new ActivityResultInfo(requestCode, resultCode, data);
        return;
    }
    mPendingActivityResult = null;
    // Reset the startActivity waiting flag
    final PendingRequestArgs requestArgs = mPendingRequestArgs;
    setWaitingForResult(null);
    if (requestArgs == null) {
        return;
    }
    final int pendingAddWidgetId = requestArgs.getWidgetId();
    Runnable exitSpringLoaded = new Runnable() {

        @Override
        public void run() {
            mStateManager.goToState(NORMAL, SPRING_LOADED_EXIT_DELAY);
        }
    };
    if (requestCode == REQUEST_BIND_APPWIDGET) {
        // This is called only if the user did not previously have permissions to bind widgets
        final int appWidgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
        if (resultCode == RESULT_CANCELED) {
            completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId, requestArgs);
            mWorkspace.removeExtraEmptyScreenDelayed(ON_ACTIVITY_RESULT_ANIMATION_DELAY, false, exitSpringLoaded);
        } else if (resultCode == RESULT_OK) {
            addAppWidgetImpl(appWidgetId, requestArgs, null, requestArgs.getWidgetHandler(), ON_ACTIVITY_RESULT_ANIMATION_DELAY);
        }
        return;
    }
    boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET || requestCode == REQUEST_CREATE_APPWIDGET);
    // We have special handling for widgets
    if (isWidgetDrop) {
        final int appWidgetId;
        int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
        if (widgetId < 0) {
            appWidgetId = pendingAddWidgetId;
        } else {
            appWidgetId = widgetId;
        }
        final int result;
        if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
            Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " + "returned from the widget configuration activity.");
            result = RESULT_CANCELED;
            completeTwoStageWidgetDrop(result, appWidgetId, requestArgs);
            mWorkspace.removeExtraEmptyScreenDelayed(ON_ACTIVITY_RESULT_ANIMATION_DELAY, false, () -> getStateManager().goToState(NORMAL));
        } else {
            if (requestArgs.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
                // When the screen id represents an actual screen (as opposed to a rank)
                // we make sure that the drop page actually exists.
                requestArgs.screenId = ensurePendingDropLayoutExists(requestArgs.screenId);
            }
            final CellLayout dropLayout = mWorkspace.getScreenWithId(requestArgs.screenId);
            dropLayout.setDropPending(true);
            final Runnable onComplete = new Runnable() {

                @Override
                public void run() {
                    completeTwoStageWidgetDrop(resultCode, appWidgetId, requestArgs);
                    dropLayout.setDropPending(false);
                }
            };
            mWorkspace.removeExtraEmptyScreenDelayed(ON_ACTIVITY_RESULT_ANIMATION_DELAY, false, onComplete);
        }
        return;
    }
    if (requestCode == REQUEST_RECONFIGURE_APPWIDGET || requestCode == REQUEST_BIND_PENDING_APPWIDGET) {
        if (resultCode == RESULT_OK) {
            // Update the widget view.
            completeAdd(requestCode, data, pendingAddWidgetId, requestArgs);
        }
        // Leave the widget in the pending state if the user canceled the configure.
        return;
    }
    if (requestCode == REQUEST_CREATE_SHORTCUT) {
        // Handle custom shortcuts created using ACTION_CREATE_SHORTCUT.
        if (resultCode == RESULT_OK && requestArgs.container != ItemInfo.NO_ID) {
            completeAdd(requestCode, data, -1, requestArgs);
            mWorkspace.removeExtraEmptyScreenDelayed(ON_ACTIVITY_RESULT_ANIMATION_DELAY, false, exitSpringLoaded);
        } else if (resultCode == RESULT_CANCELED) {
            mWorkspace.removeExtraEmptyScreenDelayed(ON_ACTIVITY_RESULT_ANIMATION_DELAY, false, exitSpringLoaded);
        }
    }
    mDragLayer.clearAnimatedView();
}
Also used : ActivityResultInfo(com.android.launcher3.util.ActivityResultInfo) PendingRequestArgs(com.android.launcher3.util.PendingRequestArgs)

Example 40 with CellLayout

use of com.android.launcher3.CellLayout in project android_packages_apps_Launcher3 by AOSPA.

the class Launcher method onRequestPermissionsResult.

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    PendingRequestArgs pendingArgs = mPendingRequestArgs;
    if (requestCode == REQUEST_PERMISSION_CALL_PHONE && pendingArgs != null && pendingArgs.getRequestCode() == REQUEST_PERMISSION_CALL_PHONE) {
        setWaitingForResult(null);
        View v = null;
        CellLayout layout = getCellLayout(pendingArgs.container, pendingArgs.screenId);
        if (layout != null) {
            v = layout.getChildAt(pendingArgs.cellX, pendingArgs.cellY);
        }
        Intent intent = pendingArgs.getPendingIntent();
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            startActivitySafely(v, intent, null);
        } else {
            // TODO: Show a snack bar with link to settings
            Toast.makeText(this, getString(R.string.msg_no_phone_permission, getString(R.string.derived_app_name)), Toast.LENGTH_SHORT).show();
        }
    }
}
Also used : PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) QsbContainerView(com.android.launcher3.qsb.QsbContainerView) OptionsPopupView(com.android.launcher3.views.OptionsPopupView) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) DragView(com.android.launcher3.dragndrop.DragView) ImageView(android.widget.ImageView) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) FloatingSurfaceView(com.android.launcher3.views.FloatingSurfaceView) AppWidgetHostView(android.appwidget.AppWidgetHostView) View(android.view.View) AllAppsContainerView(com.android.launcher3.allapps.AllAppsContainerView) ScrimView(com.android.launcher3.views.ScrimView) PendingRequestArgs(com.android.launcher3.util.PendingRequestArgs)

Aggregations

CellLayout (com.android.launcher3.CellLayout)178 View (android.view.View)169 SuppressLint (android.annotation.SuppressLint)126 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)124 AppWidgetHostView (android.appwidget.AppWidgetHostView)105 Point (android.graphics.Point)95 DragView (com.android.launcher3.dragndrop.DragView)91 PendingAppWidgetHostView (com.android.launcher3.widget.PendingAppWidgetHostView)87 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)86 ItemInfo (com.android.launcher3.model.data.ItemInfo)73 BubbleTextView (com.android.launcher3.BubbleTextView)62 Rect (android.graphics.Rect)60 FolderIcon (com.android.launcher3.folder.FolderIcon)52 DragLayer (com.android.launcher3.dragndrop.DragLayer)50 ArrayList (java.util.ArrayList)48 FolderInfo (com.android.launcher3.model.data.FolderInfo)45 Workspace (com.android.launcher3.Workspace)43 DraggableView (com.android.launcher3.dragndrop.DraggableView)43 Animator (android.animation.Animator)42 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)40