Bug 646685 - Fix watchPosition after isBetterPosition was removed. r=blassey

This commit is contained in:
Doug Turner 2011-03-30 21:13:35 -07:00
parent 1f8228e780
commit b5d804c090
6 changed files with 38 additions and 25 deletions

View File

@ -243,7 +243,6 @@ nsGeolocationRequest::nsGeolocationRequest(nsGeolocation* aLocator,
PRBool aWatchPositionRequest)
: mAllowed(PR_FALSE),
mCleared(PR_FALSE),
mIsFirstUpdate(PR_TRUE),
mIsWatchPositionRequest(aWatchPositionRequest),
mCallback(aCallback),
mErrorCallback(aErrorCallback),
@ -463,11 +462,8 @@ nsGeolocationRequest::SendLocation(nsIDOMGeoPosition* aPosition)
void
nsGeolocationRequest::Update(nsIDOMGeoPosition* aPosition)
{
if (mIsFirstUpdate) {
mIsFirstUpdate = PR_FALSE;
nsCOMPtr<nsIRunnable> ev = new RequestSendLocationEvent(aPosition, this);
NS_DispatchToMainThread(ev);
}
nsCOMPtr<nsIRunnable> ev = new RequestSendLocationEvent(aPosition, this);
NS_DispatchToMainThread(ev);
}
void

View File

@ -117,7 +117,6 @@ class nsGeolocationRequest
void NotifyError(PRInt16 errorCode);
PRPackedBool mAllowed;
PRPackedBool mCleared;
PRPackedBool mIsFirstUpdate;
PRPackedBool mIsWatchPositionRequest;
nsCOMPtr<nsITimer> mTimeoutTimer;

View File

@ -73,6 +73,7 @@ abstract public class GeckoApp
public static boolean mStartedEarly = false;
public static File sGREDir = null;
static Thread mLibLoadThread = null;
public Handler mMainHandler;
enum LaunchState {PreLaunch, Launching, WaitButton,
Launched, GeckoRunning, GeckoExiting};
@ -176,6 +177,7 @@ abstract public class GeckoApp
public void onCreate(Bundle savedInstanceState)
{
mAppContext = this;
mMainHandler = new Handler();
SharedPreferences settings = getPreferences(Activity.MODE_PRIVATE);
String localeCode = settings.getString(getPackageName() + ".locale", "");

View File

@ -119,6 +119,11 @@ public class GeckoAppShell
}
}
// Get a Handler for the main java thread
public static Handler getMainHandler() {
return GeckoApp.mAppContext.mMainHandler;
}
private static Handler sHandler = null;
// Get a Handler for a looper thread, or create one if it doesn't exist yet
@ -558,24 +563,32 @@ public class GeckoAppShell
}
}
public static void enableLocation(boolean enable) {
LocationManager lm = (LocationManager)
GeckoApp.surfaceView.getContext().getSystemService(Context.LOCATION_SERVICE);
public static void enableLocation(final boolean enable) {
getMainHandler().post(new Runnable() {
public void run() {
GeckoSurfaceView view = GeckoApp.surfaceView;
LocationManager lm = (LocationManager)
view.getContext().getSystemService(Context.LOCATION_SERVICE);
if (enable) {
Criteria crit = new Criteria();
crit.setAccuracy(Criteria.ACCURACY_FINE);
String provider = lm.getBestProvider(crit, true);
if (provider == null)
return;
if (enable) {
Criteria crit = new Criteria();
crit.setAccuracy(Criteria.ACCURACY_FINE);
String provider = lm.getBestProvider(crit, true);
if (provider == null)
return;
Location loc = lm.getLastKnownLocation(provider);
if (loc != null)
sendEventToGecko(new GeckoEvent(loc, null));
lm.requestLocationUpdates(provider, 100, (float).5, GeckoApp.surfaceView, Looper.getMainLooper());
} else {
lm.removeUpdates(GeckoApp.surfaceView);
}
Looper l = Looper.getMainLooper();
Location loc = lm.getLastKnownLocation(provider);
if (loc != null) {
view.onLocationChanged(loc);
}
lm.requestLocationUpdates(provider, 100, (float).5, view, l);
} else {
lm.removeUpdates(view);
}
}
});
}
public static void moveTaskToBack() {

View File

@ -422,6 +422,7 @@ class GeckoSurfaceView
// may want to expose multiple, or filter
// for best.
mLastGeoAddress = addresses.get(0);
GeckoAppShell.sendEventToGecko(new GeckoEvent(location[0], mLastGeoAddress));
} catch (Exception e) {
Log.w("GeckoSurfaceView", "GeocoderTask "+e);
}
@ -433,7 +434,7 @@ class GeckoSurfaceView
public void onLocationChanged(Location location)
{
if (mGeocoder == null)
mGeocoder = new Geocoder(getContext());
mGeocoder = new Geocoder(getContext(), Locale.getDefault());
if (mLastGeoAddress == null) {
new GeocoderTask().execute(location);
@ -448,7 +449,7 @@ class GeckoSurfaceView
// pfm value. don't want to slam the
// geocoder with very similar values, so
// only call after about 100m
if (results[0] > 100)
if (results[0] > 100)
new GeocoderTask().execute(location);
}

View File

@ -225,6 +225,7 @@ AndroidAddress::CreateGeoPositionAddress(JNIEnv *jenv, jobject jobj)
nsJNIString postalCode(static_cast<jstring>(jenv->CallObjectMethod(jobj, jGetPostalCodeMethod)), jenv);
nsJNIString region(static_cast<jstring>(jenv->CallObjectMethod(jobj, jGetAdminAreaMethod, 0)), jenv);
#ifdef DEBUG
printf_stderr("!!!!!!!!!!!!!! AndroidAddress::CreateGeoPositionAddress:\n\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n",
NS_LossyConvertUTF16toASCII(streetNumber).get(),
NS_LossyConvertUTF16toASCII(street).get(),
@ -235,6 +236,7 @@ AndroidAddress::CreateGeoPositionAddress(JNIEnv *jenv, jobject jobj)
NS_LossyConvertUTF16toASCII(country).get(),
NS_LossyConvertUTF16toASCII(countryCode).get(),
NS_LossyConvertUTF16toASCII(postalCode).get());
#endif
return new nsGeoPositionAddress(streetNumber,
street,