org.chromium.chrome.browser.device.DeviceClassManager Java Examples

The following examples show how to use org.chromium.chrome.browser.device.DeviceClassManager. 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: LayoutManagerChrome.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Show the overview {@link Layout}.  This is generally a {@link Layout} that visibly represents
 * all of the {@link Tab}s opened by the user.
 * @param animate Whether or not to animate the transition to overview mode.
 */
public void showOverview(boolean animate) {
    boolean useAccessibility = DeviceClassManager.enableAccessibilityLayout();

    boolean accessibilityIsVisible =
            useAccessibility && getActiveLayout() == mOverviewListLayout;
    boolean normalIsVisible = getActiveLayout() == mOverviewLayout && mOverviewLayout != null;

    // We only want to use the AccessibilityOverviewLayout if the following are all valid:
    // 1. We're already showing the AccessibilityOverviewLayout OR we're using accessibility.
    // 2. We're not already showing the normal OverviewLayout (or we are on a tablet, in which
    //    case the normal layout is always visible).
    if ((accessibilityIsVisible || useAccessibility) && !normalIsVisible) {
        startShowing(mOverviewListLayout, animate);
    } else if (mOverviewLayout != null) {
        startShowing(mOverviewLayout, animate);
    }
}
 
Example #2
Source File: ChromeTabbedActivity.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public void onAccessibilityModeChanged(boolean enabled) {
    super.onAccessibilityModeChanged(enabled);

    if (mLayoutManager != null) {
        mLayoutManager.setEnableAnimations(
                DeviceClassManager.enableAnimations(getApplicationContext()));
    }
    if (isTablet()) {
        if (getCompositorViewHolder() != null) {
            getCompositorViewHolder().onAccessibilityStatusChanged(enabled);
        }
    }
    if (mLayoutManager != null && mLayoutManager.overviewVisible()
            && mIsAccessibilityEnabled != enabled) {
        mLayoutManager.hideOverview(false);
        if (getTabModelSelector().getCurrentModel().getCount() == 0) {
            getCurrentTabCreator().launchNTP();
        }
    }
    mIsAccessibilityEnabled = enabled;
}
 
Example #3
Source File: ChromeTabbedActivity.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public void onAccessibilityModeChanged(boolean enabled) {
    super.onAccessibilityModeChanged(enabled);

    if (mLayoutManager != null) {
        mLayoutManager.setEnableAnimations(
                DeviceClassManager.enableAnimations(getApplicationContext()));
    }
    if (isTablet()) {
        if (getCompositorViewHolder() != null) {
            getCompositorViewHolder().onAccessibilityStatusChanged(enabled);
        }
    }
    if (mLayoutManager != null && mLayoutManager.overviewVisible()
            && mIsAccessibilityEnabled != enabled) {
        mLayoutManager.hideOverview(false);
        if (getTabModelSelector().getCurrentModel().getCount() == 0) {
            getCurrentTabCreator().launchNTP();
        }
    }
    mIsAccessibilityEnabled = enabled;
}
 
Example #4
Source File: ChromeActivity.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public void initializeCompositor() {
    TraceEvent.begin("ChromeActivity:CompositorInitialization");
    super.initializeCompositor();

    setTabContentManager(new TabContentManager(this, getContentOffsetProvider(),
            DeviceClassManager.enableSnapshots()));
    mCompositorViewHolder.onNativeLibraryReady(mWindowAndroid, getTabContentManager());

    if (isContextualSearchAllowed() && ContextualSearchFieldTrial.isEnabled()) {
        mContextualSearchManager = new ContextualSearchManager(this, mWindowAndroid, this);
    }

    if (ReaderModeManager.isEnabled(this)) {
        mReaderModeManager = new ReaderModeManager(getTabModelSelector(), this);
        if (mToolbarManager != null) {
            mToolbarManager.addFindToolbarObserver(
                    mReaderModeManager.getFindToolbarObserver());
        }
    }

    TraceEvent.end("ChromeActivity:CompositorInitialization");
}
 
