User Tools

Site Tools


sample_code:hexview

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

sample_code:hexview [2015/07/13 00:58]
stevegarman created
sample_code:hexview [2015/07/30 05:17]
Line 1: Line 1:
-====== File Hex Viewer ====== 
-===== Sample code ===== 
-<code JavaScript hexView.js> 
  
-//Called when application is started. 
-function OnStart() 
-{ 
- 
-    var path="/sdcard/DroidScript/Hello World/Img/Hello World.png" 
-    //Create a layout with objects vertically centered. 
-    var lay = app.CreateLayout( "linear", "Left" );       //Create a full screen scroller  
-    var scroll = app.CreateScroller( 1.0, 0.95 );  
-    lay.AddChild( scroll );  
-   
-    //Create a layout inside scroller.  
-    var layScroll = app.CreateLayout( "Linear", "Left" );  
-    scroll.AddChild( layScroll );  
-       
-    var view=app.CreateWebView(1.5,0.95); 
-    layScroll.AddChild(view); 
- 
-    //Add layout to app.     
-    app.AddLayout( lay ); 
-    hexView(path,view); 
-} 
- 
- 
-function hexView(fullPath,webView) 
-{ 
-  var file = app.CreateFile( fullPath, "r" ); 
-  var len = file.GetLength();  
-  var bull="&bull;"; 
-  var html="<p>"+fullPath+"</p><table>\n"; 
-  var int,hex,asc,hbuff,abuff,row,pos=0; 
-  file.Seek( 0 ); 
-  app.ShowProgress("Loading"); 
-  var whole = file.ReadData( len,"int" ); 
-  do 
-  { 
-    var data = whole.slice(0,8); 
-    whole=whole.slice(8); 
-    //var data = file.ReadData( 8,"int" ); 
-    if(data==undefined) break; 
-    len = data.length; 
-    hbuff=""; 
-    abuff="<td>"; 
-    var pos8="<td>"+ 
-      ("00000000"+ 
-      pos.toString(16)).slice(-8).toUpperCase() + 
-      "</td>"; 
-    for(var i=0;i<len;i++) 
-    { 
-      int=data[i]; 
-      hex=("0"+int.toString(16)).slice(-2); 
-      asc=bull; 
-      if(int>31 && int<127) 
-         asc=String.fromCharCode(int); 
-      hbuff+="<td>"+hex.toUpperCase()+"</td>"; 
-      abuff+=asc; 
-    } 
-    abuff+="</td>"; 
-    row="<tr>"+pos8+hbuff+abuff+"</tr>"; 
-    html +=row+"\n"; 
-    pos+=len; 
-  } 
-  while(len > 0); 
-   html+="</table>"; 
-  app.HideProgress(); 
-  webView.LoadHtml(html); 
-  //alert(html); 
-  file.Close(); 
-} 
- 
- 
-</code> 
sample_code/hexview.txt · Last modified: 2015/07/30 05:17 (external edit)