コード例 #1
0
ファイル: SensorDB.java プロジェクト: Marcos-G/punya
  /** Returns the active sensors. */
  @SimpleProperty(
      category = PropertyCategory.BEHAVIOR,
      description =
          "The active sensor collections, as a list of two-element sublists. The first element "
              + "of each sublist represents the sensor name. The second element of each "
              + "sublist represents the schedule period of that sensor")
  public YailList CurrentActiveSensors() {
    YailList list = new YailList();
    List<Object> arrlist = new ArrayList<Object>();
    for (Entry<String, Integer> entry : mPipeline.getActiveSensor().entrySet()) {

      //      list.clear();
      //      list.add(YailList.makeList(new String[] { "First Name", "Barack" }));
      //      list.add(YailList.makeList(new String[] { "Last Name", "Obama" }));
      //      list.add(YailList.makeList(new String[] { "Title", "President of the United States"
      // }));
      //      list.add(YailList.makeList(new String[] { "This list has too few items" }));
      //      try {
      //        web.buildPostData(YailList.makeList(list));

      arrlist.add(YailList.makeList(new Object[] {entry.getKey(), entry.getValue()}));
      //      YailList entryList = new YailList();
      //      entryList.add(entry.getKey());
      //      entryList.add(entry.getValue());
      //      list.add(entryList);
    }
    return YailList.makeList(arrlist);
  }
コード例 #2
0
  public void testSendAndReceiveBytes() {
    List<Object> list = new ArrayList<Object>();
    list.add((byte) 0);
    list.add((short) 1);
    list.add(-1);
    list.add((long) 127);
    list.add((byte) -128);
    list.add((short) 255);
    list.add("0x0");
    list.add("0x1");
    list.add("0xFF");
    list.add("0xab");
    connection.SendBytes(YailList.makeList(list));
    assertEquals(0, recordedErrorNumber);
    assertEquals(10, connection.BytesAvailableToReceive());

    List<Integer> signedBytes = connection.ReceiveSignedBytes(5);
    assertEquals(0, signedBytes.get(0).intValue());
    assertEquals(1, signedBytes.get(1).intValue());
    assertEquals(-1, signedBytes.get(2).intValue());
    assertEquals(127, signedBytes.get(3).intValue());
    assertEquals(-128, signedBytes.get(4).intValue());
    List<Integer> unsignedBytes = connection.ReceiveUnsignedBytes(5);
    assertEquals(255, unsignedBytes.get(0).intValue());
    assertEquals(0x0, unsignedBytes.get(1).intValue());
    assertEquals(0x1, unsignedBytes.get(2).intValue());
    assertEquals(0xFF, unsignedBytes.get(3).intValue());
    assertEquals(0xab, unsignedBytes.get(4).intValue());

    assertEquals(0, recordedErrorNumber);

    list = new ArrayList<Object>();
    list.add("abc");
    connection.SendBytes(YailList.makeList(list));
    assertEquals(ErrorMessages.ERROR_BLUETOOTH_COULD_NOT_DECODE_ELEMENT, recordedErrorNumber);

    recordedErrorNumber = 0;
    list = new ArrayList<Object>();
    list.add("256");
    connection.SendBytes(YailList.makeList(list));
    assertEquals(ErrorMessages.ERROR_BLUETOOTH_COULD_NOT_FIT_ELEMENT_IN_BYTE, recordedErrorNumber);

    byte[] bytes = outputStream.toByteArray();
    assertEquals(10, bytes.length);
    int i = 0;
    assertEquals((byte) 0x00, bytes[i++]); // 0
    assertEquals((byte) 0x01, bytes[i++]); // 1
    assertEquals((byte) 0xFF, bytes[i++]); // -1
    assertEquals((byte) 0x7F, bytes[i++]); // 127
    assertEquals((byte) 0x80, bytes[i++]); // -128
    assertEquals((byte) 0xFF, bytes[i++]); // 255
    assertEquals((byte) 0x00, bytes[i++]); // 0x00
    assertEquals((byte) 0x01, bytes[i++]); // 0x01
    assertEquals((byte) 0xFF, bytes[i++]); // 0xFF
    assertEquals((byte) 0xAB, bytes[i++]); // 0xab
  }
