{"id":223,"date":"2010-06-21T04:03:09","date_gmt":"2010-06-20T19:03:09","guid":{"rendered":"http:\/\/www.typea.info\/blog\/index.php\/2010\/06\/21\/androidx06ht_desire\/"},"modified":"2010-06-21T04:03:09","modified_gmt":"2010-06-20T19:03:09","slug":"androidx06ht_desire","status":"publish","type":"post","link":"https:\/\/www.typea.info\/blog\/index.php\/2010\/06\/21\/androidx06ht_desire\/","title":{"rendered":"Android(X06HT Desire) \u642d\u8f09\u30bb\u30f3\u30b5\u30fc\u306e\u5024\u3092\u53d6\u5f97\u3057\u3066\u307f\u308b"},"content":{"rendered":"<\/p>\n<p><a href=\"\/blg\/glob\/2010\/06\/android_x06ht_desire.html\" target=\"_blank\">\u5b9f\u6a5f\u3092\u4f7f\u3063\u3066\u30c7\u30d0\u30c3\u30b0\u3059\u308b\u3053\u3068\u3092\u899a\u3048\u305f<\/a>\u306e\u3067\u3001Desire \u306b\u642d\u8f09\u3055\u308c\u3066\u3044\u308b\u30bb\u30f3\u30b5\u30fc\u306e\u5024\u3092\u53d6\u5f97\u3057\u3066\u307f\u3088\u3046\u3002<\/p>\n<p><a title=\"http:\/\/developer.android.com\/reference\/android\/hardware\/SensorEvent.html\" href=\"http:\/\/developer.android.com\/reference\/android\/hardware\/SensorEvent.html\">http:\/\/developer.android.com\/reference\/android\/hardware\/SensorEvent.html<\/a><\/p>\n<h2>SenserEvent API \u306e\u5ea7\u6a19\u7cfb<\/h2>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/image\/2831976cafd7_9315\/desire.jpg\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" style=\"border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px\" title=\"desire\" border=\"0\" alt=\"desire\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/image\/2831976cafd7_9315\/desire_thumb.jpg\" width=\"188\" height=\"244\"><\/a>&nbsp;<\/p>\n<p><a href=\"http:\/\/www.komoto.org\/opengl\/sample01.html\">OpenGL\u306e\u5ea7\u6a19\u7cfb\u3068\u540c\u3058<\/a>\u3067\u3042\u308a\u3001\u4e00\u822c\u306e\u30b3\u30f3\u30d4\u30e5\u30fc\u30bf\u30fc\u4e0a\u306e\u30b9\u30af\u30ea\u30fc\u30f3\u5ea7\u6a19(\u5de6\u4e0a\u304c\u539f\u70b9)\u3068\u306f\u7570\u306a\u308b\u3002<\/p>\n<h2>3\u8ef8 \u52a0\u901f\u5ea6\u30bb\u30f3\u30b5\u30fc(3-axis Accelerometer)<\/h2>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/image\/2831976cafd7_9315\/accel.jpg\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" style=\"border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px\" title=\"accel\" border=\"0\" alt=\"accel\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/image\/2831976cafd7_9315\/accel_thumb.jpg\" width=\"244\" height=\"184\"><\/a> <\/p>\n<p><a href=\"http:\/\/ja.wikipedia.org\/wiki\/%E3%83%A1%E3%83%BC%E3%83%88%E3%83%AB%E6%AF%8E%E7%A7%92%E6%AF%8E%E7%A7%92\">m\/s2\uff08\u30e1\u30fc\u30c8\u30eb\u6bce\u79d2\u6bce\u79d2\uff09<\/a>\u3067\u3001\u52a0\u901f\u5ea6\u3092\u8868\u3059\u3002<\/p>\n<p><a title=\"\u7b2c9\u56de \u52a0\u901f\u5ea6\u306e\u8a08\u6e2c\" href=\"http:\/\/www.kri.sfc.keio.ac.jp\/report\/gakujutsu\/2007\/3-5\/HMA_09.pdf\">\u52a0\u901f\u5ea6\u306e\u8a08\u6e2c<\/a><\/p>\n<ol>\n<li>X\u8ef8\u52a0\u901f\u5ea6<\/li>\n<li>Y\u8ef8\u52a0\u901f\u5ea6<\/li>\n<li>Z\u8ef8\u52a0\u901f\u5ea6<\/li>\n<\/ol>\n<ul>\n<li>\u6c34\u5e73\u306a\u30c6\u30fc\u30d6\u30eb\u306b\u7aef\u672b\u3092\u7f6e\u3044\u3066\u3001\u5de6\u5074\u3092\u53f3\u306b\u5411\u3051\u3066\u62bc\u3057\u305f\u5834\u5408\u3001X\u8ef8\u52a0\u901f\u5ea6\u306f\u3001\u6b63\u306e\u5024\u306b\u306a\u308b\u3002<\/li>\n<li>\u6c34\u5e73\u306a\u30c6\u30fc\u30d6\u30eb\u306b\u7aef\u672b\u3092\u7f6e\u3044\u305f\u5834\u5408\u3001\u52a0\u901f\u5ea6\u306e\u5024\u306f\u3001\u7aef\u672b\u306e\u52a0\u901f\u5ea6(0 m\/s^2) \u5f15\u304f\u3001\u91cd\u529b(-9.81 m\/s^2)\u3067\u3001 +9.81 \u3068\u306a\u308b\u3002<\/li>\n<li>\u6c34\u5e73\u306a\u30c6\u30fc\u30d6\u30eb\u306b\u7aef\u672b\u3092\u7f6e\u3044\u3066\u3001\u7a7a\u306b\u5411\u3051\u3066 A m\/s^2 \u306e\u52a0\u901f\u5ea6\u3092\u304b\u3051\u305f\u5834\u5408\u3001A + 9.81 \u3068\u306a\u308b\u3002<\/li>\n<\/ul>\n<h2>3\u8ef8 \u78c1\u754c\u30bb\u30f3\u30b5\u30fc(3-axis Magnetic field sensor)<\/h2>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/image\/2831976cafd7_9315\/magnetic.jpg\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" style=\"border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px\" title=\"magnetic\" border=\"0\" alt=\"magnetic\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/image\/2831976cafd7_9315\/magnetic_thumb.jpg\" width=\"244\" height=\"184\"><\/a>&nbsp;<\/p>\n<p>\u78c1\u754c\u30bb\u30f3\u30b5\u30fc\u306f\u3001<a href=\"http:\/\/typea-mixi01.appspot.com\/yh_s?q=%E7%A3%81%E7%95%8C%E3%82%BB%E3%83%B3%E3%82%B5%E3%83%BC+%E7%94%A8%E9%80%94\">\u3044\u308d\u3044\u308d\u306a\u7528\u9014\u306b\u5229\u7528\u3067\u304d\u308b<\/a>\u3088\u3046\u3060\u304c\u3001\u81ea\u5206\u306b\u306f\u3055\u3063\u3071\u308a\u7406\u89e3\u3067\u304d\u307e\u305b\u3093\u3002<\/p>\n<p><a href=\"http:\/\/www.kepco.co.jp\/emf-k\/kiso\/tani.htm\">\u03bcT(\u30de\u30a4\u30af\u30ed\u30c6\u30b9\u30e9)<\/a>\u3068\u3044\u3046\u5358\u4f4d\u3067\u96fb\u78c1\u6ce2\u3092\u306f\u304b\u308b\u3089\u3057\u3044\u3002<\/p>\n<p>\u67d0\u30d4\u30c3\u30d7\u30a8\u30ec\u30ad\u30d0\u30f3\u306e\u985e\u4f3c\u5546\u54c1\u304c\u3001\u3046\u3061\u306b\u3042\u308a\u3001\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u898b\u308b\u3068 \u300c100\u30de\u30a4\u30af\u30ed\u30c6\u30b9\u30e9\u300d \u3068\u3046\u305f\u3063\u3066\u3044\u308b\u3002<\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/image\/2831976cafd7_9315\/pip.jpg\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" style=\"border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px\" title=\"pip\" border=\"0\" alt=\"pip\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/image\/2831976cafd7_9315\/pip_thumb.jpg\" width=\"195\" height=\"147\"><\/a> <\/p>\n<p>Desire \u306e\u80cc\u9762\u306e\u5de6\u4e0b\u3042\u305f\u308a\u306b\u8fd1\u3065\u3051\u308b\u3068\u3001\u78ba\u304b\u306b 100\u30de\u30a4\u30af\u30ed\u30c6\u30b9\u30e9 \u3092\u8d85\u3048\u308b\u5024\u3092\u691c\u77e5\uff01<\/p>\n<p>\u67d0\u30a8\u30ec\u30ad\u30d0\u30f3\u306e\u771f\u507d\u3092\u78ba\u304b\u3081\u308b\u306e\u306b\u306f\u4f7f\u3048\u305d\u3046\u3060\u3002<\/p>\n<h2>\u50be\u304d\u30bb\u30f3\u30b5\u30fc(Orientation sensor)<\/h2>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/image\/2831976cafd7_9315\/orientation.jpg\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" style=\"border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px\" title=\"orientation\" border=\"0\" alt=\"orientation\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/image\/2831976cafd7_9315\/orientation_thumb.jpg\" width=\"244\" height=\"184\"><\/a> <\/p>\n<ol>\n<li>\u65b9\u4f4d \u30fb\u30fb\u30fb 0=\u5317, 90=\u6771, 180=\u5357, 270=\u897f \u3068\u3057\u3066\u30010 \uff5e 359 \u306e\u89d2\u5ea6<\/li>\n<li>\u30d4\u30c3\u30c1(Pitch) \u30fb\u30fb\u30fb X\u8ef8\u306b\u305d\u3063\u3066\u3001-180 \uff5e 180 \u307e\u3067\u56de\u8ee2\u3002Z\u8ef8\u304c\u3001Y\u8ef8\u306b\u5411\u304b\u3046\u5834\u5408\u3001\u6b63\u306e\u5024\u3002<\/li>\n<li>\u30ed\u30fc\u30eb(Roll) \u30fb\u30fb\u30fb Y\u8ef8\u306b\u305d\u3063\u3066\u3001 -90 \uff5e 90 \u307e\u3067\u56de\u8ee2\u3002X\u8ef8\u304c\u3001Z\u8ef8\u306b\u5411\u304b\u3046\u5834\u5408\u3001\u6b63\u306e\u5024\u3002<\/li>\n<\/ol>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/image\/2831976cafd7_9315\/orientation_3.jpg\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" style=\"border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px\" title=\"orientation\" border=\"0\" alt=\"orientation\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/image\/2831976cafd7_9315\/orientation_thumb_3.jpg\" width=\"360\" height=\"197\"><\/a> <\/p>\n<h2>\u8fd1\u63a5\u30bb\u30f3\u30b5\u30fc(Proximity sensor)<\/h2>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/image\/2831976cafd7_9315\/proximity.jpg\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" style=\"border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px\" title=\"proximity\" border=\"0\" alt=\"proximity\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/image\/2831976cafd7_9315\/proximity_thumb.jpg\" width=\"244\" height=\"184\"><\/a> <\/p>\n<p>\u7269\u4f53\u304c\u8fd1\u3065\u3044\u305f\u3089\u8ddd\u96e2\u3092 cm \u3067\u691c\u77e5\u3059\u308b\u3002<\/p>\n<p>\u305f\u3060\u3057\u3001\u4e0a\u8a18\u306b\u5bfe\u5fdc\u3057\u3066\u304a\u3089\u305a\u3001\u300c\u8fd1\u3044\u300d\u300c\u9060\u3044\u300d\u306e\u3044\u305a\u308c\u304b\u3067\u8a08\u6e2c\u3059\u308b\u3082\u306e\u3082\u3042\u308b\u3002<\/p>\n<p>Desire \u3067\u306f\u3001\u8fd1\u3044 0 \u3001\u9060\u3044 1 \u3068\u8a08\u6e2c\u3055\u308c\u308b\u3088\u3046\u3060\u3002<\/p>\n<h2>\u8f1d\u5ea6\u30bb\u30f3\u30b5\u30fc(Light sensor) <\/h2>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/image\/2831976cafd7_9315\/light.jpg\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" style=\"border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px\" title=\"light\" border=\"0\" alt=\"light\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/image\/2831976cafd7_9315\/light_thumb.jpg\" width=\"244\" height=\"184\"><\/a> <\/p>\n<p>\u660e\u308b\u3055\u3092<a href=\"http:\/\/ja.wikipedia.org\/wiki\/%E3%83%AB%E3%82%AF%E3%82%B9\">\u30eb\u30af\u30b9<\/a>(lux)\u3067\u8a08\u6e2c<\/p>\n<p>&nbsp;<\/p>\n<h3>\u4e0a\u8a18\u306e\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3002<\/h3>\n<pre class=\"prettyprint linenums\">package info.typea.sensorlist;\r\npackage info.typea.sensorlist;\r\n\r\nimport java.util.ArrayList;\r\nimport java.util.List;\r\n\r\nimport android.app.ListActivity;\r\nimport android.content.SharedPreferences;\r\nimport android.content.SharedPreferences.Editor;\r\nimport android.hardware.Sensor;\r\nimport android.hardware.SensorEvent;\r\nimport android.hardware.SensorEventListener;\r\nimport android.hardware.SensorManager;\r\nimport android.os.Bundle;\r\nimport android.view.View;\r\nimport android.widget.ArrayAdapter;\r\nimport android.widget.ListAdapter;\r\nimport android.widget.ListView;\r\nimport android.widget.TextView;\r\n\r\npublic class SensorListActivity extends ListActivity {\r\n\r\n    private final static String ACTIVE_SENSOR = \"ActiveSensor\";\r\n    private SensorManager sensorManager = null;\r\n    \r\n    private List&lt;SensorItem&gt; sensorItems;\r\n    private TextView txtResult = null;\r\n    \r\n    private int activeSensorType = 0;\r\n    \r\n    \/** Called when the activity is first created. *\/\r\n    @Override\r\n    public void onCreate(Bundle savedInstanceState) {\r\n        super.onCreate(savedInstanceState);\r\n        setContentView(R.layout.main);\r\n        \r\n        sensorManager = (SensorManager)this.getSystemService(SENSOR_SERVICE);\r\n        List&lt;Sensor&gt; sensors = sensorManager.getSensorList(Sensor.TYPE_ALL);\r\n        \r\n        sensorItems = new ArrayList&lt;SensorItem&gt;();\r\n        for (Sensor sensor : sensors) {\r\n            SensorItem sensorItem = new SensorItem();\r\n            sensorItem.setSensorName(sensor.getName());\r\n            sensorItem.setSensorType(sensor.getType());\r\n            sensorItems.add(sensorItem);\r\n        }\r\n        ArrayAdapter&lt;SensorItem&gt; lstAdapter \r\n            = new ArrayAdapter&lt;SensorItem&gt;(this, R.layout.sensor_row, sensorItems);\r\n        setListAdapter(lstAdapter);\r\n    \r\n        txtResult = (TextView) findViewById(R.id.txt_result);\r\n    }\r\n    \r\n    @Override\r\n    protected void onResume() {\r\n        super.onResume();\r\n        \r\n        \/\/ \u30d7\u30ea\u30d5\u30a1\u30ec\u30f3\u30b9\u306b\u4fdd\u5b58\u3055\u308c\u305f\u30bb\u30f3\u30b5\u30fc\u3092\u5fa9\u5e30\r\n        SharedPreferences pref = getPreferences(MODE_PRIVATE);\r\n        int sensorType = pref.getInt(ACTIVE_SENSOR, 0);\r\n        startSensorTrace(sensorType);\r\n    }\r\n    \r\n    @Override\r\n    protected void onPause() {\r\n        \r\n        \/\/ \u9078\u629e\u3055\u308c\u305f\u30bb\u30f3\u30b5\u30fc\u3092\u30d7\u30ea\u30d5\u30a1\u30ec\u30f3\u30b9\u306b\u5f85\u907f\r\n        if (this.activeSensorType != 0) {\r\n            SharedPreferences pref = getPreferences(MODE_PRIVATE);\r\n            Editor editor = pref.edit();\r\n            editor.putInt(ACTIVE_SENSOR, this.activeSensorType);\r\n            editor.commit();\r\n        }\r\n        super.onPause();\r\n    }\r\n    \r\n    @Override\r\n    protected void onListItemClick(ListView l, View v, int position, long id) {\r\n        super.onListItemClick(l, v, position, id);\r\n    \r\n        txtResult.setText(\"\");\r\n        \r\n        \/\/ \u9078\u629e\u3055\u308c\u305f\u30bb\u30f3\u30b5\u30fc\u306e\u30ea\u30b9\u30cb\u30f3\u30b0\u3092\u884c\u3046\r\n        int sensorType = ((SensorItem)l.getAdapter().getItem(position)).getSensorType();\r\n        startSensorTrace(sensorType);\r\n    }\r\n        \r\n    \/**\r\n     * \u30bb\u30f3\u30b5\u30fc\u30bf\u30a4\u30d7\u3092\u6307\u5b9a\u3057\u3066\u30ea\u30b9\u30ca\u30fc\u3092\u767b\u9332\r\n     * \u6307\u5b9a\u3055\u308c\u306a\u304b\u3063\u305f\u30bb\u30f3\u30b5\u30fc\u306e\u30ea\u30b9\u30ca\u30fc\u306e\u767b\u9332\u89e3\u9664\r\n     * @param sensorType\r\n     *\/\r\n    private void startSensorTrace(int sensorType) {\r\n        ListAdapter lstAdapter = this.getListAdapter();\r\n        for (int i=0; i&lt;lstAdapter.getCount(); i++) {\r\n            SensorItem sensorItem = (SensorItem)lstAdapter.getItem(i);\r\n            if (sensorItem.getSensorType() == sensorType) {\r\n                Sensor sensor =    sensorManager.getDefaultSensor(sensorItem.getSensorType());\r\n                \/\/ \u30bb\u30f3\u30b5\u30fc\u30ea\u30b9\u30cb\u30f3\u30b0\u306e\u767b\u9332\r\n                sensorManager.registerListener(\r\n                        sensorItem.listener,sensor, SensorManager.SENSOR_DELAY_NORMAL);\r\n                this.activeSensorType = sensorType;\r\n            } else {\r\n                \/\/ \u30bb\u30f3\u30b5\u30fc\u30ea\u30b9\u30cb\u30f3\u30b0\u306e\u767b\u9332\u89e3\u9664\r\n                sensorManager.unregisterListener(sensorItem.listener);\r\n            }\r\n        }\r\n    }\r\n    \r\n    \/**\r\n     * \u52a0\u901f\u5ea6\u30bb\u30f3\u30b5\u30fc\r\n     *\/\r\n    class AccelerometerSensorListner implements SensorEventListener {\r\n        @Override\r\n        public void onAccuracyChanged(Sensor arg0, int arg1) {\r\n        }\r\n        @Override\r\n        public void onSensorChanged(SensorEvent event) {\r\n            String r = String.format(\r\n                        \"--------------------------------\\n\" + \r\n                        \"3-axis Accelerometer\\n\"+\r\n                        \"--------------------------------\\n\" +\r\n                        \"minus Gx on the x-axis : %f\\n\" +\r\n                        \"minus Gy on the y-axis : %f\\n\" +\r\n                        \"minus Gz on the z-axis : %f\"\r\n                        ,event.values[0]\r\n                        ,event.values[1]\r\n                        ,event.values[2]\r\n                      );\r\n            txtResult.setText(r);\r\n        }\r\n    }\r\n    \/**\r\n     * \u50be\u304d\u30bb\u30f3\u30b5\u30fc \r\n     * @see SensorManager.getOrientation()\r\n     *\/\r\n    class OrientationSensorListener implements SensorEventListener {\r\n        @Override\r\n        public void onAccuracyChanged(Sensor arg0, int arg1) {\r\n        }\r\n        @Override\r\n        public void onSensorChanged(SensorEvent event) {\r\n            String r = String.format(\r\n                    \"--------------------------------\\n\" + \r\n                    \"Orientation sensor\\n\"+\r\n                    \"--------------------------------\\n\" +\r\n                    \"Azimuth(0=N,90=E,180=S,270=W) : %f\\n\" +\r\n                    \"Pitch (X axis -180 to 180) : %f\\n\" +\r\n                    \"Roll (Y axis -90 to 90) : %f\"\r\n                    ,event.values[0]\r\n                    ,event.values[1]\r\n                    ,event.values[2]\r\n                  );\r\n            txtResult.setText(r);\r\n        }\r\n    }\r\n    \/**\r\n     * \u78c1\u754c\u30bb\u30f3\u30b5\u30fc \r\n     *\/\r\n    class MagneticFieldSensorListener implements SensorEventListener {\r\n        @Override\r\n        public void onAccuracyChanged(Sensor arg0, int arg1) {\r\n        }\r\n        @Override\r\n        public void onSensorChanged(SensorEvent event) {\r\n            String r = String.format(\r\n                    \"--------------------------------\\n\" + \r\n                    \"3-axis Magnetic field sensor\\n\"+\r\n                    \"--------------------------------\\n\" +\r\n                    \"X axis : %f \u03bcT\\n\" +\r\n                    \"Y axis : %f \u03bcT\\n\" +\r\n                    \"Z axis : %f \u03bcT\"\r\n                    ,event.values[0]\r\n                    ,event.values[1]\r\n                    ,event.values[2]\r\n                  );\r\n            txtResult.setText(r);\r\n        }\r\n    }\r\n    \r\n    \/**\r\n     * \u8f1d\u5ea6\u30bb\u30f3\u30b5\u30fc\r\n     *\/\r\n    class LightSensorListener implements SensorEventListener {\r\n        @Override\r\n        public void onAccuracyChanged(Sensor sensor, int accuracy) {\r\n        }\r\n\r\n        @Override\r\n        public void onSensorChanged(SensorEvent event) {\r\n            String r = String.format(\r\n                    \"--------------------------------\\n\" + \r\n                    \"light sensor\\n\"+\r\n                    \"--------------------------------\\n\" +\r\n                    \"%f lux\"\r\n                    ,event.values[0]\r\n                  );\r\n            txtResult.setText(r);\r\n        }\r\n    }\r\n    \r\n    \/**\r\n     * \u8fd1\u63a5\u30bb\u30f3\u30b5\u30fc\r\n     *\/\r\n    class ProximitySensorListener implements SensorEventListener {\r\n        @Override\r\n        public void onAccuracyChanged(Sensor sensor, int accuracy) {\r\n        }\r\n\r\n        @Override\r\n        public void onSensorChanged(SensorEvent event) {\r\n            String r = String.format(\r\n                    \"--------------------------------\\n\" + \r\n                    \"proximity sonsor\\n\"+\r\n                    \"--------------------------------\\n\" +\r\n                    \"%f cm\"\r\n                    ,event.values[0]\r\n                  );\r\n            txtResult.setText(r);\r\n        }\r\n        \r\n    }\r\n    \r\n    \/**\r\n     * @see http:\/\/developer.android.com\/reference\/android\/hardware\/SensorEvent.html\r\n     *\/\r\n    class SensorItem {\r\n        private int sensorType;\r\n        private String sensorName;\r\n        public SensorEventListener listener;\r\n        \r\n        public int getSensorType() {\r\n            return sensorType;\r\n        }\r\n\r\n        \/**\r\n         * \u30bb\u30f3\u30b5\u30fc\u3054\u3068\u306b\u30ea\u30b9\u30ca\u30fc\u3092\u751f\u6210\r\n         * @param sensorType\r\n         *\/\r\n        public void setSensorType(int sensorType) {\r\n            this.sensorType = sensorType;\r\n            \r\n            switch(this.sensorType) {\r\n            case Sensor.TYPE_ACCELEROMETER:\r\n                this.listener = new AccelerometerSensorListner();\r\n                break;\r\n            case Sensor.TYPE_ORIENTATION:\r\n                this.listener = new OrientationSensorListener();\r\n                break;\r\n            case Sensor.TYPE_MAGNETIC_FIELD:\r\n                this.listener = new MagneticFieldSensorListener();\r\n                break;\r\n            case Sensor.TYPE_LIGHT:\r\n                this.listener = new LightSensorListener();\r\n                break;\r\n            case Sensor.TYPE_PROXIMITY:\r\n                this.listener = new ProximitySensorListener();\r\n                break;\r\n            default:\r\n                this.listener = new SensorEventListener() {\r\n                    @Override\r\n                    public void onSensorChanged(SensorEvent event) {\r\n                    }\r\n                    @Override\r\n                    public void onAccuracyChanged(Sensor sensor, int accuracy) {\r\n                        txtResult.setText(\"No Sensor Listener.\");\r\n                    }\r\n                };\r\n                break;\r\n            }\r\n        }\r\n        public String getSensorName() {\r\n            return sensorName;\r\n        }\r\n        public void setSensorName(String sensorName) {\r\n            this.sensorName = sensorName;\r\n        }\r\n        @Override\r\n        public String toString() {\r\n            return getSensorName();\r\n        }\r\n    }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5b9f\u6a5f\u3092\u4f7f\u3063\u3066\u30c7\u30d0\u30c3\u30b0\u3059\u308b\u3053\u3068\u3092\u899a\u3048\u305f\u306e\u3067\u3001Desire \u306b\u642d\u8f09\u3055\u308c\u3066\u3044\u308b\u30bb\u30f3\u30b5\u30fc\u306e\u5024\u3092\u53d6\u5f97\u3057\u3066\u307f\u3088\u3046\u3002 http:\/\/developer.android.com\/reference\/android\/hardware\/Se [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"sns_share_botton_hide":"","vkExUnit_sns_title":"","_vk_print_noindex":"","sitemap_hide":"","_veu_custom_css":"","veu_display_promotion_alert":"","vkexunit_cta_each_option":"","footnotes":""},"categories":[39],"tags":[],"class_list":["post-223","post","type-post","status-publish","format-standard","hentry","category-android"],"veu_head_title_object":{"title":"","add_site_title":""},"_links":{"self":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/posts\/223","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=223"}],"version-history":[{"count":0,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/posts\/223\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=223"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=223"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=223"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}