From 65c92aab1f32168dfd99b0664aad4d2ee736a34a Mon Sep 17 00:00:00 2001 From: ScraM Team Date: Mon, 22 Oct 2018 22:17:43 -0700 Subject: [PATCH] Added Geolocation API interfaces, callbacks and data structures. --- .../java/org/teavm/jso/browser/Navigator.java | 7 +++ .../teavm/jso/geolocation/Coordinates.java | 46 +++++++++++++++++++ .../teavm/jso/geolocation/Geolocation.java | 27 +++++++++++ .../org/teavm/jso/geolocation/Position.java | 28 +++++++++++ .../teavm/jso/geolocation/PositionError.java | 35 ++++++++++++++ .../jso/geolocation/PositionErrorHandler.java | 27 +++++++++++ .../jso/geolocation/PositionHandler.java | 27 +++++++++++ 7 files changed, 197 insertions(+) create mode 100644 jso/apis/src/main/java/org/teavm/jso/geolocation/Coordinates.java create mode 100644 jso/apis/src/main/java/org/teavm/jso/geolocation/Geolocation.java create mode 100644 jso/apis/src/main/java/org/teavm/jso/geolocation/Position.java create mode 100644 jso/apis/src/main/java/org/teavm/jso/geolocation/PositionError.java create mode 100644 jso/apis/src/main/java/org/teavm/jso/geolocation/PositionErrorHandler.java create mode 100644 jso/apis/src/main/java/org/teavm/jso/geolocation/PositionHandler.java diff --git a/jso/apis/src/main/java/org/teavm/jso/browser/Navigator.java b/jso/apis/src/main/java/org/teavm/jso/browser/Navigator.java index e9bda2384..206d67f1e 100644 --- a/jso/apis/src/main/java/org/teavm/jso/browser/Navigator.java +++ b/jso/apis/src/main/java/org/teavm/jso/browser/Navigator.java @@ -16,6 +16,7 @@ package org.teavm.jso.browser; import org.teavm.jso.JSBody; +import org.teavm.jso.geolocation.Geolocation; public final class Navigator { private Navigator() { @@ -23,4 +24,10 @@ public final class Navigator { @JSBody(script = "return navigator.onLine;") public static native boolean isOnline(); + + @JSBody(script = "return navigator.geolocation;") + public static native Geolocation getGeolocation(); + + @JSBody(script = "return (\"geolocation\" in navigator);") + public static native boolean isGeolocationAvailable(); } diff --git a/jso/apis/src/main/java/org/teavm/jso/geolocation/Coordinates.java b/jso/apis/src/main/java/org/teavm/jso/geolocation/Coordinates.java new file mode 100644 index 000000000..d8f1f9ec5 --- /dev/null +++ b/jso/apis/src/main/java/org/teavm/jso/geolocation/Coordinates.java @@ -0,0 +1,46 @@ +/* + * Copyright 2018 ScraM Team. + * + * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.jso.geolocation; + +import org.teavm.jso.JSObject; +import org.teavm.jso.JSProperty; + +/** + * + * @author ScraM Team + */ +public interface Coordinates extends JSObject { + @JSProperty + double getLatitude(); + + @JSProperty + double getLongitude(); + + @JSProperty + double getAltitude(); + + @JSProperty + double getAccuracy(); + + @JSProperty + double getAltitudeAccuracy(); + + @JSProperty + double getHeading(); + + @JSProperty + double getSpeed(); +} diff --git a/jso/apis/src/main/java/org/teavm/jso/geolocation/Geolocation.java b/jso/apis/src/main/java/org/teavm/jso/geolocation/Geolocation.java new file mode 100644 index 000000000..2e604ef9b --- /dev/null +++ b/jso/apis/src/main/java/org/teavm/jso/geolocation/Geolocation.java @@ -0,0 +1,27 @@ +/* + * Copyright 2018 ScraM Team. + * + * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.jso.geolocation; + +import org.teavm.jso.JSObject; + +/** + * + * @author ScraM Team + */ +public abstract class Geolocation implements JSObject { + public abstract void getCurrentPosition(PositionHandler positionHandler); + public abstract void getCurrentPosition(PositionHandler positionHandler, PositionErrorHandler positionErrorHandler); +} diff --git a/jso/apis/src/main/java/org/teavm/jso/geolocation/Position.java b/jso/apis/src/main/java/org/teavm/jso/geolocation/Position.java new file mode 100644 index 000000000..6fec14f04 --- /dev/null +++ b/jso/apis/src/main/java/org/teavm/jso/geolocation/Position.java @@ -0,0 +1,28 @@ +/* + * Copyright 2018 ScraM Team. + * + * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.jso.geolocation; + +import org.teavm.jso.JSObject; +import org.teavm.jso.JSProperty; + +/** + * + * @author ScraM Team + */ +public interface Position extends JSObject { + @JSProperty + Coordinates getCoords(); +} diff --git a/jso/apis/src/main/java/org/teavm/jso/geolocation/PositionError.java b/jso/apis/src/main/java/org/teavm/jso/geolocation/PositionError.java new file mode 100644 index 000000000..2fc77251d --- /dev/null +++ b/jso/apis/src/main/java/org/teavm/jso/geolocation/PositionError.java @@ -0,0 +1,35 @@ +/* + * Copyright 2018 ScraM Team. + * + * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.jso.geolocation; + +import org.teavm.jso.JSObject; +import org.teavm.jso.JSProperty; + +/** + * + * @author ScraM Team + */ +public interface PositionError extends JSObject { + int PERMISSION_DENIED = 1; + int POSITION_UNAVAILABLE = 2; + int TIMEOUT = 3; + + @JSProperty + int getCode(); + + @JSProperty + String getMessage(); +} diff --git a/jso/apis/src/main/java/org/teavm/jso/geolocation/PositionErrorHandler.java b/jso/apis/src/main/java/org/teavm/jso/geolocation/PositionErrorHandler.java new file mode 100644 index 000000000..bd696837c --- /dev/null +++ b/jso/apis/src/main/java/org/teavm/jso/geolocation/PositionErrorHandler.java @@ -0,0 +1,27 @@ +/* + * Copyright 2018 ScraM Team. + * + * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.jso.geolocation; + +import org.teavm.jso.JSFunctor; +import org.teavm.jso.JSObject; + +/** + * + */ +@JSFunctor +public interface PositionErrorHandler extends JSObject { + void handlePositionError(PositionError positionError); +} diff --git a/jso/apis/src/main/java/org/teavm/jso/geolocation/PositionHandler.java b/jso/apis/src/main/java/org/teavm/jso/geolocation/PositionHandler.java new file mode 100644 index 000000000..f506c9d3e --- /dev/null +++ b/jso/apis/src/main/java/org/teavm/jso/geolocation/PositionHandler.java @@ -0,0 +1,27 @@ +/* + * Copyright 2018 ScraM Team. + * + * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.jso.geolocation; + +import org.teavm.jso.JSFunctor; +import org.teavm.jso.JSObject; + +/** + * + */ +@JSFunctor +public interface PositionHandler extends JSObject { + void handlePosition(Position position); +}