Java源码示例:org.chromium.chrome.browser.multiwindow.MultiWindowUtils

示例1
@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);
    }
}
 
示例2
/**
 * 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;
}
 
示例3
/**
 * 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();
    }
}
 
示例4
/**
 * 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));
    }
}
 
示例5
@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();
}
 
示例6
@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);
    }
}
 
示例7
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;
}
 
示例8
/**
 * 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;
}
 
示例9
/**
 * 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);
    }
}
 
示例10
/**
 * 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);
}
 
示例11
@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);
    }
}
 
示例12
@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);
}
 
示例13
/**
 * 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;
}
 
示例14
/**
 * 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);
    }
}
 
示例15
@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);
}
 
示例16
/**
 * 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);
}
 
示例17
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);
}
 
示例18
@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);
}
 
示例19
/**
 * 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);
}
 
示例20
/**
 * 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();
}
 
示例21
@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));
}
 
示例22
@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);
    }
}
 
示例23
@SuppressLint("InlinedApi")
private void launchTabbedMode() {
    maybePrefetchDnsInBackground();

    Intent newIntent = new Intent(getIntent());
    String className = MultiWindowUtils.getInstance().getTabbedActivityForIntent(
            newIntent, this).getName();
    newIntent.setClassName(getApplicationContext().getPackageName(), className);
    newIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        newIntent.addFlags(Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS);
    }
    Uri uri = newIntent.getData();
    if (uri != null && "content".equals(uri.getScheme())) {
        newIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    }
    if (mIsInLegacyMultiInstanceMode) {
        MultiWindowUtils.getInstance().makeLegacyMultiInstanceIntent(this, newIntent);
    }

    // This system call is often modified by OEMs and not actionable. http://crbug.com/619646.
    StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
    StrictMode.allowThreadDiskWrites();
    try {
        startActivity(newIntent);
    } finally {
        StrictMode.setThreadPolicy(oldPolicy);
    }
}
 
示例24
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);
}
 
示例25
@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);
}
 
示例26
/**
 * 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, activity);
    MultiWindowUtils.onMultiInstanceModeStarted();
    activity.startActivity(intent);
}
 
示例27
/**
 * 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();
}
 
示例28
@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));
}
 
示例29
/**
 * 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();
            }
        }
    });
}
 
示例30
@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);
    }
}