• 07_重力倾斜度响应



    import android.hardware.Sensor;
    import android.hardware.SensorEvent;
    import android.hardware.SensorEventListener;
    import android.hardware.SensorManager;
    import android.os.Bundle;
    import android.app.Activity;
    import android.content.Context;
    import android.view.Menu;
    import android.widget.TextView;

    public class MainActivity extends Activity  implements SensorEventListener {
        TextView textView;
        StringBuilder builder = new StringBuilder();

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            textView = new TextView(this);
            setContentView(textView);

            SensorManager manager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
            if (manager.getSensorList(Sensor.TYPE_ACCELEROMETER).size() == 0) {
                textView.setText("No accelerometer installed");
            } else {
                Sensor accelerometer = manager.getSensorList(
                        Sensor.TYPE_ACCELEROMETER).get(0);
                if (!manager.registerListener(this, accelerometer,
                        SensorManager.SENSOR_DELAY_GAME)) {
                    textView.setText("Couldn't register sensor listener");
                }
            }
        }

        @Override
        public void onSensorChanged(SensorEvent event) {
            builder.setLength(0);
            builder.append("x: ");
            builder.append(event.values[0]);
            builder.append(", y: ");
            builder.append(event.values[1]);
            builder.append(", z: ");
            builder.append(event.values[2]);
            textView.setText(builder.toString());
        }

        @Override
        public void onAccuracyChanged(Sensor sensor, int accuracy) {
            // nothing to do here
        }
    }

  • 相关阅读:
    时间操作、时间戳
    滚动条大于120px时,判断pc端的情况下,导航条固定定位
    通过js中的useragrent来判断设备是pc端还是移动端,跳转不同的地址
    js构建函数,点击按钮显示div,再点击按钮或其他区域,隐藏div
    localStorage用法总结
    轮播插件、原生js编写,弄懂这个,基本上各种轮播都可以自己写了
    (原)选择远比努力重要
    Java线程之间通信
    迪杰斯特拉(Java)
    FFTW中文参考
  • 原文地址:https://www.cnblogs.com/xl711436/p/3060421.html
Copyright © 2020-2023  润新知