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" |
Peter Beverloo
2013/03/11 17:57:25
What's happening to the DeviceOrientation.java fil
Miguel Garcia
2013/03/11 18:25:50
yes plese mv oldName newName, that way you remove
timvolodine1
2013/03/12 11:18:06
Done.
timvolodine1
2013/03/12 11:18:06
Done.
| |
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 // constants used for JNI calls to java | |
Peter Beverloo
2013/03/11 17:57:25
Please use proper sentences and grammar. As previ
timvolodine1
2013/03/12 11:18:06
actually reusing the DeviceData::Type enum now to
| |
23 // see DeviceMotionAndOrientation.java | |
24 enum DeviceMotionOrientationEvents { | |
Miguel Garcia
2013/03/11 18:25:50
This enum should probably be public, you've worked
timvolodine1
2013/03/12 11:18:06
Done.
| |
25 DEVICE_ORIENTATION = 0, | |
26 DEVICE_MOTION = 1 | |
27 }; | |
28 | |
22 } // namespace | 29 } // namespace |
23 | 30 |
24 DataFetcherImplAndroid::DataFetcherImplAndroid() { | 31 DataFetcherImplAndroid::DataFetcherImplAndroid() { |
25 device_orientation_.Reset( | 32 device_orientation_.Reset( |
26 Java_DeviceOrientation_getInstance(AttachCurrentThread())); | 33 Java_DeviceMotionAndOrientation_getInstance(AttachCurrentThread())); |
27 } | 34 } |
28 | 35 |
29 void DataFetcherImplAndroid::Init(JNIEnv* env) { | 36 void DataFetcherImplAndroid::Init(JNIEnv* env) { |
30 bool result = RegisterNativesImpl(env); | 37 bool result = RegisterNativesImpl(env); |
31 DCHECK(result); | 38 DCHECK(result); |
32 } | 39 } |
33 | 40 |
34 DataFetcher* DataFetcherImplAndroid::Create() { | 41 DataFetcher* DataFetcherImplAndroid::Create() { |
35 scoped_ptr<DataFetcherImplAndroid> fetcher(new DataFetcherImplAndroid); | 42 scoped_ptr<DataFetcherImplAndroid> fetcher(new DataFetcherImplAndroid); |
36 if (fetcher->Start(kPeriodInMilliseconds)) | 43 if (fetcher->Start(kPeriodInMilliseconds)) |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 base::AutoLock autolock(next_orientation_lock_); | 76 base::AutoLock autolock(next_orientation_lock_); |
70 | 77 |
71 Orientation* orientation = new Orientation(); | 78 Orientation* orientation = new Orientation(); |
72 orientation->set_alpha(alpha); | 79 orientation->set_alpha(alpha); |
73 orientation->set_beta(beta); | 80 orientation->set_beta(beta); |
74 orientation->set_gamma(gamma); | 81 orientation->set_gamma(gamma); |
75 orientation->set_absolute(true); | 82 orientation->set_absolute(true); |
76 next_orientation_ = orientation; | 83 next_orientation_ = orientation; |
77 } | 84 } |
78 | 85 |
86 void DataFetcherImplAndroid::GotAcceleration( | |
87 JNIEnv*, jobject, double x, double y, double z) { | |
88 // TODO: copy into shared memory buffer | |
Peter Beverloo
2013/03/11 17:57:25
This doesn't add a lot. Since it shouldn't be cal
Miguel Garcia
2013/03/11 18:25:50
Please add an owner to the TODO. I think it should
timvolodine1
2013/03/12 11:18:06
Done.
timvolodine1
2013/03/12 11:18:06
Done.
| |
89 } | |
90 | |
91 void DataFetcherImplAndroid::GotAccelerationIncludingGravity( | |
92 JNIEnv*, jobject, double x, double y, double z) { | |
93 } | |
Peter Beverloo
2013/03/11 17:57:25
Dito to line 88, please add the NOTIMPLEMENTED() e
timvolodine1
2013/03/12 11:18:06
Done.
| |
94 | |
95 void DataFetcherImplAndroid::GotRotationRate( | |
96 JNIEnv*, jobject, double alpha, double beta, double gamma) { | |
97 } | |
98 | |
99 // TODO: remove this method later, this is for compatibility now | |
Peter Beverloo
2013/03/11 17:57:25
nit: "// TODO: Remove this method when all callers
timvolodine1
2013/03/12 11:18:06
Done.
| |
79 bool DataFetcherImplAndroid::Start(int rate_in_milliseconds) { | 100 bool DataFetcherImplAndroid::Start(int rate_in_milliseconds) { |
101 return Start(DEVICE_ORIENTATION, rate_in_milliseconds); | |
102 //return Start(DEVICE_MOTION, rate_in_milliseconds); | |
Peter Beverloo
2013/03/11 17:57:25
nit: I'd prefer not to commit commented out code.
Miguel Garcia
2013/03/11 18:25:50
+1
On 2013/03/11 17:57:25, Peter Beverloo wrote:
timvolodine1
2013/03/12 11:18:06
Done.
timvolodine1
2013/03/12 11:18:06
Done.
| |
103 } | |
104 | |
105 bool DataFetcherImplAndroid::Start(int spec_event_type, | |
Miguel Garcia
2013/03/11 18:25:50
It does not really feel we need both Start methods
timvolodine1
2013/03/12 11:18:06
Done.
| |
106 int rate_in_milliseconds) { | |
80 DCHECK(!device_orientation_.is_null()); | 107 DCHECK(!device_orientation_.is_null()); |
81 return Java_DeviceOrientation_start(AttachCurrentThread(), | 108 return Java_DeviceMotionAndOrientation_start(AttachCurrentThread(), |
82 device_orientation_.obj(), | 109 device_orientation_.obj(), |
83 reinterpret_cast<jint>(this), | 110 reinterpret_cast<jint>(this), |
111 spec_event_type, | |
84 rate_in_milliseconds); | 112 rate_in_milliseconds); |
85 } | 113 } |
86 | 114 |
87 void DataFetcherImplAndroid::Stop() { | 115 // TODO: possibly remove this method, or make it stop everything |
Peter Beverloo
2013/03/11 17:57:25
In which case would we want to do that?
Miguel Garcia
2013/03/11 18:25:50
I'd remove it.
timvolodine1
2013/03/12 11:18:06
Done.
timvolodine1
2013/03/12 11:18:06
potentially in the destructor..
On 2013/03/11 17:
| |
116 // (e.g. both motion and orientation) | |
117 void DataFetcherImplAndroid::Stop(){ | |
118 Stop(DEVICE_ORIENTATION); | |
119 //Stop(DEVICE_MOTION); | |
Miguel Garcia
2013/03/11 18:25:50
commented line...
timvolodine1
2013/03/12 11:18:06
Done.
| |
120 } | |
121 | |
122 void DataFetcherImplAndroid::Stop(int spec_event_type) { | |
88 DCHECK(!device_orientation_.is_null()); | 123 DCHECK(!device_orientation_.is_null()); |
89 Java_DeviceOrientation_stop(AttachCurrentThread(), device_orientation_.obj()); | 124 Java_DeviceMotionAndOrientation_stop(AttachCurrentThread(), |
125 device_orientation_.obj(), | |
126 spec_event_type); | |
90 } | 127 } |
91 | 128 |
92 } // namespace content | 129 } // namespace content |
OLD | NEW |