Android Open Source - andro_auto_framework Recorder






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;
/*  ww w .  j av  a2s  .com*/
import java.util.ArrayList;

import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Spinner;
import android.widget.TextView;
/**
 * Recorder is the main class. It provides the functions to record user-actions.
 * These user-actions then gets publised to the server.
 * 
 * @author Varun Menon
 *
 */
public class Recorder {
  static ArrayList<Command> commandList = new ArrayList<Command>();
  static Command textCommand=null;
  private static final String LOG_TAG = "debugger";
  private static CommandTransmitter ct = new CommandTransmitter();
  
  /**
   *  A static record function that is mainly called for recording.
   *  Initializes the {@linkplain org.imaginea.botbot.Command}  object
   * @param userAction - the user-action that needs to be transmitted.
   * @param view - the class view of the element.
   * @param args - any extra arguments like text, position, etc.
   */
  public static void record(String userAction, Object view, Object... args) {
    if (view instanceof Spinner){
      Object arg = args[0];
      if(arg instanceof TextView){
        String text = ((TextView) arg).getText().toString();
        args[0]=text;
      }
    }else if (view.getClass().isAssignableFrom(AdapterView.class)){
      Object arg = args[0];
      if(arg instanceof TextView){
        String text = ((TextView) arg).getText().toString();
        args[0]=text;
      }
    }
    Command command = new Command();
    try {
      command.add(userAction, ((View) view), args);

    } catch (ClassCastException e) {
        command.add(userAction, view, args);
    }

    publishCommand(command);
    commandList.add(command);
    Log.i(LOG_TAG, "command received: " + command.toString());
  }
  
  /**
   * Publishes the new command. In case the user-action is "entertext", the command is stored temporarily.
   * When a new command is received the temporarily stored command is published along with the new command.
   * This is done because the text listener keeps on sending text as and when user enters it.
   * This will result in unnecessary command to be sent to the server.
   * 
   * @param command - The Command class object that needs to be published.
   */
  private static void publishCommand(Command command){
    if (textCommand!=null && (command.userAction).contentEquals("entertext") && (command.view.equals(textCommand.view))) {
      textCommand=command;
    }else if((command.userAction).contentEquals("entertext")){
      if(textCommand!=null)
        ct.publish(textCommand);
      textCommand=command;
    }else if(textCommand!=null){
      ct.publish(textCommand);
      textCommand=null;
      ct.publish(command);
    }else{
      ct.publish(command);
    }
    
  }
  /**
   * Used to record only the user-action without the class information. For ex. clickback.
   * @param userAction
   */
  public static void record(String userAction) {
    Command command = new Command();
    command.add(userAction);
    publishCommand(command);
    commandList.add(command);
  }
  /**
   * Used to record user-action along with the element view.
   * @param userAction
   * @param view
   */
  public static void record(String userAction, View view) {
    Command command = new Command();
    command.add(userAction, view, "");
    publishCommand(command);
    commandList.add(command);
    Log.i(LOG_TAG, "command received: " + command.toString());

  }
  /**
   * Used to record user-action for Menu action.
   * @param userAction
   * @param menu
   */
  public static void record(String userAction, Menu menu) {
    Command command = new Command();
    command.add(userAction);
    publishCommand(command);
    ct.publish(command);
    commandList.add(command);
  }
  
  public static void record(String userAction, MenuItem item) {
    Command command = new Command();
    command.add(userAction,item);
    publishCommand(command);
    ct.publish(command);
    commandList.add(command);
  }
  
  
}




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