Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Jeff Sharkey | 1abdb71 | 2013-08-11 16:28:14 -0700 | [diff] [blame] | 16 | |
Dianne Hackborn | 69969e4 | 2010-05-04 11:40:40 -0700 | [diff] [blame] | 17 | package android.app; |
| 18 | |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 19 | import android.content.Context; |
Dianne Hackborn | 69969e4 | 2010-05-04 11:40:40 -0700 | [diff] [blame] | 20 | import android.content.pm.ActivityInfo; |
Dianne Hackborn | 69969e4 | 2010-05-04 11:40:40 -0700 | [diff] [blame] | 21 | import android.content.pm.PackageManager; |
Christopher Tate | 6cce32b | 2010-07-12 18:21:36 -0700 | [diff] [blame] | 22 | import android.content.res.AssetManager; |
Dianne Hackborn | 08d5b8f | 2010-08-04 11:12:40 -0700 | [diff] [blame] | 23 | import android.content.res.Configuration; |
Dianne Hackborn | 54a181b | 2010-06-30 18:35:14 -0700 | [diff] [blame] | 24 | import android.graphics.PixelFormat; |
Dianne Hackborn | 6826741 | 2010-07-02 18:52:01 -0700 | [diff] [blame] | 25 | import android.os.Build; |
Dianne Hackborn | 69969e4 | 2010-05-04 11:40:40 -0700 | [diff] [blame] | 26 | import android.os.Bundle; |
Dianne Hackborn | 3c80a4a | 2010-06-29 19:20:40 -0700 | [diff] [blame] | 27 | import android.os.Looper; |
| 28 | import android.os.MessageQueue; |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 29 | import android.util.AttributeSet; |
Dianne Hackborn | 1e4b9f3 | 2010-06-23 14:10:57 -0700 | [diff] [blame] | 30 | import android.view.InputQueue; |
Dianne Hackborn | 54a181b | 2010-06-30 18:35:14 -0700 | [diff] [blame] | 31 | import android.view.Surface; |
Dianne Hackborn | 74323fd | 2010-05-18 17:56:23 -0700 | [diff] [blame] | 32 | import android.view.SurfaceHolder; |
Dianne Hackborn | 3c80a4a | 2010-06-29 19:20:40 -0700 | [diff] [blame] | 33 | import android.view.View; |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 34 | import android.view.ViewTreeObserver.OnGlobalLayoutListener; |
Jeff Sharkey | 1abdb71 | 2013-08-11 16:28:14 -0700 | [diff] [blame] | 35 | import android.view.WindowManager; |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 36 | import android.view.inputmethod.InputMethodManager; |
Dianne Hackborn | 69969e4 | 2010-05-04 11:40:40 -0700 | [diff] [blame] | 37 | |
Dmitriy Ivanov | 048a0db | 2015-11-15 14:58:36 -0800 | [diff] [blame] | 38 | import dalvik.system.BaseDexClassLoader; |
| 39 | |
Dianne Hackborn | 69969e4 | 2010-05-04 11:40:40 -0700 | [diff] [blame] | 40 | import java.io.File; |
| 41 | |
| 42 | /** |
| 43 | * Convenience for implementing an activity that will be implemented |
Dianne Hackborn | 08d5b8f | 2010-08-04 11:12:40 -0700 | [diff] [blame] | 44 | * purely in native code. That is, a game (or game-like thing). There |
| 45 | * is no need to derive from this class; you can simply declare it in your |
| 46 | * manifest, and use the NDK APIs from there. |
| 47 | * |
| 48 | * <p>A typical manifest would look like: |
| 49 | * |
| 50 | * {@sample development/ndk/platforms/android-9/samples/native-activity/AndroidManifest.xml |
| 51 | * manifest} |
| 52 | * |
| 53 | * <p>A very simple example of native code that is run by NativeActivity |
| 54 | * follows. This reads input events from the user and uses OpenGLES to |
| 55 | * draw into the native activity's window. |
| 56 | * |
| 57 | * {@sample development/ndk/platforms/android-9/samples/native-activity/jni/main.c all} |
Dianne Hackborn | 69969e4 | 2010-05-04 11:40:40 -0700 | [diff] [blame] | 58 | */ |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 59 | public class NativeActivity extends Activity implements SurfaceHolder.Callback2, |
| 60 | InputQueue.Callback, OnGlobalLayoutListener { |
Dianne Hackborn | e21d91c6 | 2010-10-24 14:56:38 -0700 | [diff] [blame] | 61 | /** |
| 62 | * Optional meta-that can be in the manifest for this component, specifying |
| 63 | * the name of the native shared library to load. If not specified, |
| 64 | * "main" is used. |
| 65 | */ |
Dianne Hackborn | 69969e4 | 2010-05-04 11:40:40 -0700 | [diff] [blame] | 66 | public static final String META_DATA_LIB_NAME = "android.app.lib_name"; |
| 67 | |
Dianne Hackborn | e21d91c6 | 2010-10-24 14:56:38 -0700 | [diff] [blame] | 68 | /** |
| 69 | * Optional meta-that can be in the manifest for this component, specifying |
| 70 | * the name of the main entry point for this native activity in the |
| 71 | * {@link #META_DATA_LIB_NAME} native code. If not specified, |
| 72 | * "ANativeActivity_onCreate" is used. |
| 73 | */ |
| 74 | public static final String META_DATA_FUNC_NAME = "android.app.func_name"; |
| 75 | |
| 76 | private static final String KEY_NATIVE_SAVED_STATE = "android:native_state"; |
Dianne Hackborn | 08d5b8f | 2010-08-04 11:12:40 -0700 | [diff] [blame] | 77 | |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 78 | private NativeContentView mNativeContentView; |
| 79 | private InputMethodManager mIMM; |
| 80 | |
Ashok Bhat | 58b8b24 | 2014-01-02 16:52:41 +0000 | [diff] [blame] | 81 | private long mNativeHandle; |
Dianne Hackborn | 69969e4 | 2010-05-04 11:40:40 -0700 | [diff] [blame] | 82 | |
Dianne Hackborn | 3c80a4a | 2010-06-29 19:20:40 -0700 | [diff] [blame] | 83 | private InputQueue mCurInputQueue; |
| 84 | private SurfaceHolder mCurSurfaceHolder; |
| 85 | |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 86 | final int[] mLocation = new int[2]; |
| 87 | int mLastContentX; |
| 88 | int mLastContentY; |
| 89 | int mLastContentWidth; |
| 90 | int mLastContentHeight; |
| 91 | |
| 92 | private boolean mDispatchingUnhandledKey; |
| 93 | |
Dianne Hackborn | 3c80a4a | 2010-06-29 19:20:40 -0700 | [diff] [blame] | 94 | private boolean mDestroyed; |
| 95 | |
Ashok Bhat | 58b8b24 | 2014-01-02 16:52:41 +0000 | [diff] [blame] | 96 | private native long loadNativeCode(String path, String funcname, MessageQueue queue, |
Dianne Hackborn | 805fd7e | 2011-01-16 18:30:29 -0800 | [diff] [blame] | 97 | String internalDataPath, String obbPath, String externalDataPath, int sdkVersion, |
Dmitriy Ivanov | 048a0db | 2015-11-15 14:58:36 -0800 | [diff] [blame] | 98 | AssetManager assetMgr, byte[] savedState, ClassLoader classLoader, String libraryPath, |
| 99 | String isolationPath); |
| 100 | private native String getDlError(); |
Ashok Bhat | 58b8b24 | 2014-01-02 16:52:41 +0000 | [diff] [blame] | 101 | private native void unloadNativeCode(long handle); |
| 102 | private native void onStartNative(long handle); |
| 103 | private native void onResumeNative(long handle); |
| 104 | private native byte[] onSaveInstanceStateNative(long handle); |
| 105 | private native void onPauseNative(long handle); |
| 106 | private native void onStopNative(long handle); |
| 107 | private native void onConfigurationChangedNative(long handle); |
| 108 | private native void onLowMemoryNative(long handle); |
| 109 | private native void onWindowFocusChangedNative(long handle, boolean focused); |
| 110 | private native void onSurfaceCreatedNative(long handle, Surface surface); |
| 111 | private native void onSurfaceChangedNative(long handle, Surface surface, |
Dianne Hackborn | 74323fd | 2010-05-18 17:56:23 -0700 | [diff] [blame] | 112 | int format, int width, int height); |
Ashok Bhat | 58b8b24 | 2014-01-02 16:52:41 +0000 | [diff] [blame] | 113 | private native void onSurfaceRedrawNeededNative(long handle, Surface surface); |
| 114 | private native void onSurfaceDestroyedNative(long handle); |
| 115 | private native void onInputQueueCreatedNative(long handle, long queuePtr); |
| 116 | private native void onInputQueueDestroyedNative(long handle, long queuePtr); |
| 117 | private native void onContentRectChangedNative(long handle, int x, int y, int w, int h); |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 118 | |
| 119 | static class NativeContentView extends View { |
| 120 | NativeActivity mActivity; |
| 121 | |
| 122 | public NativeContentView(Context context) { |
| 123 | super(context); |
| 124 | } |
| 125 | |
| 126 | public NativeContentView(Context context, AttributeSet attrs) { |
| 127 | super(context, attrs); |
| 128 | } |
| 129 | } |
Dianne Hackborn | 2c6081c | 2010-07-15 17:44:53 -0700 | [diff] [blame] | 130 | |
Dianne Hackborn | 69969e4 | 2010-05-04 11:40:40 -0700 | [diff] [blame] | 131 | @Override |
| 132 | protected void onCreate(Bundle savedInstanceState) { |
| 133 | String libname = "main"; |
Dianne Hackborn | e21d91c6 | 2010-10-24 14:56:38 -0700 | [diff] [blame] | 134 | String funcname = "ANativeActivity_onCreate"; |
Dianne Hackborn | 69969e4 | 2010-05-04 11:40:40 -0700 | [diff] [blame] | 135 | ActivityInfo ai; |
Yohei Yukawa | 777ef95 | 2015-11-25 20:32:24 -0800 | [diff] [blame] | 136 | |
| 137 | mIMM = getSystemService(InputMethodManager.class); |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 138 | |
Dianne Hackborn | 74323fd | 2010-05-18 17:56:23 -0700 | [diff] [blame] | 139 | getWindow().takeSurface(this); |
Dianne Hackborn | 1e4b9f3 | 2010-06-23 14:10:57 -0700 | [diff] [blame] | 140 | getWindow().takeInputQueue(this); |
Dianne Hackborn | 54a181b | 2010-06-30 18:35:14 -0700 | [diff] [blame] | 141 | getWindow().setFormat(PixelFormat.RGB_565); |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 142 | getWindow().setSoftInputMode( |
| 143 | WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED |
| 144 | | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); |
| 145 | |
| 146 | mNativeContentView = new NativeContentView(this); |
| 147 | mNativeContentView.mActivity = this; |
| 148 | setContentView(mNativeContentView); |
| 149 | mNativeContentView.requestFocus(); |
| 150 | mNativeContentView.getViewTreeObserver().addOnGlobalLayoutListener(this); |
Dianne Hackborn | 74323fd | 2010-05-18 17:56:23 -0700 | [diff] [blame] | 151 | |
Dianne Hackborn | 69969e4 | 2010-05-04 11:40:40 -0700 | [diff] [blame] | 152 | try { |
| 153 | ai = getPackageManager().getActivityInfo( |
| 154 | getIntent().getComponent(), PackageManager.GET_META_DATA); |
| 155 | if (ai.metaData != null) { |
| 156 | String ln = ai.metaData.getString(META_DATA_LIB_NAME); |
| 157 | if (ln != null) libname = ln; |
Dianne Hackborn | e21d91c6 | 2010-10-24 14:56:38 -0700 | [diff] [blame] | 158 | ln = ai.metaData.getString(META_DATA_FUNC_NAME); |
| 159 | if (ln != null) funcname = ln; |
Dianne Hackborn | 69969e4 | 2010-05-04 11:40:40 -0700 | [diff] [blame] | 160 | } |
| 161 | } catch (PackageManager.NameNotFoundException e) { |
| 162 | throw new RuntimeException("Error getting activity info", e); |
| 163 | } |
Dmitriy Ivanov | 048a0db | 2015-11-15 14:58:36 -0800 | [diff] [blame] | 164 | |
| 165 | BaseDexClassLoader classLoader = (BaseDexClassLoader) getClassLoader(); |
| 166 | String path = classLoader.findLibrary(libname); |
| 167 | |
Dianne Hackborn | 69969e4 | 2010-05-04 11:40:40 -0700 | [diff] [blame] | 168 | if (path == null) { |
Dimitry Ivanov | b9c9026 | 2016-02-19 14:09:20 -0800 | [diff] [blame] | 169 | throw new IllegalArgumentException("Unable to find native library " + libname + |
| 170 | " using classloader: " + classLoader.toString()); |
Dianne Hackborn | 69969e4 | 2010-05-04 11:40:40 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Dianne Hackborn | 08d5b8f | 2010-08-04 11:12:40 -0700 | [diff] [blame] | 173 | byte[] nativeSavedState = savedInstanceState != null |
| 174 | ? savedInstanceState.getByteArray(KEY_NATIVE_SAVED_STATE) : null; |
| 175 | |
Dianne Hackborn | e21d91c6 | 2010-10-24 14:56:38 -0700 | [diff] [blame] | 176 | mNativeHandle = loadNativeCode(path, funcname, Looper.myQueue(), |
Jeff Sharkey | e0475c8 | 2013-08-15 11:50:02 -0700 | [diff] [blame] | 177 | getAbsolutePath(getFilesDir()), getAbsolutePath(getObbDir()), |
| 178 | getAbsolutePath(getExternalFilesDir(null)), |
Dmitriy Ivanov | 048a0db | 2015-11-15 14:58:36 -0800 | [diff] [blame] | 179 | Build.VERSION.SDK_INT, getAssets(), nativeSavedState, |
| 180 | classLoader, classLoader.getLdLibraryPath(), |
| 181 | classLoader.getLibraryPermittedPath()); |
Jeff Sharkey | e0475c8 | 2013-08-15 11:50:02 -0700 | [diff] [blame] | 182 | |
Dianne Hackborn | 69969e4 | 2010-05-04 11:40:40 -0700 | [diff] [blame] | 183 | if (mNativeHandle == 0) { |
Dmitriy Ivanov | 048a0db | 2015-11-15 14:58:36 -0800 | [diff] [blame] | 184 | throw new UnsatisfiedLinkError( |
| 185 | "Unable to load native library \"" + path + "\": " + getDlError()); |
Dianne Hackborn | 69969e4 | 2010-05-04 11:40:40 -0700 | [diff] [blame] | 186 | } |
| 187 | super.onCreate(savedInstanceState); |
| 188 | } |
| 189 | |
Jeff Sharkey | e0475c8 | 2013-08-15 11:50:02 -0700 | [diff] [blame] | 190 | private static String getAbsolutePath(File file) { |
| 191 | return (file != null) ? file.getAbsolutePath() : null; |
| 192 | } |
| 193 | |
Dianne Hackborn | 69969e4 | 2010-05-04 11:40:40 -0700 | [diff] [blame] | 194 | @Override |
| 195 | protected void onDestroy() { |
Dianne Hackborn | 3c80a4a | 2010-06-29 19:20:40 -0700 | [diff] [blame] | 196 | mDestroyed = true; |
| 197 | if (mCurSurfaceHolder != null) { |
Dianne Hackborn | 54a181b | 2010-06-30 18:35:14 -0700 | [diff] [blame] | 198 | onSurfaceDestroyedNative(mNativeHandle); |
Dianne Hackborn | 3c80a4a | 2010-06-29 19:20:40 -0700 | [diff] [blame] | 199 | mCurSurfaceHolder = null; |
| 200 | } |
| 201 | if (mCurInputQueue != null) { |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 202 | onInputQueueDestroyedNative(mNativeHandle, mCurInputQueue.getNativePtr()); |
Dianne Hackborn | 3c80a4a | 2010-06-29 19:20:40 -0700 | [diff] [blame] | 203 | mCurInputQueue = null; |
| 204 | } |
Dianne Hackborn | 69969e4 | 2010-05-04 11:40:40 -0700 | [diff] [blame] | 205 | unloadNativeCode(mNativeHandle); |
| 206 | super.onDestroy(); |
| 207 | } |
| 208 | |
| 209 | @Override |
Dianne Hackborn | 69969e4 | 2010-05-04 11:40:40 -0700 | [diff] [blame] | 210 | protected void onPause() { |
| 211 | super.onPause(); |
| 212 | onPauseNative(mNativeHandle); |
| 213 | } |
| 214 | |
| 215 | @Override |
| 216 | protected void onResume() { |
| 217 | super.onResume(); |
| 218 | onResumeNative(mNativeHandle); |
| 219 | } |
| 220 | |
| 221 | @Override |
| 222 | protected void onSaveInstanceState(Bundle outState) { |
| 223 | super.onSaveInstanceState(outState); |
Dianne Hackborn | 08d5b8f | 2010-08-04 11:12:40 -0700 | [diff] [blame] | 224 | byte[] state = onSaveInstanceStateNative(mNativeHandle); |
| 225 | if (state != null) { |
| 226 | outState.putByteArray(KEY_NATIVE_SAVED_STATE, state); |
| 227 | } |
Dianne Hackborn | 69969e4 | 2010-05-04 11:40:40 -0700 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | @Override |
| 231 | protected void onStart() { |
| 232 | super.onStart(); |
| 233 | onStartNative(mNativeHandle); |
| 234 | } |
| 235 | |
| 236 | @Override |
| 237 | protected void onStop() { |
| 238 | super.onStop(); |
| 239 | onStopNative(mNativeHandle); |
| 240 | } |
| 241 | |
| 242 | @Override |
Dianne Hackborn | 08d5b8f | 2010-08-04 11:12:40 -0700 | [diff] [blame] | 243 | public void onConfigurationChanged(Configuration newConfig) { |
| 244 | super.onConfigurationChanged(newConfig); |
| 245 | if (!mDestroyed) { |
| 246 | onConfigurationChangedNative(mNativeHandle); |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | @Override |
Dianne Hackborn | 74323fd | 2010-05-18 17:56:23 -0700 | [diff] [blame] | 251 | public void onLowMemory() { |
| 252 | super.onLowMemory(); |
Dianne Hackborn | 3c80a4a | 2010-06-29 19:20:40 -0700 | [diff] [blame] | 253 | if (!mDestroyed) { |
| 254 | onLowMemoryNative(mNativeHandle); |
| 255 | } |
Dianne Hackborn | 74323fd | 2010-05-18 17:56:23 -0700 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | @Override |
Dianne Hackborn | 69969e4 | 2010-05-04 11:40:40 -0700 | [diff] [blame] | 259 | public void onWindowFocusChanged(boolean hasFocus) { |
| 260 | super.onWindowFocusChanged(hasFocus); |
Dianne Hackborn | 3c80a4a | 2010-06-29 19:20:40 -0700 | [diff] [blame] | 261 | if (!mDestroyed) { |
| 262 | onWindowFocusChangedNative(mNativeHandle, hasFocus); |
| 263 | } |
Dianne Hackborn | 69969e4 | 2010-05-04 11:40:40 -0700 | [diff] [blame] | 264 | } |
Dianne Hackborn | 74323fd | 2010-05-18 17:56:23 -0700 | [diff] [blame] | 265 | |
| 266 | public void surfaceCreated(SurfaceHolder holder) { |
Dianne Hackborn | 3c80a4a | 2010-06-29 19:20:40 -0700 | [diff] [blame] | 267 | if (!mDestroyed) { |
| 268 | mCurSurfaceHolder = holder; |
Dianne Hackborn | 54a181b | 2010-06-30 18:35:14 -0700 | [diff] [blame] | 269 | onSurfaceCreatedNative(mNativeHandle, holder.getSurface()); |
Dianne Hackborn | 3c80a4a | 2010-06-29 19:20:40 -0700 | [diff] [blame] | 270 | } |
Dianne Hackborn | 74323fd | 2010-05-18 17:56:23 -0700 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { |
Dianne Hackborn | 3c80a4a | 2010-06-29 19:20:40 -0700 | [diff] [blame] | 274 | if (!mDestroyed) { |
| 275 | mCurSurfaceHolder = holder; |
Dianne Hackborn | 54a181b | 2010-06-30 18:35:14 -0700 | [diff] [blame] | 276 | onSurfaceChangedNative(mNativeHandle, holder.getSurface(), format, width, height); |
Dianne Hackborn | 3c80a4a | 2010-06-29 19:20:40 -0700 | [diff] [blame] | 277 | } |
Dianne Hackborn | 74323fd | 2010-05-18 17:56:23 -0700 | [diff] [blame] | 278 | } |
| 279 | |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 280 | public void surfaceRedrawNeeded(SurfaceHolder holder) { |
| 281 | if (!mDestroyed) { |
| 282 | mCurSurfaceHolder = holder; |
| 283 | onSurfaceRedrawNeededNative(mNativeHandle, holder.getSurface()); |
| 284 | } |
| 285 | } |
| 286 | |
Dianne Hackborn | 74323fd | 2010-05-18 17:56:23 -0700 | [diff] [blame] | 287 | public void surfaceDestroyed(SurfaceHolder holder) { |
Dianne Hackborn | 3c80a4a | 2010-06-29 19:20:40 -0700 | [diff] [blame] | 288 | mCurSurfaceHolder = null; |
| 289 | if (!mDestroyed) { |
Dianne Hackborn | 54a181b | 2010-06-30 18:35:14 -0700 | [diff] [blame] | 290 | onSurfaceDestroyedNative(mNativeHandle); |
Dianne Hackborn | 3c80a4a | 2010-06-29 19:20:40 -0700 | [diff] [blame] | 291 | } |
Dianne Hackborn | 74323fd | 2010-05-18 17:56:23 -0700 | [diff] [blame] | 292 | } |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 293 | |
Dianne Hackborn | 1e4b9f3 | 2010-06-23 14:10:57 -0700 | [diff] [blame] | 294 | public void onInputQueueCreated(InputQueue queue) { |
Dianne Hackborn | 3c80a4a | 2010-06-29 19:20:40 -0700 | [diff] [blame] | 295 | if (!mDestroyed) { |
| 296 | mCurInputQueue = queue; |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 297 | onInputQueueCreatedNative(mNativeHandle, queue.getNativePtr()); |
Dianne Hackborn | 3c80a4a | 2010-06-29 19:20:40 -0700 | [diff] [blame] | 298 | } |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 299 | } |
| 300 | |
Dianne Hackborn | 1e4b9f3 | 2010-06-23 14:10:57 -0700 | [diff] [blame] | 301 | public void onInputQueueDestroyed(InputQueue queue) { |
Dianne Hackborn | 3c80a4a | 2010-06-29 19:20:40 -0700 | [diff] [blame] | 302 | if (!mDestroyed) { |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 303 | onInputQueueDestroyedNative(mNativeHandle, queue.getNativePtr()); |
| 304 | mCurInputQueue = null; |
Dianne Hackborn | 3c80a4a | 2010-06-29 19:20:40 -0700 | [diff] [blame] | 305 | } |
| 306 | } |
| 307 | |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 308 | public void onGlobalLayout() { |
| 309 | mNativeContentView.getLocationInWindow(mLocation); |
| 310 | int w = mNativeContentView.getWidth(); |
| 311 | int h = mNativeContentView.getHeight(); |
| 312 | if (mLocation[0] != mLastContentX || mLocation[1] != mLastContentY |
| 313 | || w != mLastContentWidth || h != mLastContentHeight) { |
| 314 | mLastContentX = mLocation[0]; |
| 315 | mLastContentY = mLocation[1]; |
| 316 | mLastContentWidth = w; |
| 317 | mLastContentHeight = h; |
| 318 | if (!mDestroyed) { |
| 319 | onContentRectChangedNative(mNativeHandle, mLastContentX, |
| 320 | mLastContentY, mLastContentWidth, mLastContentHeight); |
| 321 | } |
| 322 | } |
| 323 | } |
| 324 | |
Dianne Hackborn | 54a181b | 2010-06-30 18:35:14 -0700 | [diff] [blame] | 325 | void setWindowFlags(int flags, int mask) { |
| 326 | getWindow().setFlags(flags, mask); |
| 327 | } |
| 328 | |
| 329 | void setWindowFormat(int format) { |
| 330 | getWindow().setFormat(format); |
| 331 | } |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 332 | |
| 333 | void showIme(int mode) { |
| 334 | mIMM.showSoftInput(mNativeContentView, mode); |
| 335 | } |
| 336 | |
| 337 | void hideIme(int mode) { |
| 338 | mIMM.hideSoftInputFromWindow(mNativeContentView.getWindowToken(), mode); |
| 339 | } |
Dianne Hackborn | 69969e4 | 2010-05-04 11:40:40 -0700 | [diff] [blame] | 340 | } |