Example usage for android.content.pm ShortcutInfo clone

List of usage examples for android.content.pm ShortcutInfo clone

Introduction

In this page you can find the example usage for android.content.pm ShortcutInfo clone.

Prototype

@HotSpotIntrinsicCandidate
protected native Object clone() throws CloneNotSupportedException;

Source Link

Document

Creates and returns a copy of this object.

Usage

From source file:com.aliyun.homeshell.Folder.java

public void dealNewSelectedApps(ArrayList<ShortcutInfo> selectedShortcuts) {
    List<ShortcutInfo> currentShortcuts = new ArrayList(mInfo.contents);
    if (mInfo.isEditFolderInContents()) {
        currentShortcuts.remove(mInfo.getmEditFolderShortcutInfo());
    }//ww  w  .  j  av a 2s  .c o  m
    List<ShortcutInfo> addedShortcuts = new ArrayList<ShortcutInfo>();
    List<ShortcutInfo> removedShortcuts = new ArrayList<ShortcutInfo>();
    for (ShortcutInfo select : selectedShortcuts) {
        if (!contains(currentShortcuts, select)) {
            addedShortcuts.add(select);
        }
    }
    for (ShortcutInfo current : currentShortcuts) {
        if (!contains(selectedShortcuts, current)) {
            removedShortcuts.add(current);
        }
    }
    Log.d(FolderAppsSelectView.LOG_TAG, "The apps amount added to folder is:" + addedShortcuts.size()
            + ", detail is:" + addedShortcuts.toString());
    Log.d(FolderAppsSelectView.LOG_TAG, "The apps amount removed from folder is:" + removedShortcuts.size()
            + ", detail is:" + removedShortcuts.toString());
    //deal the new added icon
    Workspace workspace = mLauncher.getWorkspace();
    ArrayList<ItemInfo> addItems = new ArrayList<ItemInfo>();
    for (ShortcutInfo shortcut : addedShortcuts) {
        ShortcutInfo clone = shortcut.clone();
        addItems.add(clone);
        // LauncherModel.getSbgworkspaceitems().remove(shortcut);
        mInfo.add(shortcut);
    }
    workspace.removeItemsViewByItemInfo(addItems);
    workspace.updateWorkspaceAfterDelItems(addItems);
    //if one screen has no icon after this function, then remove it
    workspace.checkAndRemoveEmptyCell();
    //deal the removed icons
    if (selectedShortcuts.size() == 0) {
        removedShortcuts.remove(0);
    }
    if (removedShortcuts.size() < 1) {
        return;
    }
    long container = LauncherSettings.Favorites.CONTAINER_DESKTOP;
    List<ScreenPosition> emptyCellList = LauncherModel.findEmptyCells(removedShortcuts.size());
    Log.d(FolderAppsSelectView.LOG_TAG, "The amount of empty Cells found is " + emptyCellList.size()
            + " ,detail is : " + emptyCellList.toString());
    if (emptyCellList == null || emptyCellList.size() == 0) {
        Log.d(FolderAppsSelectView.LOG_TAG, "Have not the empty cell to place the apps in folder");
        Toast.makeText(mLauncher, getContext().getText(R.string.over_max_screen_count), Toast.LENGTH_SHORT)
                .show();
        return;
    }
    for (int i = 0; i < emptyCellList.size(); i++) {
        ScreenPosition pos = emptyCellList.get(i);
        ShortcutInfo shortcut = removedShortcuts.get(i);
        mInfo.remove(shortcut);
        //the empty position is in the new screen
        if (pos.s >= workspace.getChildCount()) {
            //if addEmptyScreen fail,then return
            if (!workspace.addEmptyScreenSync()) {
                Toast.makeText(mLauncher, getContext().getText(R.string.over_max_screen_count),
                        Toast.LENGTH_SHORT).show();
                break;
            }
        }
        //add the icon to the workspace
        CellLayout cell = (CellLayout) workspace.getChildAt(pos.s);
        shortcut.cellX = pos.x;
        shortcut.cellY = pos.y;
        shortcut.container = container;
        shortcut.screen = pos.s;
        View view = mLauncher.createShortcut(R.layout.application, cell, shortcut);
        workspace.addInScreen(view, container, pos.s, pos.x, pos.y, shortcut.spanX, shortcut.spanY, false);
        cell.onDropChild(view);
        CellLayout.LayoutParams lp = (CellLayout.LayoutParams) view.getLayoutParams();
        cell.getShortcutsAndWidgets().measureChild(view);
        LauncherModel.addOrMoveItemInDatabase(mLauncher, shortcut, container, pos.s, lp.cellX, lp.cellY);
        Log.d(FolderAppsSelectView.LOG_TAG,
                "The app:" + shortcut.title + " has moved to workspace ,the pos is " + pos.toString());
    }
    if (emptyCellList.size() < removedShortcuts.size()) {
        Toast.makeText(mLauncher, getContext().getText(R.string.over_max_screen_count), Toast.LENGTH_SHORT)
                .show();
    }
    //if one screen has no icon after this function, then remove it
    workspace.checkAndRemoveEmptyCell();
}