码迷,mamicode.com
首页 > 移动开发 > 详细

android 退出,不锁屏

时间:2014-09-19 14:04:25      阅读:243      评论:0      收藏:0      [点我收藏+]

标签:android   os   java   ar   cti   log   on   c   ad   

Cocos2dxGLSurfaceView.java
	public boolean onKeyDown(final int pKeyCode, final KeyEvent pKeyEvent) {
		switch (pKeyCode) {
			case KeyEvent.KEYCODE_BACK:
				Cocos2dxActivity.clossGame();
				return true;
			case KeyEvent.KEYCODE_MENU:
				this.queueEvent(new Runnable() {
					@Override
					public void run() {
						Cocos2dxGLSurfaceView.this.mCocos2dxRenderer.handleKeyDown(pKeyCode);
					}
				});
				return true;
			default:
				return super.onKeyDown(pKeyCode, pKeyEvent);
		}
	}

Cocos2dxActivity.java

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.app.Dialog;
	public static void clossGame()
	{
		log.info("return!");
		Cocos2dxActivity mainActivity = (Cocos2dxActivity) sContext;
		mainActivity.onPause();

		Dialog alertDialog = new AlertDialog.Builder(mainActivity). 
                setTitle("游戏提示"). 
                setMessage("是否确定要退出游戏?").
                setPositiveButton("确定", new DialogInterface.OnClickListener() { 
                    
                    @Override 
                    public void onClick(DialogInterface dialog, int which) { 
                        // TODO Auto-generated method stub
                		Cocos2dxActivity mainActivity = (Cocos2dxActivity) sContext;
                		mainActivity.finish();
                		
                		System.exit(0);
                    } 
                }).
                setNegativeButton("取消", new DialogInterface.OnClickListener() { 
                    
                    @Override 
                    public void onClick(DialogInterface dialog, int which) { 
                        // TODO Auto-generated method stub  
                		Cocos2dxActivity mainActivity = (Cocos2dxActivity) sContext;
                		mainActivity.onResume();
                    } 
                }).
                create(); 
        alertDialog.show(); 
	}



import android.view.WindowManager; 
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);   //应用运行时,保持屏幕高亮,不锁屏



android 退出,不锁屏

标签:android   os   java   ar   cti   log   on   c   ad   

原文地址:http://my.oschina.net/ffs/blog/315949

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!