Java Code Examples for android.content.res.Configuration#unset()

The following examples show how to use android.content.res.Configuration#unset() . 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: TaskRecord.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Update task's override configuration based on the bounds.
 * @param bounds The bounds of the task.
 * @param insetBounds The bounds used to calculate the system insets, which is used here to
 *                    subtract the navigation bar/status bar size from the screen size reported
 *                    to the application. See {@link IActivityManager#resizeDockedStack}.
 * @return True if the override configuration was updated.
 */
boolean updateOverrideConfiguration(Rect bounds, @Nullable Rect insetBounds) {
    if (equivalentOverrideBounds(bounds)) {
        return false;
    }
    final Rect currentBounds = getOverrideBounds();

    mTmpConfig.setTo(getOverrideConfiguration());
    final Configuration newConfig = getOverrideConfiguration();

    final boolean matchParentBounds = bounds == null || bounds.isEmpty();
    final boolean persistBounds = getWindowConfiguration().persistTaskBounds();
    if (matchParentBounds) {
        if (!currentBounds.isEmpty() && persistBounds) {
            mLastNonFullscreenBounds = currentBounds;
        }
        setBounds(null);
        newConfig.unset();
    } else {
        mTmpRect.set(bounds);
        adjustForMinimalTaskDimensions(mTmpRect);
        setBounds(mTmpRect);

        if (mStack == null || persistBounds) {
            mLastNonFullscreenBounds = getOverrideBounds();
        }
        computeOverrideConfiguration(newConfig, mTmpRect, insetBounds,
                mTmpRect.right != bounds.right, mTmpRect.bottom != bounds.bottom);
    }
    onOverrideConfigurationChanged(newConfig);
    return !mTmpConfig.equals(newConfig);
}
 
Example 2
Source File: TaskRecord.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/** Clears passed config and fills it with new override values. */
// TODO(b/36505427): TaskRecord.computeOverrideConfiguration() is a utility method that doesn't
// depend on task or stacks, but uses those object to get the display to base the calculation
// on. Probably best to centralize calculations like this in ConfigurationContainer.
void computeOverrideConfiguration(Configuration config, Rect bounds, Rect insetBounds,
        boolean overrideWidth, boolean overrideHeight) {
    mTmpNonDecorBounds.set(bounds);
    mTmpStableBounds.set(bounds);

    config.unset();
    final Configuration parentConfig = getParent().getConfiguration();

    final float density = parentConfig.densityDpi * DisplayMetrics.DENSITY_DEFAULT_SCALE;

    if (mStack != null) {
        final StackWindowController stackController = mStack.getWindowContainerController();
        stackController.adjustConfigurationForBounds(bounds, insetBounds,
                mTmpNonDecorBounds, mTmpStableBounds, overrideWidth, overrideHeight, density,
                config, parentConfig, getWindowingMode());
    } else {
        throw new IllegalArgumentException("Expected stack when calculating override config");
    }

    config.orientation = (config.screenWidthDp <= config.screenHeightDp)
            ? Configuration.ORIENTATION_PORTRAIT
            : Configuration.ORIENTATION_LANDSCAPE;

    // For calculating screen layout, we need to use the non-decor inset screen area for the
    // calculation for compatibility reasons, i.e. screen area without system bars that could
    // never go away in Honeycomb.
    final int compatScreenWidthDp = (int) (mTmpNonDecorBounds.width() / density);
    final int compatScreenHeightDp = (int) (mTmpNonDecorBounds.height() / density);
    // We're only overriding LONG, SIZE and COMPAT parts of screenLayout, so we start override
    // calculation with partial default.
    final int sl = Configuration.SCREENLAYOUT_LONG_YES | Configuration.SCREENLAYOUT_SIZE_XLARGE;
    final int longSize = Math.max(compatScreenHeightDp, compatScreenWidthDp);
    final int shortSize = Math.min(compatScreenHeightDp, compatScreenWidthDp);
    config.screenLayout = Configuration.reduceScreenLayout(sl, longSize, shortSize);
}
 
Example 3
Source File: DockedStackDividerController.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private void initSnapAlgorithmForRotations() {
    final Configuration baseConfig = mDisplayContent.getConfiguration();

    // Initialize the snap algorithms for all 4 screen orientations.
    final Configuration config = new Configuration();
    for (int rotation = 0; rotation < 4; rotation++) {
        final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270);
        final int dw = rotated
                ? mDisplayContent.mBaseDisplayHeight
                : mDisplayContent.mBaseDisplayWidth;
        final int dh = rotated
                ? mDisplayContent.mBaseDisplayWidth
                : mDisplayContent.mBaseDisplayHeight;
        final DisplayCutout displayCutout =
                mDisplayContent.calculateDisplayCutoutForRotation(rotation).getDisplayCutout();
        mService.mPolicy.getStableInsetsLw(rotation, dw, dh, displayCutout, mTmpRect);
        config.unset();
        config.orientation = (dw <= dh) ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE;

        final int displayId = mDisplayContent.getDisplayId();
        final int appWidth = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, rotation,
            baseConfig.uiMode, displayId, displayCutout);
        final int appHeight = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, rotation,
            baseConfig.uiMode, displayId, displayCutout);
        mService.mPolicy.getNonDecorInsetsLw(rotation, dw, dh, displayCutout, mTmpRect);
        final int leftInset = mTmpRect.left;
        final int topInset = mTmpRect.top;

        config.windowConfiguration.setAppBounds(leftInset /*left*/, topInset /*top*/,
                leftInset + appWidth /*right*/, topInset + appHeight /*bottom*/);

        final float density = mDisplayContent.getDisplayMetrics().density;
        config.screenWidthDp = (int) (mService.mPolicy.getConfigDisplayWidth(dw, dh,
                rotation, baseConfig.uiMode, displayId, displayCutout) / density);
        config.screenHeightDp = (int) (mService.mPolicy.getConfigDisplayHeight(dw, dh,
                rotation, baseConfig.uiMode, displayId, displayCutout) / density);
        final Context rotationContext = mService.mContext.createConfigurationContext(config);
        mSnapAlgorithmForRotation[rotation] = new DividerSnapAlgorithm(
                rotationContext.getResources(), dw, dh, getContentWidth(),
                config.orientation == ORIENTATION_PORTRAIT, mTmpRect);
    }
}