Example #5
Source File: ChromeActivity.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes the {@link CompositorViewHolder} with the relevant content it needs to properly
 * show content on the screen.
 * @param layoutManager             A {@link LayoutManagerDocument} instance.  This class is
 *                                  responsible for driving all high level screen content and
 *                                  determines which {@link Layout} is shown when.
 * @param urlBar                    The {@link View} representing the URL bar (must be
 *                                  focusable) or {@code null} if none exists.
 * @param contentContainer          A {@link ViewGroup} that can have content attached by
 *                                  {@link Layout}s.
 * @param controlContainer          A {@link ControlContainer} instance to draw.
 */
protected void initializeCompositorContent(
        LayoutManagerDocument layoutManager, View urlBar, ViewGroup contentContainer,
        ControlContainer controlContainer) {
    if (mContextualSearchManager != null) {
        mContextualSearchManager.initialize(contentContainer);
        mContextualSearchManager.setSearchContentViewDelegate(layoutManager);
    }

    layoutManager.addSceneChangeObserver(this);
    mCompositorViewHolder.setLayoutManager(layoutManager);
    mCompositorViewHolder.setFocusable(false);
    mCompositorViewHolder.setControlContainer(controlContainer);
    mCompositorViewHolder.setFullscreenHandler(getFullscreenManager());
    mCompositorViewHolder.setUrlBar(urlBar);
    mCompositorViewHolder.onFinishNativeInitialization(getTabModelSelector(), this,
            getTabContentManager(), contentContainer, mContextualSearchManager,
            mReaderModeManager);

    if (controlContainer != null
            && DeviceClassManager.enableToolbarSwipe()) {
        controlContainer.setSwipeHandler(
                getCompositorViewHolder().getLayoutManager().getTopSwipeHandler());
    }
}
 
Example #6
Source File: ChromeActivity.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public void initializeCompositor() {
    TraceEvent.begin("ChromeActivity:CompositorInitialization");
    super.initializeCompositor();

    setTabContentManager(new TabContentManager(this, getContentOffsetProvider(),
            DeviceClassManager.enableSnapshots()));
    mCompositorViewHolder.onNativeLibraryReady(mWindowAndroid, getTabContentManager());

    if (isContextualSearchAllowed() && ContextualSearchFieldTrial.isEnabled()) {
        mContextualSearchManager = new ContextualSearchManager(this, mWindowAndroid, this);
    }

    if (ReaderModeManager.isEnabled(this)) {
        mReaderModeManager = new ReaderModeManager(getTabModelSelector(), this);
        if (mToolbarManager != null) {
            mToolbarManager.addFindToolbarObserver(
                    mReaderModeManager.getFindToolbarObserver());
        }
    }

    TraceEvent.end("ChromeActivity:CompositorInitialization");
}
 
Example #7
Source File: ChromeTabbedActivity.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void onAccessibilityModeChanged(boolean enabled) {
    super.onAccessibilityModeChanged(enabled);

    if (mLayoutManager != null) {
        mLayoutManager.setEnableAnimations(DeviceClassManager.enableAnimations());
    }
    if (isTablet()) {
        if (getCompositorViewHolder() != null) {
            getCompositorViewHolder().onAccessibilityStatusChanged(enabled);
        }
    }
    if (mLayoutManager != null && mLayoutManager.overviewVisible()
            && mIsAccessibilityEnabled != enabled) {
        mLayoutManager.hideOverview(false);
        if (getTabModelSelector().getCurrentModel().getCount() == 0) {
            getCurrentTabCreator().launchNTP();
        }
    }
    mIsAccessibilityEnabled = enabled;
}
 
Example #8
Source File: LayoutManagerChrome.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isSwipeEnabled(ScrollDirection direction) {
    FullscreenManager manager = mHost.getFullscreenManager();
    if (getActiveLayout() != mStaticLayout
            || !DeviceClassManager.enableToolbarSwipe()
            || (manager != null && manager.getPersistentFullscreenMode())) {
        return false;
    }

    if (direction == ScrollDirection.DOWN) {
        boolean isAccessibility = AccessibilityUtil.isAccessibilityEnabled();
        return mOverviewLayout != null && !isAccessibility;
    }

    return direction == ScrollDirection.LEFT || direction == ScrollDirection.RIGHT;
}
 
