Long press does not call a menu

435 views
Skip to first unread message

Thiemo Melhorn

unread,
Jun 5, 2023, 3:02:12 PM6/5/23
to DroidScript
When I press on an element of a web page, it just shows an "error" and when you press "Ok" my app continues to run. Alan doesn't get the problem fixed either, even though he tries really hard. 

(You can see the "error" on the screenshot below.)
IMG_20230605_205759_916.jpg

Testbrowser.spk

Dave

unread,
Jun 8, 2023, 9:34:31 AM6/8/23
to DroidScript
Have you tried adding the 'IgnoreErrors' option to the app.CreateWebView() method?
Message has been deleted

Thiemo Melhorn

unread,
Jun 9, 2023, 8:11:51 PM6/9/23
to DroidScript

No, because I do not know where to specify with.

Cemal

unread,
Jun 13, 2023, 5:45:01 AM6/13/23
to DroidScript
app.CreateWebView( 1, 1, "IgnoreErrors" );

Thiemo Melhorn

unread,
Jun 13, 2023, 2:16:54 PM6/13/23
to DroidScript
Somehow this does not work for me.

cfg.Dark
app.Script("lang.js")

const qactive="#cccccc", qinactive="#333333", qneutral="#999999" // colours for tabs
var transparent = "#00000000";
var qbuts = [], qlays = [], qcurrent=0 // tabs buttons, layouts, current tab
var qwebs=[], qtxts=[], qcnt=-1 // webviews, text inputs, tab count, closed tabs
var qback=[], qfwrd=[] // back and forward buttons
var lstFavs // for favourites
var ttls = []
var layDrawer = app.CreateLayout( "Linear" )
var layDrawerR = app.CreateLayout( "Linear", "fillxy")
var fileurl = "https://thiemo.vweb01.partarum.de/programmieren/apk/tmBrowser.apk";
var fldr = app.GetSpecialFolder("Downloads" )
var file = "tmBrowser.apk";
var dip = 1.0 / app.GetDisplayHeight() * app.GetScreenDensity() / 160;
var dlgWidth = 0.85;
var dlgHeight = 0.85;
var packageName = "com.myname.tmBrowser";
var className = "com.myname.tmBrowser.MainActivity";
var action = "android.intent.action.VIEW";
var category = "android.intent.category.BROWSABLE";
var uri = "http, https";
var type = "text";

app.SendIntent(packageName, className, action, category);
app.SendIntent(null,null,"android.intent.category.DEFAULT")

