org.chromium.chrome.browser.multiwindow.MultiWindowUtils Java Examples

The following examples show how to use org.chromium.chrome.browser.multiwindow.MultiWindowUtils. 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: ChromeActivity.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * All deferred startup tasks that require the activity rather than the app should go here.
 */
private void onDeferredStartupForActivity() {
    BeamController.registerForBeam(this, new BeamProvider() {
        @Override
        public String getTabUrlForBeam() {
            if (isOverlayVisible()) return null;
            if (getActivityTab() == null) return null;
            return getActivityTab().getUrl();
        }
    });

    UpdateMenuItemHelper.getInstance().checkForUpdateOnBackgroundThread(this);

    if (mToolbarManager != null) {
        String simpleName = getClass().getSimpleName();
        RecordHistogram.recordTimesHistogram("MobileStartup.ToolbarInflationTime." + simpleName,
                mInflateInitialLayoutDurationMs, TimeUnit.MILLISECONDS);
        mToolbarManager.onDeferredStartup(getOnCreateTimestampMs(), simpleName);
    }

    if (MultiWindowUtils.getInstance().isInMultiWindowMode(this)) {
        onDeferredStartupForMultiWindowMode();
    }
}
 
Example #2
Source File: VrShellDelegate.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private boolean canEnterVR(Tab tab) {
    if (!LibraryLoader.isInitialized()) {
        return false;
    }
    // If vr isn't in the build, or we haven't initialized yet, or vr shell is not enabled and
    // this is not a web vr request, then return immediately.
    if (!mVrAvailable || mNativeVrShellDelegate == 0
            || (!isVrShellEnabled() && !(mRequestedWebVR || mListeningForWebVrActivate))) {
        return false;
    }
    // TODO(mthiesse): When we have VR UI for opening new tabs, etc., allow VR Shell to be
    // entered without any current tabs.
    if (tab == null || tab.getContentViewCore() == null) {
        return false;
    }
    // For now we don't handle native pages. crbug.com/661609
    if (tab.getNativePage() != null || tab.isShowingSadTab()) {
        return false;
    }
    // crbug.com/667781
    if (MultiWindowUtils.getInstance().isInMultiWindowMode(mActivity)) {
        return false;
    }
    return true;
}
 
Example #3
Source File: SigninPromoUtil.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Launches the signin promo if it needs to be displayed.
 * @param activity The parent activity.
 * @return Whether the signin promo is shown.
 */
public static boolean launchSigninPromoIfNeeded(final Activity activity) {
    // The promo is displayed if Chrome is launched directly (i.e., not with the intent to
    // navigate to and view a URL on startup), the instance is part of the field trial,
    // and the promo has been marked to display.
    ChromePreferenceManager preferenceManager = ChromePreferenceManager.getInstance(activity);
    if (MultiWindowUtils.getInstance().isLegacyMultiWindow(activity)) return false;
    if (!preferenceManager.getShowSigninPromo()) return false;
    preferenceManager.setShowSigninPromo(false);

    String lastSyncName = PrefServiceBridge.getInstance().getSyncLastAccountName();
    if (ChromeSigninController.get(activity).isSignedIn() || !TextUtils.isEmpty(lastSyncName)) {
        return false;
    }

    AccountSigninActivity.startIfAllowed(activity, SigninAccessPoint.SIGNIN_PROMO);
    preferenceManager.setSigninPromoShown();
    return true;
}
 
Example #4
Source File: OverlayPanel.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public void onActivityStateChange(Activity activity, int newState) {
    boolean isMultiWindowMode = MultiWindowUtils.getInstance().isLegacyMultiWindow(mActivity)
            || MultiWindowUtils.getInstance().isInMultiWindowMode(mActivity);

    // In multi-window mode the activity that was interacted with last is resumed and
    // all others are paused. We should not close Contextual Search in this case,
    // because the activity may be visible even though it is paused.
    if (isMultiWindowMode
            && (newState == ActivityState.PAUSED || newState == ActivityState.RESUMED)) {
        return;
    }

    if (newState == ActivityState.RESUMED
            || newState == ActivityState.STOPPED
            || newState == ActivityState.DESTROYED) {
        closePanel(StateChangeReason.UNKNOWN, false);
    }
}
 