Example #9
Source File: LayoutManagerChromePhone.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
protected void tabClosed(int id, int nextId, boolean incognito, boolean tabRemoved) {
    boolean showOverview = nextId == Tab.INVALID_TAB_ID;
    Layout overviewLayout = DeviceClassManager.enableAccessibilityLayout() ? mOverviewListLayout
                                                                           : mOverviewLayout;
    if (getActiveLayout() != overviewLayout && showOverview) {
        // Since there will be no 'next' tab to display, switch to
        // overview mode when the animation is finished.
        setNextLayout(overviewLayout);
    }
    getActiveLayout().onTabClosed(time(), id, nextId, incognito);
    Tab nextTab = getTabById(nextId);
    if (nextTab != null) nextTab.requestFocus();
    boolean animate = !tabRemoved && animationsEnabled();
    if (getActiveLayout() != overviewLayout && showOverview && !animate) {
        startShowing(overviewLayout, false);
    }
}
 
Example #10
Source File: ReaderModeManager.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * This is a wrapper for "requestPanelShow" that checks if reader mode is possible before
 * showing.
 * @param reason The reason the panel is requesting to be shown.
 */
protected void requestReaderPanelShow(StateChangeReason reason) {
    if (mTabModelSelector == null) return;

    int currentTabId = mTabModelSelector.getCurrentTabId();
    if (currentTabId == Tab.INVALID_TAB_ID) return;

    if (mReaderModePanel == null || !mTabStatusMap.containsKey(currentTabId)
            || mTabStatusMap.get(currentTabId).getStatus() != POSSIBLE
            || mTabStatusMap.get(currentTabId).isDismissed()
            || mIsInfoBarContainerShown
            || mIsFindToolbarShowing
            || mIsFullscreenModeEntered
            || mIsKeyboardShowing
            || DeviceClassManager.isAccessibilityModeEnabled(mChromeActivity)) {
        return;
    }

    mReaderModePanel.requestPanelShow(reason);
}
 
Example #11
Source File: BottomToolbarPhone.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
protected void drawTabSwitcherFadeAnimation(boolean animationFinished, float progress) {
    mNewTabButton.setAlpha(progress);

    mLocationBar.setAlpha(1f - progress);
    if (mUseToolbarHandle) mToolbarHandleView.setAlpha(1f - progress);

    int tabSwitcherThemeColor = getToolbarColorForVisualState(VisualState.TAB_SWITCHER_NORMAL);

    updateToolbarBackground(ColorUtils.getColorWithOverlay(
            getTabThemeColor(), tabSwitcherThemeColor, progress));

    // Don't use transparency for accessibility mode or low-end devices since the
    // {@link OverviewListLayout} will be used instead of the normal tab switcher.
    if (!DeviceClassManager.enableAccessibilityLayout()) {
        float alphaTransition = 1f - TAB_SWITCHER_TOOLBAR_ALPHA;
        mToolbarBackground.setAlpha((int) ((1f - (alphaTransition * progress)) * 255));
    }
}
 
Example #12
Source File: LayoutManagerChrome.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isSwipeEnabled(ScrollDirection direction) {
    FullscreenManager manager = mHost.getFullscreenManager();
    if (getActiveLayout() != mStaticLayout
            || !DeviceClassManager.enableToolbarSwipe(
                       FeatureUtilities.isDocumentMode(mHost.getContext()))
            || (manager != null && manager.getPersistentFullscreenMode())) {
        return false;
    }

    boolean isAccessibility =
            DeviceClassManager.isAccessibilityModeEnabled(mHost.getContext());
    return direction == ScrollDirection.LEFT || direction == ScrollDirection.RIGHT
            || (direction == ScrollDirection.DOWN && mOverviewLayout != null
                       && !isAccessibility);
}
 
Example #13
Source File: ChromeActivity.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void initializeCompositor() {
    TraceEvent.begin("ChromeActivity:CompositorInitialization");
    super.initializeCompositor();

    setTabContentManager(new TabContentManager(this, getContentOffsetProvider(),
            DeviceClassManager.enableSnapshots()));
    mCompositorViewHolder.onNativeLibraryReady(getWindowAndroid(), getTabContentManager());

    if (isContextualSearchAllowed() && ContextualSearchFieldTrial.isEnabled()) {
        mContextualSearchManager = new ContextualSearchManager(this, this);
    }

    if (ReaderModeManager.isEnabled(this)) {
        mReaderModeManager = new ReaderModeManager(getTabModelSelector(), this);
        if (mToolbarManager != null) {
            mToolbarManager.addFindToolbarObserver(
                    mReaderModeManager.getFindToolbarObserver());
        }
    }

    TraceEvent.end("ChromeActivity:CompositorInitialization");
}
 
