Android Open Source - andro_auto_framework Command






From Project

Back to project page andro_auto_framework.

License

The source code is released under:

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCT...

If you think the Android project andro_auto_framework listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.imaginea.botbot;
/*from  ww w.  ja  va 2 s  . c om*/
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import android.content.res.Resources.NotFoundException;
import android.view.MenuItem;
import android.view.View;

public class Command {
  ViewClasses vc = new ViewClasses();

  public Command() {

  }

  String userAction;
  Object view;
  List<Object> arguments;
  int id = 0;
  String viewClassName = "";

  public void add(String command, Object view, Object... args) {
    this.userAction = command;
    this.view = view;
    if(args.length==1 && args[0].equals("")){
      this.arguments= new ArrayList<Object>();
    }
    else{
      this.arguments = new ArrayList<Object>(Arrays.asList(args));
    }
    if (view.getClass().getName().contains("Button")) {
      this.userAction = "clickbutton";
    }
    if(String.class.isAssignableFrom(view.getClass())){
      arguments.add(0, (String)view);
      this.userAction="clicktext";
    }

  }

  public void add(String command, View view, Object... args) {
    this.userAction = command;
    this.view = view;
    if(args.length==1 && args[0].equals("")){
      this.arguments= new ArrayList<Object>();
    }
    else{
      this.arguments = new ArrayList<Object>(Arrays.asList(args));
    }
    String className = view.getClass().getName();
    if (vc.isSupportedClass(className)) {
      this.viewClassName = vc.getFullClassName(className);
    } else {
      this.viewClassName = "";
    }

    this.id = view.getId();

    try {
      if(arguments.size()>=1){
        arguments.add(0, getStringIdFromResource(view, id));
      }else{
        arguments.add(getStringIdFromResource(view, id));
      }
      if (command.contentEquals("click")) {
        this.userAction = "clickbyid";
      }
    } catch (NotFoundException e) {
      //Escaping in case the rid resource is not found
    }
  }
  
  public void add(String command, MenuItem item) {
    this.view = item;    
    this.arguments= new ArrayList<Object>();
    this.userAction="clicktext";
    arguments.add(item.getTitle());
  }
  

  private String getStringIdFromResource(View view, int id)
      throws NotFoundException {
    String rid = "";
    String tmp = (String) view.getContext().getResources()
        .getResourceName(id);
    if (tmp.contains("/")) {
      rid = tmp.substring(tmp.lastIndexOf("/") + 1);
    }
    return rid;
  }

  public String getData() {
    String data = "";
    data = data.concat("\"command\":\"" + this.userAction + "\"");
    data = data.concat(",\"viewClassName\":\"" + this.viewClassName + "\"");
    int i=0;
    for (Object args:arguments) {
      data = data.concat(",\"args[" + i + "]\":\"" + args + "\"");
      i++;
    }

    data = data.replace("\"", "\\\"");
    data = "{".concat(data).concat("}");
    return data;
  }

  public void add(String command) {
    this.userAction = command;
    this.arguments= new ArrayList<Object>();
  }

  @Override
  public String toString() {
    String retText;
    try {
      retText = "command =" + this.userAction + "; view=" + view.toString()
          + "; viewClassName=" + this.viewClassName + "; id=" + id
          + "; args[0]=" + arguments.get(0).toString()
          + "; args[1]=" + arguments.get(1).toString()
          + "; args[2]=" + arguments.get(2).toString();
    } catch (IndexOutOfBoundsException e) {
      retText = "command =" + this.userAction + "; view=" + view.toString()
          + "; viewClassName=" + this.viewClassName + "; id=" + id
          + "; args=" + arguments.toString();
    }
    return retText;
  }
}




Java Source Code List

com.imaginea.botbot.server.converter.RecordEntriesConverter.java
com.imaginea.botbot.server.converter.RecordEntryConverter.java
com.imaginea.botbot.server.converter.RecordSessionConverter.java
com.imaginea.botbot.server.converter.RecordSessionsConverter.java
com.imaginea.botbot.server.converter.UriResolver.java
com.imaginea.botbot.server.jpa.RecordEntry.java
com.imaginea.botbot.server.jpa.RecordSession.java
com.imaginea.botbot.server.service.PersistenceService.java
com.imaginea.botbot.server.service.RecordEntriesResource.java
com.imaginea.botbot.server.service.RecordEntryResource.java
com.imaginea.botbot.server.service.RecordSessionResource.java
com.imaginea.botbot.server.service.RecordSessionsResource.java
com.imaginea.botbot.server.servlet.DownloadCsv.java
com.zutubi.android.junitreport.JUnitReportListener.java
com.zutubi.android.junitreport.JUnitReportTestRunner.java
com.zutubi.android.junitreport.TestKeeper.java
com.zutubi.android.junitreport.TestngReportListener.java
org.imaginea.botbot.CommandTransmitter.java
org.imaginea.botbot.Command.java
org.imaginea.botbot.Convertor.java
org.imaginea.botbot.CustomVisitor.java
org.imaginea.botbot.ListenerAdder.java
org.imaginea.botbot.OnClickListenerTest.java
org.imaginea.botbot.OnItemClickListenerTest.java
org.imaginea.botbot.OnItemSelectedListenerTest.java
org.imaginea.botbot.OnTouchListenerTest.java
org.imaginea.botbot.Recorder.java
org.imaginea.botbot.ServerProperties.java
org.imaginea.botbot.TextListner.java
org.imaginea.botbot.ViewClasses.java
org.imaginea.botbot.api.DefaultProperties.java
org.imaginea.botbot.api.IdentifyByType.java
org.imaginea.botbot.api.TestCSVReader.java
org.imaginea.botbot.api.UsefulFunctions.java
org.imaginea.botbot.common.AndroFrameworkExecutorDataDriven.java
org.imaginea.botbot.common.AndroFrameworkExecutor.java
org.imaginea.botbot.common.BaseClass.java
org.imaginea.botbot.common.BotBotTestRunner.java
org.imaginea.botbot.common.CommandExecutor.java
org.imaginea.botbot.common.Command.java
org.imaginea.botbot.common.DataDrivenTestCase.java
org.imaginea.botbot.common.Prefrences.java
org.imaginea.botbot.common.RobotiumBaseClass.java
org.imaginea.botbot.common.TestCaseGenerator.java
org.imaginea.botbot.filereader.BaseReader.java
org.imaginea.botbot.filereader.FileTypeReader.java
org.imaginea.botbot.filereader.PropertiesReader.java
org.imaginea.botbot.keywords.BaseKeywordDefinitions.java
org.imaginea.botbot.keywords.DynamicExecution.java
org.imaginea.botbot.keywords.IKeywords.java
org.imaginea.botbot.keywords.KeywordCaller.java
org.imaginea.botbot.keywords.NativeDriverKeywordDefinitions.java
org.imaginea.botbot.keywords.RobotiumKeywordDefinition.java
org.imaginea.botbot.utility.DataDrivenDataGenerator.java
org.imaginea.botbot.utility.WebViewHandler.java