function OnStart() {
//app.ClearData( )
splashlay  = app.CreateLayout( "linear", "VCenter,FillXY" );
    logo = app.CreateImage( "Img/tmBrowser.png",0.4,-1 )
splashlay.AddChild( logo )
app.AddLayout( splashlay );

setTimeout(function(){
    app.DestroyLayout( splashlay )
  },1500)
 
    app.SetOrientation("portait")
    app.EnableBackKey(false)
    lay = app.CreateLayout( "Linear", "Vertical,FillXY,Left" )
//  scroller for tab buttons
    scroll = app.CreateScroller(1,-1,"Horizontal")
    lay.AddChild(scroll)
    horiz1 = app.CreateLayout( "Linear","Horizontal,Left" )
    scroll.AddChild(horiz1)
//  Layout toolbar
    horiz2 = app.CreateLayout( "Linear", "Horizontal", "VCenter")
    lay.AddChild( horiz2 )
//  default url
    defaultUrl = app.LoadText("defaultUrl","about:blank")
//  blank html
    defaultHtml = GetNewTabHtmlCode()
// left hand drawer
    CreateDrawer();
// right hand drawer
    CreateDrawerR();
//  dialog top confirm fav delete
    yndDelete = app.CreateYesNoDialog("Soll dieses Seite als Lesezeichen wirklich gelöscht werden?")
    yndDelete.SetOnTouch(confirmFavDelete)
//  dialog top confirm history delete
    yndDelete2 = app.CreateYesNoDialog("Soll dieser Verlauf wirklich gelöscht werden?")
    yndDelete2.SetOnTouch(confirmHisDelete)
// buttons to open drawers
    var more = newButton(horiz2,"[fa-bars]")
    more.SetOnTouch( function() {app.OpenDrawer("left");} );
//  button to add tab for blank page
    t2 = newButton(horiz2,"[fa-plus]");
    t2.SetOnTouch(function () {newtab("about:blank");})
// Tab close
     clost = newButton(horiz2,"[fa-close]")
    clost.SetOnTouch(qclose)
// button to add to favourites
    var addfav = newButton(horiz2, "[fa-star-o]")
    addfav.SetOnTouch( AddFavorites_OnTouch );
// History
    var tory = newButton(horiz2,"[fa-h-square]")  
    tory.SetOnTouch( function() {histdlg.Show();} );
// Reload Button
    rld = newButton(horiz2,"[fa-refresh]")
    rld.SetOnTouch(function() {qwebs[qcurrent].Reload();})
//  search url
    searchUrl = app.LoadText("searchUrl","https://www.google.com/search?q=")
// load saved tabs (if any)
   temp = app.LoadText("temp","")
   temp2 = app.LoadText("ttls","")
   if (temp == "") {
        newtab()
   } else {
       urls = JSON.parse(temp)
       ttls = JSON.parse(temp2)
       urls.forEach(function (current) {newtab(current);} )
   }
    qbuts[0].GetParent().SetBackColor(qneutral)
    qbuts[0].SetTextColor(clrTxt)
    qlays[0].Show()
    if (qtxts[0].GetText() == "about:blank") {
        qwebs[0].LoadHtml(defaultHtml);
    } else {
        qwebs[0].LoadUrl(qtxts[0].GetText());
    }
   
     speech = app.CreateSpeechRec();
    speech.SetOnReady ( speech_OnReady );
    speech.SetOnResult( speech_OnResult );
   
    web.SetOnUrl( web_OnUrl );
   
    //Create history dialog
    histdlg = app.CreateDialog(qhist)
    histlay = app.CreateLayout("linear", "VCenter,FillXY")
    histdlg.AddLayout(histlay)
    var toolbar = app.AddLayout(histlay,"linear","horizontal") ; use=toolbar
    var closed = newButton( toolbar, qshut + "  | [fa-close]")
    closed.SetOnTouch( function() {histdlg.Hide();})
    var deleteHistory = newButton( toolbar, "[fa-trash]" )
    deleteHistory.SetOnTouch(function() {yndDelete2.Show();})
    var text = "<p>Hier können Sie die besuchten Seiten anschauen, " +
    "die Sie zuvor besucht haben.</p>";
    txt = app.CreateText( text, 0.9, -1, "Html,Link" )
    histlay.AddChild( txt )
    histlst = app.AddList(histlay,"",0.9)
    histlst.SetOnTouch(function (title,body,icon,index) {
        newtab(title,body);
    })
   
    //Create notes dialog
    notesdlg = app.CreateDialog("Copyright:")
    layNotes = app.CreateLayout("linear", "VCenter,FillXY" )
    notesdlg.AddLayout(layNotes)
    var toolbar = app.AddLayout(layNotes,"linear","horizontal") ; use=toolbar
    var closed = newButton( toolbar, qshut + " | [fa-close]")
    closed.SetOnTouch( function() {notesdlg.Hide();})
    var text = "Thiemo Melhorn"
    txt = app.CreateText( text, 0.8, -1, "Html,Link" )
    layNotes.AddChild( txt )
    var text = "Right2TheV0id"
    txt = app.CreateText( text, 0.8, -1, "Html,Link" )
    layNotes.AddChild( txt )
    var text = "Alan Hendry"
    txt = app.CreateText( text, 0.8, -1, "Html,Link" )
    layNotes.AddChild( txt )
    mwdsh = app.AddImage(layNotes,"Img/mwdsh.png",0.5)
    mwdsh.SetOnTouchDown(function () {app.OpenUrl("https://droidscript.org/")})
   
   //Create dialog window.
    dialog = app.CreateDialog( qsettings);
var layDlg = app.CreateLayout( "linear", "Top,FillXY" );
layDlg.SetSize( dlgWidth, dlgHeight );
dialog.AddLayout( layDlg );

   //Button ok
    btnOk = newButton( layDlg, qshut +  " | [fa-close]")
    btnOk.SetOnTouch( btnOk_OnTouch );
   
    var tabs = app.CreateTabs( "Allgemein,Design,Updates", dlgWidth, dlgHeight - 48 * dip, "Top" )
    layDlg.AddChild( tabs )
   
    var layAllgemein = tabs.GetLayout( "Allgemein" );
    var layScrollerAllgemein = createContainer( layAllgemein );
    var text = "Hintergrundfarbe auswählen";
    txt = app.CreateText( text )
    layAllgemein.AddChild( txt )
    var pollux = app.AddLayout(layAllgemein,"linear","horizontal")  
    pollux.SetChildTextSize(12)
    item = app.LoadText( "item", "Schwarz" );
    clrBg = app.LoadText( "clrBg", "black" );
    clrTxt = app.LoadText( "clrTxt", "white" );
    var lstColors = app.AddSpinner( pollux,"Schwarz,Weiss,Blau" )
    lstColors.SelectItem( item )
    lstColors.SetOnChange( lstColors_OnTouch )
   
    var text = "Startseite festlegen";
    txt = app.CreateText( text )
    layAllgemein.AddChild( txt )
    var home = app.AddTextEdit( layAllgemein,defaultUrl,0.8,"Autosize")
        var save = newButton( layAllgemein,"[fa-save]")
        save.SetOnTouch(function () {
        defaultUrl=home.GetText()
        app.SaveText("defaultUrl",defaultUrl)
        app.ShowPopup("Startseite geändert!")
    })

    var text = "Suchmaschinen auswählen";
    txt = app.CreateText( text)
    layAllgemein.AddChild( txt )
    var data = "Google:[fa-google],Yahoo:[fa-yahoo],Bing:[fa-windows],Brave Search:[fa-bitcoin],Neeva:[fa-deafness]";
    lst = app.CreateList( data, 0.7, 0.4 );
    layAllgemein.AddChild( lst )
    lst.SetOnTouch(function (title,body,icon,index) {
        if (title == "Google") searchUrl = "https://www.google.com/search?q="
        if (title == "Yahoo") searchUrl = "https://www.search.yahoo.com/search?q="
        if (title == "Bing") searchUrl = "https://www.bing.com/search?q="
        if (title == "Brave Search") searchUrl = "https://search.brave.com/search?q="
        if (title == "Neeva") searchUrl = "https://neeva.com/search?q="
        app.SaveText("searchUrl",searchUrl)
    })
   
    var layUpdates = tabs.GetLayout( "Updates" )
    var layScrollerUpdates = createContainer( layUpdates );
    var text = "Manuelles Update";
    txt = app.CreateText( text)
    layUpdates.AddChild( txt )
    btnUpdates = app.AddButton( layUpdates,"Überprüfen von Updates" );
    btnUpdates.SetMargins( 0, 0.01, 0, 0 )
    btnUpdates.SetOnTouch( btnUpdates_OnTouch );
    layUpdates.AddChild( btnUpdates );
   
    layDrawer.SetBackColor( clrBg )
    layDrawerR.SetBackColor(clrBg)
    app.SetBackColor(clrBg)
   
 setcolors()
   
//Add layout to app.
app.AddLayout( lay )

   // get youtube app
    l = ""
    var list =app.GetActivities();    
    for(var i in list) {
        var a = list[i];
           l = a.label ;
           p = a.packageName ;
           c = a.className ;
          if (p.indexOf("youtube") > -1) {break;}
       }
}

