Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2014-05-03 16:23:47 +02:00
commit e4befab193
4 changed files with 367 additions and 211 deletions

View file

@ -3,7 +3,7 @@
package="net.osmand.plus" android:installLocation="auto" android:versionName="@string/app_version" android:versionCode="170"> package="net.osmand.plus" android:installLocation="auto" android:versionName="@string/app_version" android:versionCode="170">
<meta-data android:name="com.google.android.backup.api_key" <meta-data android:name="com.google.android.backup.api_key"
android:value="AEdPqrEAAAAIqF3tNGT66etVBn_vgzpfAY1wmIzKV1Ss6Ku-2A" /> android:value="AEdPqrEAAAAIqF3tNGT66etVBn_vgzpfAY1wmIzKV1Ss6Ku-2A" />
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="19"/> <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="19"/>
<uses-feature android:name="android.hardware.camera" android:required="false" /> <uses-feature android:name="android.hardware.camera" android:required="false" />
@ -68,6 +68,7 @@
<category android:name="android.intent.category.CAR_DOCK" /> <category android:name="android.intent.category.CAR_DOCK" />
<category android:name="android.intent.category.DESK_DOCK" /> <category android:name="android.intent.category.DESK_DOCK" />
</intent-filter> </intent-filter>
<!-- android matches non-greedy : http://stackoverflow.com/questions/3400072/pathpattern-to-match-file-extension-does-not-work-if-a-period-exists-elsewhere-i--> <!-- android matches non-greedy : http://stackoverflow.com/questions/3400072/pathpattern-to-match-file-extension-does-not-work-if-a-period-exists-elsewhere-i-->
<!-- mimeType&host are both needed or you will either have unwanted matching or no match when needed --> <!-- mimeType&host are both needed or you will either have unwanted matching or no match when needed -->
<intent-filter> <intent-filter>
@ -78,7 +79,16 @@
<data android:scheme="file" android:host="*" android:mimeType="*/*" android:pathPattern=".*\\..*\\..*\\.gpx"/> <data android:scheme="file" android:host="*" android:mimeType="*/*" android:pathPattern=".*\\..*\\..*\\.gpx"/>
<data android:scheme="file" android:host="*" android:mimeType="*/*" android:pathPattern=".*\\..*\\..*\\..*\\.gpx"/> <data android:scheme="file" android:host="*" android:mimeType="*/*" android:pathPattern=".*\\..*\\..*\\..*\\.gpx"/>
</intent-filter> </intent-filter>
<receiver android:name="net.osmand.plus.audionotes.MediaRemoteControlReceiver">
<!-- google navigation intent -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="google.navigation"/>
</intent-filter>
<receiver android:name="net.osmand.plus.audionotes.MediaRemoteControlReceiver">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.CAMERA_BUTTON" /> <action android:name="android.intent.action.CAMERA_BUTTON" />
<action android:name="android.intent.action.MEDIA_BUTTON" /> <action android:name="android.intent.action.MEDIA_BUTTON" />
@ -117,36 +127,37 @@
<activity android:name="net.osmand.plus.activities.search.SearchStreet2ByNameActivity"></activity> <activity android:name="net.osmand.plus.activities.search.SearchStreet2ByNameActivity"></activity>
<activity android:name="net.osmand.plus.activities.search.SearchBuildingByNameActivity"></activity> <activity android:name="net.osmand.plus.activities.search.SearchBuildingByNameActivity"></activity>
<activity android:name="net.osmand.plus.activities.EditPOIFilterActivity"></activity> <activity android:name="net.osmand.plus.activities.EditPOIFilterActivity"></activity>
<activity android:name="net.osmand.plus.activities.search.GeoIntentActivity"> <activity android:name="net.osmand.plus.activities.search.GeoIntentActivity">
<intent-filter><action android:name="android.intent.action.VIEW"></action> <intent-filter>
<category android:name="android.intent.category.DEFAULT"></category> <data android:scheme="geo" />
<data android:scheme="geo"></data> <action android:name="android.intent.action.VIEW" />
</intent-filter> <category android:name="android.intent.category.DEFAULT" />
<intent-filter> </intent-filter>
<data android:scheme="http" android:host="maps.google.com" /> <intent-filter>
<action android:name="android.intent.action.VIEW" /> <data android:scheme="http" android:host="maps.google.com"/>
<category android:name="android.intent.category.DEFAULT"/> <action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/> <category android:name="android.intent.category.DEFAULT"/>
</intent-filter> <category android:name="android.intent.category.BROWSABLE"/>
<!-- requires read permission --> </intent-filter>
<!-- <!-- requires read permission -->
<intent-filter android:label="OsmAnd"> <!--
<action android:name="android.intent.action.VIEW" /> <intent-filter android:label="OsmAnd">
<category android:name="android.intent.category.DEFAULT" /> <action android:name="android.intent.action.VIEW" />
<data android:mimeType="vnd.android.cursor.item/postal-address_v2" /> <category android:name="android.intent.category.DEFAULT" />
</intent-filter> <data android:mimeType="vnd.android.cursor.item/postal-address_v2" />
--> </intent-filter>
</activity> -->
<activity android:name="net.osmand.plus.development.TestVoiceActivity"></activity> </activity>
<activity android:name="net.osmand.plus.development.TestVoiceActivity"></activity>
<activity android:name="net.osmand.plus.activities.LocalIndexesActivity" android:label="@string/local_index_descr_title"></activity> <activity android:name="net.osmand.plus.activities.LocalIndexesActivity" android:label="@string/local_index_descr_title"></activity>
<activity android:name="net.osmand.plus.osmedit.LocalOpenstreetmapActivity" android:label="@string/local_openstreetmap_act_title"></activity> <activity android:name="net.osmand.plus.osmedit.LocalOpenstreetmapActivity" android:label="@string/local_openstreetmap_act_title"></activity>
<service android:process="net.osmand.plus" android:label="@string/process_navigation_service" android:name="net.osmand.plus.NavigationService"> <service android:process="net.osmand.plus" android:label="@string/process_navigation_service" android:name="net.osmand.plus.NavigationService">
<intent-filter><action android:name="net.osmand.plus.NavigationService"></action></intent-filter> <intent-filter><action android:name="net.osmand.plus.NavigationService"></action></intent-filter>
</service> </service>
<receiver android:name="net.osmand.plus.OnNavigationServiceAlarmReceiver"/> <receiver android:name="net.osmand.plus.OnNavigationServiceAlarmReceiver"/>
<activity android:name="net.osmand.plus.activities.OsmandBidForFixActivity"></activity> <activity android:name="net.osmand.plus.activities.OsmandBidForFixActivity"></activity>
</application> </application>
</manifest> </manifest>