Example #14
Source File: ChromeActivity.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes the {@link CompositorViewHolder} with the relevant content it needs to properly
 * show content on the screen.
 * @param layoutManager             A {@link LayoutManagerDocument} instance.  This class is
 *                                  responsible for driving all high level screen content and
 *                                  determines which {@link Layout} is shown when.
 * @param urlBar                    The {@link View} representing the URL bar (must be
 *                                  focusable) or {@code null} if none exists.
 * @param contentContainer          A {@link ViewGroup} that can have content attached by
 *                                  {@link Layout}s.
 * @param controlContainer          A {@link ControlContainer} instance to draw.
 */
protected void initializeCompositorContent(
        LayoutManagerDocument layoutManager, View urlBar, ViewGroup contentContainer,
        ControlContainer controlContainer) {
    if (mContextualSearchManager != null) {
        mContextualSearchManager.initialize(contentContainer);
        mContextualSearchManager.setSearchContentViewDelegate(layoutManager);
    }

    layoutManager.addSceneChangeObserver(this);
    mCompositorViewHolder.setLayoutManager(layoutManager);
    mCompositorViewHolder.setFocusable(false);
    mCompositorViewHolder.setControlContainer(controlContainer);
    mCompositorViewHolder.setFullscreenHandler(getFullscreenManager());
    mCompositorViewHolder.setUrlBar(urlBar);
    mCompositorViewHolder.onFinishNativeInitialization(getTabModelSelector(), this,
            getTabContentManager(), contentContainer, mContextualSearchManager,
            mReaderModeManager);

    if (controlContainer != null
            && DeviceClassManager.enableToolbarSwipe()) {
        controlContainer.setSwipeHandler(
                getCompositorViewHolder().getLayoutManager().getTopSwipeHandler());
    }
}
 
Example #15
Source File: LayoutManagerDocument.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isSwipeEnabled(ScrollDirection direction) {
    FullscreenManager manager = mHost.getFullscreenManager();
    if (getActiveLayout() != mStaticLayout
            || !FeatureUtilities.isDocumentModeEligible(mHost.getContext())
            || !DeviceClassManager.enableToolbarSwipe()
            || (manager != null && manager.getPersistentFullscreenMode())) {
        return false;
    }

    return direction == ScrollDirection.LEFT || direction == ScrollDirection.RIGHT;
}
 
Example #16
Source File: CustomTabsConnection.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
boolean maySpeculate(CustomTabsSessionToken session) {
    if (!DeviceClassManager.enablePrerendering()) return false;
    PrefServiceBridge prefs = PrefServiceBridge.getInstance();
    if (prefs.isBlockThirdPartyCookiesEnabled()) return false;
    // TODO(yusufo): The check for prerender in PrivacyManager now checks for the network
    // connection type as well, we should either change that or add another check for custom
    // tabs. Then PrivacyManager should be used to make the below check.
    if (!prefs.getNetworkPredictionEnabled()) return false;
    if (DataReductionProxySettings.getInstance().isDataReductionProxyEnabled()) return false;
    ConnectivityManager cm =
            (ConnectivityManager) mApplication.getApplicationContext().getSystemService(
                    Context.CONNECTIVITY_SERVICE);
    return !cm.isActiveNetworkMetered() || shouldPrerenderOnCellularForSession(session);
}
 
Example #17
Source File: ReaderModeManager.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * This is a wrapper for "requestPanelShow" that checks if reader mode is possible before
 * showing.
 * @param reason The reason the panel is requesting to be shown.
 */
