Android Open Source - clever-weather Search Cities Activity






From Project

Back to project page clever-weather.

License

The source code is released under:

GNU General Public License

If you think the Android project clever-weather 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 com.listotechnologies.cleverweather;
//w w  w  . j  a  v a2s  .  co  m
import android.app.Activity;
import android.app.SearchManager;
import android.content.ContentValues;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;

public class SearchCitiesActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Intent intent = getIntent();
        if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
            String query = intent.getStringExtra(SearchManager.QUERY);
            if (query != null)
                query = query.trim();

            //if we already know (via suggestions) that only one city will be returned, go straight to it
            if (query.equals(CleverWeatherProviderExtended.getLastSuggestionQuery()))
                viewForecasts(CleverWeatherProviderExtended.getLastSuggestion());
            else
                viewCities(query);
        } else if (Intent.ACTION_VIEW.equals(intent.getAction())) {
            viewForecasts(intent.getData().toString());
        }
    }

    private void viewCities(String query) {
        getFragmentManager().beginTransaction().add(android.R.id.content, CitiesFragment.newSearchInstance(query)).commit();
        setTitle(query);
    }

    private void viewForecasts(String query) {
        if (query != null) {
            ContentValues content = CleverWeatherProviderExtended.getSuggestionContent(query);
            if (content != null) {
                getFragmentManager()
                        .beginTransaction()
                        .add(android.R.id.content, ForecastsFragment.newInstance(content.getAsString(CleverWeatherProviderExtended.CITY_CODE_COLUMN),
                                                                                 content.getAsBoolean(CleverWeatherProviderExtended.CITY_ISFAVORITE_COLUMN)))
                        .commit();
                setTitle(content.getAsString(CleverWeatherProviderExtended.CITY_NAMEEN_COLUMN));
            }
        }
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                onBackPressed();
                return true;
        }
        return(super.onOptionsItemSelected(item));
    }
}




Java Source Code List

com.example.android.common.view.SlidingTabLayout.java
com.example.android.common.view.SlidingTabStrip.java
com.listotechnologies.cleverweather.ApplicationTest.java
com.listotechnologies.cleverweather.CitiesFragment.java
com.listotechnologies.cleverweather.CleverWeatherDbHelper.java
com.listotechnologies.cleverweather.CleverWeatherProviderClient.java
com.listotechnologies.cleverweather.CleverWeatherProviderExtended.java
com.listotechnologies.cleverweather.CleverWeatherProvider.java
com.listotechnologies.cleverweather.ForecastParser.java
com.listotechnologies.cleverweather.ForecastsActivity.java
com.listotechnologies.cleverweather.ForecastsFragment.java
com.listotechnologies.cleverweather.LocationGetter.java
com.listotechnologies.cleverweather.LocationHelper.java
com.listotechnologies.cleverweather.ProvinceActivity.java
com.listotechnologies.cleverweather.ProvincesFragment.java
com.listotechnologies.cleverweather.SearchCitiesActivity.java
com.listotechnologies.cleverweather.TabbedActivity.java
com.listotechnologies.cleverweather.TwoPaneFragment.java