Example #5
Source File: ChromeActivity.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Called by the system when the activity changes from fullscreen mode to multi-window mode
 * and visa-versa.
 * @param isInMultiWindowMode True if the activity is in multi-window mode.
 */
public void onMultiWindowModeChanged(boolean isInMultiWindowMode) {
    recordMultiWindowModeChangedUserAction(isInMultiWindowMode);

    if (!isInMultiWindowMode
            && ApplicationStatus.getStateForActivity(this) == ActivityState.RESUMED) {
        // Start a new UMA session when exiting multi-window mode if the activity is currently
        // resumed. When entering multi-window Android recents gains focus, so ChromeActivity
        // will get a call to onPauseWithNative(), ending the current UMA session. When exiting
        // multi-window, however, if ChromeActivity is resumed it stays in that state.
        markSessionEnd();
        markSessionResume();
        FeatureUtilities.setIsInMultiWindowMode(
                MultiWindowUtils.getInstance().isInMultiWindowMode(this));
    }

    super.onMultiWindowModeChanged(isInMultiWindowMode);
}
 
Example #6
Source File: OverlayPanel.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void onActivityStateChange(Activity activity, int newState) {
    boolean isMultiWindowMode = MultiWindowUtils.getInstance().isLegacyMultiWindow(mActivity)
            || MultiWindowUtils.getInstance().isInMultiWindowMode(mActivity);

    // In multi-window mode the activity that was interacted with last is resumed and
    // all others are paused. We should not close Contextual Search in this case,
    // because the activity may be visible even though it is paused.
    if (isMultiWindowMode
            && (newState == ActivityState.PAUSED || newState == ActivityState.RESUMED)) {
        return;
    }

    if (newState == ActivityState.RESUMED
            || newState == ActivityState.STOPPED
            || newState == ActivityState.DESTROYED) {
        closePanel(StateChangeReason.UNKNOWN, false);
    }
}
 
Example #7
Source File: ChromeTabbedActivity.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public void onResumeWithNative() {
    super.onResumeWithNative();

    CookiesFetcher.restoreCookies(this);
    StartupMetrics.getInstance().recordHistogram(false);

    if (FeatureUtilities.isTabModelMergingEnabled()) {
        boolean inMultiWindowMode = MultiWindowUtils.getInstance().isInMultiWindowMode(this);
        // Merge tabs if the activity is not in multi-window mode and mMergeTabsOnResume is true
        // or unset because the activity is just starting or was destroyed.
        if (!inMultiWindowMode && (mMergeTabsOnResume == null || mMergeTabsOnResume)) {
            maybeMergeTabs();
        }
        mMergeTabsOnResume = false;
    }
    mVrShellDelegate.maybeResumeVR();

    mLocaleManager.setSnackbarManager(getSnackbarManager());
    mLocaleManager.startObservingPhoneChanges();
}
 
Example #8
Source File: ClearBrowsingDataPreferences.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Called when clearing browsing data completes.
 * Implements the ChromePreferences.OnClearBrowsingDataListener interface.
 */
@Override
public void onBrowsingDataCleared() {
    if (getActivity() == null) return;

    // If the user deleted their browsing history, the dialog about other forms of history
    // is enabled, and it has never been shown before, show it. Note that opening a new
    // DialogFragment is only possible if the Activity is visible.
    //
    // If conditions to show the dialog about other forms of history are not met, just close
    // this preference screen.
    if (MultiWindowUtils.isActivityVisible(getActivity())
            && getSelectedOptions().contains(DialogOption.CLEAR_HISTORY)
            && mIsDialogAboutOtherFormsOfBrowsingHistoryEnabled
            && !OtherFormsOfHistoryDialogFragment.wasDialogShown(getActivity())) {
        mDialogAboutOtherFormsOfBrowsingHistory = new OtherFormsOfHistoryDialogFragment();
        mDialogAboutOtherFormsOfBrowsingHistory.show(getActivity());
        dismissProgressDialog();
        RecordHistogram.recordBooleanHistogram(DIALOG_HISTOGRAM, true);
    } else {
        dismissProgressDialog();
        getActivity().finish();
        RecordHistogram.recordBooleanHistogram(DIALOG_HISTOGRAM, false);
    }
}
 