function OnConfig() {
     if (app.GetOrientation() == "Landscape") {
        qwebs.forEach (function (current,idx) {
           current.SetSize(1,0.75)
           qtxts[idx].SetSize(0.6)
        })
     } else {
        qwebs.forEach (function (current,idx) {
           current.SetSize(1,0.75)
           qtxts[idx].SetSize(0.6)
         })
      }
 }
 
function OnBack() {
    urls=[]
    ttls = []
    qwebs.forEach (function (current,idx) {
        if (current.GetVisibility() == "Show" && current.GetUrl() != "") {
            ign=urls.push(current.GetUrl())
            ign=ttls.push(qbuts[idx].GetText())
        }
    })
    temp = JSON.stringify(urls) // save urls
    app.SaveText("temp",temp)
    temp2 = JSON.stringify(ttls) // save titles
    app.SaveText("ttls",temp2)
    var favs = lstFavs.GetList() // save favourites
    app.SaveJson("favs",favs)
    app.Exit()
}

function progress (percent) { // webpage loading
    if( percent === 100 ) {
        idx = qcurrent
        if (typeof this != "undefined" && typeof this.data != "undefined" && typeof this.data.qidx != "undefined") idx = this.data.qidx;
        qwebs[idx].Execute( "document.title", M( qbuts[idx], function( result ) { this.SetText( result.substring(0,50) ); } ) );
        qtxts[idx].SetText( qwebs[idx].GetUrl() );
        histlst.AddItem(qwebs[idx].GetUrl(),qbuts[idx].GetText())
        if (qwebs[idx].CanGoBack()) {qback[idx].Show();} else {qback[idx].Hide();}
        if (qwebs[idx].CanGoForward()) {qfwrd[idx].Show();} else {qfwrd[idx].Hide();}
     }
}

