Java Code Examples for org.chromium.chrome.browser.tabmodel.TabModelUtils#getTabIndexById()

The following examples show how to use org.chromium.chrome.browser.tabmodel.TabModelUtils#getTabIndexById() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StripLayoutHelper.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Displays the tab menu below the anchor tab.
 * @param anchorTab The tab the menu will be anchored to
 */
private void showTabMenu(StripLayoutTab anchorTab) {
    // 1. Bring the anchor tab to the foreground.
    int tabIndex = TabModelUtils.getTabIndexById(mModel, anchorTab.getId());
    TabModelUtils.setIndex(mModel, tabIndex);

    // 2. Anchor the popupMenu to the view associated with the tab
    View tabView = TabModelUtils.getCurrentTab(mModel).getView();
    mTabMenu.setAnchorView(tabView);

    // 3. Set the vertical offset to align the tab menu with bottom of the tab strip
    int verticalOffset =
            -(tabView.getHeight()
                    - (int) mContext.getResources().getDimension(R.dimen.tab_strip_height))
            - ((MarginLayoutParams) tabView.getLayoutParams()).topMargin;
    mTabMenu.setVerticalOffset(verticalOffset);

    // 4. Set the horizontal offset to align the tab menu with the right side of the tab
    int horizontalOffset = Math.round((anchorTab.getDrawX() + anchorTab.getWidth())
                                   * mContext.getResources().getDisplayMetrics().density)
            - mTabMenu.getWidth()
            - ((MarginLayoutParams) tabView.getLayoutParams()).leftMargin;
    mTabMenu.setHorizontalOffset(horizontalOffset);

    mTabMenu.show();
}
 
Example 2
Source File: StripLayoutHelper.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Called on click. This is called before the onUpOrCancel event.
 * @param time      The current time of the app in ms.
 * @param x         The x coordinate of the position of the click.
 * @param y         The y coordinate of the position of the click.
 * @param fromMouse Whether the event originates from a mouse.
 * @param buttons   State of all buttons that were pressed when onDown was invoked.
 */
public void click(long time, float x, float y, boolean fromMouse, int buttons) {
    resetResizeTimeout(false);

    if (mNewTabButton.click(x, y) && mModel != null) {
        mTabCreator.launchNTP();
        return;
    }

    final StripLayoutTab clickedTab = getTabAtPosition(x);
    if (clickedTab == null || clickedTab.isDying()) return;
    if (clickedTab.checkCloseHitTest(x, y)
            || (fromMouse && (buttons & MotionEvent.BUTTON_TERTIARY) != 0)) {
        // 1. Start the close animation.
        startAnimation(buildTabClosedAnimation(clickedTab), true);

        // 2. Set the dying state of the tab.
        clickedTab.setIsDying(true);

        // 3. Fake a selection on the next tab now.
        Tab nextTab = mModel.getNextTabIfClosed(clickedTab.getId());
        if (nextTab != null) tabSelected(time, nextTab.getId(), clickedTab.getId());

        // 4. Find out if we're closing the last tab.  This determines if we resize immediately.
        boolean lastTab = mStripTabs.length == 0
                || mStripTabs[mStripTabs.length - 1].getId() == clickedTab.getId();

        // 5. Resize the tabs appropriately.
        resizeTabStrip(!lastTab);
    } else {
        int newIndex = TabModelUtils.getTabIndexById(mModel, clickedTab.getId());
        TabModelUtils.setIndex(mModel, newIndex);
    }
}
 
Example 3
Source File: SuggestionsNavigationDelegateImpl.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private boolean openRecentTabSnippet(SnippetArticle article) {
    TabModel tabModel = mTabModelSelector.getModel(false);
    int tabId = article.getRecentTabId();
    int tabIndex = TabModelUtils.getTabIndexById(tabModel, tabId);
    if (tabIndex == TabModel.INVALID_TAB_INDEX) return false;
    TabModelUtils.setIndex(tabModel, tabIndex);
    return true;
}
 
