Example usage for android.view View setOnLongClickListener

List of usage examples for android.view View setOnLongClickListener

Introduction

In this page you can find the example usage for android.view View setOnLongClickListener.

Prototype

public void setOnLongClickListener(@Nullable OnLongClickListener l) 

Source Link

Document

Register a callback to be invoked when this view is clicked and held.

Usage

From source file:com.zyk.launcher.AsyncTaskCallback.java

/**
 * Adds the specified child in the specified screen. The position and dimension of
 * the child are defined by x, y, spanX and spanY.
 *
 * @param child The child to add in one of the workspace's screens.
 * @param screenId The screen in which to add the child.
 * @param x The X position of the child in the screen's grid.
 * @param y The Y position of the child in the screen's grid.
 * @param spanX The number of cells spanned horizontally by the child.
 * @param spanY The number of cells spanned vertically by the child.
 * @param insert When true, the child is inserted at the beginning of the children list.
 * @param computeXYFromRank When true, we use the rank (stored in screenId) to compute
 *                          the x and y position in which to place hotseat items. Otherwise
 *                          we use the x and y position to compute the rank.
 *//* www . ja v a  2s.co m*/
void addInScreen(View child, long container, long screenId, int x, int y, int spanX, int spanY, boolean insert,
        boolean computeXYFromRank) {
    if (container == LauncherSettings.Allapps.CONTAINER_ALLAPPS) {
        if (getScreenWithId(screenId) == null) {
            Log.e(TAG, "Skipping child, screenId " + screenId + " not found");
            // DEBUGGING - Print out the stack trace to see where we are adding from
            new Throwable().printStackTrace();
            return;
        }
    }
    if (screenId == Workspace.EXTRA_EMPTY_SCREEN_ID) {
        // This should never happen
        throw new RuntimeException("Screen id should not be EXTRA_EMPTY_SCREEN_ID");
    }

    final CellLayout layout;
    if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
        layout = mLauncher.getHotseat().getLayout();
        child.setOnKeyListener(new HotseatIconKeyEventListener());

        // Hide folder title in the hotseat
        if (child instanceof FolderIcon) {
            ((FolderIcon) child).setTextVisible(false);
        }

        if (computeXYFromRank) {
            x = mLauncher.getHotseat().getCellXFromOrder((int) screenId);
            y = mLauncher.getHotseat().getCellYFromOrder((int) screenId);
        } else {
            screenId = mLauncher.getHotseat().getOrderInHotseat(x, y);
        }
    } else {
        // Show folder title if not in the hotseat
        if (child instanceof FolderIcon) {
            ((FolderIcon) child).setTextVisible(true);
        }
        layout = getScreenWithId(screenId);
        child.setOnKeyListener(new IconKeyEventListener());
    }

    ViewGroup.LayoutParams genericLp = child.getLayoutParams();
    CellLayout.LayoutParams lp;
    if (genericLp == null || !(genericLp instanceof CellLayout.LayoutParams)) {
        lp = new CellLayout.LayoutParams(x, y, spanX, spanY);
    } else {
        lp = (CellLayout.LayoutParams) genericLp;
        lp.cellX = x;
        lp.cellY = y;
        lp.cellHSpan = spanX;
        lp.cellVSpan = spanY;
    }

    if (spanX < 0 && spanY < 0) {
        lp.isLockedToGrid = false;
    }

    // Get the canonical child id to uniquely represent this view in this screen
    ItemInfo info = (ItemInfo) child.getTag();
    int childId = mLauncher.getAllAppsViewIdForItem(info);

    boolean markCellsAsOccupied = !(child instanceof Folder);
    if (!layout.addViewToCellLayout(child, insert ? 0 : -1, childId, lp, markCellsAsOccupied)) {
        // TODO: This branch occurs when the workspace is adding views
        // outside of the defined grid
        // maybe we should be deleting these items from the LauncherModel?
        System.out.println("Failed to add to item at (" + lp.cellX + "," + lp.cellY + ") to CellLayout");
        Launcher.addDumpLog(TAG, "Failed to add to item at (" + lp.cellX + "," + lp.cellY + ") to CellLayout",
                true);
    }

    if (!(child instanceof Folder)) {
        child.setHapticFeedbackEnabled(false);
        child.setOnLongClickListener(mLongClickListener);
    }
    if (child instanceof DropTarget) {
        mDragController.addDropTarget((DropTarget) child);
    }
}

From source file:com.android.launcher2.Workspace.java

/**
 * Adds the specified child in the specified screen. The position and dimension of
 * the child are defined by x, y, spanX and spanY.
 *
 * @param child The child to add in one of the workspace's screens.
 * @param screen The screen in which to add the child.
 * @param x The X position of the child in the screen's grid.
 * @param y The Y position of the child in the screen's grid.
 * @param spanX The number of cells spanned horizontally by the child.
 * @param spanY The number of cells spanned vertically by the child.
 * @param insert When true, the child is inserted at the beginning of the children list.
 *///from   w  ww  .  ja  v  a2s  . com
