Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions dev/integration_tests/semantics/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# semantics

Integration test of platform semantics.
56 changes: 56 additions & 0 deletions dev/integration_tests/semantics/android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
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 {
applicationId "com.yourcompany.semantics"
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
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'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.yourcompany.semantics">

<uses-permission android:name="android.permission.INTERNET"/>

<application
android:name="io.flutter.app.FlutterApplication"
android:label="SemanticsIntegrationTest">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package com.yourcompany.semantics;

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());
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to correct these values with the density?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just so the rects will be in the same space as the rects on the SemanticsData. So you could check that a checkbox is 48 by 48

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;
}
}
}
29 changes: 29 additions & 0 deletions dev/integration_tests/semantics/android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
buildscript {
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
}
}

allprojects {
repositories {
google()
jcenter()
}
}

rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
delete rootProject.buildDir
}
1 change: 1 addition & 0 deletions dev/integration_tests/semantics/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.gradle.jvmargs=-Xmx1536M
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Fri Jun 23 08:50:38 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
15 changes: 15 additions & 0 deletions dev/integration_tests/semantics/android/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
include ':app'

def flutterProjectRoot = rootProject.projectDir.parentFile.toPath()

def plugins = new Properties()
def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins')
if (pluginsFile.exists()) {
pluginsFile.withInputStream { stream -> plugins.load(stream) }
}

plugins.each { name, path ->
def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile()
include ":$name"
project(":$name").projectDir = pluginDirectory
}
26 changes: 26 additions & 0 deletions dev/integration_tests/semantics/ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>App</string>
<key>CFBundleIdentifier</key>
<string>io.flutter.flutter.app</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>App</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>8.0</string>
</dict>
</plist>
1 change: 1 addition & 0 deletions dev/integration_tests/semantics/ios/Flutter/Debug.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "Generated.xcconfig"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "Generated.xcconfig"
Loading