Пример #1
0
 // 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);
   }
 }
Пример #2
0
 /** 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;
 }
 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;
 }