diff options
author | Kevin Jin <kjin@google.com> | 2013-03-15 14:51:24 -0700 |
---|---|---|
committer | Kevin Jin <kjin@google.com> | 2013-03-15 14:51:24 -0700 |
commit | 52107c27b6b0f2b0fdfec995784c73746bb95c4e (patch) | |
tree | 2e4928447c041bbfbcea28169c97ada43ef18d91 /src/com/google/android/droiddriver/uiautomation/UiAutomationContext.java | |
parent | cddda72410c992a12db61cef26713b498e31fea4 (diff) | |
download | droiddriver-52107c27b6b0f2b0fdfec995784c73746bb95c4e.tar.gz |
introduce *Context to manage instances and dependency
Change-Id: Ice759c2791a41df1b80dd06b6a339833cb4a7979
Diffstat (limited to 'src/com/google/android/droiddriver/uiautomation/UiAutomationContext.java')
-rw-r--r-- | src/com/google/android/droiddriver/uiautomation/UiAutomationContext.java | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/com/google/android/droiddriver/uiautomation/UiAutomationContext.java b/src/com/google/android/droiddriver/uiautomation/UiAutomationContext.java new file mode 100644 index 0000000..d4dd00f --- /dev/null +++ b/src/com/google/android/droiddriver/uiautomation/UiAutomationContext.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2013 DroidDriver committers + * + * 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.google.android.droiddriver.uiautomation; + +import android.app.UiAutomation; +import android.view.InputEvent; +import android.view.accessibility.AccessibilityNodeInfo; + +import com.google.android.droiddriver.InputInjector; +import com.google.android.droiddriver.util.Logs; +import com.google.common.base.Preconditions; + +/** + * Internal helper for managing all instances. + */ +public class UiAutomationContext { + private final UiAutomation uiAutomation; + private final InputInjector injector; + + UiAutomationContext(UiAutomation uiAutomation) { + this.uiAutomation = Preconditions.checkNotNull(uiAutomation); + injector = new InputInjector() { + @Override + public boolean injectInputEvent(InputEvent event) { + return getUiAutomation().injectInputEvent(event, true /* sync */); + } + }; + } + + public UiAutomation getUiAutomation() { + return uiAutomation; + } + + public InputInjector getInjector() { + return injector; + } + + // TODO: cache by node? + public UiAutomationElement getUiElement(AccessibilityNodeInfo node) { + return Logs.wrap(UiAutomationElement.class, new UiAutomationElement(this, node)); + } +} |