function newtab (url) { // new tab
        qcnt+=1
        if (typeof url == "undefined") {
            url = ""
            url = defaultUrl
            ttl = "Laden"
        } else ttl = ttls[qcnt]
        but5=qaddbut(horiz1,ttl,qcnt)
        tab5=qaddlay(lay,qcnt)
        horiz3 = app.AddLayout(tab5,"linear","horizontal") ; use=horiz3
        var home = newButton(use,"[fa-home]")  
        home.SetOnTouch( function() {qwebs[qcurrent].LoadUrl(defaultUrl);} );
        back = newButton(use,"[fa-arrow-left]")
        back.SetOnTouch(function() {qwebs[qcurrent].Back();})
        qback[qcnt] = back
        txt = app.AddTextEdit(use,url,0.5,-1,"SingleLine")
        txt.SetOnEnter(function () {qwebs[qcurrent].LoadUrl(this.GetText());})
        qtxts[qcnt]=txt
        fwrd = newButton(use,"[fa-arrow-right]")
        fwrd.SetOnTouch(function () {qwebs[qcurrent].Forward();})
        qfwrd[qcnt] = fwrd
        web = app.AddWebView(tab5,1,0.75, "NoLongTouch,NoActionBar") // full screen width, 0.75 screen height
        web.SetOnError(function(msg) {alert(msg);}) /// web error
        web.SetOnError(function(msg) {
            if (msg == "ERR_FILE_NOT_FOUND") {
                this.LoadUrl(searchUrl + qtxts[qcurrent].GetText())
            } else {
                app.ShowPopup(msg,"short")
            }
        })
        web.SetOnUrl(function (url) {progress(100);this.LoadUrl(url);})
        web.SetOnProgress(progress)
        web.data.qidx = qcnt
        qwebs[qcnt] = web
        if (ttl = "Laden") app.SimulateTouch(but5,0,0,"Up") // open tab
}

function web_OnUrl( url )
{
    app.Debug( "requested url = " + url );
   
    if( url.split( "." ).pop().toLowerCase() === "pdf" )
    {
        DownloadFile( url );
    }
    else
    {
        web.LoadUrl( url );
    }
}

function DownloadFile( url )
{
    downloader = app.CreateDownloader();
    downloader.SetOnComplete( downloader_OnComplete );
    downloader.Download( url, "./" );
}

function downloader_OnComplete()
{
    app.ShowPopup( "Der Download ist fertig." );
}

function lstColors_OnTouch( item, index ) { // change colours
    if (item == "Schwarz") {clrBg = "black" ; clrTxt = "white";}
    if (item == "Weiss") {clrBg = "white" ; clrTxt = "black";}
    if (item == "Blau") {clrBg = "blue" ; clrTxt = "black";}
    app.SaveText( "item", item );
    app.SaveText( "clrBg", clrBg );
    app.SaveText( "clrTxt", clrTxt );
    setcolors()
}

