DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (31ec81b5d7bb)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
#filter substitution
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package @ANDROID_PACKAGE_NAME@;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.TextSwitcher;
import android.app.Instrumentation;
import com.jayway.android.robotium.solo.Solo;
import java.util.List;

public class FennecNativeElement implements Element {
    private final Activity mActivity;
    private Integer mId;
    private Solo mSolo;
    // max time to wait for thread synchronization
    private static final int MAX_WAIT_MS = 60000;

    public FennecNativeElement(Integer id, Activity activity, Solo solo) {
        mId = id;
        mActivity = activity;
        mSolo = solo;
    }

    public Integer getId() {
        return mId;
    }

    private boolean mClickSuccess;

    public boolean click() {
        mClickSuccess = false;
        RobocopUtils.runOnUiThreadSync(mActivity,
            new Runnable() {
                public void run() {
                    View view = (View)mActivity.findViewById(mId);
                    if (view != null) {
                        if (view.performClick()) {
                            mClickSuccess = true;
                        } else {
                            FennecNativeDriver.log(FennecNativeDriver.LogLevel.WARN,
                                "Robocop called click on an element with no listener");
                        }
                    } else {
                        FennecNativeDriver.log(FennecNativeDriver.LogLevel.ERROR,
                            "click: unable to find view "+mId);
                    }
                }
            });
        return mClickSuccess;
    }

    private Object mText;

    public String getText() {
        mText = null;
        RobocopUtils.runOnUiThreadSync(mActivity,
            new Runnable() {
                public void run() {
                    View v = mActivity.findViewById(mId);
                    if (v instanceof EditText) {
                        EditText et = (EditText)v;
                        mText = et.getEditableText();
                    } else if (v instanceof TextSwitcher) {
                        TextSwitcher ts = (TextSwitcher)v;
                        ts.getNextView();
                        mText = ((TextView)ts.getCurrentView()).getText();
                    } else if (v instanceof ViewGroup) {
                        ViewGroup vg = (ViewGroup)v;
                        for (int i = 0; i < vg.getChildCount(); i++) {
                            if (vg.getChildAt(i) instanceof TextView) {
                                mText = ((TextView)vg.getChildAt(i)).getText();
                            }
                        }
                    } else if (v instanceof TextView) {
                        mText = ((TextView)v).getText(); 
                    } else if (v == null) {
                        FennecNativeDriver.log(FennecNativeDriver.LogLevel.ERROR,
                            "getText: unable to find view "+mId);
                    } else {
                        FennecNativeDriver.log(FennecNativeDriver.LogLevel.ERROR,
                            "getText: unhandled type for view "+mId);
                    }
                } // end of run() method definition
            } // end of anonymous Runnable object instantiation
        );
        if (mText == null) {
            FennecNativeDriver.log(FennecNativeDriver.LogLevel.WARN,
                "getText: Text is null for view "+mId);
            return null;
        }
        return mText.toString();
    }

    private boolean mDisplayed;

    public boolean isDisplayed() {
        mDisplayed = false;
        RobocopUtils.runOnUiThreadSync(mActivity,
            new Runnable() {
                public void run() {
                    View view = (View)mActivity.findViewById(mId);
                    if (view != null) {
                        mDisplayed = true;
                    }
                }
            });
        return mDisplayed;
    }
}