Search in sources :

Example 1 with EmptyTabObserver

use of org.chromium.chrome.browser.tab.EmptyTabObserver in project AndroidChromium by JackyAndroid.

the class CompositorViewHolder method internalInit.

private void internalInit() {
    mTabObserver = new EmptyTabObserver() {

        @Override
        public void onContentChanged(Tab tab) {
            CompositorViewHolder.this.onContentChanged();
        }
    };
    mEnableCompositorTabStrip = DeviceFormFactor.isTablet(getContext());
    addOnLayoutChangeListener(new OnLayoutChangeListener() {

        @Override
        public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
            propagateViewportToLayouts(right - left, bottom - top);
            // in so the full page is shown.
            if (mPostHideKeyboardTask != null) {
                new Handler().postDelayed(mPostHideKeyboardTask, 30);
                mPostHideKeyboardTask = null;
            }
        }
    });
    mCompositorView = new CompositorView(getContext(), this);
    // mCompositorView should always be the first child.
    addView(mCompositorView, 0, new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
}
Also used : EmptyTabObserver(org.chromium.chrome.browser.tab.EmptyTabObserver) Tab(org.chromium.chrome.browser.tab.Tab) FrameLayout(android.widget.FrameLayout) Handler(android.os.Handler) SurfaceView(android.view.SurfaceView) View(android.view.View) VirtualView(org.chromium.chrome.browser.compositor.layouts.components.VirtualView) Paint(android.graphics.Paint)

Example 2 with EmptyTabObserver

use of org.chromium.chrome.browser.tab.EmptyTabObserver in project AndroidChromium by JackyAndroid.

the class CustomTabActivity method prepareTabBackground.

/**
 * Sets the initial background color for the Tab, shown before the page content is ready.
 */
private void prepareTabBackground(final Tab tab) {
    if (!IntentHandler.isIntentChromeOrFirstParty(getIntent(), this))
        return;
    int backgroundColor = mIntentDataProvider.getInitialBackgroundColor();
    if (backgroundColor == Color.TRANSPARENT)
        return;
    // Set the background color.
    tab.getView().setBackgroundColor(backgroundColor);
    // Unset the background when the page has rendered.
    EmptyTabObserver mediaObserver = new EmptyTabObserver() {

        @Override
        public void didFirstVisuallyNonEmptyPaint(final Tab tab) {
            tab.removeObserver(this);
            // Blink has rendered the page by this point, but Android asynchronously shows it.
            // Introduce a small delay, then actually show the page.
            new Handler().postDelayed(new Runnable() {

                @Override
                public void run() {
                    if (!tab.isInitialized() || isActivityDestroyed())
                        return;
                    tab.getView().setBackgroundResource(0);
                }
            }, 50);
        }
    };
    tab.addObserver(mediaObserver);
}
Also used : EmptyTabObserver(org.chromium.chrome.browser.tab.EmptyTabObserver) Tab(org.chromium.chrome.browser.tab.Tab) IntentHandler(org.chromium.chrome.browser.IntentHandler) Handler(android.os.Handler)

Example 3 with EmptyTabObserver

use of org.chromium.chrome.browser.tab.EmptyTabObserver in project AndroidChromium by JackyAndroid.

the class WebappActivity method createTabObserver.

