Removing obsolete Android stuff

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12693 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Matthias Melcher 2018-03-02 16:07:23 +00:00
parent 5c2d98a5fc
commit f01eb0ec25
11 changed files with 0 additions and 1003 deletions

View File

@ -1,30 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- BEGIN_INCLUDE(manifest) -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.native_activity"
android:versionCode="1"
android:versionName="1.0">
<!-- This is the platform API where NativeActivity was introduced. -->
<uses-sdk android:minSdkVersion="9" />
<!-- This .apk has no Java code itself, so set hasCode to false. -->
<application android:label="@string/app_name" android:hasCode="false">
<!-- Our activity is the built-in NativeActivity framework class.
This will take care of integrating with our NDK code. -->
<activity android:name="android.app.NativeActivity"
android:label="@string/app_name"
android:configChanges="orientation|keyboardHidden">
<!-- Tell NativeActivity the name of or .so -->
<meta-data android:name="android.app.lib_name"
android:value="native-activity" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
<!-- END_INCLUDE(manifest) -->

View File

@ -1,31 +0,0 @@
/*
* "$Id$"
*
* Configuration file for the Fast Light Tool Kit (FLTK).
*
* Copyright 1998-2015 by Bill Spitzak and others.
*
* This library is free software. Distribution and use rights are outlined in
* the file "COPYING" which should have been included with this file. If this
* file is missing or damaged, see the license at:
*
* http://www.fltk.org/COPYING.php
*
* Please report all bugs and problems on the following page:
*
* http://www.fltk.org/str.php
*/
/*
============================================================================
DO NOT EDIT - This file is generated by CMake !
============================================================================
*/
/* define FL_ABI_VERSION as 10x0y for FLTK ABI version 1.x.y */
/* #undef FL_ABI_VERSION */
/*
* End of "$Id$".
*/

View File

@ -1,25 +0,0 @@
here's the general process for building and installing an Android application which uses the NDK.
1. cd to the root of its source code.
2. Run ndk-build. This builds the native code, and should result in some .so files being put into the libs directory.
3. android update project --path . --name something
4. ant debug (or similar). This will build the Java code and create an .apk. Crucially, the build process will pick up the .so files left within the libs directory and include them into the .apk.
5. adb install bin/name-of-project.apk
6. Then launch as normal using the Android GUI or using an am start command such as you give.
6a. emulator -avd Intel_x86
7. adb shell am start -n com.example.native_activity
- or -
adb shell am start com.example.native_activity/android.app.NativeActivity
8. adb uninstall com.example.native_activity
- Matt

View File

@ -1,5 +0,0 @@
PATH=$(dirname $(which android))/../build-tools/21.1.1:$PATH
pkg=$(aapt dump badging $1|awk -F" " '/package/ {print $2}'|awk -F"'" '/name=/ {print $2}')
act=$(aapt dump badging $1|awk -F" " '/launchable-activity/ {print $2}'|awk -F"'" '/name=/ {print $2}')
adb shell am start -n $pkg/$act

View File

