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
) {
24 public Integer
getId() {
28 private boolean mClickSuccess
;
31 public boolean click() {
32 mClickSuccess
= false;
33 RobocopUtils
.runOnUiThreadSync(mActivity
,
37 View view
= mActivity
.findViewById(mId
);
39 if (view
.performClick()) {
42 FennecNativeDriver
.log(FennecNativeDriver
.LogLevel
.WARN
,
43 "Robocop called click on an element with no listener");
46 FennecNativeDriver
.log(FennecNativeDriver
.LogLevel
.ERROR
,
47 "click: unable to find view "+mId
);
57 public String
getText() {
59 RobocopUtils
.runOnUiThreadSync(mActivity
,
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
;
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
);
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
91 FennecNativeDriver
.log(FennecNativeDriver
.LogLevel
.WARN
,
92 "getText: Text is null for view "+mId
);
95 return mText
.toString();
98 private boolean mDisplayed
;
101 public boolean isDisplayed() {
103 RobocopUtils
.runOnUiThreadSync(mActivity
,
107 View view
= mActivity
.findViewById(mId
);