View file

@ -1733,4 +1733,5 @@ Afghanistan, Albania, Algeria, Andorra, Angola, Anguilla, Antigua and Barbuda, A
<string name="av_camera_focus_continuous">The camera continuously tries to focus</string> <string name="av_camera_focus_continuous">The camera continuously tries to focus</string>
<string name="av_photo_play_sound">Play sound on photo shot</string> <string name="av_photo_play_sound">Play sound on photo shot</string>
<string name="av_photo_play_sound_descr">Choose whether to play a sound when shooting photos</string> <string name="av_photo_play_sound_descr">Choose whether to play a sound when shooting photos</string>
<string name="navigation_intent_invalid">Invalid format : %s</string>
</resources> </resources>

View file

@ -6,6 +6,8 @@ import java.util.ArrayList;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.StateChangedListener; import net.osmand.StateChangedListener;
@ -335,10 +337,36 @@ public class MapActivity extends AccessibleActivity {
if (intent.getData() != null) if (intent.getData() != null)
{ {
final Uri data = intent.getData(); final Uri data = intent.getData();
if ("file".equalsIgnoreCase(data.getScheme())) final String scheme = data.getScheme();
if ("file".equals(scheme))
{ {
showImportedGpx(data.getPath()); showImportedGpx(data.getPath());
} }
else if("google.navigation".equals(scheme))
{
final String schemeSpecificPart = data.getSchemeSpecificPart();
final Matcher matcher = Pattern.compile("q=(.+?),(.+?)").matcher(schemeSpecificPart);
if (matcher.matches())
{
try
{
final double lat = Double.valueOf(matcher.group(1));
final double lon = Double.valueOf(matcher.group(2));
getMyApplication().getTargetPointsHelper().navigateToPoint(new LatLon(lat, lon), false, -1);
getMapActions().enterRoutePlanningMode(null, null);
}
catch (NumberFormatException e)
{
AccessibleToast.makeText(this, getString(R.string.navigation_intent_invalid, schemeSpecificPart), Toast.LENGTH_LONG).show(); //$NON-NLS-1$
}
}
else
{
AccessibleToast.makeText(this, getString(R.string.navigation_intent_invalid, schemeSpecificPart), Toast.LENGTH_LONG).show(); //$NON-NLS-1$
}
}
} }
} }
} }

