Fix possible NPE

This commit is contained in:
Alexander Sytnyk 2017-08-01 15:16:42 +03:00
parent 1f9a7518d5
commit 3f742be6ec

View file

@ -19,7 +19,6 @@ public class MeasurementToolFragment extends Fragment {
public static final String TAG = "MeasurementToolFragment";
private MapActivity mapActivity;
private MeasurementToolLayer measurementLayer;
private TextView distanceTv;
@ -31,7 +30,7 @@ public class MeasurementToolFragment extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
mapActivity = (MapActivity) getActivity();
MapActivity mapActivity = (MapActivity) getActivity();
measurementLayer = mapActivity.getMapLayers().getMeasurementToolLayer();
IconsCache iconsCache = mapActivity.getMyApplication().getIconsCache();
final boolean nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
@ -75,12 +74,18 @@ public class MeasurementToolFragment extends Fragment {
exitMeasurementMode();
}
private MapActivity getMapActivity() {
return (MapActivity) getActivity();
}
private void updateText() {
distanceTv.setText(measurementLayer.getDistanceSt() + ",");
pointsTv.setText(pointsSt + ": " + measurementLayer.getPointsCount());
}
private void enterMeasurementMode() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
measurementLayer.setInMeasurementMode(true);
mapActivity.refreshMap();
mapActivity.disableDrawer();
@ -98,8 +103,11 @@ public class MeasurementToolFragment extends Fragment {
updateText();
}
}
private void exitMeasurementMode() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
measurementLayer.setInMeasurementMode(false);
mapActivity.refreshMap();
mapActivity.enableDrawer();
@ -114,8 +122,11 @@ public class MeasurementToolFragment extends Fragment {
measurementLayer.clearPoints();
}
}
private void mark(int status, int... widgets) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
for (int widget : widgets) {
View v = mapActivity.findViewById(widget);
if (v != null) {
@ -124,3 +135,4 @@ public class MeasurementToolFragment extends Fragment {
}
}
}
}