Update native-activity sample to get the direct surface.

Change-Id: Idb55ef8f6130d33cf9c68f6f9b0e5317f1735c0b
diff --git a/apps/native-activity/Application.mk b/apps/native-activity/Application.mk
deleted file mode 100644
index e53e442..0000000
--- a/apps/native-activity/Application.mk
+++ /dev/null
@@ -1,5 +0,0 @@
-APP_PROJECT_PATH := $(call my-dir)/project
-APP_MODULES      := native-activity
-
-# Temporary for development until API 9 ships.
-APP_PLATFORM     := android-9
\ No newline at end of file
diff --git a/build/platforms/android-9/arch-arm/usr/include/android/native_activity.h b/build/platforms/android-9/arch-arm/usr/include/android/native_activity.h
index 7f9d523..328a4b5 100644
--- a/build/platforms/android-9/arch-arm/usr/include/android/native_activity.h
+++ b/build/platforms/android-9/arch-arm/usr/include/android/native_activity.h
@@ -27,39 +27,147 @@
 extern "C" {
 #endif
 
+// Temporary until native surface API is defined.
+struct android_surface_t;
+typedef struct android_surface_t android_surface_t;
+
 struct android_activity_callbacks_t;
 
+/**
+ * This structure defines the native side of an android.app.NativeActivity.
+ * It is created by the framework, and handed to the application's native
+ * code as it is being launched.
+ */
 typedef struct android_activity_t {
+    /**
+     * Pointer to the callback function table of the native application.
+     * You can set the functions here to your own callbacks.  The callbacks
+     * pointer itself here should not be changed; it is allocated and managed
+     * for you by the framework.
+     */
     struct android_activity_callbacks_t* callbacks;
-    
+
+    /**
+     * JNI context for the main thread of the app.
+     */
     JNIEnv* env;
-    jobject clazz;
     
+    /**
+     * The NativeActivity Java class.
+     */
+    jobject clazz;
+
+    /**
+     * This is the native instance of the application.  It is not used by
+     * the framework, but can be set by the application to its own instance
+     * state.
+     */
     void* instance;
 } android_activity_t;
 
+/**
+ * These are the callbacks the framework makes into a native application.
+ * All of these callbacks happen on the main thread of the application.
+ * By default, all callbacks are NULL; set to a pointer to your own function
+ * to have it called.
+ */
 typedef struct android_activity_callbacks_t {
+    /**
+     * NativeActivity has started.  See Java documentation for Activity.onStart()
+     * for more information.
+     */
     void (*onStart)(android_activity_t* activity);
-    void (*onResume)(android_activity_t* activity);
-    void* (*onSaveInstanceState)(android_activity_t* activity, size_t* outSize);
-    void (*onPause)(android_activity_t* activity);
-    void (*onStop)(android_activity_t* activity);
-    void (*onDestroy)(android_activity_t* activity);
     
-    void (*onLowMemory)(android_activity_t* activity);
+    /**
+     * NativeActivity has resumed.  See Java documentation for Activity.onResume()
+     * for more information.
+     */
+    void (*onResume)(android_activity_t* activity);
+    
+    /**
+     * Framework is asking NativeActivity to save its current instance state.
+     * See Java documentation for Activity.onSaveInstanceState() for more
+     * information.  The returned pointer needs to be created with malloc();
+     * the framework will call free() on it for you.  You also must fill in
+     * outSize with the number of bytes in the allocation.  Note that the
+     * saved state will be persisted, so it can not contain any active
+     * entities (pointers to memory, file descriptors, etc).
+     */
+    void* (*onSaveInstanceState)(android_activity_t* activity, size_t* outSize);
+    
+    /**
+     * NativeActivity has paused.  See Java documentation for Activity.onPause()
+     * for more information.
+     */
+    void (*onPause)(android_activity_t* activity);
+    
+    /**
+     * NativeActivity has stopped.  See Java documentation for Activity.onStop()
+     * for more information.
+     */
+    void (*onStop)(android_activity_t* activity);
+    
+    /**
+     * NativeActivity is being destroyed.  See Java documentation for Activity.onDestroy()
+     * for more information.
+     */
+    void (*onDestroy)(android_activity_t* activity);
+
+    /**
+     * Focus has changed in this NativeActivity's window.  This is often used,
+     * for example, to pause a game when it loses input focus.
+     */
     void (*onWindowFocusChanged)(android_activity_t* activity, int hasFocus);
+    
+    /**
+     * The drawing surface for this native activity has been created.  You
+     * can use the given surface object to start drawing.  NOTE: surface
+     * drawing API is not yet defined.
+     */
+    void (*onSurfaceCreated)(android_activity_t* activity, android_surface_t* surface);
+
+    /**
+     * The drawing surface for this native activity has changed.  The surface
+     * given here is guaranteed to be the same as the one last given to
+     * onSurfaceCreated.  This is simply to inform you about interesting
+     * changed to that surface.
+     */
+    void (*onSurfaceChanged)(android_activity_t* activity, android_surface_t* surface,
+            int format, int width, int height);
+
+    /**
+     * The drawing surface for this native activity is going to be destroyed.
+     * You MUST ensure that you do not touch the surface object after returning
+     * from this function: in the common case of drawing to the surface from
+     * another thread, that means the implementation of this callback must
+     * properly synchronize with the other thread to stop its drawing before
+     * returning from here.
+     */
+    void (*onSurfaceDestroyed)(android_activity_t* activity, android_surface_t* surface);
+
+    /**
+     * The system is running low on memory.  Use this callback to release
+     * resources you do not need, to help the system avoid killing more
+     * important processes.
+     */
+    void (*onLowMemory)(android_activity_t* activity);
 } android_activity_callbacks_t;
 
+/**
+ * This is the function that must be in the native code to instantiate the
+ * application's native activity.  It is called with the activity instance (see
+ * above); if the code is being instantiated from a previously saved instance,
+ * the savedState will be non-NULL and point to the saved data.
+ */
 typedef void android_activity_create_t(android_activity_t* activity,
         void* savedState, size_t savedStateSize);
 
+/**
+ * The name of the function that NativeInstance looks for when launching its
+ * native code.
+ */
 extern android_activity_create_t android_onCreateActivity;
 
-#if 0
-extern android_onCreateActivity(android_activity_t activity,
-        void* savedState, size_t savedStateSize);
-#endif
-
 #ifdef __cplusplus
 };
 #endif
