Search in sources :

Example 21 with CellLayout

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

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 22 with CellLayout

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

the class Launcher method completeAddShortcut.

/**
 * Add a shortcut to the workspace or to a Folder.
 *
 * @param data The intent describing the shortcut.
 */
private void completeAddShortcut(Intent data, int container, int screenId, int cellX, int cellY, PendingRequestArgs args) {
    if (args.getRequestCode() != REQUEST_CREATE_SHORTCUT || args.getPendingIntent().getComponent() == null) {
        return;
    }
    int[] cellXY = mTmpAddItemCellCoordinates;
    CellLayout layout = getCellLayout(container, screenId);
    WorkspaceItemInfo info = PinRequestHelper.createWorkspaceItemFromPinItemRequest(this, PinRequestHelper.getPinItemRequest(data), 0);
    if (info == null) {
        // Legacy shortcuts are only supported for primary profile.
        info = Process.myUserHandle().equals(args.user) ? ModelUtils.fromLegacyShortcutIntent(this, data) : null;
        if (info == null) {
            Log.e(TAG, "Unable to parse a valid custom shortcut result");
            return;
        } else if (!new PackageManagerHelper(this).hasPermissionForActivity(info.intent, args.getPendingIntent().getComponent().getPackageName())) {
            // The app is trying to add a shortcut without sufficient permissions
            Log.e(TAG, "Ignoring malicious intent " + info.intent.toUri(0));
            return;
        }
    }
    if (container < 0) {
        // Adding a shortcut to the Workspace.
        final View view = createShortcut(info);
        boolean foundCellSpan = false;
        // First we check if we already know the exact location where we want to add this item.
        if (cellX >= 0 && cellY >= 0) {
            cellXY[0] = cellX;
            cellXY[1] = cellY;
            foundCellSpan = true;
            DragObject dragObject = new DragObject(getApplicationContext());
            dragObject.dragInfo = info;
            // If appropriate, either create a folder or add to an existing folder
            if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0, true, dragObject)) {
                return;
            }
            if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject, true)) {
                return;
            }
        } else {
            foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
        }
        if (!foundCellSpan) {
            mWorkspace.onNoCellFound(layout);
            return;
        }
        getModelWriter().addItemToDatabase(info, container, screenId, cellXY[0], cellXY[1]);
        mWorkspace.addInScreen(view, info);
    } else {
        // Adding a shortcut to a Folder.
        FolderIcon folderIcon = findFolderIcon(container);
        if (folderIcon != null) {
            FolderInfo folderInfo = (FolderInfo) folderIcon.getTag();
            folderInfo.add(info, args.rank, false);
        } else {
            Log.e(TAG, "Could not find folder with id " + container + " to add shortcut.");
        }
    }
}
Also used : FolderIcon(com.android.launcher3.folder.FolderIcon) DragObject(com.android.launcher3.DropTarget.DragObject) PackageManagerHelper(com.android.launcher3.util.PackageManagerHelper) 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) FolderInfo(com.android.launcher3.model.data.FolderInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 23 with CellLayout

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

the class Launcher method completeTwoStageWidgetDrop.

@Thunk
void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId, final PendingRequestArgs requestArgs) {
    CellLayout cellLayout = mWorkspace.getScreenWithId(requestArgs.screenId);
    Runnable onCompleteRunnable = null;
    int animationType = 0;
    AppWidgetHostView boundWidget = null;
    if (resultCode == RESULT_OK) {
        animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
        final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId, requestArgs.getWidgetHandler().getProviderInfo(this));
        boundWidget = layout;
        onCompleteRunnable = new Runnable() {

            @Override
            public void run() {
                completeAddAppWidget(appWidgetId, requestArgs, layout, null);
                mStateManager.goToState(NORMAL, SPRING_LOADED_EXIT_DELAY);
            }
        };
    } else if (resultCode == RESULT_CANCELED) {
        mAppWidgetHost.deleteAppWidgetId(appWidgetId);
        animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
    }
    if (mDragLayer.getAnimatedView() != null) {
        mWorkspace.animateWidgetDrop(requestArgs, cellLayout, (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable, animationType, boundWidget, true);
    } else if (onCompleteRunnable != null) {
        // The animated view may be null in the case of a rotation during widget configuration
        onCompleteRunnable.run();
    }
}
Also used : PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) AppWidgetHostView(android.appwidget.AppWidgetHostView) Thunk(com.android.launcher3.util.Thunk)

Example 24 with CellLayout

use of com.android.launcher3.CellLayout 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)

Example 25 with CellLayout

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

the class AppWidgetResizeFrame method showForWidget.

public static void showForWidget(LauncherAppWidgetHostView widget, CellLayout cellLayout) {
    Launcher launcher = Launcher.getLauncher(cellLayout.getContext());
    AbstractFloatingView.closeAllOpenViews(launcher);
    DragLayer dl = launcher.getDragLayer();
    AppWidgetResizeFrame frame = (AppWidgetResizeFrame) launcher.getLayoutInflater().inflate(R.layout.app_widget_resize_frame, dl, false);
    if (widget.hasEnforcedCornerRadius()) {
        float enforcedCornerRadius = widget.getEnforcedCornerRadius();
        ImageView imageView = frame.findViewById(R.id.widget_resize_frame);
        Drawable d = imageView.getDrawable();
        if (d instanceof GradientDrawable) {
            GradientDrawable gd = (GradientDrawable) d.mutate();
            gd.setCornerRadius(enforcedCornerRadius);
        }
    }
    frame.setupForWidget(widget, cellLayout, dl);
    ((DragLayer.LayoutParams) frame.getLayoutParams()).customPosition = true;
    dl.addView(frame);
    frame.mIsOpen = true;
    frame.snapToWidget(false);
}
Also used : DragLayer(com.android.launcher3.dragndrop.DragLayer) Drawable(android.graphics.drawable.Drawable) GradientDrawable(android.graphics.drawable.GradientDrawable) ImageView(android.widget.ImageView) GradientDrawable(android.graphics.drawable.GradientDrawable)

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