kopia lustrzana https://github.com/SP8EBC/MeteoSystem
shortened delay after values on favourites list are updated, chenges with plots
rodzic
a05a11988a
commit
6566b24b15
|
@ -31,6 +31,7 @@
|
||||||
<activity android:name=".activity.StationDetailsPlotsWind" />
|
<activity android:name=".activity.StationDetailsPlotsWind" />
|
||||||
<activity android:name=".activity.StationDetailsPlotsDirection" />
|
<activity android:name=".activity.StationDetailsPlotsDirection" />
|
||||||
<activity android:name=".activity.StationDetailsPlotsTemperature" />
|
<activity android:name=".activity.StationDetailsPlotsTemperature" />
|
||||||
|
<activity android:name=".activity.StationDetailsPlotsHumidity" />
|
||||||
<activity android:name=".activity.StationDetailsSummaryActivity" />
|
<activity android:name=".activity.StationDetailsSummaryActivity" />
|
||||||
<activity android:name=".activity.StationDetailsActivity" />
|
<activity android:name=".activity.StationDetailsActivity" />
|
||||||
<activity android:name=".activity.AllStationsActivity" />
|
<activity android:name=".activity.AllStationsActivity" />
|
||||||
|
|
|
@ -28,6 +28,7 @@ import org.greenrobot.eventbus.EventBus;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import cc.pogoda.mobile.pogodacc.R;
|
import cc.pogoda.mobile.pogodacc.R;
|
||||||
|
import cc.pogoda.mobile.pogodacc.activity.handler.StationDetailsActHumidityPlotButtonClickEvent;
|
||||||
import cc.pogoda.mobile.pogodacc.activity.handler.StationDetailsActTemperaturePlotButtonClickEvent;
|
import cc.pogoda.mobile.pogodacc.activity.handler.StationDetailsActTemperaturePlotButtonClickEvent;
|
||||||
import cc.pogoda.mobile.pogodacc.activity.handler.StationDetailsActTrendButtonClickEvent;
|
import cc.pogoda.mobile.pogodacc.activity.handler.StationDetailsActTrendButtonClickEvent;
|
||||||
import cc.pogoda.mobile.pogodacc.activity.handler.StationDetailsActWindDirectionPlotsButtonClickEvent;
|
import cc.pogoda.mobile.pogodacc.activity.handler.StationDetailsActWindDirectionPlotsButtonClickEvent;
|
||||||
|
@ -36,6 +37,7 @@ import cc.pogoda.mobile.pogodacc.activity.handler.StationDetailsActSummaryButton
|
||||||
import cc.pogoda.mobile.pogodacc.activity.handler.StationDetailsActWindRoseButtonClickEvent;
|
import cc.pogoda.mobile.pogodacc.activity.handler.StationDetailsActWindRoseButtonClickEvent;
|
||||||
import cc.pogoda.mobile.pogodacc.activity.updater.StationBackgroundImageUpdater;
|
import cc.pogoda.mobile.pogodacc.activity.updater.StationBackgroundImageUpdater;
|
||||||
import cc.pogoda.mobile.pogodacc.config.AppConfiguration;
|
import cc.pogoda.mobile.pogodacc.config.AppConfiguration;
|
||||||
|
import cc.pogoda.mobile.pogodacc.type.AvailableParameters;
|
||||||
import cc.pogoda.mobile.pogodacc.type.WeatherStation;
|
import cc.pogoda.mobile.pogodacc.type.WeatherStation;
|
||||||
import cc.pogoda.mobile.pogodacc.type.WeatherStationListEvent;
|
import cc.pogoda.mobile.pogodacc.type.WeatherStationListEvent;
|
||||||
import cc.pogoda.mobile.pogodacc.web.StationBackgroundDownloader;
|
import cc.pogoda.mobile.pogodacc.web.StationBackgroundDownloader;
|
||||||
|
@ -54,11 +56,14 @@ public class StationDetailsActivity extends AppCompatActivity {
|
||||||
ImageButton windSpeedPlotsButton = null;
|
ImageButton windSpeedPlotsButton = null;
|
||||||
ImageButton windDirectionPlotsButton = null;
|
ImageButton windDirectionPlotsButton = null;
|
||||||
ImageButton temperatureButton = null;
|
ImageButton temperatureButton = null;
|
||||||
|
ImageButton humidityButton = null;
|
||||||
ImageButton windRoseButton = null;
|
ImageButton windRoseButton = null;
|
||||||
ImageButton trendButton = null;
|
ImageButton trendButton = null;
|
||||||
|
|
||||||
ImageView topBackground = null;
|
ImageView topBackground = null;
|
||||||
|
|
||||||
|
AppCompatActivity act;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Click event on Station Summary Button
|
* Click event on Station Summary Button
|
||||||
*/
|
*/
|
||||||
|
@ -73,6 +78,8 @@ public class StationDetailsActivity extends AppCompatActivity {
|
||||||
|
|
||||||
StationDetailsActTemperaturePlotButtonClickEvent temperaturePlotButtonClickEvent = null;
|
StationDetailsActTemperaturePlotButtonClickEvent temperaturePlotButtonClickEvent = null;
|
||||||
|
|
||||||
|
StationDetailsActHumidityPlotButtonClickEvent humidityPlotButtonClickEvent = null;
|
||||||
|
|
||||||
StationDetailsActTrendButtonClickEvent trendButtonClickEvent = null;
|
StationDetailsActTrendButtonClickEvent trendButtonClickEvent = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -159,10 +166,14 @@ public class StationDetailsActivity extends AppCompatActivity {
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
act = this;
|
||||||
|
|
||||||
setContentView(R.layout.activity_station_details);
|
setContentView(R.layout.activity_station_details);
|
||||||
|
|
||||||
station = (WeatherStation) getIntent().getSerializableExtra("station");
|
station = (WeatherStation) getIntent().getSerializableExtra("station");
|
||||||
|
|
||||||
|
AvailableParameters parameters = station.getAvailableParameters();
|
||||||
|
|
||||||
stationName = findViewById(R.id.textViewStationName);
|
stationName = findViewById(R.id.textViewStationName);
|
||||||
stationLocation = findViewById(R.id.textViewLocalization);
|
stationLocation = findViewById(R.id.textViewLocalization);
|
||||||
stationLatLon = findViewById(R.id.textViewLatLon);
|
stationLatLon = findViewById(R.id.textViewLatLon);
|
||||||
|
@ -193,6 +204,7 @@ public class StationDetailsActivity extends AppCompatActivity {
|
||||||
windSpeedPlotsClickEvent = new StationDetailsActWindSpeedPlotsButtonClickEvent(station, this);
|
windSpeedPlotsClickEvent = new StationDetailsActWindSpeedPlotsButtonClickEvent(station, this);
|
||||||
windDirectionPlotsClickEvent = new StationDetailsActWindDirectionPlotsButtonClickEvent(station, this);
|
windDirectionPlotsClickEvent = new StationDetailsActWindDirectionPlotsButtonClickEvent(station, this);
|
||||||
temperaturePlotButtonClickEvent = new StationDetailsActTemperaturePlotButtonClickEvent(station, this);
|
temperaturePlotButtonClickEvent = new StationDetailsActTemperaturePlotButtonClickEvent(station, this);
|
||||||
|
humidityPlotButtonClickEvent = new StationDetailsActHumidityPlotButtonClickEvent(station, this);
|
||||||
windRoseClickEvent = new StationDetailsActWindRoseButtonClickEvent(station, this);
|
windRoseClickEvent = new StationDetailsActWindRoseButtonClickEvent(station, this);
|
||||||
trendButtonClickEvent = new StationDetailsActTrendButtonClickEvent(station, this);
|
trendButtonClickEvent = new StationDetailsActTrendButtonClickEvent(station, this);
|
||||||
|
|
||||||
|
@ -200,10 +212,43 @@ public class StationDetailsActivity extends AppCompatActivity {
|
||||||
summaryButton.setOnClickListener(summaryClickEvent);
|
summaryButton.setOnClickListener(summaryClickEvent);
|
||||||
|
|
||||||
windSpeedPlotsButton = findViewById(R.id.imageButtonPlotsWindSpeed);
|
windSpeedPlotsButton = findViewById(R.id.imageButtonPlotsWindSpeed);
|
||||||
|
if (parameters.windSpeed) {
|
||||||
windSpeedPlotsButton.setOnClickListener(windSpeedPlotsClickEvent);
|
windSpeedPlotsButton.setOnClickListener(windSpeedPlotsClickEvent);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
windSpeedPlotsButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(act);
|
||||||
|
builder.setMessage(R.string.station_doesnt_measure);
|
||||||
|
builder.setPositiveButton(R.string.ok, (DialogInterface var1, int var2) -> {
|
||||||
|
var1.dismiss();
|
||||||
|
});
|
||||||
|
builder.create();
|
||||||
|
builder.show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
windDirectionPlotsButton = findViewById(R.id.imageButtonPlotsWindDirection);
|
windDirectionPlotsButton = findViewById(R.id.imageButtonPlotsWindDirection);
|
||||||
|
if (parameters.windSpeed) {
|
||||||
windDirectionPlotsButton.setOnClickListener(windDirectionPlotsClickEvent);
|
windDirectionPlotsButton.setOnClickListener(windDirectionPlotsClickEvent);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
windDirectionPlotsButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(act);
|
||||||
|
builder.setMessage(R.string.station_doesnt_measure);
|
||||||
|
builder.setPositiveButton(R.string.ok, (DialogInterface var1, int var2) -> {
|
||||||
|
var1.dismiss();
|
||||||
|
});
|
||||||
|
builder.create();
|
||||||
|
builder.show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
windRoseButton = findViewById(R.id.imageButtonWindRose);
|
windRoseButton = findViewById(R.id.imageButtonWindRose);
|
||||||
windRoseButton.setOnClickListener(windRoseClickEvent);
|
windRoseButton.setOnClickListener(windRoseClickEvent);
|
||||||
|
@ -211,6 +256,25 @@ public class StationDetailsActivity extends AppCompatActivity {
|
||||||
temperatureButton = findViewById(R.id.imageButtonPlotsTemperature);
|
temperatureButton = findViewById(R.id.imageButtonPlotsTemperature);
|
||||||
temperatureButton.setOnClickListener(temperaturePlotButtonClickEvent);
|
temperatureButton.setOnClickListener(temperaturePlotButtonClickEvent);
|
||||||
|
|
||||||
|
humidityButton = findViewById(R.id.imageButtonPlotsHumidity);
|
||||||
|
if (parameters.humidity) {
|
||||||
|
humidityButton.setOnClickListener(humidityPlotButtonClickEvent);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
humidityButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(act);
|
||||||
|
builder.setMessage(R.string.station_doesnt_measure);
|
||||||
|
builder.setPositiveButton(R.string.ok, (DialogInterface var1, int var2) -> {
|
||||||
|
var1.dismiss();
|
||||||
|
});
|
||||||
|
builder.create();
|
||||||
|
builder.show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
trendButton = findViewById(R.id.imageButtonTrend);
|
trendButton = findViewById(R.id.imageButtonTrend);
|
||||||
trendButton.setOnClickListener(trendButtonClickEvent);
|
trendButton.setOnClickListener(trendButtonClickEvent);
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ import cc.pogoda.mobile.pogodacc.activity.handler.PlotClickEvent;
|
||||||
import cc.pogoda.mobile.pogodacc.dao.LastStationDataDao;
|
import cc.pogoda.mobile.pogodacc.dao.LastStationDataDao;
|
||||||
import cc.pogoda.mobile.pogodacc.dao.StationDataDao;
|
import cc.pogoda.mobile.pogodacc.dao.StationDataDao;
|
||||||
import cc.pogoda.mobile.pogodacc.type.StationDetailsPlot;
|
import cc.pogoda.mobile.pogodacc.type.StationDetailsPlot;
|
||||||
|
import cc.pogoda.mobile.pogodacc.type.StationSummaryActElements;
|
||||||
import cc.pogoda.mobile.pogodacc.type.WeatherStation;
|
import cc.pogoda.mobile.pogodacc.type.WeatherStation;
|
||||||
import cc.pogoda.mobile.pogodacc.type.web.ListOfStationData;
|
import cc.pogoda.mobile.pogodacc.type.web.ListOfStationData;
|
||||||
import cc.pogoda.mobile.pogodacc.type.web.StationData;
|
import cc.pogoda.mobile.pogodacc.type.web.StationData;
|
||||||
|
@ -70,8 +71,10 @@ public class StationDetailsPlotsDirection extends AppCompatActivity implements S
|
||||||
// and then shift to the user timezone for convinient display
|
// and then shift to the user timezone for convinient display
|
||||||
ZonedDateTime localDateTime = utcDateTime.atZone(ZoneOffset.UTC).withZoneSameInstant(ZoneId.systemDefault());
|
ZonedDateTime localDateTime = utcDateTime.atZone(ZoneOffset.UTC).withZoneSameInstant(ZoneId.systemDefault());
|
||||||
|
|
||||||
|
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("HH:mm");
|
||||||
|
|
||||||
/* format only the time to keep X axis clean */
|
/* format only the time to keep X axis clean */
|
||||||
return DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT).format(localDateTime);
|
return fmt.format(localDateTime);
|
||||||
|
|
||||||
//return dt;
|
//return dt;
|
||||||
}
|
}
|
||||||
|
@ -161,10 +164,13 @@ public class StationDetailsPlotsDirection extends AppCompatActivity implements S
|
||||||
xAxis.setTextColor(Color.WHITE);
|
xAxis.setTextColor(Color.WHITE);
|
||||||
xAxis.setDrawAxisLine(false);
|
xAxis.setDrawAxisLine(false);
|
||||||
xAxis.setDrawGridLines(true);
|
xAxis.setDrawGridLines(true);
|
||||||
xAxis.setTextColor(Color.rgb(255, 192, 56));
|
xAxis.setTextColor(R.color.design_default_color_primary_dark);
|
||||||
xAxis.setCenterAxisLabels(true);
|
xAxis.setCenterAxisLabels(true);
|
||||||
xAxis.setGranularity(1f); // one hour
|
xAxis.setGranularity(100f); // one hour
|
||||||
|
xAxis.setLabelRotationAngle(45.0f);
|
||||||
xAxis.setValueFormatter(new StationDetailsPlotsDirection.ValueFormatter());
|
xAxis.setValueFormatter(new StationDetailsPlotsDirection.ValueFormatter());
|
||||||
|
xAxis.setTextSize(123.0f);
|
||||||
|
xAxis.setCenterAxisLabels(true);
|
||||||
|
|
||||||
YAxis leftAxis = chart.getAxisLeft();
|
YAxis leftAxis = chart.getAxisLeft();
|
||||||
leftAxis.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
|
leftAxis.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
|
||||||
|
@ -173,9 +179,10 @@ public class StationDetailsPlotsDirection extends AppCompatActivity implements S
|
||||||
leftAxis.setDrawGridLines(true);
|
leftAxis.setDrawGridLines(true);
|
||||||
leftAxis.setGranularityEnabled(true);
|
leftAxis.setGranularityEnabled(true);
|
||||||
leftAxis.setAxisMinimum(0.0f);
|
leftAxis.setAxisMinimum(0.0f);
|
||||||
leftAxis.setAxisMaximum(360.0f);
|
leftAxis.setAxisMaximum(400.0f);
|
||||||
leftAxis.setYOffset(0.0f);
|
leftAxis.setYOffset(0.0f);
|
||||||
leftAxis.setTextColor(Color.rgb(255, 192, 56));
|
leftAxis.setTextColor(R.color.design_default_color_primary_dark);
|
||||||
|
leftAxis.setTextSize(123.0f);
|
||||||
|
|
||||||
YAxis rightAxis = chart.getAxisRight();
|
YAxis rightAxis = chart.getAxisRight();
|
||||||
rightAxis.setEnabled(false);
|
rightAxis.setEnabled(false);
|
||||||
|
@ -210,7 +217,7 @@ public class StationDetailsPlotsDirection extends AppCompatActivity implements S
|
||||||
|
|
||||||
if (this.textViewSpeed != null && this.textViewTimestamp != null) {
|
if (this.textViewSpeed != null && this.textViewTimestamp != null) {
|
||||||
this.textViewTimestamp.setText(date);
|
this.textViewTimestamp.setText(date);
|
||||||
this.textViewSpeed.setText(getString(R.string.wind_direction_short) + String.format(": %d", (int)direction));
|
this.textViewSpeed.setText(getString(R.string.wind_direction_short) + String.format(": %d - ", (int)direction) + StationSummaryActElements.convertDegreesToDir((int) direction));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -0,0 +1,348 @@
|
||||||
|
package cc.pogoda.mobile.pogodacc.activity;
|
||||||
|
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.graphics.Typeface;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.widget.SeekBar;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
import com.github.mikephil.charting.charts.LineChart;
|
||||||
|
import com.github.mikephil.charting.components.XAxis;
|
||||||
|
import com.github.mikephil.charting.components.YAxis;
|
||||||
|
import com.github.mikephil.charting.data.Entry;
|
||||||
|
import com.github.mikephil.charting.data.LineData;
|
||||||
|
import com.github.mikephil.charting.data.LineDataSet;
|
||||||
|
import com.github.mikephil.charting.utils.ColorTemplate;
|
||||||
|
|
||||||
|
import org.threeten.bp.LocalDateTime;
|
||||||
|
import org.threeten.bp.ZoneId;
|
||||||
|
import org.threeten.bp.ZoneOffset;
|
||||||
|
import org.threeten.bp.ZonedDateTime;
|
||||||
|
import org.threeten.bp.format.DateTimeFormatter;
|
||||||
|
import org.threeten.bp.format.FormatStyle;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import cc.pogoda.mobile.pogodacc.R;
|
||||||
|
import cc.pogoda.mobile.pogodacc.activity.handler.PlotClickEvent;
|
||||||
|
import cc.pogoda.mobile.pogodacc.dao.LastStationDataDao;
|
||||||
|
import cc.pogoda.mobile.pogodacc.dao.StationDataDao;
|
||||||
|
import cc.pogoda.mobile.pogodacc.type.StationDetailsPlot;
|
||||||
|
import cc.pogoda.mobile.pogodacc.type.WeatherStation;
|
||||||
|
import cc.pogoda.mobile.pogodacc.type.web.ListOfStationData;
|
||||||
|
import cc.pogoda.mobile.pogodacc.type.web.StationData;
|
||||||
|
|
||||||
|
public class StationDetailsPlotsHumidity extends AppCompatActivity implements SeekBar.OnSeekBarChangeListener, StationDetailsPlot {
|
||||||
|
|
||||||
|
private LineChart chart = null;
|
||||||
|
private SeekBar seekBarX = null;
|
||||||
|
private TextView textViewTimestamp = null;
|
||||||
|
private TextView textViewHumidity = null;
|
||||||
|
|
||||||
|
private int dataLn = -2;
|
||||||
|
|
||||||
|
private WeatherStation station;
|
||||||
|
|
||||||
|
private final LastStationDataDao lastStationDataDao;
|
||||||
|
private final StationDataDao stationDataDao;
|
||||||
|
|
||||||
|
private PlotClickEvent plotClickEvent;
|
||||||
|
|
||||||
|
private ArrayList<Entry> valuesHumidity;
|
||||||
|
|
||||||
|
private static final int twelve_hours = 3600 * 12;
|
||||||
|
private static final int twenty_four_hours = 3600 * 24;
|
||||||
|
private static final int three_days = 3600 * 24 * 3;
|
||||||
|
|
||||||
|
private static class ValueFormatter extends com.github.mikephil.charting.formatter.ValueFormatter {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getFormattedValue(float value) {
|
||||||
|
|
||||||
|
long millis = (long) value;
|
||||||
|
|
||||||
|
// the web service and the plot always stores the entries as UTC. So first convert epoch timestamp to the LocalDateTime
|
||||||
|
LocalDateTime utcDateTime = LocalDateTime.ofEpochSecond(millis / 1000, 0, ZoneOffset.UTC);
|
||||||
|
|
||||||
|
// and then shift to the user timezone for convinient display
|
||||||
|
ZonedDateTime localDateTime = utcDateTime.atZone(ZoneOffset.UTC).withZoneSameInstant(ZoneId.systemDefault());
|
||||||
|
|
||||||
|
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("HH:mm");
|
||||||
|
|
||||||
|
/* format only the time to keep X axis clean */
|
||||||
|
return fmt.format(localDateTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public StationDetailsPlotsHumidity() {
|
||||||
|
lastStationDataDao = new LastStationDataDao();
|
||||||
|
stationDataDao = new StationDataDao();
|
||||||
|
plotClickEvent = new PlotClickEvent(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
|
||||||
|
// first and last index to display on plot
|
||||||
|
int first_index, last_index = 0;
|
||||||
|
|
||||||
|
// display only 20% of the set at once
|
||||||
|
int window_size = (int) (valuesHumidity.size() * 0.2f);
|
||||||
|
|
||||||
|
last_index = (int) ((seekBarX.getProgress() / 100.0f) * valuesHumidity.size());
|
||||||
|
first_index = last_index - window_size;
|
||||||
|
|
||||||
|
if (first_index < 0) {
|
||||||
|
first_index = 0;
|
||||||
|
last_index = window_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setData(first_index, last_index, false);
|
||||||
|
|
||||||
|
// redraw
|
||||||
|
chart.invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateLabels(String date, Entry entry) {
|
||||||
|
int humidity = 0;
|
||||||
|
|
||||||
|
// get a timestamp from the entry
|
||||||
|
long timestamp = (long) entry.getX();
|
||||||
|
|
||||||
|
// look for the windspeed coresponding to that timestamp
|
||||||
|
for (Entry e : valuesHumidity) {
|
||||||
|
// if this is what we are looking for
|
||||||
|
if (e.getX() == entry.getX()) {
|
||||||
|
humidity = (int) e.getY();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (this.textViewHumidity != null && this.textViewTimestamp != null) {
|
||||||
|
this.textViewTimestamp.setText(date);
|
||||||
|
this.textViewHumidity.setText(getText(R.string.humidity) + String.format(": %d%%", humidity));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
// get data length for this plot
|
||||||
|
dataLn = (int)getIntent().getExtras().get("data_ln");
|
||||||
|
|
||||||
|
setContentView(R.layout.activity_station_details_plots);
|
||||||
|
|
||||||
|
station = (WeatherStation) getIntent().getSerializableExtra("station");
|
||||||
|
|
||||||
|
// download data from web service
|
||||||
|
this.downloadDataFromWebservice();
|
||||||
|
|
||||||
|
Typeface tfLight = Typeface.MONOSPACE;
|
||||||
|
|
||||||
|
setTitle(R.string.humidity_plot);
|
||||||
|
|
||||||
|
textViewTimestamp = findViewById(R.id.textViewPlotsWindTimestamp);
|
||||||
|
textViewHumidity = findViewById(R.id.textViewPlotsWindMean);
|
||||||
|
seekBarX = findViewById(R.id.seekBarPlotsWind);
|
||||||
|
chart = findViewById(R.id.chartPlotsWind);
|
||||||
|
|
||||||
|
// enable scaling and dragging
|
||||||
|
chart.setDragEnabled(true);
|
||||||
|
chart.setScaleEnabled(true);
|
||||||
|
chart.setDrawGridBackground(false);
|
||||||
|
chart.setHighlightPerDragEnabled(true);
|
||||||
|
|
||||||
|
// set an alternative background color
|
||||||
|
chart.setBackgroundColor(Color.WHITE);
|
||||||
|
chart.setViewPortOffsets(0f, 0f, 0f, 0f);
|
||||||
|
|
||||||
|
// add data
|
||||||
|
seekBarX.setProgress(100);
|
||||||
|
seekBarX.setOnSeekBarChangeListener(this);
|
||||||
|
|
||||||
|
XAxis xAxis = chart.getXAxis();
|
||||||
|
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM_INSIDE);
|
||||||
|
xAxis.setTypeface(tfLight);
|
||||||
|
xAxis.setTextSize(10f);
|
||||||
|
xAxis.setTextColor(Color.WHITE);
|
||||||
|
xAxis.setDrawAxisLine(false);
|
||||||
|
xAxis.setDrawGridLines(true);
|
||||||
|
xAxis.setTextColor(Color.rgb(255, 192, 56));
|
||||||
|
xAxis.setCenterAxisLabels(true);
|
||||||
|
xAxis.setGranularity(1f); // one hour
|
||||||
|
xAxis.setValueFormatter(new StationDetailsPlotsHumidity.ValueFormatter());
|
||||||
|
xAxis.setLabelRotationAngle(45.0f);
|
||||||
|
|
||||||
|
YAxis leftAxis = chart.getAxisLeft();
|
||||||
|
leftAxis.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
|
||||||
|
leftAxis.setTypeface(tfLight);
|
||||||
|
leftAxis.setTextColor(ColorTemplate.getHoloBlue());
|
||||||
|
leftAxis.setDrawGridLines(true);
|
||||||
|
leftAxis.setGranularityEnabled(true);
|
||||||
|
leftAxis.setAxisMinimum(0.0f);
|
||||||
|
leftAxis.setAxisMaximum(100.0f);
|
||||||
|
leftAxis.setYOffset(0.0f);
|
||||||
|
leftAxis.setTextColor(R.color.design_default_color_primary_dark);
|
||||||
|
leftAxis.setTextSize(123.0f);
|
||||||
|
|
||||||
|
YAxis rightAxis = chart.getAxisRight();
|
||||||
|
rightAxis.setEnabled(false);
|
||||||
|
|
||||||
|
int lastDataIndex = valuesHumidity.size() - 1;
|
||||||
|
|
||||||
|
// display only the last data (20% of newest data)
|
||||||
|
this.setData((long) (0.8 * (lastDataIndex)), lastDataIndex, false);
|
||||||
|
|
||||||
|
// set bar to maximum value
|
||||||
|
seekBarX.setProgress(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Downloads the data from the web service and stores it as entries ready to be displayed on the
|
||||||
|
* plot. Web Service gives the data with the epoch timestamp in second resolution, but the plot
|
||||||
|
* shows the data in millisecond resolution
|
||||||
|
*/
|
||||||
|
private void downloadDataFromWebservice() {
|
||||||
|
|
||||||
|
ListOfStationData data = null;
|
||||||
|
|
||||||
|
// utc time
|
||||||
|
ZonedDateTime utcTime = ZonedDateTime.now().withZoneSameInstant(ZoneId.of("UTC"));
|
||||||
|
|
||||||
|
// utc timestamp
|
||||||
|
long utcTimestamp = utcTime.toEpochSecond();
|
||||||
|
|
||||||
|
if (this.dataLn < 0 || this.dataLn > 2) {
|
||||||
|
// last 2000 points of data, regardless the timescale
|
||||||
|
data = lastStationDataDao.getLastStationData(station.getSystemName());
|
||||||
|
}
|
||||||
|
else if (dataLn == 0) {
|
||||||
|
// 12 hours
|
||||||
|
data = stationDataDao.getLastStationData(station.getSystemName(), utcTimestamp - twelve_hours, utcTimestamp);
|
||||||
|
}
|
||||||
|
else if (dataLn == 1) {
|
||||||
|
// 24 hours
|
||||||
|
data = stationDataDao.getLastStationData(station.getSystemName(), utcTimestamp - twenty_four_hours, utcTimestamp);
|
||||||
|
}
|
||||||
|
else if (dataLn == 2) {
|
||||||
|
// 3 days
|
||||||
|
data = stationDataDao.getLastStationData(station.getSystemName(), utcTimestamp - three_days, utcTimestamp);
|
||||||
|
}
|
||||||
|
|
||||||
|
valuesHumidity = new ArrayList<>();
|
||||||
|
|
||||||
|
if (data != null) {
|
||||||
|
for (StationData d : data.list_of_station_data) {
|
||||||
|
valuesHumidity.add(new Entry(d.epoch * 1000, d.humidity));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param from
|
||||||
|
* @param to
|
||||||
|
* @param index_or_timestamp if set to false 'to' and 'from' are treated as an index, if they are set
|
||||||
|
* to true this method will use it as epoch timestamps (in seconds)
|
||||||
|
*/
|
||||||
|
public void setData(long from, long to, boolean index_or_timestamp) {
|
||||||
|
|
||||||
|
// if only some part of input set needs to be displayed use this intermediate buffer
|
||||||
|
ArrayList<Entry> narrowed_set, narrowed_set_gusts;
|
||||||
|
|
||||||
|
// data set to be displayed on the plot
|
||||||
|
LineDataSet set_humidity;
|
||||||
|
|
||||||
|
|
||||||
|
if (valuesHumidity.size() > 0) {
|
||||||
|
|
||||||
|
if (from != 0 || to != 0) {
|
||||||
|
|
||||||
|
// if 'from' and 'to' are the index values
|
||||||
|
if (!index_or_timestamp) {
|
||||||
|
// make a sublist
|
||||||
|
narrowed_set = new ArrayList<>(valuesHumidity.subList((int)from, (int)to));
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// get first and last entry from the set
|
||||||
|
Entry first = valuesHumidity.get(0);
|
||||||
|
Entry last = valuesHumidity.get(valuesHumidity.size() - 1 );
|
||||||
|
|
||||||
|
// check if 'from' and 'to' timestamp epoch covers any data from the input set
|
||||||
|
if ( (long)first.getX() > (to * 1000) ||
|
||||||
|
(long)last.getX() < (from * 1000)) {
|
||||||
|
|
||||||
|
// if there is no data to display exit from an function
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
narrowed_set = new ArrayList<>();
|
||||||
|
narrowed_set_gusts = new ArrayList<>();
|
||||||
|
|
||||||
|
// if not copy matching elements to narrowed set
|
||||||
|
valuesHumidity.forEach((Entry e) -> {
|
||||||
|
if (e.getX() > (from * 1000) &&
|
||||||
|
e.getX() < (to * 1000)) {
|
||||||
|
narrowed_set.add(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
// and generate the set from it
|
||||||
|
set_humidity = new LineDataSet(narrowed_set, "Humidity");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// use 'values_wind_speed' directly as a whole
|
||||||
|
set_humidity = new LineDataSet(valuesHumidity, "Humidity");
|
||||||
|
}
|
||||||
|
|
||||||
|
// create a dataset and give it a type
|
||||||
|
set_humidity.setAxisDependency(YAxis.AxisDependency.LEFT);
|
||||||
|
set_humidity.setColor(ColorTemplate.getHoloBlue());
|
||||||
|
set_humidity.setValueTextColor(ColorTemplate.getHoloBlue());
|
||||||
|
set_humidity.setLineWidth(3.5f);
|
||||||
|
set_humidity.setDrawCircles(true);
|
||||||
|
set_humidity.setDrawValues(true);
|
||||||
|
set_humidity.setFillAlpha(65);
|
||||||
|
set_humidity.setFillColor(ColorTemplate.getHoloBlue());
|
||||||
|
set_humidity.setHighLightColor(Color.rgb(244, 117, 117));
|
||||||
|
set_humidity.setDrawCircleHole(false);
|
||||||
|
|
||||||
|
// create a data object with the data sets
|
||||||
|
LineData line_data = new LineData();
|
||||||
|
line_data.addDataSet(set_humidity);
|
||||||
|
line_data.setValueTextColor(Color.WHITE);
|
||||||
|
line_data.setValueTextSize(9f);
|
||||||
|
|
||||||
|
// set data
|
||||||
|
chart.setData(line_data);
|
||||||
|
chart.setDoubleTapToZoomEnabled(false);
|
||||||
|
chart.setOnChartValueSelectedListener(plotClickEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -69,10 +69,10 @@ public class StationDetailsPlotsTemperature extends AppCompatActivity implements
|
||||||
// and then shift to the user timezone for convinient display
|
// and then shift to the user timezone for convinient display
|
||||||
ZonedDateTime localDateTime = utcDateTime.atZone(ZoneOffset.UTC).withZoneSameInstant(ZoneId.systemDefault());
|
ZonedDateTime localDateTime = utcDateTime.atZone(ZoneOffset.UTC).withZoneSameInstant(ZoneId.systemDefault());
|
||||||
|
|
||||||
// format only the time to keep X axis clean
|
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("HH:mm");
|
||||||
String dt = DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT).format(localDateTime);
|
|
||||||
|
|
||||||
return dt;
|
/* format only the time to keep X axis clean */
|
||||||
|
return fmt.format(localDateTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -289,10 +289,13 @@ public class StationDetailsPlotsTemperature extends AppCompatActivity implements
|
||||||
xAxis.setTextColor(Color.WHITE);
|
xAxis.setTextColor(Color.WHITE);
|
||||||
xAxis.setDrawAxisLine(false);
|
xAxis.setDrawAxisLine(false);
|
||||||
xAxis.setDrawGridLines(true);
|
xAxis.setDrawGridLines(true);
|
||||||
xAxis.setTextColor(Color.rgb(255, 192, 56));
|
xAxis.setTextColor(R.color.design_default_color_primary_dark);
|
||||||
xAxis.setCenterAxisLabels(true);
|
xAxis.setCenterAxisLabels(true);
|
||||||
xAxis.setGranularity(1f); // one hour
|
xAxis.setGranularity(1f); // one hour
|
||||||
xAxis.setValueFormatter(new StationDetailsPlotsTemperature.ValueFormatter());
|
xAxis.setValueFormatter(new StationDetailsPlotsTemperature.ValueFormatter());
|
||||||
|
xAxis.setTextSize(123.0f);
|
||||||
|
xAxis.setCenterAxisLabels(true);
|
||||||
|
xAxis.setLabelRotationAngle(45.0f);
|
||||||
|
|
||||||
YAxis leftAxis = chart.getAxisLeft();
|
YAxis leftAxis = chart.getAxisLeft();
|
||||||
leftAxis.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
|
leftAxis.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
|
||||||
|
@ -303,7 +306,8 @@ public class StationDetailsPlotsTemperature extends AppCompatActivity implements
|
||||||
leftAxis.setAxisMinimum(-30.0f);
|
leftAxis.setAxisMinimum(-30.0f);
|
||||||
leftAxis.setAxisMaximum(40.0f);
|
leftAxis.setAxisMaximum(40.0f);
|
||||||
leftAxis.setYOffset(0.0f);
|
leftAxis.setYOffset(0.0f);
|
||||||
leftAxis.setTextColor(Color.rgb(255, 192, 56));
|
leftAxis.setTextColor(R.color.design_default_color_primary_dark);
|
||||||
|
leftAxis.setTextSize(123.0f);
|
||||||
|
|
||||||
YAxis rightAxis = chart.getAxisRight();
|
YAxis rightAxis = chart.getAxisRight();
|
||||||
rightAxis.setEnabled(false);
|
rightAxis.setEnabled(false);
|
||||||
|
|
|
@ -76,10 +76,10 @@ public class StationDetailsPlotsWind extends AppCompatActivity implements SeekBa
|
||||||
// and then shift to the user timezone for convinient display
|
// and then shift to the user timezone for convinient display
|
||||||
ZonedDateTime localDateTime = utcDateTime.atZone(ZoneOffset.UTC).withZoneSameInstant(ZoneId.systemDefault());
|
ZonedDateTime localDateTime = utcDateTime.atZone(ZoneOffset.UTC).withZoneSameInstant(ZoneId.systemDefault());
|
||||||
|
|
||||||
// format only the time to keep X axis clean
|
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("HH:mm");
|
||||||
String dt = DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT).format(localDateTime);
|
|
||||||
|
|
||||||
return dt;
|
/* format only the time to keep X axis clean */
|
||||||
|
return fmt.format(localDateTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -137,10 +137,14 @@ public class StationDetailsPlotsWind extends AppCompatActivity implements SeekBa
|
||||||
xAxis.setTextColor(Color.WHITE);
|
xAxis.setTextColor(Color.WHITE);
|
||||||
xAxis.setDrawAxisLine(false);
|
xAxis.setDrawAxisLine(false);
|
||||||
xAxis.setDrawGridLines(true);
|
xAxis.setDrawGridLines(true);
|
||||||
xAxis.setTextColor(Color.rgb(255, 192, 56));
|
xAxis.setTextColor(R.color.design_default_color_primary_dark);
|
||||||
xAxis.setCenterAxisLabels(true);
|
xAxis.setCenterAxisLabels(true);
|
||||||
xAxis.setGranularity(1f); // one hour
|
xAxis.setGranularity(1f); // one hour
|
||||||
xAxis.setValueFormatter(new ValueFormatter());
|
xAxis.setValueFormatter(new ValueFormatter());
|
||||||
|
xAxis.setLabelRotationAngle(45.0f);
|
||||||
|
xAxis.setTextSize(123.0f);
|
||||||
|
xAxis.setCenterAxisLabels(true);
|
||||||
|
xAxis.setLabelRotationAngle(45.0f);
|
||||||
|
|
||||||
YAxis leftAxis = chart.getAxisLeft();
|
YAxis leftAxis = chart.getAxisLeft();
|
||||||
leftAxis.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
|
leftAxis.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
|
||||||
|
@ -151,7 +155,8 @@ public class StationDetailsPlotsWind extends AppCompatActivity implements SeekBa
|
||||||
leftAxis.setAxisMinimum(0.0f);
|
leftAxis.setAxisMinimum(0.0f);
|
||||||
leftAxis.setAxisMaximum(this.findMaxValueForPlotScale());
|
leftAxis.setAxisMaximum(this.findMaxValueForPlotScale());
|
||||||
leftAxis.setYOffset(0.0f);
|
leftAxis.setYOffset(0.0f);
|
||||||
leftAxis.setTextColor(Color.rgb(255, 192, 56));
|
leftAxis.setTextColor(R.color.design_default_color_primary_dark);
|
||||||
|
leftAxis.setTextSize(123.0f);
|
||||||
|
|
||||||
YAxis rightAxis = chart.getAxisRight();
|
YAxis rightAxis = chart.getAxisRight();
|
||||||
rightAxis.setEnabled(false);
|
rightAxis.setEnabled(false);
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
package cc.pogoda.mobile.pogodacc.activity.handler;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
import cc.pogoda.mobile.pogodacc.activity.StationDetailsPlotsHumidity;
|
||||||
|
import cc.pogoda.mobile.pogodacc.type.WeatherStation;
|
||||||
|
|
||||||
|
public class StationDetailsActHumidityPlotButtonClickEvent implements View.OnClickListener {
|
||||||
|
|
||||||
|
WeatherStation station;
|
||||||
|
|
||||||
|
AppCompatActivity p;
|
||||||
|
|
||||||
|
Intent intent;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
intent = new Intent(p, StationDetailsPlotsHumidity.class);
|
||||||
|
intent.putExtra("station", station);
|
||||||
|
intent.putExtra("data_ln", (int)p.getIntent().getExtras().get("data_ln"));
|
||||||
|
|
||||||
|
p.startActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public StationDetailsActHumidityPlotButtonClickEvent(WeatherStation wx, AppCompatActivity parent) {
|
||||||
|
station = wx;
|
||||||
|
p = parent;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,2 @@
|
||||||
|
package cc.pogoda.mobile.pogodacc.activity.updater;public class FavouritesStationDetailsValuesUpdater {
|
||||||
|
}
|
|
@ -59,7 +59,7 @@ public class WeatherStationRecyclerViewAdapter extends RecyclerView.Adapter<AllS
|
||||||
handler = new Handler();
|
handler = new Handler();
|
||||||
favsUpdater = new FavouritesStationDetailsUpdater(handler);
|
favsUpdater = new FavouritesStationDetailsUpdater(handler);
|
||||||
|
|
||||||
handler.postDelayed(favsUpdater, 3000);
|
handler.postDelayed(favsUpdater, 300);
|
||||||
favsUpdater.setEnabled(true);
|
favsUpdater.setEnabled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ public class StationSummaryActElements implements StationActivityElements {
|
||||||
public TextView humidity_val = null;
|
public TextView humidity_val = null;
|
||||||
public TextView message = null;
|
public TextView message = null;
|
||||||
|
|
||||||
private String convertDegreesToDir(int directionInDegrees) {
|
public static String convertDegreesToDir(int directionInDegrees) {
|
||||||
String out = null;
|
String out = null;
|
||||||
|
|
||||||
if (directionInDegrees <= 11 || directionInDegrees >= 349)
|
if (directionInDegrees <= 11 || directionInDegrees >= 349)
|
||||||
|
|
Ładowanie…
Reference in New Issue