Advertisement
Guest User

pg

a guest
Nov 7th, 2014
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.17 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>jQuery Mobile Web App</title>
  6. <link href="jquery-mobile/jquery.mobile-1.0a3.min.css" rel="stylesheet" type="text/css"/>
  7. <script src="jquery-mobile/jquery-1.5.min.js" type="text/javascript"></script>
  8. <script src="jquery-mobile/jquery.mobile-1.0a3.min.js" type="text/javascript"></script>
  9. <!-- This reference to phonegap.js will allow for code hints as long as the current site has been configured as a mobile application.
  10. To configure the site as a mobile application, go to Site -> Mobile Applications -> Configure Application Framework... -->
  11. <script src="phonegap.js" type="text/javascript"></script>
  12. <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
  13. <script>
  14.  
  15. function onBodyLoad(){
  16. document.addEventListener("deviceready",onDeviceReady,false);
  17. document.addEventListener("online", onOnline, false);
  18. }
  19.  
  20.  
  21. function onDeviceReady(){
  22. navigator.notification.alert("PhoneGap is working");
  23. var height = $('#page4').height() - $('#page4 div[data-role="header"]').height();
  24. var width = $('#page4').width();
  25. $('#map_canvas').css({'height': height + 'px','width': width + 'px'});
  26. }
  27.  
  28. var watchID = null;
  29. function startWatch() {
  30. var options = { frequency: 200 };
  31.  
  32. var onSuccess = function(acceleration) {
  33. // Scale the accelerometer values from [0, 1] to [0, 100]
  34. // in order to display in the HTML range element
  35. $('#acceleration-x').val(acceleration.x * 100).slider('refresh');
  36. $('#acceleration-y').val(acceleration.y * 100).slider('refresh');
  37. $('#acceleration-z').val(acceleration.z * 100).slider('refresh');
  38. };
  39.  
  40. var onFail = function() {
  41. console.log('Failed to get acceleration');
  42. };
  43.  
  44. watchID = navigator.accelerometer.watchAcceleration(onSuccess, onFail, options);
  45. }
  46.  
  47. // Stop watching the acceleration
  48. function stopWatch() {
  49. if (watchID) {
  50. navigator.accelerometer.clearWatch(watchID);
  51. watchID = null;
  52. }
  53. }
  54.  
  55. function getPictureFromCamera(){
  56. navigator.camera.getPicture(onSuccess, onFail, { quality: 50, destinationType:Camera.DestinationType.FILE_URI });
  57.  
  58. function onSuccess(imageURI) {
  59. $('#camera-image').css({'background-image': 'url('+imageURI+')', 'background-size': '100%'});
  60. }
  61.  
  62. function onFail(message) {
  63. console.log('Failed to get an image');
  64. }
  65. }
  66.  
  67. function getPictureFromGallery(){
  68. navigator.camera.getPicture(onSuccess, onFail, { quality: 50, destinationType: Camera.DestinationType.FILE_URI, sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY });
  69.  
  70. function onSuccess(imageURI) {
  71. $('#camera-image').css({'background-image': 'url('+imageURI+')', 'background-size': '50%'});
  72. }
  73.  
  74. function onFail(message) {
  75. console.log('Failed to get an image');
  76. }
  77. }
  78.  
  79.  
  80.  
  81. function onLocSuccess(position) {
  82. console.log(position);
  83. var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
  84. var map = new google.maps.Map(document.getElementById("map_canvas"), {
  85. zoom: 12,
  86. center: latlng,
  87. mapTypeId: google.maps.MapTypeId.ROADMAP
  88. });
  89.  
  90. var marker = new google.maps.Marker({
  91. position: latlng,
  92. map: map,
  93. title: "You"
  94. });
  95. }
  96.  
  97. function onLocFail() {
  98. console.log('Failed to get geolocation');
  99. }
  100.  
  101. navigator.geolocation.getCurrentPosition(onLocSuccess, onLocFail);
  102.  
  103. </script>
  104. </head>
  105.  
  106. <body onload="onBodyLoad();">
  107.  
  108. <div data-role="page" id="page">
  109. <div data-role="header">
  110. <h1>Home</h1>
  111. </div>
  112. <div data-role="content">
  113. <ul data-role="listview">
  114. <li><a href="#page2">Accelerometer</a></li>
  115. <li><a href="#page3">Camera</a></li>
  116. <li><a href="#page4">Geolocation</a> </li>
  117. </ul>
  118. </div>
  119. </div>
  120.  
  121. <div data-role="page" id="page2">
  122. <div data-role="header">
  123. <h1>Accelerometer</h1>
  124. </div>
  125. <div data-role="content">
  126. <fieldset class="ui-grid-a">
  127. <div class="ui-block-a"><button type="button" data-theme="c" ontouchstart="startWatch();">Start</button></div>
  128. <div class="ui-block-b"><button type="button" data-theme="c" ontouchstart="stopWatch();">Stop</button></div>
  129. </fieldset>
  130.  
  131. <div data-role="fieldcontain">
  132. <label for="acceleration-x">Acceleration X:</label>
  133. <input type="range" name="acceleration-x" id="acceleration-x" value="0" min="0" max="100" />
  134. </div>
  135. <div data-role="fieldcontain">
  136. <label for="acceleration-y">Acceleration Y:</label>
  137. <input type="range" name="acceleration-y" id="acceleration-y" value="0" min="0" max="100" />
  138. </div>
  139. <div data-role="fieldcontain">
  140. <label for="acceleration-z">Acceleration Z:</label>
  141. <input type="range" name="acceleration-z" id="acceleration-z" value="0" min="0" max="100" />
  142. </div>
  143. </div>
  144. </div>
  145.  
  146. <div data-role="page" id="page3">
  147. <div data-role="header">
  148. <h1>Camera</h1>
  149.  
  150.  
  151. </div>
  152. <div data-role="content">
  153. <fieldset class="ui-grid-a">
  154. <div class="ui-block-a"><button type="button" data-theme="c" data-icon="plus" ontouchstart="getPictureFromCamera();">Camera</button></div>
  155. <div class="ui-block-b"><button type="button" data-theme="c" data-icon="search" ontouchstart="getPictureFromGallery();">Gallery</button></div>
  156. </fieldset>
  157. <div id="camera-image" class="ui-body ui-body-b" style="background-size:100%;min-height:250px"></div>
  158. </div>
  159. </div>
  160.  
  161. <div data-role="page" id="page4">
  162. <div data-role="header">
  163. <h1>Geolocation</h1>
  164. </div>
  165. <div data-role="content" style="padding:0px;">
  166. <div id="map_canvas" height="300px" width="300px"></div>
  167. </div>
  168. </div>
  169.  
  170. </body>
  171. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement