aboutsummaryrefslogtreecommitdiffstats
path: root/uiautomatorviewer
diff options
context:
space:
mode:
Diffstat (limited to 'uiautomatorviewer')
-rw-r--r--uiautomatorviewer/.classpath12
-rw-r--r--uiautomatorviewer/.gitignore1
-rw-r--r--uiautomatorviewer/.project17
-rw-r--r--uiautomatorviewer/.settings/org.eclipse.jdt.core.prefs98
-rw-r--r--uiautomatorviewer/Android.mk38
-rw-r--r--uiautomatorviewer/MODULE_LICENSE_APACHE20
-rw-r--r--uiautomatorviewer/etc/Android.mk21
-rw-r--r--uiautomatorviewer/etc/manifest.txt2
-rwxr-xr-xuiautomatorviewer/etc/uiautomatorviewer104
-rwxr-xr-xuiautomatorviewer/etc/uiautomatorviewer.bat66
-rw-r--r--uiautomatorviewer/src/com/android/uiautomator/DebugBridge.java76
-rw-r--r--uiautomatorviewer/src/com/android/uiautomator/OpenDialog.java225
-rw-r--r--uiautomatorviewer/src/com/android/uiautomator/UiAutomatorHelper.java196
-rw-r--r--uiautomatorviewer/src/com/android/uiautomator/UiAutomatorModel.java143
-rw-r--r--uiautomatorviewer/src/com/android/uiautomator/UiAutomatorView.java436
-rw-r--r--uiautomatorviewer/src/com/android/uiautomator/UiAutomatorViewer.java108
-rw-r--r--uiautomatorviewer/src/com/android/uiautomator/actions/ExpandAllAction.java42
-rw-r--r--uiautomatorviewer/src/com/android/uiautomator/actions/ImageHelper.java48
-rw-r--r--uiautomatorviewer/src/com/android/uiautomator/actions/OpenFilesAction.java83
-rw-r--r--uiautomatorviewer/src/com/android/uiautomator/actions/ScreenshotAction.java176
-rw-r--r--uiautomatorviewer/src/com/android/uiautomator/actions/ToggleNafAction.java46
-rw-r--r--uiautomatorviewer/src/com/android/uiautomator/tree/AttributePair.java26
-rw-r--r--uiautomatorviewer/src/com/android/uiautomator/tree/BasicTreeNode.java114
-rw-r--r--uiautomatorviewer/src/com/android/uiautomator/tree/BasicTreeNodeContentProvider.java63
-rw-r--r--uiautomatorviewer/src/com/android/uiautomator/tree/RootWindowNode.java52
-rw-r--r--uiautomatorviewer/src/com/android/uiautomator/tree/UiHierarchyXmlLoader.java149
-rw-r--r--uiautomatorviewer/src/com/android/uiautomator/tree/UiNode.java123
-rw-r--r--uiautomatorviewer/src/images/expandall.pngbin268 -> 0 bytes
-rw-r--r--uiautomatorviewer/src/images/open-folder.pngbin383 -> 0 bytes
-rw-r--r--uiautomatorviewer/src/images/screenshot.pngbin1226 -> 0 bytes
-rw-r--r--uiautomatorviewer/src/images/warning.pngbin147 -> 0 bytes
31 files changed, 0 insertions, 2465 deletions
diff --git a/uiautomatorviewer/.classpath b/uiautomatorviewer/.classpath
deleted file mode 100644
index 5da1fab..0000000
--- a/uiautomatorviewer/.classpath
+++ /dev/null
@@ -1,12 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry excluding="images" kind="src" path="src"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
- <classpathentry combineaccessrules="false" kind="src" path="/ddmlib"/>
- <classpathentry kind="var" path="ANDROID_OUT_FRAMEWORK/swt.jar"/>
- <classpathentry kind="var" path="ANDROID_SRC/prebuilts/tools/common/eclipse/org.eclipse.core.commands_3.6.0.I20100512-1500.jar"/>
- <classpathentry kind="var" path="ANDROID_SRC/prebuilts/tools/common/eclipse/org.eclipse.equinox.common_3.6.0.v20100503.jar"/>
- <classpathentry kind="var" path="ANDROID_SRC/prebuilts/tools/common/eclipse/org.eclipse.jface_3.6.2.M20110210-1200.jar"/>
- <classpathentry combineaccessrules="false" kind="src" path="/common"/>
- <classpathentry kind="output" path="bin"/>
-</classpath>
diff --git a/uiautomatorviewer/.gitignore b/uiautomatorviewer/.gitignore
deleted file mode 100644
index ba077a4..0000000
--- a/uiautomatorviewer/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-bin
diff --git a/uiautomatorviewer/.project b/uiautomatorviewer/.project
deleted file mode 100644
index d5a1115..0000000
--- a/uiautomatorviewer/.project
+++ /dev/null
@@ -1,17 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>uiautomatorviewer</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
-</projectDescription>
diff --git a/uiautomatorviewer/.settings/org.eclipse.jdt.core.prefs b/uiautomatorviewer/.settings/org.eclipse.jdt.core.prefs
deleted file mode 100644
index 9dbff07..0000000
--- a/uiautomatorviewer/.settings/org.eclipse.jdt.core.prefs
+++ /dev/null
@@ -1,98 +0,0 @@
-eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
-org.eclipse.jdt.core.compiler.annotation.nonnull=com.android.annotations.NonNull
-org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=com.android.annotations.NonNullByDefault
-org.eclipse.jdt.core.compiler.annotation.nonnullisdefault=disabled
-org.eclipse.jdt.core.compiler.annotation.nullable=com.android.annotations.Nullable
-org.eclipse.jdt.core.compiler.annotation.nullanalysis=enabled
-org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
-org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.6
-org.eclipse.jdt.core.compiler.debug.lineNumber=generate
-org.eclipse.jdt.core.compiler.debug.localVariable=generate
-org.eclipse.jdt.core.compiler.debug.sourceFile=generate
-org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
-org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
-org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
-org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
-org.eclipse.jdt.core.compiler.problem.deadCode=warning
-org.eclipse.jdt.core.compiler.problem.deprecation=warning
-org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
-org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
-org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
-org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore
-org.eclipse.jdt.core.compiler.problem.fallthroughCase=warning
-org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled
-org.eclipse.jdt.core.compiler.problem.fieldHiding=warning
-org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
-org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
-org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
-org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
-org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=enabled
-org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
-org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning
-org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
-org.eclipse.jdt.core.compiler.problem.localVariableHiding=warning
-org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
-org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore
-org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=warning
-org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled
-org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=warning
-org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=error
-org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
-org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
-org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore
-org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
-org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
-org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
-org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error
-org.eclipse.jdt.core.compiler.problem.nullReference=error
-org.eclipse.jdt.core.compiler.problem.nullSpecInsufficientInfo=warning
-org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error
-org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=ignore
-org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
-org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
-org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=warning
-org.eclipse.jdt.core.compiler.problem.potentialNullReference=warning
-org.eclipse.jdt.core.compiler.problem.potentialNullSpecViolation=error
-org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=warning
-org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
-org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning
-org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore
-org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=ignore
-org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=warning
-org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore
-org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore
-org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
-org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
-org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=enabled
-org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
-org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
-org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
-org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=disabled
-org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
-org.eclipse.jdt.core.compiler.problem.unclosedCloseable=error
-org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
-org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
-org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore
-org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning
-org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
-org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=warning
-org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
-org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
-org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
-org.eclipse.jdt.core.compiler.problem.unusedImport=warning
-org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
-org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
-org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=warning
-org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
-org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
-org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
-org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
-org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
-org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
-org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
-org.eclipse.jdt.core.compiler.source=1.6
diff --git a/uiautomatorviewer/Android.mk b/uiautomatorviewer/Android.mk
deleted file mode 100644
index f4c488a..0000000
--- a/uiautomatorviewer/Android.mk
+++ /dev/null
@@ -1,38 +0,0 @@
-# Copyright (C) 2012 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := $(call all-java-files-under, src)
-LOCAL_JAVA_RESOURCE_DIRS := src
-
-LOCAL_JAR_MANIFEST := etc/manifest.txt
-
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_JAVA_LIBRARIES := \
- swt \
- common \
- ddmlib \
- org.eclipse.jface_3.6.2.M20110210-1200 \
- org.eclipse.core.commands_3.6.0.I20100512-1500 \
- org.eclipse.equinox.common_3.6.0.v20100503
-
-LOCAL_MODULE := uiautomatorviewer
-
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-# Build all sub-directories
-include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/uiautomatorviewer/MODULE_LICENSE_APACHE2 b/uiautomatorviewer/MODULE_LICENSE_APACHE2
deleted file mode 100644
index e69de29..0000000
--- a/uiautomatorviewer/MODULE_LICENSE_APACHE2
+++ /dev/null
diff --git a/uiautomatorviewer/etc/Android.mk b/uiautomatorviewer/etc/Android.mk
deleted file mode 100644
index 55f326d..0000000
--- a/uiautomatorviewer/etc/Android.mk
+++ /dev/null
@@ -1,21 +0,0 @@
-# Copyright (C) 2012 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_PREBUILT_EXECUTABLES := uiautomatorviewer
-include $(BUILD_HOST_PREBUILT)
diff --git a/uiautomatorviewer/etc/manifest.txt b/uiautomatorviewer/etc/manifest.txt
deleted file mode 100644
index 1ca57cc..0000000
--- a/uiautomatorviewer/etc/manifest.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-Main-Class: com.android.uiautomator.UiAutomatorViewer
-Class-Path: org.eclipse.jface_3.6.2.M20110210-1200.jar org.eclipse.core.commands_3.6.0.I20100512-1500.jar org.eclipse.equinox.common_3.6.0.v20100503.jar
diff --git a/uiautomatorviewer/etc/uiautomatorviewer b/uiautomatorviewer/etc/uiautomatorviewer
deleted file mode 100755
index 79faf5a..0000000
--- a/uiautomatorviewer/etc/uiautomatorviewer
+++ /dev/null
@@ -1,104 +0,0 @@
-#!/bin/bash
-#
-# Copyright 2012, The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-# Set up prog to be the path of this script, including following symlinks,
-# and set up progdir to be the fully-qualified pathname of its directory.
-prog="$0"
-while [ -h "${prog}" ]; do
- newProg=`/bin/ls -ld "${prog}"`
- newProg=`expr "${newProg}" : ".* -> \(.*\)$"`
- if expr "x${newProg}" : 'x/' >/dev/null; then
- prog="${newProg}"
- else
- progdir=`dirname "${prog}"`
- prog="${progdir}/${newProg}"
- fi
-done
-oldwd=`pwd`
-progdir=`dirname "${prog}"`
-progname=`basename "${prog}"`
-cd "${progdir}"
-progdir=`pwd`
-prog="${progdir}"/"${progname}"
-cd "${oldwd}"
-
-jarfile=uiautomatorviewer.jar
-frameworkdir="$progdir"
-libdir="$progdir"
-if [ ! -r "$frameworkdir/$jarfile" ]
-then
- frameworkdir=`dirname "$progdir"`/tools/lib
- libdir=`dirname "$progdir"`/tools/lib
-fi
-if [ ! -r "$frameworkdir/$jarfile" ]
-then
- frameworkdir=`dirname "$progdir"`/framework
- libdir=`dirname "$progdir"`/lib
-fi
-if [ ! -r "$frameworkdir/$jarfile" ]
-then
- echo "${progname}: can't find $jarfile"
- exit 1
-fi
-
-javaCmd="java"
-
-os=`uname`
-if [ $os == 'Darwin' ]; then
- javaOpts="-Xmx1600M -XstartOnFirstThread"
-else
- javaOpts="-Xmx1600M"
-fi
-
-if [ `uname` = "Linux" ]; then
- export GDK_NATIVE_WINDOWS=true
-fi
-
-while expr "x$1" : 'x-J' >/dev/null; do
- opt=`expr "x$1" : 'x-J\(.*\)'`
- javaOpts="${javaOpts} -${opt}"
- shift
-done
-
-jarpath="$frameworkdir/$jarfile"
-
-# Figure out the path to the swt.jar for the current architecture.
-# if ANDROID_SWT is defined, then just use this.
-# else, if running in the Android source tree, then look for the correct swt folder in prebuilt
-# else, look for the correct swt folder in the SDK under tools/lib/
-swtpath=""
-if [ -n "$ANDROID_SWT" ]; then
- swtpath="$ANDROID_SWT"
-else
- vmarch=`${javaCmd} -jar "${frameworkdir}"/archquery.jar`
- if [ -n "$ANDROID_BUILD_TOP" ]; then
- osname=`uname -s | tr A-Z a-z`
- swtpath="${ANDROID_BUILD_TOP}/prebuilts/tools/${osname}-${vmarch}/swt"
- else
- swtpath="${frameworkdir}/${vmarch}"
- fi
-fi
-
-# Combine the swtpath and the framework dir path.
-if [ -d "$swtpath" ]; then
- frameworkdir="${swtpath}:${frameworkdir}"
-else
- echo "SWT folder '${swtpath}' does not exist."
- echo "Please export ANDROID_SWT to point to the folder containing swt.jar for your platform."
- exit 1
-fi
-
-exec "${javaCmd}" $javaOpts -Djava.ext.dirs="$frameworkdir" -Dcom.android.uiautomator.bindir="$progdir" -jar "$jarpath" "$@"
diff --git a/uiautomatorviewer/etc/uiautomatorviewer.bat b/uiautomatorviewer/etc/uiautomatorviewer.bat
deleted file mode 100755
index f3f5d47..0000000
--- a/uiautomatorviewer/etc/uiautomatorviewer.bat
+++ /dev/null
@@ -1,66 +0,0 @@
-@echo off
-rem Copyright (C) 2012 The Android Open Source Project
-rem
-rem Licensed under the Apache License, Version 2.0 (the "License");
-rem you may not use this file except in compliance with the License.
-rem You may obtain a copy of the License at
-rem
-rem http://www.apache.org/licenses/LICENSE-2.0
-rem
-rem Unless required by applicable law or agreed to in writing, software
-rem distributed under the License is distributed on an "AS IS" BASIS,
-rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-rem See the License for the specific language governing permissions and
-rem limitations under the License.
-
-rem don't modify the caller's environment
-setlocal
-
-rem Set up prog to be the path of this script, including following symlinks,
-rem and set up progdir to be the fully-qualified pathname of its directory.
-set prog=%~f0
-
-rem Change current directory and drive to where the script is, to avoid
-rem issues with directories containing whitespaces.
-cd /d %~dp0
-
-rem Get the CWD as a full path with short names only (without spaces)
-for %%i in ("%cd%") do set prog_dir=%%~fsi
-
-rem Check we have a valid Java.exe in the path.
-set java_exe=
-call lib\find_java.bat
-if not defined java_exe goto :EOF
-
-set jarfile=uiautomatorviewer.jar
-set frameworkdir=
-
-if exist %frameworkdir%%jarfile% goto JarFileOk
- set frameworkdir=lib\
-
-if exist %frameworkdir%%jarfile% goto JarFileOk
- set frameworkdir=..\framework\
-
-:JarFileOk
-
-set jarpath=%frameworkdir%%jarfile%
-
-if not defined ANDROID_SWT goto QueryArch
- set swt_path=%ANDROID_SWT%
- goto SwtDone
-
-:QueryArch
-
- for /f %%a in ('%java_exe% -jar %frameworkdir%archquery.jar') do set swt_path=%frameworkdir%%%a
-
-:SwtDone
-
-if exist %swt_path% goto SetPath
- echo SWT folder '%swt_path%' does not exist.
- echo Please set ANDROID_SWT to point to the folder containing swt.jar for your platform.
- exit /B
-
-:SetPath
-set javaextdirs=%swt_path%;%frameworkdir%
-
-call %java_exe% -Djava.ext.dirs=%javaextdirs% -Dcom.android.uiautomator.bindir=%prog_dir% -jar %jarpath% %*
diff --git a/uiautomatorviewer/src/com/android/uiautomator/DebugBridge.java b/uiautomatorviewer/src/com/android/uiautomator/DebugBridge.java
deleted file mode 100644
index 89ffb00..0000000
--- a/uiautomatorviewer/src/com/android/uiautomator/DebugBridge.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.uiautomator;
-
-import com.android.SdkConstants;
-import com.android.ddmlib.AndroidDebugBridge;
-import com.android.ddmlib.IDevice;
-
-import java.io.File;
-import java.util.Arrays;
-import java.util.List;
-
-public class DebugBridge {
- private static AndroidDebugBridge sDebugBridge;
-
- private static String getAdbLocation() {
- String toolsDir = System.getProperty("com.android.uiautomator.bindir"); //$NON-NLS-1$
- if (toolsDir == null) {
- return null;
- }
-
- File sdk = new File(toolsDir).getParentFile();
-
- // check if adb is present in platform-tools
- File platformTools = new File(sdk, "platform-tools");
- File adb = new File(platformTools, SdkConstants.FN_ADB);
- if (adb.exists()) {
- return adb.getAbsolutePath();
- }
-
- // check if adb is present in the tools directory
- adb = new File(toolsDir, SdkConstants.FN_ADB);
- if (adb.exists()) {
- return adb.getAbsolutePath();
- }
-
- return null;
- }
-
- public static void init() {
- String adbLocation = getAdbLocation();
- if (adbLocation != null) {
- AndroidDebugBridge.init(false /* debugger support */);
- sDebugBridge = AndroidDebugBridge.createBridge(adbLocation, false);
- }
- }
-
- public static void terminate() {
- if (sDebugBridge != null) {
- sDebugBridge = null;
- AndroidDebugBridge.terminate();
- }
- }
-
- public static boolean isInitialized() {
- return sDebugBridge != null;
- }
-
- public static List<IDevice> getDevices() {
- return Arrays.asList(sDebugBridge.getDevices());
- }
-}
diff --git a/uiautomatorviewer/src/com/android/uiautomator/OpenDialog.java b/uiautomatorviewer/src/com/android/uiautomator/OpenDialog.java
deleted file mode 100644
index 97a437b..0000000
--- a/uiautomatorviewer/src/com/android/uiautomator/OpenDialog.java
+++ /dev/null
@@ -1,225 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.uiautomator;
-
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.FileDialog;
-import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
-
-import java.io.File;
-
-/**
- * Implements a file selection dialog for both screen shot and xml dump file
- *
- * "OK" button won't be enabled unless both files are selected
- * It also has a convenience feature such that if one file has been picked, and the other
- * file path is empty, then selection for the other file will start from the same base folder
- *
- */
-public class OpenDialog extends Dialog {
- private static final int FIXED_TEXT_FIELD_WIDTH = 300;
- private static final int DEFAULT_LAYOUT_SPACING = 10;
- private Text mScreenshotText;
- private Text mXmlText;
- private boolean mFileChanged = false;
- private Button mOkButton;
-
- private static File sScreenshotFile;
- private static File sXmlDumpFile;
-
- /**
- * Create the dialog.
- * @param parentShell
- */
- public OpenDialog(Shell parentShell) {
- super(parentShell);
- setShellStyle(SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
- }
-
- /**
- * Create contents of the dialog.
- * @param parent
- */
- @Override
- protected Control createDialogArea(Composite parent) {
- Composite container = (Composite) super.createDialogArea(parent);
- GridLayout gl_container = new GridLayout(1, false);
- gl_container.verticalSpacing = DEFAULT_LAYOUT_SPACING;
- gl_container.horizontalSpacing = DEFAULT_LAYOUT_SPACING;
- gl_container.marginWidth = DEFAULT_LAYOUT_SPACING;
- gl_container.marginHeight = DEFAULT_LAYOUT_SPACING;
- container.setLayout(gl_container);
-
- Group openScreenshotGroup = new Group(container, SWT.NONE);
- openScreenshotGroup.setLayout(new GridLayout(2, false));
- openScreenshotGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
- openScreenshotGroup.setText("Screenshot");
-
- mScreenshotText = new Text(openScreenshotGroup, SWT.BORDER | SWT.READ_ONLY);
- if (sScreenshotFile != null) {
- mScreenshotText.setText(sScreenshotFile.getAbsolutePath());
- }
- GridData gd_screenShotText = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
- gd_screenShotText.minimumWidth = FIXED_TEXT_FIELD_WIDTH;
- gd_screenShotText.widthHint = FIXED_TEXT_FIELD_WIDTH;
- mScreenshotText.setLayoutData(gd_screenShotText);
-
- Button openScreenshotButton = new Button(openScreenshotGroup, SWT.NONE);
- openScreenshotButton.setText("...");
- openScreenshotButton.addListener(SWT.Selection, new Listener() {
- @Override
- public void handleEvent(Event event) {
- handleOpenScreenshotFile();
- }
- });
-
- Group openXmlGroup = new Group(container, SWT.NONE);
- openXmlGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
- openXmlGroup.setText("UI XML Dump");
- openXmlGroup.setLayout(new GridLayout(2, false));
-
- mXmlText = new Text(openXmlGroup, SWT.BORDER | SWT.READ_ONLY);
- mXmlText.setEditable(false);
- if (sXmlDumpFile != null) {
- mXmlText.setText(sXmlDumpFile.getAbsolutePath());
- }
- GridData gd_xmlText = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
- gd_xmlText.minimumWidth = FIXED_TEXT_FIELD_WIDTH;
- gd_xmlText.widthHint = FIXED_TEXT_FIELD_WIDTH;
- mXmlText.setLayoutData(gd_xmlText);
-
- Button openXmlButton = new Button(openXmlGroup, SWT.NONE);
- openXmlButton.setText("...");
- openXmlButton.addListener(SWT.Selection, new Listener() {
- @Override
- public void handleEvent(Event event) {
- handleOpenXmlDumpFile();
- }
- });
-
- return container;
- }
-
- /**
- * Create contents of the button bar.
- * @param parent
- */
- @Override
- protected void createButtonsForButtonBar(Composite parent) {
- mOkButton = createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
- createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
- updateButtonState();
- }
-
- /**
- * Return the initial size of the dialog.
- */
- @Override
- protected Point getInitialSize() {
- return new Point(368, 233);
- }
-
- @Override
- protected void configureShell(Shell newShell) {
- super.configureShell(newShell);
- newShell.setText("Open UI Dump Files");
- }
-
- private void handleOpenScreenshotFile() {
- FileDialog fd = new FileDialog(getShell(), SWT.OPEN);
- fd.setText("Open Screenshot File");
- File initialFile = sScreenshotFile;
- // if file has never been selected before, try to base initial path on the mXmlDumpFile
- if (initialFile == null && sXmlDumpFile != null && sXmlDumpFile.isFile()) {
- initialFile = sXmlDumpFile.getParentFile();
- }
- if (initialFile != null) {
- if (initialFile.isFile()) {
- fd.setFileName(initialFile.getAbsolutePath());
- } else if (initialFile.isDirectory()) {
- fd.setFilterPath(initialFile.getAbsolutePath());
- }
- }
- String[] filter = {"*.png"};
- fd.setFilterExtensions(filter);
- String selected = fd.open();
- if (selected != null) {
- sScreenshotFile = new File(selected);
- mScreenshotText.setText(selected);
- mFileChanged = true;
- }
- updateButtonState();
- }
-
- private void handleOpenXmlDumpFile() {
- FileDialog fd = new FileDialog(getShell(), SWT.OPEN);
- fd.setText("Open UI Dump XML File");
- File initialFile = sXmlDumpFile;
- // if file has never been selected before, try to base initial path on the mScreenshotFile
- if (initialFile == null && sScreenshotFile != null && sScreenshotFile.isFile()) {
- initialFile = sScreenshotFile.getParentFile();
- }
- if (initialFile != null) {
- if (initialFile.isFile()) {
- fd.setFileName(initialFile.getAbsolutePath());
- } else if (initialFile.isDirectory()) {
- fd.setFilterPath(initialFile.getAbsolutePath());
- }
- }
- String initialPath = mXmlText.getText();
- if (initialPath.isEmpty() && sScreenshotFile != null && sScreenshotFile.isFile()) {
- initialPath = sScreenshotFile.getParentFile().getAbsolutePath();
- }
- String[] filter = {"*.uix"};
- fd.setFilterExtensions(filter);
- String selected = fd.open();
- if (selected != null) {
- sXmlDumpFile = new File(selected);
- mXmlText.setText(selected);
- mFileChanged = true;
- }
- updateButtonState();
- }
-
- private void updateButtonState() {
- mOkButton.setEnabled(sXmlDumpFile != null && sXmlDumpFile.isFile());
- }
-
- public boolean hasFileChanged() {
- return mFileChanged;
- }
-
- public File getScreenshotFile() {
- return sScreenshotFile;
- }
-
- public File getXmlDumpFile() {
- return sXmlDumpFile;
- }
-}
diff --git a/uiautomatorviewer/src/com/android/uiautomator/UiAutomatorHelper.java b/uiautomatorviewer/src/com/android/uiautomator/UiAutomatorHelper.java
deleted file mode 100644
index 8ead9de..0000000
--- a/uiautomatorviewer/src/com/android/uiautomator/UiAutomatorHelper.java
+++ /dev/null
@@ -1,196 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.uiautomator;
-
-import com.android.ddmlib.CollectingOutputReceiver;
-import com.android.ddmlib.IDevice;
-import com.android.ddmlib.RawImage;
-import com.android.ddmlib.SyncService;
-import com.android.uiautomator.tree.BasicTreeNode;
-import com.android.uiautomator.tree.RootWindowNode;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.ImageData;
-import org.eclipse.swt.graphics.ImageLoader;
-import org.eclipse.swt.graphics.PaletteData;
-import org.eclipse.swt.widgets.Display;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
-public class UiAutomatorHelper {
- public static final int UIAUTOMATOR_MIN_API_LEVEL = 16;
-
- private static final String UIAUTOMATOR = "/system/bin/uiautomator"; //$NON-NLS-1$
- private static final String UIAUTOMATOR_DUMP_COMMAND = "dump"; //$NON-NLS-1$
- private static final String UIDUMP_DEVICE_PATH = "/data/local/tmp/uidump.xml"; //$NON-NLS-1$
- private static final int XML_CAPTURE_TIMEOUT_SEC = 40;
-
- private static boolean supportsUiAutomator(IDevice device) {
- String apiLevelString = device.getProperty(IDevice.PROP_BUILD_API_LEVEL);
- int apiLevel;
- try {
- apiLevel = Integer.parseInt(apiLevelString);
- } catch (NumberFormatException e) {
- apiLevel = UIAUTOMATOR_MIN_API_LEVEL;
- }
-
- return apiLevel >= UIAUTOMATOR_MIN_API_LEVEL;
- }
-
- private static void getUiHierarchyFile(IDevice device, File dst, IProgressMonitor monitor) {
- if (monitor == null) {
- monitor = new NullProgressMonitor();
- }
-
- monitor.subTask("Deleting old UI XML snapshot ...");
- String command = "rm " + UIDUMP_DEVICE_PATH;
-
- try {
- CountDownLatch commandCompleteLatch = new CountDownLatch(1);
- device.executeShellCommand(command,
- new CollectingOutputReceiver(commandCompleteLatch));
- commandCompleteLatch.await(5, TimeUnit.SECONDS);
- } catch (Exception e1) {
- // ignore exceptions while deleting stale files
- }
-
- monitor.subTask("Taking UI XML snapshot...");
- command = String.format("%s %s %s", UIAUTOMATOR,
- UIAUTOMATOR_DUMP_COMMAND,
- UIDUMP_DEVICE_PATH);
- CountDownLatch commandCompleteLatch = new CountDownLatch(1);
-
- try {
- device.executeShellCommand(
- command,
- new CollectingOutputReceiver(commandCompleteLatch),
- XML_CAPTURE_TIMEOUT_SEC * 1000);
- commandCompleteLatch.await(XML_CAPTURE_TIMEOUT_SEC, TimeUnit.SECONDS);
-
- monitor.subTask("Pull UI XML snapshot from device...");
- device.getSyncService().pullFile(UIDUMP_DEVICE_PATH,
- dst.getAbsolutePath(), SyncService.getNullProgressMonitor());
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- public static UiAutomatorResult takeSnapshot(IDevice device, IProgressMonitor monitor)
- throws UiAutomatorException {
- if (monitor == null) {
- monitor = new NullProgressMonitor();
- }
-
- monitor.subTask("Checking if device support UI Automator");
- if (!supportsUiAutomator(device)) {
- String msg = "UI Automator requires a device with API Level "
- + UIAUTOMATOR_MIN_API_LEVEL;
- throw new UiAutomatorException(msg, null);
- }
-
- monitor.subTask("Creating temporary files for uiautomator results.");
- File tmpDir = null;
- File xmlDumpFile = null;
- File screenshotFile = null;
- try {
- tmpDir = File.createTempFile("uiautomatorviewer_", "");
- tmpDir.delete();
- if (!tmpDir.mkdirs())
- throw new IOException("Failed to mkdir");
- xmlDumpFile = File.createTempFile("dump_", ".uix", tmpDir);
- screenshotFile = File.createTempFile("screenshot_", ".png", tmpDir);
- } catch (Exception e) {
- String msg = "Error while creating temporary file to save snapshot: "
- + e.getMessage();
- throw new UiAutomatorException(msg, e);
- }
-
- tmpDir.deleteOnExit();
- xmlDumpFile.deleteOnExit();
- screenshotFile.deleteOnExit();
-
- monitor.subTask("Obtaining UI hierarchy");
- try {
- UiAutomatorHelper.getUiHierarchyFile(device, xmlDumpFile, monitor);
- } catch (Exception e) {
- String msg = "Error while obtaining UI hierarchy XML file: " + e.getMessage();
- throw new UiAutomatorException(msg, e);
- }
-
- UiAutomatorModel model;
- try {
- model = new UiAutomatorModel(xmlDumpFile);
- } catch (Exception e) {
- String msg = "Error while parsing UI hierarchy XML file: " + e.getMessage();
- throw new UiAutomatorException(msg, e);
- }
-
- monitor.subTask("Obtaining device screenshot");
- RawImage rawImage;
- try {
- rawImage = device.getScreenshot();
- } catch (Exception e) {
- String msg = "Error taking device screenshot: " + e.getMessage();
- throw new UiAutomatorException(msg, e);
- }
-
- // rotate the screen shot per device rotation
- BasicTreeNode root = model.getXmlRootNode();
- if (root instanceof RootWindowNode) {
- for (int i = 0; i < ((RootWindowNode)root).getRotation(); i++) {
- rawImage = rawImage.getRotated();
- }
- }
- PaletteData palette = new PaletteData(
- rawImage.getRedMask(),
- rawImage.getGreenMask(),
- rawImage.getBlueMask());
- ImageData imageData = new ImageData(rawImage.width, rawImage.height,
- rawImage.bpp, palette, 1, rawImage.data);
- ImageLoader loader = new ImageLoader();
- loader.data = new ImageData[] { imageData };
- loader.save(screenshotFile.getAbsolutePath(), SWT.IMAGE_PNG);
- Image screenshot = new Image(Display.getDefault(), imageData);
-
- return new UiAutomatorResult(xmlDumpFile, model, screenshot);
- }
-
- @SuppressWarnings("serial")
- public static class UiAutomatorException extends Exception {
- public UiAutomatorException(String msg, Throwable t) {
- super(msg, t);
- }
- }
-
- public static class UiAutomatorResult {
- public final File uiHierarchy;
- public final UiAutomatorModel model;
- public final Image screenshot;
-
- public UiAutomatorResult(File uiXml, UiAutomatorModel m, Image s) {
- uiHierarchy = uiXml;
- model = m;
- screenshot = s;
- }
- }
-}
diff --git a/uiautomatorviewer/src/com/android/uiautomator/UiAutomatorModel.java b/uiautomatorviewer/src/com/android/uiautomator/UiAutomatorModel.java
deleted file mode 100644
index c724f8b..0000000
--- a/uiautomatorviewer/src/com/android/uiautomator/UiAutomatorModel.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.uiautomator;
-
-import com.android.uiautomator.tree.BasicTreeNode;
-import com.android.uiautomator.tree.BasicTreeNode.IFindNodeListener;
-import com.android.uiautomator.tree.UiHierarchyXmlLoader;
-import com.android.uiautomator.tree.UiNode;
-
-import org.eclipse.swt.graphics.Rectangle;
-
-import java.io.File;
-import java.util.List;
-
-public class UiAutomatorModel {
- private BasicTreeNode mRootNode;
- private BasicTreeNode mSelectedNode;
- private Rectangle mCurrentDrawingRect;
- private List<Rectangle> mNafNodes;
-
- // determines whether we lookup the leaf UI node on mouse move of screenshot image
- private boolean mExploreMode = true;
-
- private boolean mShowNafNodes = false;
-
- public UiAutomatorModel(File xmlDumpFile) {
- UiHierarchyXmlLoader loader = new UiHierarchyXmlLoader();
- BasicTreeNode rootNode = loader.parseXml(xmlDumpFile.getAbsolutePath());
- if (rootNode == null) {
- System.err.println("null rootnode after parsing.");
- throw new IllegalArgumentException("Invalid ui automator hierarchy file.");
- }
-
- mNafNodes = loader.getNafNodes();
- if (mRootNode != null) {
- mRootNode.clearAllChildren();
- }
-
- mRootNode = rootNode;
- mExploreMode = true;
- }
-
- public BasicTreeNode getXmlRootNode() {
- return mRootNode;
- }
-
- public BasicTreeNode getSelectedNode() {
- return mSelectedNode;
- }
-
- /**
- * change node selection in the Model recalculate the rect to highlight,
- * also notifies the View to refresh accordingly
- *
- * @param node
- */
- public void setSelectedNode(BasicTreeNode node) {
- mSelectedNode = node;
- if (mSelectedNode instanceof UiNode) {
- UiNode uiNode = (UiNode) mSelectedNode;
- mCurrentDrawingRect = new Rectangle(uiNode.x, uiNode.y, uiNode.width, uiNode.height);
- } else {
- mCurrentDrawingRect = null;
- }
- }
-
- public Rectangle getCurrentDrawingRect() {
- return mCurrentDrawingRect;
- }
-
- /**
- * Do a search in tree to find a leaf node or deepest parent node containing the coordinate
- *
- * @param x
- * @param y
- * @return
- */
- public BasicTreeNode updateSelectionForCoordinates(int x, int y) {
- BasicTreeNode node = null;
-
- if (mRootNode != null) {
- MinAreaFindNodeListener listener = new MinAreaFindNodeListener();
- boolean found = mRootNode.findLeafMostNodesAtPoint(x, y, listener);
- if (found && listener.mNode != null && !listener.mNode.equals(mSelectedNode)) {
- node = listener.mNode;
- }
- }
-
- return node;
- }
-
- public boolean isExploreMode() {
- return mExploreMode;
- }
-
- public void toggleExploreMode() {
- mExploreMode = !mExploreMode;
- }
-
- public void setExploreMode(boolean exploreMode) {
- mExploreMode = exploreMode;
- }
-
- private static class MinAreaFindNodeListener implements IFindNodeListener {
- BasicTreeNode mNode = null;
- @Override
- public void onFoundNode(BasicTreeNode node) {
- if (mNode == null) {
- mNode = node;
- } else {
- if ((node.height * node.width) < (mNode.height * mNode.width)) {
- mNode = node;
- }
- }
- }
- }
-
- public List<Rectangle> getNafNodes() {
- return mNafNodes;
- }
-
- public void toggleShowNaf() {
- mShowNafNodes = !mShowNafNodes;
- }
-
- public boolean shouldShowNafNodes() {
- return mShowNafNodes;
- }
-}
diff --git a/uiautomatorviewer/src/com/android/uiautomator/UiAutomatorView.java b/uiautomatorviewer/src/com/android/uiautomator/UiAutomatorView.java
deleted file mode 100644
index c5f3e59..0000000
--- a/uiautomatorviewer/src/com/android/uiautomator/UiAutomatorView.java
+++ /dev/null
@@ -1,436 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.uiautomator;
-
-import com.android.uiautomator.actions.ExpandAllAction;
-import com.android.uiautomator.actions.ToggleNafAction;
-import com.android.uiautomator.tree.AttributePair;
-import com.android.uiautomator.tree.BasicTreeNode;
-import com.android.uiautomator.tree.BasicTreeNodeContentProvider;
-
-import org.eclipse.jface.action.ToolBarManager;
-import org.eclipse.jface.layout.TableColumnLayout;
-import org.eclipse.jface.viewers.ArrayContentProvider;
-import org.eclipse.jface.viewers.CellEditor;
-import org.eclipse.jface.viewers.ColumnLabelProvider;
-import org.eclipse.jface.viewers.ColumnWeightData;
-import org.eclipse.jface.viewers.EditingSupport;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.TableViewerColumn;
-import org.eclipse.jface.viewers.TextCellEditor;
-import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.SashForm;
-import org.eclipse.swt.custom.StackLayout;
-import org.eclipse.swt.events.MouseAdapter;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.MouseMoveListener;
-import org.eclipse.swt.events.PaintEvent;
-import org.eclipse.swt.events.PaintListener;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.ImageData;
-import org.eclipse.swt.graphics.ImageLoader;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.graphics.Transform;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Canvas;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.FileDialog;
-import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableColumn;
-import org.eclipse.swt.widgets.Tree;
-
-import java.io.File;
-
-public class UiAutomatorView extends Composite {
- private static final int IMG_BORDER = 2;
-
- // The screenshot area is made of a stack layout of two components: screenshot canvas and
- // a "specify screenshot" button. If a screenshot is already available, then that is displayed
- // on the canvas. If it is not availble, then the "specify screenshot" button is displayed.
- private Composite mScreenshotComposite;
- private StackLayout mStackLayout;
- private Composite mSetScreenshotComposite;
- private Canvas mScreenshotCanvas;
-
- private TreeViewer mTreeViewer;
- private TableViewer mTableViewer;
-
- private float mScale = 1.0f;
- private int mDx, mDy;
-
- private UiAutomatorModel mModel;
- private File mModelFile;
- private Image mScreenshot;
-
- public UiAutomatorView(Composite parent, int style) {
- super(parent, SWT.NONE);
- setLayout(new FillLayout());
-
- SashForm baseSash = new SashForm(this, SWT.HORIZONTAL);
-
- mScreenshotComposite = new Composite(baseSash, SWT.BORDER);
- mStackLayout = new StackLayout();
- mScreenshotComposite.setLayout(mStackLayout);
-
- // draw the canvas with border, so the divider area for sash form can be highlighted
- mScreenshotCanvas = new Canvas(mScreenshotComposite, SWT.BORDER);
- mStackLayout.topControl = mScreenshotCanvas;
- mScreenshotComposite.layout();
-
- mScreenshotCanvas.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseUp(MouseEvent e) {
- if (mModel != null) {
- mModel.toggleExploreMode();
- redrawScreenshot();
- }
- }
- });
- mScreenshotCanvas.setBackground(
- getShell().getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
- mScreenshotCanvas.addPaintListener(new PaintListener() {
- @Override
- public void paintControl(PaintEvent e) {
- if (mScreenshot != null) {
- updateScreenshotTransformation();
- // shifting the image here, so that there's a border around screen shot
- // this makes highlighting red rectangles on the screen shot edges more visible
- Transform t = new Transform(e.gc.getDevice());
- t.translate(mDx, mDy);
- t.scale(mScale, mScale);
- e.gc.setTransform(t);
- e.gc.drawImage(mScreenshot, 0, 0);
- // this resets the transformation to identity transform, i.e. no change
- // we don't use transformation here because it will cause the line pattern
- // and line width of highlight rect to be scaled, causing to appear to be blurry
- e.gc.setTransform(null);
- if (mModel.shouldShowNafNodes()) {
- // highlight the "Not Accessibility Friendly" nodes
- e.gc.setForeground(e.gc.getDevice().getSystemColor(SWT.COLOR_YELLOW));
- e.gc.setBackground(e.gc.getDevice().getSystemColor(SWT.COLOR_YELLOW));
- for (Rectangle r : mModel.getNafNodes()) {
- e.gc.setAlpha(50);
- e.gc.fillRectangle(mDx + getScaledSize(r.x), mDy + getScaledSize(r.y),
- getScaledSize(r.width), getScaledSize(r.height));
- e.gc.setAlpha(255);
- e.gc.setLineStyle(SWT.LINE_SOLID);
- e.gc.setLineWidth(2);
- e.gc.drawRectangle(mDx + getScaledSize(r.x), mDy + getScaledSize(r.y),
- getScaledSize(r.width), getScaledSize(r.height));
- }
- }
- // draw the mouseover rects
- Rectangle rect = mModel.getCurrentDrawingRect();
- if (rect != null) {
- e.gc.setForeground(e.gc.getDevice().getSystemColor(SWT.COLOR_RED));
- if (mModel.isExploreMode()) {
- // when we highlight nodes dynamically on mouse move,
- // use dashed borders
- e.gc.setLineStyle(SWT.LINE_DASH);
- e.gc.setLineWidth(1);
- } else {
- // when highlighting nodes on tree node selection,
- // use solid borders
- e.gc.setLineStyle(SWT.LINE_SOLID);
- e.gc.setLineWidth(2);
- }
- e.gc.drawRectangle(mDx + getScaledSize(rect.x), mDy + getScaledSize(rect.y),
- getScaledSize(rect.width), getScaledSize(rect.height));
- }
- }
- }
- });
- mScreenshotCanvas.addMouseMoveListener(new MouseMoveListener() {
- @Override
- public void mouseMove(MouseEvent e) {
- if (mModel != null && mModel.isExploreMode()) {
- BasicTreeNode node = mModel.updateSelectionForCoordinates(
- getInverseScaledSize(e.x - mDx),
- getInverseScaledSize(e.y - mDy));
- if (node != null) {
- updateTreeSelection(node);
- }
- }
- }
- });
-
- mSetScreenshotComposite = new Composite(mScreenshotComposite, SWT.NONE);
- mSetScreenshotComposite.setLayout(new GridLayout());
-
- final Button setScreenshotButton = new Button(mSetScreenshotComposite, SWT.PUSH);
- setScreenshotButton.setText("Specify Screenshot...");
- setScreenshotButton.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent arg0) {
- FileDialog fd = new FileDialog(setScreenshotButton.getShell());
- fd.setFilterExtensions(new String[] { "*.png" });
- if (mModelFile != null) {
- fd.setFilterPath(mModelFile.getParent());
- }
- String screenshotPath = fd.open();
- if (screenshotPath == null) {
- return;
- }
-
- ImageData[] data;
- try {
- data = new ImageLoader().load(screenshotPath);
- } catch (Exception e) {
- return;
- }
-
- // "data" is an array, probably used to handle images that has multiple frames
- // i.e. gifs or icons, we just care if it has at least one here
- if (data.length < 1) {
- return;
- }
-
- mScreenshot = new Image(Display.getDefault(), data[0]);
- redrawScreenshot();
- }
- });
-
-
- // right sash is split into 2 parts: upper-right and lower-right
- // both are composites with borders, so that the horizontal divider can be highlighted by
- // the borders
- SashForm rightSash = new SashForm(baseSash, SWT.VERTICAL);
-
- // upper-right base contains the toolbar and the tree
- Composite upperRightBase = new Composite(rightSash, SWT.BORDER);
- upperRightBase.setLayout(new GridLayout(1, false));
-
- ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
- toolBarManager.add(new ExpandAllAction(this));
- toolBarManager.add(new ToggleNafAction(this));
- toolBarManager.createControl(upperRightBase);
-
- mTreeViewer = new TreeViewer(upperRightBase, SWT.NONE);
- mTreeViewer.setContentProvider(new BasicTreeNodeContentProvider());
- // default LabelProvider uses toString() to generate text to display
- mTreeViewer.setLabelProvider(new LabelProvider());
- mTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
- @Override
- public void selectionChanged(SelectionChangedEvent event) {
- BasicTreeNode selectedNode = null;
- if (event.getSelection() instanceof IStructuredSelection) {
- IStructuredSelection selection = (IStructuredSelection) event.getSelection();
- Object o = selection.getFirstElement();
- if (o instanceof BasicTreeNode) {
- selectedNode = (BasicTreeNode) o;
- }
- }
-
- mModel.setSelectedNode(selectedNode);
- redrawScreenshot();
- if (selectedNode != null) {
- loadAttributeTable();
- }
- }
- });
- Tree tree = mTreeViewer.getTree();
- tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
- // move focus so that it's not on tool bar (looks weird)
- tree.setFocus();
-
- // lower-right base contains the detail group
- Composite lowerRightBase = new Composite(rightSash, SWT.BORDER);
- lowerRightBase.setLayout(new FillLayout());
- Group grpNodeDetail = new Group(lowerRightBase, SWT.NONE);
- grpNodeDetail.setLayout(new FillLayout(SWT.HORIZONTAL));
- grpNodeDetail.setText("Node Detail");
-
- Composite tableContainer = new Composite(grpNodeDetail, SWT.NONE);
-
- TableColumnLayout columnLayout = new TableColumnLayout();
- tableContainer.setLayout(columnLayout);
-
- mTableViewer = new TableViewer(tableContainer, SWT.NONE | SWT.FULL_SELECTION);
- Table table = mTableViewer.getTable();
- table.setLinesVisible(true);
- // use ArrayContentProvider here, it assumes the input to the TableViewer
- // is an array, where each element represents a row in the table
- mTableViewer.setContentProvider(new ArrayContentProvider());
-
- TableViewerColumn tableViewerColumnKey = new TableViewerColumn(mTableViewer, SWT.NONE);
- TableColumn tblclmnKey = tableViewerColumnKey.getColumn();
- tableViewerColumnKey.setLabelProvider(new ColumnLabelProvider() {
- @Override
- public String getText(Object element) {
- if (element instanceof AttributePair) {
- // first column, shows the attribute name
- return ((AttributePair)element).key;
- }
- return super.getText(element);
- }
- });
- columnLayout.setColumnData(tblclmnKey,
- new ColumnWeightData(1, ColumnWeightData.MINIMUM_WIDTH, true));
-
- TableViewerColumn tableViewerColumnValue = new TableViewerColumn(mTableViewer, SWT.NONE);
- tableViewerColumnValue.setEditingSupport(new AttributeTableEditingSupport(mTableViewer));
- TableColumn tblclmnValue = tableViewerColumnValue.getColumn();
- columnLayout.setColumnData(tblclmnValue,
- new ColumnWeightData(2, ColumnWeightData.MINIMUM_WIDTH, true));
- tableViewerColumnValue.setLabelProvider(new ColumnLabelProvider() {
- @Override
- public String getText(Object element) {
- if (element instanceof AttributePair) {
- // second column, shows the attribute value
- return ((AttributePair)element).value;
- }
- return super.getText(element);
- }
- });
- // sets the ratio of the vertical split: left 5 vs right 3
- baseSash.setWeights(new int[]{5, 3});
- }
-
- private int getScaledSize(int size) {
- if (mScale == 1.0f) {
- return size;
- } else {
- return new Double(Math.floor((size * mScale))).intValue();
- }
- }
-
- private int getInverseScaledSize(int size) {
- if (mScale == 1.0f) {
- return size;
- } else {
- return new Double(Math.floor((size / mScale))).intValue();
- }
- }
-
- private void updateScreenshotTransformation() {
- Rectangle canvas = mScreenshotCanvas.getBounds();
- Rectangle image = mScreenshot.getBounds();
- float scaleX = (canvas.width - 2 * IMG_BORDER - 1) / (float)image.width;
- float scaleY = (canvas.height - 2 * IMG_BORDER - 1) / (float)image.height;
- // use the smaller scale here so that we can fit the entire screenshot
- mScale = Math.min(scaleX, scaleY);
- // calculate translation values to center the image on the canvas
- mDx = (canvas.width - getScaledSize(image.width) - IMG_BORDER * 2) / 2 + IMG_BORDER;
- mDy = (canvas.height - getScaledSize(image.height) - IMG_BORDER * 2) / 2 + IMG_BORDER;
- }
-
- private class AttributeTableEditingSupport extends EditingSupport {
-
- private TableViewer mViewer;
-
- public AttributeTableEditingSupport(TableViewer viewer) {
- super(viewer);
- mViewer = viewer;
- }
-
- @Override
- protected boolean canEdit(Object arg0) {
- return true;
- }
-
- @Override
- protected CellEditor getCellEditor(Object arg0) {
- return new TextCellEditor(mViewer.getTable());
- }
-
- @Override
- protected Object getValue(Object o) {
- return ((AttributePair)o).value;
- }
-
- @Override
- protected void setValue(Object arg0, Object arg1) {
- }
- }
-
- /**
- * Causes a redraw of the canvas.
- *
- * The drawing code of canvas will handle highlighted nodes and etc based on data
- * retrieved from Model
- */
- public void redrawScreenshot() {
- if (mScreenshot == null) {
- mStackLayout.topControl = mSetScreenshotComposite;
- } else {
- mStackLayout.topControl = mScreenshotCanvas;
- }
- mScreenshotComposite.layout();
-
- mScreenshotCanvas.redraw();
- }
-
- public void setInputHierarchy(Object input) {
- mTreeViewer.setInput(input);
- }
-
- public void loadAttributeTable() {
- // udpate the lower right corner table to show the attributes of the node
- mTableViewer.setInput(mModel.getSelectedNode().getAttributesArray());
- }
-
- public void expandAll() {
- mTreeViewer.expandAll();
- }
-
- public void updateTreeSelection(BasicTreeNode node) {
- mTreeViewer.setSelection(new StructuredSelection(node), true);
- }
-
- public void setModel(UiAutomatorModel model, File modelBackingFile, Image screenshot) {
- mModel = model;
- mModelFile = modelBackingFile;
-
- if (mScreenshot != null) {
- mScreenshot.dispose();
- }
- mScreenshot = screenshot;
-
- redrawScreenshot();
- // load xml into tree
- BasicTreeNode wrapper = new BasicTreeNode();
- // putting another root node on top of existing root node
- // because Tree seems to like to hide the root node
- wrapper.addChild(mModel.getXmlRootNode());
- setInputHierarchy(wrapper);
- mTreeViewer.getTree().setFocus();
-
- }
-
- public boolean shouldShowNafNodes() {
- return mModel != null ? mModel.shouldShowNafNodes() : false;
- }
-
- public void toggleShowNaf() {
- if (mModel != null) {
- mModel.toggleShowNaf();
- }
- }
-}
diff --git a/uiautomatorviewer/src/com/android/uiautomator/UiAutomatorViewer.java b/uiautomatorviewer/src/com/android/uiautomator/UiAutomatorViewer.java
deleted file mode 100644
index 37018b4..0000000
--- a/uiautomatorviewer/src/com/android/uiautomator/UiAutomatorViewer.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.uiautomator;
-
-import com.android.uiautomator.actions.OpenFilesAction;
-import com.android.uiautomator.actions.ScreenshotAction;
-
-import org.eclipse.jface.action.ToolBarManager;
-import org.eclipse.jface.window.ApplicationWindow;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.ToolBar;
-
-import java.io.File;
-
-public class UiAutomatorViewer extends ApplicationWindow {
- private UiAutomatorView mUiAutomatorView;
-
- public UiAutomatorViewer() {
- super(null);
- }
-
- @Override
- protected Control createContents(Composite parent) {
- Composite c = new Composite(parent, SWT.BORDER);
-
- GridLayout gridLayout = new GridLayout(1, false);
- gridLayout.marginWidth = 0;
- gridLayout.marginHeight = 0;
- gridLayout.horizontalSpacing = 0;
- gridLayout.verticalSpacing = 0;
- c.setLayout(gridLayout);
-
- GridData gd = new GridData(GridData.FILL_HORIZONTAL);
- c.setLayoutData(gd);
-
- ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
- toolBarManager.add(new OpenFilesAction(this));
- toolBarManager.add(new ScreenshotAction(this));
- ToolBar tb = toolBarManager.createControl(c);
- tb.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
-
- mUiAutomatorView = new UiAutomatorView(c, SWT.BORDER);
- mUiAutomatorView.setLayoutData(new GridData(GridData.FILL_BOTH));
-
- return parent;
- }
-
- public static void main(String args[]) {
- DebugBridge.init();
-
- try {
- UiAutomatorViewer window = new UiAutomatorViewer();
- window.setBlockOnOpen(true);
- window.open();
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- DebugBridge.terminate();
- }
- }
-
- @Override
- protected void configureShell(Shell newShell) {
- super.configureShell(newShell);
- newShell.setText("UI Automator Viewer");
- }
-
- @Override
- protected Point getInitialSize() {
- return new Point(800, 600);
- }
-
- public void setModel(final UiAutomatorModel model, final File modelFile,
- final Image screenshot) {
- if (Display.getDefault().getThread() != Thread.currentThread()) {
- Display.getDefault().syncExec(new Runnable() {
- @Override
- public void run() {
- mUiAutomatorView.setModel(model, modelFile, screenshot);
- }
- });
- } else {
- mUiAutomatorView.setModel(model, modelFile, screenshot);
- }
- }
-}
diff --git a/uiautomatorviewer/src/com/android/uiautomator/actions/ExpandAllAction.java b/uiautomatorviewer/src/com/android/uiautomator/actions/ExpandAllAction.java
deleted file mode 100644
index a37539b..0000000
--- a/uiautomatorviewer/src/com/android/uiautomator/actions/ExpandAllAction.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.uiautomator.actions;
-
-import com.android.uiautomator.UiAutomatorView;
-
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.resource.ImageDescriptor;
-
-public class ExpandAllAction extends Action {
-
- UiAutomatorView mView;
-
- public ExpandAllAction(UiAutomatorView view) {
- super("&Expand All");
- mView = view;;
- }
-
- @Override
- public ImageDescriptor getImageDescriptor() {
- return ImageHelper.loadImageDescriptorFromResource("images/expandall.png");
- }
-
- @Override
- public void run() {
- mView.expandAll();
- }
-}
diff --git a/uiautomatorviewer/src/com/android/uiautomator/actions/ImageHelper.java b/uiautomatorviewer/src/com/android/uiautomator/actions/ImageHelper.java
deleted file mode 100644
index 603b226..0000000
--- a/uiautomatorviewer/src/com/android/uiautomator/actions/ImageHelper.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.uiautomator.actions;
-
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.swt.SWTException;
-import org.eclipse.swt.graphics.ImageData;
-import org.eclipse.swt.graphics.ImageLoader;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-public class ImageHelper {
-
- public static ImageDescriptor loadImageDescriptorFromResource(String path) {
- InputStream is = ImageHelper.class.getClassLoader().getResourceAsStream(path);
- if (is != null) {
- ImageData[] data = null;
- try {
- data = new ImageLoader().load(is);
- } catch (SWTException e) {
- } finally {
- try {
- is.close();
- } catch (IOException e) {
- }
- }
- if (data != null && data.length > 0) {
- return ImageDescriptor.createFromImageData(data[0]);
- }
- }
- return null;
- }
-}
diff --git a/uiautomatorviewer/src/com/android/uiautomator/actions/OpenFilesAction.java b/uiautomatorviewer/src/com/android/uiautomator/actions/OpenFilesAction.java
deleted file mode 100644
index 46ee9b6..0000000
--- a/uiautomatorviewer/src/com/android/uiautomator/actions/OpenFilesAction.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.uiautomator.actions;
-
-import com.android.uiautomator.OpenDialog;
-import com.android.uiautomator.UiAutomatorModel;
-import com.android.uiautomator.UiAutomatorViewer;
-
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.ImageData;
-import org.eclipse.swt.graphics.ImageLoader;
-import org.eclipse.swt.widgets.Display;
-
-import java.io.File;
-
-public class OpenFilesAction extends Action {
- private UiAutomatorViewer mViewer;
-
- public OpenFilesAction(UiAutomatorViewer viewer) {
- super("&Open");
-
- mViewer = viewer;
- }
-
- @Override
- public ImageDescriptor getImageDescriptor() {
- return ImageHelper.loadImageDescriptorFromResource("images/open-folder.png");
- }
-
- @Override
- public void run() {
- OpenDialog d = new OpenDialog(Display.getDefault().getActiveShell());
- if (d.open() != OpenDialog.OK) {
- return;
- }
-
- UiAutomatorModel model;
- try {
- model = new UiAutomatorModel(d.getXmlDumpFile());
- } catch (Exception e) {
- // FIXME: show error
- return;
- }
-
- Image img = null;
- File screenshot = d.getScreenshotFile();
- if (screenshot != null) {
- try {
- ImageData[] data = new ImageLoader().load(screenshot.getAbsolutePath());
-
- // "data" is an array, probably used to handle images that has multiple frames
- // i.e. gifs or icons, we just care if it has at least one here
- if (data.length < 1) {
- throw new RuntimeException("Unable to load image: "
- + screenshot.getAbsolutePath());
- }
-
- img = new Image(Display.getDefault(), data[0]);
- } catch (Exception e) {
- // FIXME: show error
- return;
- }
- }
-
- mViewer.setModel(model, d.getXmlDumpFile(), img);
- }
-}
diff --git a/uiautomatorviewer/src/com/android/uiautomator/actions/ScreenshotAction.java b/uiautomatorviewer/src/com/android/uiautomator/actions/ScreenshotAction.java
deleted file mode 100644
index 700b041..0000000
--- a/uiautomatorviewer/src/com/android/uiautomator/actions/ScreenshotAction.java
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.uiautomator.actions;
-
-import com.android.ddmlib.IDevice;
-import com.android.uiautomator.DebugBridge;
-import com.android.uiautomator.UiAutomatorHelper;
-import com.android.uiautomator.UiAutomatorHelper.UiAutomatorException;
-import com.android.uiautomator.UiAutomatorHelper.UiAutomatorResult;
-import com.android.uiautomator.UiAutomatorViewer;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.dialogs.ErrorDialog;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.dialogs.ProgressMonitorDialog;
-import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.window.Window;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Combo;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Shell;
-
-import java.lang.reflect.InvocationTargetException;
-import java.util.List;
-
-public class ScreenshotAction extends Action {
- UiAutomatorViewer mViewer;
-
- public ScreenshotAction(UiAutomatorViewer viewer) {
- super("&Device Screenshot");
- mViewer = viewer;
- }
-
- @Override
- public ImageDescriptor getImageDescriptor() {
- return ImageHelper.loadImageDescriptorFromResource("images/screenshot.png");
- }
-
- @Override
- public void run() {
- if (!DebugBridge.isInitialized()) {
- MessageDialog.openError(mViewer.getShell(),
- "Error obtaining Device Screenshot",
- "Unable to connect to adb. Check if adb is installed correctly.");
- return;
- }
-
- final IDevice device = pickDevice();
- if (device == null) {
- return;
- }
-
- ProgressMonitorDialog dialog = new ProgressMonitorDialog(mViewer.getShell());
- try {
- dialog.run(true, false, new IRunnableWithProgress() {
- @Override
- public void run(IProgressMonitor monitor) throws InvocationTargetException,
- InterruptedException {
- UiAutomatorResult result = null;
- try {
- result = UiAutomatorHelper.takeSnapshot(device, monitor);
- } catch (UiAutomatorException e) {
- monitor.done();
- showError(e.getMessage(), e);
- return;
- }
-
- mViewer.setModel(result.model, result.uiHierarchy, result.screenshot);
- monitor.done();
- }
- });
- } catch (Exception e) {
- showError("Unexpected error while obtaining UI hierarchy", e);
- }
- }
-
- private void showError(final String msg, final Throwable t) {
- mViewer.getShell().getDisplay().syncExec(new Runnable() {
- @Override
- public void run() {
- Status s = new Status(IStatus.ERROR, "Screenshot", msg, t);
- ErrorDialog.openError(
- mViewer.getShell(), "Error", "Error obtaining UI hierarchy", s);
- }
- });
- }
-
- private IDevice pickDevice() {
- List<IDevice> devices = DebugBridge.getDevices();
- if (devices.size() == 0) {
- MessageDialog.openError(mViewer.getShell(),
- "Error obtaining Device Screenshot",
- "No Android devices were detected by adb.");
- return null;
- } else if (devices.size() == 1) {
- return devices.get(0);
- } else {
- DevicePickerDialog dlg = new DevicePickerDialog(mViewer.getShell(), devices);
- if (dlg.open() != Window.OK) {
- return null;
- }
- return dlg.getSelectedDevice();
- }
- }
-
- private static class DevicePickerDialog extends Dialog {
- private final List<IDevice> mDevices;
- private final String[] mDeviceNames;
- private static int sSelectedDeviceIndex;
-
- public DevicePickerDialog(Shell parentShell, List<IDevice> devices) {
- super(parentShell);
-
- mDevices = devices;
- mDeviceNames = new String[mDevices.size()];
- for (int i = 0; i < devices.size(); i++) {
- mDeviceNames[i] = devices.get(i).getName();
- }
- }
-
- @Override
- protected Control createDialogArea(Composite parentShell) {
- Composite parent = (Composite) super.createDialogArea(parentShell);
- Composite c = new Composite(parent, SWT.NONE);
-
- c.setLayout(new GridLayout(2, false));
-
- Label l = new Label(c, SWT.NONE);
- l.setText("Select device: ");
-
- final Combo combo = new Combo(c, SWT.BORDER | SWT.READ_ONLY);
- combo.setItems(mDeviceNames);
- int defaultSelection =
- sSelectedDeviceIndex < mDevices.size() ? sSelectedDeviceIndex : 0;
- combo.select(defaultSelection);
- sSelectedDeviceIndex = defaultSelection;
-
- combo.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent arg0) {
- sSelectedDeviceIndex = combo.getSelectionIndex();
- }
- });
-
- return parent;
- }
-
- public IDevice getSelectedDevice() {
- return mDevices.get(sSelectedDeviceIndex);
- }
- }
-}
diff --git a/uiautomatorviewer/src/com/android/uiautomator/actions/ToggleNafAction.java b/uiautomatorviewer/src/com/android/uiautomator/actions/ToggleNafAction.java
deleted file mode 100644
index fe4cbfa..0000000
--- a/uiautomatorviewer/src/com/android/uiautomator/actions/ToggleNafAction.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.uiautomator.actions;
-
-import com.android.uiautomator.UiAutomatorView;
-
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.resource.ImageDescriptor;
-
-public class ToggleNafAction extends Action {
- private UiAutomatorView mView;
-
- public ToggleNafAction(UiAutomatorView view) {
- super("&Toggle NAF Nodes", IAction.AS_CHECK_BOX);
- setChecked(view.shouldShowNafNodes());
-
- mView = view;
- }
-
- @Override
- public ImageDescriptor getImageDescriptor() {
- return ImageHelper.loadImageDescriptorFromResource("images/warning.png");
- }
-
- @Override
- public void run() {
- mView.toggleShowNaf();
- mView.redrawScreenshot();
- setChecked(mView.shouldShowNafNodes());
- }
-}
diff --git a/uiautomatorviewer/src/com/android/uiautomator/tree/AttributePair.java b/uiautomatorviewer/src/com/android/uiautomator/tree/AttributePair.java
deleted file mode 100644
index ef59544..0000000
--- a/uiautomatorviewer/src/com/android/uiautomator/tree/AttributePair.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.uiautomator.tree;
-
-public class AttributePair {
- public String key, value;
-
- public AttributePair(String key, String value) {
- this.key = key;
- this.value = value;
- }
-}
diff --git a/uiautomatorviewer/src/com/android/uiautomator/tree/BasicTreeNode.java b/uiautomatorviewer/src/com/android/uiautomator/tree/BasicTreeNode.java
deleted file mode 100644
index 99434d1..0000000
--- a/uiautomatorviewer/src/com/android/uiautomator/tree/BasicTreeNode.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.uiautomator.tree;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-public class BasicTreeNode {
-
- private static final BasicTreeNode[] CHILDREN_TEMPLATE = new BasicTreeNode[] {};
-
- protected BasicTreeNode mParent;
-
- protected final List<BasicTreeNode> mChildren = new ArrayList<BasicTreeNode>();
-
- public int x, y, width, height;
-
- // whether the boundary fields are applicable for the node or not
- // RootWindowNode has no bounds, but UiNodes should
- protected boolean mHasBounds = false;
-
- public void addChild(BasicTreeNode child) {
- if (child == null) {
- throw new NullPointerException("Cannot add null child");
- }
- if (mChildren.contains(child)) {
- throw new IllegalArgumentException("node already a child");
- }
- mChildren.add(child);
- child.mParent = this;
- }
-
- public List<BasicTreeNode> getChildrenList() {
- return Collections.unmodifiableList(mChildren);
- }
-
- public BasicTreeNode[] getChildren() {
- return mChildren.toArray(CHILDREN_TEMPLATE);
- }
-
- public BasicTreeNode getParent() {
- return mParent;
- }
-
- public boolean hasChild() {
- return mChildren.size() != 0;
- }
-
- public int getChildCount() {
- return mChildren.size();
- }
-
- public void clearAllChildren() {
- for (BasicTreeNode child : mChildren) {
- child.clearAllChildren();
- }
- mChildren.clear();
- }
-
- /**
- *
- * Find nodes in the tree containing the coordinate
- *
- * The found node should have bounds covering the coordinate, and none of its children's
- * bounds covers it. Depending on the layout, some app may have multiple nodes matching it,
- * the caller must provide a {@link IFindNodeListener} to receive all found nodes
- *
- * @param px
- * @param py
- * @return
- */
- public boolean findLeafMostNodesAtPoint(int px, int py, IFindNodeListener listener) {
- boolean foundInChild = false;
- for (BasicTreeNode node : mChildren) {
- foundInChild |= node.findLeafMostNodesAtPoint(px, py, listener);
- }
- // checked all children, if at least one child covers the point, return directly
- if (foundInChild) return true;
- // check self if the node has no children, or no child nodes covers the point
- if (mHasBounds) {
- if (x <= px && px <= x + width && y <= py && py <= y + height) {
- listener.onFoundNode(this);
- return true;
- } else {
- return false;
- }
- } else {
- return false;
- }
- }
-
- public Object[] getAttributesArray () {
- return null;
- };
-
- public static interface IFindNodeListener {
- void onFoundNode(BasicTreeNode node);
- }
-}
diff --git a/uiautomatorviewer/src/com/android/uiautomator/tree/BasicTreeNodeContentProvider.java b/uiautomatorviewer/src/com/android/uiautomator/tree/BasicTreeNodeContentProvider.java
deleted file mode 100644
index d78ceea..0000000
--- a/uiautomatorviewer/src/com/android/uiautomator/tree/BasicTreeNodeContentProvider.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.uiautomator.tree;
-
-
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.Viewer;
-
-public class BasicTreeNodeContentProvider implements ITreeContentProvider {
-
- private static final Object[] EMPTY_ARRAY = {};
-
- @Override
- public void dispose() {
- }
-
- @Override
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- }
-
- @Override
- public Object[] getElements(Object inputElement) {
- return getChildren(inputElement);
- }
-
- @Override
- public Object[] getChildren(Object parentElement) {
- if (parentElement instanceof BasicTreeNode) {
- return ((BasicTreeNode)parentElement).getChildren();
- }
- return EMPTY_ARRAY;
- }
-
- @Override
- public Object getParent(Object element) {
- if (element instanceof BasicTreeNode) {
- return ((BasicTreeNode)element).getParent();
- }
- return null;
- }
-
- @Override
- public boolean hasChildren(Object element) {
- if (element instanceof BasicTreeNode) {
- return ((BasicTreeNode) element).hasChild();
- }
- return false;
- }
-}
diff --git a/uiautomatorviewer/src/com/android/uiautomator/tree/RootWindowNode.java b/uiautomatorviewer/src/com/android/uiautomator/tree/RootWindowNode.java
deleted file mode 100644
index d0e27c9..0000000
--- a/uiautomatorviewer/src/com/android/uiautomator/tree/RootWindowNode.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.uiautomator.tree;
-
-
-
-public class RootWindowNode extends BasicTreeNode {
-
- private final String mWindowName;
- private Object[] mCachedAttributesArray;
- private int mRotation;
-
- public RootWindowNode(String windowName) {
- this(windowName, 0);
- }
-
- public RootWindowNode(String windowName, int rotation) {
- mWindowName = windowName;
- mRotation = rotation;
- }
-
- @Override
- public String toString() {
- return mWindowName;
- }
-
- @Override
- public Object[] getAttributesArray() {
- if (mCachedAttributesArray == null) {
- mCachedAttributesArray = new Object[]{new AttributePair("window-name", mWindowName)};
- }
- return mCachedAttributesArray;
- }
-
- public int getRotation() {
- return mRotation;
- }
-}
diff --git a/uiautomatorviewer/src/com/android/uiautomator/tree/UiHierarchyXmlLoader.java b/uiautomatorviewer/src/com/android/uiautomator/tree/UiHierarchyXmlLoader.java
deleted file mode 100644
index 2e897d9..0000000
--- a/uiautomatorviewer/src/com/android/uiautomator/tree/UiHierarchyXmlLoader.java
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.uiautomator.tree;
-
-import org.eclipse.swt.graphics.Rectangle;
-import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-import org.xml.sax.helpers.DefaultHandler;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-
-public class UiHierarchyXmlLoader {
-
- private BasicTreeNode mRootNode;
- private List<Rectangle> mNafNodes;
-
- public UiHierarchyXmlLoader() {
- }
-
- /**
- * Uses a SAX parser to process XML dump
- * @param xmlPath
- * @return
- */
- public BasicTreeNode parseXml(String xmlPath) {
- mRootNode = null;
- mNafNodes = new ArrayList<Rectangle>();
- // standard boilerplate to get a SAX parser
- SAXParserFactory factory = SAXParserFactory.newInstance();
- SAXParser parser = null;
- try {
- parser = factory.newSAXParser();
- } catch (ParserConfigurationException e) {
- e.printStackTrace();
- return null;
- } catch (SAXException e) {
- e.printStackTrace();
- return null;
- }
- // handler class for SAX parser to receiver standard parsing events:
- // e.g. on reading "<foo>", startElement is called, on reading "</foo>",
- // endElement is called
- DefaultHandler handler = new DefaultHandler(){
- BasicTreeNode mParentNode;
- BasicTreeNode mWorkingNode;
- @Override
- public void startElement(String uri, String localName, String qName,
- Attributes attributes) throws SAXException {
- boolean nodeCreated = false;
- // starting an element implies that the element that has not yet been closed
- // will be the parent of the element that is being started here
- mParentNode = mWorkingNode;
- if ("hierarchy".equals(qName)) {
- int rotation = 0;
- for (int i = 0; i < attributes.getLength(); i++) {
- if ("rotation".equals(attributes.getQName(i))) {
- try {
- rotation = Integer.parseInt(attributes.getValue(i));
- } catch (NumberFormatException nfe) {
- // do nothing
- }
- }
- }
- mWorkingNode = new RootWindowNode(attributes.getValue("windowName"), rotation);
- nodeCreated = true;
- } else if ("node".equals(qName)) {
- UiNode tmpNode = new UiNode();
- for (int i = 0; i < attributes.getLength(); i++) {
- tmpNode.addAtrribute(attributes.getQName(i), attributes.getValue(i));
- }
- mWorkingNode = tmpNode;
- nodeCreated = true;
- // check if current node is NAF
- String naf = tmpNode.getAttribute("NAF");
- if ("true".equals(naf)) {
- mNafNodes.add(new Rectangle(tmpNode.x, tmpNode.y,
- tmpNode.width, tmpNode.height));
- }
- }
- // nodeCreated will be false if the element started is neither
- // "hierarchy" nor "node"
- if (nodeCreated) {
- if (mRootNode == null) {
- // this will only happen once
- mRootNode = mWorkingNode;
- }
- if (mParentNode != null) {
- mParentNode.addChild(mWorkingNode);
- }
- }
- }
-
- @Override
- public void endElement(String uri, String localName, String qName) throws SAXException {
- //mParentNode should never be null here in a well formed XML
- if (mParentNode != null) {
- // closing an element implies that we are back to working on
- // the parent node of the element just closed, i.e. continue to
- // parse more child nodes
- mWorkingNode = mParentNode;
- mParentNode = mParentNode.getParent();
- }
- }
- };
- try {
- parser.parse(new File(xmlPath), handler);
- } catch (SAXException e) {
- e.printStackTrace();
- return null;
- } catch (IOException e) {
- e.printStackTrace();
- return null;
- }
- return mRootNode;
- }
-
- /**
- * Returns the list of "Not Accessibility Friendly" nodes found during parsing.
- *
- * Call this function after parsing
- *
- * @return
- */
- public List<Rectangle> getNafNodes() {
- return Collections.unmodifiableList(mNafNodes);
- }
-}
diff --git a/uiautomatorviewer/src/com/android/uiautomator/tree/UiNode.java b/uiautomatorviewer/src/com/android/uiautomator/tree/UiNode.java
deleted file mode 100644
index 4adebf4..0000000
--- a/uiautomatorviewer/src/com/android/uiautomator/tree/UiNode.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.uiautomator.tree;
-
-import java.util.Collections;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-public class UiNode extends BasicTreeNode {
- private static final Pattern BOUNDS_PATTERN = Pattern
- .compile("\\[-?(\\d+),-?(\\d+)\\]\\[-?(\\d+),-?(\\d+)\\]");
- // use LinkedHashMap to preserve the order of the attributes
- private final Map<String, String> mAttributes = new LinkedHashMap<String, String>();
- private String mDisplayName = "ShouldNotSeeMe";
- private Object[] mCachedAttributesArray;
-
- public void addAtrribute(String key, String value) {
- mAttributes.put(key, value);
- updateDisplayName();
- if ("bounds".equals(key)) {
- updateBounds(value);
- }
- }
-
- public Map<String, String> getAttributes() {
- return Collections.unmodifiableMap(mAttributes);
- }
-
- /**
- * Builds the display name based on attributes of the node
- */
- private void updateDisplayName() {
- String className = mAttributes.get("class");
- if (className == null)
- return;
- String text = mAttributes.get("text");
- if (text == null)
- return;
- String contentDescription = mAttributes.get("content-desc");
- if (contentDescription == null)
- return;
- String index = mAttributes.get("index");
- if (index == null)
- return;
- String bounds = mAttributes.get("bounds");
- if (bounds == null) {
- return;
- }
- // shorten the standard class names, otherwise it takes up too much space on UI
- className = className.replace("android.widget.", "");
- className = className.replace("android.view.", "");
- StringBuilder builder = new StringBuilder();
- builder.append('(');
- builder.append(index);
- builder.append(") ");
- builder.append(className);
- if (!text.isEmpty()) {
- builder.append(':');
- builder.append(text);
- }
- if (!contentDescription.isEmpty()) {
- builder.append(" {");
- builder.append(contentDescription);
- builder.append('}');
- }
- builder.append(' ');
- builder.append(bounds);
- mDisplayName = builder.toString();
- }
-
- private void updateBounds(String bounds) {
- Matcher m = BOUNDS_PATTERN.matcher(bounds);
- if (m.matches()) {
- x = Integer.parseInt(m.group(1));
- y = Integer.parseInt(m.group(2));
- width = Integer.parseInt(m.group(3)) - x;
- height = Integer.parseInt(m.group(4)) - y;
- mHasBounds = true;
- } else {
- throw new RuntimeException("Invalid bounds: " + bounds);
- }
- }
-
- @Override
- public String toString() {
- return mDisplayName;
- }
-
- public String getAttribute(String key) {
- return mAttributes.get(key);
- }
-
- @Override
- public Object[] getAttributesArray() {
- // this approach means we do not handle the situation where an attribute is added
- // after this function is first called. This is currently not a concern because the
- // tree is supposed to be readonly
- if (mCachedAttributesArray == null) {
- mCachedAttributesArray = new Object[mAttributes.size()];
- int i = 0;
- for (String attr : mAttributes.keySet()) {
- mCachedAttributesArray[i++] = new AttributePair(attr, mAttributes.get(attr));
- }
- }
- return mCachedAttributesArray;
- }
-}
diff --git a/uiautomatorviewer/src/images/expandall.png b/uiautomatorviewer/src/images/expandall.png
deleted file mode 100644
index 7bdf83d..0000000
--- a/uiautomatorviewer/src/images/expandall.png
+++ /dev/null
Binary files differ
diff --git a/uiautomatorviewer/src/images/open-folder.png b/uiautomatorviewer/src/images/open-folder.png
deleted file mode 100644
index 8c4a2e1..0000000
--- a/uiautomatorviewer/src/images/open-folder.png
+++ /dev/null
Binary files differ
diff --git a/uiautomatorviewer/src/images/screenshot.png b/uiautomatorviewer/src/images/screenshot.png
deleted file mode 100644
index 423f781..0000000
--- a/uiautomatorviewer/src/images/screenshot.png
+++ /dev/null
Binary files differ
diff --git a/uiautomatorviewer/src/images/warning.png b/uiautomatorviewer/src/images/warning.png
deleted file mode 100644
index ca3b6ed..0000000
--- a/uiautomatorviewer/src/images/warning.png
+++ /dev/null
Binary files differ