// TODO: this is not working yet
  public static void main(String[] args) throws IOException, InterruptedException {
    URL backgroundImage = Images.GoogleSearchPage;
    URL dragTargetImage = Images.OSXDockIcon;

    DragDropFrame imageFrame = new DragDropFrame(backgroundImage, dragTargetImage);
    imageFrame.autoClose(10000);

    ScreenRegion s = new DesktopScreenRegion();
    Mouse mouse = new DesktopMouse();

    URL imageURL = Images.OSXDockIcon;
    Target imageTarget = new ImageTarget(imageURL);

    ScreenRegion r = s.wait(imageTarget, 1000);
    mouse.drag(r.getCenter());

    imageURL = Images.GoogleMicrophoneIcon;
    imageTarget = new ImageTarget(imageURL);

    r = s.wait(imageTarget, 1000);
    mouse.drop(r.getCenter());

    ScreenLocation c = mouse.getLocation();
    mouse.drag(c);
    mouse.drop(Relative.to(c).left(200).above(50).getScreenLocation());
  }
예제 #2
0
파일: News.java 프로젝트: 6482/android-app
 public static News parse(InputStream inputStream) throws IOException, AppException {
   News news = null;
   Relative relative = null;
   // 获得XmlPullParser解析器
   XmlPullParser xmlParser = Xml.newPullParser();
   try {
     xmlParser.setInput(inputStream, UTF8);
     // 获得解析到的事件类别,这里有开始文档,结束文档,开始标签,结束标签,文本等等事件。
     int evtType = xmlParser.getEventType();
     // 一直循环,直到文档结束
     while (evtType != XmlPullParser.END_DOCUMENT) {
       String tag = xmlParser.getName();
       switch (evtType) {
         case XmlPullParser.START_TAG:
           if (tag.equalsIgnoreCase(NODE_START)) {
             news = new News();
           } else if (news != null) {
             if (tag.equalsIgnoreCase(NODE_ID)) {
               news.id = StringUtils.toInt(xmlParser.nextText(), 0);
             } else if (tag.equalsIgnoreCase(NODE_TITLE)) {
               news.setTitle(xmlParser.nextText());
             } else if (tag.equalsIgnoreCase(NODE_URL)) {
               news.setUrl(xmlParser.nextText());
             } else if (tag.equalsIgnoreCase(NODE_BODY)) {
               news.setBody(xmlParser.nextText());
             } else if (tag.equalsIgnoreCase(NODE_AUTHOR)) {
               news.setAuthor(xmlParser.nextText());
             } else if (tag.equalsIgnoreCase(NODE_AUTHORID)) {
               news.setAuthorId(StringUtils.toInt(xmlParser.nextText(), 0));
             } else if (tag.equalsIgnoreCase(NODE_COMMENTCOUNT)) {
               news.setCommentCount(StringUtils.toInt(xmlParser.nextText(), 0));
             } else if (tag.equalsIgnoreCase(NODE_PUBDATE)) {
               news.setPubDate(xmlParser.nextText());
             } else if (tag.equalsIgnoreCase(NODE_SOFTWARELINK)) {
               news.setSoftwareLink(xmlParser.nextText());
             } else if (tag.equalsIgnoreCase(NODE_SOFTWARENAME)) {
               news.setSoftwareName(xmlParser.nextText());
             } else if (tag.equalsIgnoreCase(NODE_FAVORITE)) {
               news.setFavorite(StringUtils.toInt(xmlParser.nextText(), 0));
             } else if (tag.equalsIgnoreCase(NODE_TYPE)) {
               news.getNewType().type = StringUtils.toInt(xmlParser.nextText(), 0);
             } else if (tag.equalsIgnoreCase(NODE_ATTACHMENT)) {
               news.getNewType().attachment = xmlParser.nextText();
             } else if (tag.equalsIgnoreCase(NODE_AUTHORUID2)) {
               news.getNewType().authoruid2 = StringUtils.toInt(xmlParser.nextText(), 0);
             } else if (tag.equalsIgnoreCase("relative")) {
               relative = new Relative();
             } else if (relative != null) {
               if (tag.equalsIgnoreCase("rtitle")) {
                 relative.title = xmlParser.nextText();
               } else if (tag.equalsIgnoreCase("rurl")) {
                 relative.url = xmlParser.nextText();
               }
             }
             // 通知信息
             else if (tag.equalsIgnoreCase("notice")) {
               // news.setNotice(new Notice());
             }
           }
           break;
         case XmlPullParser.END_TAG:
           // 如果遇到标签结束,则把对象添加进集合中
           if (tag.equalsIgnoreCase("relative") && news != null && relative != null) {
             news.getRelatives().add(relative);
             relative = null;
           }
           break;
       }
       // 如果xml没有结束,则导航到下一个节点
       evtType = xmlParser.next();
     }
   } catch (XmlPullParserException e) {
     throw AppException.xml(e);
   } finally {
     inputStream.close();
   }
   return news;
 }