void addInScreen(View child, long container, int screen, int x, int y, int spanX, int spanY, boolean insert) {
    if (container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
        if (screen < 0 || screen >= getChildCount()) {
            Log.e(TAG, "The screen must be >= 0 and < " + getChildCount() + " (was " + screen
                    + "); skipping child");
            return;
        }
    }

    final CellLayout layout;
    if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
        layout = mLauncher.getHotseat().getLayout();
        child.setOnKeyListener(null);

        // Hide folder title in the hotseat
        if (child instanceof FolderIcon) {
            ((FolderIcon) child).setTextVisible(false);
        }

        if (screen < 0) {
            screen = mLauncher.getHotseat().getOrderInHotseat(x, y);
        } else {
            // Note: We do this to ensure that the hotseat is always laid out in the orientation
            // of the hotseat in order regardless of which orientation they were added
            x = mLauncher.getHotseat().getCellXFromOrder(screen);
            y = mLauncher.getHotseat().getCellYFromOrder(screen);
        }
    } else {
        // Show folder title if not in the hotseat
        if (child instanceof FolderIcon) {
            ((FolderIcon) child).setTextVisible(true);
        }

        layout = (CellLayout) getChildAt(screen);
        child.setOnKeyListener(new IconKeyEventListener());
    }

    LayoutParams genericLp = child.getLayoutParams();
    CellLayout.LayoutParams lp;
    if (genericLp == null || !(genericLp instanceof CellLayout.LayoutParams)) {
        lp = new CellLayout.LayoutParams(x, y, spanX, spanY);
    } else {
        lp = (CellLayout.LayoutParams) genericLp;
        lp.cellX = x;
        lp.cellY = y;
        lp.cellHSpan = spanX;
        lp.cellVSpan = spanY;
    }

    if (spanX < 0 && spanY < 0) {
        lp.isLockedToGrid = false;
    }

    // Get the canonical child id to uniquely represent this view in this screen
    int childId = LauncherModel.getCellLayoutChildId(container, screen, x, y, spanX, spanY);
    boolean markCellsAsOccupied = !(child instanceof Folder);
    if (!layout.addViewToCellLayout(child, insert ? 0 : -1, childId, lp, markCellsAsOccupied)) {
        // TODO: This branch occurs when the workspace is adding views
        // outside of the defined grid
        // maybe we should be deleting these items from the LauncherModel?
        Log.w(TAG, "Failed to add to item at (" + lp.cellX + "," + lp.cellY + ") to CellLayout");
    }

    if (!(child instanceof Folder)) {
        child.setHapticFeedbackEnabled(false);
        child.setOnLongClickListener(mLongClickListener);
    }
    if (child instanceof DropTarget) {
        mDragController.addDropTarget((DropTarget) child);
    }
}

From source file:org.brandroid.openmanager.activities.OpenExplorer.java

