From 8579b64f67c5a6bca053deaeec5ad84ecdcd3000 Mon Sep 17 00:00:00 2001 From: Antonio Vanegas Date: Fri, 26 Mar 2021 11:09:52 +0100 Subject: [PATCH 01/14] added initial map fragment to track recorded view --- .../pollutionreporter/view/ChartFragment.java | 47 ++++++++++++++++--- .../pollutionreporter/view/MapFragment.java | 5 ++ .../view/SettingsSensorFragment.java | 3 +- app/src/main/res/layout/fragment_chart.xml | 8 +++- gradle.properties | 2 +- 5 files changed, 56 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/hpsaturn/pollutionreporter/view/ChartFragment.java b/app/src/main/java/hpsaturn/pollutionreporter/view/ChartFragment.java index 08b3f96f..741696a0 100644 --- a/app/src/main/java/hpsaturn/pollutionreporter/view/ChartFragment.java +++ b/app/src/main/java/hpsaturn/pollutionreporter/view/ChartFragment.java @@ -28,6 +28,10 @@ import com.hpsaturn.tools.DeviceUtil; import com.hpsaturn.tools.Logger; +import org.osmdroid.config.Configuration; +import org.osmdroid.tileprovider.tilesource.TileSourceFactory; +import org.osmdroid.views.MapView; + import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -38,6 +42,7 @@ import butterknife.BindView; import butterknife.ButterKnife; +import hpsaturn.pollutionreporter.BuildConfig; import hpsaturn.pollutionreporter.Config; import hpsaturn.pollutionreporter.MainActivity; import hpsaturn.pollutionreporter.R; @@ -71,6 +76,10 @@ public class ChartFragment extends Fragment { @BindView(R.id.rl_separator) RelativeLayout rl_separator; + @BindView(R.id.mapview) + MapView mapView; + + private long referenceTimestamp; private boolean loadingData = true; @@ -127,15 +136,47 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, loadSelectedVariables(); + Bundle args = getArguments(); if(args!=null){ recordId = args.getString(KEY_RECORD_ID) ; Logger.i(TAG,"[CHART] recordId: "+recordId); + requireActivity().runOnUiThread(() -> setupMap(recordId)); } return view; } + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + Context ctx = getContext(); + Configuration.getInstance().load(ctx, PreferenceManager.getDefaultSharedPreferences(ctx)); + Configuration.getInstance().setUserAgentValue(BuildConfig.APPLICATION_ID); + } + + private void setupMap(String recordId) { + mapView.setVisibility(View.VISIBLE); + mapView.setClickable(true); + mapView.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE); + + mapView.setMultiTouchControls(true); + mapView.setMaxZoomLevel((double) 19); + + mapView.getController().setZoom((double) 17); //set initial zoom-level, depends on your need + mapView.setUseDataConnection(true); //keeps the mapView from loading online tiles using network connection. + mapView.setEnabled(true); + (mapView.getTileProvider().getTileCache()).getProtectedTileComputers().clear(); + } + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + Logger.i(TAG,"[CHART] starting load data thread.."); + requireActivity().runOnUiThread(this::loadData); + } + + public void loadSelectedVariables(){ SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getMain()); Set values = preferences.getStringSet(getString(R.string.key_setting_vars), null); @@ -151,12 +192,6 @@ public void loadSelectedVariables(){ } } - @Override - public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - Logger.i(TAG,"[CHART] starting load data thread.."); - requireActivity().runOnUiThread(this::loadData); - } private void calculateReferenceTime(){ ArrayList data = Storage.getSensorData(getActivity()); diff --git a/app/src/main/java/hpsaturn/pollutionreporter/view/MapFragment.java b/app/src/main/java/hpsaturn/pollutionreporter/view/MapFragment.java index 32767cb5..5b265f34 100644 --- a/app/src/main/java/hpsaturn/pollutionreporter/view/MapFragment.java +++ b/app/src/main/java/hpsaturn/pollutionreporter/view/MapFragment.java @@ -20,13 +20,18 @@ import org.osmdroid.util.GeoPoint; import org.osmdroid.views.MapView; import org.osmdroid.views.overlay.Marker; +import org.osmdroid.views.overlay.Polyline; import org.osmdroid.views.overlay.infowindow.MarkerInfoWindow; +import java.util.ArrayList; +import java.util.List; + import hpsaturn.pollutionreporter.BuildConfig; import hpsaturn.pollutionreporter.R; import hpsaturn.pollutionreporter.api.AqicnApiManager; import hpsaturn.pollutionreporter.api.AqicnDataResponse; import hpsaturn.pollutionreporter.models.SensorData; +import hpsaturn.pollutionreporter.models.SensorTrack; import hpsaturn.pollutionreporter.models.SensorTrackInfo; import retrofit2.Call; import retrofit2.Callback; diff --git a/app/src/main/java/hpsaturn/pollutionreporter/view/SettingsSensorFragment.java b/app/src/main/java/hpsaturn/pollutionreporter/view/SettingsSensorFragment.java index ee1a62df..7d48a096 100644 --- a/app/src/main/java/hpsaturn/pollutionreporter/view/SettingsSensorFragment.java +++ b/app/src/main/java/hpsaturn/pollutionreporter/view/SettingsSensorFragment.java @@ -126,6 +126,8 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin } } + else + Logger.i(TAG,"skyp onSharedPreferenceChanged because is in reading mode!"); } @@ -591,7 +593,6 @@ public void configCallBack(ResponseConfig config) { getMain().showSnackMessage(R.string.msg_sync_complete); } - } onSensorReading = false; } diff --git a/app/src/main/res/layout/fragment_chart.xml b/app/src/main/res/layout/fragment_chart.xml index 802a6786..9552fcf1 100644 --- a/app/src/main/res/layout/fragment_chart.xml +++ b/app/src/main/res/layout/fragment_chart.xml @@ -8,11 +8,17 @@ android:id="@+id/lc_measures" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_above="@+id/rl_separator" + android:layout_above="@+id/mapview" android:layout_alignParentTop="true" android:layout_marginBottom="5dp" android:layout_marginTop="30dp" /> + Date: Fri, 26 Mar 2021 12:10:31 +0100 Subject: [PATCH 02/14] functional track map with colors --- .../pollutionreporter/view/ChartFragment.java | 34 +++++++++++++++++++ .../pollutionreporter/view/MapFragment.java | 15 ++++++++ 2 files changed, 49 insertions(+) diff --git a/app/src/main/java/hpsaturn/pollutionreporter/view/ChartFragment.java b/app/src/main/java/hpsaturn/pollutionreporter/view/ChartFragment.java index 741696a0..13febf9c 100644 --- a/app/src/main/java/hpsaturn/pollutionreporter/view/ChartFragment.java +++ b/app/src/main/java/hpsaturn/pollutionreporter/view/ChartFragment.java @@ -2,6 +2,7 @@ import android.content.Context; import android.content.SharedPreferences; +import android.graphics.ColorFilter; import android.graphics.Paint; import android.os.Bundle; import androidx.annotation.NonNull; @@ -30,7 +31,9 @@ import org.osmdroid.config.Configuration; import org.osmdroid.tileprovider.tilesource.TileSourceFactory; +import org.osmdroid.util.GeoPoint; import org.osmdroid.views.MapView; +import org.osmdroid.views.overlay.Polyline; import java.util.ArrayList; import java.util.HashMap; @@ -93,6 +96,8 @@ public class ChartFragment extends Fragment { private Map map = new HashMap<>(); + private List geoPoints = new ArrayList<>(); + public static ChartFragment newInstance() { return new ChartFragment(); } @@ -169,6 +174,8 @@ private void setupMap(String recordId) { (mapView.getTileProvider().getTileCache()).getProtectedTileComputers().clear(); } + + @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); @@ -223,6 +230,7 @@ else if (!data.isEmpty()) { SensorData d = it.next(); long time = d.timestamp - referenceTimestamp; addValue(time,d); + if(recordId!=null)addMapSegment(d); } refreshDataSets(); @@ -230,6 +238,29 @@ else if (!data.isEmpty()) { loadingData = false; } + private void addMapSegment(SensorData d) { + geoPoints.add(new GeoPoint(d.lat,d.lon)); + +// Polyline line = new Polyline(); //see note below! +// line.setPoints(geoPoints); +// line.addPoint(new GeoPoint(d.lat,d.lon)); + + } + + + private void updateMap() { + Polyline line = new Polyline(); //see note below! + line.setPoints(geoPoints); + ColorFilter filter = line.getOutlinePaint().getColorFilter(); + line.setOnClickListener((polyline, mapView, eventPos) -> { +// Toast.makeText(mapView.getContext(), "polyline with " + polyline.getPoints().size() + "pts was tapped", Toast.LENGTH_LONG).show(); + Logger.i(TAG,"polyline with " + polyline.getPoints().size() + "pts was tapped"); + return false; + }); + mapView.getOverlayManager().add(line); + mapView.getController().setCenter(geoPoints.get(0)); + } + private void addValue(long time, SensorData data) { Iterator it = variables.iterator(); while (it.hasNext()){ @@ -253,8 +284,11 @@ private void refreshDataSets() { chart.setData(linedata); chart.notifyDataSetChanged(); chart.invalidate(); + + if(recordId!=null)updateMap(); } + private void loadData() { Logger.i(TAG,"[CHART] loading data.."); loadingData = true; diff --git a/app/src/main/java/hpsaturn/pollutionreporter/view/MapFragment.java b/app/src/main/java/hpsaturn/pollutionreporter/view/MapFragment.java index 5b265f34..49fe7bab 100644 --- a/app/src/main/java/hpsaturn/pollutionreporter/view/MapFragment.java +++ b/app/src/main/java/hpsaturn/pollutionreporter/view/MapFragment.java @@ -98,6 +98,21 @@ public void addMarker(SensorTrackInfo trackInfo) { mapView.getController().setCenter(new GeoPoint(trackInfo.getLastLat(),trackInfo.getLastLon())); } + + public void addTrack(SensorTrack track){ + List geoPoints = new ArrayList<>(); + //add your points here + Polyline line = new Polyline(); //see note below! + line.setPoints(geoPoints); + line.setOnClickListener((polyline, mapView, eventPos) -> { +// Toast.makeText(mapView.getContext(), "polyline with " + polyline.getPoints().size() + "pts was tapped", Toast.LENGTH_LONG).show(); + Logger.i(TAG,"polyline with " + polyline.getPoints().size() + "pts was tapped"); + return false; + }); + mapView.getOverlayManager().add(line); + } + + private void loadAqicnData() { AqicnApiManager.getInstance().getDataFromHere( new Callback() { From 22e4ddaa46f97ee17753b00912f5b0de841d72cf Mon Sep 17 00:00:00 2001 From: Antonio Vanegas Date: Fri, 26 Mar 2021 13:09:12 +0100 Subject: [PATCH 03/14] first version of map track with colors --- .../pollutionreporter/view/ChartFragment.java | 130 +++++++++--------- .../pollutionreporter/view/ChartVar.java | 6 +- app/src/main/res/values/colors.xml | 1 + 3 files changed, 69 insertions(+), 68 deletions(-) diff --git a/app/src/main/java/hpsaturn/pollutionreporter/view/ChartFragment.java b/app/src/main/java/hpsaturn/pollutionreporter/view/ChartFragment.java index 13febf9c..b4aa5d54 100644 --- a/app/src/main/java/hpsaturn/pollutionreporter/view/ChartFragment.java +++ b/app/src/main/java/hpsaturn/pollutionreporter/view/ChartFragment.java @@ -175,7 +175,6 @@ private void setupMap(String recordId) { } - @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); @@ -183,6 +182,49 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat requireActivity().runOnUiThread(this::loadData); } + private void loadData() { + Logger.i(TAG,"[CHART] loading data.."); + loadingData = true; + ArrayList data = new ArrayList<>(); + if(recordId==null) { + Logger.i(TAG,"[CHART] loading current data in storage.."); + data = Storage.getSensorData(getActivity()); + } + else { + track = Storage.getTrack(getActivity(), recordId); + if(track!=null) { + Logger.i(TAG,"[CHART] loading track data from storage.."); + data = track.data; + setTrackDescription(track); + getMain().enableShareButton(); + } + else{ + Logger.i(TAG,"[CHART] loading track from firebase.."); + DatabaseReference trackRef = getMain().getDatabase().child(Config.FB_TRACKS_DATA).child(recordId); + trackRef.addListenerForSingleValueEvent(new ValueEventListener() { + @Override + public void onDataChange(@NonNull DataSnapshot dataSnapshot) { + SensorTrack track = dataSnapshot.getValue(SensorTrack.class); + if(track!=null){ + Logger.i(TAG,"[CHART] loading track on chart.."); + addData(track.data); + setTrackDescription(track); + } + else{ + Logger.e(TAG,"[CHART] onDataChange getValue is null"); + } + } + + @Override + public void onCancelled(@NonNull DatabaseError databaseError) { + Logger.e(TAG,"[CHART] onCancelled, databaseError: "+databaseError.getDetails()); + } + }); + } + } + addData(data); + } + public void loadSelectedVariables(){ SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getMain()); @@ -230,7 +272,6 @@ else if (!data.isEmpty()) { SensorData d = it.next(); long time = d.timestamp - referenceTimestamp; addValue(time,d); - if(recordId!=null)addMapSegment(d); } refreshDataSets(); @@ -238,33 +279,12 @@ else if (!data.isEmpty()) { loadingData = false; } - private void addMapSegment(SensorData d) { - geoPoints.add(new GeoPoint(d.lat,d.lon)); - -// Polyline line = new Polyline(); //see note below! -// line.setPoints(geoPoints); -// line.addPoint(new GeoPoint(d.lat,d.lon)); - - } - - - private void updateMap() { - Polyline line = new Polyline(); //see note below! - line.setPoints(geoPoints); - ColorFilter filter = line.getOutlinePaint().getColorFilter(); - line.setOnClickListener((polyline, mapView, eventPos) -> { -// Toast.makeText(mapView.getContext(), "polyline with " + polyline.getPoints().size() + "pts was tapped", Toast.LENGTH_LONG).show(); - Logger.i(TAG,"polyline with " + polyline.getPoints().size() + "pts was tapped"); - return false; - }); - mapView.getOverlayManager().add(line); - mapView.getController().setCenter(geoPoints.get(0)); - } - private void addValue(long time, SensorData data) { Iterator it = variables.iterator(); while (it.hasNext()){ - it.next().addValue(time,data); + ChartVar var = it.next(); + var.addValue(time,data); + if(recordId!=null && var.type.equals("P25"))addMapSegment(var,data); } } @@ -289,47 +309,27 @@ private void refreshDataSets() { } - private void loadData() { - Logger.i(TAG,"[CHART] loading data.."); - loadingData = true; - ArrayList data = new ArrayList<>(); - if(recordId==null) { - Logger.i(TAG,"[CHART] loading current data in storage.."); - data = Storage.getSensorData(getActivity()); - } - else { - track = Storage.getTrack(getActivity(), recordId); - if(track!=null) { - Logger.i(TAG,"[CHART] loading track data from storage.."); - data = track.data; - setTrackDescription(track); - getMain().enableShareButton(); - } - else{ - Logger.i(TAG,"[CHART] loading track from firebase.."); - DatabaseReference trackRef = getMain().getDatabase().child(Config.FB_TRACKS_DATA).child(recordId); - trackRef.addListenerForSingleValueEvent(new ValueEventListener() { - @Override - public void onDataChange(@NonNull DataSnapshot dataSnapshot) { - SensorTrack track = dataSnapshot.getValue(SensorTrack.class); - if(track!=null){ - Logger.i(TAG,"[CHART] loading track on chart.."); - addData(track.data); - setTrackDescription(track); - } - else{ - Logger.e(TAG,"[CHART] onDataChange getValue is null"); - } - } - @Override - public void onCancelled(@NonNull DatabaseError databaseError) { - Logger.e(TAG,"[CHART] onCancelled, databaseError: "+databaseError.getDetails()); - } - }); - } + + private void addMapSegment(ChartVar var, SensorData data) { + geoPoints.add(new GeoPoint(data.lat,data.lon)); + if(geoPoints.size()>1){ + Polyline line = new Polyline(); //see note below! + List segment = new ArrayList<>(); + segment.add(geoPoints.get(geoPoints.size()-2)); + segment.add(geoPoints.get(geoPoints.size()-1)); + line.setPoints(segment); + line.getOutlinePaint().setColor(var.colors.get(var.colors.size()-1)); + + line.getOutlinePaint().setStrokeWidth(15F); + line.getOutlinePaint().setStrokeCap(Paint.Cap.ROUND); + line.getOutlinePaint().setAntiAlias(true); + mapView.getOverlayManager().add(line); } - addData(data); + } + + private void updateMap() { + mapView.getController().setCenter(geoPoints.get(0)); } private void setTrackDescription(SensorTrack track){ diff --git a/app/src/main/java/hpsaturn/pollutionreporter/view/ChartVar.java b/app/src/main/java/hpsaturn/pollutionreporter/view/ChartVar.java index 1fde8003..18e1a53c 100644 --- a/app/src/main/java/hpsaturn/pollutionreporter/view/ChartVar.java +++ b/app/src/main/java/hpsaturn/pollutionreporter/view/ChartVar.java @@ -22,7 +22,7 @@ public class ChartVar { private Context ctx; - private final String type; + public String type; public List entries = new ArrayList(); @@ -121,7 +121,7 @@ public void addValue(float time,SensorData data){ switch (type) { case "CO2": if (data.CO2 <= 600) colors.add(ctx.getResources().getColor(R.color.green)); - else if (data.CO2 <= 800) colors.add(ctx.getResources().getColor(R.color.yellow)); + else if (data.CO2 <= 800) colors.add(ctx.getResources().getColor(R.color.yellow_dark)); else if (data.CO2 <= 1000) colors.add(ctx.getResources().getColor(R.color.orange)); else if (data.CO2 <= 1500) colors.add(ctx.getResources().getColor(R.color.red)); else if (data.CO2 <= 2000) colors.add(ctx.getResources().getColor(R.color.purple)); @@ -129,7 +129,7 @@ public void addValue(float time,SensorData data){ break; case "P25": if (data.P25 <= 13) colors.add(ctx.getResources().getColor(R.color.green)); - else if (data.P25 <= 35) colors.add(ctx.getResources().getColor(R.color.yellow)); + else if (data.P25 <= 35) colors.add(ctx.getResources().getColor(R.color.yellow_dark)); else if (data.P25 <= 55) colors.add(ctx.getResources().getColor(R.color.orange)); else if (data.P25 <= 150)colors.add(ctx.getResources().getColor(R.color.red)); else if (data.P25 <= 250)colors.add(ctx.getResources().getColor(R.color.purple)); diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index bab602fa..20c929f5 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -23,6 +23,7 @@ #1CAB1C #187218 #DEDE16 + #E8E372 #ffa0a0a0 #797373 #ff000000 From 315c3449a8708d63402f0efebe8666c14adf1700 Mon Sep 17 00:00:00 2001 From: Antonio Vanegas Date: Fri, 26 Mar 2021 13:44:42 +0100 Subject: [PATCH 04/14] restricted only track map for PM2.5 variable filter --- .../pollutionreporter/view/ChartFragment.java | 45 ++++++++++--------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/hpsaturn/pollutionreporter/view/ChartFragment.java b/app/src/main/java/hpsaturn/pollutionreporter/view/ChartFragment.java index b4aa5d54..e9ab71f2 100644 --- a/app/src/main/java/hpsaturn/pollutionreporter/view/ChartFragment.java +++ b/app/src/main/java/hpsaturn/pollutionreporter/view/ChartFragment.java @@ -141,12 +141,12 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, loadSelectedVariables(); - + // Try to load old track (records view) Bundle args = getArguments(); if(args!=null){ recordId = args.getString(KEY_RECORD_ID) ; Logger.i(TAG,"[CHART] recordId: "+recordId); - requireActivity().runOnUiThread(() -> setupMap(recordId)); + requireActivity().runOnUiThread(this::setupMap); } return view; @@ -160,14 +160,12 @@ public void onCreate(@Nullable Bundle savedInstanceState) { Configuration.getInstance().setUserAgentValue(BuildConfig.APPLICATION_ID); } - private void setupMap(String recordId) { + private void setupMap() { mapView.setVisibility(View.VISIBLE); mapView.setClickable(true); mapView.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE); - mapView.setMultiTouchControls(true); mapView.setMaxZoomLevel((double) 19); - mapView.getController().setZoom((double) 17); //set initial zoom-level, depends on your need mapView.setUseDataConnection(true); //keeps the mapView from loading online tiles using network connection. mapView.setEnabled(true); @@ -182,6 +180,10 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat requireActivity().runOnUiThread(this::loadData); } + /** + * initialization of data for chart and map + * load data of current recording track or old recorded track + */ private void loadData() { Logger.i(TAG,"[CHART] loading data.."); loadingData = true; @@ -225,7 +227,6 @@ public void onCancelled(@NonNull DatabaseError databaseError) { addData(data); } - public void loadSelectedVariables(){ SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getMain()); Set values = preferences.getStringSet(getString(R.string.key_setting_vars), null); @@ -255,15 +256,10 @@ private void calculateReferenceTime(){ } - public void addData(SensorData data) { - if (!loadingData) { - Long currentTime = System.currentTimeMillis() / 1000; - long time = currentTime - referenceTimestamp; - addValue(time,data); - refreshDataSets(); - } - } - + /** + * Add data from previous data (recorded track for example) + * @param data + */ private void addData(ArrayList data){ if(data==null)return; else if (!data.isEmpty()) { @@ -308,8 +304,18 @@ private void refreshDataSets() { if(recordId!=null)updateMap(); } - - + /** + * Add external data to fragment (real time visualization) + * @param data + */ + public void addData(SensorData data) { + if (!loadingData) { + Long currentTime = System.currentTimeMillis() / 1000; + long time = currentTime - referenceTimestamp; + addValue(time,data); + refreshDataSets(); + } + } private void addMapSegment(ChartVar var, SensorData data) { geoPoints.add(new GeoPoint(data.lat,data.lon)); @@ -320,8 +326,7 @@ private void addMapSegment(ChartVar var, SensorData data) { segment.add(geoPoints.get(geoPoints.size()-1)); line.setPoints(segment); line.getOutlinePaint().setColor(var.colors.get(var.colors.size()-1)); - - line.getOutlinePaint().setStrokeWidth(15F); + line.getOutlinePaint().setStrokeWidth(18F); line.getOutlinePaint().setStrokeCap(Paint.Cap.ROUND); line.getOutlinePaint().setAntiAlias(true); mapView.getOverlayManager().add(line); @@ -329,7 +334,7 @@ private void addMapSegment(ChartVar var, SensorData data) { } private void updateMap() { - mapView.getController().setCenter(geoPoints.get(0)); + if(geoPoints.size()>0) mapView.getController().setCenter(geoPoints.get(0)); } private void setTrackDescription(SensorTrack track){ From d24c554e8521014002d1339e8904d1b3892e6c32 Mon Sep 17 00:00:00 2001 From: Antonio Vanegas Date: Fri, 26 Mar 2021 13:56:49 +0100 Subject: [PATCH 05/14] added zoom to boundingbox on recorded track --- .../hpsaturn/pollutionreporter/view/ChartFragment.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/hpsaturn/pollutionreporter/view/ChartFragment.java b/app/src/main/java/hpsaturn/pollutionreporter/view/ChartFragment.java index e9ab71f2..1857e1d2 100644 --- a/app/src/main/java/hpsaturn/pollutionreporter/view/ChartFragment.java +++ b/app/src/main/java/hpsaturn/pollutionreporter/view/ChartFragment.java @@ -31,7 +31,9 @@ import org.osmdroid.config.Configuration; import org.osmdroid.tileprovider.tilesource.TileSourceFactory; +import org.osmdroid.util.BoundingBox; import org.osmdroid.util.GeoPoint; +import org.osmdroid.views.CustomZoomButtonsController; import org.osmdroid.views.MapView; import org.osmdroid.views.overlay.Polyline; @@ -334,7 +336,10 @@ private void addMapSegment(ChartVar var, SensorData data) { } private void updateMap() { - if(geoPoints.size()>0) mapView.getController().setCenter(geoPoints.get(0)); + if(geoPoints.size()>1) { + BoundingBox center = BoundingBox.fromGeoPoints(geoPoints); + mapView.zoomToBoundingBox(center, false); + } } private void setTrackDescription(SensorTrack track){ From fe1192340e721aeb4ee64fe5817da220be47ca91 Mon Sep 17 00:00:00 2001 From: Antonio Vanegas Date: Fri, 26 Mar 2021 16:14:07 +0100 Subject: [PATCH 06/14] added record fragment on click over each map mark --- .../service/RecordTrackService.java | 2 +- .../pollutionreporter/view/MapFragment.java | 43 ++++++++++++++++++- .../pollutionreporter/view/PostsFragment.java | 15 +++---- app/src/main/res/values/arrays.xml | 5 --- 4 files changed, 48 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/hpsaturn/pollutionreporter/service/RecordTrackService.java b/app/src/main/java/hpsaturn/pollutionreporter/service/RecordTrackService.java index b2291eee..7a30e5b9 100644 --- a/app/src/main/java/hpsaturn/pollutionreporter/service/RecordTrackService.java +++ b/app/src/main/java/hpsaturn/pollutionreporter/service/RecordTrackService.java @@ -49,7 +49,7 @@ public class RecordTrackService extends Service { private RecordTrackManager recordTrackManager; private final int RETRY_POLICY = 5; - private final int MAX_POINTS_SAVING = 3000; + private final int MAX_POINTS_SAVING = 1500; private int retry_connect = 0; private int retry_notify_setup = 0; diff --git a/app/src/main/java/hpsaturn/pollutionreporter/view/MapFragment.java b/app/src/main/java/hpsaturn/pollutionreporter/view/MapFragment.java index 49fe7bab..add8a80b 100644 --- a/app/src/main/java/hpsaturn/pollutionreporter/view/MapFragment.java +++ b/app/src/main/java/hpsaturn/pollutionreporter/view/MapFragment.java @@ -2,6 +2,7 @@ import android.content.Context; import android.graphics.drawable.Drawable; +import android.media.MediaPlayer; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -13,6 +14,10 @@ import androidx.fragment.app.Fragment; import androidx.preference.PreferenceManager; +import com.google.android.gms.tasks.OnCompleteListener; +import com.google.android.gms.tasks.Task; +import com.google.firebase.database.DataSnapshot; +import com.google.firebase.database.Query; import com.hpsaturn.tools.Logger; import org.osmdroid.config.Configuration; @@ -24,9 +29,12 @@ import org.osmdroid.views.overlay.infowindow.MarkerInfoWindow; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import hpsaturn.pollutionreporter.BuildConfig; +import hpsaturn.pollutionreporter.Config; +import hpsaturn.pollutionreporter.MainActivity; import hpsaturn.pollutionreporter.R; import hpsaturn.pollutionreporter.api.AqicnApiManager; import hpsaturn.pollutionreporter.api.AqicnDataResponse; @@ -80,12 +88,40 @@ private void setupMap(View view) { mapView.setUseDataConnection(true); //keeps the mapView from loading online tiles using network connection. mapView.setEnabled(true); (mapView.getTileProvider().getTileCache()).getProtectedTileComputers().clear(); + + loadLastTracks(); + } + + private void loadLastTracks() { + Query query = getMain().getDatabase().child(Config.FB_TRACKS_INFO).orderByKey().limitToLast(100); + query.get().addOnCompleteListener(new OnCompleteListener() { + @Override + public void onComplete(@NonNull Task task) { + + if (task.isSuccessful()) { + Iterable data = task.getResult().getChildren(); + Iterator it = data.iterator(); + while(it.hasNext()){ + SensorTrackInfo track = it.next().getValue(SensorTrackInfo.class); + addMarker(track); + } + } + + } + }); + } public void addMarker(SensorTrackInfo trackInfo) { Drawable icon = ResourcesCompat.getDrawable(getResources(), R.drawable.map_mark_yellow, null); - MarkerInfoWindow infoWindow = new MarkerInfoWindow(org.osmdroid.bonuspack.R.layout.bonuspack_bubble, mapView); +// MarkerInfoWindow infoWindow = new MarkerInfoWindow(org.osmdroid.bonuspack.R.layout.bonuspack_bubble, mapView); Marker pointMarker = new Marker(mapView); + pointMarker.setOnMarkerClickListener((marker, mapView) -> { + Logger.d(TAG, "OnMarkerClickListener => " + trackInfo.getName()); + ChartFragment chart = ChartFragment.newInstance(trackInfo.getName()); + getMain().addFragmentPopup(chart,ChartFragment.TAG); + return false; + }); pointMarker.setTitle("" + trackInfo.getDate()); SensorData lastSensorData = trackInfo.getLastSensorData(); if(lastSensorData!=null) pointMarker.setSnippet("Last PM2.5: "+ lastSensorData.P25); @@ -93,7 +129,7 @@ public void addMarker(SensorTrackInfo trackInfo) { pointMarker.setPosition(new GeoPoint(trackInfo.getLastLat(), trackInfo.getLastLon())); pointMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM); pointMarker.setIcon(icon); - pointMarker.setInfoWindow(infoWindow); +// pointMarker.setInfoWindow(infoWindow); mapView.getOverlays().add(pointMarker); mapView.getController().setCenter(new GeoPoint(trackInfo.getLastLat(),trackInfo.getLastLon())); } @@ -130,6 +166,9 @@ public void onFailure(Call call, Throwable t) { }); } + private MainActivity getMain() { + return ((MainActivity) getActivity()); + } } diff --git a/app/src/main/java/hpsaturn/pollutionreporter/view/PostsFragment.java b/app/src/main/java/hpsaturn/pollutionreporter/view/PostsFragment.java index a4b168ac..cc839a48 100644 --- a/app/src/main/java/hpsaturn/pollutionreporter/view/PostsFragment.java +++ b/app/src/main/java/hpsaturn/pollutionreporter/view/PostsFragment.java @@ -86,15 +86,12 @@ protected void onBindViewHolder(@NonNull PostsViewHolder viewHolder, int positio final DatabaseReference postRef = getRef(position); final String recordKey = postRef.getKey(); Logger.d(TAG,"[FB][POSTS] onBindViewHolder: "+recordKey+" name:"+trackInfo.getName()); - getMain().addTrackToMap(trackInfo); - viewHolder.itemView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - String recordId = trackInfo.getName(); - Logger.i(TAG,"[FB][POSTS] onClick -> showing record: "+recordId); - chart = ChartFragment.newInstance(recordId); - getMain().addFragmentPopup(chart,ChartFragment.TAG); - } +// getMain().addTrackToMap(trackInfo); + viewHolder.itemView.setOnClickListener(v -> { + String recordId = trackInfo.getName(); + Logger.i(TAG,"[FB][POSTS] onClick -> showing record: "+recordId); + chart = ChartFragment.newInstance(recordId); + getMain().addFragmentPopup(chart,ChartFragment.TAG); }); // Bind Post to ViewHolder, setting OnClickListener for the star button viewHolder.bindToPost(trackInfo); diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index e95e28b1..fcbd86c6 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -59,10 +59,5 @@ P25 - CO2 - CO2T - CO2H - tmp - hum From 4a01e954ee3aab6280139d3a232bfff16fcd4239 Mon Sep 17 00:00:00 2001 From: Antonio Vanegas Date: Fri, 26 Mar 2021 17:28:24 +0100 Subject: [PATCH 07/14] fixed chart height issue on low resolution devices --- .../pollutionreporter/view/ChartFragment.java | 21 +++--- .../pollutionreporter/view/MapFragment.java | 37 +++------- app/src/main/res/layout/fragment_chart.xml | 45 ++++++------ .../res/layout/fragment_chart_realtime.xml | 71 +++++++++++++++++++ 4 files changed, 119 insertions(+), 55 deletions(-) create mode 100644 app/src/main/res/layout/fragment_chart_realtime.xml diff --git a/app/src/main/java/hpsaturn/pollutionreporter/view/ChartFragment.java b/app/src/main/java/hpsaturn/pollutionreporter/view/ChartFragment.java index 1857e1d2..aaac2463 100644 --- a/app/src/main/java/hpsaturn/pollutionreporter/view/ChartFragment.java +++ b/app/src/main/java/hpsaturn/pollutionreporter/view/ChartFragment.java @@ -115,7 +115,17 @@ public static ChartFragment newInstance(String recordId) { @Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.fragment_chart, container, false); + // Try to load old track (records view) + View view; + Bundle args = getArguments(); + if(args!=null){ + recordId = args.getString(KEY_RECORD_ID) ; + Logger.i(TAG,"[CHART] recordId: "+recordId); + view = inflater.inflate(R.layout.fragment_chart, container, false); + }else{ + view = inflater.inflate(R.layout.fragment_chart_realtime, container, false); + } + ButterKnife.bind(this, view); Description description = new Description(); @@ -143,13 +153,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, loadSelectedVariables(); - // Try to load old track (records view) - Bundle args = getArguments(); - if(args!=null){ - recordId = args.getString(KEY_RECORD_ID) ; - Logger.i(TAG,"[CHART] recordId: "+recordId); - requireActivity().runOnUiThread(this::setupMap); - } + return view; } @@ -180,6 +184,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat super.onViewCreated(view, savedInstanceState); Logger.i(TAG,"[CHART] starting load data thread.."); requireActivity().runOnUiThread(this::loadData); + if(recordId!=null) requireActivity().runOnUiThread(this::setupMap); } /** diff --git a/app/src/main/java/hpsaturn/pollutionreporter/view/MapFragment.java b/app/src/main/java/hpsaturn/pollutionreporter/view/MapFragment.java index add8a80b..3d04a033 100644 --- a/app/src/main/java/hpsaturn/pollutionreporter/view/MapFragment.java +++ b/app/src/main/java/hpsaturn/pollutionreporter/view/MapFragment.java @@ -94,19 +94,17 @@ private void setupMap(View view) { private void loadLastTracks() { Query query = getMain().getDatabase().child(Config.FB_TRACKS_INFO).orderByKey().limitToLast(100); - query.get().addOnCompleteListener(new OnCompleteListener() { - @Override - public void onComplete(@NonNull Task task) { - - if (task.isSuccessful()) { - Iterable data = task.getResult().getChildren(); - Iterator it = data.iterator(); - while(it.hasNext()){ - SensorTrackInfo track = it.next().getValue(SensorTrackInfo.class); + query.get().addOnCompleteListener(task -> { + + if (task.isSuccessful()) { + Iterable data = task.getResult().getChildren(); + Iterator it = data.iterator(); + while(it.hasNext()){ + SensorTrackInfo track = it.next().getValue(SensorTrackInfo.class); + if(track.getSize()>100 && track.getSize()<1000){ addMarker(track); } } - } }); @@ -114,7 +112,7 @@ public void onComplete(@NonNull Task task) { public void addMarker(SensorTrackInfo trackInfo) { Drawable icon = ResourcesCompat.getDrawable(getResources(), R.drawable.map_mark_yellow, null); -// MarkerInfoWindow infoWindow = new MarkerInfoWindow(org.osmdroid.bonuspack.R.layout.bonuspack_bubble, mapView); + MarkerInfoWindow infoWindow = new MarkerInfoWindow(org.osmdroid.bonuspack.R.layout.bonuspack_bubble, mapView); Marker pointMarker = new Marker(mapView); pointMarker.setOnMarkerClickListener((marker, mapView) -> { Logger.d(TAG, "OnMarkerClickListener => " + trackInfo.getName()); @@ -129,26 +127,11 @@ public void addMarker(SensorTrackInfo trackInfo) { pointMarker.setPosition(new GeoPoint(trackInfo.getLastLat(), trackInfo.getLastLon())); pointMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM); pointMarker.setIcon(icon); -// pointMarker.setInfoWindow(infoWindow); + pointMarker.setInfoWindow(infoWindow); mapView.getOverlays().add(pointMarker); mapView.getController().setCenter(new GeoPoint(trackInfo.getLastLat(),trackInfo.getLastLon())); } - - public void addTrack(SensorTrack track){ - List geoPoints = new ArrayList<>(); - //add your points here - Polyline line = new Polyline(); //see note below! - line.setPoints(geoPoints); - line.setOnClickListener((polyline, mapView, eventPos) -> { -// Toast.makeText(mapView.getContext(), "polyline with " + polyline.getPoints().size() + "pts was tapped", Toast.LENGTH_LONG).show(); - Logger.i(TAG,"polyline with " + polyline.getPoints().size() + "pts was tapped"); - return false; - }); - mapView.getOverlayManager().add(line); - } - - private void loadAqicnData() { AqicnApiManager.getInstance().getDataFromHere( new Callback() { diff --git a/app/src/main/res/layout/fragment_chart.xml b/app/src/main/res/layout/fragment_chart.xml index 9552fcf1..07b1539e 100644 --- a/app/src/main/res/layout/fragment_chart.xml +++ b/app/src/main/res/layout/fragment_chart.xml @@ -8,34 +8,41 @@ android:id="@+id/lc_measures" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_above="@+id/mapview" + android:layout_above="@+id/ll_center_seperator" android:layout_alignParentTop="true" - android:layout_marginBottom="5dp" - android:layout_marginTop="30dp" /> + android:layout_marginTop="5dp" /> + + + + + android:visibility="visible" /> + android:layout_marginStart="10dp"> + android:textColor="@color/black" + android:textSize="18sp" + android:textStyle="bold" /> + android:textColor="@color/black" + android:textSize="14sp" /> - + android:textColor="@color/black" + android:textSize="14sp" /> - - + android:textColor="@color/black" + android:textSize="14sp" + android:visibility="gone" /> \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_chart_realtime.xml b/app/src/main/res/layout/fragment_chart_realtime.xml new file mode 100644 index 00000000..cdb1b828 --- /dev/null +++ b/app/src/main/res/layout/fragment_chart_realtime.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From ccb36e8e88724a43ccce7fdc6b953087ff33a78b Mon Sep 17 00:00:00 2001 From: Antonio Vanegas Date: Fri, 26 Mar 2021 18:06:13 +0100 Subject: [PATCH 08/14] restricted chart to 3000 points and some layout improvements --- .../pollutionreporter/view/ChartFragment.java | 20 +++-------- .../pollutionreporter/view/PostsFragment.java | 3 +- .../res/layout/fragment_chart_realtime.xml | 34 +++++++------------ 3 files changed, 17 insertions(+), 40 deletions(-) diff --git a/app/src/main/java/hpsaturn/pollutionreporter/view/ChartFragment.java b/app/src/main/java/hpsaturn/pollutionreporter/view/ChartFragment.java index aaac2463..91060f72 100644 --- a/app/src/main/java/hpsaturn/pollutionreporter/view/ChartFragment.java +++ b/app/src/main/java/hpsaturn/pollutionreporter/view/ChartFragment.java @@ -81,10 +81,6 @@ public class ChartFragment extends Fragment { @BindView(R.id.rl_separator) RelativeLayout rl_separator; - @BindView(R.id.mapview) - MapView mapView; - - private long referenceTimestamp; private boolean loadingData = true; @@ -99,6 +95,7 @@ public class ChartFragment extends Fragment { private Map map = new HashMap<>(); private List geoPoints = new ArrayList<>(); + private MapView mapView; public static ChartFragment newInstance() { return new ChartFragment(); @@ -122,6 +119,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, recordId = args.getString(KEY_RECORD_ID) ; Logger.i(TAG,"[CHART] recordId: "+recordId); view = inflater.inflate(R.layout.fragment_chart, container, false); + mapView = view.findViewById(R.id.mapview); }else{ view = inflater.inflate(R.layout.fragment_chart_realtime, container, false); } @@ -153,19 +151,9 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, loadSelectedVariables(); - - return view; } - @Override - public void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - Context ctx = getContext(); - Configuration.getInstance().load(ctx, PreferenceManager.getDefaultSharedPreferences(ctx)); - Configuration.getInstance().setUserAgentValue(BuildConfig.APPLICATION_ID); - } - private void setupMap() { mapView.setVisibility(View.VISIBLE); mapView.setClickable(true); @@ -178,7 +166,6 @@ private void setupMap() { (mapView.getTileProvider().getTileCache()).getProtectedTileComputers().clear(); } - @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); @@ -271,7 +258,8 @@ private void addData(ArrayList data){ if(data==null)return; else if (!data.isEmpty()) { Iterator it = data.iterator(); - while (it.hasNext()) { + int count = 0; + while (it.hasNext() && count++ <3000) { SensorData d = it.next(); long time = d.timestamp - referenceTimestamp; addValue(time,d); diff --git a/app/src/main/java/hpsaturn/pollutionreporter/view/PostsFragment.java b/app/src/main/java/hpsaturn/pollutionreporter/view/PostsFragment.java index cc839a48..aa46baad 100644 --- a/app/src/main/java/hpsaturn/pollutionreporter/view/PostsFragment.java +++ b/app/src/main/java/hpsaturn/pollutionreporter/view/PostsFragment.java @@ -66,7 +66,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat super.onViewCreated(view, savedInstanceState); // Set up FirebaseRecyclerAdapter with the Query - Query postsQuery = getMain().getDatabase().child(Config.FB_TRACKS_INFO).orderByKey().limitToLast(20); + Query postsQuery = getMain().getDatabase().child(Config.FB_TRACKS_INFO).orderByKey().limitToLast(50); Logger.d(TAG,"[FB][POSTS] Query: "+postsQuery.toString()); FirebaseRecyclerOptions options = new FirebaseRecyclerOptions.Builder() .setQuery(postsQuery, SensorTrackInfo.class) @@ -86,7 +86,6 @@ protected void onBindViewHolder(@NonNull PostsViewHolder viewHolder, int positio final DatabaseReference postRef = getRef(position); final String recordKey = postRef.getKey(); Logger.d(TAG,"[FB][POSTS] onBindViewHolder: "+recordKey+" name:"+trackInfo.getName()); -// getMain().addTrackToMap(trackInfo); viewHolder.itemView.setOnClickListener(v -> { String recordId = trackInfo.getName(); Logger.i(TAG,"[FB][POSTS] onClick -> showing record: "+recordId); diff --git a/app/src/main/res/layout/fragment_chart_realtime.xml b/app/src/main/res/layout/fragment_chart_realtime.xml index cdb1b828..4830f8bf 100644 --- a/app/src/main/res/layout/fragment_chart_realtime.xml +++ b/app/src/main/res/layout/fragment_chart_realtime.xml @@ -8,24 +8,17 @@ android:id="@+id/lc_measures" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_above="@+id/mapview" - android:layout_alignParentTop="true" - android:layout_marginBottom="5dp" - android:layout_marginTop="30dp" /> - - + android:layout_alignParentTop="true" + android:layout_marginTop="30dp" + android:layout_marginBottom="5dp" /> + android:textStyle="bold" /> + android:textColor="@color/black" + android:textSize="18sp" /> - + android:textColor="@color/black" + android:textSize="18sp" /> - - + android:textColor="@color/black" + android:textSize="18sp" /> \ No newline at end of file From dbc2f0e9c5251686810f246f068388935fc1612f Mon Sep 17 00:00:00 2001 From: Antonio Vanegas Date: Fri, 26 Mar 2021 18:38:31 +0100 Subject: [PATCH 09/14] removed timer thread for reloading adapter (old workaround) --- .../pollutionreporter/view/PostsFragment.java | 22 +------------------ 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/app/src/main/java/hpsaturn/pollutionreporter/view/PostsFragment.java b/app/src/main/java/hpsaturn/pollutionreporter/view/PostsFragment.java index aa46baad..33fa3509 100644 --- a/app/src/main/java/hpsaturn/pollutionreporter/view/PostsFragment.java +++ b/app/src/main/java/hpsaturn/pollutionreporter/view/PostsFragment.java @@ -85,7 +85,7 @@ public PostsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewTyp protected void onBindViewHolder(@NonNull PostsViewHolder viewHolder, int position, @NonNull SensorTrackInfo trackInfo) { final DatabaseReference postRef = getRef(position); final String recordKey = postRef.getKey(); - Logger.d(TAG,"[FB][POSTS] onBindViewHolder: "+recordKey+" name:"+trackInfo.getName()); +// Logger.d(TAG,"[FB][POSTS] onBindViewHolder: "+recordKey+" name:"+trackInfo.getName()); viewHolder.itemView.setOnClickListener(v -> { String recordId = trackInfo.getName(); Logger.i(TAG,"[FB][POSTS] onClick -> showing record: "+recordId); @@ -100,24 +100,9 @@ protected void onBindViewHolder(@NonNull PostsViewHolder viewHolder, int positio mRecordsList.setAdapter(mAdapter); mAdapter.notifyDataSetChanged(); mAdapter.startListening(); - mUpdateTimeTask.run(); // TODO: fucking workaround, firebase recycler wasn't update in fist time } - private Handler mHandler = new Handler(); - private UpdateTimeTask mUpdateTimeTask = new UpdateTimeTask(); - - class UpdateTimeTask extends TimerTask { - private int retries = 3; - private int counter = 0; - public void run() { - Logger.i(TAG,"[FB][POST] UpdateTimeTask, force refresh data.."); - refresh(); - if(counter++>retries)this.cancel(); - else mHandler.postDelayed(this,3000); - } - } - private void updateUI() { if(mAdapter!=null&&mAdapter.getItemCount()>0) { mEmptyMessage.setVisibility(View.GONE); @@ -150,11 +135,6 @@ public void onStop() { if (mAdapter != null) { mAdapter.stopListening(); } - try { - mHandler.removeCallbacks(mUpdateTimeTask); - } catch (Exception e) { - e.printStackTrace(); - } } @Override From 73f35cf5038c26f02017ccfae24c3c57a5cddbf9 Mon Sep 17 00:00:00 2001 From: Antonio Vanegas Date: Fri, 26 Mar 2021 18:40:21 +0100 Subject: [PATCH 10/14] fixed clear chart issue when is recording a track --- .../pollutionreporter/view/ChartFragment.java | 23 +++++++------------ .../pollutionreporter/view/ChartVar.java | 2 +- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/hpsaturn/pollutionreporter/view/ChartFragment.java b/app/src/main/java/hpsaturn/pollutionreporter/view/ChartFragment.java index 91060f72..281526cb 100644 --- a/app/src/main/java/hpsaturn/pollutionreporter/view/ChartFragment.java +++ b/app/src/main/java/hpsaturn/pollutionreporter/view/ChartFragment.java @@ -1,22 +1,19 @@ package hpsaturn.pollutionreporter.view; -import android.content.Context; import android.content.SharedPreferences; -import android.graphics.ColorFilter; import android.graphics.Paint; import android.os.Bundle; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.fragment.app.Fragment; -import androidx.preference.MultiSelectListPreference; -import androidx.preference.PreferenceManager; - import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.RelativeLayout; import android.widget.TextView; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; +import androidx.preference.PreferenceManager; + import com.github.mikephil.charting.charts.LineChart; import com.github.mikephil.charting.components.Description; import com.github.mikephil.charting.components.XAxis; @@ -29,17 +26,14 @@ import com.hpsaturn.tools.DeviceUtil; import com.hpsaturn.tools.Logger; -import org.osmdroid.config.Configuration; import org.osmdroid.tileprovider.tilesource.TileSourceFactory; import org.osmdroid.util.BoundingBox; import org.osmdroid.util.GeoPoint; -import org.osmdroid.views.CustomZoomButtonsController; import org.osmdroid.views.MapView; import org.osmdroid.views.overlay.Polyline; import java.util.ArrayList; import java.util.HashMap; -import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -47,7 +41,6 @@ import butterknife.BindView; import butterknife.ButterKnife; -import hpsaturn.pollutionreporter.BuildConfig; import hpsaturn.pollutionreporter.Config; import hpsaturn.pollutionreporter.MainActivity; import hpsaturn.pollutionreporter.R; @@ -149,8 +142,6 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, map.put(types[i],labels[i]); } - loadSelectedVariables(); - return view; } @@ -170,7 +161,7 @@ private void setupMap() { public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); Logger.i(TAG,"[CHART] starting load data thread.."); - requireActivity().runOnUiThread(this::loadData); + loadSelectedVariables(); if(recordId!=null) requireActivity().runOnUiThread(this::setupMap); } @@ -234,6 +225,8 @@ public void loadSelectedVariables(){ variables.add(var); Logger.i(TAG, "[CHART]"+type); } + + requireActivity().runOnUiThread(this::loadData); } diff --git a/app/src/main/java/hpsaturn/pollutionreporter/view/ChartVar.java b/app/src/main/java/hpsaturn/pollutionreporter/view/ChartVar.java index 18e1a53c..f54b836b 100644 --- a/app/src/main/java/hpsaturn/pollutionreporter/view/ChartVar.java +++ b/app/src/main/java/hpsaturn/pollutionreporter/view/ChartVar.java @@ -139,7 +139,7 @@ public void addValue(float time,SensorData data){ try { float value = data.getClass().getField(type).getFloat(data); - Logger.i(TAG,"--> "+type+ ":"+value); +// Logger.i(TAG,"--> "+type+ ":"+value); dataSet.addEntry(new Entry(time,value)); } catch (IllegalAccessException | NoSuchFieldException e) { From c3c24da9929ee40d7b6d26a3bd483f3dea6cd653 Mon Sep 17 00:00:00 2001 From: Antonio Vanegas Date: Fri, 26 Mar 2021 19:31:18 +0100 Subject: [PATCH 11/14] removed some logs and unnecessary packages --- .../hpsaturn/pollutionreporter/MainActivity.java | 1 - .../service/RecordTrackService.java | 8 -------- .../hpsaturn/pollutionreporter/view/MapFragment.java | 7 ------- .../pollutionreporter/view/PostsFragment.java | 12 +++++------- gradle.properties | 2 +- 5 files changed, 6 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/hpsaturn/pollutionreporter/MainActivity.java b/app/src/main/java/hpsaturn/pollutionreporter/MainActivity.java index 7c0c6269..09196ae6 100644 --- a/app/src/main/java/hpsaturn/pollutionreporter/MainActivity.java +++ b/app/src/main/java/hpsaturn/pollutionreporter/MainActivity.java @@ -20,7 +20,6 @@ import com.google.firebase.database.FirebaseDatabase; import com.hpsaturn.tools.Logger; import com.iamhabib.easy_preference.EasyPreference; -//import com.livinglifetechway.quickpermissions.annotations.WithPermissions; import com.karumi.dexter.Dexter; import com.karumi.dexter.MultiplePermissionsReport; import com.karumi.dexter.PermissionToken; diff --git a/app/src/main/java/hpsaturn/pollutionreporter/service/RecordTrackService.java b/app/src/main/java/hpsaturn/pollutionreporter/service/RecordTrackService.java index 7a30e5b9..221cf2af 100644 --- a/app/src/main/java/hpsaturn/pollutionreporter/service/RecordTrackService.java +++ b/app/src/main/java/hpsaturn/pollutionreporter/service/RecordTrackService.java @@ -135,8 +135,6 @@ public void onServiceStatus(String status) { @Override public void onServiceStart() { -// Logger.d(TAG, "[BLE] request service start.."); -// startConnection(); } @Override @@ -257,13 +255,7 @@ public void onNotificationSetupFailure() { @Override public void onNotificationReceived(byte[] bytes) { -// String strdata = new String(bytes); -// SensorData data = new Gson().fromJson(strdata, SensorData.class); -// Logger.d(TAG, "[BLE] pushing notification data to GUI.."); -// recordTrackManager.sensorNotificationData(data); - if (bleHandler != null) bleHandler.readSensorData(); - retry_notify_setup = 0; } diff --git a/app/src/main/java/hpsaturn/pollutionreporter/view/MapFragment.java b/app/src/main/java/hpsaturn/pollutionreporter/view/MapFragment.java index 3d04a033..39e53da1 100644 --- a/app/src/main/java/hpsaturn/pollutionreporter/view/MapFragment.java +++ b/app/src/main/java/hpsaturn/pollutionreporter/view/MapFragment.java @@ -2,7 +2,6 @@ import android.content.Context; import android.graphics.drawable.Drawable; -import android.media.MediaPlayer; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -14,8 +13,6 @@ import androidx.fragment.app.Fragment; import androidx.preference.PreferenceManager; -import com.google.android.gms.tasks.OnCompleteListener; -import com.google.android.gms.tasks.Task; import com.google.firebase.database.DataSnapshot; import com.google.firebase.database.Query; import com.hpsaturn.tools.Logger; @@ -25,12 +22,9 @@ import org.osmdroid.util.GeoPoint; import org.osmdroid.views.MapView; import org.osmdroid.views.overlay.Marker; -import org.osmdroid.views.overlay.Polyline; import org.osmdroid.views.overlay.infowindow.MarkerInfoWindow; -import java.util.ArrayList; import java.util.Iterator; -import java.util.List; import hpsaturn.pollutionreporter.BuildConfig; import hpsaturn.pollutionreporter.Config; @@ -39,7 +33,6 @@ import hpsaturn.pollutionreporter.api.AqicnApiManager; import hpsaturn.pollutionreporter.api.AqicnDataResponse; import hpsaturn.pollutionreporter.models.SensorData; -import hpsaturn.pollutionreporter.models.SensorTrack; import hpsaturn.pollutionreporter.models.SensorTrackInfo; import retrofit2.Call; import retrofit2.Callback; diff --git a/app/src/main/java/hpsaturn/pollutionreporter/view/PostsFragment.java b/app/src/main/java/hpsaturn/pollutionreporter/view/PostsFragment.java index 33fa3509..01c4b9fe 100644 --- a/app/src/main/java/hpsaturn/pollutionreporter/view/PostsFragment.java +++ b/app/src/main/java/hpsaturn/pollutionreporter/view/PostsFragment.java @@ -2,16 +2,16 @@ import android.os.Bundle; -import android.os.Handler; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; import com.firebase.ui.database.FirebaseRecyclerAdapter; import com.firebase.ui.database.FirebaseRecyclerOptions; @@ -19,8 +19,6 @@ import com.google.firebase.database.Query; import com.hpsaturn.tools.Logger; -import java.util.TimerTask; - import hpsaturn.pollutionreporter.Config; import hpsaturn.pollutionreporter.MainActivity; import hpsaturn.pollutionreporter.R; diff --git a/gradle.properties b/gradle.properties index fe26474c..69d092b3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,7 +11,7 @@ org.gradle.jvmargs=-Xmx1536m mCompileSdkVersion=29 mMinSdkVersion=19 mTargetSdkVersion=29 -mVersionCode=539 +mVersionCode=540 mVersionName=0.3.9 android.useAndroidX=true android.enableJetifier=true From e7ea6a9b0abc221c97e986c02493cdae67dffe25 Mon Sep 17 00:00:00 2001 From: Antonio Vanegas Date: Fri, 26 Mar 2021 20:23:04 +0100 Subject: [PATCH 12/14] testing fix on Github workflow --- libtoolscommon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libtoolscommon b/libtoolscommon index 17caf6eb..acec6fa0 160000 --- a/libtoolscommon +++ b/libtoolscommon @@ -1 +1 @@ -Subproject commit 17caf6ebd22ac9be1a0cc2f77c96baaa513d5131 +Subproject commit acec6fa09c8eb695497f8da620ab9b8d70af31be From c936ca9e4333430fb8c8a7a80f2bd25a1dae6f75 Mon Sep 17 00:00:00 2001 From: Antonio Vanegas Date: Fri, 26 Mar 2021 21:12:20 +0100 Subject: [PATCH 13/14] testing fix lint issue on submodule --- libtoolscommon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libtoolscommon b/libtoolscommon index acec6fa0..78a3d4dd 160000 --- a/libtoolscommon +++ b/libtoolscommon @@ -1 +1 @@ -Subproject commit acec6fa09c8eb695497f8da620ab9b8d70af31be +Subproject commit 78a3d4dd2bce2c6ba2f7fae7f2ba38bfc913f674 From e39833e66d3ed3f32faef8230e84693e3342d659 Mon Sep 17 00:00:00 2001 From: Antonio Vanegas Date: Fri, 26 Mar 2021 22:13:47 +0100 Subject: [PATCH 14/14] fixed resume issue on list firebase adapter --- .../pollutionreporter/view/PostsFragment.java | 25 ++++--------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/hpsaturn/pollutionreporter/view/PostsFragment.java b/app/src/main/java/hpsaturn/pollutionreporter/view/PostsFragment.java index 01c4b9fe..42ff8f70 100644 --- a/app/src/main/java/hpsaturn/pollutionreporter/view/PostsFragment.java +++ b/app/src/main/java/hpsaturn/pollutionreporter/view/PostsFragment.java @@ -2,6 +2,7 @@ import android.os.Bundle; +import android.os.Handler; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -19,6 +20,8 @@ import com.google.firebase.database.Query; import com.hpsaturn.tools.Logger; +import java.util.TimerTask; + import hpsaturn.pollutionreporter.Config; import hpsaturn.pollutionreporter.MainActivity; import hpsaturn.pollutionreporter.R; @@ -81,9 +84,6 @@ public PostsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewTyp @Override protected void onBindViewHolder(@NonNull PostsViewHolder viewHolder, int position, @NonNull SensorTrackInfo trackInfo) { - final DatabaseReference postRef = getRef(position); - final String recordKey = postRef.getKey(); -// Logger.d(TAG,"[FB][POSTS] onBindViewHolder: "+recordKey+" name:"+trackInfo.getName()); viewHolder.itemView.setOnClickListener(v -> { String recordId = trackInfo.getName(); Logger.i(TAG,"[FB][POSTS] onClick -> showing record: "+recordId); @@ -120,30 +120,15 @@ public void refresh() { } @Override - public void onStart() { - super.onStart(); - if (mAdapter != null) { - mAdapter.startListening(); - } - } - - @Override - public void onStop() { - super.onStop(); + public void onDestroy() { if (mAdapter != null) { mAdapter.stopListening(); } - } - - @Override - public void onResume() { - super.onResume(); - updateUI(); + super.onDestroy(); } private MainActivity getMain() { return ((MainActivity) getActivity()); } - }