Example #9
Source File: ChromeActivity.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Called by the system when the activity changes from fullscreen mode to multi-window mode
 * and visa-versa.
 * @param isInMultiWindowMode True if the activity is in multi-window mode.
 */
public void onMultiWindowModeChanged(boolean isInMultiWindowMode) {
    recordMultiWindowModeChangedUserAction(isInMultiWindowMode);

    if (!isInMultiWindowMode
            && ApplicationStatus.getStateForActivity(this) == ActivityState.RESUMED) {
        // Start a new UMA session when exiting multi-window mode if the activity is currently
        // resumed. When entering multi-window Android recents gains focus, so ChromeActivity
        // will get a call to onPauseWithNative(), ending the current UMA session. When exiting
        // multi-window, however, if ChromeActivity is resumed it stays in that state.
        markSessionEnd();
        markSessionResume();
        FeatureUtilities.setIsInMultiWindowMode(
                MultiWindowUtils.getInstance().isInMultiWindowMode(this));
    }
}
 
Example #10
Source File: CustomTabDelegateFactory.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void openNewTab(String url, String extraHeaders, ResourceRequestBody postData,
        int disposition, boolean isRendererInitiated) {
    // If attempting to open an incognito tab, always send the user to tabbed mode.
    if (disposition == WindowOpenDisposition.OFF_THE_RECORD) {
        if (isRendererInitiated) {
            throw new IllegalStateException(
                    "Invalid attempt to open an incognito tab from the renderer");
        }
        LoadUrlParams loadUrlParams = new LoadUrlParams(url);
        loadUrlParams.setVerbatimHeaders(extraHeaders);
        loadUrlParams.setPostData(postData);
        loadUrlParams.setIsRendererInitiated(isRendererInitiated);

        Class<? extends ChromeTabbedActivity> tabbedClass =
                MultiWindowUtils.getInstance().getTabbedActivityForIntent(
                        null, ContextUtils.getApplicationContext());
        AsyncTabCreationParams tabParams = new AsyncTabCreationParams(loadUrlParams,
                new ComponentName(ContextUtils.getApplicationContext(), tabbedClass));
        new TabDelegate(true).createNewTab(tabParams,
                TabLaunchType.FROM_LONGPRESS_FOREGROUND, TabModel.INVALID_TAB_INDEX);
        return;
    }

    super.openNewTab(url, extraHeaders, postData, disposition, isRendererInitiated);
}
 
Example #11
Source File: SigninPromoUtil.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Launches the signin promo if it needs to be displayed.
 * @param activity The parent activity.
 * @return Whether the signin promo is shown.
 */
public static boolean launchSigninPromoIfNeeded(final Activity activity) {
    // The promo is displayed if Chrome is launched directly (i.e., not with the intent to
    // navigate to and view a URL on startup), the instance is part of the field trial,
    // and the promo has been marked to display.
    ChromePreferenceManager preferenceManager = ChromePreferenceManager.getInstance();
    if (MultiWindowUtils.getInstance().isLegacyMultiWindow(activity)) return false;
    if (!preferenceManager.getShowSigninPromo()) return false;
    preferenceManager.setShowSigninPromo(false);

    String lastSyncName = PrefServiceBridge.getInstance().getSyncLastAccountName();
    if (ChromeSigninController.get().isSignedIn() || !TextUtils.isEmpty(lastSyncName)) {
        return false;
    }

    AccountSigninActivity.startIfAllowed(activity, SigninAccessPoint.SIGNIN_PROMO);
    preferenceManager.setSigninPromoShown();
    return true;
}
 
Example #12
Source File: ClearBrowsingDataPreferences.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Called when clearing browsing data completes.
 * Implements the ChromePreferences.OnClearBrowsingDataListener interface.
 */
