2424import android .support .v4 .content .CursorLoader ;
2525import android .support .v4 .content .Loader ;
2626import android .support .v4 .view .MenuItemCompat ;
27+ import android .support .v7 .app .AppCompatActivity ;
2728import android .support .v7 .widget .ShareActionProvider ;
29+ import android .support .v7 .widget .Toolbar ;
2830import android .view .LayoutInflater ;
2931import android .view .Menu ;
3032import android .view .MenuInflater ;
@@ -84,14 +86,16 @@ public class DetailFragment extends Fragment implements LoaderManager.LoaderCall
8486 public static final int COL_WEATHER_CONDITION_ID = 9 ;
8587
8688 private ImageView mIconView ;
87- private TextView mFriendlyDateView ;
8889 private TextView mDateView ;
8990 private TextView mDescriptionView ;
9091 private TextView mHighTempView ;
9192 private TextView mLowTempView ;
9293 private TextView mHumidityView ;
94+ private TextView mHumidityLabelView ;
9395 private TextView mWindView ;
96+ private TextView mWindLabelView ;
9497 private TextView mPressureView ;
98+ private TextView mPressureLabelView ;
9599
96100 public DetailFragment () {
97101 setHasOptionsMenu (true );
@@ -109,30 +113,30 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
109113 View rootView = inflater .inflate (R .layout .fragment_detail , container , false );
110114 mIconView = (ImageView ) rootView .findViewById (R .id .detail_icon );
111115 mDateView = (TextView ) rootView .findViewById (R .id .detail_date_textview );
112- mFriendlyDateView = (TextView ) rootView .findViewById (R .id .detail_day_textview );
113116 mDescriptionView = (TextView ) rootView .findViewById (R .id .detail_forecast_textview );
114117 mHighTempView = (TextView ) rootView .findViewById (R .id .detail_high_textview );
115118 mLowTempView = (TextView ) rootView .findViewById (R .id .detail_low_textview );
116119 mHumidityView = (TextView ) rootView .findViewById (R .id .detail_humidity_textview );
120+ mHumidityLabelView = (TextView ) rootView .findViewById (R .id .detail_humidity_label_textview );
117121 mWindView = (TextView ) rootView .findViewById (R .id .detail_wind_textview );
122+ mWindLabelView = (TextView ) rootView .findViewById (R .id .detail_wind_label_textview );
118123 mPressureView = (TextView ) rootView .findViewById (R .id .detail_pressure_textview );
124+ mPressureLabelView = (TextView ) rootView .findViewById (R .id .detail_pressure_label_textview );
119125 return rootView ;
120126 }
121127
122- @ Override
123- public void onCreateOptionsMenu (Menu menu , MenuInflater inflater ) {
124- // Inflate the menu; this adds items to the action bar if it is present.
125- inflater .inflate (R .menu .detailfragment , menu );
126-
128+ private void finishCreatingMenu (Menu menu ) {
127129 // Retrieve the share menu item
128130 MenuItem menuItem = menu .findItem (R .id .action_share );
131+ menuItem .setIntent (createShareForecastIntent ());
132+ }
129133
130- // Get the provider and hold onto it to set/change the share intent.
131- mShareActionProvider = ( ShareActionProvider ) MenuItemCompat . getActionProvider ( menuItem );
132-
133- // If onLoadFinished happens before this, we can go ahead and set the share intent now .
134- if ( mForecast != null ) {
135- mShareActionProvider . setShareIntent ( createShareForecastIntent () );
134+ @ Override
135+ public void onCreateOptionsMenu ( Menu menu , MenuInflater inflater ) {
136+ if ( getActivity () instanceof DetailActivity ){
137+ // Inflate the menu; this adds items to the action bar if it is present .
138+ inflater . inflate ( R . menu . detailfragment , menu );
139+ finishCreatingMenu ( menu );
136140 }
137141 }
138142
@@ -184,18 +188,20 @@ public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
184188 // Read weather condition ID from cursor
185189 int weatherId = data .getInt (COL_WEATHER_CONDITION_ID );
186190
187- // Use weather art image
188- Glide .with (this )
189- .load (Utility .getArtUrlForWeatherCondition (getActivity (), weatherId ))
190- .error (Utility .getArtResourceForWeatherCondition (weatherId ))
191- .crossFade ()
192- .into (mIconView );
191+ if ( Utility .usingLocalGraphics (getActivity ()) ) {
192+ mIconView .setImageResource (Utility .getArtResourceForWeatherCondition (weatherId ));
193+ } else {
194+ // Use weather art image
195+ Glide .with (this )
196+ .load (Utility .getArtUrlForWeatherCondition (getActivity (), weatherId ))
197+ .error (Utility .getArtResourceForWeatherCondition (weatherId ))
198+ .crossFade ()
199+ .into (mIconView );
200+ }
193201
194202 // Read date from cursor and update views for day of week and date
195203 long date = data .getLong (COL_WEATHER_DATE );
196- String friendlyDateText = Utility .getDayName (getActivity (), date );
197- String dateText = Utility .getFormattedMonthDay (getActivity (), date );
198- mFriendlyDateView .setText (friendlyDateText );
204+ String dateText = Utility .getFullFriendlyDayString (getActivity (),date );
199205 mDateView .setText (dateText );
200206
201207 // Get description from weather condition ID
@@ -226,18 +232,21 @@ public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
226232 // Read humidity from cursor and update view
227233 float humidity = data .getFloat (COL_WEATHER_HUMIDITY );
228234 mHumidityView .setText (getActivity ().getString (R .string .format_humidity , humidity ));
229- mHumidityView .setContentDescription (mHumidityView .getText ());
235+ mHumidityView .setContentDescription (getString (R .string .a11y_humidity , mHumidityView .getText ()));
236+ mHumidityLabelView .setContentDescription (mHumidityView .getContentDescription ());
230237
231238 // Read wind speed and direction from cursor and update view
232239 float windSpeedStr = data .getFloat (COL_WEATHER_WIND_SPEED );
233240 float windDirStr = data .getFloat (COL_WEATHER_DEGREES );
234241 mWindView .setText (Utility .getFormattedWind (getActivity (), windSpeedStr , windDirStr ));
235- mWindView .setContentDescription (mWindView .getText ());
242+ mWindView .setContentDescription (getString (R .string .a11y_wind , mWindView .getText ()));
243+ mWindLabelView .setContentDescription (mWindView .getContentDescription ());
236244
237245 // Read pressure from cursor and update view
238246 float pressure = data .getFloat (COL_WEATHER_PRESSURE );
239- mPressureView .setText (getActivity ().getString (R .string .format_pressure , pressure ));
240- mPressureView .setContentDescription (mPressureView .getText ());
247+ mPressureView .setText (getString (R .string .format_pressure , pressure ));
248+ mPressureView .setContentDescription (getString (R .string .a11y_pressure , mPressureView .getText ()));
249+ mPressureLabelView .setContentDescription (mPressureView .getContentDescription ());
241250
242251 // We still need this for the share intent
243252 mForecast = String .format ("%s - %s - %s/%s" , dateText , description , high , low );
@@ -247,6 +256,27 @@ public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
247256 mShareActionProvider .setShareIntent (createShareForecastIntent ());
248257 }
249258 }
259+ AppCompatActivity activity = (AppCompatActivity )getActivity ();
260+ Toolbar toolbarView = (Toolbar ) getView ().findViewById (R .id .toolbar );
261+
262+ // We need to start the enter transition after the data has loaded
263+ if (activity instanceof DetailActivity ) {
264+ activity .supportStartPostponedEnterTransition ();
265+
266+ if ( null != toolbarView ) {
267+ activity .setSupportActionBar (toolbarView );
268+
269+ activity .getSupportActionBar ().setDisplayShowTitleEnabled (false );
270+ activity .getSupportActionBar ().setDisplayHomeAsUpEnabled (true );
271+ }
272+ } else {
273+ if ( null != toolbarView ) {
274+ Menu menu = toolbarView .getMenu ();
275+ if ( null != menu ) menu .clear ();
276+ toolbarView .inflateMenu (R .menu .detailfragment );
277+ finishCreatingMenu (toolbarView .getMenu ());
278+ }
279+ }
250280 }
251281
252282 @ Override
0 commit comments