Example 4
Source File: CustomTabLayoutManager.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void didAddTab(Tab tab, TabLaunchType type) {
    if (type == TabLaunchType.FROM_RESTORE) {
        getActiveLayout().onTabRestored(time(), tab.getId());
    } else {
        int newIndex = TabModelUtils.getTabIndexById(getTabModelSelector().getModel(false),
                tab.getId());
        getActiveLayout().onTabCreated(time(), tab.getId(), newIndex,
                getTabModelSelector().getCurrentTabId(), false, false, 0f, 0f);
    }
}
 
Example 5
Source File: StripLayoutHelper.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Displays the tab menu below the anchor tab.
 * @param anchorTab The tab the menu will be anchored to
 */
private void showTabMenu(StripLayoutTab anchorTab) {
    // 1. Bring the anchor tab to the foreground.
    int tabIndex = TabModelUtils.getTabIndexById(mModel, anchorTab.getId());
    TabModelUtils.setIndex(mModel, tabIndex);

    // 2. Anchor the popupMenu to the view associated with the tab
    View tabView = TabModelUtils.getCurrentTab(mModel).getView();
    mTabMenu.setAnchorView(tabView);

    // 3. Set the vertical offset to align the tab menu with bottom of the tab strip
    int verticalOffset =
            -(tabView.getHeight()
                    - (int) mContext.getResources().getDimension(R.dimen.tab_strip_height))
            - ((MarginLayoutParams) tabView.getLayoutParams()).topMargin;
    mTabMenu.setVerticalOffset(verticalOffset);

    // 4. Set the horizontal offset to align the tab menu with the right side of the tab
    int horizontalOffset = Math.round((anchorTab.getDrawX() + anchorTab.getWidth())
                                   * mContext.getResources().getDisplayMetrics().density)
            - mTabMenu.getWidth()
            - ((MarginLayoutParams) tabView.getLayoutParams()).leftMargin;
    // Cap the horizontal offset so that the tab menu doesn't get drawn off screen.
    horizontalOffset = Math.max(horizontalOffset, 0);
    mTabMenu.setHorizontalOffset(horizontalOffset);

    mTabMenu.show();
}
 
Example 6
Source File: StripLayoutHelper.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void handleTabClick(StripLayoutTab tab) {
    if (tab == null || tab.isDying()) return;

    int newIndex = TabModelUtils.getTabIndexById(mModel, tab.getId());
    TabModelUtils.setIndex(mModel, newIndex);
}
 
Example 7
Source File: StripLayoutHelper.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Called on onDown event.
 * @param time      The time stamp in millisecond of the event.
 * @param x         The x position of the event.
 * @param y         The y position of the event.
 * @param fromMouse Whether the event originates from a mouse.
 * @param buttons   State of all buttons that are pressed.
 */
public void onDown(long time, float x, float y, boolean fromMouse, int buttons) {
    resetResizeTimeout(false);

    if (mNewTabButton.onDown(x, y)) {
        mRenderHost.requestRender();
        return;
    }

    final StripLayoutTab clickedTab = getTabAtPosition(x);
    final int index = clickedTab != null
            ? TabModelUtils.getTabIndexById(mModel, clickedTab.getId())
            : TabModel.INVALID_TAB_INDEX;
    // http://crbug.com/472186 : Needs to handle a case that index is invalid.
    // The case could happen when the current tab is touched while we're inflating the rest of
    // the tabs from disk.
    mInteractingTab = index != TabModel.INVALID_TAB_INDEX && index < mStripTabs.length
            ? mStripTabs[index]
            : null;
    boolean clickedClose = clickedTab != null
                           && clickedTab.checkCloseHitTest(x, y);
    if (clickedClose) {
        clickedTab.setClosePressed(true);
        mLastPressedCloseButton = clickedTab.getCloseButton();
        mRenderHost.requestRender();
    }

    if (!mScroller.isFinished()) {
        mScroller.forceFinished(true);
        mInteractingTab = null;
    }

    if (fromMouse && !clickedClose && clickedTab != null
            && clickedTab.getVisiblePercentage() >= 1.f
            && (buttons & MotionEvent.BUTTON_TERTIARY) == 0) {
        startReorderMode(time, x, x);
    }
}
 
