This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Android embedding refactor pr3 add remaining systemchannels #7738
Merged
matthew-carroll
merged 6 commits into
flutter:master
from
matthew-carroll:android_embedding_refactor_pr3_add_remaining_systemchannels
Feb 15, 2019
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
227ec13
Switched FlutterView over to use LocalizationChannel.
c6ab42f
Added implementations for AccessibilityChannel, PlatformChannel, and …
3eac93f
Improved PlatformChannel comments.
9d43997
PR Updates.
5ab5835
PR Updates.
b7fcd5b
PR Updates.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
shell/platform/android/io/flutter/embedding/engine/systemchannels/AccessibilityChannel.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| package io.flutter.embedding.engine.systemchannels; | ||
|
|
||
| import android.support.annotation.NonNull; | ||
| import android.support.annotation.Nullable; | ||
|
|
||
| import java.util.HashMap; | ||
|
|
||
| import io.flutter.embedding.engine.dart.DartExecutor; | ||
| import io.flutter.plugin.common.BasicMessageChannel; | ||
| import io.flutter.plugin.common.StandardMessageCodec; | ||
|
|
||
| /** | ||
| * System channel that sends accessibility requests and events from Flutter to Android. | ||
| * <p> | ||
| * See {@link AccessibilityMessageHandler}, which lists all accessibility requests and | ||
| * events that might be sent from Flutter to the Android platform. | ||
| */ | ||
| public class AccessibilityChannel { | ||
| @NonNull | ||
| public BasicMessageChannel<Object> channel; | ||
| @Nullable | ||
| private AccessibilityMessageHandler handler; | ||
|
|
||
| private final BasicMessageChannel.MessageHandler<Object> parsingMessageHandler = new BasicMessageChannel.MessageHandler<Object>() { | ||
| @Override | ||
| public void onMessage(Object message, BasicMessageChannel.Reply<Object> reply) { | ||
| // If there is no handler to respond to this message then we don't need to | ||
| // parse it. Return. | ||
| if (handler == null) { | ||
| return; | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| final HashMap<String, Object> annotatedEvent = (HashMap<String, Object>) message; | ||
| final String type = (String) annotatedEvent.get("type"); | ||
| @SuppressWarnings("unchecked") | ||
| final HashMap<String, Object> data = (HashMap<String, Object>) annotatedEvent.get("data"); | ||
|
|
||
| switch (type) { | ||
| case "announce": | ||
| String announceMessage = (String) data.get("message"); | ||
| if (announceMessage != null) { | ||
| handler.announce(announceMessage); | ||
| } | ||
| break; | ||
| case "tap": { | ||
| Integer nodeId = (Integer) annotatedEvent.get("nodeId"); | ||
| if (nodeId != null) { | ||
| handler.onTap(nodeId); | ||
| } | ||
| break; | ||
| } | ||
| case "longPress": { | ||
| Integer nodeId = (Integer) annotatedEvent.get("nodeId"); | ||
| if (nodeId != null) { | ||
| handler.onLongPress(nodeId); | ||
| } | ||
| break; | ||
| } | ||
| case "tooltip": { | ||
| String tooltipMessage = (String) data.get("message"); | ||
| if (tooltipMessage != null) { | ||
| handler.onTooltip(tooltipMessage); | ||
| } | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| /** | ||
| * Constructs an {@code AccessibilityChannel} that connects Android to the Dart code | ||
| * running in {@code dartExecutor}. | ||
| * | ||
| * The given {@code dartExecutor} is permitted to be idle or executing code. | ||
| * | ||
| * See {@link DartExecutor}. | ||
| */ | ||
| public AccessibilityChannel(@NonNull DartExecutor dartExecutor) { | ||
| channel = new BasicMessageChannel<>(dartExecutor, "flutter/accessibility", StandardMessageCodec.INSTANCE); | ||
| channel.setMessageHandler(parsingMessageHandler); | ||
| } | ||
|
|
||
| /** | ||
| * Sets the {@link AccessibilityMessageHandler} which receives all events and requests | ||
| * that are parsed from the underlying accessibility channel. | ||
| */ | ||
| public void setAccessibilityMessageHandler(@Nullable AccessibilityMessageHandler handler) { | ||
| this.handler = handler; | ||
| } | ||
|
|
||
| /** | ||
| * Handler that receives accessibility messages sent from Flutter to Android | ||
| * through a given {@link AccessibilityChannel}. | ||
| * | ||
| * To register an {@code AccessibilityMessageHandler} with a {@link AccessibilityChannel}, | ||
| * see {@link AccessibilityChannel#setAccessibilityMessageHandler(AccessibilityMessageHandler)}. | ||
| */ | ||
| public interface AccessibilityMessageHandler { | ||
matthew-carroll marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /** | ||
| * The Dart application would like the given {@code message} to be announced. | ||
| */ | ||
| void announce(@NonNull String message); | ||
|
|
||
| /** | ||
| * The user has tapped on the artifact with the given {@code nodeId}. | ||
| */ | ||
| void onTap(int nodeId); | ||
|
|
||
| /** | ||
| * The user has long pressed on the artifact with the given {@code nodeId}. | ||
| */ | ||
| void onLongPress(int nodeId); | ||
|
|
||
| /** | ||
| * The user has opened a popup window, menu, dialog, etc. | ||
| */ | ||
| void onTooltip(@NonNull String message); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.