1 /* 2 * Copyright (C) 2020 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.navigationbar.gestural; 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.res.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 QuickswitchOrientedNavHandle(Context context)32 public QuickswitchOrientedNavHandle(Context context) { 33 super(context); 34 mWidth = context.getResources().getDimensionPixelSize(R.dimen.navigation_home_handle_width); 35 } 36 setDeltaRotation(@urface.Rotation int rotation)37 public void setDeltaRotation(@Surface.Rotation int rotation) { 38 mDeltaRotation = rotation; 39 } 40 41 @Override onDraw(Canvas canvas)42 protected void onDraw(Canvas canvas) { 43 canvas.drawRoundRect(computeHomeHandleBounds(), mRadius, mRadius, mPaint); 44 } 45 computeHomeHandleBounds()46 public RectF computeHomeHandleBounds() { 47 float left; 48 float top; 49 float bottom; 50 float right; 51 float 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 float height = mRadius * 2; 59 left = getWidth() / 2f - mWidth / 2f; 60 top = (getHeight() - mBottom - height); 61 right = getWidth() / 2f + mWidth / 2f; 62 bottom = top + height; 63 break; 64 case Surface.ROTATION_90: 65 left = mBottom; 66 right = left + radiusOffset; 67 top = getHeight() / 2f - (mWidth / 2f) - (topStart / 2f); 68 bottom = top + mWidth; 69 break; 70 case Surface.ROTATION_270: 71 right = getWidth() - mBottom; 72 left = right - radiusOffset; 73 top = getHeight() / 2f - (mWidth / 2f) - (topStart / 2f); 74 bottom = top + mWidth; 75 break; 76 } 77 mTmpBoundsRectF.set(left, top, right, bottom); 78 return mTmpBoundsRectF; 79 } 80 } 81