protected void requestReaderPanelShow(StateChangeReason reason) {
    if (mTabModelSelector == null) return;

    int currentTabId = mTabModelSelector.getCurrentTabId();
    if (currentTabId == Tab.INVALID_TAB_ID) return;

    // Test if the user is requesting the desktop site. Ignore this if distiller is set to
    // ALWAYS_TRUE.
    boolean usingRequestDesktopSite = getBasePageWebContents() != null
            && getBasePageWebContents().getNavigationController().getUseDesktopUserAgent()
            && !mIsReaderHeuristicAlwaysTrue;

    if (mReaderModePanel == null || !mTabStatusMap.containsKey(currentTabId)
            || usingRequestDesktopSite
            || mTabStatusMap.get(currentTabId).getStatus() != POSSIBLE
            || mTabStatusMap.get(currentTabId).isDismissed()
            || mIsInfoBarContainerShown
            || mIsFindToolbarShowing
            || mIsFullscreenModeEntered
            || mIsKeyboardShowing
            || DeviceClassManager.isAccessibilityModeEnabled(mChromeActivity)) {
        return;
    }

    mReaderModePanel.requestPanelShow(reason);
}
 
Example #18
Source File: TabStateBrowserControlsVisibilityDelegate.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isHidingBrowserControlsEnabled() {
    WebContents webContents = mTab.getWebContents();
    if (webContents == null || webContents.isDestroyed()) return false;

    String url = mTab.getUrl();
    boolean enableHidingBrowserControls = url != null;
    enableHidingBrowserControls &= !url.startsWith(UrlConstants.CHROME_URL_PREFIX);
    enableHidingBrowserControls &= !url.startsWith(UrlConstants.CHROME_NATIVE_URL_PREFIX);

    int securityState = mTab.getSecurityLevel();
    enableHidingBrowserControls &= (securityState != ConnectionSecurityLevel.DANGEROUS
            && securityState != ConnectionSecurityLevel.SECURITY_WARNING);

    enableHidingBrowserControls &= !AccessibilityUtil.isAccessibilityEnabled();

    ContentViewCore cvc = mTab.getContentViewCore();
    enableHidingBrowserControls &= cvc == null || !cvc.isFocusedNodeEditable();
    enableHidingBrowserControls &= !mTab.isShowingErrorPage();
    enableHidingBrowserControls &= !webContents.isShowingInterstitialPage();
    enableHidingBrowserControls &= !mTab.isRendererUnresponsive();
    enableHidingBrowserControls &= (mTab.getFullscreenManager() != null);
    enableHidingBrowserControls &= DeviceClassManager.enableFullscreen();
    enableHidingBrowserControls &= !mIsFullscreenWaitingForLoad;

    return enableHidingBrowserControls;
}
 
Example #19
Source File: ToolbarTablet.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public void onFinishInflate() {
    super.onFinishInflate();
    mLocationBar = (LocationBarTablet) findViewById(R.id.location_bar);

    mHomeButton = (TintedImageButton) findViewById(R.id.home_button);
    mBackButton = (TintedImageButton) findViewById(R.id.back_button);
    mForwardButton = (TintedImageButton) findViewById(R.id.forward_button);
    mReloadButton = (TintedImageButton) findViewById(R.id.refresh_button);
    mShowTabStack = DeviceClassManager.isAccessibilityModeEnabled(getContext())
            || CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_TABLET_TAB_STACK);

    mTabSwitcherButtonDrawable =
            TabSwitcherDrawable.createTabSwitcherDrawable(getResources(), false);
    mTabSwitcherButtonDrawableLight =
            TabSwitcherDrawable.createTabSwitcherDrawable(getResources(), true);

    mAccessibilitySwitcherButton = (ImageButton) findViewById(R.id.tab_switcher_button);
    mAccessibilitySwitcherButton.setImageDrawable(mTabSwitcherButtonDrawable);
    updateSwitcherButtonVisibility(mShowTabStack);

    mBookmarkButton = (TintedImageButton) findViewById(R.id.bookmark_button);

    mMenuButton = (TintedImageButton) findViewById(R.id.menu_button);
    mMenuButtonWrapper.setVisibility(View.VISIBLE);

    if (mAccessibilitySwitcherButton.getVisibility() == View.GONE
            && mMenuButtonWrapper.getVisibility() == View.GONE) {
        ApiCompatibilityUtils.setPaddingRelative((View) mMenuButtonWrapper.getParent(), 0, 0,
                getResources().getDimensionPixelSize(R.dimen.tablet_toolbar_end_padding), 0);
    }

    mSaveOfflineButton = (TintedImageButton) findViewById(R.id.save_offline_button);

    // Initialize values needed for showing/hiding toolbar buttons when the activity size
    // changes.
    mShouldAnimateButtonVisibilityChange = false;
    mToolbarButtonsVisible = true;
    mToolbarButtons = new TintedImageButton[] {mBackButton, mForwardButton, mReloadButton};
}
 