diff --git a/apps/native-activity/project/AndroidManifest.xml b/samples/native-activity/AndroidManifest.xml
similarity index 100%
rename from apps/native-activity/project/AndroidManifest.xml
rename to samples/native-activity/AndroidManifest.xml
diff --git a/apps/native-activity/project/default.properties b/samples/native-activity/default.properties
similarity index 100%
rename from apps/native-activity/project/default.properties
rename to samples/native-activity/default.properties
diff --git a/apps/native-activity/project/jni/Android.mk b/samples/native-activity/jni/Android.mk
similarity index 100%
rename from apps/native-activity/project/jni/Android.mk
rename to samples/native-activity/jni/Android.mk
diff --git a/samples/native-activity/jni/Application.mk b/samples/native-activity/jni/Application.mk
new file mode 100644
index 0000000..22d188e
--- /dev/null
+++ b/samples/native-activity/jni/Application.mk
@@ -0,0 +1 @@
+APP_PLATFORM := android-9
diff --git a/apps/native-activity/project/jni/main.c b/samples/native-activity/jni/main.c
similarity index 74%
rename from apps/native-activity/project/jni/main.c
rename to samples/native-activity/jni/main.c
index 1cbec1f..fada1d6 100644
--- a/apps/native-activity/project/jni/main.c
+++ b/samples/native-activity/jni/main.c
@@ -64,6 +64,23 @@
     LOGI("WindowFocusChanged: %p -- %d\n", activity, focused);
 }
 
+static void onSurfaceCreated(android_activity_t* activity, android_surface_t* surface)
+{
+    LOGI("SurfaceCreated: %p -- %p\n", activity, surface);
+}
+
+static void onSurfaceChanged(android_activity_t* activity, android_surface_t* surface,
+        int format, int width, int height)
+{
+    LOGI("SurfaceChanged: %p -- %p fmt=%d w=%d h=%d\n", activity, surface,
+            format, width, height);
+}
+
+static void onSurfaceDestroyed(android_activity_t* activity, android_surface_t* surface)
+{
+    LOGI("SurfaceDestroyed: %p -- %p\n", activity, surface);
+}
+
 void android_onCreateActivity(android_activity_t* activity,
         void* savedState, size_t savedStateSize)
 {
@@ -76,4 +93,7 @@
     activity->callbacks->onStop = onStop;
     activity->callbacks->onLowMemory = onLowMemory;
     activity->callbacks->onWindowFocusChanged = onWindowFocusChanged;
+    activity->callbacks->onSurfaceCreated = onSurfaceCreated;
+    activity->callbacks->onSurfaceChanged = onSurfaceChanged;
+    activity->callbacks->onSurfaceDestroyed = onSurfaceDestroyed;
 }
diff --git a/apps/native-activity/project/res/values/strings.xml b/samples/native-activity/res/values/strings.xml
similarity index 100%
rename from apps/native-activity/project/res/values/strings.xml
rename to samples/native-activity/res/values/strings.xml
diff --git a/apps/native-activity/project/src/Barf.java b/samples/native-activity/src/Barf.java
similarity index 100%
rename from apps/native-activity/project/src/Barf.java
rename to samples/native-activity/src/Barf.java