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

The following examples show how to use org.chromium.chrome.browser.tabmodel.TabModelUtils#setIndex() . 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: LayoutManagerDocument.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void changeTabs() {
    DocumentTabModelSelector selector =
            ChromeApplication.getDocumentTabModelSelector();
    TabModel tabModel = selector.getCurrentModel();
    int currentIndex = tabModel.index();
    if (mLastScroll == ScrollDirection.LEFT) {
        if (currentIndex < tabModel.getCount() - 1) {
            TabModelUtils.setIndex(tabModel, currentIndex + 1);
        }
    } else {
        if (currentIndex > 0) {
            TabModelUtils.setIndex(tabModel, currentIndex - 1);
        }
    }
}
 
Example 3
Source File: NewTabPage.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private boolean switchToExistingTab(String url) {
    String matchPattern = CommandLine.getInstance().getSwitchValue(
            ChromeSwitches.NTP_SWITCH_TO_EXISTING_TAB);
    boolean matchByHost;
    if ("url".equals(matchPattern)) {
        matchByHost = false;
    } else if ("host".equals(matchPattern)) {
        matchByHost = true;
    } else {
        return false;
    }

    TabModel tabModel = mTabModelSelector.getModel(false);
    for (int i = tabModel.getCount() - 1; i >= 0; --i) {
        if (matchURLs(tabModel.getTabAt(i).getUrl(), url, matchByHost)) {
            TabModelUtils.setIndex(tabModel, i);
            return true;
        }
    }
    return false;
}
 
Example 4
Source File: TileGroupDelegateImpl.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private boolean switchToExistingTab(String url) {
    String matchPattern =
            CommandLine.getInstance().getSwitchValue(ChromeSwitches.NTP_SWITCH_TO_EXISTING_TAB);
    boolean matchByHost;
    if ("url".equals(matchPattern)) {
        matchByHost = false;
    } else if ("host".equals(matchPattern)) {
        matchByHost = true;
    } else {
        return false;
    }

    TabModel tabModel = mTabModelSelector.getModel(false);
    for (int i = tabModel.getCount() - 1; i >= 0; --i) {
        if (matchURLs(tabModel.getTabAt(i).getUrl(), url, matchByHost)) {
            TabModelUtils.setIndex(tabModel, i);
            return true;
        }
    }
    return false;
}
 
Example 5
Source File: TabWebContentsDelegateAndroid.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public void activateContents() {
    boolean activityIsDestroyed = false;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        activityIsDestroyed = mTab.getActivity().isDestroyed();
    }
    if (activityIsDestroyed || !mTab.isInitialized()) {
        Log.e(TAG, "Activity destroyed before calling activateContents().  Bailing out.");
        return;
    }

    TabModel model = getTabModel();
    int index = model.indexOf(mTab);
    if (index == TabModel.INVALID_TAB_INDEX) return;
    TabModelUtils.setIndex(model, index);
    bringActivityToForeground();
}
 
Example 6
Source File: LayoutManagerDocument.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void changeTabs() {
    DocumentTabModelSelector selector =
            ChromeApplication.getDocumentTabModelSelector();
    TabModel tabModel = selector.getCurrentModel();
    int currentIndex = tabModel.index();
    if (mLastScroll == ScrollDirection.LEFT) {
        if (currentIndex < tabModel.getCount() - 1) {
            TabModelUtils.setIndex(tabModel, currentIndex + 1);
        }
    } else {
        if (currentIndex > 0) {
            TabModelUtils.setIndex(tabModel, currentIndex - 1);
        }
    }
}
 
Example 7
Source File: Layout.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * To be called when the transition out of the view mode is done.
 * This is currently called by the renderer when all the animation are done while hiding.
 */
public void doneHiding() {
    mIsHiding = false;
    if (mNextTabId != Tab.INVALID_TAB_ID) {
        TabModel model = mTabModelSelector.getModelForTabId(mNextTabId);
        if (model != null) {
            TabModelUtils.setIndex(model, TabModelUtils.getTabIndexById(model, mNextTabId));
        }
        mNextTabId = Tab.INVALID_TAB_ID;
    }
    mUpdateHost.doneHiding();
    if (mRenderHost != null && mRenderHost.getResourceManager() != null) {
        mRenderHost.getResourceManager().clearTintedResourceCache();
    }
}
 
