Written before: Android13 supports gesture navigation, which is opened in settings and implemented in SystemUI. The user performs the return function by swiping gestures on the left and right sides of the screen. In fact, SystemUI calls the ready-made judgment method in the Framework. Here is the location of the gesture judgment code. Help Students who need to meet relevant needs
Code location:frameworks/base/services/core/java/com/android/server/wm/DisplayPolicy.java
DisplayPolicy(WindowManagerService service, DisplayContent displayContent) {
mService = service;
mContext = displayContent.isDefaultDisplay ? service.mContext
: service.mContext.createDisplayContext(displayContent.getDisplay());
. . . . . .
. . . . . .
. . . . . .
// TODO(b/181821798) Migrate SystemGesturesPointerEventListener to use window context.
mSystemGestures = new SystemGesturesPointerEventListener(mUiContext, mHandler,
new SystemGesturesPointerEventListener.Callbacks() {
@Override
public void onSwipeFromTop() {
synchronized (mLock) {
final WindowState bar = mStatusBar != null
? mStatusBar
: findAltBarMatchingPosition(ALT_BAR_TOP);
requestTransientBars(bar, true /* isGestureOnSystemBar */);
}
}
@Override
public void onSwipeFromBottom() {
synchronized (mLock) {
final WindowState bar = mNavigationBar != null
&& mNavigationBarPosition == NAV_BAR_BOTTOM
? mNavigationBar
: findAltBarMatchingPosition(ALT_BAR_BOTTOM);
requestTransientBars(bar, true /* isGestureOnSystemBar */);
}
}
@Override
public void onSwipeFromRight() {
final Region excludedRegion = Region.obtain();
synchronized (mLock) {
mDisplayContent.calculateSystemGestureExclusion(
excludedRegion, null /* outUnrestricted */);
requestTransientBarsForSideSwipe(excludedRegion, NAV_BAR_RIGHT,
ALT_BAR_RIGHT);
}
excludedRegion.recycle();
}
@Override
public void onSwipeFromLeft() {
final Region excludedRegion = Region.obtain();
synchronized (mLock) {
mDisplayContent.calculateSystemGestureExclusion(
excludedRegion, null /* outUnrestricted */);
requestTransientBarsForSideSwipe(excludedRegion, NAV_BAR_LEFT,
ALT_BAR_LEFT);
}
+Intent intent = new Intent("onSwipeFromLeft_Action");
+mContext.sendBroadcast(intent);
+Log.d("onSwipeFromLeft"," 收到左侧侧滑");
excludedRegion.recycle();
}
Note: If you want to monitor sliding gestures in the APP, you can directly broadcast and receive them in the above methods onSwipeFromLeft, onSwipeFromRight, onSwipeFromBottom, and onSwipeFromTop. Every time the corresponding gesture slides, it will be called here. It is effective in personal testing. Change it here than in SystemUI. For the change to be effective, gesture navigation must be turned on in SystemUI, which is not required here.
If you add broadcast directly, a non-protected broadcast error will be reported during runtime:
Solution: Add configuration in the following location