コード例 #3
0
ファイル: ListPicker.java プロジェクト: ajhalbleib/aicg
 // Not a designer property, since this could lead to unpredictable
 // results if Selection is set to an incompatible value.
 @SimpleProperty
 public void SelectionIndex(int index) {
   if (index <= 0 || index > items.size()) {
     selectionIndex = 0;
     selection = "";
   } else {
     selectionIndex = index;
     // YailLists are 0-based, but we want to be 1-based.
     selection = items.getString(selectionIndex - 1);
   }
 }
コード例 #4
0
ファイル: ListPicker.java プロジェクト: ajhalbleib/aicg
 /** Selection property setter method. */
 @DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_STRING, defaultValue = "")
 @SimpleProperty
 public void Selection(String value) {
   selection = value;
   // Now, we need to change SelectionIndex to correspond to Selection.
   // If multiple Selections have the same SelectionIndex, use the first.
   // If none do, arbitrarily set the SelectionIndex to its default value
   // of 0.
   for (int i = 0; i < items.size(); i++) {
     // The comparison is case-sensitive to be consistent with yail-equal?.
     if (items.getString(i).equals(value)) {
       selectionIndex = i + 1;
       return;
     }
   }
   selectionIndex = 0;
 }
コード例 #5
0
ファイル: ListPicker.java プロジェクト: ajhalbleib/aicg
 // TODO(user): we need a designer property for lists
 @SimpleProperty
 public void Elements(YailList itemList) {
   Object[] objects = itemList.toStringArray();
   for (int i = 0; i < objects.length; i++) {
     if (!(objects[i] instanceof String)) {
       throw new YailRuntimeError("Items passed to ListPicker must be Strings", "Error");
     }
   }
   items = itemList;
 }
コード例 #6
0
ファイル: SensorDB.java プロジェクト: Marcos-G/punya
  /*
   * Return available sensors
   */
  @SimpleFunction(
      description = "Return available names of the avaiable sesnors for data collection")
  public YailList getAvailableSensors() {

    Log.i(TAG, sensorMapping.keySet().toString());

    YailList sensorList = YailList.makeList(sensorMapping.keySet());

    return sensorList;
  }
コード例 #7
0
ファイル: ListPicker.java プロジェクト: ajhalbleib/aicg
 @Override
 public Intent getIntent() {
   Intent intent = new Intent();
   intent.setClassName(container.$context(), LIST_ACTIVITY_CLASS);
   intent.putExtra(LIST_ACTIVITY_ARG_NAME, items.toStringArray());
   // Get the current Form's opening transition anim type,
   // and pass it to the list picker activity. For consistency,
   // the closing animation will be the same (but in reverse)
   String openAnim = container.$form().getOpenAnimType();
   intent.putExtra(LIST_ACTIVITY_ANIM_TYPE, openAnim);
   return intent;
 }
コード例 #8
0
ファイル: ListPicker.java プロジェクト: ajhalbleib/aicg
 /**
  * ElementsFromString property setter method
  *
  * @param itemstring - a string containing a comma-separated list of the strings to be picked from
  */
 @DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_STRING, defaultValue = "")
 // TODO(sharon): it might be nice to have a list editorType where the developer
 // could directly enter a list of strings (e.g. one per row) and we could
 // avoid the comma-separated business.
 @SimpleProperty(category = PropertyCategory.BEHAVIOR)
 public void ElementsFromString(String itemstring) {
   if (itemstring.length() == 0) {
     items = new YailList();
   } else {
     items = YailList.makeList((Object[]) itemstring.split(" *, *"));
   }
 }
