Java Code Examples for android.content.pm.activityinfo#WindowLayout

The following examples show how to use android.content.pm.activityinfo#WindowLayout . 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: ActivityLaunchParamsModifier.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public int onCalculate(TaskRecord task, ActivityInfo.WindowLayout layout,
        ActivityRecord activity, ActivityRecord source, ActivityOptions options,
        LaunchParams currentParams, LaunchParams outParams) {
    // We only care about figuring out bounds for activities.
    if (activity == null) {
        return RESULT_SKIP;
    }

    // Activity must be resizeable in the specified task.
    if (!(mSupervisor.canUseActivityOptionsLaunchBounds(options)
            && (activity.isResizeable() || (task != null && task.isResizeable())))) {
        return RESULT_SKIP;
    }

    final Rect bounds = options.getLaunchBounds();

    // Bounds weren't valid.
    if (bounds == null || bounds.isEmpty()) {
        return RESULT_SKIP;
    }

    outParams.mBounds.set(bounds);

    // When this is the most explicit position specification so we should not allow further
    // modification of the position.
    return RESULT_DONE;
}
 
Example 2
Source File: TaskLaunchParamsModifier.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private int getFinalWidth(ActivityInfo.WindowLayout windowLayout, Rect availableRect) {
    int width = getFreeformWidth(availableRect);
    if (windowLayout.width > 0) {
        width = windowLayout.width;
    }
    if (windowLayout.widthFraction > 0) {
        width = (int) (availableRect.width() * windowLayout.widthFraction);
    }
    return width;
}
 
Example 3
Source File: TaskLaunchParamsModifier.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private int getFinalHeight(ActivityInfo.WindowLayout windowLayout, Rect availableRect) {
    int height = getFreeformHeight(availableRect);
    if (windowLayout.height > 0) {
        height = windowLayout.height;
    }
    if (windowLayout.heightFraction > 0) {
        height = (int) (availableRect.height() * windowLayout.heightFraction);
    }
    return height;
}
 
Example 4
Source File: TaskLaunchParamsModifier.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Tries to set task's bound in a way that it won't collide with any other task. By colliding
 * we mean that two tasks have left-top corner very close to each other, so one might get
 * obfuscated by the other one.
 */
@Override
public int onCalculate(TaskRecord task, ActivityInfo.WindowLayout layout,
                       ActivityRecord activity, ActivityRecord source, ActivityOptions options,
                       LaunchParams currentParams, LaunchParams outParams) {
    // We can only apply positioning if we're in a freeform stack.
    if (task == null || task.getStack() == null || !task.inFreeformWindowingMode()) {
        return RESULT_SKIP;
    }

    final ArrayList<TaskRecord> tasks = task.getStack().getAllTasks();

    mAvailableRect.set(task.getParent().getBounds());

    final Rect resultBounds = outParams.mBounds;

    if (layout == null) {
        positionCenter(tasks, mAvailableRect, getFreeformWidth(mAvailableRect),
                getFreeformHeight(mAvailableRect), resultBounds);
        return RESULT_CONTINUE;
    }

    int width = getFinalWidth(layout, mAvailableRect);
    int height = getFinalHeight(layout, mAvailableRect);
    int verticalGravity = layout.gravity & Gravity.VERTICAL_GRAVITY_MASK;
    int horizontalGravity = layout.gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
    if (verticalGravity == Gravity.TOP) {
        if (horizontalGravity == Gravity.RIGHT) {
            positionTopRight(tasks, mAvailableRect, width, height, resultBounds);
        } else {
            positionTopLeft(tasks, mAvailableRect, width, height, resultBounds);
        }
    } else if (verticalGravity == Gravity.BOTTOM) {
        if (horizontalGravity == Gravity.RIGHT) {
            positionBottomRight(tasks, mAvailableRect, width, height, resultBounds);
        } else {
            positionBottomLeft(tasks, mAvailableRect, width, height, resultBounds);
        }
    } else {
        // Some fancy gravity setting that we don't support yet. We just put the activity in the
        // center.
        Slog.w(TAG, "Received unsupported gravity: " + layout.gravity
                + ", positioning in the center instead.");
        positionCenter(tasks, mAvailableRect, width, height, resultBounds);
    }

    return RESULT_CONTINUE;
}