Example #20
Source File: TabStateBrowserControlsVisibilityDelegate.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isHidingBrowserControlsEnabled() {
    WebContents webContents = mTab.getWebContents();
    if (webContents == null || webContents.isDestroyed()) return false;

    String url = mTab.getUrl();
    boolean enableHidingBrowserControls = url != null;
    enableHidingBrowserControls &= !url.startsWith(UrlConstants.CHROME_SCHEME);
    enableHidingBrowserControls &= !url.startsWith(UrlConstants.CHROME_NATIVE_SCHEME);

    int securityState = mTab.getSecurityLevel();
    enableHidingBrowserControls &= (securityState != ConnectionSecurityLevel.DANGEROUS
            && securityState != ConnectionSecurityLevel.SECURITY_WARNING);

    enableHidingBrowserControls &=
            !AccessibilityUtil.isAccessibilityEnabled(mTab.getApplicationContext());

    ContentViewCore cvc = mTab.getContentViewCore();
    enableHidingBrowserControls &= cvc == null || !cvc.isFocusedNodeEditable();
    enableHidingBrowserControls &= !mTab.isShowingErrorPage();
    enableHidingBrowserControls &= !webContents.isShowingInterstitialPage();
    enableHidingBrowserControls &= !mTab.isRendererUnresponsive();
    enableHidingBrowserControls &= (mTab.getFullscreenManager() != null);
    enableHidingBrowserControls &= DeviceClassManager.enableFullscreen();
    enableHidingBrowserControls &= !mIsFullscreenWaitingForLoad;

    return enableHidingBrowserControls;
}
 
Example #21
Source File: GeolocationSnackbarController.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Shows the geolocation snackbar if it hasn't already been shown and the geolocation snackbar
 * is currently relevant: i.e. the default search engine is Google, location is enabled
 * for Chrome, the tab is not incognito, etc.
 *
 * @param snackbarManager The SnackbarManager used to show the snackbar.
 * @param view Any view that's attached to the view hierarchy.
 * @param isIncognito Whether the currently visible tab is incognito.
 * @param delayMs The delay in ms before the snackbar should be shown. This is intended to
 *                give the keyboard time to animate in.
 */
public static void maybeShowSnackbar(final SnackbarManager snackbarManager, View view,
        boolean isIncognito, int delayMs) {
    final Context context = view.getContext();
    if (ChromeFeatureList.isEnabled(ChromeFeatureList.CONSISTENT_OMNIBOX_GEOLOCATION)) return;
    if (getGeolocationSnackbarShown(context)) return;

    // If in incognito mode, don't show the snackbar now, but maybe show it later.
    if (isIncognito) return;

    if (neverShowSnackbar(context)) {
        setGeolocationSnackbarShown(context);
        return;
    }

    Uri searchUri = Uri.parse(TemplateUrlService.getInstance().getUrlForSearchQuery("foo"));
    TypefaceSpan robotoMediumSpan = new TypefaceSpan("sans-serif-medium");
    String messageWithoutSpans = context.getResources().getString(
            R.string.omnibox_geolocation_disclosure, "<b>" + searchUri.getHost() + "</b>");
    SpannableString message = SpanApplier.applySpans(messageWithoutSpans,
            new SpanInfo("<b>", "</b>", robotoMediumSpan));
    String settings = context.getResources().getString(R.string.preferences);
    int durationMs = DeviceClassManager.isAccessibilityModeEnabled(view.getContext())
            ? ACCESSIBILITY_SNACKBAR_DURATION_MS : SNACKBAR_DURATION_MS;
    final GeolocationSnackbarController controller = new GeolocationSnackbarController();
    final Snackbar snackbar = Snackbar
            .make(message, controller, Snackbar.TYPE_ACTION, Snackbar.UMA_OMNIBOX_GEOLOCATION)
            .setAction(settings, view)
            .setSingleLine(false)
            .setDuration(durationMs);

    view.postDelayed(new Runnable() {
        @Override
        public void run() {
            snackbarManager.dismissSnackbars(controller);
            snackbarManager.showSnackbar(snackbar);
            setGeolocationSnackbarShown(context);
        }
    }, delayMs);
}
 
