OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 package org.chromium.ui.gfx; | |
6 | |
7 import android.content.ContentResolver; | |
8 import android.content.Context; | |
9 import android.content.Intent; | |
10 | |
11 import org.chromium.base.JNINamespace; | |
12 | |
13 /** | |
14 * The window base class that has the minimum functionality. | |
15 */ | |
16 @JNINamespace("ui") | |
17 public abstract class NativeWindow { | |
18 | |
19 // Native pointer to the c++ WindowAndroid object. | |
20 private int mNativeWindowAndroid = 0; | |
21 | |
22 private Context mContext; | |
23 | |
24 /** | |
25 * An interface that intent callback objects have to implement. | |
26 */ | |
27 public interface IntentCallback { | |
28 /** | |
29 * Handles the data returned by the requested intent. | |
30 * @param window A window reference. | |
31 * @param resultCode Result code of the requested intent. | |
32 * @param contentResolver An instance of ContentResolver class for acces
sing returned data. | |
33 * @param data The data returned by the intent. | |
34 */ | |
35 public void onIntentCompleted(NativeWindow window, int resultCode, | |
36 ContentResolver contentResolver, Intent data); | |
37 } | |
38 | |
39 /** | |
40 * Constructs a Window object, saves a reference to the context. | |
41 * @param context | |
42 */ | |
43 public NativeWindow(Context context) { | |
44 mNativeWindowAndroid = 0; | |
45 mContext = context; | |
46 } | |
47 | |
48 /** | |
49 * Stub overridden by extending class. | |
50 */ | |
51 abstract public void sendBroadcast(Intent intent); | |
52 | |
53 /** | |
54 * Stub overridden by extending class. | |
55 */ | |
56 abstract public boolean showIntent(Intent intent, IntentCallback callback, S
tring error); | |
57 | |
58 /** | |
59 * Stub overridden by extending class. | |
60 */ | |
61 abstract public void showError(String error); | |
62 | |
63 /** | |
64 * @return context. | |
65 */ | |
66 public Context getContext() { | |
67 return mContext; | |
68 } | |
69 | |
70 /** | |
71 * Destroys the c++ WindowAndroid object if one has been created. | |
72 */ | |
73 public void destroy() { | |
74 if (mNativeWindowAndroid != 0) { | |
75 nativeDestroy(mNativeWindowAndroid); | |
76 mNativeWindowAndroid = 0; | |
77 } | |
78 } | |
79 | |
80 /** | |
81 * Returns a pointer to the c++ AndroidWindow object and calls the initializ
er if | |
82 * the object has not been previously initialized. | |
83 * @return A pointer to the c++ AndroidWindow. | |
84 */ | |
85 public int getNativePointer() { | |
86 if (mNativeWindowAndroid == 0) { | |
87 mNativeWindowAndroid = nativeInit(); | |
88 } | |
89 return mNativeWindowAndroid; | |
90 } | |
91 | |
92 private native int nativeInit(); | |
93 private native void nativeDestroy(int nativeWindowAndroid); | |
94 | |
95 } | |
OLD | NEW |