2 * Copyright (C) 2010 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package android.webkit;
20 * This class is simply a container for the methods used to implement DeviceMotion and
21 * DeviceOrientation, including the mock DeviceOrientationClient for use in LayoutTests.
23 * This could be part of WebViewCore, but have moved it to its own class to
27 public final class DeviceMotionAndOrientationManager {
28 private WebViewCore mWebViewCore;
30 public DeviceMotionAndOrientationManager(WebViewCore webViewCore) {
31 mWebViewCore = webViewCore;
35 * Sets whether the Page for this WebViewCore should use a mock DeviceOrientation
38 public void useMock() {
39 assert WebViewCore.THREAD_NAME.equals(Thread.currentThread().getName());
40 nativeUseMock(mWebViewCore);
44 * Set the position for the mock DeviceOrientation service for this WebViewCore.
46 public void setMockOrientation(boolean canProvideAlpha, double alpha, boolean canProvideBeta,
47 double beta, boolean canProvideGamma, double gamma) {
48 assert WebViewCore.THREAD_NAME.equals(Thread.currentThread().getName());
49 nativeSetMockOrientation(mWebViewCore, canProvideAlpha, alpha, canProvideBeta, beta,
50 canProvideGamma, gamma);
53 // We only provide accelerationIncludingGravity.
54 public void onMotionChange(Double x, Double y, Double z, double interval) {
55 nativeOnMotionChange(mWebViewCore,
56 x != null, x != null ? x.doubleValue() : 0.0,
57 y != null, y != null ? y.doubleValue() : 0.0,
58 z != null, z != null ? z.doubleValue() : 0.0,
61 public void onOrientationChange(Double alpha, Double beta, Double gamma) {
62 nativeOnOrientationChange(mWebViewCore,
63 alpha != null, alpha != null ? alpha.doubleValue() : 0.0,
64 beta != null, beta != null ? beta.doubleValue() : 0.0,
65 gamma != null, gamma != null ? gamma.doubleValue() : 0.0);
69 private static native void nativeUseMock(WebViewCore webViewCore);
70 private static native void nativeSetMockOrientation(WebViewCore webViewCore,
71 boolean canProvideAlpha, double alpha, boolean canProvideBeta, double beta,
72 boolean canProvideGamma, double gamma);
73 private static native void nativeOnMotionChange(WebViewCore webViewCore,
74 boolean canProvideX, double x, boolean canProvideY, double y,
75 boolean canProvideZ, double z, double interval);
76 private static native void nativeOnOrientationChange(WebViewCore webViewCore,
77 boolean canProvideAlpha, double alpha, boolean canProvideBeta, double beta,
78 boolean canProvideGamma, double gamma);