User Tools

Site Tools


sample_code:hexview

Differences

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

Link to this comparison view

Next revision
Previous revision
sample_code:hexview [2015/07/13 00:58]
stevegarman created
sample_code:hexview [2015/07/30 05:17] (current)
Line 2: Line 2:
 ===== Sample code ===== ===== Sample code =====
 <code JavaScript hexView.js> <code JavaScript hexView.js>
 +var picker,view,hv={};
 //Called when application is started. //Called when application is started.
 function OnStart() function OnStart()
 { {
- 
-    var path="/sdcard/DroidScript/Hello World/Img/Hello World.png" 
     //Create a layout with objects vertically centered.     //Create a layout with objects vertically centered.
     var lay = app.CreateLayout( "linear", "Left" );       //Create a full screen scroller      var lay = app.CreateLayout( "linear", "Left" );       //Create a full screen scroller 
Line 17: Line 15:
     scroll.AddChild( layScroll );      scroll.AddChild( layScroll ); 
              
-    var view=app.CreateWebView(1.5,0.95);+    view=app.CreateWebView(1.5,0.95);
     layScroll.AddChild(view);     layScroll.AddChild(view);
  
     //Add layout to app.         //Add layout to app.    
     app.AddLayout( lay );     app.AddLayout( lay );
-    hexView(path,view);+    var path="/sdcard/DroidScript/Hello World/Img/Hello World.png"; 
 +    hexViewStart(path,view);
 } }
  
 +function hexViewStart(fullPath,webView)
 +{
 +  hv={chunksize:1024,path:fullPath};
 +  hv.webView=webView;
 +  hv.file = app.CreateFile( hv.path, "r" );
 +  hv.len = hv.file.GetLength(); 
 +  hv.html="<p>"+fullPath+"</p><table>\n";
 +  hv.file.Seek( 0 );
 +  app.ShowProgress("Loading");
 +  hexViewChunk();
 +}
  
-function hexView(fullPath,webView)+function hexViewChunk()
 { {
-  var file app.CreateFilefullPath, "r" ); +  var pos=hv.file.GetPointer(); 
-  var len file.GetLength(); +  var whole = hv.file.ReadData( hv.chunksize,"int" ); 
 +  if(whole == undefined) 
 +  { 
 +       hexViewEnd(); 
 +       return; 
 +  }
   var bull="&bull;";   var bull="&bull;";
-  var html="<p>"+fullPath+"</p><table>\n"; +  var int,hex,asc,hbuff,abuff,row;
-  var int,hex,asc,hbuff,abuff,row,pos=0; +
-  file.Seek( 0 ); +
-  app.ShowProgress("Loading"); +
-  var whole = file.ReadData( len,"int" );+
   do   do
   {   {
Line 42: Line 53:
     //var data = file.ReadData( 8,"int" );     //var data = file.ReadData( 8,"int" );
     if(data==undefined) break;     if(data==undefined) break;
-    len = data.length;+    var len = data.length;
     hbuff="";     hbuff="";
-    abuff="<td>";+    abuff="<td style='background-color:#ddffdd;'>";
     var pos8="<td>"+     var pos8="<td>"+
       ("00000000"+       ("00000000"+
Line 56: Line 67:
       if(int>31 && int<127)       if(int>31 && int<127)
          asc=String.fromCharCode(int);          asc=String.fromCharCode(int);
-      hbuff+="<td>"+hex.toUpperCase()+"</td>";+      if(asc=="<")asc="&lt;"; 
 +      hbuff+="<td>"+hex.toUpperCase()+"</td >";
       abuff+=asc;       abuff+=asc;
     }     }
     abuff+="</td>";     abuff+="</td>";
     row="<tr>"+pos8+hbuff+abuff+"</tr>";     row="<tr>"+pos8+hbuff+abuff+"</tr>";
-    html +=row+"\n";+    if(len>0) hv.html +=row+"\n";
     pos+=len;     pos+=len;
   }   }
   while(len > 0);   while(len > 0);
-   html+="</table>";+  setTimeout("hexViewChunk()",1); 
 +
 + 
 +function hexViewEnd() 
 +
 +  hv.html+="</table>";
   app.HideProgress();   app.HideProgress();
-  webView.LoadHtml(html); +  hv.webView.LoadHtml(hv.html); 
-  //alert(html); +  hv.file.Close(); 
-  file.Close();+
 + 
 +function pickit() 
 +
 +    if( ! picker ) 
 +    { 
 +       picker = new FilePicker(openit,"/"); 
 +       picker.SetFolder("/sdcard"); 
 +       picker.SetHideFiles(false); 
 +    } 
 +    picker.Show(picker); 
 +     
 +
 +function openit(pth) 
 +
 +     hexViewStart(pth,view);
 } }
  
  
 </code> </code>
sample_code/hexview.1436749097.txt.gz · Last modified: 2015/07/13 08:58 (external edit)