Android Open Source - EdmontonWifi Search Activity






From Project

Back to project page EdmontonWifi.

License

The source code is released under:

MIT License

If you think the Android project EdmontonWifi listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package hey.rich.edmontonwifi.activities;
//w  w w  . java2s  .co  m
import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.app.SearchManager;
import android.content.Intent;
import android.os.Bundle;
import android.provider.SearchRecentSuggestions;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.Toast;

import hey.rich.edmontonwifi.EdmontonWifi;
import hey.rich.edmontonwifi.R;
import hey.rich.edmontonwifi.Objects.Wifi;
import hey.rich.edmontonwifi.adapters.WifiArrayAdapter;
import hey.rich.edmontonwifi.utils.WifiSearchRecentSuggestionsProvider;

public class SearchActivity extends Activity {
  private List<Wifi> wifis;
  private WifiArrayAdapter adapter;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_search);

    ListView lView = (ListView) findViewById(R.id.search_activity_listview);

    wifis = new ArrayList<Wifi>(EdmontonWifi.getWifiList(
                getApplicationContext()).getAllWifis());
    adapter = new WifiArrayAdapter(this, wifis);
    lView.setAdapter(adapter);

    lView.setOnItemClickListener(new OnItemClickListener() {
      @Override
      public void onItemClick(AdapterView<?> parent, View view,
          int position, long id) {
        Intent i = new Intent(getApplicationContext(),
            WifiViewActivity.class);
        i.putExtra(WifiViewActivity.WIFI_ID, position);
        if(i.resolveActivity(getPackageManager())!= null){
          startActivity(i);  
        }
        else{
          Toast.makeText(getApplicationContext(), "Error Trying to Open, Try Again Later", Toast.LENGTH_LONG).show();
        }
        

      }
    });

    handleIntent(getIntent());

  }

  @Override
  protected void onNewIntent(Intent intent) {
    setIntent(intent);
    handleIntent(intent);
  }

  private void handleIntent(Intent i) {

    if (Intent.ACTION_SEARCH.equals(i.getAction())) {
      String query = i.getStringExtra(SearchManager.QUERY);
      

      // Save recent search
      SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this,
          WifiSearchRecentSuggestionsProvider.AUTHORITY,
          WifiSearchRecentSuggestionsProvider.MODE);
      suggestions.saveRecentQuery(query, null);
      
      performSearch(query);
    }
  }

  private void performSearch(String query) {
    // Should probably optimize this somehow
    List<Wifi> newWifis = new ArrayList<Wifi>();
    for (Wifi w : wifis) {
      if (w.getAddress().toLowerCase().contains(query.toLowerCase())
          || w.getName().toLowerCase().contains(query.toLowerCase())) {
        newWifis.add(w);
      }
    }


    wifis.clear();
    wifis.addAll(newWifis);
    adapter.notifyDataSetChanged();
  }
}




Java Source Code List

hey.rich.edmontonwifi.EdmontonWifi.java
hey.rich.edmontonwifi.Objects.ConstructionList.java
hey.rich.edmontonwifi.Objects.Construction.java
hey.rich.edmontonwifi.Objects.Data.java
hey.rich.edmontonwifi.Objects.WifiList.java
hey.rich.edmontonwifi.Objects.Wifi.java
hey.rich.edmontonwifi.activities.ConstructionViewActivity.java
hey.rich.edmontonwifi.activities.MainActivity.java
hey.rich.edmontonwifi.activities.SearchActivity.java
hey.rich.edmontonwifi.activities.WifiViewActivity.java
hey.rich.edmontonwifi.adapters.ConstructionArrayAdapter.java
hey.rich.edmontonwifi.adapters.WifiArrayAdapter.java
hey.rich.edmontonwifi.fragments.ClearSearchHistoryDialogFragment.java
hey.rich.edmontonwifi.fragments.ConstructionFragment.java
hey.rich.edmontonwifi.fragments.NavigationDrawerFragment.java
hey.rich.edmontonwifi.fragments.SettingsFragment.java
hey.rich.edmontonwifi.fragments.WifiFragment.java
hey.rich.edmontonwifi.utils.JsonReader.java
hey.rich.edmontonwifi.utils.Sorters.java
hey.rich.edmontonwifi.utils.WifiSearchRecentSuggestionsProvider.java