Search in sources :

Example 1 with BikeNetworkInfo

use of be.brunoparmentier.openbikesharing.app.models.BikeNetworkInfo in project OpenBikeSharing by bparmentier.

the class BikeNetworksListAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View v = convertView;
    if (v == null) {
        LayoutInflater vi;
        vi = LayoutInflater.from(getContext());
        v = vi.inflate(android.R.layout.simple_list_item_2, parent, false);
    }
    BikeNetworkInfo network = getItem(position);
    if (network != null) {
        TextView text1 = (TextView) v.findViewById(android.R.id.text1);
        TextView text2 = (TextView) v.findViewById(android.R.id.text2);
        text1.setText(network.getLocation().getCity() + " (" + network.getLocation().getCountry() + ")");
        text2.setText(network.getName());
    }
    return v;
}
Also used : LayoutInflater(android.view.LayoutInflater) BikeNetworkInfo(be.brunoparmentier.openbikesharing.app.models.BikeNetworkInfo) TextView(android.widget.TextView) TextView(android.widget.TextView) View(android.view.View)

Example 2 with BikeNetworkInfo

use of be.brunoparmentier.openbikesharing.app.models.BikeNetworkInfo in project OpenBikeSharing by bparmentier.

the class BikeNetworksListActivity method onCreateOptionsMenu.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.bike_networks_list, menu);
    SearchManager manager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
    searchView.setSearchableInfo(manager.getSearchableInfo(getComponentName()));
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String s) {
            return false;
        }

        @Override
        public // TODO: avoid redundancy
        boolean onQueryTextChange(String s) {
            if (bikeNetworks == null) {
                return false;
            }
            searchedBikeNetworks = new ArrayList<>();
            for (BikeNetworkInfo network : bikeNetworks) {
                if (network.getName().toLowerCase().contains(s.toLowerCase()) || network.getLocation().getCity().toLowerCase().contains(s.toLowerCase())) {
                    searchedBikeNetworks.add(network);
                }
            }
            bikeNetworksListAdapter = new BikeNetworksListAdapter(BikeNetworksListActivity.this, android.R.layout.simple_expandable_list_item_2, android.R.id.text1, searchedBikeNetworks);
            listView.setAdapter(bikeNetworksListAdapter);
            listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(BikeNetworksListActivity.this);
                    SharedPreferences.Editor editor = settings.edit();
                    editor.putString(PREF_KEY_NETWORK_ID, searchedBikeNetworks.get(position).getId());
                    editor.putString(PREF_KEY_NETWORK_NAME, searchedBikeNetworks.get(position).getName());
                    editor.putString(PREF_KEY_NETWORK_CITY, searchedBikeNetworks.get(position).getLocation().getCity());
                    editor.putLong(PREF_KEY_NETWORK_LATITUDE, Double.doubleToRawLongBits(searchedBikeNetworks.get(position).getLocation().getLatitude()));
                    editor.putLong(PREF_KEY_NETWORK_LONGITUDE, Double.doubleToRawLongBits(searchedBikeNetworks.get(position).getLocation().getLongitude()));
                    editor.apply();
                    Toast.makeText(BikeNetworksListActivity.this, searchedBikeNetworks.get(position).getName() + " (" + searchedBikeNetworks.get(position).getLocation().getCity() + ") " + getString(R.string.network_selected), Toast.LENGTH_SHORT).show();
                    Intent resultIntent = new Intent();
                    resultIntent.putExtra(KEY_NETWORK_ID, searchedBikeNetworks.get(position).getId());
                    if (getParent() == null) {
                        setResult(Activity.RESULT_OK, resultIntent);
                    } else {
                        getParent().setResult(Activity.RESULT_OK, resultIntent);
                    }
                    finish();
                }
            });
            return true;
        }
    });
    return true;
}
Also used : SearchManager(android.app.SearchManager) SharedPreferences(android.content.SharedPreferences) BikeNetworkInfo(be.brunoparmentier.openbikesharing.app.models.BikeNetworkInfo) ArrayList(java.util.ArrayList) Intent(android.content.Intent) View(android.view.View) AdapterView(android.widget.AdapterView) SearchView(android.widget.SearchView) ListView(android.widget.ListView) SearchView(android.widget.SearchView) BikeNetworksListAdapter(be.brunoparmentier.openbikesharing.app.adapters.BikeNetworksListAdapter) AdapterView(android.widget.AdapterView)

Aggregations

View (android.view.View)2 BikeNetworkInfo (be.brunoparmentier.openbikesharing.app.models.BikeNetworkInfo)2 SearchManager (android.app.SearchManager)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 LayoutInflater (android.view.LayoutInflater)1 AdapterView (android.widget.AdapterView)1 ListView (android.widget.ListView)1 SearchView (android.widget.SearchView)1 TextView (android.widget.TextView)1 BikeNetworksListAdapter (be.brunoparmentier.openbikesharing.app.adapters.BikeNetworksListAdapter)1 ArrayList (java.util.ArrayList)1