MeteoSystem/app/src/main/java/cc/pogoda/mobile/pogodacc/activity/StationDetailsWindRoseActiv...

81 wiersze
2.8 KiB
Java
Czysty Zwykły widok Historia

2020-12-19 08:51:34 +00:00
package cc.pogoda.mobile.pogodacc.activity;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
2020-12-28 22:56:50 +00:00
import android.os.Handler;
2020-12-19 08:51:34 +00:00
import cc.pogoda.mobile.pogodacc.R;
2020-12-28 22:56:50 +00:00
import cc.pogoda.mobile.pogodacc.activity.updater.StationDetailsValuesUpdater;
import cc.pogoda.mobile.pogodacc.dao.SummaryDao;
import cc.pogoda.mobile.pogodacc.type.StationWindRoseActElements;
import cc.pogoda.mobile.pogodacc.type.WeatherStation;
import cc.pogoda.mobile.pogodacc.type.web.Summary;
2020-12-19 08:51:34 +00:00
public class StationDetailsWindRoseActivity extends AppCompatActivity {
2020-12-28 22:56:50 +00:00
WeatherStation station;
Summary summary;
StationDetailsValuesUpdater updater = null;
Handler handler = null;
StationWindRoseActElements elements;
public StationDetailsWindRoseActivity() {
}
2020-12-19 08:51:34 +00:00
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_station_details_wind_rose);
2020-12-28 22:56:50 +00:00
station = (WeatherStation) getIntent().getSerializableExtra("station");
// find all elements in the xml layout file and set the references in a holding object
2020-12-28 22:56:50 +00:00
elements = new StationWindRoseActElements();
elements.windArrow = findViewById(R.id.imageViewWindRoseArrow);
2021-12-09 20:38:54 +00:00
elements.windSpeed = findViewById(R.id.textViewWindRoseWindSpeedValue);
elements.windGusts = findViewById(R.id.textViewWindRoseWindGustsValue);
elements.windDirection = findViewById(R.id.textViewWindRoseWindDirectionValue);
elements.temperature = findViewById(R.id.textViewWindRoseTemperaturaValue);
elements.maxGust = findViewById(R.id.textViewWindRoseMaxHourGust);
elements.minAverage = findViewById(R.id.textViewWindRoseMinHourSpeed);
elements.pressure = findViewById(R.id.textViewWindRosePressure);
2020-12-28 22:56:50 +00:00
elements.setActivity(this);
// create the handler which will update the screen in background
2020-12-28 22:56:50 +00:00
handler = new Handler();
SummaryDao summary_dao = new SummaryDao();
// get the set of current values to preconfigure all elements on this activity
summary = summary_dao.getStationSummary(station.getSystemName());
// update parameters (like turn the wind direction arrow)
2021-01-07 07:27:55 +00:00
elements.updateFromSummary(summary, station.getAvailableParameters());
2020-12-28 22:56:50 +00:00
handler = new Handler();
updater = new StationDetailsValuesUpdater(elements, handler, station.getSystemName(), station);
2020-12-28 22:56:50 +00:00
if (handler != null && updater != null) {
// start the handler to update the wind rose activity in background
2020-12-28 22:56:50 +00:00
handler.post(updater);
}
}
@Override
protected void onStop() {
// remove and stop background callback
2020-12-28 22:56:50 +00:00
if (handler != null && updater != null) {
handler.removeCallbacks(updater);
}
super.onStop();
2020-12-19 08:51:34 +00:00
}
}