blob: 25a060e0a0a7149a1b861def6214851c9e72a048 [file] [log] [blame]
Jorim Jaggi737af722015-12-31 10:42:27 +01001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.internal.policy;
18
19import android.graphics.Rect;
20import android.view.WindowManager;
21
22/**
23 * Utility functions for docked stack divider used by both window manager and System UI.
24 *
25 * @hide
26 */
27public class DockedDividerUtils {
28
29 public static void calculateBoundsForPosition(int position, int dockSide, Rect outRect,
30 int displayWidth, int displayHeight, int dividerSize) {
31 outRect.set(0, 0, displayWidth, displayHeight);
32 switch (dockSide) {
33 case WindowManager.DOCKED_LEFT:
34 outRect.right = position;
35 break;
36 case WindowManager.DOCKED_TOP:
37 outRect.bottom = position;
38 break;
39 case WindowManager.DOCKED_RIGHT:
40 outRect.left = position + dividerSize;
41 break;
42 case WindowManager.DOCKED_BOTTOM:
43 outRect.top = position + dividerSize;
44 break;
45 }
46 if (outRect.left > outRect.right) {
47 outRect.left = outRect.right;
48 }
49 if (outRect.top > outRect.bottom) {
50 outRect.top = outRect.bottom;
51 }
52 if (outRect.right < outRect.left) {
53 outRect.right = outRect.left;
54 }
55 if (outRect.bottom < outRect.top) {
56 outRect.bottom = outRect.top;
57 }
58 }
59
60 public static int calculatePositionForBounds(Rect bounds, int dockSide, int dividerSize) {
61 switch (dockSide) {
62 case WindowManager.DOCKED_LEFT:
63 return bounds.right;
64 case WindowManager.DOCKED_TOP:
65 return bounds.bottom;
66 case WindowManager.DOCKED_RIGHT:
67 return bounds.left - dividerSize;
68 case WindowManager.DOCKED_BOTTOM:
69 return bounds.top - dividerSize;
70 default:
71 return 0;
72 }
73 }
74}