Skip to content

Commit

Permalink
Merge pull request getodk#2293 from jd-alexander/geo_point_fix
Browse files Browse the repository at this point in the history
GeoPointMapActivity crash when map isn't ready resolved
  • Loading branch information
lognaturel authored Jun 15, 2018
2 parents ffb576c + bcf7b9c commit 3d046bf
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package org.odk.collect.android.activities;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.location.Location;
Expand All @@ -33,7 +32,6 @@
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMapLongClickListener;
import com.google.android.gms.maps.GoogleMap.OnMarkerDragListener;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
Expand Down Expand Up @@ -129,14 +127,11 @@ public void onCreate(Bundle savedInstanceState) {
showLocation = findViewById(R.id.show_location);

locationClient = LocationClients.clientForContext(this);
locationClient.setListener(this);

isMapReady = false;
((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(GoogleMap googleMap) {
setupMap(googleMap);
}
((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMapAsync(googleMap -> {
setupMap(googleMap);
locationClient.setListener(GeoPointMapActivity.this);
});
}

Expand Down Expand Up @@ -219,89 +214,67 @@ public void onClick(View v) {
});

reloadLocation.setEnabled(false);
reloadLocation.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (marker != null) {
marker.remove();
}
latLng = null;
marker = null;
setClear = false;
latLng = new LatLng(location.getLatitude(), location.getLongitude());
markerOptions.position(latLng);
if (marker == null) {
marker = map.addMarker(markerOptions);
if (draggable && !readOnly) {
marker.setDraggable(true);
}
reloadLocation.setOnClickListener(v -> {
if (marker != null) {
marker.remove();
}
latLng = null;
marker = null;
setClear = false;
latLng = new LatLng(location.getLatitude(), location.getLongitude());
markerOptions.position(latLng);
if (marker == null) {
marker = map.addMarker(markerOptions);
if (draggable && !readOnly) {
marker.setDraggable(true);
}
captureLocation = true;
isDragged = false;
zoomToPoint();
}
captureLocation = true;
isDragged = false;
zoomToPoint();
});

// Focuses on marked location
//showLocation.setClickable(false);
showLocation.setEnabled(false);
showLocation.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
showZoomDialog();
}
});
showLocation.setOnClickListener(v -> showZoomDialog());

// Menu Layer Toggle
ImageButton layers = findViewById(R.id.layer_menu);
layers.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
helper.showLayersDialog(GeoPointMapActivity.this);
}
});
layers.setOnClickListener(v -> helper.showLayersDialog(GeoPointMapActivity.this));
zoomDialogView = getLayoutInflater().inflate(R.layout.geo_zoom_dialog, null);
zoomLocationButton = zoomDialogView.findViewById(R.id.zoom_location);
zoomLocationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
zoomToLocation();
zoomDialog.dismiss();
}
zoomLocationButton.setOnClickListener(v -> {
zoomToLocation();
zoomDialog.dismiss();
});

zoomPointButton = zoomDialogView.findViewById(R.id.zoom_saved_location);
zoomPointButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
zoomToPoint();
zoomDialog.dismiss();
}
zoomPointButton.setOnClickListener(v -> {
zoomToPoint();
zoomDialog.dismiss();
});

ImageButton clearPointButton = findViewById(R.id.clear);
clearPointButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (marker != null) {
marker.remove();
}
if (location != null) {
reloadLocation.setEnabled(true);
// locationStatus.setVisibility(View.VISIBLE);
}
// reloadLocation.setEnabled(true);
locationInfo.setVisibility(View.VISIBLE);
locationStatus.setVisibility(View.VISIBLE);
latLng = null;
marker = null;
setClear = true;
isDragged = false;
captureLocation = false;
draggable = intentDraggable;
locationFromIntent = false;
overlayMyLocationLayers();
clearPointButton.setOnClickListener(v -> {
if (marker != null) {
marker.remove();
}
if (location != null) {
reloadLocation.setEnabled(true);
// locationStatus.setVisibility(View.VISIBLE);
}
// reloadLocation.setEnabled(true);
locationInfo.setVisibility(View.VISIBLE);
locationStatus.setVisibility(View.VISIBLE);
latLng = null;
marker = null;
setClear = true;
isDragged = false;
captureLocation = false;
draggable = intentDraggable;
locationFromIntent = false;
overlayMyLocationLayers();
});