function setcolors () {
    var objs = app.GetObjects();
    for( var i in objs )
    {
        if( !objs[i] ) continue; // Ignore deleted objects.
       
        var objsi = objs[i];
        var objsit = objsi.GetType();
       
        if( objsit == "Layout" || objsit == "Scroller" || objsit == "CheckBox" || objsit == "" )
        {
            objsi.SetBackColor( clrBg );
        }
        else if( objsit === "Text" || objsit === "TextEdit" || objsit === "Spinner" || objsit === "CheckBox"  )
        {
            objsi.Batch({
                SetBackColor_: [clrBg],
                SetTextColor: [ clrTxt ],
            })
        }
        else if( objsit === "List" )
        {
            objsi.Batch({
                SetBackColor_: [clrBg],
                SetTextColor: [ clrTxt ],
                SetTextColor1: [ clrTxt ],
                SetTextColor2: [ clrTxt ],
            })
        }
        else if( objsit === "Button" )
        {
            objsi.SetStyle( transparent, transparent, 0, null, 0, 0 , null, 0, 0 );
            objsi.SetTextColor( clrTxt );
        }
    }
    qbuts[qcurrent].GetParent().SetBackColor(qneutral)
}

function ViewportWidthHack( progress )
{
    if( progress > 10 )
        qwebs[qcurrent].Execute( qwebs[qcurrent].GetUrl );
}

function createContainer(layTab) {
var scroller = app.CreateScroller(dlgWidth, -1 );
  var layScroller = app.CreateLayout( "linear", "Top" );
  layScroller.SetPadding( 0, 10*dip, 0, 30*dip );
  layScroller.SetSize( dlgWidth);
  scroller.AddChild( layScroller );
  layTab.AddChild(scroller);
  return layScroller;
}

function btnOk_OnTouch() {
dialog.Hide();
}

//Will be called when the user touches our button.
function btnUpdates_OnTouch()
{
    //Make sure that the destination folder exists.
    app.MakeFolder( fldr );
   
    //Download file from the web.
    //(You can omit the 'file' parameter to use the original file name.
    dload = app.CreateDownloader( /*"NoDialog "*/ );
    dload.SetOnDownload( dload_OnDownload );
    dload.SetOnError( dload_OnError );
    dload.Download( fileurl, fldr, file );
}

// Handle the completion of the download.
function dload_OnDownload( file )
{
 app.ShowPopup( "Die Datei " + file + " ist heruntergeladen." );
}

//Handle download errors.
function dload_OnError( error )
{
 app.ShowPopup( "Es gab beim herunterladen einen Fehler. Bitte versuchen Sie es erneut. " );
}

function CreateDrawer() { // left drawer
    layDrawer.SetChildTextSize(12)
    layDrawer.SetChildMargins(15,5,5,15,"px")
   
    item = app.LoadText( "item", "black" );
    clrBg = app.LoadText( "clrBg", "black" );
    clrTxt = app.LoadText( "clrTxt", "white" );
   
    app.AddImage(layDrawer,"Img/tmBrowser.png")
 
    var closed = newButton( layDrawer, qshut + "  | [fa-close]")
    closed.SetOnTouch(function() {app.CloseDrawer("left");})
    var toolbar = app.AddLayout(layDrawer,"linear","horizontal") ; use=toolbar
    // Toolbar
    stp = newButton(use,"[fa-stop]")
    stp.SetOnTouch(function() {qwebs[qcurrent].Stop();})
    var brow = newButton( use, "[fa-chrome]")
    brow.SetOnTouch( function () { app.OpenUrl(qwebs[qcurrent].GetUrl()); } )
    // menu
    var notes  = newButton( layDrawer, "[fa-user] | " + qcopyr)
    notes.SetOnTouch(function() {notesdlg.Show();} )
    var btn0 = newButton( layDrawer,"[fa-cog] | " + qsettings)
    btn0.SetOnTouch( btn0_OnTouch )
    var html5 = newButton( layDrawer, "[fa-html5] | Quellcode anzeigen")
    html5.SetOnTouch( html5_OnTouch )
    var much = newButton(layDrawer,"[fa-star] | " + qfavs)
    much.SetOnTouch( function() {app.OpenDrawer("right");} );
    var speech = newButton( layDrawer, "[fa-microphone] | Sprachausgabe starten")
    speech.SetOnTouch( function() {btn_OnTouch();})
    var lstExit = newButton( layDrawer, "[fa-window-close] Speichern und beenden")
    lstExit.SetOnTouch( OnBack )
   
    app.AddDrawer( layDrawer, "left", 1.0)
}

