DroidScript wiki

(was AndroidScript) unofficial documentation by the community

User Tools

Site Tools


Sidebar

News

Version1.42 is out since December 2nd 2016


Frequently Asked Questions


Namespaces

Note for contributors

If you wish to create a new page in the DroidScript wiki, please click on the most appropriate namespace above and follow the notes for contributors there.

Because of spam, it has been necessary to add a CAPTCHA to the registration form and the save option for editing pages. You will not need to prove you are human if you are logged in, so please register.

Please feel free to improve any existing page, as well as adding new pages to increase the sum of public knowledge about DroidScript.

Formatting Syntax

sample_code:hexview

File Hex Viewer

Sample code

hexView.js
var picker,view,hv={};
//Called when application is started.
function OnStart()
{
    //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 ); 
      
    view=app.CreateWebView(1.5,0.95);
    layScroll.AddChild(view);
 
    //Add layout to app.    
    app.AddLayout( lay );
    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 hexViewChunk()
{
  var pos=hv.file.GetPointer();
  var whole = hv.file.ReadData( hv.chunksize,"int" );
  if(whole == undefined)
  {
       hexViewEnd();
       return;
  }
  var bull="&bull;";
  var int,hex,asc,hbuff,abuff,row;
  do
  {
    var data = whole.slice(0,8);
    whole=whole.slice(8);
    //var data = file.ReadData( 8,"int" );
    if(data==undefined) break;
    var len = data.length;
    hbuff="";
    abuff="<td style='background-color:#ddffdd;'>";
    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);
      if(asc=="<")asc="&lt;";
      hbuff+="<td>"+hex.toUpperCase()+"</td >";
      abuff+=asc;
    }
    abuff+="</td>";
    row="<tr>"+pos8+hbuff+abuff+"</tr>";
    if(len>0) hv.html +=row+"\n";
    pos+=len;
  }
  while(len > 0);
  setTimeout("hexViewChunk()",1);
}
 
function hexViewEnd()
{
  hv.html+="</table>";
  app.HideProgress();
  hv.webView.LoadHtml(hv.html);
  hv.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);
}
sample_code/hexview.txt · Last modified: 2015/07/29 21:17 by stevegarman