Example 8
Source File: VrShellImpl.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@CalledByNative
private void showTab(int id) {
    Tab tab = mActivity.getTabModelSelector().getTabById(id);
    if (tab == null) {
        return;
    }
    int index = mActivity.getTabModelSelector().getModel(tab.isIncognito()).indexOf(tab);
    if (index == TabModel.INVALID_TAB_INDEX) {
        return;
    }
    TabModelUtils.setIndex(mActivity.getTabModelSelector().getModel(tab.isIncognito()), index);
}
 
Example 9
Source File: Layout.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * To be called when the transition out of the view mode is done.
 * This is currently called by the renderer when all the animation are done while hiding.
 */
public void doneHiding() {
    mIsHiding = false;
    if (mNextTabId != Tab.INVALID_TAB_ID) {
        TabModel model = mTabModelSelector.getModelForTabId(mNextTabId);
        if (model != null) {
            TabModelUtils.setIndex(model, TabModelUtils.getTabIndexById(model, mNextTabId));
        }
        mNextTabId = Tab.INVALID_TAB_ID;
    }
    mUpdateHost.doneHiding();
    if (mRenderHost != null && mRenderHost.getResourceManager() != null) {
        mRenderHost.getResourceManager().clearTintedResourceCache();
    }
}
 
Example 10
Source File: StripLayoutHelper.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void startReorderMode(long time, float currentX, float startX) {
    if (mInReorderMode) return;

    // 1. Reset the last pressed close button state.
    if (mLastPressedCloseButton != null && mLastPressedCloseButton.isPressed()) {
        mLastPressedCloseButton.setPressed(false);
    }
    mLastPressedCloseButton = null;

    // 2. Check to see if we have a valid tab to start dragging.
    mInteractingTab = getTabAtPosition(startX);
    if (mInteractingTab == null) return;

    // 3. Set initial state parameters.
    mLastReorderScrollTime = 0;
    mReorderState = REORDER_SCROLL_NONE;
    mLastReorderX = startX;
    mInReorderMode = true;

    // 4. Select this tab so that it is always in the foreground.
    TabModelUtils.setIndex(
            mModel, TabModelUtils.getTabIndexById(mModel, mInteractingTab.getId()));

    // 5. Fast expand to make sure this tab is visible. If tabs are not cascaded, the selected
    //    tab will already be visible, so there's no need to fast expand to make it visible.
    if (mShouldCascadeTabs) {
        float fastExpandDelta =
                calculateOffsetToMakeTabVisible(mInteractingTab, true, true, true);
        mScroller.startScroll(mScrollOffset, 0, (int) fastExpandDelta, 0, time,
                EXPAND_DURATION_MS);
    }

    // 6. Request an update.
    mUpdateHost.requestUpdate();
}
 
Example 11
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 12
Source File: AccessibilityTabModelAdapter.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public void tabSelected(int tab) {
    if (mListener != null) mListener.showTab(tab);
    TabModelUtils.setIndex(mActualTabModel,
            TabModelUtils.getTabIndexById(mActualTabModel, tab));
    notifyDataSetChanged();
}
 
Example 13
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 14
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 15
Source File: StripLayoutHelper.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private void startReorderMode(long time, float currentX, float startX) {
    if (mInReorderMode) return;

    // 1. Reset the last pressed close button state.
    if (mLastPressedCloseButton != null && mLastPressedCloseButton.isPressed()) {
        mLastPressedCloseButton.setPressed(false);
    }
    mLastPressedCloseButton = null;

    // 2. Check to see if we have a valid tab to start dragging.
    mInteractingTab = getTabAtPosition(startX);
    if (mInteractingTab == null) return;

    // 3. Set initial state parameters.
    mLastReorderScrollTime = 0;
    mReorderState = REORDER_SCROLL_NONE;
    mLastReorderX = startX;
    mInReorderMode = true;

    // 4. Select this tab so that it is always in the foreground.
    TabModelUtils.setIndex(
            mModel, TabModelUtils.getTabIndexById(mModel, mInteractingTab.getId()));

    // 5. Fast expand to make sure this tab is visible. If tabs are not cascaded, the selected
    //    tab will already be visible, so there's no need to fast expand to make it visible.
    if (mShouldCascadeTabs) {
        float fastExpandDelta =
                calculateOffsetToMakeTabVisible(mInteractingTab, true, true, true);
        mScroller.startScroll(mScrollOffset, 0, (int) fastExpandDelta, 0, time,
                EXPAND_DURATION_MS);
    }

    // 6. Request an update.
    mUpdateHost.requestUpdate();
}
 