function CreateDrawerR() { // right drawer (favourites)
    var toolbar  = app.CreateLayout( "linear", "horizontal" )
    toolbar.SetPadding( 0.02, 0.02, 0.02, 0.02 );
    var deleteFavorites = newButton( toolbar, "[fa-trash]" )
    deleteFavorites.SetOnTouch(function() {yndDelete.Show();})
    var closr = newButton( toolbar, qshut + " | [fa-close]" )
    closr.SetOnTouch(function() {app.CloseDrawer("right");})
    layDrawerR.AddChild( toolbar )
   
    var text = qfavs
    txt = app.CreateText( text)
    layDrawerR.AddChild( txt )
    var text = "Hier werden Ihre Lesezeichen angezeigt, die Sie zuvor abgespeichert haben."
    txt = app.CreateText( text, 0.8, -6, "Html,Link")
    layDrawerR.AddChild( txt )
    lstFavs = app.AddList(layDrawerR,"",1,-1,"html")
    var favs = app.LoadJson("favs","{}")
    for (let i = 0; i < favs.length; i++) {
        var ti = favs[i]
        lstFavs.AddItem(ti.title,ti.body)
    }
    lstFavs.SetOnTouch(lstFavs_OnTouch)
    app.AddDrawer( layDrawerR, "right", 1.0 )
}
 
function confirmFavDelete(result) {
     if (result == "Yes") {
         lstFavs.RemoveItemByIndex()
         app.ShowPopup("Lesezeichen gelöscht")
     }
}

function confirmHisDelete(result) {
     if (result == "Yes") {
      histlst.SetList("")
      histdlg.Dismiss()
      qbuts[qcurrent].Gone()
      qwebs[qcurrent].Gone()
      newtab()
         app.ShowPopup("Verlauf gelöscht")
     }
}
 
function AddFavorites_OnTouch() {
    title = qbuts[qcurrent].GetText()
    body  = qwebs[qcurrent].GetUrl()
    let domain = new URL(body)
    domain = domain.hostname.replace('www.','')
    tail = "favicons?domain="+domain
    lookup = "https://www.google.com/s2/"+tail
    dload = app.CreateDownloader("NoDialog")
    dload.SetOnComplete( dload_OnComplete )
    dload.Download( lookup, app.GetPrivateFolder( "Pictures" ) )
}

function dload_OnComplete() {
    dttm = new Date
    image = app.GetPrivateFolder( "Pictures" ) + "/" + dttm.getTime() + ".jpg"
    app.RenameFile(app.GetPrivateFolder( "Pictures" )+"/"+tail ,image)
    lstFavs.AddItem(title,body,image)
    app.ShowPopup("Lesezeichen hinzugefügt")
}
 
function lstFavs_OnTouch(title,body,icon,index) {
//    qwebs[qcurrent].LoadUrl(body)
    newtab(body)
    app.CloseDrawer( "right" )
    app.closed
}
 
function html5_OnTouch( item, title, body, type, index ) { // show source
    var func = GetWebPageSourceCode();
    qwebs[qcurrent].Execute( func, function( result ) {
        app.Alert( unescape( result ), "Quellcode" );
    } );
}

function GetWebPageSourceCode() {
    return "(function() { "
        +"var t = document.doctype;"
        +"var h = document.body.parentElement;"
        +"var s = new XMLSerializer();"
        +"return escape("
        +"(t?s.serializeToString(t)+'\\n':'')+s.serializeToString(h)"
        +");"
    + "})();";
}
 
function newButton(lay,text) {
    var but = app.AddButton(lay,text,-1,-1,"fontawesome")
    but.SetStyle(transparent,transparent, 0, null, 0, 0)
    but.SetTextColor(clrTxt)
    but.Animate( "FadeIn" )
    return but
}

function GetNewTabHtmlCode() {
    var html = "<!DOCTYPE html>"
             + "<html lang='de'>"
             + "    <head>"
             + "        <meta charset='utf-8'>"
             + "        <meta name='viewport' content='width=device-width'>"
             + "        <title>Neuer Tab</title>"
             +"  <style>.google { padding: 50px; width: 10px; }"
             +"  .youtube { padding: 50px; height: 20px;width: 10px; }</style>"
             + "    </head>"
             + "    <body>"
             +" <div class='google'><a href='https://google.com'><img src='https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_92x30dp.png'>'</a></div>"
             +" "
             + "    </body>"
             + "</html>"
    return html;
}

