/******************************************************************************************************************* * * When the activity is paused, the {@link LocationFinder} is stopped (e.g. to turn the GPS off). * ******************************************************************************************************************/ @Override protected void onPause() { super.onPause(); locationFinder.removePropertyChangeListener(locationFinderListener); locationFinder.stop(); }
public void onClick (final @Nonnull View view) { locationFinder.findAddress(); } };
public void onClick (final @Nonnull View view) { locationFinder.start(); } };
final Range range = locationFinder.getRange(); etCoordinate.setText(locationPreferences.format(range)); btRecomputePlace.setEnabled(true); final Address address = (Address)locationFinder.getAddress(); final State state = locationFinder.getState(); final String providerName = locationFinder.getProviderName(); buffer.append((providerName != null) ? providerName : "no provider"); switch (locationFinder.getProviderStatus())
setAddressSearchEnabled(locationPreferences.isReverseGeocodingEnabled()); setState(IDLE); setProviderName(locationManager.getBestProvider((Criteria)locationPreferences.getCriteria(), true));
public void onSharedPreferenceChanged (final @Nonnull SharedPreferences sharedPreferences, final @Nonnull String string) { setAddressSearchEnabled(locationPreferences.isReverseGeocodingEnabled()); } };
public void renderTo (final @Nonnull TextView textView, @Nonnull Object... extra) { final StringBuilder builder = new StringBuilder(); builder.append(generalPreferences.get().formatDateAndTime(observation.getDate(), "<b>", "</b>")); final Location location = observation.getLocation(); if (location != null) // shouldn't happen, but it does because of various bugs { builder.append("<br>"); builder.append(location.getDisplayName()); try { final Range range = location.as(Range); builder.append(String.format("<br><small>%s</small>", locationPreferences.get().format(range))); } catch (AsException e) { // range not available, never mind } } textView.setText(Html.fromHtml(builder.toString())); } }
/******************************************************************************************************************* * * When the activity is resumed, the {@link LocationFinder} is eventually reactivated; the UI is updated for some * things in the UI that might have been changed after new settings in the preferences. * ******************************************************************************************************************/ @Override protected void onResume() { super.onResume(); // here, so you can detect the locale change map.clear(); map.put(State.COMPUTING_RANGE, getMessage(_, "computingRange")); map.put(State.SEARCHING_FOR_ADDRESS, getMessage(_, "placeSearchInProgress")); map.put(State.IDLE, ""); final boolean geoCodingEnabled = locationFinder.isAddressSearchEnabled(); findViewById(R.id.tvGeocodingDisabled).setVisibility(AndroidUtilities.visibility(!geoCodingEnabled)); btRecomputePlace.setVisibility(AndroidUtilities.visibility(geoCodingEnabled)); // btRecomputePlace.setEnabled(locationFinder.isAddressSearchEnabled()); locationFinder.addPropertyChangeListener(locationFinderListener); // locationFinder.start(); // pre-started by ObservationsActivity updateDisplay(); }
/******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ public void cancelNewObservation() { ThreadAssertions.assertThread(UI); log.info("cancelNewObservation()"); locationFinder.stop(); // we pre-started it view.notifyNewObservationCancelled(notification().withText(_, "addedNewObservationCancelled")); }
/******************************************************************************************************************* * * ******************************************************************************************************************/ @Nonnull public String format (final @Nonnull Range range) { return String.format("%s (\u007E%.0fm)", format(range.getCoordinate()), range.getRadius()); }
/******************************************************************************************************************* * * Adds the picked location to the {@link Observation} being built in the {@link ObservationClipboard}. * ******************************************************************************************************************/ private void commitLocation() { final List<Object> capabilities = new ArrayList<Object>(); capabilities.add(new DefaultDisplayable(etPlace.getText().toString(), "SimpleLocation")); try { capabilities.add(locationFinder.getRange()); } catch (NotFoundException e) { } final Location location = new SimpleLocation(capabilities.toArray()); // FIXME: use observationSet.findOrCreate() final ObservationClipboard observationClipboard = Locator.find(ObservationClipboard.class); final Observation.Builder builder = observationClipboard.getBuilder(); observationClipboard.setBuilder(builder.at(location)); controlFlow.toNextStep(); }
setAddressSearchEnabled(locationPreferences.isReverseGeocodingEnabled()); setState(IDLE); setProviderName(locationManager.getBestProvider((Criteria)locationPreferences.getCriteria(), true));
/******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ public void startNewObservationSequence() { ThreadAssertions.assertThread(UI); log.info("startNewObservationSequence()"); observationClipboard.clear(); final Builder builder = observationClipboard.getBuilder(); observationClipboard.setBuilder(builder.at(Calendar.getInstance().getTime())); locationFinder.start(); // search needs time, and we pre-start it }
public void onSharedPreferenceChanged (final @Nonnull SharedPreferences sharedPreferences, final @Nonnull String string) { setAddressSearchEnabled(locationPreferences.isReverseGeocodingEnabled()); } };
buffer.append(" - ").append(locationPreferences.format(location.as(Range)));