@Override
public void onBrowsingDataCleared() {
    if (getActivity() == null) return;

    // If the user deleted their browsing history, the dialog about other forms of history
    // is enabled, and it has never been shown before, show it. Note that opening a new
    // DialogFragment is only possible if the Activity is visible.
    //
    // If conditions to show the dialog about other forms of history are not met, just close
    // this preference screen.
    if (MultiWindowUtils.isActivityVisible(getActivity())
            && getSelectedOptions().contains(DialogOption.CLEAR_HISTORY)
            && mIsDialogAboutOtherFormsOfBrowsingHistoryEnabled
            && !OtherFormsOfHistoryDialogFragment.wasDialogShown(getActivity())) {
        mDialogAboutOtherFormsOfBrowsingHistory = new OtherFormsOfHistoryDialogFragment();
        mDialogAboutOtherFormsOfBrowsingHistory.show(getActivity());
        dismissProgressDialog();
        RecordHistogram.recordBooleanHistogram(DIALOG_HISTOGRAM, true);
    } else {
        dismissProgressDialog();
        getActivity().finish();
        RecordHistogram.recordBooleanHistogram(DIALOG_HISTOGRAM, false);
    }
}
 
Example #13
Source File: SigninPromoUtil.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Launches the signin promo if it needs to be displayed.
 * @param activity The parent activity.
 * @return Whether the signin promo is shown.
 */
public static boolean launchSigninPromoIfNeeded(final Activity activity) {
    // The promo is displayed if Chrome is launched directly (i.e., not with the intent to
    // navigate to and view a URL on startup), the instance is part of the field trial,
    // and the promo has been marked to display.
    ChromePreferenceManager preferenceManager = ChromePreferenceManager.getInstance(activity);
    if (MultiWindowUtils.getInstance().isLegacyMultiWindow(activity)) return false;
    if (!preferenceManager.getShowSigninPromo()) return false;
    preferenceManager.setShowSigninPromo(false);

    String lastSyncName = PrefServiceBridge.getInstance().getSyncLastAccountName();
    if (ChromeSigninController.get(activity).isSignedIn() || !TextUtils.isEmpty(lastSyncName)) {
        return false;
    }

    AccountSigninActivity.startAccountSigninActivity(activity, SigninAccessPoint.SIGNIN_PROMO);
    preferenceManager.setSigninPromoShown();
    return true;
}
 
Example #14
Source File: ChromeActivity.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void onResumeWithNative() {
    super.onResumeWithNative();
    markSessionResume();
    RecordUserAction.record("MobileComeToForeground");

    if (getActivityTab() != null) {
        LaunchMetrics.commitLaunchMetrics(getActivityTab().getWebContents());
    }
    ContentViewCore cvc = getContentViewCore();
    if (cvc != null) cvc.onResume();
    FeatureUtilities.setCustomTabVisible(isCustomTab());
    FeatureUtilities.setIsInMultiWindowMode(
            MultiWindowUtils.getInstance().isInMultiWindowMode(this));

    VideoPersister.getInstance().cleanup(this);
    VrShellDelegate.maybeRegisterVrEntryHook(this);
}
 
Example #15
Source File: OverlayPanel.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public void onActivityStateChange(Activity activity, int newState) {
    boolean isMultiWindowMode = MultiWindowUtils.getInstance().isLegacyMultiWindow(mActivity)
            || MultiWindowUtils.getInstance().isInMultiWindowMode(mActivity);

    // In multi-window mode the activity that was interacted with last is resumed and
    // all others are paused. We should not close Contextual Search in this case,
    // because the activity may be visible even though it is paused.
    if (isMultiWindowMode
            && (newState == ActivityState.PAUSED || newState == ActivityState.RESUMED)) {
        return;
    }

    if (newState == ActivityState.RESUMED
            || newState == ActivityState.STOPPED
            || newState == ActivityState.DESTROYED) {
        closePanel(StateChangeReason.UNKNOWN, false);
    }
}
 
Example #16
Source File: ChromeActivity.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Called by the system when the activity changes from fullscreen mode to multi-window mode
 * and visa-versa.
 * @param isInMultiWindowMode True if the activity is in multi-window mode.
 */
