diff --git a/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java b/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java index 969f527cbe63f..caf04ccdd0b55 100644 --- a/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java +++ b/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java @@ -96,17 +96,30 @@ public void onMethodCall(final MethodCall call, final MethodChannel.Result resul case "touch": onTouch(call, result); return; + case "setDirection": + setDirection(call, result); + return; } result.notImplemented(); } - @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) + @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) private void createPlatformView(MethodCall call, MethodChannel.Result result) { Map args = call.arguments(); int id = (int) args.get("id"); String viewType = (String) args.get("viewType"); double logicalWidth = (double) args.get("width"); double logicalHeight = (double) args.get("height"); + int direction = (int) args.get("direction"); + + if (!validateDirection(direction)) { + result.error( + "error", + "Trying to create a view with unknown direction value: " + direction + "(view id: " + id + ")", + null + ); + return; + } if (vdControllers.containsKey(id)) { result.error( @@ -147,6 +160,7 @@ private void createPlatformView(MethodCall call, MethodChannel.Result result) { } vdControllers.put(id, vdController); + vdController.getView().setLayoutDirection(direction); // TODO(amirh): copy accessibility nodes to the FlutterView's accessibility tree. @@ -253,6 +267,39 @@ private void onTouch(MethodCall call, MethodChannel.Result result) { result.success(null); } + @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) + private void setDirection(MethodCall call, MethodChannel.Result result) { + Map args = call.arguments(); + int id = (int) args.get("id"); + int direction = (int) args.get("direction"); + + if (!validateDirection(direction)) { + result.error( + "error", + "Trying to set unknown direction value: " + direction + "(view id: " + id + ")", + null + ); + return; + } + + View view = vdControllers.get(id).getView(); + if (view == null) { + result.error( + "error", + "Sending touch to an unknown view with id: " + id, + null + ); + return; + } + + view.setLayoutDirection(direction); + result.success(null); + } + + private static boolean validateDirection(int direction) { + return direction == View.LAYOUT_DIRECTION_LTR || direction == View.LAYOUT_DIRECTION_RTL; + } + @SuppressWarnings("unchecked") private static List parsePointerPropertiesList(Object rawPropertiesList) { List rawProperties = (List) rawPropertiesList;