/** * Gsensor changed ,send message to update view * * @date 2015-2-11 pm 3:31:15 * @param values * @param msg */ private void sendGSensorChangedMSG(float[] values, Message msg) { msg = mHandler.obtainMessage( MSG_UPDATE_GSSOR, String.format( Locale.ENGLISH, "X:%+8.4f\nY:%+8.4f\nZ:%+8.4f", values[0], values[1], values[2])); mHandler.sendMessage(msg); if (values[0] > ORI_CHANGE_LEN || values[0] < -ORI_CHANGE_LEN || values[1] > ORI_CHANGE_LEN || values[1] < -ORI_CHANGE_LEN || values[2] > ORI_CHANGE_LEN || values[2] < -ORI_CHANGE_LEN) { updateGssorView(values[0], values[1], values[2]); } if (mGSsorView.getmOriTestSum() == GSensorOriView.ORI_SUM) { ItemTestActivity.itemActivity.handler.sendEmptyMessage( ItemTestActivity.MSG_BTN_PASS_CLICKABLE); } }
/** * @date 2015-2-11 pm 3:29:36 * @param x Gx * @param y Gy * @param z Gz */ public void updateGssorView(float x, float y, float z) { if (x > ORI_CHANGE_LEN && !mGSsorView.isRight) { mGSsorView.isRight = true; mGSsorView.addmOriTestSum(); } if (x < -ORI_CHANGE_LEN && !mGSsorView.isLeft) { mGSsorView.isLeft = true; mGSsorView.addmOriTestSum(); } if (y < -ORI_CHANGE_LEN && !mGSsorView.isDown) { mGSsorView.isDown = true; mGSsorView.addmOriTestSum(); } if (y > ORI_CHANGE_LEN && !mGSsorView.isUp) { mGSsorView.isUp = true; mGSsorView.addmOriTestSum(); } if (z > ORI_CHANGE_LEN && !mGSsorView.isPositive) { mGSsorView.isPositive = true; mGSsorView.addmOriTestSum(); } if (z < -ORI_CHANGE_LEN && !mGSsorView.isNegative) { mGSsorView.isNegative = true; mGSsorView.addmOriTestSum(); Log.i("hah", "" + z); } mGSsorView.invalidate(); }
/** when leave this Activity, unregisterListener of SensorManager */ @Override public void onPause() { mSsorManager.unregisterListener(this); mGSsorView.clearViewState(); super.onPause(); }