Geocoding up and running

This commit is contained in:
mar-v-in 2014-12-25 22:44:00 +01:00
parent 68833c0cef
commit a79141c0d1
9 changed files with 36 additions and 6 deletions

View file

@ -54,12 +54,13 @@ LOCAL_MODULE_TAGS := optional
LOCAL_RESOURCE_DIR := $(addprefix $(LOCAL_PATH)/, $(res_dir))
LOCAL_SRC_FILES := $(call all-java-files-under, src)
# Remove LocationProvider V1 as it does not work with gms package name
LOCAL_SRC_FILES := $(filter-out src/org/microg/nlp/location/LocationProviderV1.java, $(LOCAL_SRC_FILES))
LOCAL_SRC_FILES := $(filter-out src/org/microg/nlp/location/LocationServiceV1.java, $(LOCAL_SRC_FILES))
LOCAL_JAVA_LIBRARIES := framework com.android.location.provider
# Include compat v9 files if necassary
ifeq ($(shell [ $(PLATFORM_SDK_VERSION) -ge 17 ] && echo true), true)
LOCAL_JAVA_LIBRARIES += UnifiedNlpCompatV9
endif
LOCAL_STATIC_JAVA_LIBRARIES := UnifiedNlpApi android-support-v4 android-support-v7-appcompat
LOCAL_PACKAGE_NAME := NetworkLocation
LOCAL_SDK_VERSION := current

View file

@ -4,6 +4,7 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import org.microg.nlp.geocode.GeocodeService;
import org.microg.nlp.location.LocationService;
public class PackageReceiver extends BroadcastReceiver {
@ -14,5 +15,6 @@ public class PackageReceiver extends BroadcastReceiver {
Log.d(TAG, "Intent received: " + intent);
Log.d(TAG, "Reloading location service...");
LocationService.reloadLocationService(context);
GeocodeService.reloadLocationService(context);
}
}

View file

@ -26,6 +26,18 @@ class BackendFuser {
}
}
}
public void bind() {
for (BackendHelper backendHelper : backendHelpers) {
backendHelper.bind();
}
}
public void unbind() {
for (BackendHelper backendHelper : backendHelpers) {
backendHelper.unbind();
}
}
public List<Address> getFromLocation(double latitude, double longitude, int maxResults,
String locale) {

View file

@ -47,6 +47,10 @@ class GeocodeProviderV1 extends GeocodeProvider implements org.microg.nlp.geocod
@Override
public void reload() {
if (backendFuser != null) {
backendFuser.unbind();
}
backendFuser = new BackendFuser(context);
backendFuser.bind();
}
}

View file

@ -1,11 +1,18 @@
package org.microg.nlp.geocode;
import android.content.Context;
import android.content.Intent;
import org.microg.nlp.ProviderService;
import static org.microg.nlp.api.NlpApiConstants.ACTION_RELOAD_SETTINGS;
public abstract class GeocodeService extends ProviderService<GeocodeProvider> {
public static void reloadLocationService(Context context) {
Intent intent = new Intent(ACTION_RELOAD_SETTINGS);
intent.setClass(context, GeocodeServiceV1.class);
context.startService(intent);
}
/**
* Creates an GeocodeService. Invoked by your subclass's constructor.
*

View file

@ -15,7 +15,7 @@ public abstract class LocationService extends ProviderService<LocationProvider>
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
intent.setClass(context, LocationServiceV2.class);
} else {
// TODO
intent.setClass(context, LocationServiceV1.class);
}
context.startService(intent);
}

View file

@ -129,7 +129,6 @@ public abstract class AbstractBackendConfigFragment extends Fragment {
updateAddButton();
resetAdapter();
saveActiveBackends(activeBackends);
LocationService.reloadLocationService(getActivity());
}
public static String serviceInfosToBackendString(List<ServiceInfo> backends) {

View file

@ -6,6 +6,8 @@ import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.graphics.drawable.Drawable;
import org.microg.nlp.Preferences;
import org.microg.nlp.geocode.GeocodeService;
import org.microg.nlp.location.LocationService;
import java.util.ArrayList;
import java.util.HashMap;
@ -36,5 +38,6 @@ public class GeocodeBackendConfigFragment extends AbstractBackendConfigFragment
@Override
protected void saveActiveBackends(List<ServiceInfo> activeBackends) {
new Preferences(getActivity()).setGeocoderBackends(serviceInfosToBackendString(activeBackends));
GeocodeService.reloadLocationService(getActivity());
}
}

View file

@ -3,6 +3,7 @@ package org.microg.nlp.ui;
import android.content.Intent;
import android.content.pm.ServiceInfo;
import org.microg.nlp.Preferences;
import org.microg.nlp.location.LocationService;
import java.util.List;
import java.util.Map;
@ -31,6 +32,7 @@ public class LocationBackendConfigFragment extends AbstractBackendConfigFragment
protected void saveActiveBackends(List<ServiceInfo> activeBackends) {
new Preferences(getActivity())
.setLocationBackends(serviceInfosToBackendString(activeBackends));
LocationService.reloadLocationService(getActivity());
}
}