Example #1
0
  protected void setLoadPicture() throws UiObjectNotFoundException {
    // 点击更多按钮
    showMore();

    // 选择设置
    UiObject settings = new UiObject(new UiSelector().resourceId("android:id/title").text("设置"));
    settings.clickAndWaitForNewWindow();

    // 选择带宽管理
    UiObject privacy = new UiObject(new UiSelector().resourceId("android:id/title").text("带宽管理"));
    privacy.clickAndWaitForNewWindow();

    // 勾选加载图片
    UiObject list = new UiObject(new UiSelector().className(ListView.class));
    for (int i = 0; i < list.getChildCount(); i++) {
      UiObject ll = list.getChild(new UiSelector().className(LinearLayout.class).index(i));
      UiObject tv = ll.getChild(new UiSelector().className(TextView.class).index(0));
      if (tv.getText().equals("加载图片")) {
        UiObject enable = ll.getChild(new UiSelector().resourceId("android:id/checkbox"));
        if (enable.isCheckable() && !enable.isChecked()) {
          enable.click();
        }
        break;
      }
    }

    // 返回浏览界面
    getUiDevice().pressBack();
    getUiDevice().pressBack();
  }
Example #2
0
 public boolean getBoolAttribute(final String attr)
     throws UiObjectNotFoundException, NoAttributeFoundException {
   boolean res = false;
   if (attr.equals("enabled")) {
     res = el.isEnabled();
   } else if (attr.equals("checkable")) {
     res = el.isCheckable();
   } else if (attr.equals("checked")) {
     res = el.isChecked();
   } else if (attr.equals("clickable")) {
     res = el.isClickable();
   } else if (attr.equals("focusable")) {
     res = el.isFocusable();
   } else if (attr.equals("focused")) {
     res = el.isFocused();
   } else if (attr.equals("longClickable")) {
     res = el.isLongClickable();
   } else if (attr.equals("scrollable")) {
     res = el.isScrollable();
   } else if (attr.equals("selected")) {
     res = el.isSelected();
   } else if (attr.equals("displayed")) {
     res = el.exists();
   } else {
     throw new NoAttributeFoundException(attr);
   }
   return res;
 }