@Override
public void onMultiWindowModeChanged(boolean isInMultiWindowMode) {
    recordMultiWindowModeChangedUserAction(isInMultiWindowMode);

    if (!isInMultiWindowMode
            && ApplicationStatus.getStateForActivity(this) == ActivityState.RESUMED) {
        // Start a new UMA session when exiting multi-window mode if the activity is currently
        // resumed. When entering multi-window Android recents gains focus, so ChromeActivity
        // will get a call to onPauseWithNative(), ending the current UMA session. When exiting
        // multi-window, however, if ChromeActivity is resumed it stays in that state.
        markSessionEnd();
        markSessionResume();
        FeatureUtilities.setIsInMultiWindowMode(
                MultiWindowUtils.getInstance().isInMultiWindowMode(this));
    }

    super.onMultiWindowModeChanged(isInMultiWindowMode);
}
 
Example #17
Source File: ChromeActivity.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * All deferred startup tasks that require the activity rather than the app should go here.
 */
private void initDeferredStartupForActivity() {
    DeferredStartupHandler.getInstance().addDeferredTask(new Runnable() {
        @Override
        public void run() {
            if (isActivityDestroyed()) return;
            BeamController.registerForBeam(ChromeActivity.this, new BeamProvider() {
                @Override
                public String getTabUrlForBeam() {
                    if (isOverlayVisible()) return null;
                    if (getActivityTab() == null) return null;
                    return getActivityTab().getUrl();
                }
            });

            UpdateMenuItemHelper.getInstance().checkForUpdateOnBackgroundThread(
                    ChromeActivity.this);
        }
    });

    final String simpleName = getClass().getSimpleName();
    DeferredStartupHandler.getInstance().addDeferredTask(new Runnable() {
        @Override
        public void run() {
            if (isActivityDestroyed()) return;
            if (mToolbarManager != null) {
                RecordHistogram.recordTimesHistogram(
                        "MobileStartup.ToolbarInflationTime." + simpleName,
                        mInflateInitialLayoutDurationMs, TimeUnit.MILLISECONDS);
                mToolbarManager.onDeferredStartup(getOnCreateTimestampMs(), simpleName);
            }

            if (MultiWindowUtils.getInstance().isInMultiWindowMode(ChromeActivity.this)) {
                onDeferredStartupForMultiWindowMode();
            }
        }
    });
}
 
Example #18
Source File: ChromeActivity.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public void onConfigurationChanged(Configuration newConfig) {
    if (mAppMenuHandler != null) mAppMenuHandler.hideAppMenu();
    super.onConfigurationChanged(newConfig);

    if (newConfig.screenWidthDp != mScreenWidthDp) {
        mScreenWidthDp = newConfig.screenWidthDp;
        final Activity activity = this;

        if (mRecordMultiWindowModeScreenWidthRunnable != null) {
            mHandler.removeCallbacks(mRecordMultiWindowModeScreenWidthRunnable);
        }

        // When exiting Android N multi-window mode, onConfigurationChanged() gets called before
        // isInMultiWindowMode() returns false. Delay to avoid recording width when exiting
        // multi-window mode. This also ensures that we don't record intermediate widths seen
        // only for a brief period of time.
        mRecordMultiWindowModeScreenWidthRunnable = new Runnable() {
            @Override
            public void run() {
                mRecordMultiWindowModeScreenWidthRunnable = null;
                if (MultiWindowUtils.getInstance().isInMultiWindowMode(activity)) {
                    recordMultiWindowModeScreenWidth();
                }
            }
        };
        mHandler.postDelayed(mRecordMultiWindowModeScreenWidthRunnable,
                RECORD_MULTI_WINDOW_SCREEN_WIDTH_DELAY_MS);
    }
}
 
