diff --git a/.idea/misc.xml b/.idea/misc.xml
index 3d21ecd..5d19981 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -37,7 +37,7 @@
-
+
diff --git a/RiskAhead-Android.iml b/RiskAhead-Android.iml
index 69b9b49..d6d1356 100644
--- a/RiskAhead-Android.iml
+++ b/RiskAhead-Android.iml
@@ -13,7 +13,7 @@
-
+
\ No newline at end of file
diff --git a/app/app.iml b/app/app.iml
index 0669b3b..a092e42 100644
--- a/app/app.iml
+++ b/app/app.iml
@@ -92,6 +92,7 @@
+
@@ -101,6 +102,7 @@
+
@@ -145,6 +147,5 @@
-
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index ab7f6c0..76da134 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -13,14 +13,14 @@ apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 25
- buildToolsVersion '25.0.0'
+ buildToolsVersion '25.0.2'
defaultConfig {
applicationId "org.deke.risk.riskahead"
minSdkVersion 15
targetSdkVersion 23
- versionCode 35
- versionName "2.1.1"
+ versionCode 42
+ versionName "3.0.2"
}
buildTypes {
release {
diff --git a/app/src/main/java/org/deke/risk/riskahead/LoginActivity.java b/app/src/main/java/org/deke/risk/riskahead/LoginActivity.java
index daf147c..ee6fd21 100644
--- a/app/src/main/java/org/deke/risk/riskahead/LoginActivity.java
+++ b/app/src/main/java/org/deke/risk/riskahead/LoginActivity.java
@@ -22,7 +22,6 @@ import android.util.Patterns;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
-import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
@@ -45,8 +44,6 @@ import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.beardedhen.androidbootstrap.BootstrapButton;
-import com.google.android.gms.plus.Plus;
-import com.google.android.gms.plus.model.people.Person;
import java.util.HashMap;
import java.util.Map;
@@ -314,9 +311,7 @@ public class LoginActivity extends AppCompatActivity implements FacebookButtonFr
@Override
protected Map getParams() {
- Map params = new HashMap<>();
-
- return params;
+ return new HashMap<>();
}
};
}
diff --git a/app/src/main/java/org/deke/risk/riskahead/MapsActivity.java b/app/src/main/java/org/deke/risk/riskahead/MapsActivity.java
index 7d76470..b1be5b2 100644
--- a/app/src/main/java/org/deke/risk/riskahead/MapsActivity.java
+++ b/app/src/main/java/org/deke/risk/riskahead/MapsActivity.java
@@ -31,6 +31,7 @@ import android.widget.TextView;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
+
import android.location.LocationListener;
import com.android.volley.toolbox.StringRequest;
@@ -70,11 +71,9 @@ import java.util.Locale;
import java.util.Map;
/**
- *
* (C) Copyright 2016 RiskAhead (http://www.riskahead.net)
* Developer & Contributor: Dennis Thießen (dennis.thiessen@riskahead.net)
* Date of Release: 10.02.2016
- *
*/
public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCallbacks,
ClusterManager.OnClusterItemInfoWindowClickListener, ClusterManager.OnClusterClickListener, ClusterManager.OnClusterItemClickListener, OnMapReadyCallback {
@@ -101,8 +100,10 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
private Marker markerShowingInfoWindow;
private IncidentReport clickedClusterItem;
- protected LocationManager locationManager;
- Location location;
+ private LocationManager locationManager;
+ private LocationListener locationListener;
+ private Location location;
+
private static final int MIN_DISTANCE_CHANGE_FOR_UPDATES = 10; // 10 meters
private static final int MIN_TIME_BW_UPDATES = 1000 * 60; // 1 minute
@@ -121,6 +122,7 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
super.onCreate(savedInstanceState);
userHasToBeLoggedIn();
+
if (session.getSubsPremium()) {
MIN_ZOOM_LEVEL = 7;
} else {
@@ -138,6 +140,7 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
initMap();
+
handleIntent(getIntent());
initClustering();
}
@@ -150,21 +153,16 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
- Log.d(TAG,"Getting permission results...");
+ Log.d(TAG, "Getting permission results...");
switch (requestCode) {
case MY_PERMISSIONS_REQUEST_LOCATION: {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
- Log.d(TAG,"Permission was granted by user");
-
- try{
- mMap.setMyLocationEnabled(true);
- }catch (SecurityException e){
- Log.e(TAG,"Security Exception:"+e.getMessage());
- }
-
+ Log.d(TAG, "Permission was granted by user");
+ enableMyLocationButton();
getLocation();
- }else{
- Log.d(TAG,"Permission was not granted by user");
+
+ } else {
+ Log.d(TAG, "Permission was not granted by user");
String sDefSystemLanguage = Locale.getDefault().getLanguage();
@@ -182,29 +180,25 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
new LatLng(19.410704, -99.132385), DEFAULT_ZOOM_LEVEL));
break;
}
-
- try{
- mMap.setMyLocationEnabled(false);
- }catch (SecurityException e){
- Log.e(TAG,"Security Exception:"+e.getMessage());
- }
}
}
}
}
private void initMap() {
- Log.d(TAG,"Init Map");
+ Log.d(TAG, "Init Map");
mMap.getUiSettings().setZoomControlsEnabled(true);
-
+ mMap.setMinZoomPreference(MIN_ZOOM_LEVEL);
mMap.setOnMyLocationButtonClickListener(new GoogleMap.OnMyLocationButtonClickListener() {
@Override
public boolean onMyLocationButtonClick() {
getLocation();
- return true;
+ return false;
}
});
+ enableMyLocationButton();
+
mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
@Override
public void onMapClick(LatLng point) {
@@ -254,13 +248,13 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
addButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- session.setLocation(Double.doubleToRawLongBits(markedLocation.latitude), Double.doubleToRawLongBits(markedLocation.longitude));
+ session.setManualLocation(Double.doubleToRawLongBits(markedLocation.latitude), Double.doubleToRawLongBits(markedLocation.longitude));
Log.d(TAG, "MARKED LOCATION: " + markedLocation.latitude + " " + markedLocation.longitude);
gotoSettingsActivity();
}
});
}
- }else{
+ } else {
addButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -276,31 +270,22 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
}
public GoogleMap.OnCameraIdleListener getCameraChangeListener() {
- return new GoogleMap.OnCameraIdleListener()
- {
+ return new GoogleMap.OnCameraIdleListener() {
@Override
- public void onCameraIdle()
- {
+ public void onCameraIdle() {
mClusterManager.onCameraIdle();
CameraPosition position = mMap.getCameraPosition();
-
- if((position.zoom < MIN_ZOOM_LEVEL) && !session.getSubsPremium()) {
- mMap.animateCamera(CameraUpdateFactory.zoomTo(MIN_ZOOM_LEVEL));
- showMessage(getString(R.string.txt_map_zoomoutpremium));
- return;
- }
-
current_zoom_level = position.zoom;
- if(position.zoom > 13) {
+ if (position.zoom > 13) {
PRELOAD_PERCENTAGE = 0.7;
- }else{
+ } else {
PRELOAD_PERCENTAGE = 0.3;
}
LatLngBounds bounds = mMap.getProjection().getVisibleRegion().latLngBounds;
- Log.d("OnCameraChangeListener", "Position: "+bounds.getCenter()+" Zoom: "+position.zoom + " Bounds: NE:" + bounds.northeast + " SW: " + bounds.southwest);
+ Log.d("OnCameraChangeListener", "Position: " + bounds.getCenter() + " Zoom: " + position.zoom + " Bounds: NE:" + bounds.northeast + " SW: " + bounds.southwest);
Log.d("OnCameraChangeListener", "Saved Position - Bounds: NE:" + curNortheastBounds + " SW: " + curSouthwestBounds);
boolean isOutOfBounds = false;
@@ -311,39 +296,39 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
double southwestLat, southwestLng;
double northeastLat, northeastLng;
- if(bounds.southwest.latitude < bounds.northeast.latitude){
+ if (bounds.southwest.latitude < bounds.northeast.latitude) {
southwestLat = bounds.southwest.latitude - distanceLat * PRELOAD_PERCENTAGE;
northeastLat = bounds.northeast.latitude + distanceLat * PRELOAD_PERCENTAGE;
- if((curSouthwestBounds != null) && ((bounds.southwest.latitude < curSouthwestBounds.latitude) || (bounds.northeast.latitude > curNortheastBounds.latitude))){
+ if ((curSouthwestBounds != null) && ((bounds.southwest.latitude < curSouthwestBounds.latitude) || (bounds.northeast.latitude > curNortheastBounds.latitude))) {
isOutOfBounds = true;
}
} else {
southwestLat = bounds.southwest.latitude + distanceLat * PRELOAD_PERCENTAGE;
northeastLat = bounds.northeast.latitude - distanceLat * PRELOAD_PERCENTAGE;
- if((curSouthwestBounds != null) && ((bounds.southwest.latitude > curSouthwestBounds.latitude) || (bounds.northeast.latitude < curNortheastBounds.latitude))){
+ if ((curSouthwestBounds != null) && ((bounds.southwest.latitude > curSouthwestBounds.latitude) || (bounds.northeast.latitude < curNortheastBounds.latitude))) {
isOutOfBounds = true;
}
}
- if(bounds.southwest.longitude < bounds.northeast.longitude){
+ if (bounds.southwest.longitude < bounds.northeast.longitude) {
southwestLng = bounds.southwest.longitude - distanceLon * PRELOAD_PERCENTAGE;
northeastLng = bounds.northeast.longitude + distanceLon * PRELOAD_PERCENTAGE;
- if((curSouthwestBounds != null) && ((bounds.southwest.longitude < curSouthwestBounds.longitude) || (bounds.northeast.longitude > curNortheastBounds.longitude))){
+ if ((curSouthwestBounds != null) && ((bounds.southwest.longitude < curSouthwestBounds.longitude) || (bounds.northeast.longitude > curNortheastBounds.longitude))) {
isOutOfBounds = true;
}
} else {
southwestLng = bounds.southwest.longitude + distanceLon * PRELOAD_PERCENTAGE;
northeastLng = bounds.northeast.longitude - distanceLon * PRELOAD_PERCENTAGE;
- if((curSouthwestBounds != null) && ((bounds.southwest.longitude > curSouthwestBounds.longitude) || (bounds.northeast.longitude < curNortheastBounds.longitude))){
+ if ((curSouthwestBounds != null) && ((bounds.southwest.longitude > curSouthwestBounds.longitude) || (bounds.northeast.longitude < curNortheastBounds.longitude))) {
isOutOfBounds = true;
}
}
- if((curSouthwestBounds == null) || isOutOfBounds) {
+ if ((curSouthwestBounds == null) || isOutOfBounds) {
curNortheastBounds = new LatLng(northeastLat, northeastLng);
curSouthwestBounds = new LatLng(southwestLat, southwestLng);
@@ -358,7 +343,7 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
refreshIncidentHeatMap(curNortheastBounds, curSouthwestBounds);
markersShown = false;
}
- } else if((position.zoom >= THRESHOLD_ZOOM_LEVEL) && !markersShown){
+ } else if ((position.zoom >= THRESHOLD_ZOOM_LEVEL) && !markersShown) {
curNortheastBounds = new LatLng(northeastLat, northeastLng);
curSouthwestBounds = new LatLng(southwestLat, southwestLng);
@@ -367,7 +352,7 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
refreshIncidentHeatMap(curNortheastBounds, curSouthwestBounds);
refreshIncidentMarkers(curNortheastBounds, curSouthwestBounds);
markersShown = true;
- } else if((position.zoom < THRESHOLD_ZOOM_LEVEL) && !markersShown){
+ } else if ((position.zoom < THRESHOLD_ZOOM_LEVEL) && !markersShown) {
mClusterManager.clearItems();
markersShown = false;
}
@@ -375,19 +360,18 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
};
}
- private void refreshIncidentMarkers(LatLng northeast, LatLng southwest){
+ private void refreshIncidentMarkers(LatLng northeast, LatLng southwest) {
showProgress();
String tag_string_req = "getincidentsfrombound";
- StringRequest strReq = getStringRequestGetAllIncidentsFromBound(northeast,southwest);
+ StringRequest strReq = getStringRequestGetAllIncidentsFromBound(northeast, southwest);
AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
}
- private void addIncidentMarkersOnMap(JSONArray incidents){
-
+ private void addIncidentMarkersOnMap(JSONArray incidents) {
mClusterManager.clearItems();
- for(int i = 0; i < incidents.length();i++){
+ for (int i = 0; i < incidents.length(); i++) {
try {
mClusterManager.addItem(new IncidentReport(incidents.getJSONObject(i)));
} catch (JSONException e) {
@@ -398,7 +382,7 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
mClusterManager.cluster();
}
- private void refreshIncidentHeatMap(LatLng northeast, LatLng southwest){
+ private void refreshIncidentHeatMap(LatLng northeast, LatLng southwest) {
showProgress();
String tag_string_req = "getincidentsforheatmapfrombound";
@@ -406,10 +390,10 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
}
- private void addIncidentMarkersOnHeatMap(JSONArray incidents){
+ private void addIncidentMarkersOnHeatMap(JSONArray incidents) {
ArrayList heatMapPositions = new ArrayList<>();
- for(int i = 0; i < incidents.length();i++){
+ for (int i = 0; i < incidents.length(); i++) {
try {
heatMapPositions.add(new WeightedLatLng(new LatLng(incidents.getJSONObject(i).getDouble("latitude"), incidents.getJSONObject(i).getDouble("longitude")), 1.0));
} catch (JSONException e) {
@@ -417,20 +401,17 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
}
}
- if(mProvider == null){
+ if (mProvider == null) {
mProvider = new HeatmapTileProvider.Builder()
.radius(50)
.weightedData(heatMapPositions)
.opacity(0.7)
.build();
-
mOverlay = mMap.addTileOverlay(new TileOverlayOptions().tileProvider(mProvider));
- Log.d("HEATMAP", "HeatMap initialized");
- }else{
+ } else {
mProvider.setWeightedData(heatMapPositions);
mOverlay.clearTileCache();
- Log.d("HEATMAP", "HeatMap updated");
}
}
@@ -447,7 +428,7 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
if (!error) {
JSONArray incidents = jObj.getJSONArray("msg");
- Log.d(TAG, "HeatMap positions response length: " + incidents .length());
+ Log.d(TAG, "HeatMap positions response length: " + incidents.length());
addIncidentMarkersOnHeatMap(incidents);
} else {
String errorMsg = jObj.getString("error_msg");
@@ -554,7 +535,7 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
new MyCustomAdapterForItems());
}
- private void loadInfoWindowInformation(View infoView, String incidentID){
+ private void loadInfoWindowInformation(View infoView, String incidentID) {
showProgress();
String tag_string_req = "getincidentscoreforinfowindow";
@@ -580,7 +561,7 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
TextView tvUsername = ((TextView) infoView.findViewById(R.id.txt_infowindow_fromuser));
RatingBar rbScore = ((RatingBar) infoView.findViewById(R.id.rb_infowindow_rating));
- tvUsername.setText(String.format("%s %s",getString(R.string.lbl_mapsinfowindow_author),clickedClusterItem.getFromUsername()));
+ tvUsername.setText(String.format("%s %s", getString(R.string.lbl_mapsinfowindow_author), clickedClusterItem.getFromUsername()));
rbScore.setRating(clickedClusterItem.getScoreStars());
if (markerShowingInfoWindow != null && markerShowingInfoWindow.isInfoWindowShown()) {
@@ -589,7 +570,7 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
}
} else {
String errorMsg = jObj.getString("error_msg");
- Log.e(TAG, "Error getting incident details (server returned error): " + errorMsg);
+ Log.i(TAG, "Error getting incident details (server returned error): " + errorMsg);
showMessage(getResources().getString(R.string.txt_errormsg_getinfowindow));
}
} catch (JSONException e) {
@@ -617,9 +598,7 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
};
}
-
private class MyCustomAdapterForItems implements GoogleMap.InfoWindowAdapter {
-
private final View myContentsView;
MyCustomAdapterForItems() {
@@ -652,40 +631,39 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
tvCategory.setText(clickedClusterItem.getIncidentCategoryName(getApplicationContext()));
tvSubcategory.setText(clickedClusterItem.getIncidentSubCategoryName(getApplicationContext()));
- tvSuspect.setText(String.format("%s %s",getString(R.string.lbl_mapsinfowindow_suspect),clickedClusterItem.getSuspectString(getApplicationContext())));
- tvVictim.setText(String.format("%s %s",getString(R.string.lbl_mapsinfowindow_victim),clickedClusterItem.getVictimString(getApplicationContext())));
+ tvSuspect.setText(String.format("%s %s", getString(R.string.lbl_mapsinfowindow_suspect), clickedClusterItem.getSuspectString(getApplicationContext())));
+ tvVictim.setText(String.format("%s %s", getString(R.string.lbl_mapsinfowindow_victim), clickedClusterItem.getVictimString(getApplicationContext())));
tvTime.setText(String.format("%s %s", getString(R.string.lbl_mapsinfowindow_time), clickedClusterItem.getTimeString(getApplicationContext())));
}
return myContentsView;
}
}
- private void handleIntent(Intent intent){
- if(Intent.ACTION_SEARCH.equals(intent.getAction()))
- {
+ private void handleIntent(Intent intent) {
+ if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
doSearch(query);
- } else if(Intent.ACTION_VIEW.equals(intent.getAction())) {
+ } else if (Intent.ACTION_VIEW.equals(intent.getAction())) {
getPlace(intent.getStringExtra(SearchManager.EXTRA_DATA_KEY));
} else {
String intentMessage = intent.getStringExtra(EXTRA_MESSAGE);
- if(intentMessage != null && intentMessage.contains(":")) {
+ if (intentMessage != null && intentMessage.contains(":")) {
String[] position = intentMessage.split(":");
String latitude = position[0];
String longitude = position[1];
- LatLng point = new LatLng(Double.parseDouble(latitude),Double.parseDouble(longitude));
+ LatLng point = new LatLng(Double.parseDouble(latitude), Double.parseDouble(longitude));
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(point, DEFAULT_ZOOM_LEVEL));
- if(getIntent().hasExtra(AppConfig.EXTRA_MAP_TYPE)) mMarker = mMap.addMarker(new MarkerOptions().position(point));
+ if (getIntent().hasExtra(AppConfig.EXTRA_MAP_TYPE))
+ mMarker = mMap.addMarker(new MarkerOptions().position(point));
} else {
LatLng myPosition = session.getLocation();
- if ((myPosition != null) && (myPosition.latitude != 0.0) && (myPosition.longitude != 0.0))
- {
+ if ((myPosition != null) && (myPosition.latitude != 0.0) && (myPosition.longitude != 0.0)) {
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(myPosition.latitude, myPosition.longitude), DEFAULT_ZOOM_LEVEL));
- }else{
+ } else {
getLocation();
}
}
@@ -698,7 +676,9 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
}
@Override
- public boolean onClusterClick(Cluster cluster) { return false; }
+ public boolean onClusterClick(Cluster cluster) {
+ return false;
+ }
@Override
public void onClusterItemInfoWindowClick(IncidentReport incidentReport) {
@@ -712,49 +692,50 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
handleIntent(intent);
}
- private void doSearch(String query){
+ private void doSearch(String query) {
Bundle data = new Bundle();
data.putString("query", query);
getSupportLoaderManager().restartLoader(0, data, this);
}
- private void getPlace(String query){
+ private void getPlace(String query) {
Bundle data = new Bundle();
data.putString("query", query);
getSupportLoaderManager().restartLoader(1, data, this);
}
- private void showLocations(Cursor c){
+ private void showLocations(Cursor c) {
MarkerOptions markerOptions;
LatLng position = null;
- while(c.moveToNext()){
+ while (c.moveToNext()) {
markerOptions = new MarkerOptions();
- position = new LatLng(Double.parseDouble(c.getString(1)),Double.parseDouble(c.getString(2)));
+ position = new LatLng(Double.parseDouble(c.getString(1)), Double.parseDouble(c.getString(2)));
markerOptions.position(position);
markerOptions.title(c.getString(0));
}
- if(position!=null){
+ if (position != null) {
CameraUpdate cameraPosition = CameraUpdateFactory.newLatLng(position);
mMap.animateCamera(cameraPosition);
}
if (position != null) {
- myLocation = new LatLng(position.latitude,position.longitude);
+ myLocation = new LatLng(position.latitude, position.longitude);
}
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(myLocation, DEFAULT_ZOOM_LEVEL));
}
@Override
- public void onLoaderReset(Loader arg0) {}
+ public void onLoaderReset(Loader arg0) {
+ }
@Override
public Loader onCreateLoader(int arg0, Bundle query) {
CursorLoader cLoader = null;
- if(arg0==0)
- cLoader = new CursorLoader(getBaseContext(), PlaceProvider.SEARCH_URI, null, null, new String[]{query.getString("query") }, null);
- else if(arg0==1)
- cLoader = new CursorLoader(getBaseContext(), PlaceProvider.DETAILS_URI, null, null, new String[]{ query.getString("query") }, null);
+ if (arg0 == 0)
+ cLoader = new CursorLoader(getBaseContext(), PlaceProvider.SEARCH_URI, null, null, new String[]{query.getString("query")}, null);
+ else if (arg0 == 1)
+ cLoader = new CursorLoader(getBaseContext(), PlaceProvider.DETAILS_URI, null, null, new String[]{query.getString("query")}, null);
return cLoader;
}
@@ -763,11 +744,11 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
@Override
public void onLocationChanged(Location loc) {
- if(loc.getLongitude() != 0.0 && loc.getLatitude() != 0.0) {
+ if (loc.getLongitude() != 0.0 && loc.getLatitude() != 0.0) {
Log.d(TAG, "Save GPS as new location...");
- if(session.getLocation() == null || session.getLocation().latitude == 0.0 || session.getLocation().longitude == 0.0){
+ if (session.getLocation() == null || session.getLocation().latitude == 0.0 || session.getLocation().longitude == 0.0) {
session.setLocation(Double.doubleToRawLongBits(loc.getLatitude()), Double.doubleToRawLongBits(loc.getLongitude()));
- }else{
+ } else {
session.setLocation(Double.doubleToRawLongBits(loc.getLatitude()), Double.doubleToRawLongBits(loc.getLongitude()));
}
@@ -776,13 +757,16 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
}
@Override
- public void onProviderDisabled(String provider) {}
+ public void onProviderDisabled(String provider) {
+ }
@Override
- public void onProviderEnabled(String provider) {}
+ public void onProviderEnabled(String provider) {
+ }
@Override
- public void onStatusChanged(String provider, int status, Bundle extras) {}
+ public void onStatusChanged(String provider, int status, Bundle extras) {
+ }
}
private boolean isLocationEnabled() {
@@ -792,56 +776,50 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
public Location getLocation() {
//check for permission
- if (ActivityCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED){
- Log.d(TAG,"Permission for GPS not granted yet - ask for permission now");
- ActivityCompat.requestPermissions(this,new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION,android.Manifest.permission.ACCESS_COARSE_LOCATION},MY_PERMISSIONS_REQUEST_LOCATION);
- }else{
- Log.d(TAG,"Permission for GPS granted - get position");
- mMap.setMyLocationEnabled(true);
- MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.frag_maps_map);
- View locationButton = ((View) mapFragment.getView().findViewById(Integer.parseInt("1")).getParent()).findViewById(Integer.parseInt("2"));
- RelativeLayout.LayoutParams rlp = (RelativeLayout.LayoutParams) locationButton.getLayoutParams();
- rlp.setMargins(0, 200, 30, 30);
+ Log.d(TAG, "Permission for GPS not granted yet - ask for permission now");
+ if (ActivityCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
+ ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION, android.Manifest.permission.ACCESS_COARSE_LOCATION}, MY_PERMISSIONS_REQUEST_LOCATION);
+ } else {
+ Log.d(TAG, "Permission for GPS granted - get position");
+ locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
+ locationListener = new MyLocationListener();
try {
- locationManager = (LocationManager) getApplicationContext().getSystemService(LOCATION_SERVICE);
- LocationListener locationListener = new MyLocationListener();
-
if (!isLocationEnabled()) {
showMessage("Please activate GPS in your android settings.");
- Log.d(TAG,"Locationservice not enabled");
+ Log.d(TAG, "Locationservice not enabled");
} else {
- Log.d(TAG,"Locationservice enabled - check type");
+ Log.d(TAG, "Locationservice enabled - check type");
// if GPS Enabled get lat/long using GPS Services
if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
- Log.d(TAG,"Locationservice enabled - GPS Provider Found");
+ Log.d(TAG, "Locationservice enabled - GPS Provider Found");
if (location == null) {
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, locationListener);
- Log.d("GPS Enabled", "GPS Enabled");
+ Log.d(TAG, "GPS location from GPS Service activated");
if (locationManager != null) {
- location = locationManager .getLastKnownLocation(LocationManager.GPS_PROVIDER);
+ location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
- myLocation = new LatLng(location.getLatitude(),location.getLongitude());
+ myLocation = new LatLng(location.getLatitude(), location.getLongitude());
}
}
}
- }else if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
+ } else if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
// get location from Network Provider
- Log.d(TAG,"Locationservice enabled - Network Provider Found");
+ Log.d(TAG, "Locationservice enabled - Network Provider Found");
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER,
- 22,
- 33, locationListener);
- Log.d("Network", "Network");
+ MIN_TIME_BW_UPDATES,
+ MIN_DISTANCE_CHANGE_FOR_UPDATES, locationListener);
+ Log.d(TAG, "GPS location from Network Provider activated");
if (locationManager != null) {
location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location != null) {
- myLocation = new LatLng(location.getLatitude(),location.getLongitude());
+ myLocation = new LatLng(location.getLatitude(), location.getLongitude());
}
}
}
@@ -858,6 +836,18 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
return location;
}
+ private void enableMyLocationButton() {
+ try{
+ mMap.setMyLocationEnabled(true);
+ MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.frag_maps_map);
+ View locationButton = ((View) mapFragment.getView().findViewById(Integer.parseInt("1")).getParent()).findViewById(Integer.parseInt("2"));
+ RelativeLayout.LayoutParams rlp = (RelativeLayout.LayoutParams) locationButton.getLayoutParams();
+ rlp.setMargins(0, 250, 30, 30);
+ }catch(SecurityException se){
+ ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION, android.Manifest.permission.ACCESS_COARSE_LOCATION}, MY_PERMISSIONS_REQUEST_LOCATION);
+ }
+ }
+
@Override
public void onLoadFinished(Loader arg0, Cursor c) {
showLocations(c);
@@ -873,7 +863,7 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
SearchableInfo searchInfo = searchManager.getSearchableInfo(getComponentName());
searchView.setSearchableInfo(searchInfo);
- EditText txtSearch = ((EditText)searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text));
+ EditText txtSearch = ((EditText) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text));
txtSearch.setHint(getResources().getString(R.string.search_hint));
txtSearch.setHintTextColor(Color.DKGRAY);
txtSearch.setTextColor(Color.BLACK);
@@ -882,9 +872,18 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
}
@Override
- protected void onPause(){
+ protected void onPause() {
+ Log.d(TAG,"onPause executed: LM: "+(locationManager != null)+" LL: "+(locationListener!=null));
+ if(locationManager != null && locationListener != null) {
+ locationManager.removeUpdates(locationListener);
+ locationListener = null;
+ locationManager = null;
+ }
+
+
super.onPause();
- if(showAdd) showAd();
+
+ if (showAdd) showAd();
}
@Override
@@ -897,21 +896,21 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
return getResources().getString(R.string.title_activity_maps);
}
- private void showProgress(){
+ private void showProgress() {
findViewById(R.id.pb_map_progress).setVisibility(View.VISIBLE);
pbCounter++;
}
@Override
- protected void onResume(){
+ protected void onResume() {
super.onResume();
navDrawer.setSelection(mapAvtivityID, false);
showAdd = true;
}
- private void hideProgress(){
+ private void hideProgress() {
pbCounter--;
- if(pbCounter == 0){
+ if (pbCounter == 0) {
findViewById(R.id.pb_map_progress).setVisibility(View.GONE);
}
}
diff --git a/app/src/main/java/org/deke/risk/riskahead/ReportWFActivity.java b/app/src/main/java/org/deke/risk/riskahead/ReportWFActivity.java
index 28a8c7c..55ed95a 100644
--- a/app/src/main/java/org/deke/risk/riskahead/ReportWFActivity.java
+++ b/app/src/main/java/org/deke/risk/riskahead/ReportWFActivity.java
@@ -459,7 +459,6 @@ public class ReportWFActivity extends BaseActivity implements ReportWF_1_Fragmen
private void finishReportAndGotoMap(IncidentReport incident) {
resetStateAndIncident();
- showAd();
gotoMapActivity(incident.getPosition().latitude + ":" + incident.getPosition().longitude);
}
diff --git a/app/src/main/java/org/deke/risk/riskahead/fragment/ReportWF_2_Fragment.java b/app/src/main/java/org/deke/risk/riskahead/fragment/ReportWF_2_Fragment.java
index bfb37af..8f6d6b5 100644
--- a/app/src/main/java/org/deke/risk/riskahead/fragment/ReportWF_2_Fragment.java
+++ b/app/src/main/java/org/deke/risk/riskahead/fragment/ReportWF_2_Fragment.java
@@ -6,6 +6,9 @@ import android.support.v4.app.DialogFragment;
import android.app.TimePickerDialog;
import android.content.Context;
import android.os.Bundle;
+import android.support.v4.app.FragmentManager;
+import android.text.Editable;
+import android.text.TextWatcher;
import android.text.format.DateFormat;
import android.view.LayoutInflater;
import android.view.View;
@@ -46,19 +49,22 @@ public class ReportWF_2_Fragment extends BaseReportWFFragment {
private Spinner timeCategory;
private Spinner timeSubCategory;
- private EditText inputTimeFrom;
- private EditText inputDateFrom;
- private EditText inputTimeTo;
- private EditText inputDateTo;
+ private static EditText inputTimeFrom;
+ private static EditText inputDateFrom;
+ private static EditText inputTimeTo;
+ private static EditText inputDateTo;
- private EditText tmpInput;
+ private static EditText tmpInput;
private IncidentReport incident;
private OnInputFinishedListener mCallback;
- private boolean tmpIsToDate = false;
- private boolean tmpIsToTime = false;
+ public static boolean tmpIsToDate = false;
+ public static boolean tmpIsToTime = false;
+
+ private DialogFragment timePickerFragment;
+ private DialogFragment datePickerFragment;
public interface OnInputFinishedListener {
void onInputFinished(boolean finished);
@@ -194,6 +200,22 @@ public class ReportWF_2_Fragment extends BaseReportWFFragment {
@Override
public void onClick(View v) {
tmpInput = inputDateFrom;
+ tmpInput.addTextChangedListener(new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+
+ }
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
+
+ }
+
+ @Override
+ public void afterTextChanged(Editable s) {
+ checkIfFinished();
+ }
+ });
showDatePickerDialog();
}
});
@@ -202,6 +224,22 @@ public class ReportWF_2_Fragment extends BaseReportWFFragment {
@Override
public void onClick(View v) {
tmpInput = inputTimeFrom;
+ tmpInput.addTextChangedListener(new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+
+ }
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
+
+ }
+
+ @Override
+ public void afterTextChanged(Editable s) {
+ checkIfFinished();
+ }
+ });
showTimePickerDialog();
}
});
@@ -233,7 +271,7 @@ public class ReportWF_2_Fragment extends BaseReportWFFragment {
});
}
- public class TimePickerFragment extends DialogFragment implements TimePickerDialog.OnTimeSetListener {
+ public static class TimePickerFragment extends DialogFragment implements TimePickerDialog.OnTimeSetListener {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
@@ -247,17 +285,22 @@ public class ReportWF_2_Fragment extends BaseReportWFFragment {
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
tmpInput.setText(String.format("%02d:%02d",hourOfDay,minute));
- checkIfFinished();
+ //checkIfFinished();
}
}
public void showTimePickerDialog() {
- DialogFragment newFragment = new TimePickerFragment();
+ FragmentManager fm = getFragmentManager();
+ timePickerFragment = (TimePickerFragment) fm.findFragmentByTag("Pick Time");
- newFragment.show(getActivity().getSupportFragmentManager(), "Pick Time");
+ if(timePickerFragment == null){
+ timePickerFragment = new TimePickerFragment();
+ }
+
+ timePickerFragment.show(fm, "Pick Time");
}
- public class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {
+ public static class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
@@ -286,13 +329,20 @@ public class ReportWF_2_Fragment extends BaseReportWFFragment {
public void onDateSet(DatePicker view, int year, int month, int day) {
tmpInput.setText(String.format("%04d-%02d-%02d",year,month + 1,day));
- checkIfFinished();
+ //checkIfFinished();
}
}
public void showDatePickerDialog() {
- DialogFragment newFragment = new DatePickerFragment();
- newFragment.show(getActivity().getSupportFragmentManager(), "Pick Date");
+
+ FragmentManager fm = getFragmentManager();
+ datePickerFragment = (DatePickerFragment) fm.findFragmentByTag("Pick Date");
+
+ if(datePickerFragment == null){
+ datePickerFragment = new DatePickerFragment();
+ }
+
+ datePickerFragment.show(fm, "Pick Date");
}
private void checkIfFinished(){
@@ -361,6 +411,25 @@ public class ReportWF_2_Fragment extends BaseReportWFFragment {
checkIfFinished();
}
+ @Override
+ public void onStop() {
+ super.onStop();
+ //invalidate the DialogFragment to avoid stupid memory leak
+ if (timePickerFragment != null) {
+ if (timePickerFragment.isVisible()) {
+ timePickerFragment.dismiss();
+ }
+ timePickerFragment = null;
+ }
+
+ if (datePickerFragment != null) {
+ if (datePickerFragment.isVisible()) {
+ datePickerFragment.dismiss();
+ }
+ datePickerFragment = null;
+ }
+ }
+
@Override
public void onPause() {
super.onPause();
diff --git a/app/src/main/java/org/deke/risk/riskahead/fragment/SettingsFragment.java b/app/src/main/java/org/deke/risk/riskahead/fragment/SettingsFragment.java
index 1ef3bf5..b4cc77a 100644
--- a/app/src/main/java/org/deke/risk/riskahead/fragment/SettingsFragment.java
+++ b/app/src/main/java/org/deke/risk/riskahead/fragment/SettingsFragment.java
@@ -128,7 +128,9 @@ public class SettingsFragment extends PreferenceFragment {
prefLocation.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
- if (session.getLocation().longitude != 0.0 && session.getLocation().latitude != 0.0) {
+ if (session.getManualLocation().longitude != 0.0 && session.getManualLocation().latitude != 0.0) {
+ ((SettingsActivity) getActivity()).getNotifyLocationFromMapActivity(Double.toString(session.getManualLocation().latitude) + " : " + Double.toString(session.getManualLocation().longitude));
+ } else if(session.getLocation().longitude != 0.0 && session.getLocation().latitude != 0.0){
((SettingsActivity) getActivity()).getNotifyLocationFromMapActivity(Double.toString(session.getLocation().latitude) + " : " + Double.toString(session.getLocation().longitude));
} else {
((SettingsActivity) getActivity()).getNotifyLocationFromMapActivity();
@@ -218,7 +220,7 @@ public class SettingsFragment extends PreferenceFragment {
prefRadius.setValue(Integer.toString(session.getNotificationRadius()));
prefRadius.setSummary(prefRadius.getEntry());
prefGPSENabled.setChecked(session.isGPSForNotificationsEnabled());
- prefLocation.setSummary(getResources().getString(R.string.txt_settings_gps_loca_sum)+":\n"+Double.toString(session.getLocation().latitude)+" : "+Double.toString(session.getLocation().longitude));
+ prefLocation.setSummary(getResources().getString(R.string.txt_settings_gps_loca_sum)+":\n"+Double.toString(session.getManualLocation().latitude)+" : "+Double.toString(session.getManualLocation().longitude));
if(session.getSubsPremium()){
if(session.isGPSForNotificationsEnabled()){
diff --git a/app/src/main/java/org/deke/risk/riskahead/helper/BaseActivity.java b/app/src/main/java/org/deke/risk/riskahead/helper/BaseActivity.java
index 46e4ce5..95b14a2 100644
--- a/app/src/main/java/org/deke/risk/riskahead/helper/BaseActivity.java
+++ b/app/src/main/java/org/deke/risk/riskahead/helper/BaseActivity.java
@@ -71,11 +71,9 @@ import java.util.Locale;
import java.util.Map;
/**
- *
* (C) Copyright 2016 RiskAhead (http://www.riskahead.net)
* Developer & Contributor: Dennis Thießen (dennis.thiessen@riskahead.net)
* Date of Release: 10.02.2016
- *
*/
public abstract class BaseActivity extends AppCompatActivity {
@@ -106,14 +104,14 @@ public abstract class BaseActivity extends AppCompatActivity {
int onStartCount = 0;
- public void userHasToBeLoggedIn(){
+ public void userHasToBeLoggedIn() {
if (!session.isLoggedIn()) {
logout();
}
isNetworkAvailable();
}
- public HashMap getUser(){
+ public HashMap getUser() {
user = session.getUserDetails();
return user;
}
@@ -137,14 +135,11 @@ public abstract class BaseActivity extends AppCompatActivity {
super.onCreate(savedInstanceState);
-
onStartCount = 1;
- if (savedInstanceState == null)
- {
+ if (savedInstanceState == null) {
this.overridePendingTransition(R.anim.slide_in_left,
R.anim.slide_out_left);
- } else
- {
+ } else {
onStartCount = 2;
}
@@ -156,22 +151,15 @@ public abstract class BaseActivity extends AppCompatActivity {
session = new SessionManager(getApplicationContext());
user = session.getUserDetails();
- Log.d(TAG,user.get(SessionManager.KEY_UID));
+ Log.d(TAG, user.get(SessionManager.KEY_UID));
mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
initNavigationDrawer(savedInstanceState);
-
- if(!isMyNotificationServiceRunning() && session.getNotificationEnabled()){
-
- if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
- ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.ACCESS_FINE_LOCATION,Manifest.permission.ACCESS_COARSE_LOCATION},1);
- return;
- }
-
- Log.d(TAG,"onCreate: NotificationService not running. Starting service...");
+ if (!isMyNotificationServiceRunning()) {
+ Log.d(TAG, "onCreate: NotificationService not running. Starting service...");
Intent wtdSServiceIntent = new Intent(this, NotificationService.class);
PendingIntent wtdSServicePendingIntent = PendingIntent.getService(this, 0, wtdSServiceIntent, 0);
@@ -182,13 +170,12 @@ public abstract class BaseActivity extends AppCompatActivity {
AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
am.setInexactRepeating(AlarmManager.RTC, firstStart, interval,
- wtdSServicePendingIntent);
+ wtdSServicePendingIntent);
- Log.d(TAG, "AlarmManager set");
startService(new Intent(this, NotificationService.class));
- }else{
- Log.d(TAG,"onCreate: NotificationService already running. Not starting more services.");
+ } else {
+ Log.d(TAG, "onCreate: NotificationService already running. Not starting more services.");
}
AppRater.app_launched(BaseActivity.this);
@@ -203,30 +190,29 @@ public abstract class BaseActivity extends AppCompatActivity {
}
@Override
- protected void onDestroy(){
+ protected void onDestroy() {
super.onDestroy();
unregisterBroadcastReceiver();
}
@Override
- protected void onResume(){
+ protected void onResume() {
super.onResume();
registerBroadcastReceiver();
-
}
- public void registerBroadcastReceiver(){
+ public void registerBroadcastReceiver() {
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(AppConfig.INTENT_LOGOUT);
myReceiver = new LogoutReceiver();
registerReceiver(myReceiver, intentFilter);
}
- public void unregisterBroadcastReceiver(){
- try{
+ public void unregisterBroadcastReceiver() {
+ try {
unregisterReceiver(myReceiver);
- }catch(final Exception e){
+ } catch (final Exception e) {
e.printStackTrace();
}
}
@@ -305,7 +291,7 @@ public abstract class BaseActivity extends AppCompatActivity {
@Override
public void onDrawerClosed(View drawerView) {
android.support.v7.app.ActionBar actionBar = getSupportActionBar();
- if(actionBar != null) actionBar.setTitle(getActivityName());
+ if (actionBar != null) actionBar.setTitle(getActivityName());
}
@Override
@@ -324,38 +310,37 @@ public abstract class BaseActivity extends AppCompatActivity {
new DividerDrawerItem(),
item6,
item7).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
- @Override
- public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
+ @Override
+ public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
- switch ((int)drawerItem.getIdentifier()) {
- case 2:
- gotoReportActivity();
- return false;
- case 3:
- gotoMapActivity();
- return false;
- case 4:
- gotoProfileActivity();
- return false;
- case 5:
- gotoSettingsActivity();
- return false;
- case 6:
- gotoSubscriptionsActivity();
- return false;
- case 7:
- logoutUser();
- break;
- default:
- Log.d("Unknown switch page: ", Integer.toString(position));
- break;
- }
-
- return false;
- }
- }).build();
+ switch ((int) drawerItem.getIdentifier()) {
+ case 2:
+ gotoReportActivity();
+ return false;
+ case 3:
+ gotoMapActivity();
+ return false;
+ case 4:
+ gotoProfileActivity();
+ return false;
+ case 5:
+ gotoSettingsActivity();
+ return false;
+ case 6:
+ gotoSubscriptionsActivity();
+ return false;
+ case 7:
+ logoutUser();
+ break;
+ default:
+ Log.d("Unknown switch page: ", Integer.toString(position));
+ break;
+ }
+ return false;
+ }
+ }).build();
}
@@ -366,25 +351,23 @@ public abstract class BaseActivity extends AppCompatActivity {
mInterstitialAd.loadAd(adRequest);
}
- public void showAd(){
- if(System.currentTimeMillis() == 0) session.setLastAddShown(System.currentTimeMillis());
+ public void showAd() {
+ if (session.getLastAddShown() == 0) session.setLastAddShown(System.currentTimeMillis());
- if(System.currentTimeMillis() > session.getLastAddShown()+120000){
+ if (System.currentTimeMillis() > (session.getLastAddShown() + 120000)) {
Log.d(TAG, "SHOW ADD!");
- if (mInterstitialAd.isLoaded()) {
- Log.d(TAG, "Loading Add...");
- if(!(session.getSubsNoAds() || session.getSubsPremium())){
-
+ if (mInterstitialAd.isLoaded()) {
+ Log.d(TAG, "Loading Add...");
+ if (!(session.getSubsNoAds() || session.getSubsPremium())) {
mInterstitialAd.show();
session.setLastAddShown(System.currentTimeMillis());
-
- }else{
- Log.d(TAG,"Add not shown because user has status.");
+ } else {
+ Log.d(TAG, "Add not shown because user has status.");
+ }
}
- }
- }else{
+ } else {
Log.d(TAG, "SHOW NO ADD ( TIME NOT OUT ) !");
}
}
@@ -393,7 +376,7 @@ public abstract class BaseActivity extends AppCompatActivity {
ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
- if(activeNetworkInfo == null){
+ if (activeNetworkInfo == null) {
new AlertDialog.Builder(this)
.setTitle(getString(R.string.alert_internetconnection_title))
.setMessage(getString(R.string.alert_internetconnection_text))
@@ -441,13 +424,13 @@ public abstract class BaseActivity extends AppCompatActivity {
return true;
}
- public void gotoReportActivity(){
+ public void gotoReportActivity() {
Intent intent;
intent = new Intent(getApplicationContext(), ReportWFActivity.class);
startActivity(intent);
}
- public void gotoReportActivity(String position){
+ public void gotoReportActivity(String position) {
Intent intent;
intent = new Intent(getApplicationContext(), ReportWFActivity.class);
intent.putExtra(EXTRA_MESSAGE, position);
@@ -455,34 +438,34 @@ public abstract class BaseActivity extends AppCompatActivity {
finish();
}
- public void gotoMapActivity(){
+ public void gotoMapActivity() {
Intent intent;
intent = new Intent(BaseActivity.this, MapsActivity.class);
BaseActivity.this.startActivity(intent);
}
- public void gotoMapActivity(String position){
+ public void gotoMapActivity(String position) {
Intent intent;
intent = new Intent(getApplicationContext(), MapsActivity.class);
intent.putExtra(EXTRA_MESSAGE, position);
startActivity(intent);
}
- public void getNotifyLocationFromMapActivity(){
+ public void getNotifyLocationFromMapActivity() {
Intent intent;
intent = new Intent(getApplicationContext(), MapsActivity.class);
intent.putExtra(AppConfig.EXTRA_MAP_TYPE, AppConfig.INTENT_MAP_GETNOTIFY);
startActivity(intent);
}
- public void getIncidentLocationFromMapActivity(){
+ public void getIncidentLocationFromMapActivity() {
Intent intent;
intent = new Intent(getApplicationContext(), MapsActivity.class);
intent.putExtra(AppConfig.EXTRA_MAP_TYPE, AppConfig.INTENT_MAP_GETINCLOC);
startActivity(intent);
}
- public void getNotifyLocationFromMapActivity(String position){
+ public void getNotifyLocationFromMapActivity(String position) {
Intent intent;
intent = new Intent(getApplicationContext(), MapsActivity.class);
intent.putExtra(EXTRA_MESSAGE, position);
@@ -490,7 +473,7 @@ public abstract class BaseActivity extends AppCompatActivity {
startActivity(intent);
}
- public void getIncidentLocationFromMapActivity(String position){
+ public void getIncidentLocationFromMapActivity(String position) {
Intent intent;
intent = new Intent(getApplicationContext(), MapsActivity.class);
intent.putExtra(EXTRA_MESSAGE, position);
@@ -498,32 +481,32 @@ public abstract class BaseActivity extends AppCompatActivity {
startActivity(intent);
}
- public void gotoProfileActivity(){
+ public void gotoProfileActivity() {
Intent intent;
intent = new Intent(getApplicationContext(), ProfileActivity.class);
startActivity(intent);
}
- public void gotoProfileActivity(String uid){
+ public void gotoProfileActivity(String uid) {
Intent intent;
intent = new Intent(getApplicationContext(), ProfileActivity.class);
intent.putExtra(EXTRA_MESSAGE, uid);
startActivity(intent);
}
- public void gotoSettingsActivity(){
+ public void gotoSettingsActivity() {
Intent intent;
intent = new Intent(getApplicationContext(), SettingsActivity.class);
startActivity(intent);
}
- public void gotoSubscriptionsActivity(){
+ public void gotoSubscriptionsActivity() {
Intent intent;
intent = new Intent(getApplicationContext(), SubscriptionsActivity.class);
startActivity(intent);
}
- public void gotoViewReportActivity(Integer uid){
+ public void gotoViewReportActivity(Integer uid) {
Intent intent;
intent = new Intent(getApplicationContext(), ViewReportActivity.class);
intent.putExtra(EXTRA_MESSAGE, uid);
@@ -534,36 +517,36 @@ public abstract class BaseActivity extends AppCompatActivity {
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
- if((id == R.id.menu_action_exit)){
+ if ((id == R.id.menu_action_exit)) {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
- }else if((id == R.id.menu_action_about)){
+ } else if ((id == R.id.menu_action_about)) {
showAboutInfoDialog();
- }else if((id == R.id.menu_action_language)){
+ } else if ((id == R.id.menu_action_language)) {
showLanguageDialog();
- }else if((id == R.id.menu_action_help)){
+ } else if ((id == R.id.menu_action_help)) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.riskahead.net/contact/"));
startActivity(browserIntent);
- }else if((id == R.id.menu_action_feedback)){
+ } else if ((id == R.id.menu_action_feedback)) {
showFeedbackDialog();
}
return super.onOptionsItemSelected(item);
}
- private void showLanguageDialog(){
+ private void showLanguageDialog() {
AlertDialog.Builder b = new AlertDialog.Builder(this);
b.setTitle(R.string.txt_language_title);
- String[] types = {"ar - العربية", "de - Deutsch", "en - English", "es - Español", "et - Eesti keel", "fi - Suomi", "fr - Français", "lv - Latviešu valoda", "mn - Монгол хэл", "nl - Nederlands", "pl - Polszczyzna", "pt - Português do Brasil", "ru - Pусский", "tr - Türkçe"};
+ String[] types = {"ar - العربية", "de - Deutsch", "en - English", "es - Español", "et - Eesti keel", "fi - Suomi", "fr - Français", "lv - Latviešu valoda", "mn - Монгол хэл", "nl - Nederlands", "pl - Polszczyzna", "pt - Português do Brasil", "ru - Pусский", "tr - Türkçe"};
b.setItems(types, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
- switch(which){
+ switch (which) {
case 0:
setLocale("ar");
break;
@@ -635,12 +618,12 @@ public abstract class BaseActivity extends AppCompatActivity {
((TextView) dialoglayout.findViewById(R.id.txt_about_terms)).setMovementMethod(LinkMovementMethod.getInstance());
try {
- ((TextView) dialoglayout.findViewById(R.id.lbl_about_version)).setText(String.format("Version: %s",getPackageManager().getPackageInfo(getPackageName(), 0).versionName));
+ ((TextView) dialoglayout.findViewById(R.id.lbl_about_version)).setText(String.format("Version: %s", getPackageManager().getPackageInfo(getPackageName(), 0).versionName));
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
- AlertDialog.Builder builder = new AlertDialog.Builder(BaseActivity.this)
+ AlertDialog.Builder builder = new AlertDialog.Builder(BaseActivity.this)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//do nothing
@@ -652,7 +635,7 @@ public abstract class BaseActivity extends AppCompatActivity {
}
private void showFeedbackDialog() {
- AlertDialog.Builder alert=new AlertDialog.Builder(this);
+ AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle(R.string.menu_action_feedback);
alert.setMessage(R.string.txt_feedback_message);
@@ -664,7 +647,7 @@ public abstract class BaseActivity extends AppCompatActivity {
input.setLayoutParams(lp);
input.setLines(4);
- input.setBackgroundColor(ContextCompat.getColor(getApplicationContext(),R.color.bootstrap_gray_lightest));
+ input.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.bootstrap_gray_lightest));
input.setGravity(Gravity.TOP);
input.setHint(R.string.txt_feedback_hint);
@@ -686,7 +669,7 @@ public abstract class BaseActivity extends AppCompatActivity {
});
AlertDialog ad = alert.create();
- ad.setView(input,0,50,0,20);
+ ad.setView(input, 0, 50, 0, 20);
ad.show();
}
@@ -697,11 +680,11 @@ public abstract class BaseActivity extends AppCompatActivity {
while (e.hasMoreElements()) {
String k = (String) e.nextElement();
String v = props.getProperty(k);
- sysprop += k+": "+v+"\n";
+ sysprop += k + ": " + v + "\n";
}
- StringRequest strReq = getStringRequestSendFeedback(feedback,sysprop);
+ StringRequest strReq = getStringRequestSendFeedback(feedback, sysprop);
String tag_string_req = "reqsendfeedback";
AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
}
@@ -748,7 +731,7 @@ public abstract class BaseActivity extends AppCompatActivity {
};
}
- public void showMessage(String statusText){
+ public void showMessage(String statusText) {
Toast.makeText(this, statusText, Toast.LENGTH_LONG).show();
}
@@ -795,5 +778,4 @@ public abstract class BaseActivity extends AppCompatActivity {
}
-
}
diff --git a/app/src/main/java/org/deke/risk/riskahead/helper/NotificationService.java b/app/src/main/java/org/deke/risk/riskahead/helper/NotificationService.java
index ead2885..a0d5dda 100644
--- a/app/src/main/java/org/deke/risk/riskahead/helper/NotificationService.java
+++ b/app/src/main/java/org/deke/risk/riskahead/helper/NotificationService.java
@@ -51,11 +51,16 @@ public class NotificationService extends Service {
private static final int MIN_DISTANCE_CHANGE_FOR_UPDATES = 10; // 10 meters
private static final int MIN_TIME_BW_UPDATES = 1000 * 60; // 1 minute
+ private static int gpscounter = 0;
public SessionManager session;
+
public HashMap user;
- public LocationManager locationManager;
+ private LocationManager locationManager;
+ private LocationListener locationListener;
+
+ private LatLng myPosition;
public NotificationService() {
super();
@@ -63,75 +68,87 @@ public class NotificationService extends Service {
@Override
public void onCreate() {
- Log.d(TAG, "onCreate NotificationService");
-
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
session = new SessionManager(getApplicationContext());
user = session.getUserDetails();
- locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
- LocationListener locationListener = new MyLocationListener();
+ Log.d(TAG, "NotificationService created. Starting notification task...");
+ mNotifyTask.run();
+ }
- if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
- if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
- Log.d(TAG,"Locationservice enabled - GPS Provider Found");
+ private void initAndGetPosition() {
+ Log.d(TAG,"Trying to get a position. GPS enabled: "+session.isGPSForNotificationsEnabled());
+ if(session.isGPSForNotificationsEnabled()) {
- locationManager.requestLocationUpdates(
- LocationManager.GPS_PROVIDER,
- MIN_TIME_BW_UPDATES,
- MIN_DISTANCE_CHANGE_FOR_UPDATES, locationListener);
- Log.d("GPS Enabled", "GPS Enabled");
+ if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
+ locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
+ locationListener = new MyLocationListener();
- if (locationManager != null) {
- Location tmpLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
- if (tmpLocation != null) {
- session.setLocation(Double.doubleToRawLongBits(tmpLocation.getLatitude()),Double.doubleToRawLongBits(tmpLocation.getLongitude()));
+ if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
+ Log.d(TAG, "Locationservice enabled - GPS Provider Found");
+
+ locationManager.requestLocationUpdates(
+ LocationManager.GPS_PROVIDER,
+ MIN_TIME_BW_UPDATES,
+ MIN_DISTANCE_CHANGE_FOR_UPDATES, locationListener);
+ Log.d(TAG, "GPS Provider enabled");
+
+ if (locationManager != null) {
+ Location tmpLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
+ if (tmpLocation != null) {
+ Log.d(TAG,"Last known position found from GPS Provider");
+ removeLocationListener();
+ session.setLocation(Double.doubleToRawLongBits(tmpLocation.getLatitude()), Double.doubleToRawLongBits(tmpLocation.getLongitude()));
+ myPosition = session.getLocation();
+ session.setNotificationServiceReady(true);
+ }
}
- }
- }else if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
- // get location from Network Provider
- Log.d(TAG,"Locationservice enabled - Network Provider Found");
- locationManager.requestLocationUpdates(
- LocationManager.NETWORK_PROVIDER,
- 22,
- 33, locationListener);
- Log.d("Network", "Network");
- if (locationManager != null) {
- Location tmpLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
- if (tmpLocation != null) {
- session.setLocation(Double.doubleToRawLongBits(tmpLocation.getLatitude()),Double.doubleToRawLongBits(tmpLocation.getLongitude()));
+ } else if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
+ // get location from Network Provider
+ Log.d(TAG, "Locationservice enabled - Network Provider Found");
+ locationManager.requestLocationUpdates(
+ LocationManager.NETWORK_PROVIDER,
+ MIN_TIME_BW_UPDATES,
+ MIN_DISTANCE_CHANGE_FOR_UPDATES, locationListener);
+ Log.d(TAG, "Network Provider enabled");
+ if (locationManager != null) {
+ Location tmpLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
+ if (tmpLocation != null) {
+ Log.d(TAG,"Last known position found from Network Provider");
+ removeLocationListener();
+ session.setLocation(Double.doubleToRawLongBits(tmpLocation.getLatitude()), Double.doubleToRawLongBits(tmpLocation.getLongitude()));
+ myPosition = session.getLocation();
+ session.setNotificationServiceReady(true);
+ }
}
}
}
-
-
-
- locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 5000, 10, locationListener);
+ }else{
+ myPosition = session.getManualLocation();
}
+ }
- Log.d(TAG, "Service Created. Starting notification task...");
- mNotifyTask.run();
+ private void removeLocationListener() {
+ if(locationManager != null && locationListener != null){
+ locationManager.removeUpdates(locationListener);
+ locationListener = null;
+ locationManager = null;
+ }
}
private class MyLocationListener implements LocationListener {
@Override
public void onLocationChanged(Location loc) {
- if(session.isGPSForNotificationsEnabled() && loc.getLongitude() != 0.0 && loc.getLatitude() != 0.0) {
- Log.d(TAG, "Save GPS as new location...");
- if(session.getLocation() == null || session.getLocation().latitude == 0.0 || session.getLocation().longitude == 0.0){
- session.setLocation(Double.doubleToRawLongBits(loc.getLatitude()), Double.doubleToRawLongBits(loc.getLongitude()));
- mNotifyHandler.removeCallbacksAndMessages(null);
- mNotifyTask.run();
- }else{
- session.setLocation(Double.doubleToRawLongBits(loc.getLatitude()), Double.doubleToRawLongBits(loc.getLongitude()));
- }
+ Log.d(TAG,"onLocationChanged: "+gpscounter);
+ session.setLocation(Double.doubleToRawLongBits(loc.getLatitude()), Double.doubleToRawLongBits(loc.getLongitude()));
+ session.setNotificationServiceReady(true);
- session.setNotificationServiceReady(true);
-
- }else{
- Log.d(TAG,"Don't Save GPS as new location because GPS for notifications is disabled...: "+session.isGPSForNotificationsEnabled());
+ if(gpscounter > 3){
+ removeLocationListener();
}
+
+ gpscounter++;
}
@Override
@@ -154,14 +171,15 @@ public class NotificationService extends Service {
public void run() {
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND);
- LatLng myPosition = session.getLocation();
+ boolean notifyEnabled = session.getNotificationEnabled();
int radius = session.getNotificationRadius();
int pollFrequency = session.getNotificationPollFreq() * 1000 * 60;
- boolean notifyEnabled = session.getNotificationEnabled();
Log.d(this.toString(), "Run Notification Task. Notifications enabled = " + notifyEnabled);
if(notifyEnabled && session.isLoggedIn()){
+ initAndGetPosition();
+
if ((myPosition != null) && (myPosition.latitude != 0.0) && (myPosition.longitude != 0.0)) {
session.setNotificationServiceReady(true);
String lastNotificationTime;
@@ -172,7 +190,7 @@ public class NotificationService extends Service {
lastNotificationTime = session.getLastNotification();
}
- Log.d(this.toString(), "Lookup location with position: " + myPosition + " Radius: "+ radius +" PollFrequency: "+ pollFrequency +" lastNotifyTime: " + lastNotificationTime);
+ Log.d(this.toString(), "Lookup location with position: " + myPosition + " Radius: "+ radius +" PollFrequency: "+ pollFrequency +" lastNotifyTime: " + lastNotificationTime + " GPSActivated: "+session.isGPSForNotificationsEnabled());
StringRequest strReq = getStringRequestIncidentsFromAreaAndTime(myPosition.latitude, myPosition.longitude, radius, lastNotificationTime);
String tag_string_req = "req_incidents";
@@ -272,18 +290,16 @@ public class NotificationService extends Service {
);
mBuilder.setContentIntent(resultPendingIntent);
- int mId = 1;
- mNotificationManager.notify(mId, mBuilder.build());
-
+ mNotificationManager.notify(1, mBuilder.build());
session.setLastNotification(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime()));
-
}
@Override
public void onDestroy(){
+ if(locationManager != null && locationListener != null) locationManager.removeUpdates(locationListener);
+
super.onDestroy();
+
Log.d(TAG, "Destroy NotificationService");
}
-
-
}
diff --git a/app/src/main/java/org/deke/risk/riskahead/helper/SessionManager.java b/app/src/main/java/org/deke/risk/riskahead/helper/SessionManager.java
index c6f25d7..3092eba 100644
--- a/app/src/main/java/org/deke/risk/riskahead/helper/SessionManager.java
+++ b/app/src/main/java/org/deke/risk/riskahead/helper/SessionManager.java
@@ -49,6 +49,9 @@ public class SessionManager {
public static final String KEY_LOCATION_LAT = "location_latitude";
public static final String KEY_LOCATION_LNG = "location_longitude";
+ public static final String KEY_MAN_LOCATION_LAT = "man_location_latitude";
+ public static final String KEY_MAN_LOCATION_LNG = "man_location_longitude";
+
public static final String KEY_LAST_NOTIFICATION = "lastNotificationTime";
public static final String KEY_NOTIFY_ENABLED = "notifyEnabled" ;
public static final String KEY_NOTIFY_RADIUS = "notifyRadius";
@@ -88,6 +91,16 @@ public class SessionManager {
return new LatLng(Double.longBitsToDouble(status.getLong(KEY_LOCATION_LAT, 0)), Double.longBitsToDouble(status.getLong(KEY_LOCATION_LNG, 0)));
}
+ public void setManualLocation(Long latitude, Long longitude){
+ statusEditor.putLong(KEY_MAN_LOCATION_LAT, latitude);
+ statusEditor.putLong(KEY_MAN_LOCATION_LNG, longitude);
+ statusEditor.apply();
+ }
+
+ public LatLng getManualLocation(){
+ return new LatLng(Double.longBitsToDouble(status.getLong(KEY_MAN_LOCATION_LAT, 0)), Double.longBitsToDouble(status.getLong(KEY_MAN_LOCATION_LNG, 0)));
+ }
+
public void setGPSForNotificationsEnabled(boolean isEnabled){
statusEditor.putBoolean(KEY_NOTIFY_GPS, isEnabled);
statusEditor.apply();
diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml
index f25440d..e8024db 100644
--- a/app/src/main/res/values-de/strings.xml
+++ b/app/src/main/res/values-de/strings.xml
@@ -248,43 +248,43 @@
- - Robbery
- - Drug related
- - Strike/Riot
+ - Überfall
+ - Drogenkriminalität
+ - Streik/Aufstand
- Checkpoint/Blockade
- - Corruption/Extorsion
+ - Korruption/Missbrauch
- - Mugging
- - Sexual Assault
- - Physical Attack
- - Fight
- - Arrest/Capture
- - Forced Labour
+ - Raubüberfall
+ - Sexuelle Belästigung
+ - Physischer Angriff
+ - Kampf
+ - Arrest/Übernahme
+ - Zwangsarbeit
- - Rape
- - Kidnapping/Hostage
- - Shooting
- - Bombing
- - Murder
- - Dead body
+ - Vergewaltigung
+ - Geiselnahme
+ - Schießerei
+ - Bombenangriff
+ - Mord
+ - Leiche
- - Heat Wave
- - Cyclone/Tornado
- - Flood
- - Earthquake
- - Wild Fire
- - Volcano
+ - Hitzewelle
+ - Tornado
+ - Flut
+ - Erdbeben
+ - Wildfeuer
+ - Vulkanausbruch
- Tsunami
- - Fire
- - Chemical/Oil Spill
- - Epidemic
- - Chaos/Anarchy
+ - Feuer
+ - Chemie-/Ölunfall
+ - Epidemie
+ - Chaos/Anarchie
diff --git a/build.gradle b/build.gradle
index 76c8e46..ffb590c 100644
--- a/build.gradle
+++ b/build.gradle
@@ -6,7 +6,7 @@ buildscript {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
- classpath 'com.android.tools.build:gradle:2.3.0'
+ classpath 'com.android.tools.build:gradle:2.3.1'
classpath 'com.google.gms:google-services:1.3.0-beta3'
classpath 'io.fabric.tools:gradle:1.+'
}