public void setupBaseBarButtons(Menu menu, boolean flush) {
    if (flush)/* www .  jav  a  2 s.  com*/
        mLastMenuClass = "";
    TableLayout mBaseBar = (TableLayout) findViewById(R.id.base_bar);
    mToolbarButtons = (ViewGroup) findViewById(R.id.base_row);
    mStaticButtons = (ViewGroup) findViewById(R.id.title_static_buttons);
    OpenFragment f = getSelectedFragment();
    boolean topButtons = false;
    if (!getResources().getBoolean(R.bool.allow_split_actionbar)
            || !(getSetting(null, "pref_basebar", true) || mBaseBar == null || mToolbarButtons == null)
                    && findViewById(R.id.title_buttons) != null) {
        mToolbarButtons = (ViewGroup) findViewById(R.id.title_buttons);
        if (mToolbarButtons == null && !BEFORE_HONEYCOMB)
            mToolbarButtons = (ViewGroup) getActionBar().getCustomView().findViewById(R.id.title_buttons);
        if (mBaseBar != null)
            mBaseBar.setVisibility(View.GONE);
        topButtons = true;
    }
    if (!shouldFlushMenu(menu))
        return;
    USE_SPLIT_ACTION_BAR = !topButtons;
    if (mToolbarButtons != null) {
        mToolbarButtons.removeAllViews();
        //if(!topButtons) mToolbarButtons.measure(LayoutParams.MATCH_PARENT, getResources().getDimensionPixelSize(R.dimen.actionbar_compat_height));

        int i = -1;
        int btnWidth = getResources().getDimensionPixelSize(R.dimen.actionbar_compat_button_width)
                + (getResources().getDimensionPixelSize(R.dimen.vpi_padding_horizontal) * 2); // (int)(16 * getResources().getDimension(R.dimen.one_dp));
        int tblWidth = mToolbarButtons.getWidth();
        if (tblWidth <= 0 && !topButtons)
            tblWidth = getWindowWidth();
        if (topButtons || tblWidth <= 0 || tblWidth > getWindowWidth()
                || !getResources().getBoolean(R.bool.ignore_max_base_buttons))
            tblWidth = btnWidth * getResources().getInteger(R.integer.max_base_buttons);
        ArrayList<View> buttons = new ArrayList<View>();
        buttons.addAll(ViewUtils.findChildByClass(mToolbarButtons, ImageButton.class));
        boolean maxedOut = false;
        while (++i < menu.size()) {
            if (buttons.size() * btnWidth >= tblWidth) {
                maxedOut = true;
                Logger.LogDebug("Base bar full after #" + i + " ~ " + buttons.size() + " ("
                        + (buttons.size() * btnWidth) + ">" + tblWidth + ")!");
                break;
            } else if (menu.getItem(i) instanceof MenuItemImpl) {
                final MenuItemImpl item = (MenuItemImpl) menu.getItem(i);
                //if(item.getItemId() == R.id.title_menu) break;
                if (!item.isCheckable() && item.isVisible()) {
                    View btn = makeMenuButton(item, mToolbarButtons);
                    if (item.hasSubMenu())
                        btn.setTag(item.getSubMenu());
                    else if (!BEFORE_HONEYCOMB && item.getActionView() != null) {
                        if (DEBUG)
                            Logger.LogDebug("ACTION VIEW!!!");
                        btn = item.getActionView();
                        //ActionBarHelper h = ActionBarHelper.createInstance(this);
                    }
                    buttons.add(btn);
                    if (i > 0)
                        btn.setNextFocusLeftId(menu.getItem(i - 1).getItemId());
                    if (i < menu.size() - 1)
                        btn.setNextFocusRightId(menu.getItem(i + 1).getItemId());
                    if (!USE_PRETTY_MENUS || topButtons)
                        btn.setOnCreateContextMenuListener(this);
                    menu.getItem(i).setVisible(false);
                    btn.setOnClickListener(this);
                    btn.setOnFocusChangeListener(this);
                    btn.setOnKeyListener(this);
                    if (mToolbarButtons.findViewById(menu.getItem(i).getItemId()) == null)
                        mToolbarButtons.addView(btn);
                    //menu.removeItem(item.getItemId());
                    if (DEBUG)
                        Logger.LogDebug("Added " + item.getTitle() + " to base bar.");
                }
                //else Logger.LogWarning(item.getTitle() + " should not show. " + item.getShowAsAction() + " :: " + item.getFlags());
            }
        }
        mToolbarButtons.setVisibility(View.VISIBLE);
        mLastMenuClass = f.getClassName();
        if (MenuUtils.countVisibleMenus(mMainMenu) > 0) {
            if (maxedOut && buttons.size() > 0) {
                View old = buttons.remove(buttons.size() - 1);
                MenuUtils.setMenuVisible(mMainMenu, true, old.getId());
                mToolbarButtons.removeView(old);
            }
            final ImageButton btn = (ImageButton) getLayoutInflater().inflate(R.layout.toolbar_button,
                    mToolbarButtons);
            btn.setImageResource(R.drawable.ic_menu_more);
            //btn.measure(getResources().getDimensionPixelSize(R.dimen.actionbar_compat_button_home_width), getResources().getDimensionPixelSize(R.dimen.actionbar_compat_height));
            btn.setId(R.id.menu_more);
            if (buttons.size() > 0) {
                buttons.get(buttons.size() - 1).setNextFocusRightId(R.id.menu_more);
                btn.setNextFocusLeftId(buttons.get(buttons.size() - 1).getId());
            }
            btn.setOnKeyListener(this);
            btn.setOnClickListener(this);
            btn.setOnLongClickListener(this);
            btn.setFocusable(true);
            btn.setOnFocusChangeListener(this);
            buttons.add(btn);
            mToolbarButtons.addView(btn);
        }
        if (buttons.size() > 0) {
            View last = buttons.get(buttons.size() - 1);
            last.setNextFocusRightId(android.R.id.home);
            if (findViewById(android.R.id.home) != null)
                findViewById(android.R.id.home).setNextFocusLeftId(last.getId());
        }

        Logger.LogDebug("Added " + buttons.size() + " children to Base Bar.");
        if (mBaseBar != null) {
            if (buttons.size() < 1)
                mBaseBar.setVisibility(View.GONE);
            else
                mBaseBar.setStretchAllColumns(true);
        }
    } else if (BEFORE_HONEYCOMB)
        Logger.LogWarning("No Base Row!?");
}

From source file:com.fairphone.fplauncher3.Workspace.java

/**
 * Adds the specified child in the specified screen. The position and dimension of
 * the child are defined by x, y, spanX and spanY.
 *
 * @param child The child to add in one of the workspace's screens.
 * @param screenId The screen in which to add the child.
 * @param x The X position of the child in the screen's grid.
 * @param y The Y position of the child in the screen's grid.
 * @param spanX The number of cells spanned horizontally by the child.
 * @param spanY The number of cells spanned vertically by the child.
 * @param insert When true, the child is inserted at the beginning of the children list.
 * @param computeXYFromRank When true, we use the rank (stored in screenId) to compute
 *                          the x and y position in which to place hotseat items. Otherwise
 *                          we use the x and y position to compute the rank.
 *//*from   w ww .  j av  a  2 s .c  om*/
