Skip to content

Commit a882102

Browse files
[Android KeyEvents] Split AndroidKeyProcessor into separate classes (flutter#25628)
1 parent 1c5d163 commit a882102

File tree

19 files changed

+1167
-933
lines changed

19 files changed

+1167
-933
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,6 @@ FILE: ../../../flutter/shell/platform/android/io/flutter/app/FlutterApplication.
783783
FILE: ../../../flutter/shell/platform/android/io/flutter/app/FlutterFragmentActivity.java
784784
FILE: ../../../flutter/shell/platform/android/io/flutter/app/FlutterPlayStoreSplitApplication.java
785785
FILE: ../../../flutter/shell/platform/android/io/flutter/app/FlutterPluginRegistry.java
786-
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/android/AndroidKeyProcessor.java
787786
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/android/AndroidTouchProcessor.java
788787
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/android/DrawableSplashScreen.java
789788
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/android/ExclusiveAppComponent.java
@@ -799,6 +798,8 @@ FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/android/Flutt
799798
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/android/FlutterSurfaceView.java
800799
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/android/FlutterTextureView.java
801800
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/android/FlutterView.java
801+
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/android/KeyChannelResponder.java
802+
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/android/KeyboardManager.java
802803
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/android/MotionEventTracker.java
803804
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/android/RenderMode.java
804805
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/android/SplashScreen.java

shell/platform/android/BUILD.gn

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ android_java_sources = [
128128
"io/flutter/app/FlutterFragmentActivity.java",
129129
"io/flutter/app/FlutterPlayStoreSplitApplication.java",
130130
"io/flutter/app/FlutterPluginRegistry.java",
131-
"io/flutter/embedding/android/AndroidKeyProcessor.java",
132131
"io/flutter/embedding/android/AndroidTouchProcessor.java",
133132
"io/flutter/embedding/android/DrawableSplashScreen.java",
134133
"io/flutter/embedding/android/ExclusiveAppComponent.java",
@@ -144,6 +143,8 @@ android_java_sources = [
144143
"io/flutter/embedding/android/FlutterSurfaceView.java",
145144
"io/flutter/embedding/android/FlutterTextureView.java",
146145
"io/flutter/embedding/android/FlutterView.java",
146+
"io/flutter/embedding/android/KeyChannelResponder.java",
147+
"io/flutter/embedding/android/KeyboardManager.java",
147148
"io/flutter/embedding/android/MotionEventTracker.java",
148149
"io/flutter/embedding/android/RenderMode.java",
149150
"io/flutter/embedding/android/SplashScreen.java",
@@ -458,13 +459,14 @@ action("robolectric_tests") {
458459
"test/io/flutter/FlutterTestSuite.java",
459460
"test/io/flutter/SmokeTest.java",
460461
"test/io/flutter/TestUtils.java",
461-
"test/io/flutter/embedding/android/AndroidKeyProcessorTest.java",
462462
"test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java",
463463
"test/io/flutter/embedding/android/FlutterActivityTest.java",
464464
"test/io/flutter/embedding/android/FlutterAndroidComponentTest.java",
465465
"test/io/flutter/embedding/android/FlutterFragmentActivityTest.java",
466466
"test/io/flutter/embedding/android/FlutterFragmentTest.java",
467467
"test/io/flutter/embedding/android/FlutterViewTest.java",
468+
"test/io/flutter/embedding/android/KeyChannelResponderTest.java",
469+
"test/io/flutter/embedding/android/KeyboardManagerTest.java",
468470
"test/io/flutter/embedding/android/RobolectricFlutterActivity.java",
469471
"test/io/flutter/embedding/engine/FlutterEngineCacheTest.java",
470472
"test/io/flutter/embedding/engine/FlutterEngineConnectionRegistryTest.java",

shell/platform/android/io/flutter/embedding/android/AndroidKeyProcessor.java

Lines changed: 0 additions & 275 deletions
This file was deleted.

shell/platform/android/io/flutter/embedding/android/FlutterView.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public class FlutterView extends FrameLayout implements MouseCursorPlugin.MouseC
104104
@Nullable private MouseCursorPlugin mouseCursorPlugin;
105105
@Nullable private TextInputPlugin textInputPlugin;
106106
@Nullable private LocalizationPlugin localizationPlugin;
107-
@Nullable private AndroidKeyProcessor androidKeyProcessor;
107+
@Nullable private KeyboardManager keyboardManager;
108108
@Nullable private AndroidTouchProcessor androidTouchProcessor;
109109
@Nullable private AccessibilityBridge accessibilityBridge;
110110

@@ -705,7 +705,7 @@ public InputConnection onCreateInputConnection(@NonNull EditorInfo outAttrs) {
705705
return super.onCreateInputConnection(outAttrs);
706706
}
707707

708-
return textInputPlugin.createInputConnection(this, outAttrs);
708+
return textInputPlugin.createInputConnection(this, keyboardManager, outAttrs);
709709
}
710710

711711
/**
@@ -730,7 +730,7 @@ public boolean checkInputConnectionProxy(View view) {
730730
* D-pad button. It is generally not invoked when a virtual software keyboard is used, though a
731731
* software keyboard may choose to invoke this method in some situations.
732732
*
733-
* <p>{@link KeyEvent}s are sent from Android to Flutter. {@link AndroidKeyProcessor} may do some
733+
* <p>{@link KeyEvent}s are sent from Android to Flutter. {@link KeyboardManager} may do some
734734
* additional work with the given {@link KeyEvent}, e.g., combine this {@code keyCode} with the
735735
* previous {@code keyCode} to generate a unicode combined character.
736736
*/
@@ -747,7 +747,7 @@ public boolean dispatchKeyEvent(KeyEvent event) {
747747
// superclass. The key processor will typically handle all events except
748748
// those where it has re-dispatched the event after receiving a reply from
749749
// the framework that the framework did not handle it.
750-
return (isAttachedToFlutterEngine() && androidKeyProcessor.onKeyEvent(event))
750+
return (isAttachedToFlutterEngine() && keyboardManager.handleEvent(event))
751751
|| super.dispatchKeyEvent(event);
752752
}
753753

@@ -975,8 +975,14 @@ public void attachToFlutterEngine(@NonNull FlutterEngine flutterEngine) {
975975
this.flutterEngine.getTextInputChannel(),
976976
this.flutterEngine.getPlatformViewsController());
977977
localizationPlugin = this.flutterEngine.getLocalizationPlugin();
978-
androidKeyProcessor =
979-
new AndroidKeyProcessor(this, this.flutterEngine.getKeyEventChannel(), textInputPlugin);
978+
979+
keyboardManager =
980+
new KeyboardManager(
981+
this,
982+
textInputPlugin,
983+
new KeyChannelResponder[] {
984+
new KeyChannelResponder(flutterEngine.getKeyEventChannel())
985+
});
980986
androidTouchProcessor =
981987
new AndroidTouchProcessor(this.flutterEngine.getRenderer(), /*trackMotionEvents=*/ false);
982988
accessibilityBridge =
@@ -1060,8 +1066,7 @@ public void detachFromFlutterEngine() {
10601066
// TODO(mattcarroll): once this is proven to work, move this line ot TextInputPlugin
10611067
textInputPlugin.getInputMethodManager().restartInput(this);
10621068
textInputPlugin.destroy();
1063-
1064-
androidKeyProcessor.destroy();
1069+
keyboardManager.destroy();
10651070

10661071
if (mouseCursorPlugin != null) {
10671072
mouseCursorPlugin.destroy();

0 commit comments

Comments
 (0)