use of com.android.internal.policy.DividerSnapAlgorithm in project android_frameworks_base by ResurrectionRemix.
the class DockedStackDividerController method initSnapAlgorithmForRotations.
private void initSnapAlgorithmForRotations() {
final Configuration baseConfig = mService.mCurConfiguration;
// 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;
mService.mPolicy.getStableInsetsLw(rotation, dw, dh, mTmpRect);
config.setToDefaults();
config.orientation = (dw <= dh) ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE;
config.screenWidthDp = (int) (mService.mPolicy.getConfigDisplayWidth(dw, dh, rotation, baseConfig.uiMode) / mDisplayContent.getDisplayMetrics().density);
config.screenHeightDp = (int) (mService.mPolicy.getConfigDisplayHeight(dw, dh, rotation, baseConfig.uiMode) / mDisplayContent.getDisplayMetrics().density);
final Context rotationContext = mService.mContext.createConfigurationContext(config);
mSnapAlgorithmForRotation[rotation] = new DividerSnapAlgorithm(rotationContext.getResources(), dw, dh, getContentWidth(), config.orientation == ORIENTATION_PORTRAIT, mTmpRect);
}
}
use of com.android.internal.policy.DividerSnapAlgorithm in project android_frameworks_base by ResurrectionRemix.
the class TaskStack method snapDockedStackAfterRotation.
/**
* Snaps the bounds after rotation to the closest snap target for the docked stack.
*/
private void snapDockedStackAfterRotation(Rect outBounds) {
// Calculate the current position.
final DisplayInfo displayInfo = mDisplayContent.getDisplayInfo();
final int dividerSize = mService.getDefaultDisplayContentLocked().getDockedDividerController().getContentWidth();
final int dockSide = getDockSide(outBounds);
final int dividerPosition = DockedDividerUtils.calculatePositionForBounds(outBounds, dockSide, dividerSize);
final int displayWidth = mDisplayContent.getDisplayInfo().logicalWidth;
final int displayHeight = mDisplayContent.getDisplayInfo().logicalHeight;
// Snap the position to a target.
final int rotation = displayInfo.rotation;
final int orientation = mService.mCurConfiguration.orientation;
mService.mPolicy.getStableInsetsLw(rotation, displayWidth, displayHeight, outBounds);
final DividerSnapAlgorithm algorithm = new DividerSnapAlgorithm(mService.mContext.getResources(), displayWidth, displayHeight, dividerSize, orientation == Configuration.ORIENTATION_PORTRAIT, outBounds);
final SnapTarget target = algorithm.calculateNonDismissingSnapTarget(dividerPosition);
// Recalculate the bounds based on the position of the target.
DockedDividerUtils.calculateBoundsForPosition(target.position, dockSide, outBounds, displayInfo.logicalWidth, displayInfo.logicalHeight, dividerSize);
}
use of com.android.internal.policy.DividerSnapAlgorithm in project android_frameworks_base by ResurrectionRemix.
the class TaskStack method getStackDockedModeBounds.
/**
* Outputs the bounds a stack should be given the presence of a docked stack on the display.
* @param displayRect The bounds of the display the docked stack is on.
* @param outBounds Output bounds that should be used for the stack.
* @param stackId Id of stack we are calculating the bounds for.
* @param dockedBounds Bounds of the docked stack.
* @param dockDividerWidth We need to know the width of the divider make to the output bounds
* close to the side of the dock.
* @param dockOnTopOrLeft If the docked stack is on the top or left side of the screen.
*/
private void getStackDockedModeBounds(Rect displayRect, Rect outBounds, int stackId, Rect dockedBounds, int dockDividerWidth, boolean dockOnTopOrLeft) {
final boolean dockedStack = stackId == DOCKED_STACK_ID;
final boolean splitHorizontally = displayRect.width() > displayRect.height();
outBounds.set(displayRect);
if (dockedStack) {
if (mService.mDockedStackCreateBounds != null) {
outBounds.set(mService.mDockedStackCreateBounds);
return;
}
// The initial bounds of the docked stack when it is created about half the screen space
// and its bounds can be adjusted after that. The bounds of all other stacks are
// adjusted to occupy whatever screen space the docked stack isn't occupying.
final DisplayInfo di = mDisplayContent.getDisplayInfo();
mService.mPolicy.getStableInsetsLw(di.rotation, di.logicalWidth, di.logicalHeight, mTmpRect2);
final int position = new DividerSnapAlgorithm(mService.mContext.getResources(), di.logicalWidth, di.logicalHeight, dockDividerWidth, mService.mCurConfiguration.orientation == ORIENTATION_PORTRAIT, mTmpRect2).getMiddleTarget().position;
if (dockOnTopOrLeft) {
if (splitHorizontally) {
outBounds.right = position;
} else {
outBounds.bottom = position;
}
} else {
if (splitHorizontally) {
outBounds.left = position + dockDividerWidth;
} else {
outBounds.top = position + dockDividerWidth;
}
}
return;
}
// Other stacks occupy whatever space is left by the docked stack.
if (!dockOnTopOrLeft) {
if (splitHorizontally) {
outBounds.right = dockedBounds.left - dockDividerWidth;
} else {
outBounds.bottom = dockedBounds.top - dockDividerWidth;
}
} else {
if (splitHorizontally) {
outBounds.left = dockedBounds.right + dockDividerWidth;
} else {
outBounds.top = dockedBounds.bottom + dockDividerWidth;
}
}
DockedDividerUtils.sanitizeStackBounds(outBounds, !dockOnTopOrLeft);
}
use of com.android.internal.policy.DividerSnapAlgorithm in project android_frameworks_base by ResurrectionRemix.
the class ShortcutKeyDispatcher method handleDockKey.
private void handleDockKey(long shortcutCode) {
try {
int dockSide = mWindowManagerService.getDockedStackSide();
if (dockSide == WindowManager.DOCKED_INVALID) {
// If there is no window docked, we dock the top-most window.
Recents recents = getComponent(Recents.class);
int dockMode = (shortcutCode == SC_DOCK_LEFT) ? ActivityManager.DOCKED_STACK_CREATE_MODE_TOP_OR_LEFT : ActivityManager.DOCKED_STACK_CREATE_MODE_BOTTOM_OR_RIGHT;
recents.dockTopTask(NavigationBarGestureHelper.DRAG_MODE_NONE, dockMode, null, MetricsEvent.WINDOW_DOCK_SHORTCUTS);
} else {
// If there is already a docked window, we respond by resizing the docking pane.
DividerView dividerView = getComponent(Divider.class).getView();
DividerSnapAlgorithm snapAlgorithm = dividerView.getSnapAlgorithm();
int dividerPosition = dividerView.getCurrentPosition();
DividerSnapAlgorithm.SnapTarget currentTarget = snapAlgorithm.calculateNonDismissingSnapTarget(dividerPosition);
int increment = (shortcutCode == SC_DOCK_LEFT) ? -1 : 1;
DividerSnapAlgorithm.SnapTarget target = snapAlgorithm.cycleNonDismissTarget(currentTarget, increment);
dividerView.startDragging(true, /* animate */
false);
dividerView.stopDragging(target.position, 0f, true, /* avoidDismissStart */
true);
}
} catch (RemoteException e) {
Log.e(TAG, "handleDockKey() failed.");
}
}
use of com.android.internal.policy.DividerSnapAlgorithm in project android_frameworks_base by crdroidandroid.
the class TaskStack method getStackDockedModeBounds.
/**
* Outputs the bounds a stack should be given the presence of a docked stack on the display.
* @param displayRect The bounds of the display the docked stack is on.
* @param outBounds Output bounds that should be used for the stack.
* @param stackId Id of stack we are calculating the bounds for.
* @param dockedBounds Bounds of the docked stack.
* @param dockDividerWidth We need to know the width of the divider make to the output bounds
* close to the side of the dock.
* @param dockOnTopOrLeft If the docked stack is on the top or left side of the screen.
*/
private void getStackDockedModeBounds(Rect displayRect, Rect outBounds, int stackId, Rect dockedBounds, int dockDividerWidth, boolean dockOnTopOrLeft) {
final boolean dockedStack = stackId == DOCKED_STACK_ID;
final boolean splitHorizontally = displayRect.width() > displayRect.height();
outBounds.set(displayRect);
if (dockedStack) {
if (mService.mDockedStackCreateBounds != null) {
outBounds.set(mService.mDockedStackCreateBounds);
return;
}
// The initial bounds of the docked stack when it is created about half the screen space
// and its bounds can be adjusted after that. The bounds of all other stacks are
// adjusted to occupy whatever screen space the docked stack isn't occupying.
final DisplayInfo di = mDisplayContent.getDisplayInfo();
mService.mPolicy.getStableInsetsLw(di.rotation, di.logicalWidth, di.logicalHeight, mTmpRect2);
final int position = new DividerSnapAlgorithm(mService.mContext.getResources(), di.logicalWidth, di.logicalHeight, dockDividerWidth, mService.mCurConfiguration.orientation == ORIENTATION_PORTRAIT, mTmpRect2).getMiddleTarget().position;
if (dockOnTopOrLeft) {
if (splitHorizontally) {
outBounds.right = position;
} else {
outBounds.bottom = position;
}
} else {
if (splitHorizontally) {
outBounds.left = position + dockDividerWidth;
} else {
outBounds.top = position + dockDividerWidth;
}
}
return;
}
// Other stacks occupy whatever space is left by the docked stack.
if (!dockOnTopOrLeft) {
if (splitHorizontally) {
outBounds.right = dockedBounds.left - dockDividerWidth;
} else {
outBounds.bottom = dockedBounds.top - dockDividerWidth;
}
} else {
if (splitHorizontally) {
outBounds.left = dockedBounds.right + dockDividerWidth;
} else {
outBounds.top = dockedBounds.bottom + dockDividerWidth;
}
}
DockedDividerUtils.sanitizeStackBounds(outBounds, !dockOnTopOrLeft);
}
Aggregations