Example 8
Source File: CustomTabLayoutManager.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public void didAddTab(Tab tab, TabLaunchType type) {
    if (type == TabLaunchType.FROM_RESTORE) {
        getActiveLayout().onTabRestored(time(), tab.getId());
    } else {
        int newIndex = TabModelUtils.getTabIndexById(getTabModelSelector().getModel(false),
                tab.getId());
        getActiveLayout().onTabCreated(time(), tab.getId(), newIndex,
                getTabModelSelector().getCurrentTabId(), false, false, 0f, 0f);
    }
}
 
Example 9
Source File: StripLayoutHelper.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Displays the tab menu below the anchor tab.
 * @param anchorTab The tab the menu will be anchored to
 */
private void showTabMenu(StripLayoutTab anchorTab) {
    // 1. Bring the anchor tab to the foreground.
    int tabIndex = TabModelUtils.getTabIndexById(mModel, anchorTab.getId());
    TabModelUtils.setIndex(mModel, tabIndex);

    // 2. Anchor the popupMenu to the view associated with the tab
    View tabView = TabModelUtils.getCurrentTab(mModel).getView();
    mTabMenu.setAnchorView(tabView);

    // 3. Set the vertical offset to align the tab menu with bottom of the tab strip
    int verticalOffset =
            -(tabView.getHeight()
                    - (int) mContext.getResources().getDimension(R.dimen.tab_strip_height))
            - ((MarginLayoutParams) tabView.getLayoutParams()).topMargin;
    mTabMenu.setVerticalOffset(verticalOffset);

    // 4. Set the horizontal offset to align the tab menu with the right side of the tab
    int horizontalOffset = Math.round((anchorTab.getDrawX() + anchorTab.getWidth())
                                   * mContext.getResources().getDisplayMetrics().density)
            - mTabMenu.getWidth()
            - ((MarginLayoutParams) tabView.getLayoutParams()).leftMargin;
    // Cap the horizontal offset so that the tab menu doesn't get drawn off screen.
    horizontalOffset = Math.max(horizontalOffset, 0);
    mTabMenu.setHorizontalOffset(horizontalOffset);

    mTabMenu.show();
}
 
Example 10
Source File: StripLayoutHelper.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Called on click. This is called before the onUpOrCancel event.
 * @param time      The current time of the app in ms.
 * @param x         The x coordinate of the position of the click.
 * @param y         The y coordinate of the position of the click.
 * @param fromMouse Whether the event originates from a mouse.
 * @param buttons   State of all buttons that were pressed when onDown was invoked.
 */
public void click(long time, float x, float y, boolean fromMouse, int buttons) {
    resetResizeTimeout(false);

    if (mNewTabButton.click(x, y) && mModel != null) {
        if (!mModel.isIncognito()) mModel.commitAllTabClosures();
        mTabCreator.launchNTP();
        return;
    }

    final StripLayoutTab clickedTab = getTabAtPosition(x);
    if (clickedTab == null || clickedTab.isDying()) return;
    if (clickedTab.checkCloseHitTest(x, y)
            || (fromMouse && (buttons & MotionEvent.BUTTON_TERTIARY) != 0)) {
        // 1. Start the close animation.
        startAnimation(buildTabClosedAnimation(clickedTab), true);

        // 2. Set the dying state of the tab.
        clickedTab.setIsDying(true);

        // 3. Fake a selection on the next tab now.
        Tab nextTab = mModel.getNextTabIfClosed(clickedTab.getId());
        if (nextTab != null) tabSelected(time, nextTab.getId(), clickedTab.getId());

        // 4. Find out if we're closing the last tab.  This determines if we resize immediately.
        boolean lastTab = mStripTabs.length == 0
                || mStripTabs[mStripTabs.length - 1].getId() == clickedTab.getId();

        // 5. Resize the tabs appropriately.
        resizeTabStrip(!lastTab);
    } else {
        int newIndex = TabModelUtils.getTabIndexById(mModel, clickedTab.getId());
        TabModelUtils.setIndex(mModel, newIndex);
    }
}
 
Example 11
Source File: StripLayoutHelper.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Called on onDown event.
 * @param time      The time stamp in millisecond of the event.
 * @param x         The x position of the event.
 * @param y         The y position of the event.
 * @param fromMouse Whether the event originates from a mouse.
 * @param buttons   State of all buttons that are pressed.
 */
