This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void onLocationChanged( String newLocation ) { | |
// replace the uri, since the location has changed | |
Uri uri = mUri; | |
if (null != uri) { | |
long date = WeatherContract.WeatherEntry.getDateFromUri(uri); | |
Uri updatedUri = WeatherContract.WeatherEntry.buildWeatherLocationWithDate(newLocation, date); | |
mUri = updatedUri; | |
getLoaderManager().restartLoader(DETAIL_LOADER, null, this); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:baselineAligned="false" | |
android:divider="?android:attr/dividerHorizontal" | |
android:orientation="horizontal" | |
tools:context="com.example.android.sunshine.app.MainActivity"> | |
<!-- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int viewType = getItemViewType(cursor.getPosition()); | |
switch (viewType) { | |
case VIEW_TYPE_TODAY: { | |
// Get weather icon | |
viewHolder.iconView.setImageResource(Utility.getArtResourceForWeatherCondition( | |
cursor.getInt(ForecastFragment.COL_WEATHER_CONDITION_ID))); | |
break; | |
} | |
case VIEW_TYPE_FUTURE_DAY: { | |
// Get weather icon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static int getIconResourceForWeatherCondition(int weatherId) { | |
// Based on weather code data found at: | |
// http://bugs.openweathermap.org/projects/api/wiki/Weather_Condition_Codes | |
if (weatherId >= 200 && weatherId <= 232) { | |
return R.drawable.ic_storm; | |
} else if (weatherId >= 300 && weatherId <= 321) { | |
return R.drawable.ic_light_rain; | |
} else if (weatherId >= 500 && weatherId <= 504) { | |
return R.drawable.ic_rain; | |
} else if (weatherId == 511) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Windspeed formats --> | |
<!-- Wind in mph [CHAR LIMIT=25] --> | |
<string name="format_wind_mph">Wind: <xliff:g id="speed">%1$1.0f</xliff:g> mph <xliff:g id="direction">%2$s</xliff:g></string> | |
<!-- Wind in kph [CHAR LIMIT=25] --> | |
<string name="format_wind_kmh">Wind: <xliff:g id="speed">%1$1.0f</xliff:g> km/h <xliff:g id="direction">%2$s</xliff:g></string> | |
<!-- Pressure format CHAR LIMIT=25] --> | |
<string name="format_pressure">Pressure: <xliff:g id="pressure">%1.0f</xliff:g> hPa</string> | |
<!-- Humidity format CHAR LIMIT=25]--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Master layout. --> | |
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:orientation="vertical" | |
android:padding="16dp"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String getFormattedWind(Context context, float windSpeed, float degrees) { | |
int windFormat; | |
if (Utility.isMetric(context)) { | |
windFormat = R.string.format_wind_kmh; | |
} else { | |
windFormat = R.string.format_wind_mph; | |
windSpeed = .621371192237334f * windSpeed; | |
} | |
// From wind direction in degrees, determine compass direction as a string (e.g NW) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DetailFragment extends Fragment implements LoaderManager.LoaderCallbacks<Cursor> { | |
private static final String LOG_TAG = DetailFragment.class.getSimpleName(); | |
private static final String FORECAST_SHARE_HASHTAG = " #SunshineApp"; | |
private ShareActionProvider mShareActionProvider; | |
private String mForecast; | |
private static final int DETAIL_LOADER = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class ViewHolder { | |
public final ImageView iconView; | |
public final TextView dateView; | |
public final TextView descriptionView; | |
public final TextView highTempView; | |
public final TextView lowTempView; | |
public ViewHolder(View view) { | |
iconView = (ImageView) view.findViewById(R.id.list_item_icon); | |
dateView = (TextView) view.findViewById(R.id.list_item_date_textview); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Date label when displaying today's weather forecast [CHAR LIMIT=20] --> | |
<string name="today">Today</string> | |
<!-- Date label when displaying tomorrow's weather forecast [CHAR LIMIT=20] --> | |
<string name="tomorrow">Tomorrow</string> | |
<!-- Date format for displaying day of week and date (i.e. Mon Jun 1) [CHAR LIMIT=20] --> | |
<string name="format_full_friendly_date"><xliff:g id="day">%1$s</xliff:g>, <xliff:g id="date">%2$s</xliff:g></string> | |
<!-- Strings for formatting weather-related data --> |
NewerOlder