Search in sources :

Example 1 with FindToolbarManager

use of org.chromium.chrome.browser.widget.findinpage.FindToolbarManager in project AndroidChromium by JackyAndroid.

the class ChromeTabbedActivity method initializeUI.

private void initializeUI() {
    try {
        TraceEvent.begin("ChromeTabbedActivity.initializeUI");
        CommandLine commandLine = CommandLine.getInstance();
        commandLine.appendSwitch(ContentSwitches.ENABLE_INSTANT_EXTENDED_API);
        CompositorViewHolder compositorViewHolder = getCompositorViewHolder();
        if (DeviceFormFactor.isTablet(this)) {
            boolean enableTabSwitcher = CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_TABLET_TAB_STACK);
            mLayoutManager = new LayoutManagerChromeTablet(compositorViewHolder, enableTabSwitcher ? new StackLayoutFactory() : null);
        } else {
            mLayoutManager = new LayoutManagerChromePhone(compositorViewHolder, new StackLayoutFactory());
        }
        mLayoutManager.setEnableAnimations(DeviceClassManager.enableAnimations(this));
        mLayoutManager.addOverviewModeObserver(this);
        // TODO(yusufo): get rid of findViewById(R.id.url_bar).
        initializeCompositorContent(mLayoutManager, findViewById(R.id.url_bar), mContentContainer, mControlContainer);
        mTabModelSelectorImpl.setOverviewModeBehavior(mLayoutManager);
        mUndoBarPopupController.initialize();
        // Adjust the content container if we're not entering fullscreen mode.
        if (getFullscreenManager() == null) {
            float controlHeight = getResources().getDimension(R.dimen.control_container_height);
            ((FrameLayout.LayoutParams) mContentContainer.getLayoutParams()).topMargin = (int) controlHeight;
        }
        // fullscreen manager.
        if (mTabModelSelectorImpl != null && mTabModelSelectorImpl.getCurrentTab() != null) {
            mTabModelSelectorImpl.getCurrentTab().setFullscreenManager(getFullscreenManager());
        }
        mFindToolbarManager = new FindToolbarManager(this, getToolbarManager().getActionModeController().getActionModeCallback());
        if (getContextualSearchManager() != null) {
            getContextualSearchManager().setFindToolbarManager(mFindToolbarManager);
        }
        OnClickListener tabSwitcherClickHandler = new OnClickListener() {

            @Override
            public void onClick(View v) {
                if (getFullscreenManager() != null && getFullscreenManager().getPersistentFullscreenMode()) {
                    return;
                }
                toggleOverview();
            }
        };
        OnClickListener newTabClickHandler = new OnClickListener() {

            @Override
            public void onClick(View v) {
                getTabModelSelector().getModel(false).commitAllTabClosures();
                // This assumes that the keyboard can not be seen at the same time as the
                // newtab button on the toolbar.
                getCurrentTabCreator().launchNTP();
                mLocaleManager.showSearchEnginePromoIfNeeded(ChromeTabbedActivity.this);
            }
        };
        OnClickListener bookmarkClickHandler = new OnClickListener() {

            @Override
            public void onClick(View v) {
                addOrEditBookmark(getActivityTab());
            }
        };
        getToolbarManager().initializeWithNative(mTabModelSelectorImpl, getFullscreenManager(), mFindToolbarManager, mLayoutManager, mLayoutManager, tabSwitcherClickHandler, newTabClickHandler, bookmarkClickHandler, null);
        if (isTablet()) {
            EmptyBackgroundViewWrapper bgViewWrapper = new EmptyBackgroundViewWrapper(getTabModelSelector(), getTabCreator(false), ChromeTabbedActivity.this, getAppMenuHandler(), getSnackbarManager(), mLayoutManager);
            bgViewWrapper.initialize();
        }
        mLayoutManager.hideOverview(false);
        mUIInitialized = true;
    } finally {
        TraceEvent.end("ChromeTabbedActivity.initializeUI");
    }
}
Also used : CommandLine(org.chromium.base.CommandLine) LayoutManagerChromePhone(org.chromium.chrome.browser.compositor.layouts.LayoutManagerChromePhone) EmptyBackgroundViewWrapper(org.chromium.chrome.browser.widget.emptybackground.EmptyBackgroundViewWrapper) CompositorViewHolder(org.chromium.chrome.browser.compositor.CompositorViewHolder) FindToolbarManager(org.chromium.chrome.browser.widget.findinpage.FindToolbarManager) FrameLayout(android.widget.FrameLayout) LayoutManagerChromeTablet(org.chromium.chrome.browser.compositor.layouts.LayoutManagerChromeTablet) OnClickListener(android.view.View.OnClickListener) View(android.view.View) ContentVideoView(org.chromium.content.browser.ContentVideoView)

