[Sample App] - Sliding Menu and Action Bar

647 views
Skip to first unread message

Dave Smart

unread,
May 5, 2016, 7:58:02 AM5/5/16
to DroidScript
Hi Guys,

This is a template for creating apps with action bars and sliding menus (similar to the Gmail app).  It shows how to switch layouts ('pages') with both webview and native style pages included.

Regards
David
Sliding Menu.spk

Gerard Hernandez

unread,
May 5, 2016, 10:38:10 AM5/5/16
to DroidScript
Thanks Dave,k this will be quite useful to make more appealing apps.

Manuel Lopes

unread,
May 5, 2016, 6:19:26 PM5/5/16
to DroidScript
thanks dave

Karym Metwally

unread,
Oct 11, 2016, 5:56:46 AM10/11/16
to DroidScript
Thanks

Brad Yoch

unread,
Mar 28, 2018, 3:19:50 AM3/28/18
to DroidScript
Something is going wrong with it. It won't change the web view back to main.
My Android version is 23

MyScripts

unread,
Aug 5, 2020, 10:45:24 PM8/5/20
to DroidScript
Script Error func.apply is not a function!
Source: file:///android_asset/app.js
Line: 1631

Symbroson

unread,
Aug 7, 2020, 6:36:18 AM8/7/20
to DroidScript
You can fix that easily by changing the _Cbm thing to a regular anonymous callback argument

Steve Garman

unread,
Aug 7, 2020, 6:49:11 AM8/7/20
to DroidScript
In case Symbroson's suggestion was not entirely clear.
Go to Panel.js and change

this.layBack.SetOnTouch( _Cb(this,"OnTouch" ) );

to

this.layBack.SetOnTouch( this.OnTouch );

Steve Garman

unread,
Aug 7, 2020, 7:49:26 AM8/7/20
to DroidScript
Sorry, I posted untested code.
It will remove the error but it won't dismiss the menu.

Try this instead

this.layBack.SetOnTouch( function( ) {
_this.OnTouch();
});

Kallikratidas

unread,
Aug 7, 2020, 12:01:53 PM8/7/20
to DroidScript
WebView error _Run is not defined.

Alan Hendry

unread,
Aug 21, 2021, 11:25:25 AM8/21/21
to DroidScript
Hi,
I don't get the 3rd error
WebView error _Run is not defined.
(Android 11 go, DS 2.09)
This was posted a year ago, has anyone done any more work on it?
Specifically I'd like to have multiple  menus 
(like the DS edit page with drop-downs for the list of files, and the three vertical dots icon
and/or the pop-up menus when long-touching icons on the DS home page).
Somewhere I ran across a DS app that listed what was in one of the js files included in DS,
but I've forgotten where it was. Can some-one remind me?
Regards, ah

Steve Garman

unread,
Aug 21, 2021, 2:19:00 PM8/21/21
to DroidScript
"use strict"
var gTxeSearch, gCode, gLower
var gFile = "/Sys/DroidScript.js"
function OnStart()
{
   var lay = app.CreateLayout("linear", "VCenter, FillXY")
   var layH = app.AddLayout(lay, "linear", "Horizontal")
   gTxeSearch = app.AddTextEdit(layH, "", 0.8);
   gTxeSearch.SetHint("Search")
   var btnSearch = app.AddButton(layH, "\uf00e", -1, -1,
      "fontAwesome")
   btnSearch.SetOnLongTouch();
   btnSearch.SetOnTouch(btnSearch_OnTouch);
   scroll = app.AddScroller(lay, 1, -1)

   var cont = app.ReadFile( gFile );
   gCode = app.CreateTextEdit(cont, -
      1, -1, "left,readonly,noKeyboard")
   scroll.AddChild(gCode)

   app.AddLayout(lay)
   gLower = cont.toLowerCase()
}

//Called when the search button is pressed
function btnSearch_OnTouch()
{
   var searchText = gTxeSearch.GetText()
   if(searchText === "") return
   var pause = doFind(searchText, gCode)
   if(this === gTxeSearch)
   {
      this.Focus()
      app.ShowKeyboard(this)
   }
}

function doFind(sought, thisedt, repeating)
{
   app.HideKeyboard();
   //thisedt = textEdit to be searched.
   //sought = string to be searched for.
   //both toLowerCase for case-insensitive search
   sought = sought.toLowerCase()
      //current cursor position is start for search
   var curs = thisedt.GetCursorPos();
   if(repeating) curs = -1
      //only compare against the searchable range
   var lc = gLower.slice(curs + 1)
      // try to find next occurence of sought
   var pos = lc.indexOf(sought); //string version
   //var pos = lc.search(sought);    //regex version
   if(pos > -1)
   {
      //we found it
      pos = pos + curs + 1
      thisedt.SetCursorPos(pos)
      thisedt.SetSelection(pos, pos + sought.length);
      var s = "Line:" + thisedt.GetCursorLine();
      app.ShowPopup(s, "short,bottom");
   }
   else
   {
      //not found - go to start of text
      //then search again once
      thisedt.SetCursorPos(0)
      thisedt.SetSelection(0, 0)
      if(!repeating) doFind(sought, thisedt, true)
      else app.ShowPopup("Not found", "bottom")
   }
   return ""
}  ///

