在5.0之前的版本中,我们可以在phoneWindowManager里监听key_code_F12键来获取recent键的点击事件,但在如今版本中已经不能这样做了,recent键被单独拿了出来,我们可以在
/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java
中的onRecentsClick(View v) 方法中监听到
private void onRecentsClick(View v) {
if (LatencyTracker.isEnabled(getContext())) {
LatencyTracker.getInstance(getContext()).onActionStart(
LatencyTracker.ACTION_TOGGLE_RECENTS);
}
mStatusBar.awakenDreams();
mCommandQueue.toggleRecentApps();
}
也可以在
SystemUI/src/com/android/systemui/recents/RecentsImpl.java
中的 startRecentsActivity(ActivityOptions opts, final AppTransitionAnimationSpecsFuture future) 方法中做监听
private void startRecentsActivity(ActivityOptions opts,
final AppTransitionAnimationSpecsFuture future) {
Intent intent = new Intent();
intent.setClassName(RECENTS_PACKAGE, RECENTS_ACTIVITY);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
| Intent.FLAG_ACTIVITY_TASK_ON_HOME);
HidePipMenuEvent hideMenuEvent = new HidePipMenuEvent();
hideMenuEvent.addPostAnimationCallback(() -> {
Recents.getSystemServices().startActivityAsUserAsync(intent, opts);
EventBus.getDefault().send(new RecentsActivityStartingEvent());
if (future != null) {
future.composeSpecsSynchronous();
}
});
EventBus.getDefault().send(hideMenuEvent);
// Once we have launched the activity, reset the dummy stack view tasks so we don't hold
// onto references to the same tasks consumed by the activity
mDummyStackView.setTasks(mEmptyTaskStack, false /* notifyStackChanges */);
}
有些手机厂商开发了手势模式,和系统原生走的是完全不同的方法
我们可以在
SystemUI/src/com/android/systemui/statusbar/phone/QuickStepController.java
中的startQuickStep(MotionEvent event)方法中监听到
private void startQuickStep(MotionEvent event) {
mQuickStepStarted = true;
event.transform(mTransformGlobalMatrix);
try {
mOverviewEventSender.getProxy().onQuickStep(event);
if (DEBUG_OVERVIEW_PROXY) {
Log.d(TAG_OPS, "Quick Step Start");
}
} catch (RemoteException e) {
Log.e(TAG, "Failed to send quick step started.", e);
} finally {
event.transform(mTransformLocalMatrix);
}
mOverviewEventSender.notifyQuickStepStarted();
mHandler.removeCallbacksAndMessages(null);
if (mHitTarget != null) {
mHitTarget.abortCurrentGesture();
}
if (mQuickScrubActive) {
animateEnd();
}
}
在手势模式中对home键还做了左右滑动事件的监听,我们同样可以在该类的 startQuickScrub() 中监听到
private void startQuickScrub() {
if (!mQuickScrubActive) {
mQuickScrubActive = true;
mLightTrackColor = mContext.getColor(R.color.quick_step_track_background_light);
mDarkTrackColor = mContext.getColor(R.color.quick_step_track_background_dark);
ObjectAnimator trackAnimator = ObjectAnimator.ofPropertyValuesHolder(this,
PropertyValuesHolder.ofFloat(mTrackAlphaProperty, 1f),
PropertyValuesHolder.ofFloat(mTrackScaleProperty, 1f));
trackAnimator.setInterpolator(ALPHA_IN);
trackAnimator.setDuration(ANIM_IN_DURATION_MS);
ObjectAnimator navBarAnimator = ObjectAnimator.ofFloat(this, mNavBarAlphaProperty, 0f);
navBarAnimator.setInterpolator(ALPHA_OUT);
navBarAnimator.setDuration(ANIM_OUT_DURATION_MS);
mTrackAnimator = new AnimatorSet();
mTrackAnimator.playTogether(trackAnimator, navBarAnimator);
mTrackAnimator.start();
try {
mOverviewEventSender.getProxy().onQuickScrubStart();
if (DEBUG_OVERVIEW_PROXY) {
Log.d(TAG_OPS, "Quick Scrub Start");
}
} catch (RemoteException e) {
Log.e(TAG, "Failed to send start of quick scrub.", e);
}
mOverviewEventSender.notifyQuickScrubStarted();
if (mHitTarget != null) {
mHitTarget.abortCurrentGesture();
}
}
}