@ -1,371 +0,0 @@
/* config.h. Generated from configh.cmake.in by CMake. */
/*
* "$Id$"
*
* Configuration file for the Fast Light Tool Kit (FLTK).
*
* Copyright 1998-2016 by Bill Spitzak and others.
*
* This library is free software. Distribution and use rights are outlined in
* the file "COPYING" which should have been included with this file. If this
* file is missing or damaged, see the license at:
*
* http://www.fltk.org/COPYING.php
*
* Please report all bugs and problems on the following page:
*
* http://www.fltk.org/str.php
*/
/*
* Where to find files...
*/
#define FLTK_DATADIR "/usr/local/share/fltk"
#define FLTK_DOCDIR "/usr/local/share/doc/fltk"
/*
* BORDER_WIDTH:
*
* Thickness of FL_UP_BOX and FL_DOWN_BOX. Current 1,2, and 3 are
* supported.
*
* 3 is the historic FLTK look.
* 2 is the default and looks like Microsoft Windows, KDE, and Qt.
* 1 is a plausible future evolution...
*
* Note that this may be simulated at runtime by redefining the boxtypes
* using Fl::set_boxtype().
*/
#define BORDER_WIDTH 2
/*
* HAVE_GL:
*
* Do you have OpenGL? Set this to 0 if you don't have or plan to use
* OpenGL, and FLTK will be smaller.
*/
#undef HAVE_GL
/*
* HAVE_GL_GLU_H:
*
* Do you have the OpenGL Utility Library header file?
* (many broken Mesa RPMs do not...)
*/
#undef HAVE_GL_GLU_H
/*
* HAVE_GLXGETPROCADDRESSARB:
*
* Do you have the OpenGL glXGetProcAddressARB() function?
*/
/* #undef HAVE_GLXGETPROCADDRESSARB */
/*
* USE_COLORMAP:
*
* Setting this to zero will save a good deal of code (especially for
* fl_draw_image), but FLTK will only work on TrueColor visuals.
*/
#define USE_COLORMAP 1
/*
* HAVE_XINERAMA
*
* Do we have the Xinerama library to support multi-head displays?
*/
#define HAVE_XINERAMA 0
/*
* USE_XFT
*
* Use the new Xft library to draw anti-aliased text.
*/
#define USE_XFT 0
/*
* HAVE_XDBE:
*
* Do we have the X double-buffer extension?
*/
#define HAVE_XDBE 0
/*
* USE_XDBE:
*
* Actually try to use the double-buffer extension?
*/
#define USE_XDBE HAVE_XDBE
/*
* HAVE_XFIXES:
*
* Do we have the X fixes extension?
*/
#define HAVE_XFIXES 0
/*
* HAVE_XCURSOR:
*
* Do we have the X cursor library?
*/
#define HAVE_XCURSOR 0
/*
* HAVE_XRENDER:
*
* Do we have the X render library?
*/
#define HAVE_XRENDER 0
/*
* HAVE_X11_XREGION_H:
*
* Do we have the X11 Xregion.h header file ?
*/
#define HAVE_X11_XREGION_H 1
/*
* __APPLE_QUARTZ__:
*
* All Apple implementations are now based on Quartz and Cocoa,
* so this flag should always be on for Mac OS X. This flag has
* no meaning on operating systems other than Mac OS X.
*/
/* #undef __APPLE_QUARTZ__ */
/*
* USE_X11
*
* Should we use X11 for the current platform
*
*/
/* #undef USE_X11 */
/*
* USE_SDL
*
* Should we use SDL for the current platform
*
*/
//#define USE_SDL 1
/*
* FL_PORTING
*
* A little helper that points to locations in the core that still need to be ported to
* the core driver setup.
*/
#define FL_PORTING 1
/*
* HAVE_OVERLAY:
*
* Use the X overlay extension? FLTK will try to use an overlay
* visual for Fl_Overlay_Window, the Gl_Window overlay, and for the
* menus. Setting this to zero will remove a substantial amount of
* code from FLTK. Overlays have only been tested on SGI servers!
*/
#define HAVE_OVERLAY 0
/*
* HAVE_GL_OVERLAY:
*
* It is possible your GL has an overlay even if X does not. If so,
* set this to 1.
*/
#define HAVE_GL_OVERLAY HAVE_OVERLAY
/*
* WORDS_BIGENDIAN:
*
* Byte order of your machine: 1 = big-endian, 0 = little-endian.
*/
#ifdef __APPLE__
#include <mac_endianness.h>
#else
#define WORDS_BIGENDIAN 0
#endif
/*
* U16, U32, U64:
*
* Types used by fl_draw_image. One of U32 or U64 must be defined.
* U16 is optional but FLTK will work better with it!
*/
#define U16 unsigned short
#define U32 unsigned
#define U64 unsigned long
/*
* HAVE_DIRENT_H, HAVE_SYS_NDIR_H, HAVE_SYS_DIR_H, HAVE_NDIR_H,
* HAVE_SCANDIR, HAVE_SCANDIR_POSIX:
*
* Where is <dirent.h> (used only by fl_file_chooser and scandir).
*/
#define HAVE_DIRENT_H 1
/* #undef HAVE_SYS_NDIR_H */
/* #undef HAVE_SYS_DIR_H */
/* #undef HAVE_NDIR_H */
#define HAVE_SCANDIR 1
#define HAVE_SCANDIR_POSIX 1
/*
* Possibly missing sprintf-style functions:
*/
#define HAVE_VSNPRINTF 1
#define HAVE_SNPRINTF 1
/*
* String functions and headers...
*/
#define HAVE_STRINGS_H 1
#define HAVE_STRCASECMP 1
#define HAVE_STRLCAT 1
#define HAVE_STRLCPY 1
/*
* Do we have POSIX locale support?
*/
//#undef HAVE_LOCALE_H
//#undef HAVE_LOCALECONV
/*
* HAVE_SYS_SELECT_H:
*
* Whether or not select() call has its own header file.
*/
#define HAVE_SYS_SELECT_H 1
/*
* HAVE_SYS_STDTYPES_H:
*
* Whether or not we have the <sys/stdtypes.h> header file.
*/
/* #undef HAVE_SYS_STDTYPES_H */
/*
* USE_POLL:
*
* Use the poll() call provided on Linux and Irix instead of select()
*/
#define USE_POLL 0
/*
* Do we have various image libraries?
*/
#define HAVE_LIBPNG 1
#define HAVE_LIBZ 1
#define HAVE_LIBJPEG 1
/*
* FLTK_USE_CAIRO
*
* Do we have the cairo library available and want extended cairo use in FLTK ?
* This implies to link cairo.lib in all FLTK based apps.
*/
/* #undef FLTK_USE_CAIRO */
/*
* FLTK_HAVE_CAIRO
*
* Do we have the cairo library available?
*/
/* #undef FLTK_HAVE_CAIRO */
/*
* Which header file do we include for libpng?
*/
#define HAVE_PNG_H 1
/* #undef HAVE_LIBPNG_PNG_H */
/*
* Do we have the png_xyz() functions?
*/
#define HAVE_PNG_GET_VALID 1
#define HAVE_PNG_SET_TRNS_TO_ALPHA 1
/*
* Do we have POSIX threading?
*/
#define HAVE_PTHREAD 1
#define HAVE_PTHREAD_H 1
/*
* Do we have the ALSA library?
*/
/* #undef HAVE_ALSA_ASOUNDLIB_H */
/*
* Do we have the long long type?
*/
#define HAVE_LONG_LONG 1
#ifdef HAVE_LONG_LONG
# define FLTK_LLFMT "%lld"
# define FLTK_LLCAST (long long)
#else
# define FLTK_LLFMT "%ld"
# define FLTK_LLCAST (long)
#endif /* HAVE_LONG_LONG */
/*
* Do we have the dlsym() function and header?
*/
#define HAVE_DLFCN_H 1
#define HAVE_DLSYM 1
/*
* Do we want print support?
*/
/* #undef NO_PRINT_SUPPORT */
/*
* Do we want filename handling and a filechooser?
*/
/* #undef FL_CFG_NO_FILESYSTEM_SUPPORT */
/*
* End of "$Id$".
*/