Alan Hendry

unread,
Dec 3, 2021, 9:31:42 AM12/3/21
to DroidScript
HI,
This takes a while to load and search, could progress be shown?
(i keep thinking that it's stuck).
Not sure if the scroller is needed.
Eliminating slice and using start position on indexOf may speed up search.
Could it be modified so that gTxeSearch OnEnter starts the search?
(I keep pressing enter, then realise it doesn't initiate search, then backspace and click icon).
Regards, ah

Alan Hendry

unread,
Dec 4, 2021, 11:03:59 AM12/4/21
to DroidScript
I've added progress, and used indexOf start position instead of slice (see /// commented code).
It loads and searches in about 5 seconds.
Scroller allows "flicks" to scroll quickly (so left in).
Can't get OnEnter to search.
There's also a commented line of code to use regular expressions
   //var pos = lc.search(sought);    //regex version
AFAIK it can't use start position (but a case insensitive rexexp could avoid convertng to lower  case).
Regards, ah

"use strict"
var gTxeSearch, gCode, gLower, gFile = "/Sys/DroidScript.js"
 
function OnStart() {
    app.ShowProgress( "Loading" )
    app.SetDebug( false )
   var lay = app.CreateLayout("linear", "VCenter, FillXY")
   var layH = app.AddLayout(lay, "linear", "Horizontal")
   var bou = app.GetTextBounds( "WW",32 ).width
   gTxeSearch = app.AddTextEdit(layH, "", 1-bou);
   gTxeSearch.SetHint("Search")
   var btnSearch = app.AddButton(layH, "\uf00e", -1, -1,"fontAwesome")
   btnSearch.SetOnLongTouch();
   btnSearch.SetOnTouch(btnSearch_OnTouch);
   scroll = app.AddScroller(lay, 1, -1)
 
   var cont = app.ReadFile( gFile );
   gCode = app.CreateTextEdit(cont, -1, -1, "left,readonly,noKeyboard,nospell")
   scroll.AddChild(gCode)
 
   app.AddLayout(lay)
   gLower = cont.toLowerCase()
   app.HideProgress()
}
 
//Called when the search button is pressed
function btnSearch_OnTouch() {
   var searchText = gTxeSearch.GetText()
   if(searchText === "") return
   var pause = doFind(searchText, gCode)
   if(this === gTxeSearch) {
      this.Focus()
      app.ShowKeyboard(this)
   }
}
 
function doFind(sought, thisedt, repeating) {
app.ShowProgress( "Searching") 
   app.HideKeyboard();
   //thisedt = textEdit to be searched.
   //sought = string to be searched for.
   //both toLowerCase for case-insensitive search
   sought = sought.toLowerCase()
      //current cursor position is start for search
   var curs = thisedt.GetCursorPos()
   if(repeating) curs = -1
      //only compare against the searchable range
///   var lc = gLower.slice(curs + 1)
      // try to find next occurence of sought
///   var pos = lc.indexOf(sought); //string version
var pos=gLower.indexOf(sought,curs+1)
   //var pos = lc.search(sought);    //regex version
   if(pos > -1) {
      //we found it
///      pos = pos + curs + 1
      thisedt.SetCursorPos(pos)
      thisedt.SetSelection(pos, pos + sought.length)
      var s = "Line:" + thisedt.GetCursorLine()
      app.ShowPopup(s, "short,bottom")
   }  else {
      //not found - go to start of text
      //then search again once
      thisedt.SetCursorPos(0)
      thisedt.SetSelection(0, 0)
      if(!repeating) doFind(sought, thisedt, true)
      else app.ShowPopup("Not found", "bottom")
   }
   app.HideProgress()
   return ""
}

Alan Hendry

unread,
Dec 16, 2021, 7:49:07 AM12/16/21
to DroidScript
HI,
I've modified to search on pressing enter key.
   gTxeSearch = app.AddTextEdit(layH, "", 1-bou,-1,"SingleLine")
   gTxeSearch.SetHint("Search")
   gTxeSearch.SetOnEnter( function() {app.SimulateTouch( btnSearch ) ;})
Not sure what this was for, so commented out
///   btnSearch.SetOnLongTouch(); 
And this
///   if(this === gTxeSearch) {
///      this.Focus()
///      app.ShowKeyboard(this)
///   }
Here the doFind result was ignored
      if(!repeating) doFind(sought, thisedt, true)
So changed the other invocation
///   var pause = doFind(searchText, gCode)
   doFind(searchText, gCode)
And removed the return of empty string
///   return ""

Considering writing a Premium version 
using CreateCodeEdit and Search method (may search quicker, 
and includes matchCase so removing  cont.toLowerCase() should speed up initial set up) 

Regards, ah

"use strict"
var gTxeSearch, gCode, gLower, gFile = "/Sys/DroidScript.js"
 
function OnStart() {
   app.ShowProgress( "Loading" )
   app.SetDebug( false )
   var lay = app.CreateLayout("linear", "VCenter, FillXY")
   var layH = app.AddLayout(lay, "linear", "Horizontal")
   var bou = app.GetTextBounds( "WW",32 ).width
   gTxeSearch = app.AddTextEdit(layH, "", 1-bou,-1,"SingleLine")
   gTxeSearch.SetHint("Search")
   gTxeSearch.SetOnEnter( function() {app.SimulateTouch( btnSearch ) ;})

   var btnSearch = app.AddButton(layH, "\uf00e", -1, -1,"fontAwesome")
//   btnSearch.SetOnLongTouch();

   btnSearch.SetOnTouch(btnSearch_OnTouch)
   scroll = app.AddScroller(lay, 1, -1)
 
   var cont = app.ReadFile( gFile )
   gCode = app.CreateTextEdit(cont, -1, -1, "left,readonly,noKeyboard,nospell")
   scroll.AddChild(gCode)
 
   app.AddLayout(lay)
   gLower = cont.toLowerCase()
   app.HideProgress()
}
 
//Called when the search button is pressed
function btnSearch_OnTouch() {
   var searchText = gTxeSearch.GetText()
   if(searchText === "") return
///   var pause = doFind(searchText, gCode)
   doFind(searchText, gCode)
//   if(this === gTxeSearch) {
//      this.Focus()
//      app.ShowKeyboard(this)
//   }
///   return ""
}

Alan Hendry

unread,
Dec 28, 2021, 4:56:28 PM12/28/21
to DroidScript
HI,
If you have a run-time error then DS usually selects the line in error and scrolls to it
But sometimes it doesn't (mainly when the error is in a separate script file).
The error message tells you what file and line number, but counting the lines is a pain.
I've made further mods to the codeviewer app. 
You have to specify the folder and file name before you run it, 
then you can type in a line number and it'll highlight the line and scroll there.
The line is copied to the clipboard (so you can go to DS edit and find the line of code). 
If there is interest then I can look at allowing the user to choose the folder and file.
There's no validation that the line number you type is numeric.
Regards, ah

"use strict"
var folder = "XeF6 Camera Remote Copy"
var file = "XeF6 Camera Remote Copy.js"
var gFile = app.GetAppPath()+"/../"+folder+"/"+file
//alert(gFile)
var gTxeSearch, gCode, gLower, lno

function OnStart() {
   app.ShowProgress( "Loading" )
   app.SetDebug( false )
   var lay = app.CreateLayout("linear", "VCenter, FillXY")
   var layH = app.AddLayout(lay, "linear", "Horizontal")
   var bou = app.GetTextBounds( "WW",32 ).width
   gTxeSearch = app.AddTextEdit(layH, "", 0.5-bou,-1,"SingleLine")

   gTxeSearch.SetHint("Search")
   gTxeSearch.SetOnEnter( function() {app.SimulateTouch( btnSearch ) ;})
   var btnSearch = app.AddButton(layH, "\uf00e", -1, -1,"fontAwesome")
   btnSearch.SetOnTouch(btnSearch_OnTouch)
   lno= app.AddTextEdit(layH, "", 0.5-bou,-1,"SingleLine")
   lno.SetHint("Line No")
   lno.SetOnEnter( function() {
      var q = Number(this.GetText()) - 1
      var r = gCode.GetLineStart(q)
      var s = gCode.GetLineStart(q+1)
      gCode.SetCursorPos(r)
      gCode.SetSelection(r,s)
      var tardis = gCode.GetSelectedText()
      app.SetClipboardText(tardis)

   })

   scroll = app.AddScroller(lay, 1, -1)
   var cont = app.ReadFile( gFile )
   gCode = app.CreateTextEdit(cont, -1, -1, "left,readonly,noKeyboard,nospell")
   scroll.AddChild(gCode)
 
   app.AddLayout(lay)
   gLower = cont.toLowerCase() // lower case for search

   app.HideProgress()
}
 
//Called when the search button is pressed
function btnSearch_OnTouch() {
   var searchText = gTxeSearch.GetText()
   if(searchText === "") return
///   var pause = doFind(searchText, gCode)
   doFind(searchText, gCode)
}
 
function doFind(sought, thisedt, repeating) {
   app.ShowProgress( "Searching")
   app.HideKeyboard()
   //sought = string to be searched for.
   //thisedt = textEdit to be searched.
   sought = sought.toLowerCase() // lower case for search

   //current cursor position is start for search
   var curs = thisedt.GetCursorPos()
   if(repeating) curs = -1
  //only compare against the searchable range
  // try to find next occurence of sought
   var pos=gLower.indexOf(sought,curs+1)
   //var pos = lc.search(sought);    //regex version
   if(pos > -1) {
      //we found it

Right2TheV0id

unread,
Mar 19, 2023, 1:56:04 PM3/19/23
to DroidScript
Here's a working version of the Sliding Menu Sample adapted to DS 2.57.
I fixed "It won't change the web view back to main" pointed out by Brad Yoch by removing the setTimeout in the OnFadeOut function.

Sample_Sliding Menu.spk
Reply all
Reply to author
Forward
0 new messages