package org.libsdl.app;
import java.util.Arrays;
import android.app.*;
import android.content.*;
import android.view.*;
import android.view.inputmethod.BaseInputConnection;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputMethodManager;
import android.widget.AbsoluteLayout;
import android.os.*;
import android.util.Log;
import android.graphics.*;
import android.media.*;
import android.hardware.*;
/**
SDL Activity
*/
public class SDLActivity extends Activity {
private static final String TAG = "SDL";
// Keep track of the paused state
public static boolean mIsPaused = false, mIsSurfaceReady = false, mHasFocus = true;
// Main components
protected static SDLActivity mSingleton;
protected static SDLSurface mSurface;
protected static View mTextEdit;
protected static ViewGroup mLayout;
// This is what SDL runs in. It invokes SDL_main(), eventually
protected static Thread mSDLThread;
// Audio
protected static Thread mAudioThread;
protected static AudioTrack mAudioTrack;
// Load the .so
static {
System.loadLibrary("SDL2");
//System.loadLibrary("SDL2_image");
//System.loadLibrary("SDL2_mixer");
//System.loadLibrary("SDL2_net");
//System.loadLibrary("SDL2_ttf");
System.loadLibrary("main");
}
// Setup
@Override
protected void onCreate(Bundle savedInstanceState) {
//Log.v("SDL", "onCreate()");
super.onCreate(savedInstanceState);
// So we can call stuff from static callbacks
mSingleton = this;
// Set up the surface
mSurface = new SDLSurface(getApplication());
mLayout = new AbsoluteLayout(this);
mLayout.addView(mSurface);
setContentView(mLayout);
}
// Events
@Override
protected void onPause() {
Log.v("SDL", "onPause()");
super.onPause();
SDLActivity.handlePause();
}
@Override
protected void onResume() {
Log.v("SDL", "onResume()");
super.onResume();
SDLActivity.handleResume();
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
Log.v("SDL", "onWindowFocusChanged(): " + hasFocus);
SDLActivity.mHasFocus = hasFocus;
if (hasFocus) {
SDLActivity.handleResume();
}
}
@Override
public void onLowMemory() {
Log.v("SDL", "onLowMemory()");
super.onLowMemory();
SDLActivity.nativeLowMemory();
}
@Override
protected void onDestroy() {
super.onDestroy();
Log.v("SDL", "onDestroy()");
// Send a quit message to the application
SDLActivity.nativeQuit();
// Now wait for the SDL thread to quit
if (mSDLThread != null) {
try {
mSDLThread.join();
} catch(Exception e) {
Log.v("SDL", "Problem stopping thread: " + e);
}
mSDLThread = null;
//Log.v("SDL", "Finished waiting for SDL thread");
}
}
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
int keyCode = event.getKeyCode();
// Ignore certain special keys so they're handled by Android
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN ||
keyCode == KeyEvent.KEYCODE_VOLUME_UP ||
keyCode == KeyEvent.KEYCODE_CAMERA ||
keyCode == 168 || /* API 11: KeyEvent.KEYCODE_ZOOM_IN */
keyCode == 169 /* API 11: KeyEvent.KEYCODE_ZOOM_OUT */
) {
return false;
}
return super.dispatchKeyEvent(event);
}
/** Called by onPause or surfaceDestroyed. Even if surfaceDestroyed
* is the first to be called, mIsSurfaceReady should still be set
* to 'true' during the call to onPause (in a usual scenario).
*/
public static void handlePause() {
if (!SDLActivity.mIsPaused && SDLActivity.mIsSurfaceReady) {
SDLActivity.mIsPaused = true;
SDLActivity.nativePause();
mSurface.enableSensor(Sensor.TYPE_ACCELEROMETER, false);
}
}
/** Called by onResume or surfaceCreated. An actual resume should be done only when the surface is ready.
* Note: Some Android variants may send multiple surfaceChanged events, so we don't need to resume
* every time we get one of those events, only if it comes after surfaceDestroyed
*/
public static void handleResume() {
if (SDLActivity.mIsPaused && SDLActivity.mIsSurfaceReady && SDLActivity.mHasFocus) {
SDLActivity.mIsPaused = false;
SDLActivity.nativeResume();
mSurface.enableSensor(Sensor.TYPE_ACCELEROMETER, true);
}
}
// Messages from the SDLMain thread
static final int COMMAND_CHANGE_TITLE = 1;
static final int COMMAND_UNUSED = 2;
static final int COMMAND_TEXTEDIT_HIDE = 3;
protected static final int COMMAND_USER = 0x8000;
/**
* This method is called by SDL if SDL did not handle a message itself.
* This happens if a received message contains an unsupported command.
* Method can be overwritten to handle Messages in a different class.
* @param command the command of the message.
* @param param the parameter of the message. May be null.
* @return if the message was handled in overridden method.
*/
protected boolean onUnhandledMessage(int command, Object param) {
return false;
}
/**
* A Handler class for Messages from native SDL applications.
* It uses current Activities as target (e.g. for the title).
* static to prevent implicit references to enclosing object.
*/
protected static class SDLCommandHandler extends Handler {
@Override
public void handleMessage(Message msg) {
Context context = getContext();
if (context == null) {
Log.e(TAG, "error handling message, getContext() returned null");
return;
}
switch (msg.arg1) {
case COMMAND_CHANGE_TITLE:
if (context instanceof Activity) {
((Activity) context).setTitle((String)msg.obj);
} else {
Log.e(TAG, "error handling message, getContext() returned no Activity");
}
break;
case COMMAND_TEXTEDIT_HIDE:
if (mTextEdit != null) {
mTextEdit.setVisibility(View.GONE);
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(mTextEdit.getWindowToken(), 0);
}
break;
default:
if ((context instanceof SDLActivity) && !((SDLActivity) context).onUnhandledMessage(msg.arg1, msg.obj)) {
Log.e(TAG, "error handling message, command is " + msg.arg1);
}
}
}
}
// Handler for the messages
Handler commandHandler = new SDLCommandHandler();
// Send a message from the SDLMain thread
boolean sendCommand(int command, Object data) {
Message msg = commandHandler.obtainMessage();
msg.arg1 = command;
msg.obj = data;
return commandHandler.sendMessage(msg);
}
// C functions we call
public static native void nativeInit();
public static native void nativeLowMemory();
public static native void nativeQuit();
public static native void nativePause();
public static native void nativeResume();
public static native void onNativeResize(int x, int y, int format);
public static native void onNativeKeyDown(int keycode);
public static native void onNativeKeyUp(int keycode);
public static native void onNati
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
Eclipse Android 例子源码 SDL Android 例子源码可用工程,实测编译通过在模拟器运行(SDL 2.0 for Android),工程目录名叫AndroidTst2,编译通过可用, sdl source code for android android source code for sdl 2.0 这个工程的文件夹名字是: AndroidTst2,是一个测试SDL初始化的例子,需要注意的是你需要搭建好开windows 的Android开发环境: 1. JDK 2. Android SDK 3. NDK 下载最新版的,我的用的是NDk r9c。 此工程我本人亲自编译通过,有在模拟器上运行,运行结果是模拟器:屏幕显示全红色(480x512的像素显示红色)。 此工程基于sdl 2.0 主要是.JNI工程,通过java,用c写图形在android上跑,相信sdl以后还对不会写java的人有很大参考价值和帮助.
资源推荐
资源详情
资源评论
收起资源包目录
SDL Android 例子源码可用工程,实测编译通过在模拟器运行(SDL 2.0 for Android)Eclipse (1047个子文件)
resources.ap_ 19KB
SDLActivity.apk 562KB
Android.mk.bak.bak 381B
Android.mk.bak 371B
Android_static.mk.bak.bak 237B
Android_static.mk.bak 227B
SDL_audiotypecvt.c 605KB
SDL_blit_auto.c 275KB
SDL_test_imageBlitBlend.c 207KB
SDL_malloc.c 188KB
SDL_test_imageBlit.c 113KB
SDL_blit_N.c 90KB
SDL_video.c 83KB
SDL_test_font.c 83KB
SDL_dxjoystick.c 65KB
SDL_render_d3d.c 64KB
SDL_render_gles2.c 61KB
SDL_RLEaccel.c 53KB
SDL_render.c 52KB
SDL_test_imagePrimitivesBlend.c 51KB
SDL_windowskeyboard.c 50KB
SDL_android.c 50KB
SDL_test_common.c 48KB
SDL_x11window.c 47KB
SDL_render_gl.c 47KB
SDL_syshaptic.c 47KB
SDL_yuv_sw.c 44KB
SDL_DirectFB_render.c 43KB
SDL_blit_A.c 42KB
SDL_string.c 42KB
SDL_sysjoystick.c 40KB
SDL_audio.c 37KB
SDL_gamecontroller.c 37KB
SDL_syshaptic.c 37KB
SDL_test_imagePrimitives.c 37KB
SDL_render_gles.c 35KB
SDL_x11events.c 35KB
SDL_shaders_gles2.c 35KB
SDL_audiocvt.c 34KB
SDL_evdev.c 33KB
SDL_pixels.c 31KB
SDL_windowsevents.c 31KB
SDL_surface.c 30KB
SDL_x11modes.c 29KB
SDL_iconv.c 28KB
SDL_DirectFB_events.c 28KB
SDL_render_psp.c 27KB
SDL_x11opengl.c 27KB
SDL_qsa_audio.c 27KB
SDL_syshaptic.c 27KB
SDL_x11messagebox.c 26KB
SDL_pandora.c 26KB
SDL_sysjoystick.c 24KB
SDL_blendline.c 24KB
SDL_render_sw.c 23KB
imKStoUCS.c 23KB
SDL_test_harness.c 22KB
SDL_keyboard.c 22KB
SDL_windowsopengl.c 22KB
SDL_yuv_mmx.c 21KB
SDL_stdlib.c 21KB
SDL_joystick.c 21KB
SDL_alsa_audio.c 21KB
SDL_gesture.c 20KB
SDL_rwops.c 20KB
SDL_cpuinfo.c 20KB
edid-parse.c 19KB
SDL_wave.c 19KB
SDL_windowswindow.c 19KB
SDL_bmp.c 18KB
SDL_haptic.c 18KB
SDL_coreaudio.c 18KB
SDL_paudio.c 18KB
SDL_x11video.c 18KB
SDL_sysjoystick.c 18KB
SDL_mouse.c 17KB
SDL_pulseaudio.c 17KB
SDL_directsound.c 17KB
SDL_DirectFB_window.c 16KB
SDL_events.c 16KB
SDL_test_imageFace.c 16KB
SDL_qsort.c 16KB
SDL_rotate.c 15KB
SDL_DirectFB_video.c 15KB
e_sqrt.c 15KB
SDL_mmjoystick.c 14KB
SDL_xaudio2.c 13KB
SDL_test_fuzzer.c 13KB
e_pow.c 13KB
SDL_DirectFB_modes.c 13KB
SDL_sunaudio.c 13KB
SDL_androidkeyboard.c 13KB
SDL_windowsmessagebox.c 13KB
SDL_DirectFB_WM.c 13KB
SDL_egl.c 12KB
SDL_blit_1.c 12KB
SDL_mixer.c 12KB
SDL_rect.c 12KB
SDL_blit_0.c 12KB
SDL_winmm.c 12KB
共 1047 条
- 1
- 2
- 3
- 4
- 5
- 6
- 11
mynameislinduan
- 粉丝: 127
- 资源: 57
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 阿里云OSS Java版SDK.zip
- 阿里云api网关请求签名示例(java实现).zip
- 通过示例学习 Android 的 RxJava.zip
- 通过多线程编程在 Java 中发现并发模式和特性 线程、锁、原子等等 .zip
- 通过在终端中进行探索来学习 JavaScript .zip
- 通过不仅针对初学者而且针对 JavaScript 爱好者(无论他们的专业水平如何)设计的编码挑战,自然而自信地拥抱 JavaScript .zip
- 适用于 Kotlin 和 Java 的现代 JSON 库 .zip
- yolo5实战-yolo资源
- english-chinese-dictionary-数据结构课程设计
- mp-mysql-injector-spring-boot-starter-sql注入
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
前往页