void addInScreen(View child, long container, long screenId, int x, int y, int spanX, int spanY, boolean insert,
        boolean computeXYFromRank) {
    if (container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
        if (getScreenWithId(screenId) == null) {
            Log.e(TAG, "Skipping child, screenId " + screenId + " not found");
            // DEBUGGING - Print out the stack trace to see where we are adding from
            new Throwable().printStackTrace();
            return;
        }
    }
    if (screenId == EXTRA_EMPTY_SCREEN_ID) {
        // This should never happen
        throw new RuntimeException("Screen id should not be EXTRA_EMPTY_SCREEN_ID");
    }

    final CellLayout layout;
    // Show folder title
    if (child instanceof FolderIcon) {
        ((FolderIcon) child).setTextVisible(true);
    }
    layout = getScreenWithId(screenId);
    child.setOnKeyListener(new IconKeyEventListener());

    ViewGroup.LayoutParams genericLp = child.getLayoutParams();
    CellLayout.LayoutParams lp;
    if (genericLp == null || !(genericLp instanceof CellLayout.LayoutParams)) {
        lp = new CellLayout.LayoutParams(x, y, spanX, spanY);
    } else {
        lp = (CellLayout.LayoutParams) genericLp;
        lp.cellX = x;
        lp.cellY = y;
        lp.cellHSpan = spanX;
        lp.cellVSpan = spanY;
    }

    if (spanX < 0 && spanY < 0) {
        lp.isLockedToGrid = false;
    }

    // Get the canonical child id to uniquely represent this view in this screen
    ItemInfo info = (ItemInfo) child.getTag();
    int childId = mLauncher.getViewIdForItem(info);

    boolean markCellsAsOccupied = !(child instanceof Folder);
    if (!layout.addViewToCellLayout(child, insert ? 0 : -1, childId, lp, markCellsAsOccupied)) {
        // TODO: This branch occurs when the workspace is adding views
        // outside of the defined grid
        // maybe we should be deleting these items from the LauncherModel?
        Launcher.addDumpLog(TAG, "Failed to add to item at (" + lp.cellX + "," + lp.cellY + ") to CellLayout",
                true);
    }

    if (!(child instanceof Folder)) {
        child.setHapticFeedbackEnabled(false);
        child.setOnLongClickListener(mLongClickListener);
    }
    if (child instanceof DropTarget) {
        mDragController.addDropTarget((DropTarget) child);
    }
}

From source file:cc.flydev.launcher.Workspace.java

/**
 * Adds the specified child in the specified screen. The position and dimension of
 * the child are defined by x, y, spanX and spanY.
 *
 * @param child The child to add in one of the workspace's screens.
 * @param screenId The screen in which to add the child.
 * @param x The X position of the child in the screen's grid.
 * @param y The Y position of the child in the screen's grid.
 * @param spanX The number of cells spanned horizontally by the child.
 * @param spanY The number of cells spanned vertically by the child.
 * @param insert When true, the child is inserted at the beginning of the children list.
 * @param computeXYFromRank When true, we use the rank (stored in screenId) to compute
 *                          the x and y position in which to place hotseat items. Otherwise
 *                          we use the x and y position to compute the rank.
 *//*w ww  .j  av  a 2  s  .c  o m*/
void addInScreen(View child, long container, long screenId, int x, int y, int spanX, int spanY, boolean insert,
        boolean computeXYFromRank) {
    if (container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
        if (getScreenWithId(screenId) == null) {
            Log.e(TAG, "Skipping child, screenId " + screenId + " not found");
            // DEBUGGING - Print out the stack trace to see where we are adding from
            new Throwable().printStackTrace();
            return;
        }
    }
    if (screenId == EXTRA_EMPTY_SCREEN_ID) {
        // This should never happen
        throw new RuntimeException("Screen id should not be EXTRA_EMPTY_SCREEN_ID");
    }

    final CellLayout layout;
    if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
        layout = mLauncher.getHotseat().getLayout();
        child.setOnKeyListener(null);

        // Hide folder title in the hotseat
        if (child instanceof FolderIcon) {
            ((FolderIcon) child).setTextVisible(false);
        }

        if (computeXYFromRank) {
            x = mLauncher.getHotseat().getCellXFromOrder((int) screenId);
            y = mLauncher.getHotseat().getCellYFromOrder((int) screenId);
        } else {
            screenId = mLauncher.getHotseat().getOrderInHotseat(x, y);
        }
    } else {
        // Show folder title if not in the hotseat
        if (child instanceof FolderIcon) {
            ((FolderIcon) child).setTextVisible(true);
        }
        layout = getScreenWithId(screenId);
        child.setOnKeyListener(new IconKeyEventListener());
    }

    ViewGroup.LayoutParams genericLp = child.getLayoutParams();
    CellLayout.LayoutParams lp;
    if (genericLp == null || !(genericLp instanceof CellLayout.LayoutParams)) {
        lp = new CellLayout.LayoutParams(x, y, spanX, spanY);
    } else {
        lp = (CellLayout.LayoutParams) genericLp;
        lp.cellX = x;
        lp.cellY = y;
        lp.cellHSpan = spanX;
        lp.cellVSpan = spanY;
    }

    if (spanX < 0 && spanY < 0) {
        lp.isLockedToGrid = false;
    }

    // Get the canonical child id to uniquely represent this view in this screen
    int childId = LauncherModel.getCellLayoutChildId(container, screenId, x, y, spanX, spanY);
    boolean markCellsAsOccupied = !(child instanceof Folder);
    if (!layout.addViewToCellLayout(child, insert ? 0 : -1, childId, lp, markCellsAsOccupied)) {
        // TODO: This branch occurs when the workspace is adding views
        // outside of the defined grid
        // maybe we should be deleting these items from the LauncherModel?
        Launcher.addDumpLog(TAG, "Failed to add to item at (" + lp.cellX + "," + lp.cellY + ") to CellLayout",
                true);
    }

    if (!(child instanceof Folder)) {
        child.setHapticFeedbackEnabled(false);
        child.setOnLongClickListener(mLongClickListener);
    }
    if (child instanceof DropTarget) {
        mDragController.addDropTarget((DropTarget) child);
    }
}

