aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKevin Jin <kjin@google.com>2013-11-04 16:11:01 -0800
committerKevin Jin <kjin@google.com>2013-11-04 16:11:01 -0800
commit07401c162d1957a497ab08937f1188cc602f29c6 (patch)
tree241553b448da6122af21215569082f7c67031175 /src
parentdfc316e1bfb37148c50947c46f5aaed5cb2e708a (diff)
downloaddroiddriver-07401c162d1957a497ab08937f1188cc602f29c6.tar.gz
Adjust the screenshot origin if the root view is not at (0,0).
Move comments on immutable UiElement attributes to the ctors. Change-Id: I3936c11342511c0d843a5096e954d8f754f8e931
Diffstat (limited to 'src')
-rw-r--r--src/com/google/android/droiddriver/instrumentation/InstrumentationDriver.java22
-rw-r--r--src/com/google/android/droiddriver/instrumentation/ViewElement.java12
-rw-r--r--src/com/google/android/droiddriver/uiautomation/UiAutomationElement.java14
3 files changed, 36 insertions, 12 deletions
diff --git a/src/com/google/android/droiddriver/instrumentation/InstrumentationDriver.java b/src/com/google/android/droiddriver/instrumentation/InstrumentationDriver.java
index dbe9789..11cf461 100644
--- a/src/com/google/android/droiddriver/instrumentation/InstrumentationDriver.java
+++ b/src/com/google/android/droiddriver/instrumentation/InstrumentationDriver.java
@@ -19,6 +19,12 @@ package com.google.android.droiddriver.instrumentation;
import android.app.Activity;
import android.app.Instrumentation;
import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Matrix;
+import android.graphics.Paint;
+import android.graphics.Rect;
+import android.graphics.RectF;
+import android.graphics.Bitmap.Config;
import android.os.SystemClock;
import android.util.Log;
import android.view.View;
@@ -99,7 +105,21 @@ public class InstrumentationDriver extends BaseDroidDriver {
try {
rootView.destroyDrawingCache();
rootView.buildDrawingCache(false);
- screenshot = Bitmap.createBitmap(rootView.getDrawingCache());
+ Bitmap drawingCache = rootView.getDrawingCache();
+ int[] xy = new int[2];
+ rootView.getLocationOnScreen(xy);
+ if (xy[0] == 0 && xy[1] == 0) {
+ screenshot = Bitmap.createBitmap(drawingCache);
+ } else {
+ Canvas canvas = new Canvas();
+ Rect rect = new Rect(0, 0, drawingCache.getWidth(), drawingCache.getHeight());
+ rect.offset(xy[0], xy[1]);
+ screenshot =
+ Bitmap.createBitmap(rect.width() + xy[0], rect.height() + xy[1], Config.ARGB_8888);
+ canvas.setBitmap(screenshot);
+ canvas.drawBitmap(drawingCache, null, new RectF(rect), null);
+ canvas.setBitmap(null);
+ }
rootView.destroyDrawingCache();
} catch (Throwable e) {
Logs.log(Log.ERROR, e);
diff --git a/src/com/google/android/droiddriver/instrumentation/ViewElement.java b/src/com/google/android/droiddriver/instrumentation/ViewElement.java
index c4aecc1..186681f 100644
--- a/src/com/google/android/droiddriver/instrumentation/ViewElement.java
+++ b/src/com/google/android/droiddriver/instrumentation/ViewElement.java
@@ -41,11 +41,7 @@ import java.util.List;
import java.util.Map;
/**
- * A UiElement that is backed by a View. A snapshot of all attributes is taken
- * at construction. The attributes of a {@code ViewElement} instance are
- * immutable. If the underlying view is updated, a new {@code ViewElement}
- * instance will be created in
- * {@link com.google.android.droiddriver.DroidDriver#refreshUiElementTree}.
+ * A UiElement that is backed by a View.
*/
public class ViewElement extends BaseUiElement {
private static class SnapshotViewAttributesRunnable implements Runnable {
@@ -205,6 +201,12 @@ public class ViewElement extends BaseUiElement {
private final ViewElement parent;
private final List<ViewElement> children;
+ /**
+ * A snapshot of all attributes is taken at construction. The attributes of a
+ * {@code ViewElement} instance are immutable. If the underlying view is
+ * updated, a new {@code ViewElement} instance will be created in
+ * {@link com.google.android.droiddriver.DroidDriver#refreshUiElementTree}.
+ */
public ViewElement(final InstrumentationContext context, View view, ViewElement parent) {
this.context = Preconditions.checkNotNull(context);
Preconditions.checkNotNull(view);
diff --git a/src/com/google/android/droiddriver/uiautomation/UiAutomationElement.java b/src/com/google/android/droiddriver/uiautomation/UiAutomationElement.java
index 7c4b5e8..f80f33d 100644
--- a/src/com/google/android/droiddriver/uiautomation/UiAutomationElement.java
+++ b/src/com/google/android/droiddriver/uiautomation/UiAutomationElement.java
@@ -40,12 +40,7 @@ import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeoutException;
/**
- * A UiElement that is backed by an {@link AccessibilityNodeInfo}. A snapshot of
- * all attributes is taken at construction. The attributes of a
- * {@code UiAutomationElement} instance are immutable. If the underlying
- * {@link AccessibilityNodeInfo} is updated, a new {@code UiAutomationElement}
- * instance will be created in
- * {@link com.google.android.droiddriver.DroidDriver#refreshUiElementTree}.
+ * A UiElement that is backed by an {@link AccessibilityNodeInfo}.
*/
public class UiAutomationElement extends BaseUiElement {
private static final AccessibilityEventFilter ANY_EVENT_FILTER = new AccessibilityEventFilter() {
@@ -62,6 +57,13 @@ public class UiAutomationElement extends BaseUiElement {
private final UiAutomationElement parent;
private final List<UiAutomationElement> children;
+ /**
+ * A snapshot of all attributes is taken at construction. The attributes of a
+ * {@code UiAutomationElement} instance are immutable. If the underlying
+ * {@link AccessibilityNodeInfo} is updated, a new {@code UiAutomationElement}
+ * instance will be created in
+ * {@link com.google.android.droiddriver.DroidDriver#refreshUiElementTree}.
+ */
public UiAutomationElement(UiAutomationContext context, AccessibilityNodeInfo node,
UiAutomationElement parent) {
this.context = Preconditions.checkNotNull(context);