function qaddbut(qlay,qtxt,qidx) { // add button for tab
    var v = app.AddLayout(qlay,"Linear")
    v.Batch({
        SetBackColor_: [clrBg],
        SetPadding_: [0,0,0,5,"px"]
    })
    var q = app.CreateText(qtxt )
    v.AddChild(q)
    q.Batch({
        SetBackColor_: [clrBg],
        SetTextColor: [ clrTxt ],
        SetPadding_: [20,20,20,20,"px"]
    })
    q.SetOnTouchUp(q_OnTouch)
    q.data.qidx = qidx
    qbuts[qidx] = q
    return q
}
 
function qaddlay(qlay,qidx) { // add layout for tab
    var q = app.AddLayout(qlay,"Linear")
    q.Gone()
    qlays[qidx] = q
    return q
}
 
function q_OnTouch (event) { // touched tab button, swap active tab
    var qidx = this.data.qidx
    if (qidx!=qcurrent && !isNaN(event.X)) {
       qbuts[qcurrent].SetTextColor(clrTxt)
       qbuts[qcurrent].GetParent().SetBackColor(clrBg)
       qlays[qcurrent].Gone()
       if (qtxts[qidx].GetText() == "about:blank") qwebs[qidx].LoadHtml(defaultHtml,"file:///Sys/") //?
       else if (qwebs[qidx].GetUrl() == "" && qtxts[qidx].GetText() != "") qwebs[qidx].LoadUrl(qtxts[qidx].GetText()) ///
       qbuts[qidx].SetTextColor(clrTxt)
       qbuts[qidx].GetParent().SetBackColor(qneutral)
       qlays[qidx].Show()
       qcurrent=qidx
    }
}
 
function qclose () { // close (hide) tab
    // look for another open tab
    opn = -1
    qbuts.forEach (function(current,idx) {
        if (idx != qcurrent && qbuts[idx].GetVisibility()=="Show") opn = idx
    } )
    // close this tab if another is open
    if (opn == -1) {alert("Tab kann nicht geschlossen werden");}
    else {
        qbuts[qcurrent].Gone()
        qwebs[qcurrent].Gone()
        app.SimulateTouch(qbuts[opn],0,0,"Up")    
   }
}

//Start recognize
function Listen()
{
    app.HideProgress()
    speech.Recognize()
}
 
function btn_OnTouch() {
    speech.Recognize();
}
 
function speech_OnReady() {
    app.ShowPopup("Ich höre zu")
}
 
function speech_OnResult( results ) {
//  results.forEach(function (current,index,array) {
    for (let i = 0; i < results.length; i++) {
      //Get result.
      var cmd = results[i].toLowerCase()
   
    //Watch for key phrases.
    if( cmd.indexOf("zurück")>-1 ) {
        qwebs[qcurrent].Back() ; break ;
    }
   else if( cmd.indexOf("vorwärts")>-1 ) {
        qwebs[qcurrent].Forward() ; break ;
    }
    else if( cmd.indexOf("gehe zu")>-1 ) {
        temp = cmd.replace("gehe ","");
        temp = temp.replace("zu ","");
        temp = "https://" + temp
        qwebs[qcurrent].LoadUrl(temp)
        break ;
        }
    else if (  cmd.indexOf(qcopyr.toLowerCase() )>-1 ) {
        notesdlg.Show() ; break ;
    }
    else if (  cmd.indexOf(qsettings.toLowerCase() )>-1 ) {
        dialog.Show() ; break ;
    }
    else if (  cmd.indexOf(qfavs.toLowerCase() )>-1 ) {
        app.OpenDrawer("right") ; break ;
    }
    else if (  cmd.indexOf(qhist.toLowerCase() )>-1 ) {
        histdlg.Show() ; break ;
    }
    else if (  cmd.indexOf(qshut.toLowerCase() )>-1 ) {
        if (notesdlg.IsVisible()) notesdlg.Hide()
        if (histdlg.IsVisible()) histdlg.Hide()
        if (dialog.IsVisible()) dialog.Hide()
        if (app.GetDrawerState("left") == "Open") app.CloseDrawer("left")
        if (app.GetDrawerState("right") == "Open") app.CloseDrawer("right")
        break ;
    }
    else if( cmd.indexOf("beenden")>-1 ) {
        OnBack();
        }
        else alert(cmd)
    }
    Listen()
 }
 
