Advertisement
Guest User

Untitled

a guest
Sep 19th, 2013
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.96 KB | None | 0 0
  1. // Get the SensorManager
  2. mSensorManager= (SensorManager) getSystemService(SENSOR_SERVICE);
  3.  
  4. // List of Sensors Available
  5. List<Sensor> msensorList = mSensorManager.getSensorList(Sensor.TYPE_ALL);
  6.  
  7. // Print Sensor Details
  8. Sensor sens;
  9. int type,i;
  10. String text = new String("");
  11. // Do the list of available sensors on a String and print detail about each sensor
  12. for (i=0;i<msensorList.size();i++){
  13. sens = msensorList.get(i);
  14. type = sens.getType();
  15. text = " - "+getString(R.string.power)+" "+String.valueOf(sens.getPower())+"mAn";
  16. text+= " - "+getString(R.string.resolution)+" "+String.valueOf(sens.getResolution())+"n";
  17. text+= " - "+getString(R.string.maxrange)+" "+String.valueOf(sens.getMaximumRange ())+"n";
  18. text+= " - "+getString(R.string.vendor)+" "+sens.getVendor()+"n";
  19. text+= " - "+getString(R.string.version)+" "+String.valueOf(sens.getVersion());
  20. switch(type) { // Check the type of Sensor that generate the event and show is resolution
  21. case Sensor.TYPE_ACCELEROMETER:
  22. mTextAccTitle.setVisibility(0);
  23. mTextAccTitle.setMaxHeight(30);
  24. mTextAcc.setVisibility(0);
  25. mTextAcc.setMaxHeight(100);
  26. mTextAcc.setText(text); // Print data of the Sensor
  27. break;
  28. case Sensor.TYPE_GYROSCOPE:
  29. mTextGyrTitle.setVisibility(0);
  30. mTextGyr.setVisibility(0);
  31. mTextGyr.setText(text); // Print data of the Sensor
  32. break;
  33. case Sensor.TYPE_LIGHT:
  34. mTextLigTitle.setVisibility(0);
  35. mTextLig.setVisibility(0);
  36. mTextLig.setText(text); // Print data of the Sensor
  37. break;
  38. case Sensor.TYPE_MAGNETIC_FIELD:
  39. mTextMagTitle.setVisibility(0);
  40. mTextMag.setVisibility(0);
  41. mTextMag.setText(text); // Print data of the Sensor
  42. break;
  43. case Sensor.TYPE_ORIENTATION:
  44. mTextOriTitle.setVisibility(0);
  45. mTextOri.setVisibility(0);
  46. mTextOri.setText(text); // Print data of the Sensor
  47. break;
  48. case Sensor.TYPE_PRESSURE:
  49. mTextPreTitle.setVisibility(0);
  50. mTextPre.setVisibility(0);
  51. mTextPre.setText(text); // Print data of the Sensor
  52. break;
  53. case Sensor.TYPE_PROXIMITY:
  54. mTextProTitle.setVisibility(0);
  55. mTextPro.setVisibility(0);
  56. mTextPro.setText(text); // Print data of the Sensor
  57. break;
  58. case Sensor.TYPE_TEMPERATURE:
  59. mTextTemTitle.setVisibility(0);
  60. mTextTem.setVisibility(0);
  61. mTextTem.setText(text); // Print data of the Sensor
  62. break;
  63. }
  64. }
  65. }
  66. // Get the texts fields of the layout and setup to invisible
  67. void setTextViews(){
  68. mTextAccTitle = (TextView) findViewById(R.id.sensorAccTitle);
  69. mTextAccTitle.setVisibility(4);
  70. mTextAccTitle.setMaxHeight(0);
  71. mTextAcc = (TextView) findViewById(R.id.sensorAcc);
  72. mTextAcc.setMaxHeight(0);
  73. mTextAcc.setVisibility(4);
  74. mTextGyrTitle = (TextView) findViewById(R.id.sensorGyrTitle);
  75. mTextGyrTitle.setVisibility(4);
  76. mTextGyrTitle.setMaxHeight(0);
  77. mTextGyr = (TextView) findViewById(R.id.sensorGyr);
  78. mTextGyr.setVisibility(4);
  79. mTextGyrTitle.setMaxHeight(0);
  80. mTextLigTitle = (TextView) findViewById(R.id.sensorLigTitle);
  81. mTextLigTitle.setVisibility(4);
  82. mTextLigTitle.setMaxHeight(0);
  83. mTextLig = (TextView) findViewById(R.id.sensorLig);
  84. mTextLig.setVisibility(4);
  85. mTextLig.setMaxHeight(0);
  86. mTextMagTitle = (TextView) findViewById(R.id.sensorMagTitle);
  87. mTextMagTitle.setVisibility(4);
  88. mTextMagTitle.setMaxHeight(0);
  89. mTextMag = (TextView) findViewById(R.id.sensorMag);
  90. mTextMag.setVisibility(4);
  91. mTextMag.setMaxHeight(0);
  92. mTextOriTitle = (TextView) findViewById(R.id.sensorOriTitle);
  93. mTextOriTitle.setVisibility(4);
  94. mTextOriTitle.setMaxHeight(0);
  95. mTextOri = (TextView) findViewById(R.id.sensorOri);
  96. mTextOri.setVisibility(4);
  97. mTextOri.setMaxHeight(0);
  98. mTextPreTitle = (TextView) findViewById(R.id.sensorPreTitle);
  99. mTextPreTitle.setVisibility(4);
  100. mTextPreTitle.setMaxHeight(0);
  101. mTextPre = (TextView) findViewById(R.id.sensorPre);
  102. mTextPre.setVisibility(4);
  103. mTextPre.setMaxHeight(0);
  104. mTextProTitle = (TextView) findViewById(R.id.sensorProTitle);
  105. mTextProTitle.setVisibility(4);
  106. mTextProTitle.setMaxHeight(0);
  107. mTextPro = (TextView) findViewById(R.id.sensorPro);
  108. mTextPro.setVisibility(4);
  109. mTextPro.setMaxHeight(0);
  110. mTextTemTitle = (TextView) findViewById(R.id.sensorTemTitle);
  111. mTextTemTitle.setVisibility(4);
  112. mTextTemTitle.setMaxHeight(0);
  113. mTextTem = (TextView) findViewById(R.id.sensorTem);
  114. mTextTem.setVisibility(4);
  115. mTextTem.setMaxHeight(0);
  116. }
  117.  
  118. public class SensorInfo extends Activity {
  119. private SensorManager mSensorManager;
  120. TextView mTextAcc,mTextGyr,mTextLig,mTextMag,mTextOri,
  121. mTextPre,mTextPro,mTextTem,
  122. mSensorsTotTitle,mSensorAvailablesTitle,mTextAccTitle,mTextGyrTitle,mTextLigTitle,mTextMagTitle,mTextOriTitle,
  123. mTextPreTitle,mTextProTitle,mTextTemTitle;
  124. @Override
  125. public void onCreate(Bundle savedInstanceState) {
  126. super.onCreate(savedInstanceState);
  127. setContentView(R.layout.detaillayout);
  128. // Get the texts fields of the layout and setup to invisible
  129. setTextViews();
  130.  
  131. // Get the SensorManager
  132. mSensorManager= (SensorManager) getSystemService(SENSOR_SERVICE);
  133.  
  134. // List of Sensors Available
  135. List<Sensor> msensorList = mSensorManager.getSensorList(Sensor.TYPE_ALL);
  136.  
  137. // Print Sensor Details
  138. Sensor sens;
  139. int type,i;
  140. String text = new String("");
  141. // Do the list of available sensors on a String and print detail about each sensor
  142. for (i=0;i<msensorList.size();i++){
  143. sens = msensorList.get(i);
  144. type = sens.getType();
  145. text = " - "+getString(R.string.power)+" "+String.valueOf(sens.getPower())+"mAn";
  146. text+= " - "+getString(R.string.resolution)+" "+String.valueOf(sens.getResolution())+"n";
  147. text+= " - "+getString(R.string.maxrange)+" "+String.valueOf(sens.getMaximumRange ())+"n";
  148. text+= " - "+getString(R.string.vendor)+" "+sens.getVendor()+"n";
  149. text+= " - "+getString(R.string.version)+" "+String.valueOf(sens.getVersion());
  150. switch(type) { // Check the type of Sensor that generate the event and show is resolution
  151. case Sensor.TYPE_ACCELEROMETER:
  152. mTextAccTitle.setVisibility(0);
  153. mTextAccTitle.setMaxHeight(30);
  154. mTextAcc.setVisibility(0);
  155. mTextAcc.setMaxHeight(100);
  156. mTextAcc.setText(text); // Print data of the Sensor
  157. break;
  158. case Sensor.TYPE_GYROSCOPE:
  159. mTextGyrTitle.setVisibility(0);
  160. mTextGyrTitle.setMaxHeight(30);
  161. mTextGyr.setVisibility(0);
  162. mTextGyr.setMaxHeight(100);
  163. mTextGyr.setText(text); // Print data of the Sensor
  164. break;
  165. case Sensor.TYPE_LIGHT:
  166. mTextLigTitle.setVisibility(0);
  167. mTextLigTitle.setMaxHeight(30);
  168. mTextLig.setVisibility(0);
  169. mTextLig.setMaxHeight(100);
  170. mTextLig.setText(text); // Print data of the Sensor
  171. break;
  172. case Sensor.TYPE_MAGNETIC_FIELD:
  173. mTextMagTitle.setVisibility(0);
  174. mTextMagTitle.setMaxHeight(30);
  175. mTextMag.setVisibility(0);
  176. mTextMag.setMaxHeight(100);
  177. mTextMag.setText(text); // Print data of the Sensor
  178. break;
  179. case Sensor.TYPE_ORIENTATION:
  180. mTextOriTitle.setVisibility(0);
  181. mTextOriTitle.setMaxHeight(30);
  182. mTextOri.setVisibility(0);
  183. mTextOri.setMaxHeight(100);
  184. mTextOri.setText(text); // Print data of the Sensor
  185. break;
  186. case Sensor.TYPE_PRESSURE:
  187. mTextPreTitle.setVisibility(0);
  188. mTextPreTitle.setMaxHeight(30);
  189. mTextPre.setVisibility(0);
  190. mTextPre.setMaxHeight(100);
  191. mTextPre.setText(text); // Print data of the Sensor
  192. break;
  193. case Sensor.TYPE_PROXIMITY:
  194. mTextProTitle.setVisibility(0);
  195. mTextProTitle.setMaxHeight(30);
  196. mTextPro.setVisibility(0);
  197. mTextPro.setMaxHeight(100);
  198. mTextPro.setText(text); // Print data of the Sensor
  199. break;
  200. case Sensor.TYPE_TEMPERATURE:
  201. mTextTemTitle.setVisibility(0);
  202. mTextTemTitle.setMaxHeight(30);
  203. mTextTem.setVisibility(0);
  204. mTextTem.setMaxHeight(100);
  205. mTextTem.setText(text); // Print data of the Sensor
  206. break;
  207. }
  208. }
  209. }
  210. // Get the texts fields of the layout and setup to invisible
  211. void setTextViews(){
  212. mTextAccTitle = (TextView) findViewById(R.id.sensorAccTitle);
  213. mTextAccTitle.setVisibility(4);
  214. mTextAccTitle.setMaxHeight(0);
  215. mTextAcc = (TextView) findViewById(R.id.sensorAcc);
  216. mTextAcc.setMaxHeight(0);
  217. mTextAcc.setVisibility(4);
  218. mTextGyrTitle = (TextView) findViewById(R.id.sensorGyrTitle);
  219. mTextGyrTitle.setVisibility(4);
  220. mTextGyrTitle.setMaxHeight(0);
  221. mTextGyr = (TextView) findViewById(R.id.sensorGyr);
  222. mTextGyr.setVisibility(4);
  223. mTextGyrTitle.setMaxHeight(0);
  224. mTextLigTitle = (TextView) findViewById(R.id.sensorLigTitle);
  225. mTextLigTitle.setVisibility(4);
  226. mTextLigTitle.setMaxHeight(0);
  227. mTextLig = (TextView) findViewById(R.id.sensorLig);
  228. mTextLig.setVisibility(4);
  229. mTextLig.setMaxHeight(0);
  230. mTextMagTitle = (TextView) findViewById(R.id.sensorMagTitle);
  231. mTextMagTitle.setVisibility(4);
  232. mTextMagTitle.setMaxHeight(0);
  233. mTextMag = (TextView) findViewById(R.id.sensorMag);
  234. mTextMag.setVisibility(4);
  235. mTextMag.setMaxHeight(0);
  236. mTextOriTitle = (TextView) findViewById(R.id.sensorOriTitle);
  237. mTextOriTitle.setVisibility(4);
  238. mTextOriTitle.setMaxHeight(0);
  239. mTextOri = (TextView) findViewById(R.id.sensorOri);
  240. mTextOri.setVisibility(4);
  241. mTextOri.setMaxHeight(0);
  242. mTextPreTitle = (TextView) findViewById(R.id.sensorPreTitle);
  243. mTextPreTitle.setVisibility(4);
  244. mTextPreTitle.setMaxHeight(0);
  245. mTextPre = (TextView) findViewById(R.id.sensorPre);
  246. mTextPre.setVisibility(4);
  247. mTextPre.setMaxHeight(0);
  248. mTextProTitle = (TextView) findViewById(R.id.sensorProTitle);
  249. mTextProTitle.setVisibility(4);
  250. mTextProTitle.setMaxHeight(0);
  251. mTextPro = (TextView) findViewById(R.id.sensorPro);
  252. mTextPro.setVisibility(4);
  253. mTextPro.setMaxHeight(0);
  254. mTextTemTitle = (TextView) findViewById(R.id.sensorTemTitle);
  255. mTextTemTitle.setVisibility(4);
  256. mTextTemTitle.setMaxHeight(0);
  257. mTextTem = (TextView) findViewById(R.id.sensorTem);
  258. mTextTem.setVisibility(4);
  259. mTextTem.setMaxHeight(0);
  260. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement