Add android semantics integration test to device lab (#20971)
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
def localProperties = new Properties()
|
||||
def localPropertiesFile = rootProject.file('local.properties')
|
||||
if (localPropertiesFile.exists()) {
|
||||
localPropertiesFile.withInputStream { stream ->
|
||||
localProperties.load(stream)
|
||||
}
|
||||
}
|
||||
|
||||
def flutterRoot = localProperties.getProperty('flutter.sdk')
|
||||
if (flutterRoot == null) {
|
||||
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
|
||||
}
|
||||
|
||||
apply plugin: 'com.android.application'
|
||||
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
|
||||
|
||||
android {
|
||||
compileSdkVersion 27
|
||||
|
||||
lintOptions {
|
||||
disable 'InvalidPackage'
|
||||
}
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 16
|
||||
targetSdkVersion 27
|
||||
versionCode 1
|
||||
versionName "0.0.1"
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
// TODO: Add your own signing config for the release build.
|
||||
// Signing with the debug keys for now, so `flutter run --release` works.
|
||||
signingConfig signingConfigs.debug
|
||||
}
|
||||
}
|
||||
|
||||
aaptOptions {
|
||||
// TODO(goderbauer): remove when https://github.com/flutter/flutter/issues/8986 is resolved.
|
||||
if(System.getenv("FLUTTER_CI_WIN")) {
|
||||
println "AAPT cruncher disabled when running on Win CI."
|
||||
cruncherEnabled false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
flutter {
|
||||
source '../..'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'com.android.support.test:runner:1.0.2'
|
||||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.yourcompany.platforminteraction">
|
||||
|
||||
<!-- The INTERNET permission is required for development. Specifically,
|
||||
flutter needs it to communicate with the running application
|
||||
to allow setting breakpoints, to provide hot reload, etc.
|
||||
-->
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
|
||||
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
|
||||
calls FlutterMain.startInitialization(this); in its onCreate method.
|
||||
In most cases you can leave this as-is, but you if you want to provide
|
||||
additional functionality it is fine to subclass or reimplement
|
||||
FlutterApplication and put your custom class here. -->
|
||||
<application android:name="io.flutter.app.FlutterApplication" android:label="Platform Interaction" android:icon="@mipmap/ic_launcher">
|
||||
<activity android:name="com.yourcompany.platforminteraction.MainActivity"
|
||||
android:launchMode="singleTop"
|
||||
android:theme="@android:style/Theme.Black.NoTitleBar"
|
||||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
|
||||
android:hardwareAccelerated="true"
|
||||
android:windowSoftInputMode="adjustResize">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
</manifest>
|
||||
@@ -0,0 +1,111 @@
|
||||
// Copyright 2018 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
package com.yourcompany.platforminteraction;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.lang.StringBuilder;
|
||||
|
||||
import android.graphics.Rect;
|
||||
import android.os.Bundle;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.WindowManager;
|
||||
import android.content.Context;
|
||||
|
||||
import io.flutter.app.FlutterActivity;
|
||||
import io.flutter.plugin.common.MethodCall;
|
||||
import io.flutter.plugin.common.MethodChannel;
|
||||
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
|
||||
import io.flutter.plugins.GeneratedPluginRegistrant;
|
||||
import io.flutter.view.FlutterView;
|
||||
|
||||
import android.view.accessibility.AccessibilityManager;
|
||||
import android.view.accessibility.AccessibilityNodeProvider;
|
||||
import android.view.accessibility.AccessibilityNodeInfo;
|
||||
|
||||
public class MainActivity extends FlutterActivity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
GeneratedPluginRegistrant.registerWith(this);
|
||||
new MethodChannel(getFlutterView(), "semantics").setMethodCallHandler(new SemanticsTesterMethodHandler());
|
||||
}
|
||||
|
||||
class SemanticsTesterMethodHandler implements MethodCallHandler {
|
||||
Float mScreenDensity = 1.0f;
|
||||
|
||||
@Override
|
||||
public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
|
||||
FlutterView flutterView = getFlutterView();
|
||||
AccessibilityNodeProvider provider = flutterView.getAccessibilityNodeProvider();
|
||||
DisplayMetrics displayMetrics = new DisplayMetrics();
|
||||
WindowManager wm = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
|
||||
wm.getDefaultDisplay().getMetrics(displayMetrics);
|
||||
mScreenDensity = displayMetrics.density;
|
||||
if (methodCall.method.equals("getSemanticsNode")) {
|
||||
Map<String, Object> data = methodCall.arguments();
|
||||
@SuppressWarnings("unchecked")
|
||||
Integer id = (Integer) data.get("id");
|
||||
if (id == null) {
|
||||
result.error("No ID provided", "", null);
|
||||
return;
|
||||
}
|
||||
if (provider == null) {
|
||||
result.error("Semantics not enabled", "", null);
|
||||
return;
|
||||
}
|
||||
AccessibilityNodeInfo node = provider.createAccessibilityNodeInfo(id);
|
||||
result.success(convertSemantics(node, id));
|
||||
return;
|
||||
}
|
||||
result.notImplemented();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map<String, Object> convertSemantics(AccessibilityNodeInfo node, int id) {
|
||||
if (node == null)
|
||||
return null;
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
Map<String, Object> flags = new HashMap<>();
|
||||
Map<String, Object> rect = new HashMap<>();
|
||||
result.put("id", id);
|
||||
result.put("text", node.getText());
|
||||
result.put("contentDescription", node.getContentDescription());
|
||||
flags.put("isChecked", node.isChecked());
|
||||
flags.put("isCheckable", node.isCheckable());
|
||||
flags.put("isDismissable", node.isDismissable());
|
||||
flags.put("isEditable", node.isEditable());
|
||||
flags.put("isEnabled", node.isEnabled());
|
||||
flags.put("isFocusable", node.isFocusable());
|
||||
flags.put("isFocused", node.isFocused());
|
||||
flags.put("isPassword", node.isPassword());
|
||||
flags.put("isLongClickable", node.isLongClickable());
|
||||
result.put("flags", flags);
|
||||
Rect nodeRect = new Rect();
|
||||
node.getBoundsInScreen(nodeRect);
|
||||
rect.put("left", nodeRect.left / mScreenDensity);
|
||||
rect.put("top", nodeRect.top/ mScreenDensity);
|
||||
rect.put("right", nodeRect.right / mScreenDensity);
|
||||
rect.put("bottom", nodeRect.bottom/ mScreenDensity);
|
||||
rect.put("width", nodeRect.width());
|
||||
rect.put("height", nodeRect.height());
|
||||
result.put("rect", rect);
|
||||
result.put("className", node.getClassName());
|
||||
result.put("contentDescription", node.getContentDescription());
|
||||
result.put("liveRegion", node.getLiveRegion());
|
||||
List<AccessibilityNodeInfo.AccessibilityAction> actionList = node.getActionList();
|
||||
if (actionList.size() > 0) {
|
||||
ArrayList<Integer> actions = new ArrayList<>();
|
||||
for (AccessibilityNodeInfo.AccessibilityAction action : actionList) {
|
||||
actions.add(action.getId());
|
||||
}
|
||||
result.put("actions", actions);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 544 B |
Binary file not shown.
|
After Width: | Height: | Size: 442 B |
Binary file not shown.
|
After Width: | Height: | Size: 721 B |
Binary file not shown.
|
After Width: | Height: | Size: 1.0 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
Reference in New Issue
Block a user