Example #19
Source File: CompositorView.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    if (mRootView != null) {
        mRootView.getWindowVisibleDisplayFrame(mCacheAppRect);

        // Check whether the top position of the window has changed as we always must
        // resize in that case to the specified height spec.  On certain versions of
        // Android when you change the top position (i.e. by leaving fullscreen) and
        // do not shrink the SurfaceView, it will appear to be pinned to the top of
        // the screen under the notification bar and all touch offsets will be wrong
        // as well as a gap will appear at the bottom of the screen.
        int windowTop = mCacheAppRect.top;
        boolean topChanged = windowTop != mPreviousWindowTop;
        mPreviousWindowTop = windowTop;

        Activity activity = mWindowAndroid != null ? mWindowAndroid.getActivity().get() : null;
        boolean isMultiWindow = MultiWindowUtils.getInstance().isLegacyMultiWindow(activity)
                || MultiWindowUtils.getInstance().isInMultiWindowMode(activity);

        // If the measured width is the same as the allowed width (i.e. the orientation has
        // not changed) and multi-window mode is off, use the largest measured height seen thus
        // far.  This will prevent surface resizes as a result of showing the keyboard.
        if (!topChanged && !isMultiWindow
                && getMeasuredWidth() == MeasureSpec.getSize(widthMeasureSpec)
                && getMeasuredHeight() > MeasureSpec.getSize(heightMeasureSpec)) {
            heightMeasureSpec =
                    MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.EXACTLY);
        }
    }
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
 
Example #20
Source File: ChromeTabbedActivity.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onResumeWithNative() {
    super.onResumeWithNative();

    if (shouldDestroyIncognitoProfile()) {
        Profile.getLastUsedProfile().getOffTheRecordProfile().destroyWhenAppropriate();
    } else {
        CookiesFetcher.restoreCookies(this);
    }

    StartupMetrics.getInstance().recordHistogram(false);

    if (FeatureUtilities.isTabModelMergingEnabled()) {
        boolean inMultiWindowMode = MultiWindowUtils.getInstance().isInMultiWindowMode(this);
        // Merge tabs if the activity is not in multi-window mode and mMergeTabsOnResume is true
        // or unset because the activity is just starting or was destroyed.
        if (!inMultiWindowMode && (mMergeTabsOnResume == null || mMergeTabsOnResume)) {
            maybeMergeTabs();
        }
        mMergeTabsOnResume = false;
    }

    mLocaleManager.setSnackbarManager(getSnackbarManager());
    mLocaleManager.startObservingPhoneChanges();

    if (isWarmOnResume()) {
        SuggestionsEventReporterBridge.onActivityWarmResumed();
    } else {
        SuggestionsEventReporterBridge.onColdStart();
    }
}
 
Example #21
Source File: ChromeTabbedActivity.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void moveTabToOtherWindow(Tab tab) {
    Class<? extends Activity> targetActivity =
            MultiWindowUtils.getInstance().getOpenInOtherWindowActivity(this);
    if (targetActivity == null) return;

    Intent intent = new Intent(this, targetActivity);
    MultiWindowUtils.setOpenInOtherWindowIntentExtras(intent, this, targetActivity);
    MultiWindowUtils.onMultiInstanceModeStarted();

    tab.detachAndStartReparenting(intent, null, null);
}
 
Example #22
Source File: CompositorView.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    if (mRootView != null) {
        mRootView.getWindowVisibleDisplayFrame(mCacheAppRect);

        // Check whether the top position of the window has changed as we always must
        // resize in that case to the specified height spec.  On certain versions of
        // Android when you change the top position (i.e. by leaving fullscreen) and
        // do not shrink the SurfaceView, it will appear to be pinned to the top of
        // the screen under the notification bar and all touch offsets will be wrong
        // as well as a gap will appear at the bottom of the screen.
        int windowTop = mCacheAppRect.top;
        boolean topChanged = windowTop != mPreviousWindowTop;
        mPreviousWindowTop = windowTop;

        Activity activity = mWindowAndroid != null ? mWindowAndroid.getActivity().get() : null;
        boolean isMultiWindow = MultiWindowUtils.getInstance().isLegacyMultiWindow(activity)
                || MultiWindowUtils.getInstance().isInMultiWindowMode(activity);

        // If the measured width is the same as the allowed width (i.e. the orientation has
        // not changed) and multi-window mode is off, use the largest measured height seen thus
        // far.  This will prevent surface resizes as a result of showing the keyboard.
        if (!topChanged && !isMultiWindow
                && getMeasuredWidth() == MeasureSpec.getSize(widthMeasureSpec)
                && getMeasuredHeight() > MeasureSpec.getSize(heightMeasureSpec)) {
            heightMeasureSpec =
                    MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.EXACTLY);
        }
    }
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
 