From source file:com.example.launcher3.Workspace.java

/**
 * Adds the specified child in the specified screen. The position and
 * dimension of the child are defined by x, y, spanX and spanY.
 *
 * @param child/*from   w  w w .j  a  v  a 2  s .  co  m*/
 *            The child to add in one of the workspace's screens.
 * @param screenId
 *            The screen in which to add the child.
 * @param x
 *            The X position of the child in the screen's grid.
 * @param y
 *            The Y position of the child in the screen's grid.
 * @param spanX
 *            The number of cells spanned horizontally by the child.
 * @param spanY
 *            The number of cells spanned vertically by the child.
 * @param insert
 *            When true, the child is inserted at the beginning of the
 *            children list.
 * @param computeXYFromRank
 *            When true, we use the rank (stored in screenId) to compute the
 *            x and y position in which to place hotseat items. Otherwise we
 *            use the x and y position to compute the rank.
 */
void addInScreen(View child, long container, long screenId, int x, int y, int spanX, int spanY, boolean insert,
        boolean computeXYFromRank) {
    if (container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
        if (getScreenWithId(screenId) == null) {
            Log.e(TAG, "Skipping child, screenId " + screenId + " not found");
            // DEBUGGING - Print out the stack trace to see where we are
            // adding from
            new Throwable().printStackTrace();
            return;
        }
    }
    if (screenId == EXTRA_EMPTY_SCREEN_ID) {
        // This should never happen
        throw new RuntimeException("Screen id should not be EXTRA_EMPTY_SCREEN_ID");
    }

    final CellLayout layout;
    if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
        layout = mLauncher.getHotseat().getLayout();
        child.setOnKeyListener(null);

        // Hide folder title in the hotseat
        if (child instanceof FolderIcon) {
            ((FolderIcon) child).setTextVisible(false);
        }

        if (computeXYFromRank) {
            x = mLauncher.getHotseat().getCellXFromOrder((int) screenId);
            y = mLauncher.getHotseat().getCellYFromOrder((int) screenId);
        } else {
            screenId = mLauncher.getHotseat().getOrderInHotseat(x, y);
        }
    } else {
        // Show folder title if not in the hotseat
        if (child instanceof FolderIcon) {
            ((FolderIcon) child).setTextVisible(true);
        }
        layout = getScreenWithId(screenId);
        child.setOnKeyListener(new IconKeyEventListener());
    }

    ViewGroup.LayoutParams genericLp = child.getLayoutParams();
    CellLayout.LayoutParams lp;
    if (genericLp == null || !(genericLp instanceof CellLayout.LayoutParams)) {
        lp = new CellLayout.LayoutParams(x, y, spanX, spanY);
    } else {
        lp = (CellLayout.LayoutParams) genericLp;
        lp.cellX = x;
        lp.cellY = y;
        lp.cellHSpan = spanX;
        lp.cellVSpan = spanY;
    }

    if (spanX < 0 && spanY < 0) {
        lp.isLockedToGrid = false;
    }

    // Get the canonical child id to uniquely represent this view in this
    // screen
    int childId = LauncherModel.getCellLayoutChildId(container, screenId, x, y, spanX, spanY);
    boolean markCellsAsOccupied = !(child instanceof Folder);
    if (!layout.addViewToCellLayout(child, insert ? 0 : -1, childId, lp, markCellsAsOccupied)) {
        // TODO: This branch occurs when the workspace is adding views
        // outside of the defined grid
        // maybe we should be deleting these items from the LauncherModel?
        Launcher.addDumpLog(TAG, "Failed to add to item at (" + lp.cellX + "," + lp.cellY + ") to CellLayout",
                true);
    }

    if (!(child instanceof Folder)) {
        child.setHapticFeedbackEnabled(false);
        child.setOnLongClickListener(mLongClickListener);
    }
    if (child instanceof DropTarget) {
        mDragController.addDropTarget((DropTarget) child);
    }
}

From source file:com.aidy.launcher3.ui.workspace.Workspace.java

