01: /*
02: *
03: *
04: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
05: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License version
09: * 2 only, as published by the Free Software Foundation.
10: *
11: * This program is distributed in the hope that it will be useful, but
12: * WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * General Public License version 2 for more details (a copy is
15: * included at /legal/license.txt).
16: *
17: * You should have received a copy of the GNU General Public License
18: * version 2 along with this work; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA
21: *
22: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
23: * Clara, CA 95054 or visit www.sun.com if you need additional
24: * information or have any questions.
25: */
26: package javax.microedition.location;
27:
28: import com.sun.j2me.location.*;
29: import com.sun.midp.security.Permissions;
30: import com.sun.midp.main.*;
31:
32: /**
33: * This class is defined by the JSR-179 specification
34: * <em>Location API for J2ME for J2ME™.</em>
35: */
36: // JAVADOC COMMENT ELIDED
37: public class Orientation {
38: /** Orientation support property */
39: private static final String ORIENTATION_SUPPORTED = "com.sun.j2me.location.OrientationSupported";
40: /** Angle off the horizon. */
41: private float azimuth;
42: /** Sample uses magnetic north. */
43: private boolean isMagnetic;
44: /** Pitch direction. */
45: private float pitch;
46: /** Roll direction. */
47: private float roll;
48:
49: // JAVADOC COMMENT ELIDED
50: public Orientation(float azimuth, boolean isMagnetic, float pitch,
51: float roll) {
52: this .azimuth = azimuth;
53: this .isMagnetic = isMagnetic;
54: this .pitch = pitch;
55: this .roll = roll;
56: }
57:
58: // JAVADOC COMMENT ELIDED
59: public float getCompassAzimuth() {
60: return azimuth;
61: }
62:
63: // JAVADOC COMMENT ELIDED
64: public boolean isOrientationMagnetic() {
65: return isMagnetic;
66: }
67:
68: // JAVADOC COMMENT ELIDED
69: public float getPitch() {
70: return pitch;
71: }
72:
73: // JAVADOC COMMENT ELIDED
74: public float getRoll() {
75: return roll;
76: }
77:
78: // JAVADOC COMMENT ELIDED
79: public static Orientation getOrientation() throws LocationException {
80: String orientationSupported = Configuration
81: .getProperty(ORIENTATION_SUPPORTED);
82: if (orientationSupported.equals("true")) {
83: Util.checkForPermission(Permissions.ORIENTATION);
84: OrientationProvider provider = OrientationProvider
85: .getInstance();
86: if (provider != null) {
87: return provider.getOrientation();
88: }
89: } else {
90: throw new LocationException(
91: "Orientation retrieval not supported");
92: }
93: return null;
94: }
95: }
|