Example #23
Source File: TabDelegate.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a tab in the "other" window in multi-window mode. This will only work if
 * {@link MultiWindowUtils#isOpenInOtherWindowSupported} is true for the given activity.
 *
 * @param loadUrlParams Parameters specifying the URL to load and other navigation details.
 * @param activity      The current {@link Activity}
 * @param parentId      The ID of the parent tab, or {@link Tab#INVALID_TAB_ID}.
 */
public void createTabInOtherWindow(LoadUrlParams loadUrlParams, Activity activity,
        int parentId) {
    Intent intent = createNewTabIntent(
            new AsyncTabCreationParams(loadUrlParams), parentId, false);

    Class<? extends Activity> targetActivity =
            MultiWindowUtils.getInstance().getOpenInOtherWindowActivity(activity);
    if (targetActivity == null) return;

    MultiWindowUtils.setOpenInOtherWindowIntentExtras(intent, activity, targetActivity);
    IntentHandler.addTrustedIntentExtras(intent);
    MultiWindowUtils.onMultiInstanceModeStarted();
    activity.startActivity(intent);
}
 
Example #24
Source File: DataReductionPromoScreen.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Launch the data reduction promo, if it needs to be displayed.
 */
public static void launchDataReductionPromo(Activity parentActivity) {
    // The promo is displayed if Chrome is launched directly (i.e., not with the intent to
    // navigate to and view a URL on startup), the instance is part of the field trial,
    // and the promo has not been displayed before.
    if (!DataReductionPromoUtils.canShowPromos()) return;
    if (DataReductionPromoUtils.getDisplayedFreOrSecondRunPromo()) return;
    // Showing the promo dialog in multiwindow mode is broken on Galaxy Note devices:
    // http://crbug.com/354696. If we're in multiwindow mode, save the dialog for later.
    if (MultiWindowUtils.getInstance().isLegacyMultiWindow(parentActivity)) return;

    DataReductionPromoScreen promoScreen = new DataReductionPromoScreen(parentActivity);
    promoScreen.setOnDismissListener(promoScreen);
    promoScreen.show();
}
 
Example #25
Source File: ChromeActivity.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onConfigurationChanged(Configuration newConfig) {
    if (mAppMenuHandler != null) mAppMenuHandler.hideAppMenu();
    super.onConfigurationChanged(newConfig);

    // We only handle VR UI mode changes. Any other changes should follow the default behavior
    // of recreating the activity.
    if (didChangeNonVrUiMode(mUiMode, newConfig.uiMode)) {
        recreate();
        return;
    }
    mUiMode = newConfig.uiMode;

    if (newConfig.screenWidthDp != mScreenWidthDp) {
        mScreenWidthDp = newConfig.screenWidthDp;
        final Activity activity = this;

        if (mRecordMultiWindowModeScreenWidthRunnable != null) {
            mHandler.removeCallbacks(mRecordMultiWindowModeScreenWidthRunnable);
        }

        // When exiting Android N multi-window mode, onConfigurationChanged() gets called before
        // isInMultiWindowMode() returns false. Delay to avoid recording width when exiting
        // multi-window mode. This also ensures that we don't record intermediate widths seen
        // only for a brief period of time.
        mRecordMultiWindowModeScreenWidthRunnable = new Runnable() {
            @Override
            public void run() {
                mRecordMultiWindowModeScreenWidthRunnable = null;
                if (MultiWindowUtils.getInstance().isInMultiWindowMode(activity)) {
                    recordMultiWindowModeScreenWidth();
                }
            }
        };
        mHandler.postDelayed(mRecordMultiWindowModeScreenWidthRunnable,
                RECORD_MULTI_WINDOW_SCREEN_WIDTH_DELAY_MS);
    }
}
 
Example #26
Source File: DataReductionPromoScreen.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Launch the data reduction promo, if it needs to be displayed.
 */
public static void launchDataReductionPromo(Activity parentActivity) {
    // The promo is displayed if Chrome is launched directly (i.e., not with the intent to
    // navigate to and view a URL on startup), the instance is part of the field trial,
    // and the promo has not been displayed before.
    if (!DataReductionPromoUtils.canShowPromos()) return;
    if (DataReductionPromoUtils.getDisplayedFreOrSecondRunPromo()) return;
    // Showing the promo dialog in multiwindow mode is broken on Galaxy Note devices:
    // http://crbug.com/354696. If we're in multiwindow mode, save the dialog for later.
    if (MultiWindowUtils.getInstance().isLegacyMultiWindow(parentActivity)) return;

    DataReductionPromoScreen promoScreen = new DataReductionPromoScreen(parentActivity);
    promoScreen.setOnDismissListener(promoScreen);
    promoScreen.show();
}
 
Example #27
Source File: ChromeTabbedActivity.java    From delion with Apache License 2.0 5 votes vote down vote up
private void moveTabToOtherWindow(Tab tab) {
    Class<? extends Activity> targetActivity =
            MultiWindowUtils.getInstance().getOpenInOtherWindowActivity(this);
    if (targetActivity == null) return;

    Intent intent = new Intent(this, targetActivity);
    MultiWindowUtils.setOpenInOtherWindowIntentExtras(intent, this, targetActivity);

    tab.detachAndStartReparenting(intent, null, null, true);
}
 
Example #28
Source File: TabDelegate.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a tab in the "other" window in multi-window mode. This will only work if
 * {@link MultiWindowUtils#isOpenInOtherWindowSupported} is true for the given activity.
 *
 * @param loadUrlParams Parameters specifying the URL to load and other navigation details.
 * @param activity      The current {@link Activity}
 * @param parentId      The ID of the parent tab, or {@link Tab#INVALID_TAB_ID}.
 */
public void createTabInOtherWindow(LoadUrlParams loadUrlParams, Activity activity,
        int parentId) {
    Intent intent = createNewTabIntent(new AsyncTabCreationParams(loadUrlParams), parentId);

    Class<? extends Activity> targetActivity =
            MultiWindowUtils.getInstance().getOpenInOtherWindowActivity(activity);
    if (targetActivity == null) return;
    MultiWindowUtils.setOpenInOtherWindowIntentExtras(intent, activity, targetActivity);
    IntentHandler.addTrustedIntentExtras(intent, activity);
    activity.startActivity(intent);
}
 
Example #29
Source File: DataReductionPromoScreen.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Launch the data reduction promo, if it needs to be displayed.
 */
public static void launchDataReductionPromo(Activity parentActivity) {
    // The promo is displayed if Chrome is launched directly (i.e., not with the intent to
    // navigate to and view a URL on startup), the instance is part of the field trial,
    // and the promo has not been displayed before.
    if (!DataReductionPromoUtils.canShowPromos()) return;
    if (DataReductionPromoUtils.getDisplayedFreOrSecondRunPromo()) return;
    // Showing the promo dialog in multiwindow mode is broken on Galaxy Note devices:
    // http://crbug.com/354696. If we're in multiwindow mode, save the dialog for later.
    if (MultiWindowUtils.getInstance().isLegacyMultiWindow(parentActivity)) return;

    DataReductionPromoScreen promoScreen = new DataReductionPromoScreen(parentActivity);
    promoScreen.setOnDismissListener(promoScreen);
    promoScreen.show();
}
 
Example #30
Source File: ChromeActivity.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
public void onResumeWithNative() {
    super.onResumeWithNative();
    markSessionResume();
    RecordUserAction.record("MobileComeToForeground");

    if (getActivityTab() != null) {
        LaunchMetrics.commitLaunchMetrics(getActivityTab().getWebContents());
    }
    FeatureUtilities.setCustomTabVisible(isCustomTab());
    FeatureUtilities.setIsInMultiWindowMode(
            MultiWindowUtils.getInstance().isInMultiWindowMode(this));
}