diff options
Diffstat (limited to 'ui/android')
-rw-r--r-- | ui/android/java/src/org/chromium/ui/SelectFileDialog.java | 10 | ||||
-rw-r--r-- | ui/android/java/src/org/chromium/ui/WindowAndroid.java (renamed from ui/android/java/src/org/chromium/ui/gfx/ActivityNativeWindow.java) | 66 | ||||
-rw-r--r-- | ui/android/java/src/org/chromium/ui/gfx/NativeWindow.java | 95 | ||||
-rw-r--r-- | ui/android/ui_jni_registrar.cc | 6 | ||||
-rw-r--r-- | ui/android/window_android.cc | 45 | ||||
-rw-r--r-- | ui/android/window_android.h | 36 |
6 files changed, 144 insertions, 114 deletions
diff --git a/ui/android/java/src/org/chromium/ui/SelectFileDialog.java b/ui/android/java/src/org/chromium/ui/SelectFileDialog.java index a50a257..a9b117b 100644 --- a/ui/android/java/src/org/chromium/ui/SelectFileDialog.java +++ b/ui/android/java/src/org/chromium/ui/SelectFileDialog.java @@ -19,14 +19,14 @@ import java.util.List; import org.chromium.base.CalledByNative; import org.chromium.base.JNINamespace; -import org.chromium.ui.gfx.NativeWindow; +import org.chromium.ui.WindowAndroid; /** * A dialog that is triggered from a file input field that allows a user to select a file based on * a set of accepted file types. The path of the selected file is passed to the native dialog. */ @JNINamespace("ui") -class SelectFileDialog implements NativeWindow.IntentCallback{ +class SelectFileDialog implements WindowAndroid.IntentCallback{ private static final String IMAGE_TYPE = "image/"; private static final String VIDEO_TYPE = "video/"; private static final String AUDIO_TYPE = "audio/"; @@ -53,10 +53,10 @@ class SelectFileDialog implements NativeWindow.IntentCallback{ * Creates and starts an intent based on the passed fileTypes and capture value. * @param fileTypes MIME types requested (i.e. "image/*") * @param capture The capture value as described in http://www.w3.org/TR/html-media-capture/ - * @param window The NativeWindow that can show intents + * @param window The WindowAndroid that can show intents */ @CalledByNative - private void selectFile(String[] fileTypes, String capture, NativeWindow window) { + private void selectFile(String[] fileTypes, String capture, WindowAndroid window) { mFileTypes = new ArrayList<String>(Arrays.asList(fileTypes)); mCapture = capture; @@ -140,7 +140,7 @@ class SelectFileDialog implements NativeWindow.IntentCallback{ * @param results The results of the requested intent. */ @Override - public void onIntentCompleted(NativeWindow window, int resultCode, + public void onIntentCompleted(WindowAndroid window, int resultCode, ContentResolver contentResolver, Intent results) { if (resultCode != Activity.RESULT_OK) { onFileNotSelected(); diff --git a/ui/android/java/src/org/chromium/ui/gfx/ActivityNativeWindow.java b/ui/android/java/src/org/chromium/ui/WindowAndroid.java index 821a8a8..58716d8 100644 --- a/ui/android/java/src/org/chromium/ui/gfx/ActivityNativeWindow.java +++ b/ui/android/java/src/org/chromium/ui/WindowAndroid.java @@ -2,10 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -package org.chromium.ui.gfx; +package org.chromium.ui; import android.app.Activity; import android.content.ActivityNotFoundException; +import android.content.ContentResolver; +import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.util.SparseArray; @@ -13,11 +15,16 @@ import android.widget.Toast; import java.util.HashMap; +import org.chromium.base.JNINamespace; + /** - * The window that has access to the main activity and is able to create and receive intents, - * and show error messages. + * The window base class that has the minimum functionality. */ -public class ActivityNativeWindow extends NativeWindow { +@JNINamespace("ui") +public class WindowAndroid { + + // Native pointer to the c++ WindowAndroid object. + private int mNativeWindowAndroid = 0; // Constants used for intent request code bounding. private static final int REQUEST_CODE_PREFIX = 1000; @@ -33,8 +40,7 @@ public class ActivityNativeWindow extends NativeWindow { /** * @param activity */ - public ActivityNativeWindow(Activity activity) { - super(activity); + public WindowAndroid(Activity activity) { mActivity = activity; mOutstandingIntents = new SparseArray<IntentCallback>(); mIntentErrors = new HashMap<Integer, String>(); @@ -48,7 +54,6 @@ public class ActivityNativeWindow extends NativeWindow { * @param error The error string to be show if activity is paused before intent results. * @return Whether the intent was shown. */ - @Override public boolean showIntent(Intent intent, IntentCallback callback, String error) { int requestCode = REQUEST_CODE_PREFIX + mNextRequestCode; mNextRequestCode = (mNextRequestCode + 1) % REQUEST_CODE_RANGE_SIZE; @@ -69,7 +74,6 @@ public class ActivityNativeWindow extends NativeWindow { * Displays an error message with a provided error message string. * @param error The error message string to be displayed. */ - @Override public void showError(String error) { if (error != null) { Toast.makeText(mActivity, error, Toast.LENGTH_SHORT).show(); @@ -87,15 +91,15 @@ public class ActivityNativeWindow extends NativeWindow { /** * Broadcasts the given intent to all interested BroadcastReceivers. */ - @Override public void sendBroadcast(Intent intent) { mActivity.sendBroadcast(intent); } /** - * @return Application activity. + * TODO(nileshagrawal): Stop returning Activity Context crbug.com/233440. + * @return Activity context. */ - public Activity getActivity() { + public Context getContext() { return mActivity; } @@ -149,4 +153,44 @@ public class ActivityNativeWindow extends NativeWindow { return false; } + /** + * An interface that intent callback objects have to implement. + */ + public interface IntentCallback { + /** + * Handles the data returned by the requested intent. + * @param window A window reference. + * @param resultCode Result code of the requested intent. + * @param contentResolver An instance of ContentResolver class for accessing returned data. + * @param data The data returned by the intent. + */ + public void onIntentCompleted(WindowAndroid window, int resultCode, + ContentResolver contentResolver, Intent data); + } + + /** + * Destroys the c++ WindowAndroid object if one has been created. + */ + public void destroy() { + if (mNativeWindowAndroid != 0) { + nativeDestroy(mNativeWindowAndroid); + mNativeWindowAndroid = 0; + } + } + + /** + * Returns a pointer to the c++ AndroidWindow object and calls the initializer if + * the object has not been previously initialized. + * @return A pointer to the c++ AndroidWindow. + */ + public int getNativePointer() { + if (mNativeWindowAndroid == 0) { + mNativeWindowAndroid = nativeInit(); + } + return mNativeWindowAndroid; + } + + private native int nativeInit(); + private native void nativeDestroy(int nativeWindowAndroid); + } diff --git a/ui/android/java/src/org/chromium/ui/gfx/NativeWindow.java b/ui/android/java/src/org/chromium/ui/gfx/NativeWindow.java deleted file mode 100644 index 3782d30..0000000 --- a/ui/android/java/src/org/chromium/ui/gfx/NativeWindow.java +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package org.chromium.ui.gfx; - -import android.content.ContentResolver; -import android.content.Context; -import android.content.Intent; - -import org.chromium.base.JNINamespace; - -/** - * The window base class that has the minimum functionality. - */ -@JNINamespace("ui") -public abstract class NativeWindow { - - // Native pointer to the c++ WindowAndroid object. - private int mNativeWindowAndroid = 0; - - private Context mContext; - - /** - * An interface that intent callback objects have to implement. - */ - public interface IntentCallback { - /** - * Handles the data returned by the requested intent. - * @param window A window reference. - * @param resultCode Result code of the requested intent. - * @param contentResolver An instance of ContentResolver class for accessing returned data. - * @param data The data returned by the intent. - */ - public void onIntentCompleted(NativeWindow window, int resultCode, - ContentResolver contentResolver, Intent data); - } - - /** - * Constructs a Window object, saves a reference to the context. - * @param context - */ - public NativeWindow(Context context) { - mNativeWindowAndroid = 0; - mContext = context; - } - - /** - * Stub overridden by extending class. - */ - abstract public void sendBroadcast(Intent intent); - - /** - * Stub overridden by extending class. - */ - abstract public boolean showIntent(Intent intent, IntentCallback callback, String error); - - /** - * Stub overridden by extending class. - */ - abstract public void showError(String error); - - /** - * @return context. - */ - public Context getContext() { - return mContext; - } - - /** - * Destroys the c++ WindowAndroid object if one has been created. - */ - public void destroy() { - if (mNativeWindowAndroid != 0) { - nativeDestroy(mNativeWindowAndroid); - mNativeWindowAndroid = 0; - } - } - - /** - * Returns a pointer to the c++ AndroidWindow object and calls the initializer if - * the object has not been previously initialized. - * @return A pointer to the c++ AndroidWindow. - */ - public int getNativePointer() { - if (mNativeWindowAndroid == 0) { - mNativeWindowAndroid = nativeInit(); - } - return mNativeWindowAndroid; - } - - private native int nativeInit(); - private native void nativeDestroy(int nativeWindowAndroid); - -} diff --git a/ui/android/ui_jni_registrar.cc b/ui/android/ui_jni_registrar.cc index e2ddac1..5a0149b 100644 --- a/ui/android/ui_jni_registrar.cc +++ b/ui/android/ui_jni_registrar.cc @@ -6,21 +6,21 @@ #include "base/android/jni_android.h" #include "base/android/jni_registrar.h" +#include "ui/android/window_android.h" #include "ui/base/clipboard/clipboard_android_initialization.h" #include "ui/base/l10n/l10n_util_android.h" #include "ui/gfx/android/device_display_info.h" #include "ui/gfx/android/java_bitmap.h" -#include "ui/gfx/android/window_android.h" namespace ui { namespace android { static base::android::RegistrationMethod kUiRegisteredMethods[] = { + { "Clipboard", ui::RegisterClipboardAndroid }, { "DeviceDisplayInfo", gfx::DeviceDisplayInfo::RegisterDeviceDisplayInfo }, { "JavaBitmap", gfx::JavaBitmap::RegisterJavaBitmap }, { "LocalizationUtils", l10n_util::RegisterLocalizationUtil }, - { "NativeWindow", ui::WindowAndroid::RegisterWindowAndroid }, - { "Clipboard", ui::RegisterClipboardAndroid }, + { "WindowAndroid", ui::WindowAndroid::RegisterWindowAndroid }, }; bool RegisterJni(JNIEnv* env) { diff --git a/ui/android/window_android.cc b/ui/android/window_android.cc new file mode 100644 index 0000000..1f2ccb2f9 --- /dev/null +++ b/ui/android/window_android.cc @@ -0,0 +1,45 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/android/window_android.h" + +#include "base/android/jni_android.h" +#include "base/android/jni_helper.h" +#include "base/android/scoped_java_ref.h" +#include "jni/WindowAndroid_jni.h" + +namespace ui { + +using base::android::AttachCurrentThread; +using base::android::ScopedJavaLocalRef; + +WindowAndroid::WindowAndroid(JNIEnv* env, jobject obj) + : weak_java_window_(env, obj) { +} + +void WindowAndroid::Destroy(JNIEnv* env, jobject obj) { + delete this; +} + +ScopedJavaLocalRef<jobject> WindowAndroid::GetJavaObject() { + return weak_java_window_.get(AttachCurrentThread()); +} + +bool WindowAndroid::RegisterWindowAndroid(JNIEnv* env) { + return RegisterNativesImpl(env); +} + +WindowAndroid::~WindowAndroid() { +} + +// ---------------------------------------------------------------------------- +// Native JNI methods +// ---------------------------------------------------------------------------- + +jint Init(JNIEnv* env, jobject obj) { + WindowAndroid* window = new WindowAndroid(env, obj); + return reinterpret_cast<jint>(window); +} + +} // namespace ui diff --git a/ui/android/window_android.h b/ui/android/window_android.h new file mode 100644 index 0000000..c1c5c44 --- /dev/null +++ b/ui/android/window_android.h @@ -0,0 +1,36 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_ANDROID_WINDOW_ANDROID_H_ +#define UI_ANDROID_WINDOW_ANDROID_H_ + +#include <jni.h> +#include "base/android/jni_helper.h" +#include "base/android/scoped_java_ref.h" +#include "ui/base/ui_export.h" + +namespace ui { + +// Android implementation of the activity window. +class UI_EXPORT WindowAndroid { + public: + WindowAndroid(JNIEnv* env, jobject obj); + + void Destroy(JNIEnv* env, jobject obj); + + base::android::ScopedJavaLocalRef<jobject> GetJavaObject(); + + static bool RegisterWindowAndroid(JNIEnv* env); + + private: + ~WindowAndroid(); + + JavaObjectWeakGlobalRef weak_java_window_; + + DISALLOW_COPY_AND_ASSIGN(WindowAndroid); +}; + +} // namespace ui + +#endif // UI_ANDROID_WINDOW_ANDROID_H_ |