- mForecastAdapter = forecastAdapter;
- }
-
- private boolean DEBUG = true;
-
- /* The date/time conversion code is going to be moved outside the asynctask later,
- * so for convenience we're breaking it out into its own method now.
- */
- private String getReadableDateString(long time) {
- // Because the API returns a unix timestamp (measured in seconds),
- // it must be converted to milliseconds in order to be converted to valid date.
- Date date = new Date(time * 1000);
- SimpleDateFormat format = new SimpleDateFormat("E, MMM d");
- return format.format(date).toString();
- }
-
- /**
- * Prepare the weather high/lows for presentation.
- */
- private String formatHighLows(double high, double low) {
- // Data is fetched in Celsius by default.
- // If user prefers to see in Fahrenheit, convert the values here.
- // We do this rather than fetching in Fahrenheit so that the user can
- // change this option without us having to re-fetch the data once
- // we start storing the values in a database.
- SharedPreferences sharedPrefs =
- PreferenceManager.getDefaultSharedPreferences(mContext);
- String unitType = sharedPrefs.getString(
- mContext.getString(R.string.pref_units_key),
- mContext.getString(R.string.pref_units_metric));
-
- if (unitType.equals(mContext.getString(R.string.pref_units_imperial))) {
- high = (high * 1.8) + 32;
- low = (low * 1.8) + 32;
- } else if (!unitType.equals(mContext.getString(R.string.pref_units_metric))) {
- Log.d(LOG_TAG, "Unit type not found: " + unitType);
- }
-
- // For presentation, assume the user doesn't care about tenths of a degree.
- long roundedHigh = Math.round(high);
- long roundedLow = Math.round(low);
-
- String highLowStr = roundedHigh + "/" + roundedLow;
- return highLowStr;