public void onDown(long time, float x, float y, boolean fromMouse, int buttons) {
    resetResizeTimeout(false);

    if (mNewTabButton.onDown(x, y)) {
        mRenderHost.requestRender();
        return;
    }

    final StripLayoutTab clickedTab = getTabAtPosition(x);
    final int index = clickedTab != null
            ? TabModelUtils.getTabIndexById(mModel, clickedTab.getId())
            : TabModel.INVALID_TAB_INDEX;
    // http://crbug.com/472186 : Needs to handle a case that index is invalid.
    // The case could happen when the current tab is touched while we're inflating the rest of
    // the tabs from disk.
    mInteractingTab = index != TabModel.INVALID_TAB_INDEX && index < mStripTabs.length
            ? mStripTabs[index]
            : null;
    boolean clickedClose = clickedTab != null
                           && clickedTab.checkCloseHitTest(x, y);
    if (clickedClose) {
        clickedTab.setClosePressed(true);
        mLastPressedCloseButton = clickedTab.getCloseButton();
        mRenderHost.requestRender();
    }

    if (!mScroller.isFinished()) {
        mScroller.forceFinished(true);
        mInteractingTab = null;
    }

    if (fromMouse && !clickedClose && clickedTab != null
            && clickedTab.getVisiblePercentage() >= 1.f
            && (buttons & MotionEvent.BUTTON_TERTIARY) == 0) {
        startReorderMode(time, x, x);
    }
}
 
Example 12
Source File: CustomTabLayoutManager.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
public void didAddTab(Tab tab, TabLaunchType type) {
    int newIndex = TabModelUtils.getTabIndexById(getTabModelSelector().getModel(false),
            tab.getId());
    getActiveLayout().onTabCreated(time(), tab.getId(), newIndex,
            getTabModelSelector().getCurrentTabId(), false, false, 0f, 0f);
}
 
Example 13
Source File: StripLayoutHelper.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Called on onDown event.
 * @param time      The time stamp in millisecond of the event.
 * @param x         The x position of the event.
 * @param y         The y position of the event.
 * @param fromMouse Whether the event originates from a mouse.
 * @param buttons   State of all buttons that are pressed.
 */
public void onDown(long time, float x, float y, boolean fromMouse, int buttons) {
    resetResizeTimeout(false);

    if (mNewTabButton.onDown(x, y)) {
        mRenderHost.requestRender();
        return;
    }

    final StripLayoutTab clickedTab = getTabAtPosition(x);
    final int index = clickedTab != null
            ? TabModelUtils.getTabIndexById(mModel, clickedTab.getId())
            : TabModel.INVALID_TAB_INDEX;
    // http://crbug.com/472186 : Needs to handle a case that index is invalid.
    // The case could happen when the current tab is touched while we're inflating the rest of
    // the tabs from disk.
    mInteractingTab = index != TabModel.INVALID_TAB_INDEX && index < mStripTabs.length
            ? mStripTabs[index]
            : null;
    boolean clickedClose = clickedTab != null
                           && clickedTab.checkCloseHitTest(x, y);
    if (clickedClose) {
        clickedTab.setClosePressed(true);
        mLastPressedCloseButton = clickedTab.getCloseButton();
        mRenderHost.requestRender();
    }

    if (!mScroller.isFinished()) {
        mScroller.forceFinished(true);
        mInteractingTab = null;
    }

    if (fromMouse && !clickedClose && clickedTab != null
            && clickedTab.getVisiblePercentage() >= 1.f
            && (buttons & MotionEvent.BUTTON_TERTIARY) == 0) {
        startReorderMode(time, x, x);
    }
}
 
Example 14
Source File: LayoutManagerChrome.java    From AndroidChromium with Apache License 2.0 3 votes vote down vote up
/**
 * Should be called when a tab created event is triggered.
 * @param id             The id of the tab that was created.
 * @param sourceId       The id of the creating tab if any.
 * @param launchType     How the tab was launched.
 * @param incognito      Whether or not the created tab is incognito.
 * @param willBeSelected Whether or not the created tab will be selected.
 * @param originX        The x coordinate of the action that created this tab in dp.
 * @param originY        The y coordinate of the action that created this tab in dp.
 */