/**
 * Adds the specified child in the specified screen. The position and
 * dimension of the child are defined by x, y, spanX and spanY.
 * //  w  w  w .  ja v  a 2s  . co  m
 * @param child
 *            The child to add in one of the workspace's screens.
 * @param screenId
 *            The screen in which to add the child.
 * @param x
 *            The X position of the child in the screen's grid.
 * @param y
 *            The Y position of the child in the screen's grid.
 * @param spanX
 *            The number of cells spanned horizontally by the child.
 * @param spanY
 *            The number of cells spanned vertically by the child.
 * @param insert
 *            When true, the child is inserted at the beginning of the
 *            children list.
 * @param computeXYFromRank
 *            When true, we use the rank (stored in screenId) to compute the
 *            x and y position in which to place hotseat items. Otherwise we
 *            use the x and y position to compute the rank.
 */
public void addInScreen(View child, long container, long screenId, int x, int y, int spanX, int spanY,
        boolean insert, boolean computeXYFromRank) {
    if (container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
        if (getScreenWithId(screenId) == null) {
            Log.e(TAG, "Skipping child, screenId " + screenId + " not found");
            // DEBUGGING - Print out the stack trace to see where we are
            // adding from
            new Throwable().printStackTrace();
            return;
        }
    }
    if (screenId == EXTRA_EMPTY_SCREEN_ID) {
        // This should never happen
        throw new RuntimeException("Screen id should not be EXTRA_EMPTY_SCREEN_ID");
    }

    final CellLayout layout;
    if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
        layout = mLauncher.getHotseat().getLayout();
        child.setOnKeyListener(null);

        // Hide folder title in the hotseat
        if (child instanceof FolderIcon) {
            ((FolderIcon) child).setTextVisible(false);
        }

        if (computeXYFromRank) {
            x = mLauncher.getHotseat().getCellXFromOrder((int) screenId);
            y = mLauncher.getHotseat().getCellYFromOrder((int) screenId);
        } else {
            screenId = mLauncher.getHotseat().getOrderInHotseat(x, y);
        }
    } else {
        // Show folder title if not in the hotseat
        if (child instanceof FolderIcon) {
            ((FolderIcon) child).setTextVisible(true);
        }
        layout = getScreenWithId(screenId);
        child.setOnKeyListener(new IconKeyEventListener());
    }

    ViewGroup.LayoutParams genericLp = child.getLayoutParams();
    CellLayout.LayoutParams lp;
    if (genericLp == null || !(genericLp instanceof CellLayout.LayoutParams)) {
        lp = new CellLayout.LayoutParams(x, y, spanX, spanY);
    } else {
        lp = (CellLayout.LayoutParams) genericLp;
        lp.cellX = x;
        lp.cellY = y;
        lp.cellHSpan = spanX;
        lp.cellVSpan = spanY;
    }

    if (spanX < 0 && spanY < 0) {
        lp.isLockedToGrid = false;
    }

    // Get the canonical child id to uniquely represent this view in this
    // screen
    int childId = LauncherModel.getCellLayoutChildId(container, screenId, x, y, spanX, spanY);
    boolean markCellsAsOccupied = !(child instanceof Folder);
    if (!layout.addViewToCellLayout(child, insert ? 0 : -1, childId, lp, markCellsAsOccupied)) {
        // TODO: This branch occurs when the workspace is adding views
        // outside of the defined grid
        // maybe we should be deleting these items from the LauncherModel?
        Launcher.addDumpLog(TAG, "Failed to add to item at (" + lp.cellX + "," + lp.cellY + ") to CellLayout",
                true);
    }

    if (!(child instanceof Folder)) {
        child.setHapticFeedbackEnabled(false);
        child.setOnLongClickListener(mLongClickListener);
    }
    if (child instanceof DropTarget) {
        mDragController.addDropTarget((DropTarget) child);
    }
}

From source file:com.auratech.launcher.Workspace.java

/**
 * Adds the specified child in the specified screen. The position and dimension of
 * the child are defined by x, y, spanX and spanY.
 *
 * @param child The child to add in one of the workspace's screens.
 * @param screenId The screen in which to add the child.
 * @param x The X position of the child in the screen's grid.
 * @param y The Y position of the child in the screen's grid.
 * @param spanX The number of cells spanned horizontally by the child.
 * @param spanY The number of cells spanned vertically by the child.
 * @param insert When true, the child is inserted at the beginning of the children list.
 * @param computeXYFromRank When true, we use the rank (stored in screenId) to compute
 *                          the x and y position in which to place hotseat items. Otherwise
 *                          we use the x and y position to compute the rank.
 *//* w  ww.ja v  a 2s .  co m*/
