Search in sources :

Example 6 with TabModelSelectorTabObserver

use of org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver in project AndroidChromium by JackyAndroid.

the class LayoutManagerChromeTablet method init.

@Override
public void init(TabModelSelector selector, TabCreatorManager creator, TabContentManager content, ViewGroup androidContentContainer, ContextualSearchManagementDelegate contextualSearchDelegate, ReaderModeManagerDelegate readerModeDelegate, DynamicResourceLoader dynamicResourceLoader) {
    if (mTabStripLayoutHelperManager != null) {
        mTabStripLayoutHelperManager.setTabModelSelector(selector, creator);
    }
    super.init(selector, creator, content, androidContentContainer, contextualSearchDelegate, readerModeDelegate, dynamicResourceLoader);
    mTabObserver = new TabModelSelectorTabObserver(selector) {

        @Override
        public void onFaviconUpdated(Tab tab, Bitmap icon) {
            updateTitle(tab);
        }

        @Override
        public void onTitleUpdated(Tab tab) {
            updateTitle(tab);
        }
    };
    // Make sure any tabs already restored get loaded into the title cache.
    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++) {
            Tab tab = model.getTabAt(j);
            if (tab != null && mTitleCache != null) {
                mTitleCache.getUpdatedTitle(tab, mDefaultTitle);
            }
        }
    }
}
Also used : Bitmap(android.graphics.Bitmap) Tab(org.chromium.chrome.browser.tab.Tab) TabModelSelectorTabObserver(org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver) TabModel(org.chromium.chrome.browser.tabmodel.TabModel)

Example 7 with TabModelSelectorTabObserver

use of org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver in project AndroidChromium by JackyAndroid.

the class ContextReporter method enable.

/**
     * Starts reporting context.
     */
public void enable() {
    Tab currentTab = mActivity.getActivityTab();
    reportUsageOfCurrentContextIfPossible(currentTab, false, null);
    TabModelSelector selector = mActivity.getTabModelSelector();
    assert selector != null;
    if (mSelectorTabObserver == null) {
        mSelectorTabObserver = new TabModelSelectorTabObserver(selector) {

            @Override
            public void onTitleUpdated(Tab tab) {
                // Report usage declaring this as a title change.
                reportUsageOfCurrentContextIfPossible(tab, true, null);
            }

            @Override
            public void onUrlUpdated(Tab tab) {
                reportUsageOfCurrentContextIfPossible(tab, false, null);
            }
        };
    }
    if (mModelObserver == null) {
        assert !selector.getModels().isEmpty();
        mModelObserver = new EmptyTabModelObserver() {

            @Override
            public void didSelectTab(Tab tab, TabSelectionType type, int lastId) {
                reportUsageOfCurrentContextIfPossible(tab, false, null);
            }
        };
        for (TabModel model : selector.getModels()) {
            model.addObserver(mModelObserver);
        }
    }
    if (mContextualSearchObserver == null && mActivity.getContextualSearchManager() != null) {
        mContextualSearchObserver = new ContextualSearchObserver() {

            @Override
            public void onShowContextualSearch(GSAContextDisplaySelection contextSelection) {
                if (contextSelection != null)
                    reportDisplaySelection(contextSelection);
            }

            @Override
            public void onHideContextualSearch() {
                reportDisplaySelection(null);
            }
        };
        mActivity.getContextualSearchManager().addObserver(mContextualSearchObserver);
    }
}
Also used : Tab(org.chromium.chrome.browser.tab.Tab) TabModelSelector(org.chromium.chrome.browser.tabmodel.TabModelSelector) TabModelSelectorTabObserver(org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver) TabSelectionType(org.chromium.chrome.browser.tabmodel.TabModel.TabSelectionType) EmptyTabModelObserver(org.chromium.chrome.browser.tabmodel.EmptyTabModelObserver) TabModel(org.chromium.chrome.browser.tabmodel.TabModel) ContextualSearchObserver(org.chromium.chrome.browser.contextualsearch.ContextualSearchObserver)

Example 8 with TabModelSelectorTabObserver

use of org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver in project AndroidChromium by JackyAndroid.

the class UmaSessionStats method startNewSession.

/**
     * Starts a new session for logging.
     * @param tabModelSelector A TabModelSelector instance for recording tab counts on page loads.
     * If null, UmaSessionStats does not record page loads and tab counts.
     */
public void startNewSession(TabModelSelector tabModelSelector) {
    ensureNativeInitialized();
    mTabModelSelector = tabModelSelector;
    if (mTabModelSelector != null) {
        mComponentCallbacks = new ComponentCallbacks() {

            @Override
            public void onLowMemory() {
            // Not required
            }

            @Override
            public void onConfigurationChanged(Configuration newConfig) {
                mKeyboardConnected = newConfig.keyboard != Configuration.KEYBOARD_NOKEYS;
            }
        };
        mContext.registerComponentCallbacks(mComponentCallbacks);
        mKeyboardConnected = mContext.getResources().getConfiguration().keyboard != Configuration.KEYBOARD_NOKEYS;
        mTabModelSelectorTabObserver = new TabModelSelectorTabObserver(mTabModelSelector) {

            @Override
            public void onPageLoadFinished(Tab tab) {
                recordPageLoadStats(tab);
            }
        };
    }
    nativeUmaResumeSession(sNativeUmaSessionStats);
    updatePreferences();
    updateMetricsServiceState();
}
Also used : ComponentCallbacks(android.content.ComponentCallbacks) Configuration(android.content.res.Configuration) Tab(org.chromium.chrome.browser.tab.Tab) TabModelSelectorTabObserver(org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver)

Aggregations

Tab (org.chromium.chrome.browser.tab.Tab)8 TabModelSelectorTabObserver (org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver)8 TabModel (org.chromium.chrome.browser.tabmodel.TabModel)4 SuppressLint (android.annotation.SuppressLint)2 LayoutTab (org.chromium.chrome.browser.compositor.layouts.components.LayoutTab)2 TabModelSelector (org.chromium.chrome.browser.tabmodel.TabModelSelector)2 ComponentCallbacks (android.content.ComponentCallbacks)1 Configuration (android.content.res.Configuration)1 Bitmap (android.graphics.Bitmap)1 ContextualSearchObserver (org.chromium.chrome.browser.contextualsearch.ContextualSearchObserver)1 EmptyTabModelObserver (org.chromium.chrome.browser.tabmodel.EmptyTabModelObserver)1 EmptyTabModelSelectorObserver (org.chromium.chrome.browser.tabmodel.EmptyTabModelSelectorObserver)1 TabSelectionType (org.chromium.chrome.browser.tabmodel.TabModel.TabSelectionType)1 ToolbarControlContainer (org.chromium.chrome.browser.toolbar.ToolbarControlContainer)1 ControlContainer (org.chromium.chrome.browser.widget.ControlContainer)1