public void onEventMainThread(TemperatureEvent event) { temperatureTxt.setText(Helper.formatTemperature(event.getTemperature())); }
public void updateForecastOnUi(HashMap<String, String> map) { if (rootView != null && map.size() > 2) { // update image Resources res = getResources(); int resourceId = res.getIdentifier( "open" + map.get(Helper.TAG_WEATHER_IMAGE), "drawable", getActivity().getApplicationContext().getPackageName()); Drawable drawable = res.getDrawable(resourceId); imageView.setImageDrawable(drawable); // update description TextView basicWeatherDescriptionTextView = (TextView) rootView.findViewById(R.id.basicWeather); basicWeatherDescriptionTextView.setText( helper.capitalize(map.get(Helper.TAG_WEATHER_DESCRIPTION))); basicWeatherDescriptionTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18); // update temperature TextView temperatureTextView = (TextView) rootView.findViewById(R.id.temperature); temperatureTextView.setText(helper.formatTemperature(map.get(Helper.TAG_TEMP))); temperatureTextView.setGravity(Gravity.CENTER_VERTICAL); // update time DateFormat df = new SimpleDateFormat("EEE, d MMM yyyy, HH:mm"); String date = df.format(Calendar.getInstance().getTime()); dateTime = (TextView) rootView.findViewById(R.id.dateTime); dateTime.setText(date); String[] forecastDescriptions = helper.getForecastDescriptions(); String[] tagNames = helper.getTagNames(); String[] tagUnits = helper.getForecastUnits(); MyExpandableHeightGridView gridView = (MyExpandableHeightGridView) rootView.findViewById(R.id.gridview); gridView.setExpanded(true); // create the grid item mapping String[] from = new String[] {"forecast_name", "value"}; int[] to = new int[] {R.id.item1, R.id.item2}; // prepare the list of all records List<HashMap<String, String>> fillMaps = new ArrayList<HashMap<String, String>>(); // first add the wind separately HashMap<String, String> windSpeedToFill = new HashMap<String, String>(); windSpeedToFill.put("forecast_name", "Wind speed"); windSpeedToFill.put("value", map.get(Helper.TAG_WINDSP) + " " + Helper.UNIT_WIND_SPEED); fillMaps.add(windSpeedToFill); HashMap<String, String> windDirToFill = new HashMap<String, String>(); windDirToFill.put("forecast_name", "Wind direction"); windDirToFill.put("value", helper.windDegreesToDirection(map.get(Helper.TAG_WINDDIR))); fillMaps.add(windDirToFill); for (int i = 0; i < forecastDescriptions.length; i++) { HashMap<String, String> mapToFill = new HashMap<String, String>(); mapToFill.put("forecast_name", forecastDescriptions[i]); mapToFill.put("value", map.get(tagNames[i]) + " " + tagUnits[i]); fillMaps.add(mapToFill); } // fill in the grid_item layout MySimpleAdapter adapter = new MySimpleAdapter(getActivity(), fillMaps, R.layout.grid_item, from, to); gridView.setAdapter(adapter); // fill in the homeNext layout firstLine = (TextView) rootView.findViewById(R.id.homeNext_firstLine); secondLine = (TextView) rootView.findViewById(R.id.homeNext_secondLine); thirdLine = (TextView) rootView.findViewById(R.id.homeNext_thirdLine); forthLine = (TextView) rootView.findViewById(R.id.homeNext_forthLine); nextImageView = (ImageView) rootView.findViewById(R.id.homeNext_icon); nextImageView.setImageResource( getResources() .getIdentifier( "open" + mapToFillHomeNext.get(Helper.TAG_WEATHER_IMAGE), "drawable", getActivity().getApplicationContext().getPackageName())); firstLine.setText(mapToFillHomeNext.get("formattedDate")); secondLine.setText( helper.formatTemperature(mapToFillHomeNext.get(Helper.TAG_TEMP)) + " " + helper.capitalize(mapToFillHomeNext.get(Helper.TAG_WEATHER_DESCRIPTION))); thirdLine.setText( Html.fromHtml( "<b>Wind:</b> " + mapToFillHomeNext.get(Helper.TAG_WINDSP) + " " + Helper.UNIT_WIND_SPEED + " " + helper.windDegreesToDirection(mapToFillHomeNext.get(Helper.TAG_WINDDIR)) + " <b>Pressure:</b> " + mapToFillHomeNext.get(Helper.TAG_MSLP) + " " + Helper.UNIT_MSLP)); if (!mapToFillHomeNext.get(Helper.TAG_SNOW).equals("0.0")) { forthLine.setText( Html.fromHtml( "<b>Snow:</b> " + mapToFillHomeNext.get(Helper.TAG_RAIN) + " " + Helper.UNIT_SNOW + " <b>Humidity:</b> " + mapToFillHomeNext.get(Helper.TAG_RELHUM) + " " + Helper.UNIT_RELHUM)); } else if (!mapToFillHomeNext.get(Helper.TAG_RAIN).equals("0.0")) { forthLine.setText( Html.fromHtml( "<b>Rain:</b> " + mapToFillHomeNext.get(Helper.TAG_RAIN) + " " + Helper.UNIT_RAIN + " <b>Humidity:</b> " + mapToFillHomeNext.get(Helper.TAG_RELHUM) + " " + Helper.UNIT_RELHUM)); } else { forthLine.setText( Html.fromHtml( "<b>Humidity:</b> " + mapToFillHomeNext.get(Helper.TAG_RELHUM) + " " + Helper.UNIT_RELHUM)); } homeNext.setVisibility(View.VISIBLE); // show current lan/lon for beta testers /*TextView debug = (TextView) rootView.findViewById(R.id.debug); debug.setText(Html.fromHtml("device lat: " + mLastLocation.getLatitude() + " lon: " + mLastLocation.getLongitude() + "<br>server lat: " + map.get(Helper.TAG_LAT) + " lon: " + map.get(Helper.TAG_LON)));*/ } }