Beispiel #1
0
  @Override
  public void onResume() {
    // TODO Auto-generated method stub
    super.onResume();

    getSensorInfo.StartSensor();
    getLocation.StartLocation();
  }
Beispiel #2
0
  /** 传感器监听函数 */
  private void setListener() {

    getLocation.setOnLocationListener(
        new GetLocation.OnLocationListener() { // GPS的位置数据,定位成功一次后取消GPS定位

          @Override
          public void onLocationChanged(BDLocation bdLocation) {
            // TODO Auto-generated method stub

            cityaddString = bdLocation.getAddrStr();

            getLocation.StopLocation();
          }
        });

    getSensorInfo.setOnAcceleratedListener(
        new GetSensorInfo.OnAcceleratedListener() { // 加速度回调

          @Override
          public void onAcceleratedChanged(int count) {
            // TODO Auto-generated method stub

          }
        });

    getSensorInfo.setOnOrientationListener(
        new GetSensorInfo.OnOrientationListener() { // 方向传感器回调

          @Override
          public void onOrientationChanged(float orientation) {
            // TODO Auto-generated method stub

            if (Math.abs(angle - orientation) > 1
                && (System.currentTimeMillis() - fristtime) > 200) {

              angle = orientation;

              Message message = new Message();
              message.what = 1;
              handler.sendMessage(message);

              fristtime = System.currentTimeMillis();
            }

            if (orientation < 40) {

              angleTextView.setText((int) orientation + "°  N" + "\n" + cityaddString);

            } else if (orientation < 50) {

              angleTextView.setText((int) orientation + "°  NE" + "\n" + cityaddString);

            } else if (orientation < 120) {

              angleTextView.setText((int) orientation + "°  E" + "\n" + cityaddString);

            } else if (orientation < 150) {

              angleTextView.setText((int) orientation + "°  SE" + "\n" + cityaddString);

            } else if (orientation < 220) {

              angleTextView.setText((int) orientation + "°  S" + "\n" + cityaddString);

            } else if (orientation < 240) {

              angleTextView.setText((int) orientation + "°  SW" + "\n" + cityaddString);

            } else if (orientation < 300) {

              angleTextView.setText((int) orientation + "°  W" + "\n" + cityaddString);

            } else if (orientation < 330) {

              angleTextView.setText((int) orientation + "°  NW" + "\n" + cityaddString);

            } else {
              angleTextView.setText((int) orientation + "°  N" + "\n" + cityaddString);
            }
          }
        });
  }