コード例 #9
0
ファイル: Survey.java プロジェクト: Marcos-G/punya
  /*
   * This is for survey that is of type: MultipleChoice, ChooseList, CheckBox and Scale
   * Note that for Scale, only three options will
   */
  @SimpleFunction(
      description =
          "For survey style MultipleChoice, ChooseList, CheckBox and ScalePass"
              + "use this to pass in options for survey answers. Note for Scale, "
              + "only three options should be passed in and in the order of \"min\", \"max\", "
              + "\"default\" value of the scale")
  public void SetOptions(YailList options) {
    String[] objects = options.toStringArray();

    for (int i = 0; i < objects.length; i++) {
      this.options.add(objects[i]);
    }
  }
コード例 #10
0
 public Spannable[] itemsToColoredText() {
   // TODO(hal): Generalize this so that different items could have different
   // colors and even fonts and sizes
   int size = items.size();
   int displayTextSize = textSize;
   Spannable[] objects = new Spannable[size];
   for (int i = 1; i <= size; i++) {
     // Note that the ListPicker and otherPickers pickers convert Yail lists to string by calling
     // YailList.ToStringArray.
     // ListView however, does the string conversion via the adapter, so we must ensure
     // that the adapter uses YailListElementToSring
     String itemString = YailList.YailListElementToString(items.get(i));
     // Is there a more efficient way to do conversion to spannable strings that does not
     // need to allocate new objects?
     Spannable chars = new SpannableString(itemString);
     chars.setSpan(new ForegroundColorSpan(textColor), 0, chars.length(), 0);
     if (!container.$form().getCompatibilityMode()) {
       displayTextSize = (int) (textSize * container.$form().deviceDensity());
     }
     chars.setSpan(new AbsoluteSizeSpan(displayTextSize), 0, chars.length(), 0);
     objects[i - 1] = chars;
   }
   return objects;
 }
コード例 #11
0
  /**
   * Creates a new ListView component.
   *
   * @param container container that the component will be placed in
   */
  public ListView(ComponentContainer container) {
    super(container);
    this.container = container;
    items = YailList.makeEmptyList();
    // initialize selectionIndex which also sets selection
    SelectionIndex(0);
    view = new android.widget.ListView(container.$context());
    view.setOnItemClickListener(this);
    view.setChoiceMode(android.widget.ListView.CHOICE_MODE_SINGLE);
    view.setScrollingCacheEnabled(false);
    listViewLayout = new LinearLayout(container.$context());
    listViewLayout.setOrientation(LinearLayout.VERTICAL);

    txtSearchBox = new EditText(container.$context());
    txtSearchBox.setSingleLine(true);
    txtSearchBox.setWidth(Component.LENGTH_FILL_PARENT);
    txtSearchBox.setPadding(10, 10, 10, 10);
    txtSearchBox.setHint("Search list...");

    // set up the listener
    txtSearchBox.addTextChangedListener(
        new TextWatcher() {

          @Override
          public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
            // When user changed the Text
            adapter.getFilter().filter(cs);
          }

          @Override
          public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
            // no-op. Required method
          }

          @Override
          public void afterTextChanged(Editable arg0) {
            // no-op. Required method
          }
        });

    if (showFilter) {
      txtSearchBox.setVisibility(View.VISIBLE);
    } else {
      txtSearchBox.setVisibility(View.GONE);
    }

    // set the colors and initialize the elements
    // note that the TextColor and ElementsFromString setters
    // need to have the textColor set first, since they reset the
    // adapter

    Width(Component.LENGTH_FILL_PARENT);
    BackgroundColor(DEFAULT_BACKGROUND_COLOR);
    SelectionColor(DEFAULT_SELECTION_COLOR);

    textColor = DEFAULT_TEXT_COLOR;
    TextColor(textColor);
    textSize = DEFAULT_TEXT_SIZE;
    TextSize(textSize);
    ElementsFromString("");

    listViewLayout.addView(txtSearchBox);
    listViewLayout.addView(view);
    listViewLayout.requestLayout();
    container.$add(this);
  };