onTouchEvent构造器
2015-06-02 23:10
260 查看
public boolean onTouchEvent(MotionEvent e) { act_Main.onKeyNum=0; float x = e.getX(); float y = e.getY(); switch (e.getAction()) { case MotionEvent.ACTION_DOWN: if (isScreenSaver) { stopAll(); } else { if (!colorEdgeFlag2 && 100 < x && x < SCREEN_WIDTH * 0.84f - SCREEN_WIDTH / 16 * 1.2f && SCREEN_HEIGHT / 12 < y && y < SCREEN_HEIGHT * 11 / 12) { act_Main.playSound(0, 0); screenClick.setCoor1(x, y); // System.out.println(screenClick.getI()+":"+screenClick.getJ()); elementIndex = screenClick.getElementIndex(); currStart = 0; if (count == 1) { colorEdgeFlag1 = !colorEdgeFlag1; colorEdgeFlag2 = false; } else { if (colorEdgeFlag1) { screenClick.setCoor2(x, y); saveIndex[0] = screenClick.getElementIndex(); colorEdgeFlag2 = true; moveFlag = true; } else { colorEdgeFlag1 = true; colorEdgeFlag2 = false; } } } if (colorEdgeFlag2 && UtilConfigArea.isInArea(x, y, AREA_3DVIEW)) { if(hasInertia)//按下时,如果有惯性,那么直接停止 { hasInertia=false; curr_angle_speed=0; } } if (UtilConfigArea.isInArea(x, y, AREA_BUTTON_HELP)) { rightHelpFlag = true; } if (UtilConfigArea.isInArea(x, y, AREA_CONDITION1) && ballSecondMove) { conditionFlag = true; addFlag = true; if (!cubeList.isEmpty()) { cubeList.clear(); } for (int i = 0; i < CUBE_NUM; i++) { double angle = new Random().nextFloat() * 360; tcTempaa = new DW_CubeTexture(CUBE_HALFSIZE, boxShape, dynamicsWorld, 1, 0.15f * (float) Math.sin(Math.toDegrees(angle)), (new Random().nextFloat() + 0.5f) * 1.0f, 0.15f * (float) Math.cos(Math.toDegrees(angle)), ShaderManager.getOnlyTextureShaderProgram()); synchronized (iCubeList) { iCubeList.add(tcTempaa); } } } if (UtilConfigArea.isInArea(x, y, AREA_CONDITION2) && ballSecondMove) { conditionFlag = false; } if (UtilConfigArea.isInArea(x, y, AREA_UPHELP) && ballFisrtMove) { secondMoveFlag = true; } if (UtilConfigArea.isInArea(x, y, AREA_RETURN) && conditionIndex == 0 || conditionIndex == 1) { stopAll(); } if (UtilConfigArea.isInArea(x, y, AREA_RIGHT_UP_HELP) && rightHelpFlag) { TIME_SAPN_FLAG = TIME_SAPN_FLAG == 0 ? 1 : 0; switch (TIME_SAPN_FLAG) { case 0: TIME_SPAN = 200f; Toast.makeText(act_Main, "屏保时间间隔为:200秒", Toast.LENGTH_LONG).show(); break; case 1: TIME_SPAN = 3f; Toast.makeText(act_Main, "屏保时间间隔为:3秒", Toast.LENGTH_LONG).show(); break; } } } break; case MotionEvent.ACTION_MOVE: float dx = x - mPreviousX; float dy = y - mPreviousY; if (colorEdgeFlag1 && UtilConfigArea.isInArea(x, y, AREA_CONTENT)) { currStart -= dy * TOUCH_SCALE_FACTOR * 0.005f; } if (colorEdgeFlag1 && !colorEdgeFlag2 && UtilConfigArea.isInArea(x, y, AREA_3DVIEW)) { drawElectronCloud.roateX += dy * TOUCH_SCALE_FACTOR; drawElectronCloud.roateY += dx * TOUCH_SCALE_FACTOR; } if (colorEdgeFlag2 && UtilConfigArea.isInArea(x, y, AREA_3DVIEW)) { switch (compoundIndex - 2) { case 0: if(Math.abs(dy)>8)//设定一个阈值,如果大于这个阈值,松开手指后,添加惯性 { isTouchMoved=true;//当前正在触摸 移动中 curr_angle_speed=ori_angle_speed*(dy/SCREEN_WIDTH); } cp_Salt.roateX += dy * TOUCH_SCALE_FACTOR; cp_Salt.roateY += dx * TOUCH_SCALE_FACTOR; break; case 1: cp_Water.roateX += dy * TOUCH_SCALE_FACTOR; cp_Water.roateY += dx * TOUCH_SCALE_FACTOR; } } break; case MotionEvent.ACTION_UP: timeCount = 0; if (act_Main.bgMusic[0].isPlaying()) { act_Main.bgMusic[0].pause(); } break; } if (colorEdgeFlag2 && UtilConfigArea.isInArea(x, y, AREA_3DVIEW)) { if(isTouchMoved)//如果当前滑动过 { isTouchMoved=false;//false hasInertia=true;//具有惯性true //若当前角速度大于零则加速度置为负 curr_acceleratedSpeed=ori_acceleratedSpeed; if(curr_angle_speed>0) { curr_acceleratedSpeed=-ori_acceleratedSpeed; } } else//这里启动角度智能调整 { auto_adjust=true; }} mPreviousX = x; mPreviousY = y; return true; }
相关文章推荐
- Oracle Memory Architecture(SGA,PGA)
- Ubuntu 下 Mysql 新建数据库和用户
- 把Jar文件转成exe安装文件
- 用MFC实现WebGUI--(CDHtmlDialog)
- 深刻理解Python中的元类(metaclass)
- mysql 存储引擎
- [LeetCode] Permutations
- 在js中获取query string 以及重写URL的函数
- 4.2-2
- HDU 1166 线段树的单点更新 区间求和
- TortoiseSVN客户端重新设置用户名和密码
- 序列化
- Struts2原理图
- 由于 Web 服务器上的“ISAPI 和 CGI 限制”列表设置,无法提供您请求的页面。
- 请开启您PHP环境的openssl
- 欢迎使用CSDN-markdown编辑器
- HTML5 localStorage本地存储实际应用举例
- HTML5学习笔记 视频
- 课程改进建议
- Ubuntu 系统设置中不见了语言支持这个图标