blob: fe74677a8d51659d9f665c4a14604f07c4e4087b [file] [log] [blame]
Vinit Nayak9c84ea12020-06-19 17:31:50 -07001/*
2 * Copyright (C) 2019 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.systemui.statusbar.phone;
18
19import android.content.Context;
20import android.graphics.Canvas;
21import android.graphics.RectF;
22import android.view.Surface;
23
24import com.android.systemui.R;
25
26/** Temporarily shown view when using QuickSwitch to switch between apps of different rotations */
27public class QuickswitchOrientedNavHandle extends NavigationHandle {
28 private final int mWidth;
29 private final RectF mTmpBoundsRectF = new RectF();
30 private @Surface.Rotation int mDeltaRotation;
31
32 public QuickswitchOrientedNavHandle(Context context) {
33 super(context);
34 mWidth = context.getResources().getDimensionPixelSize(R.dimen.navigation_home_handle_width);
35 }
36
37 void setDeltaRotation(@Surface.Rotation int rotation) {
38 mDeltaRotation = rotation;
39 }
40
41 @Override
42 protected void onDraw(Canvas canvas) {
43 canvas.drawRoundRect(computeHomeHandleBounds(), mRadius, mRadius, mPaint);
44 }
45
46 RectF computeHomeHandleBounds() {
47 int left;
48 int top;
49 int bottom;
50 int right;
51 int radiusOffset = mRadius * 2;
52 int topStart = getLocationOnScreen()[1];
53
54 switch (mDeltaRotation) {
55 default:
56 case Surface.ROTATION_0:
57 case Surface.ROTATION_180:
58 int height = mRadius * 2;
59 left = getWidth() / 2 - mWidth / 2;
60 top = (getHeight() - mBottom - height);
61 right = getWidth() / 2 + mWidth / 2;
62 bottom = top + height;
63 break;
64 case Surface.ROTATION_90:
65 left = mBottom;
66 right = left + radiusOffset;
67 top = getHeight() / 2 - (mWidth / 2) - (topStart / 2);
68 bottom = top + mWidth;
69 break;
70 case Surface.ROTATION_270:
71 right = getWidth() - mBottom;
72 left = right - radiusOffset;
73 top = getHeight() / 2 - (mWidth / 2) - (topStart / 2);
74 bottom = top + mWidth;
75 break;
76 }
77 mTmpBoundsRectF.set(left, top, right, bottom);
78 return mTmpBoundsRectF;
79 }
80}