1 /*
   2  * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package com.sun.javafx.ext.device.ios.sensors;
  26 
  27 
  28 import java.util.ArrayList;
  29 import java.util.List;
  30 
  31 public class IOSLocationManager {
  32 
  33     public interface HeadingListener {
  34         void headingUpdated(
  35             final double magneticHeading,
  36             final double trueHeading,
  37             final double magneticFieldX,
  38             final double magneticFieldY,
  39             final double magneticFieldZ);
  40     }
  41 
  42     public interface LocationListener {
  43         void locationUpdated(
  44             final double latitude,
  45             final double longitude,
  46             final double altitude,
  47             final double course,
  48             final double speed);
  49     }
  50 
  51     static {
  52         _init();
  53     }
  54 
  55     private static native void _init();
  56 
  57     public static native boolean isHeadingAvailable();
  58 
  59 
  60     private static List<HeadingListener> headingListeners = new ArrayList<HeadingListener>();
  61 
  62     public static void addHeadingListener(final HeadingListener headingListener) {
  63         headingListeners.add(headingListener);
  64     }
  65 
  66     public static void removeHeadingListener(final HeadingListener headingListener) {
  67         headingListeners.remove(headingListener);
  68     }
  69 
  70 
  71     private static List<LocationListener> locationListeners = new ArrayList<LocationListener>();
  72 
  73     public static void addLocationListener(final LocationListener locationListener) {
  74         locationListeners.add(locationListener);
  75     }
  76 
  77     public static void removeLocationListener(final LocationListener locationListener) {
  78         locationListeners.remove(locationListener);
  79     }
  80 
  81 
  82     private static void didUpdateHeading(
  83         final double magneticHeading,
  84         final double trueHeading,
  85         final double magneticFieldX,
  86         final double magneticFieldY,
  87         final double magneticFieldZ) {
  88         for (HeadingListener headingListener : headingListeners) {
  89             headingListener.headingUpdated(
  90                 magneticHeading,
  91                 trueHeading,
  92                 magneticFieldX,
  93                 magneticFieldY,
  94                 magneticFieldZ
  95             );
  96         }
  97     }
  98 
  99     private static void didUpdateLocation(
 100         final double latitude,
 101         final double longiude,
 102         final double altitude,
 103         final double course,
 104         final double speed) {
 105         for (LocationListener locationListener : locationListeners) {
 106             locationListener.locationUpdated(
 107                     latitude,
 108                     longiude,
 109                     altitude,
 110                     course,
 111                     speed
 112             );
 113         }
 114     }
 115 }