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
mynameislinduan
- 粉丝: 129
- 资源: 57
最新资源
- 手机云控系统空白框架源码,适用于任何平台项目批量化控制脚本运行 #autois #PHP
- 西门子200smart工程项目案例 电气原理图: 5个柜子:1个总电源柜、2个变频柜、1个动力柜、1个PLC控制柜 实现泵、风机的两地控制(就地按钮箱与上位机) 阀控制、模拟量采集、 西门子G120
- 57步进电机驱动板,可以通过编码器调速,支持SPI通讯屏显示,485通讯 板子上面有电位器可电流设定或者485改电流设定 最大电流支持4.5A,如果需要更大电流需要改元器件参数 有启停和方向按键
- 基于hadoop的协同过滤就业推荐系统 推荐原理:以用户对岗位的评分和用户的收藏行为作为基础数据集,应用hadoop通过mapreduce程序进行协同过滤计算,得出用户对岗位的预测评分,根据评分高低对
- 永磁直驱风机在不对称故障下的低电压穿越simulink仿真模型,通过改变控制策略来模拟不对故障下的系统电压穿越 下图为单相接地故障时风机电压、电流、直流侧电压图形
- C语言俄罗斯方块源代码-俄罗斯方块c语言
- 三菱Q系列PLC项目资料 本系统采用三菱Q系列PLC,本系统中用到16个伺服电机,采用16轴控制器通过光纤驱动16个伺服,其中涉及到定位控制和同步控制 另外还有CCLINK通讯 触摸屏采用维纶通的
- 西门子PLC程序实例,西门子S7-200SMART布袋除尘程序,另送一个200Smart电除尘器程序 布袋除尘器PLC控制程序含图纸及昆仑通泰触摸屏画面,分手动模式自动模式选择,脉冲阀顺序动作 电
- S7-200 PLC和组态王组态控制的花式喷泉控制系统 带解释的梯形图程序,接线图原理图图纸,io分配,组态画面
- 三菱FX3U 485ADP与3台东元Teco变频器N310通讯实战程序 功能:通过三菱fx3u 485ADP-MB板对3台东元Teco N310变频器进行modbus通讯,实现频率设定,启停控
- Util-大炮打蚊子c++
- PMU优化配置 系统完全可观 软件:MATLAB 优化 PMU 放置 (OPP) 问题的六种算法,包括两种模拟 火方法、两种图论过程和递归安全 N 算法 从MatPower获得的IEEE 14
- QAPlatform-python与mysql基础
- 电力系统机组调度 考虑了源荷不确定性 求解:matlab+yalmip+gurobi作为求解器) 内容:考虑源荷两侧不确定性的含风电的低碳调度,引入模糊机会约束,程序包括储能、风光、火电机组及水电机组
- HFI脉振方波高频注入代码 增强滑膜esmo代码 配套有文档 HFI脉振方波高频注入代码 增强滑膜esmo代码 配套有文档,学习的好东西 1esmo和 hfi的原厂文档 送原厂esmo.c ,esm
- matlab 代码基于主从博弈的共享储能与综合能源微网优化运行研究 综合能源微网与共享储能的结合具有一定的创新性,在共享储能的背景下考虑微网运营商与用户聚合商之间的博弈关系,微网的收益和用户的收益之间
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
- 4
前往页