Intent intent = getIntent();
Expand Down Expand Up @@ -477,17 +450,10 @@ public void showZoomDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(getString(R.string.zoom_to_where));
builder.setView(zoomDialogView)
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
})
.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
dialog.cancel();
zoomDialog.dismiss();
}
.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.cancel())
.setOnCancelListener(dialog -> {
dialog.cancel();
zoomDialog.dismiss();
});
zoomDialog = builder.create();
}
Expand Down Expand Up @@ -523,20 +489,16 @@ private void showGPSDisabledAlertToUser() {
alertDialogBuilder.setMessage(getString(R.string.gps_enable_message))
.setCancelable(false)
.setPositiveButton(getString(R.string.enable_gps),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
startActivityForResult(
new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS), 0);
errorDialog = null;
}
(dialog, id) -> {
startActivityForResult(
new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS), 0);
errorDialog = null;
});

alertDialogBuilder.setNegativeButton(getString(R.string.cancel),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
errorDialog = null;
}
(dialog, id) -> {
dialog.cancel();
errorDialog = null;
});

errorDialog = alertDialogBuilder.create();
Expand Down
41 changes: 20 additions & 21 deletions config/pmd-ruleset.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0"?>
<!--
<?xml version="1.0"?><!--
~ Copyright 2015 Vincent Brison.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -15,8 +14,7 @@
~ limitations under the License.
-->

<ruleset
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Android Application Rules"
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Android Application Rules"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd">
Expand All @@ -26,14 +24,14 @@
<exclude-pattern>.*/R.java</exclude-pattern>
<exclude-pattern>.*/gen/.*</exclude-pattern>

<rule ref="rulesets/java/android.xml"/>
<rule ref="rulesets/java/clone.xml"/>
<rule ref="rulesets/java/finalizers.xml"/>
<rule ref="rulesets/java/android.xml" />
<rule ref="rulesets/java/clone.xml" />
<rule ref="rulesets/java/finalizers.xml" />
<rule ref="rulesets/java/imports.xml">
<exclude name="TooManyStaticImports"/>
<exclude name="TooManyStaticImports" />
</rule>
<rule ref="rulesets/java/logging-java.xml"/>
<rule ref="rulesets/java/braces.xml"/>
<rule ref="rulesets/java/logging-java.xml" />
<rule ref="rulesets/java/braces.xml" />
<rule ref="rulesets/java/strings.xml">
<exclude name="AvoidDuplicateLiterals" />
<exclude name="InefficientEmptyStringCheck" />
Expand All @@ -51,15 +49,15 @@
<exclude name="ReturnFromFinallyBlock" />
</rule>
<rule ref="rulesets/java/naming.xml">
<exclude name="AbstractNaming"/>
<exclude name="LongVariable"/>
<exclude name="ShortMethodName"/>
<exclude name="ShortVariable"/>
<exclude name="VariableNamingConventions"/>
<exclude name="AvoidFieldNameMatchingMethodName"/>
<exclude name="ShortClassName"/>
<exclude name="MethodNamingConventions"/>
<exclude name="AvoidFieldNameMatchingTypeName"/>
<exclude name="AbstractNaming" />
<exclude name="LongVariable" />
<exclude name="ShortMethodName" />
<exclude name="ShortVariable" />
<exclude name="VariableNamingConventions" />
<exclude name="AvoidFieldNameMatchingMethodName" />
<exclude name="ShortClassName" />
<exclude name="MethodNamingConventions" />
<exclude name="AvoidFieldNameMatchingTypeName" />
</rule>
<rule ref="rulesets/java/design.xml">
<exclude name="ConfusingTernary" />
Expand Down Expand Up @@ -114,13 +112,14 @@
<exclude name="AvoidCatchingNPE" />
<exclude name="AvoidCatchingThrowable" />
</rule>
<rule ref="rulesets/java/typeresolution.xml" >
<rule ref="rulesets/java/typeresolution.xml">
<exclude name="SignatureDeclareThrowsException" />
<exclude name="LooseCoupling" />
</rule>
<rule ref="rulesets/java/unnecessary.xml" >
<rule ref="rulesets/java/unnecessary.xml">
<!-- Decided not to use in #1519 -->
<exclude name="UselessParentheses" />
<exclude name="UselessQualifiedThis" />
</rule>
<rule ref="rulesets/java/codesize.xml">
<exclude name="CyclomaticComplexity" />
Expand Down

0 comments on commit 3d046bf

Please sign in to comment.