//Called when user touches our button.
function CreateHistory()  {
    histlay.show
}
 
function btn0_OnTouch() {
    dialog.Show() //"dlg.Show" -> "dialog.Show"
}

Thiemo Melhorn

unread,
Jun 13, 2023, 2:31:43 PM6/13/23
to DroidScript
Alan and I just can't get it to work. That's why I also deleted the part in the code then again

Thiemo Melhorn

unread,
Jun 15, 2023, 9:25:45 AM6/15/23
to DroidScript
I have now managed to solve the problem myself.


aweb.spk

Alan Hendry

unread,
Jun 17, 2023, 7:45:21 AM6/17/23
to DroidScript
HI,
This just seems to use DS onTouch to detect long touch
with a timer between touch down and up. 
It seems to always respond with a dialog saying C
I thought the aim was to get the URL of the link or image that the user touches.
Regards, ah

Thiemo Melhorn

unread,
Jun 17, 2023, 5:16:25 PM6/17/23
to DroidScript
I still don't know how copying the URL or text works.

Alan Hendry

unread,
Jun 18, 2023, 1:15:17 PM6/18/23
to DroidScript
HI,
This requires 2.62 (currently in beta testing)
It can intercept details of long touches on links and images.
Long touches on text cause text selection, 
handles to select more text and popup for copy/share/select all/web search.
Regards, ah
aweb.spk

Thiemo Melhorn

unread,
Jun 19, 2023, 4:20:52 PM6/19/23
to DroidScript
How to bring the "Copy" function to life?

Alan Hendry

unread,
Jun 21, 2023, 1:59:29 PM6/21/23
to DroidScript
HI,
What do want to copy? (From where, to where)
Regards, ah

Thiemo Melhorn

unread,
Jun 21, 2023, 4:14:16 PM6/21/23
to DroidScript
I would like to "save" the link that is also displayed in the dialog or a text on the WebView to the clipboard first, so that any app that can capture text can also fetch it from the clipboard.

Alan Hendry

unread,
Jun 22, 2023, 4:52:58 PM6/22/23
to DroidScript
HI,
See details of how users copy text above ( it goes to the clipboard automatically).
Also see SPK above which requires 2.62 (it's only in beta and has no builder)
for how to get URL of link, then just setclipboard.
Regards, ah

Thiemo Melhorn

unread,
Jun 22, 2023, 6:53:52 PM6/22/23
to DroidScript
Nothing is automatically copied to the clipboard.

Alan Hendry

unread,
Jun 23, 2023, 5:42:58 AM6/23/23
to DroidScript
HI,
What did you do?
You need to long touch on the text, (move the handles if you need to), touch Copy
Regards, ah 
 

Thiemo Melhorn

unread,
Jun 23, 2023, 12:41:09 PM6/23/23
to DroidScript
I have the dialog with "Copy ", as well as "Open" when I long press and then get another dialog with the link in text form and it does not go to the clipboard.

Thiemo Melhorn

unread,
Jun 27, 2023, 9:15:35 PM6/27/23
to DroidScript
I got the problem solved.

Thiemo Melhorn

unread,
Jun 27, 2023, 9:23:36 PM6/27/23
to DroidScript
function OnStart() {

  lay = app.CreateLayout("linear", "VCenter,FillXY");
  web = app.AddWebView(lay, 1, 1);
  web.SetContextMenus("Copy to URL");
  web.SetOnContextMenu(doit);
  web.LoadUrl("page.html");
  app.AddLayout(lay);
}

function copyTextToClipboard(text) {
  app.SetClipboardText(text);
}

function doit(action, selectedText, selectionRect, pageUrl) {
  copyTextToClipboard(selectedText);
}
Reply all
Reply to author
Forward
0 new messages