Vinit Nayak | 9c84ea1 | 2020-06-19 17:31:50 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.systemui.statusbar.phone; |
| 18 | |
| 19 | import android.content.Context; |
| 20 | import android.graphics.Canvas; |
| 21 | import android.graphics.RectF; |
| 22 | import android.view.Surface; |
| 23 | |
| 24 | import com.android.systemui.R; |
| 25 | |
| 26 | /** Temporarily shown view when using QuickSwitch to switch between apps of different rotations */ |
| 27 | public 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 | } |