Пример #1
0
  /**
   * Construct a prefence item corresponding to a single parser entry
   *
   * @param category root preference category
   * @param parent parent preference screen
   * @param multi true if we are setting up multiple location selection menu
   * @param locMgr location manager
   * @return constructed preference
   */
  private Preference buildLocationItem(
      ParserCategory category, PreferenceScreen parent, boolean multi, LocationManager locMgr) {

    // Current rules are that category must contain only  subcategory or only parser entries.  See
    // which this is
    String catName = category.getName();
    ParserEntry[] entries = category.getParserList();
    boolean subcat = false;
    boolean plist = false;
    for (ParserEntry entry : entries) {
      if (entry.isCategory()) subcat = true;
      else plist = true;
    }
    if (subcat && plist)
      throw new RuntimeException("Parser group " + catName + " mixes parser and category entries");
    if (!subcat && !plist) throw new RuntimeException("Parser group " + catName + " is empty");

    // If it only contains subcategories, build a new preference screen with them
    if (subcat) {
      PreferenceScreen sub = getPreferenceManager().createPreferenceScreen(this);
      sub.setTitle(catName);
      buildLocationMenu(category, sub, multi, locMgr);
      return sub;
    }

    // Otherwise we are handing a parser list
    // What we do next depends on whether this is a single or multiple selection menu

    // If we are doing multiple selections, create a new preference screen and fill it
    // a location checkbox for each parser entry
    if (multi) {
      PreferenceScreen sub = getPreferenceManager().createPreferenceScreen(this);
      sub.setTitle(catName);
      for (ParserEntry entry : entries) {
        sub.addPreference(
            new LocationCheckBoxPreference(
                this, entry.getParserName(), stripStateAbbrv(entry.getLocName()), locMgr));
      }
      return sub;
    }

    // If we are doing single location selections, build a list preference
    // that can select from any of the parsers in this category
    LocationListPreference list = new LocationListPreference(this, locMgr, parent);
    list.setTitle(catName);
    list.setDialogTitle(catName);

    String[] values = new String[entries.length];
    String[] names = new String[entries.length];
    for (int ndx = 0; ndx < entries.length; ndx++) {
      ParserEntry entry = entries[ndx];
      values[ndx] = entry.getParserName();
      names[ndx] = stripStateAbbrv(entry.getLocName());
    }
    list.setEntryValues(values);
    list.setEntries(names);
    return list;
  }
Пример #2
0
 /**
  * Construct a preference screen corresponding to a configured parser category
  *
  * @param parserCategory parser category
  * @param screen preference screen being set up
  * @param multi true if we are setting up a mutiple location selection menu
  * @param locMgr Location manager
  */
 private void buildLocationMenu(
     ParserCategory parserCategory,
     PreferenceScreen screen,
     boolean multi,
     LocationManager locMgr) {
   for (ParserEntry entry : parserCategory.getParserList()) {
     if (!entry.isCategory())
       throw new RuntimeException(
           "Top level parser entry " + entry.getParserName() + " must be a category");
     Preference pref = buildLocationItem(entry.getCategory(), screen, multi, locMgr);
     screen.addPreference(pref);
   }
 }