Example 2 with FindToolbarManager

use of org.chromium.chrome.browser.widget.findinpage.FindToolbarManager in project AndroidChromium by JackyAndroid.

the class CustomTabActivity method finishNativeInitialization.

@Override
public void finishNativeInitialization() {
    final CustomTabsConnection connection = CustomTabsConnection.getInstance(getApplication());
    // prerendering doesn't support extra headers.
    if (IntentHandler.getExtraHeadersFromIntent(getIntent()) != null) {
        connection.cancelPrerender(mSession);
    }
    getTabModelSelector().getModel(false).addObserver(mTabModelObserver);
    boolean successfulStateRestore = false;
    // Attempt to restore the previous tab state if applicable.
    if (getSavedInstanceState() != null) {
        assert mMainTab == null;
        getTabModelSelector().loadState(true);
        getTabModelSelector().restoreTabs(true);
        mMainTab = getTabModelSelector().getCurrentTab();
        successfulStateRestore = mMainTab != null;
        if (successfulStateRestore)
            initializeMainTab(mMainTab);
    }
    // If no tab was restored, create a new tab.
    if (!successfulStateRestore) {
        if (mHasCreatedTabEarly) {
            // When the tab is created early, we don't have the TabContentManager connected,
            // since compositor related controllers were not initialized at that point.
            mMainTab.attachTabContentManager(getTabContentManager());
        } else {
            mMainTab = createMainTab();
        }
        getTabModelSelector().getModel(false).addTab(mMainTab, 0, mMainTab.getLaunchType());
    }
    ToolbarControlContainer controlContainer = (ToolbarControlContainer) findViewById(R.id.control_container);
    LayoutManagerDocument layoutDriver = new CustomTabLayoutManager(getCompositorViewHolder());
    initializeCompositorContent(layoutDriver, findViewById(R.id.url_bar), (ViewGroup) findViewById(android.R.id.content), controlContainer);
    mFindToolbarManager = new FindToolbarManager(this, getToolbarManager().getActionModeController().getActionModeCallback());
    if (getContextualSearchManager() != null) {
        getContextualSearchManager().setFindToolbarManager(mFindToolbarManager);
    }
    getToolbarManager().initializeWithNative(getTabModelSelector(), getFullscreenManager(), mFindToolbarManager, null, layoutDriver, null, null, null, new OnClickListener() {

        @Override
        public void onClick(View v) {
            RecordUserAction.record("CustomTabs.CloseButtonClicked");
            finishAndClose();
        }
    });
    mMainTab.setFullscreenManager(getFullscreenManager());
    mCustomTabContentHandler = new CustomTabContentHandler() {

        @Override
        public void loadUrlAndTrackFromTimestamp(LoadUrlParams params, long timestamp) {
            if (!TextUtils.isEmpty(params.getUrl())) {
                params.setUrl(DataReductionProxySettings.getInstance().maybeRewriteWebliteUrl(params.getUrl()));
            }
            loadUrlInTab(getActivityTab(), params, timestamp);
        }

        @Override
        public CustomTabsSessionToken getSession() {
            return mSession;
        }

        @Override
        public boolean shouldIgnoreIntent(Intent intent) {
            return mIntentHandler.shouldIgnoreIntent(CustomTabActivity.this, intent);
        }

        @Override
        public boolean updateCustomButton(int id, Bitmap bitmap, String description) {
            CustomButtonParams params = mIntentDataProvider.getButtonParamsForId(id);
            if (params == null)
                return false;
            params.update(bitmap, description);
            if (params.showOnToolbar()) {
                if (!CustomButtonParams.doesIconFitToolbar(CustomTabActivity.this, bitmap)) {
                    return false;
                }
                showCustomButtonOnToolbar();
            } else {
                if (mBottomBarDelegate != null) {
                    mBottomBarDelegate.updateBottomBarButtons(params);
                }
            }
            return true;
        }

        @Override
        public boolean updateRemoteViews(RemoteViews remoteViews, int[] clickableIDs, PendingIntent pendingIntent) {
            if (mBottomBarDelegate == null)
                return false;
            return mBottomBarDelegate.updateRemoteViews(remoteViews, clickableIDs, pendingIntent);
        }
    };
    recordClientPackageName();
    connection.showSignInToastIfNecessary(mSession, getIntent());
    String url = getUrlToLoad();
    String packageName = connection.getClientPackageNameForSession(mSession);
    if (TextUtils.isEmpty(packageName)) {
        packageName = connection.extractCreatorPackage(getIntent());
    }
    DataUseTabUIManager.onCustomTabInitialNavigation(mMainTab, packageName, url);
    if (!mHasCreatedTabEarly && !successfulStateRestore) {
        loadUrlInTab(mMainTab, new LoadUrlParams(url), IntentHandler.getTimestampFromIntent(getIntent()));
    }
    // Put Sync in the correct state by calling tab state initialized. crbug.com/581811.
    getTabModelSelector().markTabStateInitialized();
    SharedPreferences preferences = ContextUtils.getAppSharedPreferences();
    String lastUrl = preferences.getString(LAST_URL_PREF, null);
    if (lastUrl != null && lastUrl.equals(getUrlToLoad())) {
        RecordUserAction.record("CustomTabsMenuOpenSameUrl");
    } else {
        preferences.edit().putString(LAST_URL_PREF, getUrlToLoad()).apply();
    }
    super.finishNativeInitialization();
}
Also used : SharedPreferences(android.content.SharedPreferences) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) LayoutManagerDocument(org.chromium.chrome.browser.compositor.layouts.LayoutManagerDocument) View(android.view.View) ToolbarControlContainer(org.chromium.chrome.browser.toolbar.ToolbarControlContainer) Bitmap(android.graphics.Bitmap) RemoteViews(android.widget.RemoteViews) FindToolbarManager(org.chromium.chrome.browser.widget.findinpage.FindToolbarManager) OnClickListener(android.view.View.OnClickListener) LoadUrlParams(org.chromium.content_public.browser.LoadUrlParams) PendingIntent(android.app.PendingIntent) CustomTabsSessionToken(android.support.customtabs.CustomTabsSessionToken)

