Search in sources :

Example 1 with ContextualSearchObserver

use of org.chromium.chrome.browser.contextualsearch.ContextualSearchObserver 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)

Aggregations

ContextualSearchObserver (org.chromium.chrome.browser.contextualsearch.ContextualSearchObserver)1 Tab (org.chromium.chrome.browser.tab.Tab)1 EmptyTabModelObserver (org.chromium.chrome.browser.tabmodel.EmptyTabModelObserver)1 TabModel (org.chromium.chrome.browser.tabmodel.TabModel)1 TabSelectionType (org.chromium.chrome.browser.tabmodel.TabModel.TabSelectionType)1 TabModelSelector (org.chromium.chrome.browser.tabmodel.TabModelSelector)1 TabModelSelectorTabObserver (org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver)1