Example 16
Source File: AccessibilityTabModelAdapter.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
public void tabSelected(int tab) {
    if (mListener != null) mListener.showTab(tab);
    TabModelUtils.setIndex(mActualTabModel,
            TabModelUtils.getTabIndexById(mActualTabModel, tab));
    notifyDataSetChanged();
}
 
Example 17
Source File: TabWebContentsDelegateAndroid.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void activateContents() {
    ChromeActivity activity = mTab.getActivity();
    if (activity == null) {
        Log.e(TAG, "Activity not set activateContents().  Bailing out.");
        return;
    }
    if (activity.isActivityDestroyed()) {
        Log.e(TAG, "Activity destroyed before calling activateContents().  Bailing out.");
        return;
    }
    if (!mTab.isInitialized()) {
        Log.e(TAG, "Tab not initialized before calling activateContents().  Bailing out.");
        return;
    }

    // Do nothing if the tab can currently be interacted with by the user.
    if (mTab.isUserInteractable()) return;

    TabModel model = getTabModel();
    int index = model.indexOf(mTab);
    if (index == TabModel.INVALID_TAB_INDEX) return;
    TabModelUtils.setIndex(model, index);

    // Do nothing if the activity is visible (STOPPED is the only valid invisible state as we
    // explicitly check isActivityDestroyed above).
    if (ApplicationStatus.getStateForActivity(activity) == ActivityState.STOPPED) {
        bringActivityToForeground();
    }
}
 
Example 18
Source File: AccessibilityTabModelAdapter.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void tabSelected(int tab) {
    if (mListener != null) mListener.showTab(tab);
    TabModelUtils.setIndex(mActualTabModel,
            TabModelUtils.getTabIndexById(mActualTabModel, tab));
    notifyDataSetChanged();
}
 
Example 19
Source File: Layout.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * To be called when the transition out of the view mode is done.
 * This is currently called by the renderer when all the animation are done while hiding.
 */
public void doneHiding() {
    mIsHiding = false;
    if (mNextTabId != Tab.INVALID_TAB_ID) {
        TabModel model = mTabModelSelector.getModelForTabId(mNextTabId);
        if (model != null) {
            TabModelUtils.setIndex(model, TabModelUtils.getTabIndexById(model, mNextTabId));
        }
        mNextTabId = Tab.INVALID_TAB_ID;
    }
    mUpdateHost.doneHiding();
}
 
Example 20
Source File: StripLayoutHelper.java    From delion with Apache License 2.0 5 votes vote down vote up
private void startReorderMode(long time, float currentX, float startX) {
    if (mInReorderMode) return;

    // 1. Reset the last pressed close button state.
    if (mLastPressedCloseButton != null && mLastPressedCloseButton.isPressed()) {
        mLastPressedCloseButton.setPressed(false);
    }
    mLastPressedCloseButton = null;

    // 2. Check to see if we have a valid tab to start dragging.
    mInteractingTab = getTabAtPosition(startX);
    if (mInteractingTab == null) return;

    // 3. Set initial state parameters.
    mLastReorderScrollTime = 0;
    mReorderState = REORDER_SCROLL_NONE;
    mLastReorderX = startX;
    mInReorderMode = true;

    // 4. Select this tab so that it is always in the foreground.
    TabModelUtils.setIndex(
            mModel, TabModelUtils.getTabIndexById(mModel, mInteractingTab.getId()));

    // 5. Fast expand to make sure this tab is visible. If tabs are not cascaded, the selected
    //    tab will already be visible, so there's no need to fast expand to make it visible.
    if (mShouldCascadeTabs) {
        float fastExpandDelta =
                calculateOffsetToMakeTabVisible(mInteractingTab, true, true, true);
        mScroller.startScroll(mScrollOffset, 0, (int) fastExpandDelta, 0, time,
                EXPAND_DURATION_MS);
    }

    // 6. Request an update.
    mUpdateHost.requestUpdate();
}