webview and jquery vs javascript clock

aubete

Member
Licensed User
Longtime User
Hi!

I try the webview, but the javascript not working. The js:

B4X:
function twatch(){
  var ttm= $("#acttm").text();
        var t= ttm.split(":");
        var m;
  var s= Number(t[2]);
  var wrt= true;

  if( s>=59 ){
    s= 0;
    m= Number(t[1]);
    if( m>=59 ){
      clearInterval(timerWatch);
      $.get('index.php?a=0', function(data) {
        if(data.hiba==0){
          $("#actdt").text(data.date);
          $("#acttm").text(data.time);
        }
      }, "json");
      timerWatch= setInterval(function(){twatch()},1000);
      wrt= false;
    }
    else{
      m++;
    }
    t[1]= m.toString();
    if(m<10) t[1]= '0'+t[1];
  }
  else{
    s++;
  }
  if(wrt){
    t[2]= s.toString();
    if(s<10) t[2]= "0"+t[2];
    $("#acttm").text(t[0]+":"+t[1]+":"+t[2]);
  }
}// twatch

This is a "easy" watch. The inbuilt web browser, can use this. counting the seconds. but my webview can't.

my code:

B4X:
Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   Dim wv1 As WebView
   Dim wvs1 As WebViewSettings
   Dim wvx1 As WebViewXtender
   Dim wvxx1 As WebViewExtras
   Dim p1,p2 As Panel
   Dim l1, lx, ly As Label
   Dim timer1 As Timer
End Sub

Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   'Activity.LoadLayout("Layout1")
   wv1.Initialize("wv")
   Activity.AddView(wv1,0,0,99%x,99%y)
   
   wv1.JavaScriptEnabled = True
   wv1.ZoomEnabled = False
   wvs1.setDefaultZoom(wv1,"FAR")
   wvs1.setAppCacheEnabled(wv1,False)
   wvs1.setLightTouchEnabled(wv1,False)
   wvs1.setLoadWithOverviewMode(wv1,True)
   
End Sub

Sub Activity_Resume
   wv1.LoadUrl("http://192.168.242.145/flyvision/index.php")
   wvx1.resumeTimers(wv1)
   wvx1.setJavaScriptEnabled(wv1, True)
'   wvxx1.addJavascriptInterface(wv1, "jsi")

End Sub

i try webviewextras, webviewsettings, webviewextend. but not counting that clock.

TY

AuBeTe
 

warwound

Expert
Licensed User
Longtime User
Use WebViewExtras addWebChromeClient method.
Run the JavaScript again and look at the device log - do you see any JavaScript errors logged?

Martin.

Sent from my HUAWEI U8815 using Tapatalk 2
 
Upvote 0

aubete

Member
Licensed User
Longtime User
Use WebViewExtras addWebChromeClient method.
Run the JavaScript again and look at the device log - do you see any JavaScript errors logged?

Martin.

The addWebChromeClient is the solution.

But this the far zoom is not work perfectly. always draw a grey bar to the left and bottom on the screen The showed page and the phone's screen is perfectly same resolution

AuBeTe

Ps.: Sorry my english
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
You have a layout problem in the webpage?
If so you'll have to modify the webpage's CSS styles to suit your device screen.

Martin.
 
Upvote 0
Top