// Save preferences: scroll position, selected tab, expanded buildings
  @Override
  public void onPause() {
    super.onPause();

    SharedPreferences settings = getPreferences(MODE_PRIVATE);
    SharedPreferences.Editor editor = settings.edit();

    // Save last tab
    editor.putInt("lastTab", curTab);

    // Save current expanded buildings to be retrieved later
    editor.putStringSet("lastNearbyExpandedBuildings", nearbyExpandedBldgs);
    editor.putStringSet("lastAllExpandedBuildings", allExpandedBldgs);

    // Save list position (index & top) in each tab
    int curPos[] = sm.getCurPos();
    int nearPos[] = sm.getNearPos();
    int allPos[] = sm.getAllPos();

    editor.putInt("curPosIndex", curPos[0]);
    editor.putInt("nearPosIndex", nearPos[0]);
    editor.putInt("allPosIndex", allPos[0]);
    editor.putInt("curPosTop", curPos[1]);
    editor.putInt("nearPosTop", nearPos[1]);
    editor.putInt("allPosTop", allPos[1]);

    // Note: Only those buildings still nearby should become expanded
    // Since the fragments all call getBuildings before re-populating.
    // So only those still in the getBuildings list will be able to be
    // re-expanded!

    editor.commit();
  }
  public void restorePreferences() {
    // Restore last tab
    SharedPreferences settings = getPreferences(MODE_PRIVATE);
    curTab = settings.getInt("lastTab", 0);

    // Restore last expanded buildings (by tab)
    nearbyExpandedBldgs =
        settings.getStringSet("lastNearbyExpandedBuildings", new HashSet<String>());
    allExpandedBldgs = settings.getStringSet("lastAllExpandedBuildings", new HashSet<String>());

    // Restore position in each tab
    sm.setCurPos(settings.getInt("curPosIndex", 0), settings.getInt("curPosTop", 0));
    sm.setNearbyPos(settings.getInt("nearPosIndex", 0), settings.getInt("nearPosTop", 0));
    sm.setAllPos(settings.getInt("allPosIndex", 0), settings.getInt("allPosTop", 0));
  }