View File

@ -1,11 +0,0 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# "build.properties", and override values to adapt the script to your
# project structure.
# Project target.
target=android-10

View File

@ -1,208 +0,0 @@
# Copyright (C) 2010 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
TOP_PATH := $(call my-dir)/../..
#################
## FLTK library
include $(CLEAR_VARS)
LOCAL_PATH += $(TOP_PATH)/Android
LOCAL_PATH += $(TOP_PATH)
LOCAL_MODULE := native-activity
LOCAL_C_INCLUDES := $(TOP_PATH)
LOCAL_SRC_FILES := \
test/unittests.cxx \
src/flstring.c \
src/scandir.c \
src/numericsort.c \
src/vsnprintf.c \
src/xutf8/is_right2left.c \
src/xutf8/is_spacing.c \
src/xutf8/case.c \
src/xutf8/utf8Input.c \
src/xutf8/utf8Utils.c \
src/xutf8/utf8Wrap.c \
src/xutf8/keysym2Ucs.c \
src/fl_utf.c \
src/Fl.cxx \
src/Fl_Adjuster.cxx \
src/Fl_Bitmap.cxx \
src/Fl_Browser.cxx \
src/Fl_Browser_.cxx \
src/Fl_Browser_load.cxx \
src/Fl_Box.cxx \
src/Fl_Button.cxx \
src/Fl_Chart.cxx \
src/Fl_Check_Browser.cxx \
src/Fl_Check_Button.cxx \
src/Fl_Choice.cxx \
src/Fl_Clock.cxx \
src/Fl_Color_Chooser.cxx \
src/Fl_Copy_Surface.cxx \
src/Fl_Counter.cxx \
src/Fl_Device.cxx \
src/Fl_Dial.cxx \
src/Fl_Help_Dialog_Dox.cxx \
src/Fl_Double_Window.cxx \
src/Fl_File_Browser.cxx \
src/Fl_File_Chooser.cxx \
src/Fl_File_Chooser2.cxx \
src/Fl_File_Icon.cxx \
src/Fl_File_Input.cxx \
src/Fl_Graphics_Driver.cxx \
src/Fl_Group.cxx \
src/Fl_Help_View.cxx \
src/Fl_Image.cxx \
src/Fl_Image_Surface.cxx \
src/Fl_Input.cxx \
src/Fl_Input_.cxx \
src/Fl_Light_Button.cxx \
src/Fl_Menu.cxx \
src/Fl_Menu_.cxx \
src/Fl_Menu_Bar.cxx \
src/Fl_Menu_Button.cxx \
src/Fl_Menu_Window.cxx \
src/Fl_Menu_add.cxx \
src/Fl_Menu_global.cxx \
src/Fl_Multi_Label.cxx \
src/Fl_Native_File_Chooser.cxx \
src/Fl_Overlay_Window.cxx \
src/Fl_Pack.cxx \
src/Fl_Paged_Device.cxx \
src/Fl_Pixmap.cxx \
src/Fl_Positioner.cxx \
src/Fl_Preferences.cxx \
src/Fl_Printer.cxx \
src/Fl_Progress.cxx \
src/Fl_Repeat_Button.cxx \
src/Fl_Return_Button.cxx \
src/Fl_Roller.cxx \
src/Fl_Round_Button.cxx \
src/Fl_Screen_Driver.cxx \
src/Fl_Scroll.cxx \
src/Fl_Scrollbar.cxx \
src/Fl_Shared_Image.cxx \
src/Fl_Single_Window.cxx \
src/Fl_Slider.cxx \
src/Fl_Table.cxx \
src/Fl_Table_Row.cxx \
src/Fl_Tabs.cxx \
src/Fl_Text_Buffer.cxx \
src/Fl_Text_Display.cxx \
src/Fl_Text_Editor.cxx \
src/Fl_Tile.cxx \
src/Fl_Tiled_Image.cxx \
src/Fl_Tooltip.cxx \
src/Fl_Tree.cxx \
src/Fl_Tree_Item_Array.cxx \
src/Fl_Tree_Item.cxx \
src/Fl_Tree_Prefs.cxx \
src/Fl_Valuator.cxx \
src/Fl_Value_Input.cxx \
src/Fl_Value_Output.cxx \
src/Fl_Value_Slider.cxx \
src/Fl_Widget.cxx \
src/Fl_Widget_Surface.cxx \
src/Fl_Window.cxx \
src/Fl_Window_Driver.cxx \
src/Fl_Window_fullscreen.cxx \
src/Fl_Window_hotspot.cxx \
src/Fl_Window_iconize.cxx \
src/Fl_Wizard.cxx \
src/Fl_XBM_Image.cxx \
src/Fl_XPM_Image.cxx \
src/Fl_abort.cxx \
src/Fl_add_idle.cxx \
src/Fl_arg.cxx \
src/Fl_compose.cxx \
src/Fl_display.cxx \
src/Fl_get_key.cxx \
src/Fl_get_system_colors.cxx \
src/Fl_grab.cxx \
src/Fl_lock.cxx \
src/Fl_own_colormap.cxx \
src/Fl_visual.cxx \
src/filename_absolute.cxx \
src/filename_expand.cxx \
src/filename_ext.cxx \
src/filename_isdir.cxx \
src/filename_list.cxx \
src/filename_match.cxx \
src/filename_setext.cxx \
src/fl_arc.cxx \
src/fl_ask.cxx \
src/fl_boxtype.cxx \
src/fl_color.cxx \
src/fl_cursor.cxx \
src/fl_curve.cxx \
src/fl_diamond_box.cxx \
src/fl_dnd.cxx \
src/fl_draw.cxx \
src/fl_draw_pixmap.cxx \
src/fl_engraved_label.cxx \
src/fl_file_dir.cxx \
src/fl_font.cxx \
src/fl_gleam.cxx \
src/fl_gtk.cxx \
src/fl_labeltype.cxx \
src/fl_line_style.cxx \
src/fl_open_uri.cxx \
src/fl_oval_box.cxx \
src/fl_overlay.cxx \
src/fl_overlay_visual.cxx \
src/fl_plastic.cxx \
src/fl_read_image.cxx \
src/fl_rect.cxx \
src/fl_round_box.cxx \
src/fl_rounded_box.cxx \
src/fl_set_font.cxx \
src/fl_scroll_area.cxx \
src/fl_shadow_box.cxx \
src/fl_shortcut.cxx \
src/fl_show_colormap.cxx \
src/fl_symbols.cxx \
src/fl_vertex.cxx \
src/screen_xywh.cxx \
src/fl_utf8.cxx \
src/fl_encoding_latin1.cxx \
src/fl_encoding_mac_roman.cxx \
src/drivers/Pico/Fl_Pico_System_Driver.cxx \
src/drivers/Pico/Fl_Pico_Screen_Driver.cxx \
src/drivers/Pico/Fl_Pico_Window_Driver.cxx \
src/drivers/Pico/Fl_Pico_Graphics_Driver.cxx \
src/drivers/Pico/Fl_Pico_Copy_Surface.cxx \
src/drivers/Pico/Fl_Pico_Image_Surface.cxx \
src/drivers/PicoAndroid/Fl_PicoAndroid_System_Driver.cxx \
src/drivers/PicoAndroid/Fl_PicoAndroid_Screen_Driver.cxx \
src/drivers/PicoAndroid/Fl_PicoAndroid_Window_Driver.cxx \
src/drivers/PicoAndroid/Fl_PicoAndroid_Graphics_Driver.cxx \
src/drivers/PicoAndroid/Fl_PicoAndroid_Copy_Surface.cxx \
src/drivers/PicoAndroid/Fl_PicoAndroid_Image_Surface.cxx
#Android/jni/main.c
LOCAL_CFLAGS := -DFL_PORTING -DANDROID -DFL_PICO_ANDROID -DFL_LIBRARY
LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv1_CM
LOCAL_STATIC_LIBRARIES := android_native_app_glue
include $(BUILD_SHARED_LIBRARY)
$(call import-module,android/native_app_glue)

