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 "base/android/jni_android.h" | 5 #include "base/android/jni_android.h" |
6 #include "base/android/scoped_java_ref.h" | 6 #include "base/android/scoped_java_ref.h" |
7 | 7 |
8 // The main purpose of this is to ensure sample_for_tests_jni.h | 8 // The main purpose of this is to ensure sample_for_tests_jni.h |
9 // compiles and the functions declared in it as expected. | 9 // compiles and the functions declared in it as expected. |
10 | 10 |
11 using base::android::AttachCurrentThread; | 11 using base::android::AttachCurrentThread; |
12 using base::android::ScopedJavaLocalRef; | 12 using base::android::ScopedJavaLocalRef; |
13 | 13 |
14 namespace content { | 14 namespace base { |
| 15 namespace android { |
15 | 16 |
16 class CPPClass { | 17 class CPPClass { |
17 public: | 18 public: |
18 class InnerClass { | 19 class InnerClass { |
19 public: | 20 public: |
20 jdouble MethodOtherP0(JNIEnv* env, jobject obj) { | 21 jdouble MethodOtherP0(JNIEnv* env, jobject obj) { |
21 return 0.0; | 22 return 0.0; |
22 } | 23 } |
23 }; | 24 }; |
24 | 25 |
25 void Destroy(JNIEnv* env, jobject obj) { | 26 void Destroy(JNIEnv* env, jobject obj) { |
26 delete this; | 27 delete this; |
27 } | 28 } |
28 | 29 |
29 jint Method(JNIEnv* env, jobject obj) { | 30 jint Method(JNIEnv* env, jobject obj) { |
30 return 0; | 31 return 0; |
31 } | 32 } |
32 | 33 |
33 ScopedJavaLocalRef<jstring> InnerMethod(JNIEnv* env, jobject obj) { | 34 ScopedJavaLocalRef<jstring> InnerMethod(JNIEnv* env, jobject obj) { |
34 return ScopedJavaLocalRef<jstring>(); | 35 return ScopedJavaLocalRef<jstring>(); |
35 } | 36 } |
36 }; | 37 }; |
37 | 38 |
38 } // namespace content | 39 } // namespace android |
| 40 } // namespace base |
39 | 41 |
40 #include "jni/SampleForTests_jni.h" | 42 #include "jni/SampleForTests_jni.h" |
41 | 43 |
42 int main() { | 44 int main() { |
43 // On a regular application, you'd call AttachCurrentThread(). This sample is | 45 // On a regular application, you'd call AttachCurrentThread(). This sample is |
44 // not yet linking with all the libraries. | 46 // not yet linking with all the libraries. |
45 JNIEnv* env = /* AttachCurrentThread() */ NULL; | 47 JNIEnv* env = /* AttachCurrentThread() */ NULL; |
46 | 48 |
47 // This is how you call a java static method from C++. | 49 // This is how you call a java static method from C++. |
48 bool foo = content::Java_SampleForTests_staticJavaMethod(env); | 50 bool foo = base::android::Java_SampleForTests_staticJavaMethod(env); |
49 | 51 |
50 // This is how you call a java method from C++. Note that you must have | 52 // This is how you call a java method from C++. Note that you must have |
51 // obtained the jobject somehow. | 53 // obtained the jobject somehow. |
52 jobject my_java_object = NULL; | 54 jobject my_java_object = NULL; |
53 int bar = content::Java_SampleForTests_javaMethod(env, my_java_object, 1, 2); | 55 int bar = base::android::Java_SampleForTests_javaMethod( |
| 56 env, my_java_object, 1, 2); |
54 | 57 |
55 return 0; | 58 return 0; |
56 } | 59 } |
OLD | NEW |