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