protected TabObserver createTabObserver() {
    return new EmptyTabObserver() {

        @Override
        public void onSSLStateUpdated(Tab tab) {
            updateUrlBar();
        }

        @Override
        public void onDidStartProvisionalLoadForFrame(Tab tab, boolean isMainFrame, String validatedUrl) {
            if (isMainFrame)
                updateUrlBar();
        }

        @Override
        public void onDidChangeThemeColor(Tab tab, int color) {
            if (!isWebappDomain())
                return;
            mBrandColor = color;
            updateTaskDescription();
        }

        @Override
        public void onTitleUpdated(Tab tab) {
            if (!isWebappDomain())
                return;
            updateTaskDescription();
        }

        @Override
        public void onFaviconUpdated(Tab tab, Bitmap icon) {
            if (!isWebappDomain())
                return;
            // No need to cache the favicon if there is an icon declared in app manifest.
            if (mWebappInfo.icon() != null)
                return;
            if (icon == null)
                return;
            if (mLargestFavicon == null || icon.getWidth() > mLargestFavicon.getWidth() || icon.getHeight() > mLargestFavicon.getHeight()) {
                mLargestFavicon = icon;
                updateTaskDescription();
            }
        }

        @Override
        public void onDidNavigateMainFrame(Tab tab, String url, String baseUrl, boolean isNavigationToDifferentPage, boolean isNavigationInPage, int statusCode) {
            updateUrlBar();
        }

        @Override
        public void onDidAttachInterstitialPage(Tab tab) {
            updateUrlBar();
            int state = ApplicationStatus.getStateForActivity(WebappActivity.this);
            if (state == ActivityState.PAUSED || state == ActivityState.STOPPED || state == ActivityState.DESTROYED) {
                return;
            }
            // Kick the interstitial navigation to Chrome.
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(getActivityTab().getUrl()));
            intent.setPackage(getPackageName());
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
            // Pretend like the navigation never happened.  We delay so that this happens while
            // the Activity is in the background.
            mHandler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    getActivityTab().goBack();
                }
            }, MS_BEFORE_NAVIGATING_BACK_FROM_INTERSTITIAL);
        }

        @Override
        public void onDidDetachInterstitialPage(Tab tab) {
            updateUrlBar();
        }

        @Override
        public void didFirstVisuallyNonEmptyPaint(Tab tab) {
            hideSplashScreen(WebappUma.SPLASHSCREEN_HIDES_REASON_PAINT);
        }

        @Override
        public void onPageLoadFinished(Tab tab) {
            hideSplashScreen(WebappUma.SPLASHSCREEN_HIDES_REASON_LOAD_FINISHED);
        }

        @Override
        public void onPageLoadFailed(Tab tab, int errorCode) {
            hideSplashScreen(WebappUma.SPLASHSCREEN_HIDES_REASON_LOAD_FAILED);
        }

        @Override
        public void onCrash(Tab tab, boolean sadTabShown) {
            hideSplashScreen(WebappUma.SPLASHSCREEN_HIDES_REASON_CRASH);
        }
    };
}
Also used : EmptyTabObserver(org.chromium.chrome.browser.tab.EmptyTabObserver) Bitmap(android.graphics.Bitmap) Tab(org.chromium.chrome.browser.tab.Tab) Intent(android.content.Intent)

Example 4 with EmptyTabObserver

use of org.chromium.chrome.browser.tab.EmptyTabObserver in project AndroidChromium by JackyAndroid.

the class FullScreenActivity method createTab.

/**
 * Creates the {@link Tab} used by the FullScreenActivity.
 * If the {@code savedInstanceState} exists, then the user did not intentionally close the app
 * by swiping it away in the recent tasks list.  In that case, we try to restore the tab from
 * disk.
 */
private Tab createTab() {
    Tab tab = null;
    boolean unfreeze = false;
    int tabId = Tab.INVALID_TAB_ID;
    String tabUrl = null;
    if (getSavedInstanceState() != null) {
        tabId = getSavedInstanceState().getInt(BUNDLE_TAB_ID, Tab.INVALID_TAB_ID);
        tabUrl = getSavedInstanceState().getString(BUNDLE_TAB_URL);
    }
    if (tabId != Tab.INVALID_TAB_ID && tabUrl != null && getActivityDirectory() != null) {
        // Restore the tab.
        TabState tabState = TabState.restoreTabState(getActivityDirectory(), tabId);
        tab = new Tab(tabId, Tab.INVALID_TAB_ID, false, this, getWindowAndroid(), TabLaunchType.FROM_RESTORE, TabCreationState.FROZEN_ON_RESTORE, tabState);
        unfreeze = true;
    }
    if (tab == null) {
        tab = new Tab(Tab.INVALID_TAB_ID, Tab.INVALID_TAB_ID, false, this, getWindowAndroid(), TabLaunchType.FROM_CHROME_UI, null, null);
    }
    tab.initialize(null, getTabContentManager(), createTabDelegateFactory(), false, unfreeze);
    tab.addObserver(new EmptyTabObserver() {

        @Override
        public void onContentChanged(Tab tab) {
            assert tab == mTab;
            handleTabContentChanged();
        }
    });
    return tab;
}
Also used : EmptyTabObserver(org.chromium.chrome.browser.tab.EmptyTabObserver) Tab(org.chromium.chrome.browser.tab.Tab) TabState(org.chromium.chrome.browser.TabState)

Aggregations

EmptyTabObserver (org.chromium.chrome.browser.tab.EmptyTabObserver)4 Tab (org.chromium.chrome.browser.tab.Tab)4 Handler (android.os.Handler)2 Intent (android.content.Intent)1 Bitmap (android.graphics.Bitmap)1 Paint (android.graphics.Paint)1 SurfaceView (android.view.SurfaceView)1 View (android.view.View)1 FrameLayout (android.widget.FrameLayout)1 IntentHandler (org.chromium.chrome.browser.IntentHandler)1 TabState (org.chromium.chrome.browser.TabState)1 VirtualView (org.chromium.chrome.browser.compositor.layouts.components.VirtualView)1