Aggregations

View (android.view.View)2 OnClickListener (android.view.View.OnClickListener)2 FindToolbarManager (org.chromium.chrome.browser.widget.findinpage.FindToolbarManager)2 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 Bitmap (android.graphics.Bitmap)1 CustomTabsIntent (android.support.customtabs.CustomTabsIntent)1 CustomTabsSessionToken (android.support.customtabs.CustomTabsSessionToken)1 FrameLayout (android.widget.FrameLayout)1 RemoteViews (android.widget.RemoteViews)1 CommandLine (org.chromium.base.CommandLine)1 CompositorViewHolder (org.chromium.chrome.browser.compositor.CompositorViewHolder)1 LayoutManagerChromePhone (org.chromium.chrome.browser.compositor.layouts.LayoutManagerChromePhone)1 LayoutManagerChromeTablet (org.chromium.chrome.browser.compositor.layouts.LayoutManagerChromeTablet)1 LayoutManagerDocument (org.chromium.chrome.browser.compositor.layouts.LayoutManagerDocument)1 ToolbarControlContainer (org.chromium.chrome.browser.toolbar.ToolbarControlContainer)1 EmptyBackgroundViewWrapper (org.chromium.chrome.browser.widget.emptybackground.EmptyBackgroundViewWrapper)1 ContentVideoView (org.chromium.content.browser.ContentVideoView)1 LoadUrlParams (org.chromium.content_public.browser.LoadUrlParams)1