Android Open Source - UK-Weather-repo Weather Daily Weather Forecast Child Fragment






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;
//w  w  w  . ja  v a 2 s  .  com
import java.util.Date;

import android.content.Context;
import android.os.Bundle;
import android.text.format.DateFormat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.google.gson.Gson;
import com.haringeymobile.ukweather.data.objects.CityDailyWeatherForecast;
import com.haringeymobile.ukweather.data.objects.Temperature;
import com.haringeymobile.ukweather.data.objects.TemperatureScale;
import com.haringeymobile.ukweather.data.objects.WeatherInformation;
import com.haringeymobile.ukweather.utils.MiscMethods;

/** A fragment displaying weather forecast for one day. */
public class WeatherDailyWeatherForecastChildFragment extends
    WeatherInfoFragment {

  private TextView extraTemperaturesTextView;

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_daily_weather_forecast,
        container, false);
    getCommonViews(view);
    extraTemperaturesTextView = (TextView) view
        .findViewById(R.id.night_morning_evening_temperatures_text_view);
    return view;
  }

  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    Bundle args = getArguments();
    String jsonString = args.getString(WeatherInfoFragment.JSON_STRING);
    Gson gson = new Gson();
    CityDailyWeatherForecast cityWeatherForecast = gson.fromJson(
        jsonString, CityDailyWeatherForecast.class);
    displayWeather(cityWeatherForecast);
  }

  @Override
  protected void displayExtraInfo(WeatherInformation weatherInformation) {
    CityDailyWeatherForecast cityDailyWeatherForecast = (CityDailyWeatherForecast) weatherInformation;

    String extraInfoText = getExtraInfoText(cityDailyWeatherForecast);
    extraInfoTextView.setText(extraInfoText);

    String temperatureInfo = getExtraTemperatureText(cityDailyWeatherForecast);
    extraTemperaturesTextView.setText(temperatureInfo);
  }

  /**
   * Obtains a text to be displayed in the extraInfoTextView.
   * 
   * @param cityDailyWeatherForecast
   *            Java object, corresponding to the Open Weather Map JSON
   *            weather forecast data for one day
   * @return a weather forecast date, time, and location
   */
  private String getExtraInfoText(
      CityDailyWeatherForecast cityDailyWeatherForecast) {
    Context context = getActivity();
    Date date = new Date(cityDailyWeatherForecast.getDate() * 1000);
    String dateString = DateFormat.getLongDateFormat(context).format(date);
    String timeString = DateFormat.getTimeFormat(context).format(date);
    return dateString + "\n" + timeString + "\n"
        + getArguments().getString(CITY_NAME);
  }

  /**
   * Obtains and displays the night, morning, and evening temperatures.
   * 
   * @param cityDailyWeatherForecast
   *            Java object, corresponding to the Open Weather Map JSON
   *            weather forecast data for one day
   */

  /**
   * Obtains a text to be displayed in the extraTemperaturesTextView.
   * 
   * @param cityDailyWeatherForecast
   *            Java object, corresponding to the Open Weather Map JSON
   *            weather forecast data for one day
   * @return the night, morning, and evening temperatures
   */
  private String getExtraTemperatureText(
      CityDailyWeatherForecast cityDailyWeatherForecast) {
    CityDailyWeatherForecast weatherForecast = (CityDailyWeatherForecast) cityDailyWeatherForecast;
    Temperature temperature = weatherForecast.getTemperature();
    TemperatureScale temperatureScale = getTemperatureScale();
    String temperatureScaleDegree = res.getString(temperatureScale
        .getDisplayResourceId());
    String temperatureInfo = MiscMethods.formatDoubleValue(temperature
        .getNightTemperature(temperatureScale))
        + temperatureScaleDegree;
    temperatureInfo += "\n"
        + MiscMethods.formatDoubleValue(temperature
            .getMorningTemperature(temperatureScale))
        + temperatureScaleDegree;
    return temperatureInfo += "\n"
        + MiscMethods.formatDoubleValue(temperature
            .getEveningTemperature(temperatureScale))
        + temperatureScaleDegree;
  }

}




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