void addInScreen(View child, long container, long screenId, int x, int y, int spanX, int spanY, boolean insert,
        boolean computeXYFromRank) {
    if (container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
        if (getScreenWithId(screenId) == null) {
            Log.e(TAG, "Skipping child, screenId " + screenId + " not found");
            // DEBUGGING - Print out the stack trace to see where we are adding from
            new Throwable().printStackTrace();
            return;
        }
    }
    if (screenId == EXTRA_EMPTY_SCREEN_ID) {
        // This should never happen
        throw new RuntimeException("Screen id should not be EXTRA_EMPTY_SCREEN_ID");
    }

    final CellLayout layout;
    if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
        layout = mLauncher.getHotseat().getLayout();
        child.setOnKeyListener(null);

        // Hide folder title in the hotseat
        if (child instanceof FolderIcon) {
            ((FolderIcon) child).setTextVisible(false);
        }

        if (computeXYFromRank) {
            x = mLauncher.getHotseat().getCellXFromOrder((int) screenId);
            y = mLauncher.getHotseat().getCellYFromOrder((int) screenId);
        } else {
            screenId = mLauncher.getHotseat().getOrderInHotseat(x, y);
        }
    } else {
        // Show folder title if not in the hotseat
        if (child instanceof FolderIcon) {
            ((FolderIcon) child).setTextVisible(true);
        }
        layout = getScreenWithId(screenId);
        child.setOnKeyListener(new IconKeyEventListener());
    }

    ViewGroup.LayoutParams genericLp = child.getLayoutParams();
    CellLayout.LayoutParams lp;
    if (genericLp == null || !(genericLp instanceof CellLayout.LayoutParams)) {
        lp = new CellLayout.LayoutParams(x, y, spanX, spanY);
    } else {
        lp = (CellLayout.LayoutParams) genericLp;
        lp.cellX = x;
        lp.cellY = y;
        lp.cellHSpan = spanX;
        lp.cellVSpan = spanY;
    }

    if (spanX < 0 && spanY < 0) {
        lp.isLockedToGrid = false;
    }

    // Get the canonical child id to uniquely represent this view in this screen
    ItemInfo info = (ItemInfo) child.getTag();
    int childId = mLauncher.getViewIdForItem(info);

    boolean markCellsAsOccupied = !(child instanceof Folder);
    if (!layout.addViewToCellLayout(child, insert ? 0 : -1, childId, lp, markCellsAsOccupied)) {
        // TODO: This branch occurs when the workspace is adding views
        // outside of the defined grid
        // maybe we should be deleting these items from the LauncherModel?
        Launcher.addDumpLog(TAG, "Failed to add to item at (" + lp.cellX + "," + lp.cellY + ") to CellLayout",
                true);
    }

    if (!(child instanceof Folder)) {
        child.setHapticFeedbackEnabled(false);
        child.setOnLongClickListener(mLongClickListener);
    }
    if (child instanceof DropTarget) {
        mDragController.addDropTarget((DropTarget) child);
    }
}

From source file:com.phonemetra.turbo.launcher.Workspace.java

/**
 * Adds the specified child in the specified screen. The position and dimension of
 * the child are defined by x, y, spanX and spanY.
 *
 * @param child The child to add in one of the workspace's screens.
 * @param screenId The screen in which to add the child.
 * @param x The X position of the child in the screen's grid.
 * @param y The Y position of the child in the screen's grid.
 * @param spanX The number of cells spanned horizontally by the child.
 * @param spanY The number of cells spanned vertically by the child.
 * @param insert When true, the child is inserted at the beginning of the children list.
 * @param computeXYFromRank When true, we use the rank (stored in screenId) to compute
 *                          the x and y position in which to place hotseat items. Otherwise
 *                          we use the x and y position to compute the rank.
 */// www.java 2  s. c om
void addInScreen(View child, long container, long screenId, int x, int y, int spanX, int spanY, boolean insert,
        boolean computeXYFromRank) {
    //Reload settings
    reloadSettings();
    if (container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
        if (getScreenWithId(screenId) == null) {
            Log.e(TAG, "Skipping child, screenId " + screenId + " not found");
            // DEBUGGING - Print out the stack trace to see where we are adding from
            new Throwable().printStackTrace();
            return;
        }
    }
    if (screenId == EXTRA_EMPTY_SCREEN_ID) {
        // This should never happen
        throw new RuntimeException("Screen id should not be EXTRA_EMPTY_SCREEN_ID");
    }

    final CellLayout layout;
    if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
        layout = mLauncher.getHotseat().getLayout();
        child.setOnKeyListener(null);

        // Hide folder title in the hotseat
        if (child instanceof FolderIcon) {
            ((FolderIcon) child).setTextVisible(false);
        }

        if (computeXYFromRank) {
            x = mLauncher.getHotseat().getCellXFromOrder((int) screenId);
            y = mLauncher.getHotseat().getCellYFromOrder((int) screenId);
        } else {
            screenId = mLauncher.getHotseat().getOrderInHotseat(x, y);
        }
    } else {
        // Show folder title if not in the hotseat
        if (child instanceof FolderIcon) {
            ((FolderIcon) child).setTextVisible(!mHideIconLabels);
        } else if (child instanceof BubbleTextView) {
            ((BubbleTextView) child).setTextVisibility(!mHideIconLabels);
        }
        layout = getScreenWithId(screenId);
        child.setOnKeyListener(new IconKeyEventListener());
    }

    ViewGroup.LayoutParams genericLp = child.getLayoutParams();
    CellLayout.LayoutParams lp;
    if (genericLp == null || !(genericLp instanceof CellLayout.LayoutParams)) {
        lp = new CellLayout.LayoutParams(x, y, spanX, spanY);
    } else {
        lp = (CellLayout.LayoutParams) genericLp;
        lp.cellX = x;
        lp.cellY = y;
        lp.cellHSpan = spanX;
        lp.cellVSpan = spanY;
    }

    if (spanX < 0 && spanY < 0) {
        lp.isLockedToGrid = false;
    }

    // Get the canonical child id to uniquely represent this view in this screen
    ItemInfo info = (ItemInfo) child.getTag();
    int childId = mLauncher.getViewIdForItem(info);

    boolean markCellsAsOccupied = !(child instanceof Folder);
    if (!layout.addViewToCellLayout(child, insert ? 0 : -1, childId, lp, markCellsAsOccupied)) {

    }

    if (!(child instanceof Folder)) {
        if (container != LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
            child.setHapticFeedbackEnabled(false);
        }
        child.setOnLongClickListener(mLongClickListener);
    }
    if (child instanceof DropTarget) {
        mDragController.addDropTarget((DropTarget) child);
    }
}