Example #22
Source File: CustomTabsConnection.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private boolean mayPrerender(CustomTabsSessionToken session) {
    if (!DeviceClassManager.enablePrerendering()) return false;
    // TODO(yusufo): The check for prerender in PrivacyManager now checks for the network
    // connection type as well, we should either change that or add another check for custom
    // tabs. Then PrivacyManager should be used to make the below check.
    if (!PrefServiceBridge.getInstance().getNetworkPredictionEnabled()) return false;
    if (DataReductionProxySettings.getInstance().isDataReductionProxyEnabled()) return false;
    ConnectivityManager cm =
            (ConnectivityManager) mApplication.getApplicationContext().getSystemService(
                    Context.CONNECTIVITY_SERVICE);
    return !cm.isActiveNetworkMetered() || shouldPrerenderOnCellularForSession(session);
}
 
Example #23
Source File: ChromeBrowserInitializer.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * This is needed for device class manager which depends on commandline args that are
 * initialized in preInflationStartup()
 */
private void preInflationStartupDone() {
    // Domain reliability uses significant enough memory that we should disable it on low memory
    // devices for now.
    // TODO(zbowling): remove this after domain reliability is refactored. (crbug.com/495342)
    if (DeviceClassManager.disableDomainReliability()) {
        CommandLine.getInstance().appendSwitch(ChromeSwitches.DISABLE_DOMAIN_RELIABILITY);
    }
}
 
Example #24
Source File: LayoutManagerDocument.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isSwipeEnabled(ScrollDirection direction) {
    FullscreenManager manager = mHost.getFullscreenManager();
    if (getActiveLayout() != mStaticLayout
            || !FeatureUtilities.isDocumentModeEligible(mHost.getContext())
            || !DeviceClassManager.enableToolbarSwipe()
            || (manager != null && manager.getPersistentFullscreenMode())) {
        return false;
    }

    return direction == ScrollDirection.LEFT || direction == ScrollDirection.RIGHT;
}
 
Example #25
Source File: LayoutManagerChrome.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isSwipeEnabled(ScrollDirection direction) {
    FullscreenManager manager = mHost.getFullscreenManager();
    if (getActiveLayout() != mStaticLayout
            || !DeviceClassManager.enableToolbarSwipe()
            || (manager != null && manager.getPersistentFullscreenMode())) {
        return false;
    }

    boolean isAccessibility =
            DeviceClassManager.isAccessibilityModeEnabled(mHost.getContext());
    return direction == ScrollDirection.LEFT || direction == ScrollDirection.RIGHT
            || (direction == ScrollDirection.DOWN && mOverviewLayout != null
                       && !isAccessibility);
}
 
Example #26
Source File: SnackbarManager.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private int getDuration(Snackbar snackbar) {
    int durationMs = snackbar.getDuration();
    if (durationMs == 0) {
        durationMs = DeviceClassManager.isAccessibilityModeEnabled(mActivity)
                ? sAccessibilitySnackbarDurationMs : sSnackbarDurationMs;
    }
    return durationMs;
}
 
Example #27
Source File: ChromeActivity.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes the {@link CompositorViewHolder} with the relevant content it needs to properly
 * show content on the screen.
 * @param layoutManager             A {@link LayoutManagerDocument} instance.  This class is
 *                                  responsible for driving all high level screen content and
 *                                  determines which {@link Layout} is shown when.
 * @param urlBar                    The {@link View} representing the URL bar (must be
 *                                  focusable) or {@code null} if none exists.
 * @param contentContainer          A {@link ViewGroup} that can have content attached by
 *                                  {@link Layout}s.
 * @param controlContainer          A {@link ControlContainer} instance to draw.
 */
