1 /* 2 * Copyright (C) 2023 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.dreams.touch; 18 19 import static com.android.systemui.dreams.touch.dagger.ShadeModule.NOTIFICATION_SHADE_GESTURE_INITIATION_HEIGHT; 20 21 import android.graphics.Rect; 22 import android.graphics.Region; 23 import android.view.GestureDetector; 24 import android.view.MotionEvent; 25 26 import com.android.systemui.shade.ShadeViewController; 27 import com.android.systemui.statusbar.phone.CentralSurfaces; 28 29 import java.util.Optional; 30 31 import javax.inject.Inject; 32 import javax.inject.Named; 33 34 /** 35 * {@link ShadeTouchHandler} is responsible for handling swipe down gestures over dream 36 * to bring down the shade. 37 */ 38 public class ShadeTouchHandler implements DreamTouchHandler { 39 private final Optional<CentralSurfaces> mSurfaces; 40 private final ShadeViewController mShadeViewController; 41 private final int mInitiationHeight; 42 43 @Inject ShadeTouchHandler(Optional<CentralSurfaces> centralSurfaces, ShadeViewController shadeViewController, @Named(NOTIFICATION_SHADE_GESTURE_INITIATION_HEIGHT) int initiationHeight)44 ShadeTouchHandler(Optional<CentralSurfaces> centralSurfaces, 45 ShadeViewController shadeViewController, 46 @Named(NOTIFICATION_SHADE_GESTURE_INITIATION_HEIGHT) int initiationHeight) { 47 mSurfaces = centralSurfaces; 48 mShadeViewController = shadeViewController; 49 mInitiationHeight = initiationHeight; 50 } 51 52 @Override onSessionStart(TouchSession session)53 public void onSessionStart(TouchSession session) { 54 if (mSurfaces.map(CentralSurfaces::isBouncerShowing).orElse(false)) { 55 session.pop(); 56 return; 57 } 58 59 session.registerInputListener(ev -> { 60 mShadeViewController.handleExternalTouch((MotionEvent) ev); 61 62 if (ev instanceof MotionEvent) { 63 if (((MotionEvent) ev).getAction() == MotionEvent.ACTION_UP) { 64 session.pop(); 65 } 66 } 67 }); 68 69 session.registerGestureListener(new GestureDetector.SimpleOnGestureListener() { 70 @Override 71 public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, 72 float distanceY) { 73 return true; 74 } 75 76 @Override 77 public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, 78 float velocityY) { 79 return true; 80 } 81 }); 82 } 83 84 @Override getTouchInitiationRegion(Rect bounds, Region region)85 public void getTouchInitiationRegion(Rect bounds, Region region) { 86 final Rect outBounds = new Rect(bounds); 87 outBounds.inset(0, 0, 0, outBounds.height() - mInitiationHeight); 88 region.op(outBounds, Region.Op.UNION); 89 } 90 } 91