OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/device_orientation/data_fetcher_impl_android.h" | 5 #include "content/browser/device_orientation/data_fetcher_impl_android.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "content/browser/device_orientation/orientation.h" | 9 #include "content/browser/device_orientation/orientation.h" |
10 #include "jni/DeviceOrientation_jni.h" | 10 #include "jni/DeviceMotionAndOrientation_jni.h" |
11 | 11 |
12 using base::android::AttachCurrentThread; | 12 using base::android::AttachCurrentThread; |
13 | 13 |
14 namespace content { | 14 namespace content { |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 // This should match ProviderImpl::kDesiredSamplingIntervalMs. | 18 // This should match ProviderImpl::kDesiredSamplingIntervalMs. |
19 // TODO(husky): Make that constant public so we can use it directly. | 19 // TODO(husky): Make that constant public so we can use it directly. |
20 const int kPeriodInMilliseconds = 100; | 20 const int kPeriodInMilliseconds = 100; |
21 | 21 |
22 } // namespace | 22 } // namespace |
23 | 23 |
24 DataFetcherImplAndroid::DataFetcherImplAndroid() { | 24 DataFetcherImplAndroid::DataFetcherImplAndroid() { |
25 device_orientation_.Reset( | 25 device_orientation_.Reset( |
26 Java_DeviceOrientation_getInstance(AttachCurrentThread())); | 26 Java_DeviceMotionAndOrientation_getInstance(AttachCurrentThread())); |
27 } | 27 } |
28 | 28 |
29 void DataFetcherImplAndroid::Init(JNIEnv* env) { | 29 void DataFetcherImplAndroid::Init(JNIEnv* env) { |
30 bool result = RegisterNativesImpl(env); | 30 bool result = RegisterNativesImpl(env); |
31 DCHECK(result); | 31 DCHECK(result); |
32 } | 32 } |
33 | 33 |
34 // TODO(timvolodine): Modify this method to be able to distinguish | |
35 // device motion from orientation. | |
34 DataFetcher* DataFetcherImplAndroid::Create() { | 36 DataFetcher* DataFetcherImplAndroid::Create() { |
35 scoped_ptr<DataFetcherImplAndroid> fetcher(new DataFetcherImplAndroid); | 37 scoped_ptr<DataFetcherImplAndroid> fetcher(new DataFetcherImplAndroid); |
36 if (fetcher->Start(kPeriodInMilliseconds)) | 38 if (fetcher->Start(DeviceData::kTypeOrientation, kPeriodInMilliseconds)) |
37 return fetcher.release(); | 39 return fetcher.release(); |
38 | 40 |
39 LOG(ERROR) << "DataFetcherImplAndroid::Start failed!"; | 41 LOG(ERROR) << "DataFetcherImplAndroid::Start failed!"; |
40 return NULL; | 42 return NULL; |
41 } | 43 } |
42 | 44 |
43 DataFetcherImplAndroid::~DataFetcherImplAndroid() { | 45 DataFetcherImplAndroid::~DataFetcherImplAndroid() { |
44 Stop(); | 46 // TODO(timvolodine): Support device motion as well. Only stop |
47 // the active event type(s). | |
48 Stop(DeviceData::kTypeOrientation); | |
45 } | 49 } |
46 | 50 |
47 const DeviceData* DataFetcherImplAndroid::GetDeviceData( | 51 const DeviceData* DataFetcherImplAndroid::GetDeviceData( |
48 DeviceData::Type type) { | 52 DeviceData::Type type) { |
49 if (type != DeviceData::kTypeOrientation) | 53 if (type != DeviceData::kTypeOrientation) |
50 return NULL; | 54 return NULL; |
51 return GetOrientation(); | 55 return GetOrientation(); |
52 } | 56 } |
53 | 57 |
54 const Orientation* DataFetcherImplAndroid::GetOrientation() { | 58 const Orientation* DataFetcherImplAndroid::GetOrientation() { |
(...skipping 14 matching lines...) Expand all Loading... | |
69 base::AutoLock autolock(next_orientation_lock_); | 73 base::AutoLock autolock(next_orientation_lock_); |
70 | 74 |
71 Orientation* orientation = new Orientation(); | 75 Orientation* orientation = new Orientation(); |
72 orientation->set_alpha(alpha); | 76 orientation->set_alpha(alpha); |
73 orientation->set_beta(beta); | 77 orientation->set_beta(beta); |
74 orientation->set_gamma(gamma); | 78 orientation->set_gamma(gamma); |
75 orientation->set_absolute(true); | 79 orientation->set_absolute(true); |
76 next_orientation_ = orientation; | 80 next_orientation_ = orientation; |
77 } | 81 } |
78 | 82 |
79 bool DataFetcherImplAndroid::Start(int rate_in_milliseconds) { | 83 void DataFetcherImplAndroid::GotAcceleration( |
84 JNIEnv*, jobject, double x, double y, double z) { | |
85 NOTIMPLEMENTED(); | |
86 } | |
87 | |
88 void DataFetcherImplAndroid::GotAccelerationIncludingGravity( | |
89 JNIEnv*, jobject, double x, double y, double z) { | |
90 NOTIMPLEMENTED(); | |
91 } | |
92 | |
93 void DataFetcherImplAndroid::GotRotationRate( | |
94 JNIEnv*, jobject, double alpha, double beta, double gamma) { | |
95 NOTIMPLEMENTED(); | |
96 } | |
97 | |
98 bool DataFetcherImplAndroid::Start(DeviceData::Type event_type, | |
99 int rate_in_milliseconds) { | |
80 DCHECK(!device_orientation_.is_null()); | 100 DCHECK(!device_orientation_.is_null()); |
81 return Java_DeviceOrientation_start(AttachCurrentThread(), | 101 return Java_DeviceMotionAndOrientation_start(AttachCurrentThread(), |
bulach
2013/03/19 15:22:36
nit: preferred way for callers is to move the firs
timvolodine
2013/03/19 16:50:08
Done.
| |
82 device_orientation_.obj(), | 102 device_orientation_.obj(), |
83 reinterpret_cast<jint>(this), | 103 reinterpret_cast<jint>(this), |
104 static_cast<jint>(event_type), | |
84 rate_in_milliseconds); | 105 rate_in_milliseconds); |
85 } | 106 } |
86 | 107 |
87 void DataFetcherImplAndroid::Stop() { | 108 void DataFetcherImplAndroid::Stop(DeviceData::Type event_type) { |
88 DCHECK(!device_orientation_.is_null()); | 109 DCHECK(!device_orientation_.is_null()); |
89 Java_DeviceOrientation_stop(AttachCurrentThread(), device_orientation_.obj()); | 110 Java_DeviceMotionAndOrientation_stop(AttachCurrentThread(), |
111 device_orientation_.obj(), | |
bulach
2013/03/19 15:22:36
nit: as above..
timvolodine
2013/03/19 16:50:08
Done.
| |
112 static_cast<jint>(event_type)); | |
90 } | 113 } |
91 | 114 |
92 } // namespace content | 115 } // namespace content |
OLD | NEW |