public void createWeatherView(JSONObject data, boolean createCache) { try { SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHH", Locale.US); df.setTimeZone(TimeZone.getTimeZone("GMT+0")); Date reportTime = df.parse(data.getString("init")); SimpleDateFormat df2 = new SimpleDateFormat("yyyy-MM-dd HH:mm 'UTC'Z", Locale.US); updatetimeTextView.setText(df2.format(reportTime)); if (createCache) { cacheManager.createWeatherCache(longitude, latitude, reportTime, data.toString()); } WeatherView wv = new WeatherView(longitude, latitude, reportTime, userPrefs.isUseCen()); wv.setData(data); forecastScrollView.removeAllViews(); forecastScrollView.addView(wv.getView(context)); weatherUpdated = true; if (SettingsProvider.getInstance(context).isNewLaunch()) { Toast.makeText(getApplicationContext(), R.string.toast_cloud_info, Toast.LENGTH_LONG) .show(); } } catch (ParseException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } }
@Override public void onTaskFinished(Object sender, TaskFinishedEvent event) { Log.d("deepsky", "Task finished"); TaskContext taskContext = event.getContext(); String response = (String) taskContext.get(SatelliteTask.KEY_RESULT); long delay = (Long) taskContext.get(Task.KEY_END_TIME) - (Long) taskContext.get(Task.KEY_START_TIME); cacheManager.createSatelliteCache(longitude, latitude, response); try { JSONObject data = new JSONObject(response); SatelliteView sv = new SatelliteView(context, satelliteView); sv.setData(data); satelliteUpdated = true; } catch (JSONException e) { Toast.makeText(context, R.string.toast_data_error, Toast.LENGTH_SHORT).show(); } finally { refreshDialog.dismiss(); } StatManager.getInstance().sendSatelliteStat(delay); }
private void startSatelliteTask() { JSONObject data = cacheManager.getSatelliteCache(longitude, latitude, 0.5); if (data != null && !satelliteCacheExpired(data)) { SatelliteView sv = new SatelliteView(context, satelliteView); sv.setData(data); satelliteUpdated = true; } else { if (!NetworkManager.isNetworkAvailable()) { Toast.makeText(this.context, R.string.toast_without_network, Toast.LENGTH_SHORT).show(); return; } refreshDialog.show(); TaskContext taskContext = new TaskContext(); SatelliteTask issTask = new SatelliteTask(); issTask.addTaskListener(new WeakReference<Task.OnTaskListener>(satTaskListener)); taskContext.set(SatelliteTask.KEY_LAT, latitude); taskContext.set(SatelliteTask.KEY_LON, longitude); taskContext.set(SatelliteTask.KEY_START_TIME, System.currentTimeMillis()); issTask.execute(taskContext); } }
private void startWeatherTask() { JSONObject cache = cacheManager.getWeatherCache(longitude, latitude, 10.0 / 24.0); if (cache != null) { createWeatherView(cache, false); } else { if (!NetworkManager.isNetworkAvailable()) { Toast.makeText(this.context, R.string.toast_without_network, Toast.LENGTH_SHORT).show(); return; } refreshDialog.show(); TaskContext taskContext = new TaskContext(); taskContext.set(WeatherTask.KEY_URL, ConfigUtil.getString(Keys.HTTP_REAL_SERVER)); taskContext.set(WeatherTask.KEY_LON, longitude); taskContext.set(WeatherTask.KEY_LAT, latitude); taskContext.set(WeatherTask.KEY_START_TIME, System.currentTimeMillis()); WeatherTask task = new WeatherTask(); task.addTaskListener(new WeakReference<Task.OnTaskListener>(weatherTaskListener)); task.execute(taskContext); } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); this.context = this; this.cacheManager = CacheManager.getInstance(context); this.reportMode = MODE_WEATHER; this.exitTime = 0L; this.reportsViewPager = (CustomerViewPager) findViewById(R.id.viewpager_reports); this.updateButton = (ImageButton) findViewById(R.id.button_update); this.locationButton = (ImageButton) findViewById(R.id.button_location); this.settingsButton = (ImageButton) findViewById(R.id.button_settings); this.switchReportButton = (ImageButton) findViewById(R.id.button_switch_report); this.updatetimeTextView = (TextView) findViewById(R.id.textview_updatetime); this.locationTextView = (TextView) findViewById(R.id.textview_location); LayoutInflater inflater = LayoutInflater.from(context); weatherView = inflater.inflate(R.layout.linearlayout_weather, null); satelliteView = inflater.inflate(R.layout.linearlayout_satellite, null); this.forecastScrollView = (HorizontalScrollView) weatherView.findViewById(R.id.scrollview_forecast); this.templabelTextView = (TextView) weatherView.findViewById(R.id.textview_templabel); reportsViewList = new ArrayList<View>(); reportsViewList.add(weatherView); reportsViewList.add(satelliteView); reportsViewPager.setScrollable(false); reportsViewPager.setSwitchDuration(700); reportsViewPager.setAdapter(pagerAdapter); this.refreshDialog = DialogManager.createRefreshDialog(context); loadSettings(); StatManager.getInstance().sendStartApp(null); UmengUpdateAgent.update(this); }
@Override protected void onDestroy() { cacheManager.close(); super.onDestroy(); }