Bumping gaia.json for 2 gaia revision(s) a=gaia-bump
[gecko.git] / build / mobile / robocop / FennecNativeElement.java
blob105c2b7c4b8dfcda31120dcda744dddef468ffc5
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 package org.mozilla.gecko;
7 import android.app.Activity;
8 import android.view.View;
9 import android.view.ViewGroup;
10 import android.widget.EditText;
11 import android.widget.TextSwitcher;
12 import android.widget.TextView;
14 public class FennecNativeElement implements Element {
15 private final Activity mActivity;
16 private final Integer mId;
18 public FennecNativeElement(Integer id, Activity activity) {
19 mId = id;
20 mActivity = activity;
23 @Override
24 public Integer getId() {
25 return mId;
28 private boolean mClickSuccess;
30 @Override
31 public boolean click() {
32 mClickSuccess = false;
33 RobocopUtils.runOnUiThreadSync(mActivity,
34 new Runnable() {
35 @Override
36 public void run() {
37 View view = mActivity.findViewById(mId);
38 if (view != null) {
39 if (view.performClick()) {
40 mClickSuccess = true;
41 } else {
42 FennecNativeDriver.log(FennecNativeDriver.LogLevel.WARN,
43 "Robocop called click on an element with no listener");
45 } else {
46 FennecNativeDriver.log(FennecNativeDriver.LogLevel.ERROR,
47 "click: unable to find view "+mId);
50 });
51 return mClickSuccess;
54 private Object mText;
56 @Override
57 public String getText() {
58 mText = null;
59 RobocopUtils.runOnUiThreadSync(mActivity,
60 new Runnable() {
61 @Override
62 public void run() {
63 View v = mActivity.findViewById(mId);
64 if (v instanceof EditText) {
65 EditText et = (EditText)v;
66 mText = et.getEditableText();
67 } else if (v instanceof TextSwitcher) {
68 TextSwitcher ts = (TextSwitcher)v;
69 ts.getNextView();
70 mText = ((TextView)ts.getCurrentView()).getText();
71 } else if (v instanceof ViewGroup) {
72 ViewGroup vg = (ViewGroup)v;
73 for (int i = 0; i < vg.getChildCount(); i++) {
74 if (vg.getChildAt(i) instanceof TextView) {
75 mText = ((TextView)vg.getChildAt(i)).getText();
78 } else if (v instanceof TextView) {
79 mText = ((TextView)v).getText();
80 } else if (v == null) {
81 FennecNativeDriver.log(FennecNativeDriver.LogLevel.ERROR,
82 "getText: unable to find view "+mId);
83 } else {
84 FennecNativeDriver.log(FennecNativeDriver.LogLevel.ERROR,
85 "getText: unhandled type for view "+mId);
87 } // end of run() method definition
88 } // end of anonymous Runnable object instantiation
90 if (mText == null) {
91 FennecNativeDriver.log(FennecNativeDriver.LogLevel.WARN,
92 "getText: Text is null for view "+mId);
93 return null;
95 return mText.toString();
98 private boolean mDisplayed;
100 @Override
101 public boolean isDisplayed() {
102 mDisplayed = false;
103 RobocopUtils.runOnUiThreadSync(mActivity,
104 new Runnable() {
105 @Override
106 public void run() {
107 View view = mActivity.findViewById(mId);
108 if (view != null) {
109 mDisplayed = true;
113 return mDisplayed;