protected void initializeCompositorContent(
        LayoutManagerDocument layoutManager, View urlBar, ViewGroup contentContainer,
        ControlContainer controlContainer) {
    if (controlContainer != null) {
        mFullscreenManager = createFullscreenManager(controlContainer);
    }

    if (mContextualSearchManager != null) {
        mContextualSearchManager.initialize(contentContainer);
        mContextualSearchManager.setSearchContentViewDelegate(layoutManager);
    }

    layoutManager.addSceneChangeObserver(this);
    mCompositorViewHolder.setLayoutManager(layoutManager);
    mCompositorViewHolder.setFocusable(false);
    mCompositorViewHolder.setControlContainer(controlContainer);
    mCompositorViewHolder.setFullscreenHandler(mFullscreenManager);
    mCompositorViewHolder.setUrlBar(urlBar);
    mCompositorViewHolder.onFinishNativeInitialization(getTabModelSelector(), this,
            getTabContentManager(), contentContainer, mContextualSearchManager,
            mReaderModeManager);

    if (controlContainer != null
            && DeviceClassManager.enableToolbarSwipe(FeatureUtilities.isDocumentMode(this))) {
        controlContainer.setSwipeHandler(
                getCompositorViewHolder().getLayoutManager().getTopSwipeHandler());
    }
}
 
Example #28
Source File: LayoutManagerDocument.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isSwipeEnabled(ScrollDirection direction) {
    FullscreenManager manager = mHost.getFullscreenManager();
    if (getActiveLayout() != mStaticLayout
            || !FeatureUtilities.isDocumentModeEligible(mHost.getContext())
            || !DeviceClassManager.enableToolbarSwipe(
                       FeatureUtilities.isDocumentMode(mHost.getContext()))
            || (manager != null && manager.getPersistentFullscreenMode())) {
        return false;
    }

    return direction == ScrollDirection.LEFT || direction == ScrollDirection.RIGHT;
}
 
Example #29
Source File: SnackbarManager.java    From delion with Apache License 2.0 5 votes vote down vote up
private int getDuration(Snackbar snackbar) {
    int durationMs = snackbar.getDuration();
    if (durationMs == 0) {
        durationMs = DeviceClassManager.isAccessibilityModeEnabled(mActivity)
                ? sAccessibilitySnackbarDurationMs : sSnackbarDurationMs;
    }
    return durationMs;
}
 
Example #30
Source File: ToolbarTablet.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
public void onFinishInflate() {
    super.onFinishInflate();
    mLocationBar = (LocationBarTablet) findViewById(R.id.location_bar);

    mHomeButton = (TintedImageButton) findViewById(R.id.home_button);
    mBackButton = (TintedImageButton) findViewById(R.id.back_button);
    mForwardButton = (TintedImageButton) findViewById(R.id.forward_button);
    mReloadButton = (TintedImageButton) findViewById(R.id.refresh_button);
    mShowTabStack = DeviceClassManager.isAccessibilityModeEnabled(getContext())
            || CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_TABLET_TAB_STACK);

    mTabSwitcherButtonDrawable =
            TabSwitcherDrawable.createTabSwitcherDrawable(getResources(), false);
    mTabSwitcherButtonDrawableLight =
            TabSwitcherDrawable.createTabSwitcherDrawable(getResources(), true);

    mAccessibilitySwitcherButton = (ImageButton) findViewById(R.id.tab_switcher_button);
    mAccessibilitySwitcherButton.setImageDrawable(mTabSwitcherButtonDrawable);
    updateSwitcherButtonVisibility(mShowTabStack);

    mBookmarkButton = (TintedImageButton) findViewById(R.id.bookmark_button);

    mMenuButton = (TintedImageButton) findViewById(R.id.menu_button);
    mMenuButtonWrapper.setVisibility(
            shouldShowMenuButton() ? View.VISIBLE : View.GONE);

    if (mAccessibilitySwitcherButton.getVisibility() == View.GONE
            && mMenuButtonWrapper.getVisibility() == View.GONE) {
        ApiCompatibilityUtils.setPaddingRelative((View) mMenuButtonWrapper.getParent(), 0, 0,
                getResources().getDimensionPixelSize(R.dimen.tablet_toolbar_end_padding), 0);
    }

    // Initialize values needed for showing/hiding toolbar buttons when the activity size
    // changes.
    mShouldAnimateButtonVisibilityChange = false;
    mToolbarButtonsVisible = true;
    mToolbarButtons = new TintedImageButton[] {mBackButton, mForwardButton, mReloadButton};
}