Ejemplo n.º 1
0
  private void startSearching(boolean clearResults) {
    stopSearching();

    if (clearResults) {
      bridges.clear();
      bridgesAdapter.clear();
    }

    bridgeSearchTask = new BridgeSearchTask();
    bridgeSearchTask.execute();

    setSearchIndicator(true);
  }
Ejemplo n.º 2
0
  @SuppressWarnings("unchecked")
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_link);

    // Set up layout
    bridgesList = (ListView) findViewById(R.id.link_bridges);
    bridgesAdapter = new BridgeAdapter(this);
    bridgesList.setAdapter(bridgesAdapter);
    bridgesList.setEmptyView(findViewById(R.id.link_empty));

    // Set up loading UI elements
    ActionBar ab = getActionBar();
    ab.setCustomView(R.layout.loader);
    ab.setDisplayShowCustomEnabled(true);
    ab.setDisplayShowHomeEnabled(false);

    RelativeLayout loadingLayout = (RelativeLayout) ab.getCustomView();

    loadingSpinner = (ProgressBar) loadingLayout.findViewById(R.id.loader_spinner);
    refreshButton = (ImageButton) loadingLayout.findViewById(R.id.loader_refresh);

    setEventHandlers();

    // Restore state or start over
    if (savedInstanceState == null) {
      Bridge lastBridge = Util.getLastBridge(this);
      if (lastBridge != null) {
        // This will be set again after a successful connection, connection failure leaves the last
        // bridge null
        Util.setLastBridge(this, null);

        // Try connecting to last bridge
        connectToLastBridge(lastBridge);
      } else {
        // Start searching for bridges and add them to the results
        startSearching(true);
      }
    } else {
      bridges = (ArrayList<Bridge>) savedInstanceState.getSerializable("bridges");

      for (Bridge b : bridges) {
        bridgesAdapter.add(b);
      }

      // If a search was running, continue without removing existing results
      if (savedInstanceState.getBoolean("searching")) {
        startSearching(false);
      }
    }
  }