Android Open Source - UK-Weather-repo Weather Info Activity






From Project

Back to project page UK-Weather-repo.

License

The source code is released under:

Apache License

If you think the Android project UK-Weather-repo 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.haringeymobile.ukweather;
//from  w  w  w  . j  av  a2  s  . c  o m
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;

/** An activity displaying some kind of weather information. */
public class WeatherInfoActivity extends ActionBarActivity {

  /**
   * A tag in the string resources, indicating that the MainActivity currently
   * has a second pane to contain a WeatherInfoFragment, so this activity is
   * not necessary and should finish.
   */
  public static final String DUAL_PANE = "dual_pane";

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    setTheme(R.style.Theme_AppCompat);
    super.onCreate(savedInstanceState);

    boolean isDualPane = DUAL_PANE.equals(getResources().getString(
        R.string.weather_info_frame_layout_pane_number_tag));
    if (isDualPane) {
      finish();
    } else {
      displayContent();
    }
  }

  /** Sets the action bar and adds the required fragment to the layout. */
  private void displayContent() {
    setContentView(R.layout.activity_weather_info);

    Intent intent = getIntent();
    WeatherInfoType weatherInfoType = intent
        .getParcelableExtra(MainActivity.WEATHER_INFORMATION_TYPE);
    setActionBar(weatherInfoType);

    String jsonString = intent
        .getStringExtra(MainActivity.WEATHER_INFO_JSON_STRING);
    addRequiredFragment(weatherInfoType, jsonString);
  }

  /**
   * Adjusts the action bar title and icon to the type of weather information
   * 
   * @param weatherInfoType
   *            a kind of weather information to be displayed on the screen
   */
  private void setActionBar(WeatherInfoType weatherInfoType) {
    ActionBar actionBar = getSupportActionBar();
    try {
      actionBar.setTitle(weatherInfoType.getLabelResourceId());
      actionBar.setIcon(weatherInfoType.getIconResourceId());
    } catch (NullPointerException e) {
      // TODO Perhaps there is a better way to deal with this
      // Seems to cause problems only when testing - a
      // NullPointerException is thrown at line 139 at
      // http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.3_r2.1/android/support/v7/app/ActionBarImplICS.java
      // Similar problem: line 136 at
      // https://github.com/appcelerator/titanium_mobile/blob/master/android/modules/ui/src/java/ti/modules/titanium/ui/widget/tabgroup/TiUIActionBarTabGroup.java
    }
  }

  /**
   * Creates and adds the correct type of fragment to the activity.
   * 
   * @param weatherInfoType
   *            a kind of weather information to be displayed on the screen
   * @param jsonString
   *            a string representing the JSON weather data
   */
  private void addRequiredFragment(WeatherInfoType weatherInfoType,
      String jsonString) {
    Fragment fragment = weatherInfoType == WeatherInfoType.CURRENT_WEATHER ? WeatherInfoFragment
        .newInstance(weatherInfoType, null, jsonString)
        : WeatherForecastParentFragment.newInstance(weatherInfoType,
            jsonString);
    getSupportFragmentManager().beginTransaction()
        .replace(R.id.weather_info_container, fragment).commit();
  }

}




Java Source Code List

com.astuetz.PagerSlidingTabStrip.java
com.haringeymobile.ukweather.AboutActivity.java
com.haringeymobile.ukweather.BaseCityCursorAdapter.java
com.haringeymobile.ukweather.BaseCityListFragmentWithButtons.java
com.haringeymobile.ukweather.CityListFragmentWithUtilityButtons.java
com.haringeymobile.ukweather.CityListFragmentWithWeatherButtons.java
com.haringeymobile.ukweather.CityManagementActivity.java
com.haringeymobile.ukweather.CitySearchResultsDialog.java
com.haringeymobile.ukweather.CityUtilitiesCursorAdapter.java
com.haringeymobile.ukweather.CityWeatherCursorAdapter.java
com.haringeymobile.ukweather.DeleteCityDialog.java
com.haringeymobile.ukweather.GetAvailableCitiesTask.java
com.haringeymobile.ukweather.MainActivity.java
com.haringeymobile.ukweather.SettingsActivityPreHoneycomb.java
com.haringeymobile.ukweather.SettingsActivity.java
com.haringeymobile.ukweather.SettingsFragment.java
com.haringeymobile.ukweather.WeatherCurrentInfoFragment.java
com.haringeymobile.ukweather.WeatherDailyWeatherForecastChildFragment.java
com.haringeymobile.ukweather.WeatherForecastParentFragment.java
com.haringeymobile.ukweather.WeatherInfoActivity.java
com.haringeymobile.ukweather.WeatherInfoFragment.java
com.haringeymobile.ukweather.WeatherInfoType.java
com.haringeymobile.ukweather.WeatherThreeHourlyForecastChildFragment.java
com.haringeymobile.ukweather.WorkerFragmentToRetrieveJsonString.java
com.haringeymobile.ukweather.data.InitialCity.java
com.haringeymobile.ukweather.data.JsonFetcher.java
com.haringeymobile.ukweather.data.OpenWeatherMapUrl.java
com.haringeymobile.ukweather.data.objects.CityCurrentWeather.java
com.haringeymobile.ukweather.data.objects.CityDailyWeatherForecast.java
com.haringeymobile.ukweather.data.objects.CityInfo.java
com.haringeymobile.ukweather.data.objects.CityThreeHourlyWeatherForecast.java
com.haringeymobile.ukweather.data.objects.Clouds.java
com.haringeymobile.ukweather.data.objects.Coordinates.java
com.haringeymobile.ukweather.data.objects.NumericParameters.java
com.haringeymobile.ukweather.data.objects.Rain.java
com.haringeymobile.ukweather.data.objects.SearchResponseForDailyForecastQuery.java
com.haringeymobile.ukweather.data.objects.SearchResponseForFindQuery.java
com.haringeymobile.ukweather.data.objects.SearchResponseForThreeHourlyForecastQuery.java
com.haringeymobile.ukweather.data.objects.SystemParameters.java
com.haringeymobile.ukweather.data.objects.TemperatureScale.java
com.haringeymobile.ukweather.data.objects.Temperature.java
com.haringeymobile.ukweather.data.objects.WeatherInformation.java
com.haringeymobile.ukweather.data.objects.Weather.java
com.haringeymobile.ukweather.data.objects.WindSpeedMeasurementUnit.java
com.haringeymobile.ukweather.data.objects.Wind.java
com.haringeymobile.ukweather.database.CityTable.java
com.haringeymobile.ukweather.database.DatabaseHelper.java
com.haringeymobile.ukweather.database.GeneralDatabaseService.java
com.haringeymobile.ukweather.database.SqlOperation.java
com.haringeymobile.ukweather.database.WeatherContentProvider.java
com.haringeymobile.ukweather.utils.AsyncTaskWithProgressBar.java
com.haringeymobile.ukweather.utils.GlobalConstants.java
com.haringeymobile.ukweather.utils.MiscMethods.java
com.haringeymobile.ukweather.utils.SharedPrefsHelper.java