View File

@ -1,4 +0,0 @@
#APP_ABI := armeabi armeabi-v7a mips x64
#APP_ABI := all
APP_ABI := armeabi-v7a
APP_PLATFORM := android-10

View File

@ -1,307 +0,0 @@
/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
//BEGIN_INCLUDE(all)
#include <jni.h>
#include <errno.h>
#include <EGL/egl.h>
#include <GLES/gl.h>
#include <android/sensor.h>
#include <android/log.h>
#include <android_native_app_glue.h>
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "native-activity", __VA_ARGS__))
#define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, "native-activity", __VA_ARGS__))
/**
* Our saved state data.
*/
struct saved_state {
float angle;
int32_t x;
int32_t y;
};
/**
* Shared state for our app.
*/
struct engine {
struct android_app* app;
ASensorManager* sensorManager;
const ASensor* accelerometerSensor;
ASensorEventQueue* sensorEventQueue;
int animating;
EGLDisplay display;
EGLSurface surface;
EGLContext context;
int32_t width;
int32_t height;
struct saved_state state;
};
/**
* Initialize an EGL context for the current display.
*/
static int engine_init_display(struct engine* engine) {
// initialize OpenGL ES and EGL
/*
* Here specify the attributes of the desired configuration.
* Below, we select an EGLConfig with at least 8 bits per color
* component compatible with on-screen windows
*/
const EGLint attribs[] = {
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_BLUE_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_RED_SIZE, 8,
EGL_NONE
};
EGLint w, h, dummy, format;
EGLint numConfigs;
EGLConfig config;
EGLSurface surface;
EGLContext context;
EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
eglInitialize(display, 0, 0);
/* Here, the application chooses the configuration it desires. In this
* sample, we have a very simplified selection process, where we pick
* the first EGLConfig that matches our criteria */
eglChooseConfig(display, attribs, &config, 1, &numConfigs);
/* EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is
* guaranteed to be accepted by ANativeWindow_setBuffersGeometry().
* As soon as we picked a EGLConfig, we can safely reconfigure the
* ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID. */
eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);
ANativeWindow_setBuffersGeometry(engine->app->window, 0, 0, format);
surface = eglCreateWindowSurface(display, config, engine->app->window, NULL);
context = eglCreateContext(display, config, NULL, NULL);
if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) {
LOGW("Unable to eglMakeCurrent");
return -1;
}
eglQuerySurface(display, surface, EGL_WIDTH, &w);
eglQuerySurface(display, surface, EGL_HEIGHT, &h);
engine->display = display;
engine->context = context;
engine->surface = surface;
engine->width = w;
engine->height = h;
engine->state.angle = 0;
// Initialize GL state.
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
glEnable(GL_CULL_FACE);
glShadeModel(GL_SMOOTH);
glDisable(GL_DEPTH_TEST);
return 0;
}
/**
* Just the current frame in the display.
*/
static void engine_draw_frame(struct engine* engine) {
if (engine->display == NULL) {
// No display.
return;
}
// Just fill the screen with a color.
glClearColor(((float)engine->state.x)/engine->width, engine->state.angle,
((float)engine->state.y)/engine->height, 1);
glClear(GL_COLOR_BUFFER_BIT);
eglSwapBuffers(engine->display, engine->surface);
}
/**
* Tear down the EGL context currently associated with the display.
*/
static void engine_term_display(struct engine* engine) {
if (engine->display != EGL_NO_DISPLAY) {
eglMakeCurrent(engine->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
if (engine->context != EGL_NO_CONTEXT) {
eglDestroyContext(engine->display, engine->context);
}
if (engine->surface != EGL_NO_SURFACE) {
eglDestroySurface(engine->display, engine->surface);
}
eglTerminate(engine->display);
}
engine->animating = 0;
engine->display = EGL_NO_DISPLAY;
engine->context = EGL_NO_CONTEXT;
engine->surface = EGL_NO_SURFACE;
}
/**
* Process the next input event.
*/
static int32_t engine_handle_input(struct android_app* app, AInputEvent* event) {
struct engine* engine = (struct engine*)app->userData;
if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION) {
engine->animating = 1;
engine->state.x = AMotionEvent_getX(event, 0);
engine->state.y = AMotionEvent_getY(event, 0);
return 1;
}
return 0;
}
/**
* Process the next main command.
*/
static void engine_handle_cmd(struct android_app* app, int32_t cmd) {
struct engine* engine = (struct engine*)app->userData;
switch (cmd) {
case APP_CMD_SAVE_STATE:
// The system has asked us to save our current state. Do so.
engine->app->savedState = malloc(sizeof(struct saved_state));
*((struct saved_state*)engine->app->savedState) = engine->state;
engine->app->savedStateSize = sizeof(struct saved_state);
break;
case APP_CMD_INIT_WINDOW:
// The window is being shown, get it ready.
if (engine->app->window != NULL) {
engine_init_display(engine);
engine_draw_frame(engine);
}
break;
case APP_CMD_TERM_WINDOW:
// The window is being hidden or closed, clean it up.
engine_term_display(engine);
break;
case APP_CMD_GAINED_FOCUS:
// When our app gains focus, we start monitoring the accelerometer.
if (engine->accelerometerSensor != NULL) {
ASensorEventQueue_enableSensor(engine->sensorEventQueue,
engine->accelerometerSensor);
// We'd like to get 60 events per second (in us).
ASensorEventQueue_setEventRate(engine->sensorEventQueue,
engine->accelerometerSensor, (1000L/60)*1000);
}
break;
case APP_CMD_LOST_FOCUS:
// When our app loses focus, we stop monitoring the accelerometer.
// This is to avoid consuming battery while not being used.
if (engine->accelerometerSensor != NULL) {
ASensorEventQueue_disableSensor(engine->sensorEventQueue,
engine->accelerometerSensor);
}
// Also stop animating.
engine->animating = 0;
engine_draw_frame(engine);
break;
}
}
/**
* This is the main entry point of a native application that is using
* android_native_app_glue. It runs in its own thread, with its own
* event loop for receiving input events and doing other things.
*/
void android_main(struct android_app* state) {
struct engine engine;
// Make sure glue isn't stripped.
app_dummy();
memset(&engine, 0, sizeof(engine));
state->userData = &engine;
state->onAppCmd = engine_handle_cmd;
state->onInputEvent = engine_handle_input;
engine.app = state;
// Prepare to monitor accelerometer
engine.sensorManager = ASensorManager_getInstance();
engine.accelerometerSensor = ASensorManager_getDefaultSensor(engine.sensorManager,
ASENSOR_TYPE_ACCELEROMETER);
engine.sensorEventQueue = ASensorManager_createEventQueue(engine.sensorManager,
state->looper, LOOPER_ID_USER, NULL, NULL);
if (state->savedState != NULL) {
// We are starting with a previous saved state; restore from it.
engine.state = *(struct saved_state*)state->savedState;
}
// loop waiting for stuff to do.
while (1) {
// Read all pending events.
int ident;
int events;
struct android_poll_source* source;
// If not animating, we will block forever waiting for events.
// If animating, we loop until all events are read, then continue
// to draw the next frame of animation.
while ((ident=ALooper_pollAll(engine.animating ? 0 : -1, NULL, &events,
(void**)&source)) >= 0) {
// Process this event.
if (source != NULL) {
source->process(state, source);
}
// If a sensor has data, process it now.
if (ident == LOOPER_ID_USER) {
if (engine.accelerometerSensor != NULL) {
ASensorEvent event;
while (ASensorEventQueue_getEvents(engine.sensorEventQueue,
&event, 1) > 0) {
LOGI("accelerometer: x=%f y=%f z=%f",
event.acceleration.x, event.acceleration.y,
event.acceleration.z);
}
}
}
// Check if we are exiting.
if (state->destroyRequested != 0) {
engine_term_display(&engine);
return;
}
}
if (engine.animating) {
// Done with events; draw next animation frame.
engine.state.angle += .01f;
if (engine.state.angle > 1) {
engine.state.angle = 0;
}
// Drawing is throttled to the screen update rate, so there
// is no need to do timing here.
engine_draw_frame(&engine);
}
}
}
//END_INCLUDE(all)

View File

@ -1,7 +0,0 @@
ndk-build
android update project --path . --name native
ant debug
adb install -r bin/native-debug.apk
./adb-run.sh bin/native-debug.apk
adb logcat | grep native-activity

View File

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">NativeActivity</string>
</resources>