Java Code Examples for org.chromium.chrome.browser.tabmodel.TabModel#getCount()
The following examples show how to use
org.chromium.chrome.browser.tabmodel.TabModel#getCount() .
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: LayoutManagerDocument.java From delion with Apache License 2.0 | 6 votes |
@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 2
Source File: TileGroupDelegateImpl.java From 365browser with Apache License 2.0 | 6 votes |
@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 3
Source File: SeparateTaskManagedCustomTabActivity.java From delion with Apache License 2.0 | 6 votes |
@Override protected IntentHandlerDelegate createIntentHandlerDelegate() { return new IntentHandlerDelegate() { @Override public void processWebSearchIntent(String query) { } @Override public void processUrlViewIntent(String url, String referer, String headers, TabOpenType tabOpenType, String externalAppId, int tabIdToBringToFront, boolean hasUserGesture, Intent intent) { Tab currentTab = getTabCreator(false).launchUrlFromExternalApp( url, referer, headers, externalAppId, true, intent, mIntentHandlingTimeMs); // Close all existing tabs from the previous session. TabModel tabModel = getTabModelSelector().getModel(false); for (int i = tabModel.getCount() - 1; i >= 0; i--) { if (tabModel.getTabAt(i).equals(currentTab)) continue; tabModel.closeTab(tabModel.getTabAt(i), false, false, false); } } }; }
Example 4
Source File: SeparateTaskManagedCustomTabActivity.java From 365browser with Apache License 2.0 | 6 votes |
@Override protected IntentHandlerDelegate createIntentHandlerDelegate() { return new IntentHandlerDelegate() { @Override public void processWebSearchIntent(String query) { } @Override public void processUrlViewIntent(String url, String referer, String headers, TabOpenType tabOpenType, String externalAppId, int tabIdToBringToFront, boolean hasUserGesture, Intent intent) { Tab currentTab = getTabCreator(false).launchUrlFromExternalApp( url, referer, headers, externalAppId, true, intent, mIntentHandlingTimeMs); // Close all existing tabs from the previous session. TabModel tabModel = getTabModelSelector().getModel(false); for (int i = tabModel.getCount() - 1; i >= 0; i--) { if (tabModel.getTabAt(i).equals(currentTab)) continue; tabModel.closeTab(tabModel.getTabAt(i), false, false, false); } } }; }
Example 5
Source File: LayoutManagerDocument.java From 365browser with Apache License 2.0 | 6 votes |
@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 6
Source File: LayoutManagerDocument.java From AndroidChromium with Apache License 2.0 | 6 votes |
@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: SeparateTaskManagedCustomTabActivity.java From AndroidChromium with Apache License 2.0 | 6 votes |
@Override protected IntentHandlerDelegate createIntentHandlerDelegate() { return new IntentHandlerDelegate() { @Override public void processWebSearchIntent(String query) { } @Override public void processUrlViewIntent(String url, String referer, String headers, TabOpenType tabOpenType, String externalAppId, int tabIdToBringToFront, boolean hasUserGesture, Intent intent) { Tab currentTab = getTabCreator(false).launchUrlFromExternalApp( url, referer, headers, externalAppId, true, intent, mIntentHandlingTimeMs); // Close all existing tabs from the previous session. TabModel tabModel = getTabModelSelector().getModel(false); for (int i = tabModel.getCount() - 1; i >= 0; i--) { if (tabModel.getTabAt(i).equals(currentTab)) continue; tabModel.closeTab(tabModel.getTabAt(i), false, false, false); } } }; }
Example 8
Source File: CustomTabTabPersistencePolicy.java From 365browser with Apache License 2.0 | 5 votes |
/** * Get all current Tab IDs used by the specified activity. * * @param activity The activity whose tab IDs are to be collected from. * @param tabIds Where the tab IDs should be added to. */ private static void getAllTabIdsForActivity(CustomTabActivity activity, Set<Integer> tabIds) { if (activity == null) return; TabModelSelector selector = activity.getTabModelSelector(); if (selector == null) return; List<TabModel> models = selector.getModels(); for (int i = 0; i < models.size(); i++) { TabModel model = models.get(i); for (int j = 0; j < model.getCount(); j++) { tabIds.add(model.getTabAt(j).getId()); } } }
Example 9
Source File: OverviewListLayout.java From 365browser with Apache License 2.0 | 5 votes |
@Override public void onTabsAllClosing(long time, boolean incognito) { super.onTabsAllClosing(time, incognito); TabModel model = mTabModelSelector.getModel(incognito); while (model.getCount() > 0) TabModelUtils.closeTabByIndex(model, 0); if (incognito) { mTabModelSelector.selectModel(!incognito); } if (mTabModelWrapper == null) return; mTabModelWrapper.setStateBasedOnModel(); }
Example 10
Source File: EmptyBackgroundViewWrapper.java From AndroidChromium with Apache License 2.0 | 5 votes |
private boolean shouldShowEmptyContainer() { TabModel model = mTabModelSelector.getModel(false); if (model == null) { return false; } boolean isIncognitoEmpty = mTabModelSelector.getModel(true).getCount() == 0; boolean incognitoSelected = mTabModelSelector.isIncognitoSelected(); // Only show the empty container if: // 1. There are no tabs in the normal TabModel AND // 2. Overview mode is not showing AND // 3. We're in the normal TabModel OR there are no tabs present in either model return model.getCount() == 0 && !mOverviewModeBehavior.overviewVisible() && (!incognitoSelected || isIncognitoEmpty); }
Example 11
Source File: Tab.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** * @return The most recently used rank for this tab in the given TabModel. */ private static int computeMRURank(Tab tab, TabModel model) { final long tabLastShow = tab.getTabUma().getLastShownTimestamp(); int mruRank = 0; for (int i = 0; i < model.getCount(); i++) { Tab otherTab = model.getTabAt(i); if (otherTab != tab && otherTab.getTabUma() != null && otherTab.getTabUma().getLastShownTimestamp() > tabLastShow) { mruRank++; } } return mruRank; }
Example 12
Source File: CustomTabTabPersistencePolicy.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** * Get all current Tab IDs used by the specified activity. * * @param activity The activity whose tab IDs are to be collected from. * @param tabIds Where the tab IDs should be added to. */ private static void getAllTabIdsForActivity(CustomTabActivity activity, Set<Integer> tabIds) { if (activity == null) return; TabModelSelector selector = activity.getTabModelSelector(); if (selector == null) return; List<TabModel> models = selector.getModels(); for (int i = 0; i < models.size(); i++) { TabModel model = models.get(i); for (int j = 0; j < model.getCount(); j++) { tabIds.add(model.getTabAt(j).getId()); } } }
Example 13
Source File: EmptyBackgroundViewWrapper.java From 365browser with Apache License 2.0 | 5 votes |
private boolean shouldShowEmptyContainer() { TabModel model = mTabModelSelector.getModel(false); if (model == null) { return false; } boolean isIncognitoEmpty = mTabModelSelector.getModel(true).getCount() == 0; boolean incognitoSelected = mTabModelSelector.isIncognitoSelected(); // Only show the empty container if: // 1. There are no tabs in the normal TabModel AND // 2. Overview mode is not showing AND // 3. We're in the normal TabModel OR there are no tabs present in either model return model.getCount() == 0 && !mOverviewModeBehavior.overviewVisible() && (!incognitoSelected || isIncognitoEmpty); }
Example 14
Source File: EmptyBackgroundViewWrapper.java From delion with Apache License 2.0 | 5 votes |
private boolean shouldShowEmptyContainer() { TabModel model = mTabModelSelector.getModel(false); if (model == null) { return false; } boolean isIncognitoEmpty = mTabModelSelector.getModel(true).getCount() == 0; boolean incognitoSelected = mTabModelSelector.isIncognitoSelected(); // Only show the empty container if: // 1. There are no tabs in the normal TabModel AND // 2. Overview mode is not showing AND // 3. We're in the normal TabModel OR there are no tabs present in either model return model.getCount() == 0 && !mOverviewModeBehavior.overviewVisible() && (!incognitoSelected || isIncognitoEmpty); }
Example 15
Source File: Tab.java From delion with Apache License 2.0 | 5 votes |
/** * @return The most recently used rank for this tab in the given TabModel. */ private static int computeMRURank(Tab tab, TabModel model) { final long tabLastShow = tab.getTabUma().getLastShownTimestamp(); int mruRank = 0; for (int i = 0; i < model.getCount(); i++) { Tab otherTab = model.getTabAt(i); if (otherTab != tab && otherTab.getTabUma() != null && otherTab.getTabUma().getLastShownTimestamp() > tabLastShow) { mruRank++; } } return mruRank; }
Example 16
Source File: UmaSessionStats.java From AndroidChromium with Apache License 2.0 | 4 votes |
private int getTabCountFromModel(TabModel model) { return model == null ? 0 : model.getCount(); }
Example 17
Source File: ToolbarSwipeLayout.java From AndroidChromium with Apache License 2.0 | 4 votes |
@Override public void swipeStarted(long time, ScrollDirection direction, float x, float y) { if (mTabModelSelector == null || mToTab != null || direction == ScrollDirection.DOWN) { return; } boolean dragFromLeftEdge = direction == ScrollDirection.RIGHT; // Finish off any other animations. forceAnimationToFinish(); // Determine which tabs we're showing. TabModel model = mTabModelSelector.getCurrentModel(); if (model == null) return; int fromIndex = model.index(); if (fromIndex == TabModel.INVALID_TAB_INDEX) return; // On RTL, edge-dragging to the left is the next tab. int toIndex = (LocalizationUtils.isLayoutRtl() ^ dragFromLeftEdge) ? fromIndex - 1 : fromIndex + 1; int leftIndex = dragFromLeftEdge ? toIndex : fromIndex; int rightIndex = !dragFromLeftEdge ? toIndex : fromIndex; List<Integer> visibleTabs = new ArrayList<Integer>(); if (0 <= leftIndex && leftIndex < model.getCount()) { int leftTabId = model.getTabAt(leftIndex).getId(); mLeftTab = createLayoutTab(leftTabId, model.isIncognito(), NO_CLOSE_BUTTON, NEED_TITLE); prepareLayoutTabForSwipe(mLeftTab, leftIndex != fromIndex); visibleTabs.add(leftTabId); } if (0 <= rightIndex && rightIndex < model.getCount()) { int rightTabId = model.getTabAt(rightIndex).getId(); mRightTab = createLayoutTab(rightTabId, model.isIncognito(), NO_CLOSE_BUTTON, NEED_TITLE); prepareLayoutTabForSwipe(mRightTab, rightIndex != fromIndex); visibleTabs.add(rightTabId); } updateCacheVisibleIds(visibleTabs); mToTab = null; // Reset the tab offsets. mOffsetStart = dragFromLeftEdge ? 0 : getWidth(); mOffset = 0; mOffsetTarget = 0; if (mLeftTab != null && mRightTab != null) { mLayoutTabs = new LayoutTab[] {mLeftTab, mRightTab}; } else if (mLeftTab != null) { mLayoutTabs = new LayoutTab[] {mLeftTab}; } else if (mRightTab != null) { mLayoutTabs = new LayoutTab[] {mRightTab}; } else { mLayoutTabs = null; } requestUpdate(); }
Example 18
Source File: ToolbarSwipeLayout.java From 365browser with Apache License 2.0 | 4 votes |
@Override public void swipeStarted(long time, ScrollDirection direction, float x, float y) { if (mTabModelSelector == null || mToTab != null || direction == ScrollDirection.DOWN) { return; } boolean dragFromLeftEdge = direction == ScrollDirection.RIGHT; // Finish off any other animations. forceAnimationToFinish(); // Determine which tabs we're showing. TabModel model = mTabModelSelector.getCurrentModel(); if (model == null) return; int fromIndex = model.index(); if (fromIndex == TabModel.INVALID_TAB_INDEX) return; // On RTL, edge-dragging to the left is the next tab. int toIndex = (LocalizationUtils.isLayoutRtl() ^ dragFromLeftEdge) ? fromIndex - 1 : fromIndex + 1; int leftIndex = dragFromLeftEdge ? toIndex : fromIndex; int rightIndex = !dragFromLeftEdge ? toIndex : fromIndex; List<Integer> visibleTabs = new ArrayList<Integer>(); if (0 <= leftIndex && leftIndex < model.getCount()) { int leftTabId = model.getTabAt(leftIndex).getId(); mLeftTab = createLayoutTab(leftTabId, model.isIncognito(), NO_CLOSE_BUTTON, NEED_TITLE); prepareLayoutTabForSwipe(mLeftTab, leftIndex != fromIndex); visibleTabs.add(leftTabId); } if (0 <= rightIndex && rightIndex < model.getCount()) { int rightTabId = model.getTabAt(rightIndex).getId(); mRightTab = createLayoutTab(rightTabId, model.isIncognito(), NO_CLOSE_BUTTON, NEED_TITLE); prepareLayoutTabForSwipe(mRightTab, rightIndex != fromIndex); visibleTabs.add(rightTabId); } updateCacheVisibleIds(visibleTabs); mToTab = null; // Reset the tab offsets. mOffsetStart = dragFromLeftEdge ? 0 : getWidth(); mOffset = 0; mOffsetTarget = 0; if (mLeftTab != null && mRightTab != null) { mLayoutTabs = new LayoutTab[] {mLeftTab, mRightTab}; } else if (mLeftTab != null) { mLayoutTabs = new LayoutTab[] {mLeftTab}; } else if (mRightTab != null) { mLayoutTabs = new LayoutTab[] {mRightTab}; } else { mLayoutTabs = null; } requestUpdate(); }
Example 19
Source File: UmaSessionStats.java From 365browser with Apache License 2.0 | 4 votes |
private int getTabCountFromModel(TabModel model) { return model == null ? 0 : model.getCount(); }
Example 20
Source File: ToolbarSwipeLayout.java From delion with Apache License 2.0 | 4 votes |
@Override public void swipeStarted(long time, ScrollDirection direction, float x, float y) { if (mTabModelSelector == null || mToTab != null || direction == ScrollDirection.DOWN) { return; } boolean dragFromLeftEdge = direction == ScrollDirection.RIGHT; // Finish off any other animations. forceAnimationToFinish(); // Determine which tabs we're showing. TabModel model = mTabModelSelector.getCurrentModel(); if (model == null) return; int fromIndex = model.index(); if (fromIndex == TabModel.INVALID_TAB_INDEX) return; // On RTL, edge-dragging to the left is the next tab. int toIndex = (LocalizationUtils.isLayoutRtl() ^ dragFromLeftEdge) ? fromIndex - 1 : fromIndex + 1; int leftIndex = dragFromLeftEdge ? toIndex : fromIndex; int rightIndex = !dragFromLeftEdge ? toIndex : fromIndex; List<Integer> visibleTabs = new ArrayList<Integer>(); if (0 <= leftIndex && leftIndex < model.getCount()) { int leftTabId = model.getTabAt(leftIndex).getId(); mLeftTab = createLayoutTab(leftTabId, model.isIncognito(), NO_CLOSE_BUTTON, NEED_TITLE); prepareLayoutTabForSwipe(mLeftTab, leftIndex != fromIndex); visibleTabs.add(leftTabId); } if (0 <= rightIndex && rightIndex < model.getCount()) { int rightTabId = model.getTabAt(rightIndex).getId(); mRightTab = createLayoutTab(rightTabId, model.isIncognito(), NO_CLOSE_BUTTON, NEED_TITLE); prepareLayoutTabForSwipe(mRightTab, rightIndex != fromIndex); visibleTabs.add(rightTabId); } updateCacheVisibleIds(visibleTabs); mToTab = null; // Reset the tab offsets. mOffsetStart = dragFromLeftEdge ? 0 : getWidth(); mOffset = 0; mOffsetTarget = 0; if (mLeftTab != null && mRightTab != null) { mLayoutTabs = new LayoutTab[] {mLeftTab, mRightTab}; } else if (mLeftTab != null) { mLayoutTabs = new LayoutTab[] {mLeftTab}; } else if (mRightTab != null) { mLayoutTabs = new LayoutTab[] {mRightTab}; } else { mLayoutTabs = null; } requestUpdate(); }