protected void tabCreated(int id, int sourceId, TabLaunchType launchType, boolean incognito,
        boolean willBeSelected, float originX, float originY) {
    Tab newTab = TabModelUtils.getTabById(getTabModelSelector().getModel(incognito), id);
    mCreatingNtp = newTab != null && newTab.isNativePage();

    int newIndex = TabModelUtils.getTabIndexById(getTabModelSelector().getModel(incognito), id);
    getActiveLayout().onTabCreated(
            time(), id, newIndex, sourceId, incognito, !willBeSelected, originX, originY);
}
 
Example 15
Source File: LayoutManagerChrome.java    From 365browser with Apache License 2.0 3 votes vote down vote up
/**
 * Should be called when a tab created event is triggered.
 * @param id             The id of the tab that was created.
 * @param sourceId       The id of the creating tab if any.
 * @param launchType     How the tab was launched.
 * @param incognito      Whether or not the created tab is incognito.
 * @param willBeSelected Whether or not the created tab will be selected.
 * @param originX        The x coordinate of the action that created this tab in dp.
 * @param originY        The y coordinate of the action that created this tab in dp.
 */
protected void tabCreated(int id, int sourceId, TabLaunchType launchType, boolean incognito,
        boolean willBeSelected, float originX, float originY) {
    Tab newTab = TabModelUtils.getTabById(getTabModelSelector().getModel(incognito), id);
    mCreatingNtp = newTab != null && newTab.isNativePage();

    int newIndex = TabModelUtils.getTabIndexById(getTabModelSelector().getModel(incognito), id);
    getActiveLayout().onTabCreated(
            time(), id, newIndex, sourceId, incognito, !willBeSelected, originX, originY);
}
 
Example 16
Source File: LayoutManagerChrome.java    From delion with Apache License 2.0 3 votes vote down vote up
/**
 * Should be called when a tab created event is triggered.
 * @param id             The id of the tab that was created.
 * @param sourceId       The id of the creating tab if any.
 * @param launchType     How the tab was launched.
 * @param incognito      Whether or not the created tab is incognito.
 * @param willBeSelected Whether or not the created tab will be selected.
 * @param originX        The x coordinate of the action that created this tab in dp.
 * @param originY        The y coordinate of the action that created this tab in dp.
 */
protected void tabCreated(int id, int sourceId, TabLaunchType launchType, boolean incognito,
        boolean willBeSelected, float originX, float originY) {
    Tab newTab = TabModelUtils.getTabById(getTabModelSelector().getModel(incognito), id);
    mCreatingNtp = newTab != null && newTab.isNativePage();

    int newIndex = TabModelUtils.getTabIndexById(getTabModelSelector().getModel(incognito), id);
    getActiveLayout().onTabCreated(
            time(), id, newIndex, sourceId, incognito, !willBeSelected, originX, originY);
}
 
Example 17
Source File: Stack.java    From AndroidChromium with Apache License 2.0 2 votes vote down vote up
/**
 * Animates the closing of the stack. Focusing on the selected tab.
 *
 * @param time The current time of the app in ms.
 * @param id   The id of the tab to select.
 */
public void tabSelectingEffect(long time, int id) {
    int index = TabModelUtils.getTabIndexById(mTabModel, id);
    startAnimation(time, OverviewAnimationType.TAB_FOCUSED, index, -1, false);
}
 
Example 18
Source File: Stack.java    From delion with Apache License 2.0 2 votes vote down vote up
/**
 * Animates the closing of the stack. Focusing on the selected tab.
 *
 * @param time The current time of the app in ms.
 * @param id   The id of the tab to select.
 */
public void tabSelectingEffect(long time, int id) {
    int index = TabModelUtils.getTabIndexById(mTabModel, id);
    startAnimation(time, OverviewAnimationType.TAB_FOCUSED, index, -1, false);
}
 
Example 19
Source File: Stack.java    From 365browser with Apache License 2.0 2 votes vote down vote up
/**
 * Animates the closing of the stack. Focusing on the selected tab.
 *
 * @param time The current time of the app in ms.
 * @param id   The id of the tab to select.
 */
public void tabSelectingEffect(long time, int id) {
    int index = TabModelUtils.getTabIndexById(mTabModel, id);
    startAnimation(time, OverviewAnimationType.TAB_FOCUSED, index, -1, false);
}