View file

@ -1,5 +1,6 @@
package net.osmand.plus.activities.search; package net.osmand.plus.activities.search;
import android.os.AsyncTask;
import gnu.trove.map.hash.TLongObjectHashMap; import gnu.trove.map.hash.TLongObjectHashMap;
import java.util.ArrayList; import java.util.ArrayList;
@ -7,6 +8,8 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.osmand.ResultMatcher; import net.osmand.ResultMatcher;
import net.osmand.access.AccessibleToast; import net.osmand.access.AccessibleToast;
@ -42,59 +45,110 @@ import android.widget.Toast;
public class GeoIntentActivity extends OsmandListActivity { public class GeoIntentActivity extends OsmandListActivity {
private ProgressDialog progressDlg; private ProgressDialog progressDlg;
private LatLon location; private LatLon location;
private ProgressDialog startProgressDialog; private ProgressDialog startProgressDialog;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState); {
setContentView(R.layout.search_address_offline); super.onCreate(savedInstanceState);
getSupportActionBar().setTitle(R.string.search_osm_offline); setContentView(R.layout.search_address_offline);
startProgressDialog = new ProgressDialog(this); getSupportActionBar().setTitle(R.string.search_osm_offline);
getMyApplication().checkApplicationIsBeingInitialized(this, startProgressDialog); startProgressDialog = new ProgressDialog(this);
location = getMyApplication().getSettings().getLastKnownMapLocation(); getMyApplication().checkApplicationIsBeingInitialized(this, startProgressDialog);
final Intent intent = getIntent(); location = getMyApplication().getSettings().getLastKnownMapLocation();
if (intent != null) {
progressDlg = ProgressDialog.show(this, final Intent intent = getIntent();
getString(R.string.searching), if (intent != null)
getString(R.string.searching_address)); {
final Thread searcher = new Thread(new Runnable() { final ProgressDialog progress = ProgressDialog.show(GeoIntentActivity.this, getString(R.string.searching), getString(R.string.searching_address));
@Override final GeoIntentTask task = new GeoIntentTask(progress, intent);
public void run() {
try { progress.setOnCancelListener(new OnCancelListener()
while(getMyApplication().isApplicationInitializing()) { {
Thread.sleep(200); @Override
} public void onCancel(DialogInterface dialog)
Collection<? extends MapObject> results = extract( {
intent.getData()).execute(); task.cancel(true);
// show the first result on map, and populate the list! }
if (!results.isEmpty()) { });
showResult(0, new ArrayList<MapObject>(results)); progress.setCancelable(true);
} else {
showResult(R.string.search_nothing_found, null); task.execute();
} }
} catch (Exception e) { }
e.printStackTrace();
showResult(R.string.error_doing_search, null); private class GeoIntentTask extends AsyncTask<Void,Void, ExecutionResult>
} finally { {
if (progressDlg != null) { private final ProgressDialog progress;
progressDlg.dismiss(); private final Intent intent;
}
} private GeoIntentTask(final ProgressDialog progress, final Intent intent)
} {
}, "SearchingAddress"); this.progress = progress;
searcher.start(); this.intent = intent;
progressDlg.setOnCancelListener(new OnCancelListener() { }
@Override
public void onCancel(DialogInterface dialog) { @Override
searcher.interrupt(); protected void onPreExecute()
} {
}); }
progressDlg.setCancelable(true);
} @Override
// finish(); protected ExecutionResult doInBackground(Void... nothing)
} {
try
{
while (getMyApplication().isApplicationInitializing())
{
Thread.sleep(200);
}
return extract(intent.getScheme(), intent.getData()).execute();
}
catch (Exception e)
{
return null;
}
}
@Override
protected void onPostExecute(ExecutionResult result)
{
progress.dismiss();
if (result != null)
{
if (result.isEmpty())
{
AccessibleToast.makeText(GeoIntentActivity.this, getString(R.string.search_nothing_found), Toast.LENGTH_LONG).show();
}
else
{
if (result.hasZoom())
{
getMyApplication().getSettings().setLastKnownMapZoom(result.getZoom());
}
final List<MapObject> places = new ArrayList<MapObject>(result.getMapObjects());
setListAdapter(new MapObjectAdapter(places));
if (places.size() == 1)
{
onListItemClick(
getListView(),
getListAdapter().getView(0, null, null),
0,
getListAdapter().getItemId(0)
);
}
}
}
else
{
AccessibleToast.makeText(GeoIntentActivity.this, getString(R.string.search_offline_geo_error, intent.getData()), Toast.LENGTH_LONG).show();
}
}
}
@Override @Override
protected Dialog onCreateDialog(int id) { protected Dialog onCreateDialog(int id) {
@ -104,26 +158,7 @@ public class GeoIntentActivity extends OsmandListActivity {
return super.onCreateDialog(id); return super.onCreateDialog(id);
} }
private void showResult(final int warning, final List<MapObject> places) { private class MapObjectAdapter extends ArrayAdapter<MapObject> {
runOnUiThread(new Runnable() {
@Override
public void run() {
if (places == null) {
AccessibleToast.makeText(GeoIntentActivity.this, getString(warning),
Toast.LENGTH_LONG).show();
} else {
setListAdapter(new MapObjectAdapter(places));
if (places.size() == 1) {
onListItemClick(getListView(), getListAdapter()
.getView(0, null, null), 0, getListAdapter()
.getItemId(0));
}
}
}
});
}
class MapObjectAdapter extends ArrayAdapter<MapObject> {
public MapObjectAdapter(List<MapObject> places) { public MapObjectAdapter(List<MapObject> places) {
super(GeoIntentActivity.this, super(GeoIntentActivity.this,
@ -190,74 +225,117 @@ public class GeoIntentActivity extends OsmandListActivity {
} }
/** /**
* geo:latitude,longitude<BR> * Extracts information from geo and map intents:
* geo:latitude,longitude?z=zoom<BR> *
* geo:0,0?q=my+street+address<BR> * geo:47.6,-122.3<br/>
* geo:0,0?q=business+near+city * geo:47.6,-122.3?z=11<br/>
* * geo:0,0?q=34.99,-106.61(Treasure)<br/>
* @param data * geo:0,0?q=1600+Amphitheatre+Parkway%2C+CA<br/>
*
* @param scheme The intent scheme
* @param data The intent uri
* @return * @return
*/ */
private MyService extract(Uri data) { private MyService extract(final String scheme, final Uri data)
if ("http".equalsIgnoreCase(data.getScheme()) && "maps.google.com".equals(data.getHost())) { {
String q = null; if ("http".equals(scheme))
String parameter = data.getQueryParameter("q"); {
if (parameter == null) { String q = null;
parameter = data.getQueryParameter("daddr"); String parameter = data.getQueryParameter("q");
} if (parameter == null)
if(parameter != null) { {
q = parameter.split(" ")[0]; parameter = data.getQueryParameter("daddr");
} }
if (q.indexOf(',') != -1) { if (parameter != null)
int i = q.indexOf(','); {
String lat = q.substring(0, i); q = parameter.split(" ")[0];
String lon = q.substring(i + 1); }
if (lat.indexOf(':') != -1) { if (q.indexOf(',') != -1)
i = lat.indexOf(':'); {
lat = lat.substring(i + 1); int i = q.indexOf(',');
} String lat = q.substring(0, i);
try { String lon = q.substring(i + 1);
double llat = Double.parseDouble(lat.trim()); if (lat.indexOf(':') != -1)
double llon = Double.parseDouble(lon.trim()); {
return new GeoPointSearch(llat, llon); i = lat.indexOf(':');
} catch (NumberFormatException e) { lat = lat.substring(i + 1);
showErrorMessage(q); }
} try
} else { {
showErrorMessage(q); double llat = Double.parseDouble(lat.trim());
} double llon = Double.parseDouble(lon.trim());
} else if (data.getSchemeSpecificPart().indexOf("0,0?") != -1) { return new GeoPointSearch(llat, llon);
// it is 0,0? that means a search }
return new GeoAddressSearch(data.getQuery()); catch (NumberFormatException e)
} else { {
String geo = data.getSchemeSpecificPart(); return null;
if(geo == null) { }
showErrorMessage(""); }
} else { else
int latIndex = geo.indexOf(','); {
if (latIndex > 0) { return null;
int lonIndex = geo.indexOf(',', latIndex + 1); }
int altIndex = geo.indexOf(';', latIndex + 1); }
int paramIndex = geo.indexOf('?', latIndex + 1); if ("geo".equals(scheme))
paramIndex = paramIndex > 0 ? paramIndex : geo.length(); {
altIndex = altIndex > 0 && altIndex < paramIndex ? altIndex : paramIndex; //geo:
lonIndex = lonIndex > 0 && lonIndex < altIndex ? lonIndex : altIndex; final String schemeSpecific = data.getSchemeSpecificPart();
try { if (schemeSpecific == null)
double lat = Double.parseDouble(geo.substring(0, latIndex).trim()); {
double lon = Double.parseDouble(geo.substring(latIndex + 1, lonIndex).trim()); return null;
return new GeoPointSearch(lat, lon); }
} catch (NumberFormatException e) { if (schemeSpecific.startsWith("0,0?q="))
showErrorMessage(geo); {
} //geo:0,0?q=34.99,-106.61(Treasure)
} else { //geo:0,0?q=1600+Amphitheatre+Parkway%2C+CA
showErrorMessage(geo); final String query = schemeSpecific.substring("0,0?q=".length());
}
}
}
return new Empty();
}
private final class GeoAddressSearch implements MyService { final Matcher matcher = Pattern.compile("([\\-0-9.]+),([\\-0-9.]+)(?:,[\\-0-9.]+)?\\((.+?)\\)").matcher(query);
if (matcher.matches())
{
final double lat = Double.valueOf(matcher.group(1));
final double lon = Double.valueOf(matcher.group(2));
final String name = matcher.group(3);
return new GeoPointSearch(lat, lon, name);
}
else
{
//we suppose it's a search
return new GeoAddressSearch(query);
}
}
else
{
//geo:47.6,-122.3
//geo:47.6,-122.3?z=11
//allow for http://tools.ietf.org/html/rfc5870 (geo uri) , just ignore everything after ';'
final String pattern = "([\\-0-9.]+),([\\-0-9.]+)(?:,([\\-0-9.]+))?(?:\\?z=([0-9]+))?(?:;.*)?";
final Matcher matcher = Pattern.compile(pattern).matcher(schemeSpecific);
if (matcher.matches())
{
final double lat = Double.valueOf(matcher.group(1));
final double lon = Double.valueOf(matcher.group(2));
if (matcher.group(4) == null)
{
return new GeoPointSearch(lat, lon);
}
else
{
return new GeoPointSearch(lat, lon, Integer.valueOf(matcher.group(4)));
}
}
else
{
return null;
}
}
}
return null;
}
private final class GeoAddressSearch implements MyService {
private List<String> elements; private List<String> elements;
public GeoAddressSearch(String query) { public GeoAddressSearch(String query) {
@ -318,14 +396,14 @@ public class GeoIntentActivity extends OsmandListActivity {
} }
@Override @Override
public Collection<? extends MapObject> execute() { public ExecutionResult execute() {
if (elements.isEmpty()) { if (elements.isEmpty()) {
return Collections.emptyList(); return ExecutionResult.EMPTY;
} }
List<String> q = new ArrayList<String>(elements); List<String> q = new ArrayList<String>(elements);
MapObject geo = checkGeoPoint(); MapObject geo = checkGeoPoint();
if(geo != null) { if(geo != null) {
return Collections.singleton(geo); return new ExecutionResult(Collections.singleton(geo));
} }
// now try to search the City, Street, Etc.. if Street is not found, // now try to search the City, Street, Etc.. if Street is not found,
@ -357,7 +435,7 @@ public class GeoIntentActivity extends OsmandListActivity {
} }
} }
if(cityIds.isEmpty()) { if(cityIds.isEmpty()) {
return allStreets; return new ExecutionResult(allStreets);
} }
final List<MapObject> connectedStreets = new ArrayList<MapObject>(); final List<MapObject> connectedStreets = new ArrayList<MapObject>();
Iterator<Street> p = allStreets.iterator(); Iterator<Street> p = allStreets.iterator();
@ -382,16 +460,16 @@ public class GeoIntentActivity extends OsmandListActivity {
List<MapObject> all = new ArrayList<MapObject>(); List<MapObject> all = new ArrayList<MapObject>();
all.addAll(cityIds.valueCollection()); all.addAll(cityIds.valueCollection());
all.addAll(allStreets); all.addAll(allStreets);
return all; return new ExecutionResult(all);
} else { } else {
// add all other results to connected streets // add all other results to connected streets
connectedStreets.addAll(cityIds.valueCollection()); connectedStreets.addAll(cityIds.valueCollection());
return connectedStreets; return new ExecutionResult(connectedStreets);
} }
} }
private Collection<RegionAddressRepository> limitSearchToCountries(List<String> q) { private Collection<RegionAddressRepository> limitSearchToCountries(List<String> q) {
ResourceManager resourceManager = resourceManager(); ResourceManager resourceManager = getMyApplication().getResourceManager();
List<RegionAddressRepository> foundCountries = new ArrayList<RegionAddressRepository>(); List<RegionAddressRepository> foundCountries = new ArrayList<RegionAddressRepository>();
RegionAddressRepository country; RegionAddressRepository country;
Iterator<String> it = q.iterator(); Iterator<String> it = q.iterator();
@ -414,61 +492,99 @@ public class GeoIntentActivity extends OsmandListActivity {
} }
private ResourceManager resourceManager() { private static class GeoPointSearch implements MyService {
return getMyApplication().getResourceManager(); private final MapObject point;
} private final int zoom;
public GeoPointSearch(double lat , double lon)
{
this(lat, lon, ExecutionResult.NO_ZOOM);
}
private void showErrorMessage(final String geo) { public GeoPointSearch(double lat , double lon, int zoom)
runOnUiThread(new Runnable() { {
@Override this(lat, lon, "Lat: " + lat + ",Lon: " + lon, zoom);
public void run() { }
AccessibleToast.makeText(GeoIntentActivity.this,
getString(R.string.search_offline_geo_error, geo),
Toast.LENGTH_LONG);
}
});
}
private static class Empty implements MyService {
@Override public GeoPointSearch(double lat , double lon, String name )
public Collection<MapObject> execute() { {
return Collections.emptyList(); this(lat, lon, name,ExecutionResult.NO_ZOOM);
} }
} public GeoPointSearch(double lat , double lon, String name, int zoom )
{
private static class GeoPointSearch implements MyService { final Amenity amenity = new Amenity();
private MapObject point; amenity.setLocation(lat, lon);
/** amenity.setName(name);
* geo:latitude,longitude geo:latitude,longitude?z=zoom amenity.setType(AmenityType.USER_DEFINED);
*/ amenity.setSubType("");
public GeoPointSearch(double lat , double lon ) {
// TODO zoom is omited for now this.point = amenity;
point = new Amenity(); this.zoom = zoom;
((Amenity)point).setType(AmenityType.USER_DEFINED);
((Amenity)point).setSubType("");
point.setLocation(lat, lon);
point.setName("Lat: " + lat + ",Lon:" + lon);
} }
@Override
@Override public ExecutionResult execute() {
public Collection<? extends MapObject> execute() {
if (point != null) { if (point != null) {
return Collections.singletonList(point); return new ExecutionResult(Collections.singletonList(point), zoom);
} else { } else {
return Collections.emptyList(); return ExecutionResult.EMPTY;
} }
} }
} }
private interface MyService { private static class ExecutionResult
{
public static final int NO_ZOOM = -1;
public static final ExecutionResult EMPTY = new ExecutionResult(new ArrayList<MapObject>(), NO_ZOOM);
public Collection<? extends MapObject> execute(); private final Collection<? extends MapObject> mapObjects;
private final int zoom;
public ExecutionResult(final Collection<? extends MapObject> mapObjects)
{
this(mapObjects, NO_ZOOM);
}
public ExecutionResult(final Collection<? extends MapObject> mapObjects, final int zoom)
{
this.mapObjects = mapObjects;
this.zoom = zoom;
}
public boolean isEmpty()
{
return mapObjects.isEmpty();
}
public boolean hasZoom()
{
return zoom != NO_ZOOM;
}
public Collection<? extends MapObject> getMapObjects()
{
return mapObjects;
}
public int getZoom()
{
return zoom;
}
@Override
public String toString()
{
return "ExecutionResult{" +
"mapObjects=" + mapObjects +
", zoom=" + zoom +
'}';
}
}
private static interface MyService
{
public ExecutionResult execute();
} }
} }