コード例 #1
0
  public void propertyChanged(String key, Object oldValue, Object newValue, KrollProxy proxy) {

    if (key.equals(TiC.PROPERTY_HEADER_TITLE)) {
      setHeaderTitle(TiConvert.toString(newValue));
    } else if (key.equals(TiC.PROPERTY_FOOTER_TITLE)) {
      setFooterTitle(TiConvert.toString(newValue));
    } else if (key.equals(TiC.PROPERTY_SECTIONS) && newValue instanceof Object[]) {
      processSections((Object[]) newValue);
      if (adapter != null) {
        adapter.notifyDataSetChanged();
      }
    } else if (key.equals(TiC.PROPERTY_SEARCH_TEXT)) {
      this.searchText = TiConvert.toString(newValue);
      if (this.searchText != null) {
        reFilter(this.searchText);
      }
    } else if (key.equals(TiC.PROPERTY_CASE_INSENSITIVE_SEARCH)) {
      this.caseInsensitive = TiConvert.toBoolean(newValue, true);
      if (this.searchText != null) {
        reFilter(this.searchText);
      }
    } else if (key.equals(TiC.PROPERTY_SEARCH_VIEW)) {
      TiViewProxy searchView = (TiViewProxy) newValue;
      if (isSearchViewValid(searchView)) {
        TiUIView search = searchView.getOrCreateView();
        setSearchListener(searchView, search);
        if (searchLayout != null) {
          searchLayout.removeAllViews();
          addSearchLayout(searchLayout, searchView, search);
        } else {
          layoutSearchView(searchView);
        }
      } else {
        Log.e(TAG, "Searchview type is invalid");
      }

    } else if (key.equals(TiC.PROPERTY_SHOW_VERTICAL_SCROLL_INDICATOR) && newValue != null) {
      listView.setVerticalScrollBarEnabled(TiConvert.toBoolean(newValue));
    } else if (key.equals(TiC.PROPERTY_DEFAULT_ITEM_TEMPLATE) && newValue != null) {
      defaultTemplateBinding = TiConvert.toString(newValue);
      refreshItems();
    } else if (key.equals(TiC.PROPERTY_SEPARATOR_COLOR)) {
      String color = TiConvert.toString(newValue);
      setSeparatorColor(color);
    } else {
      super.propertyChanged(key, oldValue, newValue, proxy);
    }
  }
コード例 #2
0
  public void processProperties(KrollDict d) {

    if (d.containsKey(TiC.PROPERTY_TEMPLATES)) {
      Object templates = d.get(TiC.PROPERTY_TEMPLATES);
      if (templates != null) {
        processTemplates(new KrollDict((HashMap) templates));
      }
    }

    if (d.containsKey(TiC.PROPERTY_SEARCH_TEXT)) {
      this.searchText = TiConvert.toString(d, TiC.PROPERTY_SEARCH_TEXT);
    }

    if (d.containsKey(TiC.PROPERTY_SEARCH_VIEW)) {
      TiViewProxy searchView = (TiViewProxy) d.get(TiC.PROPERTY_SEARCH_VIEW);
      if (isSearchViewValid(searchView)) {
        TiUIView search = searchView.getOrCreateView();
        setSearchListener(searchView, search);
        layoutSearchView(searchView);
      } else {
        Log.e(TAG, "Searchview type is invalid");
      }
    }

    if (d.containsKey(TiC.PROPERTY_CASE_INSENSITIVE_SEARCH)) {
      this.caseInsensitive = TiConvert.toBoolean(d, TiC.PROPERTY_CASE_INSENSITIVE_SEARCH, true);
    }

    if (d.containsKey(TiC.PROPERTY_SEPARATOR_COLOR)) {
      String color = TiConvert.toString(d, TiC.PROPERTY_SEPARATOR_COLOR);
      setSeparatorColor(color);
    }

    if (d.containsKey(TiC.PROPERTY_SHOW_VERTICAL_SCROLL_INDICATOR)) {
      listView.setVerticalScrollBarEnabled(
          TiConvert.toBoolean(d, TiC.PROPERTY_SHOW_VERTICAL_SCROLL_INDICATOR, true));
    }

    if (d.containsKey(TiC.PROPERTY_DEFAULT_ITEM_TEMPLATE)) {
      defaultTemplateBinding = TiConvert.toString(d, TiC.PROPERTY_DEFAULT_ITEM_TEMPLATE);
    }

    ListViewProxy listProxy = (ListViewProxy) proxy;
    if (d.containsKey(TiC.PROPERTY_SECTIONS)) {
      // if user didn't append/modify/delete sections before this is called, we process sections
      // as usual. Otherwise, we process the preloadSections, which should also contain the
      // section(s)
      // from this dictionary as well as other sections that user append/insert/deleted prior to
      // this.
      if (!listProxy.isPreload()) {
        processSections((Object[]) d.get(TiC.PROPERTY_SECTIONS));
      } else {
        processSections(listProxy.getPreloadSections().toArray());
      }
    } else if (listProxy.isPreload()) {
      // if user didn't specify 'sections' property upon creation of listview but append/insert it
      // afterwards
      // we process them instead.
      processSections(listProxy.getPreloadSections().toArray());
    }

    listProxy.clearPreloadSections();

    if (d.containsKey(TiC.PROPERTY_HEADER_VIEW)) {
      Object viewObj = d.get(TiC.PROPERTY_HEADER_VIEW);
      setHeaderOrFooterView(viewObj, true);
    } else if (d.containsKey(TiC.PROPERTY_HEADER_TITLE)) {
      headerView = inflater.inflate(headerFooterId, null);
      setHeaderTitle(TiConvert.toString(d, TiC.PROPERTY_HEADER_TITLE));
    }

    if (d.containsKey(TiC.PROPERTY_FOOTER_VIEW)) {
      Object viewObj = d.get(TiC.PROPERTY_FOOTER_VIEW);
      setHeaderOrFooterView(viewObj, false);
    } else if (d.containsKey(TiC.PROPERTY_FOOTER_TITLE)) {
      footerView = inflater.inflate(headerFooterId, null);
      setFooterTitle(TiConvert.toString(d, TiC.PROPERTY_FOOTER_TITLE));
    }

    // Check to see if headerView and footerView are specified. If not, we hide the views
    if (headerView == null) {
      headerView = inflater.inflate(headerFooterId, null);
      headerView.findViewById(titleId).setVisibility(View.GONE);
    }

    if (footerView == null) {
      footerView = inflater.inflate(headerFooterId, null);
      footerView.findViewById(titleId).setVisibility(View.GONE);
    }

    // Have to add header and footer before setting adapter
    listView.addHeaderView(headerView);
    listView.addFooterView(footerView);

    listView.setAdapter(adapter);

    super.processProperties(d);
  }