Ejemplo n.º 1
0
  @Override
  public void handleCreationDict(KrollDict options) {
    options = handleStyleOptions(options);
    if (langConversionTable != null) {
      KrollDict foundStrings = new KrollDict();
      for (String key : langConversionTable.keySet()) {
        // if we have it already, ignore
        if (!options.containsKey(key)) {
          String convertKey = (String) langConversionTable.get(key);
          String langKey = (String) options.get(convertKey);
          if (langKey != null) {
            try {
              String localText = getLocalizedText(langKey);
              foundStrings.put(key, localText);
            } catch (TiRHelper.ResourceNotFoundException e) {
              Log.w(LCAT, "Localized text key '" + langKey + "' is invalid.");
            }
          }
        }
      }

      if (!(foundStrings.isEmpty())) {
        extend(foundStrings);
        options.putAll(foundStrings);
      }
    }
    options = handleStyleOptions(options);
    super.handleCreationDict(options);

    // TODO eventManager.addOnEventChangeListener(this);
  }
Ejemplo n.º 2
0
  public void populateViews(
      KrollDict data,
      TiBaseListViewItem cellContent,
      TiListViewTemplate template,
      int itemIndex,
      int sectionIndex,
      View item_layout) {
    Object cell = cellContent.getTag();
    // Handling root item, since that is not in the views map.
    if (!(cell instanceof TiListItem)) {
      Log.e(TAG, "Cell is not TiListItem. Something is wrong..", Log.DEBUG_MODE);
      return;
    }

    TiListItem listItem = (TiListItem) cell;
    KrollDict listItemProperties;
    String itemId = null;

    if (data.containsKey(TiC.PROPERTY_PROPERTIES)) {
      listItemProperties = new KrollDict((HashMap) data.get(TiC.PROPERTY_PROPERTIES));
    } else {
      listItemProperties = template.getRootItem().getDefaultProperties();
    }

    // find out if we need to update itemId
    if (listItemProperties.containsKey(TiC.PROPERTY_ITEM_ID)) {
      itemId = TiConvert.toString(listItemProperties.get(TiC.PROPERTY_ITEM_ID));
    }

    // update extra event data for list item
    appendExtraEventData(listItem, itemIndex, sectionIndex, TiC.PROPERTY_PROPERTIES, itemId);

    HashMap<String, ViewItem> views = (HashMap<String, ViewItem>) cellContent.getViewsMap();
    // Loop through all our views and apply default properties
    for (String binding : views.keySet()) {
      DataItem dataItem = template.getDataItem(binding);
      ViewItem viewItem = views.get(binding);
      TiUIView view = viewItem.getView();
      // update extra event data for views
      if (view != null) {
        appendExtraEventData(view, itemIndex, sectionIndex, binding, itemId);
      }
      // if binding is contain in data given to us, process that data, otherwise
      // apply default properties.
      if (data.containsKey(binding) && view != null) {
        KrollDict properties = new KrollDict((HashMap) data.get(binding));
        KrollDict diffProperties = viewItem.generateDiffProperties(properties);
        if (!diffProperties.isEmpty()) {
          view.processProperties(diffProperties);
        }

      } else if (dataItem != null && view != null) {
        KrollDict diffProperties = viewItem.generateDiffProperties(dataItem.getDefaultProperties());
        if (!diffProperties.isEmpty()) {
          view.processProperties(diffProperties);
        }
      } else {
        Log.w(
            TAG,
            "Sorry, " + binding + " isn't a valid binding. Perhaps you made a typo?",
            Log.DEBUG_MODE);
      }
    }

    // process listItem properties
    KrollDict listItemDiff = cellContent.getViewItem().generateDiffProperties(listItemProperties);
    if (!listItemDiff.isEmpty()) {
      listItem.processProperties(listItemDiff);
    }
  }