From source file:com.android.launcher4.Workspace.java

/**
 * Adds the specified child in the specified screen. The position and dimension of
 * the child are defined by x, y, spanX and spanY.
 *
 * @param child The child to add in one of the workspace's screens.
 * @param screenId The screen in which to add the child.
 * @param x The X position of the child in the screen's grid.
 * @param y The Y position of the child in the screen's grid.
 * @param spanX The number of cells spanned horizontally by the child.
 * @param spanY The number of cells spanned vertically by the child.
 * @param insert When true, the child is inserted at the beginning of the children list.
 * @param computeXYFromRank When true, we use the rank (stored in screenId) to compute
 *                          the x and y position in which to place hotseat items. Otherwise
 *                          we use the x and y position to compute the rank.
 *//*from w  w w .  ja  v  a2s  .  co m*/
void addInScreen(View child, long container, long screenId, int x, int y, int spanX, int spanY, boolean insert,
        boolean computeXYFromRank) {
    if (container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
        if (getScreenWithId(screenId) == null) {
            Log.e(TAG, "Skipping child, screenId " + screenId + " not found");
            // DEBUGGING - Print out the stack trace to see where we are adding from
            new Throwable().printStackTrace();
            return;
        }
    }
    if (screenId == EXTRA_EMPTY_SCREEN_ID) {
        // This should never happen
        throw new RuntimeException("Screen id should not be EXTRA_EMPTY_SCREEN_ID");
    }

    final CellLayout layout;
    if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
        layout = mLauncher.getHotseat().getLayout();
        child.setOnKeyListener(new HotseatIconKeyEventListener());

        // Hide folder title in the hotseat
        if (child instanceof FolderIcon) {
            ((FolderIcon) child).setTextVisible(false);
        }

        if (computeXYFromRank) {
            x = mLauncher.getHotseat().getCellXFromOrder((int) screenId);
            y = mLauncher.getHotseat().getCellYFromOrder((int) screenId);
        } else {
            screenId = mLauncher.getHotseat().getOrderInHotseat(x, y);
        }
    } else {
        // Show folder title if not in the hotseat
        if (child instanceof FolderIcon) {
            ((FolderIcon) child).setTextVisible(true);
        }
        layout = getScreenWithId(screenId);
        child.setOnKeyListener(new IconKeyEventListener());
    }

    ViewGroup.LayoutParams genericLp = child.getLayoutParams();
    CellLayout.LayoutParams lp;
    if (genericLp == null || !(genericLp instanceof CellLayout.LayoutParams)) {
        lp = new CellLayout.LayoutParams(x, y, spanX, spanY);
    } else {
        lp = (CellLayout.LayoutParams) genericLp;
        lp.cellX = x;
        lp.cellY = y;
        lp.cellHSpan = spanX;
        lp.cellVSpan = spanY;
    }

    if (spanX < 0 && spanY < 0) {
        lp.isLockedToGrid = false;
    }

    // Get the canonical child id to uniquely represent this view in this screen
    ItemInfo info = (ItemInfo) child.getTag();
    int childId = mLauncher.getViewIdForItem(info);

    boolean markCellsAsOccupied = !(child instanceof Folder);
    if (!layout.addViewToCellLayout(child, insert ? 0 : -1, childId, lp, markCellsAsOccupied)) {
        // TODO: This branch occurs when the workspace is adding views
        // outside of the defined grid
        // maybe we should be deleting these items from the LauncherModel?
        Launcher.addDumpLog(TAG, "Failed to add to item at (" + lp.cellX + "," + lp.cellY + ") to CellLayout",
                true);
    }

    if (!(child instanceof Folder)) {
        child.setHapticFeedbackEnabled(false);
        child.setOnLongClickListener(mLongClickListener);
    }
    if (child instanceof DropTarget) {
        mDragController.addDropTarget((DropTarget) child);
    }
}