зеркало из https://github.com/mozilla/pjs.git
Bug 568249 - Support geolocation on Android, r=dougt
This commit is contained in:
Родитель
dcbc8ae480
Коммит
fa98381437
|
@ -0,0 +1,79 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Android code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mozilla Foundation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Michael Wu <mwu@mozilla.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsGeolocation.h"
|
||||
#include "nsGeoPosition.h"
|
||||
#include "AndroidBridge.h"
|
||||
#include "AndroidLocationProvider.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
extern nsIGeolocationUpdate *gLocationCallback;
|
||||
|
||||
NS_IMPL_ISUPPORTS1(AndroidLocationProvider, nsIGeolocationProvider)
|
||||
|
||||
AndroidLocationProvider::AndroidLocationProvider()
|
||||
{
|
||||
}
|
||||
|
||||
AndroidLocationProvider::~AndroidLocationProvider()
|
||||
{
|
||||
NS_IF_RELEASE(gLocationCallback);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
AndroidLocationProvider::Startup()
|
||||
{
|
||||
AndroidBridge::Bridge()->EnableLocation(true);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
AndroidLocationProvider::Watch(nsIGeolocationUpdate* aCallback)
|
||||
{
|
||||
NS_IF_RELEASE(gLocationCallback);
|
||||
gLocationCallback = aCallback;
|
||||
NS_IF_ADDREF(gLocationCallback);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
AndroidLocationProvider::Shutdown()
|
||||
{
|
||||
AndroidBridge::Bridge()->EnableLocation(false);
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Android code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mozilla Foundation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Michael Wu <mwu@mozilla.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef AndroidLocationProvider_h
|
||||
#define AndroidLocationProvider_h
|
||||
|
||||
#include "nsIGeolocationProvider.h"
|
||||
|
||||
class AndroidLocationProvider : public nsIGeolocationProvider
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIGEOLOCATIONPROVIDER
|
||||
|
||||
AndroidLocationProvider();
|
||||
private:
|
||||
~AndroidLocationProvider();
|
||||
};
|
||||
|
||||
#endif /* AndroidLocationProvider_h */
|
|
@ -37,6 +37,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include "nsGeoPosition.h"
|
||||
#include "MaemoLocationProvider.h"
|
||||
#include "nsIClassInfo.h"
|
||||
#include "nsDOMClassInfoID.h"
|
||||
|
@ -46,138 +47,6 @@
|
|||
#include "nsIServiceManager.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
// nsGeoPositionCoords
|
||||
////////////////////////////////////////////////////
|
||||
|
||||
class nsGeoPositionCoords : public nsIDOMGeoPositionCoords
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIDOMGEOPOSITIONCOORDS
|
||||
|
||||
nsGeoPositionCoords(double aLat, double aLong, double aAlt, double aHError,
|
||||
double aVError, double aHeading, double aSpeed) :
|
||||
mLat(aLat), mLong(aLong), mAlt(aAlt), mHError(aHError),
|
||||
mVError(aVError), mHeading(aHeading), mSpeed(aSpeed) { };
|
||||
private:
|
||||
~nsGeoPositionCoords() { }
|
||||
double mLat, mLong, mAlt, mHError, mVError, mHeading, mSpeed;
|
||||
};
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN(nsGeoPositionCoords)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMGeoPositionCoords)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMGeoPositionCoords)
|
||||
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(GeoPositionCoords)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
NS_IMPL_THREADSAFE_ADDREF(nsGeoPositionCoords)
|
||||
NS_IMPL_THREADSAFE_RELEASE(nsGeoPositionCoords)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGeoPositionCoords::GetLatitude(double *aLatitude)
|
||||
{
|
||||
*aLatitude = mLat;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGeoPositionCoords::GetLongitude(double *aLongitude)
|
||||
{
|
||||
*aLongitude = mLong;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGeoPositionCoords::GetAltitude(double *aAltitude)
|
||||
{
|
||||
*aAltitude = mAlt;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGeoPositionCoords::GetAccuracy(double *aAccuracy)
|
||||
{
|
||||
*aAccuracy = mHError;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGeoPositionCoords::GetAltitudeAccuracy(double *aAltitudeAccuracy)
|
||||
{
|
||||
*aAltitudeAccuracy = mVError;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGeoPositionCoords::GetHeading(double *aHeading)
|
||||
{
|
||||
*aHeading = mHeading;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGeoPositionCoords::GetSpeed(double *aSpeed)
|
||||
{
|
||||
*aSpeed = mSpeed;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
// nsGeoPosition
|
||||
////////////////////////////////////////////////////
|
||||
|
||||
class nsGeoPosition : public nsIDOMGeoPosition
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIDOMGEOPOSITION
|
||||
|
||||
nsGeoPosition(double aLat, double aLong, double aAlt, double aHError,
|
||||
double aVError, double aHeading, double aSpeed,
|
||||
long long aTimestamp): mTimestamp(aTimestamp)
|
||||
{
|
||||
mCoords = new nsGeoPositionCoords(aLat, aLong, aAlt, aHError,
|
||||
aVError, aHeading, aSpeed);
|
||||
NS_ASSERTION(mCoords, "null mCoords in nsGeoPosition");
|
||||
};
|
||||
|
||||
private:
|
||||
~nsGeoPosition() {}
|
||||
long long mTimestamp;
|
||||
nsRefPtr<nsGeoPositionCoords> mCoords;
|
||||
};
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN(nsGeoPosition)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMGeoPosition)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMGeoPosition)
|
||||
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(GeoPosition)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
NS_IMPL_THREADSAFE_ADDREF(nsGeoPosition)
|
||||
NS_IMPL_THREADSAFE_RELEASE(nsGeoPosition)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGeoPosition::GetTimestamp(DOMTimeStamp* aTimestamp)
|
||||
{
|
||||
*aTimestamp = mTimestamp;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGeoPosition::GetCoords(nsIDOMGeoPositionCoords * *aCoords)
|
||||
{
|
||||
NS_IF_ADDREF(*aCoords = mCoords);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGeoPosition::GetAddress(nsIDOMGeoPositionAddress** aAddress)
|
||||
{
|
||||
*aAddress = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS2(MaemoLocationProvider, nsIGeolocationProvider, nsITimerCallback)
|
||||
|
||||
MaemoLocationProvider::MaemoLocationProvider() :
|
||||
|
|
|
@ -62,14 +62,19 @@ LOCAL_INCLUDES = \
|
|||
$(NULL)
|
||||
|
||||
ifdef WINCE_WINDOWS_MOBILE
|
||||
CPPSRCS += WinMobileLocationProvider.cpp
|
||||
CPPSRCS += WinMobileLocationProvider.cpp nsGeoPosition.cpp
|
||||
endif
|
||||
|
||||
ifdef MOZ_MAEMO_LIBLOCATION
|
||||
CPPSRCS += MaemoLocationProvider.cpp
|
||||
CPPSRCS += MaemoLocationProvider.cpp nsGeoPosition.cpp
|
||||
LOCAL_INCLUDES += $(MOZ_PLATFORM_MAEMO_CFLAGS)
|
||||
endif
|
||||
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),android)
|
||||
CPPSRCS += AndroidLocationProvider.cpp nsGeoPosition.cpp
|
||||
EXPORTS += nsGeoPosition.h
|
||||
endif
|
||||
|
||||
EXTRA_COMPONENTS = \
|
||||
NetworkGeolocationProvider.js \
|
||||
GPSDGeolocationProvider.js \
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsGeoPosition.h"
|
||||
#include "WinMobileLocationProvider.h"
|
||||
#include "nsGeolocation.h"
|
||||
#include "nsIClassInfo.h"
|
||||
|
@ -44,152 +45,6 @@
|
|||
#include "nsIPrefBranch.h"
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
// nsGeoPositionCoords
|
||||
////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Simple object that holds a single point in space.
|
||||
*/
|
||||
class nsGeoPositionCoords : public nsIDOMGeoPositionCoords
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIDOMGEOPOSITIONCOORDS
|
||||
|
||||
nsGeoPositionCoords(double aLat, double aLong,
|
||||
double aAlt, double aHError,
|
||||
double aVError, double aHeading,
|
||||
double aSpeed) :
|
||||
mLat(aLat), mLong(aLong),
|
||||
mAlt(aAlt), mHError(aHError),
|
||||
mVError(aVError), mHeading(aHeading),
|
||||
mSpeed(aSpeed) {};
|
||||
private:
|
||||
~nsGeoPositionCoords() {}
|
||||
double mLat, mLong, mAlt, mHError, mVError, mHeading, mSpeed;
|
||||
};
|
||||
|
||||
DOMCI_DATA(GeoPositionCoords, nsGeoPositionCoords)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN(nsGeoPositionCoords)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMGeoPositionCoords)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMGeoPositionCoords)
|
||||
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(GeoPositionCoords)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
NS_IMPL_THREADSAFE_ADDREF(nsGeoPositionCoords)
|
||||
NS_IMPL_THREADSAFE_RELEASE(nsGeoPositionCoords)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGeoPositionCoords::GetLatitude(double *aLatitude)
|
||||
{
|
||||
*aLatitude = mLat;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGeoPositionCoords::GetLongitude(double *aLongitude)
|
||||
{
|
||||
*aLongitude = mLong;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGeoPositionCoords::GetAltitude(double *aAltitude)
|
||||
{
|
||||
*aAltitude = mAlt;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGeoPositionCoords::GetAccuracy(double *aAccuracy)
|
||||
{
|
||||
*aAccuracy = mHError;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGeoPositionCoords::GetAltitudeAccuracy(double *aAltitudeAccuracy)
|
||||
{
|
||||
*aAltitudeAccuracy = mVError;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGeoPositionCoords::GetHeading(double *aHeading)
|
||||
{
|
||||
*aHeading = mHeading;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGeoPositionCoords::GetSpeed(double *aSpeed)
|
||||
{
|
||||
*aSpeed = mSpeed;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
// nsGeoPosition
|
||||
////////////////////////////////////////////////////
|
||||
|
||||
class nsGeoPosition : public nsIDOMGeoPosition
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIDOMGEOPOSITION
|
||||
|
||||
nsGeoPosition(double aLat, double aLong,
|
||||
double aAlt, double aHError,
|
||||
double aVError, double aHeading,
|
||||
double aSpeed, long long aTimestamp): mTimestamp(aTimestamp)
|
||||
{
|
||||
mCoords = new nsGeoPositionCoords(aLat, aLong,
|
||||
aAlt, aHError,
|
||||
aVError, aHeading,
|
||||
aSpeed);
|
||||
NS_ASSERTION(mCoords, "null mCoords in nsGeoPosition");
|
||||
};
|
||||
|
||||
private:
|
||||
~nsGeoPosition() {}
|
||||
long long mTimestamp;
|
||||
nsRefPtr<nsGeoPositionCoords> mCoords;
|
||||
};
|
||||
|
||||
DOMCI_DATA(GeoPosition, nsGeoPosition)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN(nsGeoPosition)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMGeoPosition)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMGeoPosition)
|
||||
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(GeoPosition)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
NS_IMPL_THREADSAFE_ADDREF(nsGeoPosition)
|
||||
NS_IMPL_THREADSAFE_RELEASE(nsGeoPosition)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGeoPosition::GetTimestamp(DOMTimeStamp* aTimestamp)
|
||||
{
|
||||
*aTimestamp = mTimestamp;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGeoPosition::GetCoords(nsIDOMGeoPositionCoords * *aCoords)
|
||||
{
|
||||
NS_IF_ADDREF(*aCoords = mCoords);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGeoPosition::GetAddress(nsIDOMGeoPositionAddress** aAddress)
|
||||
{
|
||||
*aAddress = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS2(WinMobileLocationProvider, nsIGeolocationProvider, nsITimerCallback)
|
||||
|
||||
WinMobileLocationProvider::WinMobileLocationProvider() :
|
||||
|
|
|
@ -0,0 +1,172 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Geolocation.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mozilla Foundation
|
||||
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Doug Turner <dougt@meer.net> (Original Author)
|
||||
* Nino D'Aversa <ninodaversa@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsGeoPosition.h"
|
||||
#include "nsDOMClassInfo.h"
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
// nsGeoPositionCoords
|
||||
////////////////////////////////////////////////////
|
||||
nsGeoPositionCoords::nsGeoPositionCoords(double aLat, double aLong,
|
||||
double aAlt, double aHError,
|
||||
double aVError, double aHeading,
|
||||
double aSpeed) :
|
||||
mLat(aLat), mLong(aLong),
|
||||
mAlt(aAlt), mHError(aHError),
|
||||
mVError(aVError), mHeading(aHeading),
|
||||
mSpeed(aSpeed)
|
||||
{
|
||||
}
|
||||
|
||||
nsGeoPositionCoords::~nsGeoPositionCoords()
|
||||
{
|
||||
}
|
||||
|
||||
DOMCI_DATA(GeoPositionCoords, nsGeoPositionCoords)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN(nsGeoPositionCoords)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMGeoPositionCoords)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMGeoPositionCoords)
|
||||
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(GeoPositionCoords)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
NS_IMPL_THREADSAFE_ADDREF(nsGeoPositionCoords)
|
||||
NS_IMPL_THREADSAFE_RELEASE(nsGeoPositionCoords)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGeoPositionCoords::GetLatitude(double *aLatitude)
|
||||
{
|
||||
*aLatitude = mLat;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGeoPositionCoords::GetLongitude(double *aLongitude)
|
||||
{
|
||||
*aLongitude = mLong;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGeoPositionCoords::GetAltitude(double *aAltitude)
|
||||
{
|
||||
*aAltitude = mAlt;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGeoPositionCoords::GetAccuracy(double *aAccuracy)
|
||||
{
|
||||
*aAccuracy = mHError;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGeoPositionCoords::GetAltitudeAccuracy(double *aAltitudeAccuracy)
|
||||
{
|
||||
*aAltitudeAccuracy = mVError;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGeoPositionCoords::GetHeading(double *aHeading)
|
||||
{
|
||||
*aHeading = mHeading;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGeoPositionCoords::GetSpeed(double *aSpeed)
|
||||
{
|
||||
*aSpeed = mSpeed;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
// nsGeoPosition
|
||||
////////////////////////////////////////////////////
|
||||
|
||||
nsGeoPosition::nsGeoPosition(double aLat, double aLong,
|
||||
double aAlt, double aHError,
|
||||
double aVError, double aHeading,
|
||||
double aSpeed, long long aTimestamp) :
|
||||
mTimestamp(aTimestamp)
|
||||
{
|
||||
mCoords = new nsGeoPositionCoords(aLat, aLong,
|
||||
aAlt, aHError,
|
||||
aVError, aHeading,
|
||||
aSpeed);
|
||||
NS_ASSERTION(mCoords, "null mCoords in nsGeoPosition");
|
||||
}
|
||||
|
||||
nsGeoPosition::~nsGeoPosition()
|
||||
{
|
||||
}
|
||||
|
||||
DOMCI_DATA(GeoPosition, nsGeoPosition)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN(nsGeoPosition)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMGeoPosition)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMGeoPosition)
|
||||
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(GeoPosition)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
NS_IMPL_THREADSAFE_ADDREF(nsGeoPosition)
|
||||
NS_IMPL_THREADSAFE_RELEASE(nsGeoPosition)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGeoPosition::GetTimestamp(DOMTimeStamp* aTimestamp)
|
||||
{
|
||||
*aTimestamp = mTimestamp;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGeoPosition::GetCoords(nsIDOMGeoPositionCoords * *aCoords)
|
||||
{
|
||||
NS_IF_ADDREF(*aCoords = mCoords);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGeoPosition::GetAddress(nsIDOMGeoPositionAddress** aAddress)
|
||||
{
|
||||
*aAddress = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Geolocation.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mozilla Foundation
|
||||
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Doug Turner <dougt@meer.net> (Original Author)
|
||||
* Nino D'Aversa <ninodaversa@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef nsGeoPosition_h
|
||||
#define nsGeoPosition_h
|
||||
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsIClassInfo.h"
|
||||
#include "nsDOMClassInfoID.h"
|
||||
#include "nsIDOMGeoPositionCoords.h"
|
||||
#include "nsIDOMGeoPosition.h"
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
// nsGeoPositionCoords
|
||||
////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Simple object that holds a single point in space.
|
||||
*/
|
||||
class nsGeoPositionCoords : public nsIDOMGeoPositionCoords
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIDOMGEOPOSITIONCOORDS
|
||||
|
||||
nsGeoPositionCoords(double aLat, double aLong,
|
||||
double aAlt, double aHError,
|
||||
double aVError, double aHeading,
|
||||
double aSpeed);
|
||||
private:
|
||||
~nsGeoPositionCoords();
|
||||
double mLat, mLong, mAlt, mHError, mVError, mHeading, mSpeed;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
// nsGeoPosition
|
||||
////////////////////////////////////////////////////
|
||||
|
||||
class nsGeoPosition : public nsIDOMGeoPosition
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIDOMGEOPOSITION
|
||||
|
||||
nsGeoPosition(double aLat, double aLong,
|
||||
double aAlt, double aHError,
|
||||
double aVError, double aHeading,
|
||||
double aSpeed, long long aTimestamp);
|
||||
|
||||
private:
|
||||
~nsGeoPosition();
|
||||
long long mTimestamp;
|
||||
nsRefPtr<nsGeoPositionCoords> mCoords;
|
||||
};
|
||||
|
||||
#endif /* nsGeoPosition_h */
|
||||
|
|
@ -62,6 +62,10 @@
|
|||
#include "MaemoLocationProvider.h"
|
||||
#endif
|
||||
|
||||
#ifdef ANDROID
|
||||
#include "AndroidLocationProvider.h"
|
||||
#endif
|
||||
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDocument.h"
|
||||
|
||||
|
@ -426,6 +430,12 @@ nsresult nsGeolocationService::Init()
|
|||
if (provider)
|
||||
mProviders.AppendObject(provider);
|
||||
#endif
|
||||
|
||||
#ifdef ANDROID
|
||||
provider = new AndroidLocationProvider();
|
||||
if (provider)
|
||||
mProviders.AppendObject(provider);
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -962,7 +972,7 @@ nsGeolocation::WindowOwnerStillExists()
|
|||
return PR_TRUE;
|
||||
}
|
||||
|
||||
#ifndef WINCE_WINDOWS_MOBILE
|
||||
#if !defined(WINCE_WINDOWS_MOBILE) && !defined(MOZ_MAEMO_LIBLOCATION) && !defined(ANDROID)
|
||||
DOMCI_DATA(GeoPositionCoords, void)
|
||||
DOMCI_DATA(GeoPosition, void)
|
||||
#endif
|
||||
|
|
|
@ -34,6 +34,8 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef nsGeoLocation_h
|
||||
#define nsGeoLocation_h
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsAutoPtr.h"
|
||||
|
@ -223,3 +225,5 @@ private:
|
|||
// owning back pointer.
|
||||
nsRefPtr<nsGeolocationService> mService;
|
||||
};
|
||||
|
||||
#endif /* nsGeoLocation_h */
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
<uses-sdk android:minSdkVersion="5"
|
||||
android:targetSdkVersion="5"/>
|
||||
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
|
||||
|
|
|
@ -51,6 +51,7 @@ import android.content.*;
|
|||
import android.graphics.*;
|
||||
import android.widget.*;
|
||||
import android.hardware.*;
|
||||
import android.location.*;
|
||||
|
||||
import android.util.*;
|
||||
import android.content.DialogInterface;
|
||||
|
@ -192,6 +193,24 @@ class GeckoAppShell
|
|||
}
|
||||
}
|
||||
|
||||
public static void enableLocation(boolean enable) {
|
||||
LocationManager lm = (LocationManager)
|
||||
GeckoApp.surfaceView.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;
|
||||
|
||||
sendEventToGecko(new GeckoEvent(lm.getLastKnownLocation(provider)));
|
||||
lm.requestLocationUpdates(provider, 100, (float).5, GeckoApp.surfaceView, Looper.getMainLooper());
|
||||
} else {
|
||||
lm.removeUpdates(GeckoApp.surfaceView);
|
||||
}
|
||||
}
|
||||
|
||||
public static void returnIMEQueryResult(String result, int selectionStart, int selectionEnd) {
|
||||
GeckoApp.surfaceView.inputConnection.mSelectionStart = selectionStart;
|
||||
GeckoApp.surfaceView.inputConnection.mSelectionEnd = selectionEnd;
|
||||
|
|
|
@ -44,6 +44,7 @@ import android.content.*;
|
|||
import android.graphics.*;
|
||||
import android.widget.*;
|
||||
import android.hardware.*;
|
||||
import android.location.*;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
|
@ -58,10 +59,11 @@ public class GeckoEvent {
|
|||
public static final int KEY_EVENT = 1;
|
||||
public static final int MOTION_EVENT = 2;
|
||||
public static final int SENSOR_EVENT = 3;
|
||||
public static final int IME_EVENT = 4;
|
||||
public static final int DRAW = 5;
|
||||
public static final int SIZE_CHANGED = 6;
|
||||
public static final int ACTIVITY_STOPPING = 7;
|
||||
public static final int LOCATION_EVENT = 4;
|
||||
public static final int IME_EVENT = 5;
|
||||
public static final int DRAW = 6;
|
||||
public static final int SIZE_CHANGED = 7;
|
||||
public static final int ACTIVITY_STOPPING = 8;
|
||||
|
||||
public static final int IME_BATCH_END = 0;
|
||||
public static final int IME_BATCH_BEGIN = 1;
|
||||
|
@ -80,6 +82,7 @@ public class GeckoEvent {
|
|||
public int mKeyCode, mUnicodeChar;
|
||||
public int mCount, mCount2;
|
||||
public String mCharacters;
|
||||
public Location mLocation;
|
||||
|
||||
public int mNativeWindow;
|
||||
|
||||
|
@ -116,6 +119,11 @@ public class GeckoEvent {
|
|||
mZ = s.values[2] / SensorManager.GRAVITY_EARTH;
|
||||
}
|
||||
|
||||
public GeckoEvent(Location l) {
|
||||
mType = LOCATION_EVENT;
|
||||
mLocation = l;
|
||||
}
|
||||
|
||||
public GeckoEvent(boolean batchEdit, String text) {
|
||||
mType = IME_EVENT;
|
||||
if (text != null)
|
||||
|
|
|
@ -63,6 +63,7 @@ import android.content.*;
|
|||
import android.graphics.*;
|
||||
import android.widget.*;
|
||||
import android.hardware.*;
|
||||
import android.location.*;
|
||||
|
||||
import android.util.*;
|
||||
|
||||
|
@ -74,7 +75,7 @@ import android.util.*;
|
|||
*/
|
||||
class GeckoSurfaceView
|
||||
extends SurfaceView
|
||||
implements SurfaceHolder.Callback, SensorEventListener
|
||||
implements SurfaceHolder.Callback, SensorEventListener, LocationListener
|
||||
{
|
||||
public GeckoSurfaceView(Context context) {
|
||||
super(context);
|
||||
|
@ -645,6 +646,7 @@ class GeckoSurfaceView
|
|||
return inputConnection;
|
||||
}
|
||||
|
||||
// accelerometer
|
||||
public void onAccuracyChanged(Sensor sensor, int accuracy)
|
||||
{
|
||||
}
|
||||
|
@ -654,6 +656,24 @@ class GeckoSurfaceView
|
|||
GeckoAppShell.sendEventToGecko(new GeckoEvent(event));
|
||||
}
|
||||
|
||||
// geolocation
|
||||
public void onLocationChanged(Location location)
|
||||
{
|
||||
GeckoAppShell.sendEventToGecko(new GeckoEvent(location));
|
||||
}
|
||||
|
||||
public void onProviderDisabled(String provider)
|
||||
{
|
||||
}
|
||||
|
||||
public void onProviderEnabled(String provider)
|
||||
{
|
||||
}
|
||||
|
||||
public void onStatusChanged(String provider, int status, Bundle extras)
|
||||
{
|
||||
}
|
||||
|
||||
// event stuff
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
GeckoAppShell.sendEventToGecko(new GeckoEvent(event));
|
||||
|
|
|
@ -93,6 +93,7 @@ AndroidBridge::Init(JNIEnv *jEnv,
|
|||
|
||||
jShowIME = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "showIME", "(I)V");
|
||||
jEnableAccelerometer = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "enableAccelerometer", "(Z)V");
|
||||
jEnableLocation = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "enableLocation", "(Z)V");
|
||||
jReturnIMEQueryResult = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "returnIMEQueryResult", "(Ljava/lang/String;II)V");
|
||||
jScheduleRestart = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "scheduleRestart", "()V");
|
||||
jNotifyXreExit = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "onXreExit", "()V");
|
||||
|
@ -181,6 +182,12 @@ AndroidBridge::EnableAccelerometer(bool aEnable)
|
|||
mJNIEnv->CallStaticVoidMethod(mGeckoAppShellClass, jEnableAccelerometer, aEnable);
|
||||
}
|
||||
|
||||
void
|
||||
AndroidBridge::EnableLocation(bool aEnable)
|
||||
{
|
||||
mJNIEnv->CallStaticVoidMethod(mGeckoAppShellClass, jEnableLocation, aEnable);
|
||||
}
|
||||
|
||||
void
|
||||
AndroidBridge::ReturnIMEQueryResult(const PRUnichar *result, PRUint32 len, int selectionStart, int selectionEnd)
|
||||
{
|
||||
|
|
|
@ -91,6 +91,8 @@ public:
|
|||
|
||||
void EnableAccelerometer(bool aEnable);
|
||||
|
||||
void EnableLocation(bool aEnable);
|
||||
|
||||
void ReturnIMEQueryResult(const PRUnichar *result, PRUint32 len, int selectionStart, int selectionEnd);
|
||||
|
||||
void NotifyXreExit();
|
||||
|
@ -141,6 +143,7 @@ protected:
|
|||
// other things
|
||||
jmethodID jShowIME;
|
||||
jmethodID jEnableAccelerometer;
|
||||
jmethodID jEnableLocation;
|
||||
jmethodID jReturnIMEQueryResult;
|
||||
jmethodID jNotifyXreExit;
|
||||
jmethodID jScheduleRestart;
|
||||
|
|
|
@ -59,6 +59,7 @@ jfieldID AndroidGeckoEvent::jFlagsField = 0;
|
|||
jfieldID AndroidGeckoEvent::jUnicodeCharField = 0;
|
||||
jfieldID AndroidGeckoEvent::jCountField = 0;
|
||||
jfieldID AndroidGeckoEvent::jCount2Field = 0;
|
||||
jfieldID AndroidGeckoEvent::jLocationField = 0;
|
||||
|
||||
jclass AndroidPoint::jPointClass = 0;
|
||||
jfieldID AndroidPoint::jXField = 0;
|
||||
|
@ -70,6 +71,15 @@ jfieldID AndroidRect::jLeftField = 0;
|
|||
jfieldID AndroidRect::jRightField = 0;
|
||||
jfieldID AndroidRect::jTopField = 0;
|
||||
|
||||
jclass AndroidLocation::jLocationClass = 0;
|
||||
jmethodID AndroidLocation::jGetLatitudeMethod = 0;
|
||||
jmethodID AndroidLocation::jGetLongitudeMethod = 0;
|
||||
jmethodID AndroidLocation::jGetAltitudeMethod = 0;
|
||||
jmethodID AndroidLocation::jGetAccuracyMethod = 0;
|
||||
jmethodID AndroidLocation::jGetBearingMethod = 0;
|
||||
jmethodID AndroidLocation::jGetSpeedMethod = 0;
|
||||
jmethodID AndroidLocation::jGetTimeMethod = 0;
|
||||
|
||||
jclass AndroidGeckoSurfaceView::jGeckoSurfaceViewClass = 0;
|
||||
jmethodID AndroidGeckoSurfaceView::jBeginDrawingMethod = 0;
|
||||
jmethodID AndroidGeckoSurfaceView::jEndDrawingMethod = 0;
|
||||
|
@ -95,6 +105,7 @@ mozilla::InitAndroidJavaWrappers(JNIEnv *jEnv)
|
|||
AndroidGeckoEvent::InitGeckoEventClass(jEnv);
|
||||
AndroidGeckoSurfaceView::InitGeckoSurfaceViewClass(jEnv);
|
||||
AndroidPoint::InitPointClass(jEnv);
|
||||
AndroidLocation::InitLocationClass(jEnv);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -122,6 +133,7 @@ AndroidGeckoEvent::InitGeckoEventClass(JNIEnv *jEnv)
|
|||
jUnicodeCharField = getField("mUnicodeChar", "I");
|
||||
jCountField = getField("mCount", "I");
|
||||
jCount2Field = getField("mCount2", "I");
|
||||
jLocationField = getField("mLocation", "Landroid/location/Location;");
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -136,6 +148,38 @@ AndroidGeckoSurfaceView::InitGeckoSurfaceViewClass(JNIEnv *jEnv)
|
|||
jEndDrawingMethod = getMethod("endDrawing", "()V");
|
||||
}
|
||||
|
||||
void
|
||||
AndroidLocation::InitLocationClass(JNIEnv *jEnv)
|
||||
{
|
||||
initInit();
|
||||
|
||||
jLocationClass = getClassGlobalRef("android/location/Location");
|
||||
jGetLatitudeMethod = getMethod("getLatitude", "()D");
|
||||
jGetLongitudeMethod = getMethod("getLongitude", "()D");
|
||||
jGetAltitudeMethod = getMethod("getAltitude", "()D");
|
||||
jGetAccuracyMethod = getMethod("getAccuracy", "()F");
|
||||
jGetBearingMethod = getMethod("getBearing", "()F");
|
||||
jGetSpeedMethod = getMethod("getSpeed", "()F");
|
||||
jGetTimeMethod = getMethod("getTime", "()J");
|
||||
}
|
||||
|
||||
nsGeoPosition*
|
||||
AndroidLocation::CreateGeoPosition(JNIEnv *jenv, jobject jobj)
|
||||
{
|
||||
double latitude = jenv->CallDoubleMethod(jobj, jGetLatitudeMethod);
|
||||
double longitude = jenv->CallDoubleMethod(jobj, jGetLongitudeMethod);
|
||||
double altitude = jenv->CallDoubleMethod(jobj, jGetAltitudeMethod);
|
||||
float accuracy = jenv->CallFloatMethod (jobj, jGetAccuracyMethod);
|
||||
float bearing = jenv->CallFloatMethod (jobj, jGetBearingMethod);
|
||||
float speed = jenv->CallFloatMethod (jobj, jGetSpeedMethod);
|
||||
long long time = jenv->CallLongMethod (jobj, jGetTimeMethod);
|
||||
|
||||
return new nsGeoPosition(latitude, longitude,
|
||||
altitude, accuracy,
|
||||
accuracy, bearing,
|
||||
speed, time);
|
||||
}
|
||||
|
||||
void
|
||||
AndroidPoint::InitPointClass(JNIEnv *jEnv)
|
||||
{
|
||||
|
@ -259,6 +303,12 @@ AndroidGeckoEvent::Init(JNIEnv *jenv, jobject jobj)
|
|||
mZ = jenv->GetFloatField(jobj, jZField);
|
||||
break;
|
||||
|
||||
case LOCATION_EVENT: {
|
||||
jobject location = jenv->GetObjectField(jobj, jLocationField);
|
||||
mGeoPosition = AndroidLocation::CreateGeoPosition(jenv, location);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
#include <jni.h>
|
||||
#include <android/log.h>
|
||||
|
||||
#include "nsGeoPosition.h"
|
||||
#include "nsPoint.h"
|
||||
#include "nsRect.h"
|
||||
#include "nsString.h"
|
||||
|
@ -322,6 +323,21 @@ public:
|
|||
};
|
||||
};
|
||||
|
||||
class AndroidLocation : public WrappedJavaObject
|
||||
{
|
||||
public:
|
||||
static void InitLocationClass(JNIEnv *jEnv);
|
||||
static nsGeoPosition* CreateGeoPosition(JNIEnv *jenv, jobject jobj);
|
||||
static jclass jLocationClass;
|
||||
static jmethodID jGetLatitudeMethod;
|
||||
static jmethodID jGetLongitudeMethod;
|
||||
static jmethodID jGetAltitudeMethod;
|
||||
static jmethodID jGetAccuracyMethod;
|
||||
static jmethodID jGetBearingMethod;
|
||||
static jmethodID jGetSpeedMethod;
|
||||
static jmethodID jGetTimeMethod;
|
||||
};
|
||||
|
||||
class AndroidGeckoEvent : public WrappedJavaObject
|
||||
{
|
||||
public:
|
||||
|
@ -359,6 +375,7 @@ public:
|
|||
int UnicodeChar() { return mUnicodeChar; }
|
||||
int Count() { return mCount; }
|
||||
int Count2() { return mCount2; }
|
||||
nsGeoPosition* GeoPosition() { return mGeoPosition; }
|
||||
|
||||
protected:
|
||||
int mAction;
|
||||
|
@ -373,6 +390,7 @@ protected:
|
|||
int mCount, mCount2;
|
||||
float mX, mY, mZ;
|
||||
nsString mCharacters;
|
||||
nsRefPtr<nsGeoPosition> mGeoPosition;
|
||||
|
||||
void ReadP0Field(JNIEnv *jenv);
|
||||
void ReadP1Field(JNIEnv *jenv);
|
||||
|
@ -398,6 +416,7 @@ protected:
|
|||
static jfieldID jCountField;
|
||||
static jfieldID jCount2Field;
|
||||
static jfieldID jUnicodeCharField;
|
||||
static jfieldID jLocationField;
|
||||
|
||||
public:
|
||||
enum {
|
||||
|
@ -405,10 +424,11 @@ public:
|
|||
KEY_EVENT = 1,
|
||||
MOTION_EVENT = 2,
|
||||
SENSOR_EVENT = 3,
|
||||
IME_EVENT = 4,
|
||||
DRAW = 5,
|
||||
SIZE_CHANGED = 6,
|
||||
ACTIVITY_STOPPING = 7,
|
||||
LOCATION_EVENT = 4,
|
||||
IME_EVENT = 5,
|
||||
DRAW = 6,
|
||||
SIZE_CHANGED = 7,
|
||||
ACTIVITY_STOPPING = 8,
|
||||
dummy_java_enum_list_end
|
||||
};
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
#include "nsThreadUtils.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "nsIAppStartup.h"
|
||||
#include "nsIGeolocationProvider.h"
|
||||
|
||||
#include "prenv.h"
|
||||
|
||||
|
@ -67,6 +68,7 @@ PRLogModuleInfo *gWidgetLog = nsnull;
|
|||
#endif
|
||||
|
||||
nsAccelerometerAndroid *gAccel = nsnull;
|
||||
nsIGeolocationUpdate *gLocationCallback = nsnull;
|
||||
|
||||
nsAppShell *nsAppShell::gAppShell = nsnull;
|
||||
AndroidGeckoEvent *nsAppShell::gEarlyEvent = nsnull;
|
||||
|
@ -218,6 +220,16 @@ nsAppShell::ProcessNextNativeEvent(PRBool mayWait)
|
|||
gAccel->AccelerationChanged(-curEvent->X(), curEvent->Y(), curEvent->Z());
|
||||
break;
|
||||
|
||||
case AndroidGeckoEvent::LOCATION_EVENT:
|
||||
if (!gLocationCallback)
|
||||
break;
|
||||
|
||||
if (curEvent->GeoPosition())
|
||||
gLocationCallback->Update(curEvent->GeoPosition());
|
||||
else
|
||||
NS_WARNING("Received location event without geoposition!");
|
||||
break;
|
||||
|
||||
case AndroidGeckoEvent::ACTIVITY_STOPPING: {
|
||||
nsCOMPtr<nsIAppStartup> appSvc = do_GetService("@mozilla.org/toolkit/app-startup;1");
|
||||
if (appSvc)
|
||||
|
|
Загрузка…
Ссылка в новой задаче