onTouchEvent构造器

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;
	}

原文地址:https://www.cnblogs.com/Anzhongliu/p/6092078.html