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