Árvore de páginas

Versões comparadas

Chave

  • Esta linha foi adicionada.
  • Esta linha foi removida.
  • A formatação mudou.

...

Portuguese

Este arquivo HTML contém o exemplo das chamadas e callBacks das funções para acesso aos perifericos dos dispositivo (camera, gps, etc) e também para acesso ao banco da dados SQLite.

Arquivo

Bloco de código
languagehtml
themeEclipse
linenumberstrue
collapsefalse
<!DOCTYPE html>
<html>

<head>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">

    <style>
        body {
            font-family: 'Calibri';
        }
        
        a {
            text-decoration: none;
        }
        
        div {
            display: inline-block;
            float: left;
            background-color: #019AC4;
            color: #FFFFFF;
            width: 250px;
            height: 34px;
            margin: 10px;
            padding: 10px;
        }
    </style>

    <script src="totvstec.js"></script>
    <script>
        onload = function () { loadEngine(); }

        function loadEngine() {

            // Conecta WebSocket Server
            totvstec.connectWS( function(){
                // Carrega mensageria exclusiva da pagina
                dialog.advplToJs.connect(function (codeType, codeContent, objectName) {
                    //if (codeType == "") {
                    //}
                });

                // Envia sinal informando termino da carga
                dialog.jsToAdvpl("page_started", "Pagina inicializada");
            });
            
        }

        // Funcoes de CallBack Advpl -> JS
        function getPictureSuccess(image) {
            totvstec.createNotification( 1, "getPicture", image );
            totvstec.runAdvpl('Encode64(,"' + image + '",.T.,.T.)', imgEncodedSuccess);
        }

        function barCodeScannerSuccess(barCode) {
            totvstec.createNotification( 1, "barCodeScanner", barCode );
        }

        function pairedDevicesSuccess(paired) {
            alert(paired);
        }

        function getCurrentPositionSuccess(position) {
            window.location.href = "http:// Necessario retirar o sinal de Grau para que o MAPS reconheca a posicao
maps.google.com/?q=" + position;
        }
        
       position =function position.replace(/�/g, "");readAccelerometerSuccess(sensorRead) {
            window.location.href = "http://maps.google.com/?q=" + positionalert(sensorRead);
        }
        
        function readAccelerometerSuccessaddCalendarSuccess(sensorReadid) {
            alert(sensorRead"CalendarId:" + id);
        }
        
        function getDate(){
  var savedid = "0";
        function  var today = new Date(findCalendarSuccess(retIds) {
            alert("Ids encontrados " + retIds);
            varobj dd = todayJSON.getDateparse(retIds);
            varsavedid mm = today.getMonth()+1; //January is 0!
obj.ids[0];
        }
        
     var  yyyy =function today.getFullYeargetCalendarSuccess(calev); {
            return mm+'/'+dd+'/'+yyyyobj = JSON.parse(calev);
        }
    alert("titulo    
 - " + obj.title      + function runAdvplSuccess(retStr){"\n" +
            alert(retStr);
      "descricao - " }

 + obj.descr      + function testDeviceSuccess(lRet){"\n" +
            alert(lRet);
      "local    }
 - " + obj.addr    
   +     function getTempPathSuccess(tempPath){"\n" +
            alert(tempPath);
      "data ini }
 - " + obj.startdate  + "\n" +
        function findContactSuccess(contact) {
        "hora ini   alert(contact);
        }

- " + obj.starttime  + "\n" +
                 function dbGetSuccess("data){
 fim  - " + obj.enddate    +  var jsonStr = JSON.stringify(data);
"\n" +
               alert('dbGetSuccess: ' + jsonStr.replace(/"/g, "'"));
  "hora fim  - " + obj.endtime    + "\n" }+
        
        function dbError(error){
            alert("dbError: "dia todo  - " + errorobj.allday);
        }
        		
		function dbSuccessgetDate(){
			var today = new Date();
			var dd = today.getDate();
			var mm   = today.getMonth()+1; //January Dummy
        }
is 0!
			var yyyy = today.getFullYear();
			return mm+'/'+dd+'/'+yyyy;
		}
		
		function runAdvplSuccess(retStr){
			alert(retStr);
		}
		
		function imgEncodedSuccess(retStr){
		      //Envia a imagem encoded em base64 via REST/JSON/XML
		      //Para exemplificar, quem receber isto deve fazer parecido com abaixo
		      totvstec.decode64(retStr,"imagem.jpg",true, imgSavedSuccess);
		}
		function imgSavedSuccess(ret){
			alert("Imagem " + ret + " salva com sucesso!");
		}

        function testDeviceSuccess(lRet){
            alert(lRet);
        }
        
        function getTempPathSuccess(tempPath){
        	alert(tempPath);
        }
		
		function findContactSuccess(contact) {
			alert(contact);
		}

		function dbGetSuccess(data){
			var jsonStr = JSON.stringify(data);
			alert('dbGetSuccess: ' + jsonStr.replace(/"/g, "'"));
		}
		
		function dbError(error){
			alert("dbError: " + error);
		}
		function dbSuccess(){
			// Dummy
		}
		
		function getFindContactFilter(){
			var filter = prompt("Entre com a palavra-chave: ", "TOTVS");
			if (filter != null) {
				return filter;
			}
			else {
				return "";
			}
		}
		
		// Cria tabela
		function dbCreateTableSuccess(){
			totvstec.dbExec( "insert into newTab values (1,'User 1')", dbSuccess, dbError );
			totvstec.dbExec( "insert into newTab values (2,'User 2')", dbSuccess, dbError );
			totvstec.dbExec( "insert into newTab values (3,'User 3')", dbSuccess, dbError );
			alert("dbCreateTableSuccess: Tabela criada com sucesso");
		}		
		function dbCreateTable(){
			totvstec.dbExec("create table newTab (cod INTEGER, name TEXT)", dbCreateTableSuccess, dbError);
		}
		
		// Deleta tabela
		function dbDropTableSuccess(){
			alert("dbDropTable: Ok");
		}
		function dbDropTable(){
			totvstec.dbExec("drop table newTab", dbDropTableSuccess, dbError);
		}

		function testCommitProcess(){
			totvstec.dbBegin(dbSuccess, dbError);
			totvstec.dbExec( "insert into newTab values (4,'User 4')", dbSuccess, dbError );
			totvstec.dbExec( "insert into newTab values (5,'User 5')", dbSuccess, dbError );
			totvstec.dbExec( "insert into newTab values (6,'User 6')", dbSuccess, dbError );
			totvstec.dbCommit(dbSuccess, dbError);
			alert("testCommitProcess: Ok");
		}

		function testRollbackProcess(){
			totvstec.dbBegin(dbSuccess, dbError);
			totvstec.dbExec( "insert into newTab values (4,'User 4')", dbSuccess, dbError );
			totvstec.dbExec( "insert into newTab values (5,'User 5')", dbSuccess, dbError );
			totvstec.dbExec( "insert into newTab values (6,'User 6')", dbSuccess, dbError );
			totvstec.dbRollback(dbSuccess, dbError);
			alert("testRollbackProcess: Ok");
		}
		
    </script>
</head>

<body>
    <font face=calibri color="#FFFFFF">

        <p><img src="logo_totvs.png" align="left">
             <br>
        // Cria tabela
  <font size=14 face=calibri color="#039CBB">&nbsp;Cloud Bridge  function dbCreateTableSuccess(){- Custom</font>
        </p><br>

     totvstec.dbExec( "insert into newTab values (1,'User 1')", dbSuccess, dbError );<div style="background-color: #DB4437; width: 90%; height: 12px;">
            totvstec.dbExec( "insert into newTab values (2,'User 2')", dbSuccess, dbError );<font size="4">Acesso ao SQLite </font><br><br>
        </div>

        <a onclick='dbCreateTable();'>
   totvstec.dbExec( "insert into newTab values (3,'User 3')", dbSuccess, dbError );<div>
             alert("dbCreateTableSuccess: Tabela criada com sucesso");
<font size="5">Cria Tabela</font><br><br>
           } </div>
        </a>

        function dbCreateTable<a onclick='dbDropTable(){;'>
            totvstec.dbExec("create table newTab (cod INTEGER, name TEXT)", dbCreateTableSuccess, dbError);
<div>
                }
  <font size="5">Apaga Tabela</font><br><br>
      
        // Deleta tabela</div>
        function dbDropTableSuccess(){</a>

        <a onclick='totvstec.dbGet("select * from alert("dbDropTable: Ok");newTab", dbGetSuccess, dbError);'>
        }
    <div>
    function dbDropTable(){
            totvstec.dbExec("drop table newTab", dbDropTableSuccess, dbError);
<font size="5">Recupera dados</font><br><br>
            }

</div>
        </a>
  function testCommitProcess(){
      
        <a onclick='totvstec.dbBegin(dbSuccessdbGet("SELECT name FROM sqlite_master WHERE type=\"table\"", dbGetSuccess, dbError);'>
            totvstec.dbExec( "insert into newTab values (4,'User 4')", dbSuccess, dbError );
     <div>
                <font size="5">Lista Tabelas</font><br><br>
       totvstec.dbExec( "insert into newTab values (5,'User 5')", dbSuccess, dbError );
 </div>
        </a>        totvstec.dbExec( "insert into newTab values (6,'User 6')", dbSuccess, dbError );

        <a onclick='testRollbackProcess();'>
            totvstec.dbCommit(dbSuccess, dbError); <div>
            alert("testCommitProcess: Ok");    <font size="5">Proc.c/ Rollback</font><br><br>
        }

    </div>
    function testRollbackProcess(){
   </a>

         totvstec.dbBegin(dbSuccess, dbError);<a onclick='testCommitProcess();'>
            totvstec.dbExec( "insert into newTab values (4,'User 4')", dbSuccess, dbError );
<div>
                <font size="5">Proc. c/ Commit</font><br><br>
   totvstec.dbExec( "insert into newTab values (5,'User 5')", dbSuccess, dbError );</div>
        </a>

    totvstec.dbExec( "insert into newTab values (6,'User 6')", dbSuccess, dbError );    <div style="background-color: #DB4437; width: 90%; height: 12px;">
            totvstec.dbRollback(dbSuccess, dbError); <font size="4">Acesso ao periferico</font><br><br>
        </div>

    alert("testRollbackProcess: Ok");
   <a onclick='totvstec.runAdvpl("DtoS(CtoD(\"" +getDate()+   }"\"))", runAdvplSuccess);'>
        
    </script>
</head>

<body>
<div>
     <font face=calibri color="#FFFFFF">

        <p><img src="logo_totvs.png" align="left"> <font size="5">runAdvpl</font><br><br>
            <br></div>
        </a>

    <font   size=14 face=calibri color="#039CBB">&nbsp;Cloud Bridge - Custom</font>
 <a onclick='totvstec.getPicture(0,getPictureSuccess);'>
            </p><br><div>

        <div style="background-color: #DB4437; width: 90%; height: 12px;">
  <font size="5">Captura imagem</font><br><br>
        <font size="4">Acesso ao SQLite </font><br><br>div>
        </div>
a>
        
        <a onclick='dbCreateTable(totvstec.getPicture(200,getPictureSuccess);'>
            <div>
                <font size="5">Cria Tabela<>Captura imagem (Redimensionando)</font><br><br>
            </div>
        </a>

        <a onclick='dbDropTabletotvstec.barCodeScanner(barCodeScannerSuccess);'>
            <div>
                <font size="5">Apaga Tabela<>C&oacute;digo de barras</font><br><br>
            </div>
        </a>

        <a onclick='totvstec.dbGet("select * from newTab", dbGetSuccess, dbErrorpairedDevices(pairedDevicesSuccess);'>
            <div>
                <font size="5">Recupera dados<>Pareados</font><br><br>
            </div>
        </a>
        
        <a onclick='totvstec.dbGet("SELECT name FROM sqlite_master WHERE type=\"table\"", dbGetSuccess, dbErrorgetCurrentPosition(getCurrentPositionSuccess);'>
            <div>
                <font size="5">Lista Tabelas<">Geo Posi&ccedil;&atilde;o</font><br><br>
            </div>
        </a>        

        <a onclick='testRollbackProcesstotvstec.unlockOrientation();'>
            <div>
                <font size="5">Proc.c/ Rollback<>Libera Orienta&ccedil;&atilde;o</font><br><br>
            </div>
        </a>

        <a onclick='testCommitProcesstotvstec.lockOrientation();'>
            <div>
                <font size="5">Proc. c/ Commit</font><br><br>
            </div><div>
        </a>

        <div<font stylesize="background-color: #DB4437; width: 90%; height: 12px;">"5">Trava Orienta&ccedil;&atilde;o</font><br><br>
            <font size="4">Acesso ao periferico</font><br><br></div>
        </div>a>

        <a onclick='totvstec.runAdvplcreateNotification("DtoS(CtoD(\"" +getDate()+ "\"))", runAdvplSuccess 1, "Titulo da Notifica&ccedil;&atilde;o", "Corpo  da Notifica&ccedil;&atilde;o" );'>
            <div>
                <font size="5">runAdvpl<>Notifica&ccedil;&atilde;o</font><br><br>
            </div>
        </a>

        <a onclick='totvstec.getPicturevibrate(getPictureSuccess400);'>
            <div>
                <font size="5">Captura imagem<>Vibrar</font><br><br>
            </div>
        </a>

        <a onclick='totvstec.barCodeScannergetTempPath(barCodeScannerSuccessgetTempPathSuccess);'>
            <div>
                <font size="5">C&oacute;digo de barras<>GetTempPath</font><br><br>
            </div>
        </a>
        
        <a onclick='totvstec.pairedDevicesreadAccelerometer(pairedDevicesSuccessreadAccelerometerSuccess);'>
            <div>
                <font size="5">Pareados<>Aceler&ocirc;metro</font><br><br>
            </div>
        </a>

        
        <a onclick='totvstec.getCurrentPositionenblOnPause(getCurrentPositionSuccess);'>
            <div>
                <font size="5">Geo Posi&ccedil;&atilde;o<>Ativar OnPause</font><br><br>
            </div>
        </a>
        
        <a onclick='totvstec.unlockOrientationenblOnResume();'>
            <div>
                <font size="5">Libera Orienta&ccedil;&atilde;o<>Ativar OnResume</font><br><br>
            </div>
        </a>

        <a onclick='totvstec.lockOrientation();'>
        <a    <div>
                <font size="5">Trava Orienta&ccedil;&atilde;o</font><br><br>
            </div>
        </a>

        <a onclick='totvstec.createNotification( 1, "Titulo da Notifica&ccedil;&atilde;o", "Corpo  da Notifica&ccedil;&atilde;o" onclick='totvstec.addContact("CST TOTVS", "Centro de Servi&ccedil;os TOTVS", "TOTVS SA", "[email protected]", 2, "+55 11 4003-0015", 2, "Av. Braz Leme, 1631 - Jd. S&atilde;o Bento - S&atilde;o Paulo/SP", "Canal exclusivo para assuntos administrativos e financeiros. Atendimento: de segunda &agrave; sexta, das 8h00 &agrave;s 12h00 e das 13h30 &agrave;s 18h00.");'>
            <div>
                <font size="5">Notifica&ccedil;&atilde;o<>AddContact</font><br><br>
            </div>
        </a>
		
        <a onclick='totvstec.vibrate(400findContact(getFindContactFilter() , findContactSuccess);'>
            <div>
                <font size="5">Vibrar<>FindContact</font><br><br>
            </div>
        </a>
        
        <a onclick='totvstec.addCalendar("TOTVS", "Descrição TOTVS", "Endereço TOTVS", new Date().toJSON().slice(0,10),"08:00:00", new Date().toJSON().slice(0,10), "09:00:00",    <a onclick='totvstec.getTempPath(getTempPathSuccess"False", addCalendarSuccess);'>
            <div>
                <font size="5">GetTempPath<>AddCalendar</font><br><br>
            </div>
        </a>
        
        <a onclick='totvstec.readAccelerometer(readAccelerometerSuccess);'>
            <div>
    </a>
        
    <font size="5">Aceler&ocirc;metro</font><br><br>
   <a onclick='totvstec.findCalendar(new Date().toJSON().slice(0,10),new Date( (new Date()).valueOf() + 1000*3600*24  </div>).toJSON().slice(0,10), findCalendarSuccess);'>
        </a>
        <div>
        <a onclick='totvstec.addContact("CST TOTVS", "Centro de Servi&ccedil;os TOTVS", "TOTVS SA",<font "[email protected]", 2, "+55 11 4003-0015", 2, "Av. Braz Leme, 1631 - Jd. S&atilde;o Bento - S&atilde;o Paulo/SP", "Canal exclusivo para assuntos administrativos e financeiros. Atendimento: de segunda &agrave; sexta, das 8h00 &agrave;s 12h00 e das 13h30 &agrave;s 18h00."size="5">FindCalendar</font><br><br>
            </div>
        </a>
        
        <a onclick='totvstec.viewCalendar(savedid);'>
            <div>
                <font size="5">AddContact<>ViewCalendar</font><br><br>
            </div>
        </a>
        
        <a onclick='totvstec.findContactgetCalendar("totvs", findContactSuccesssavedid,getCalendarSuccess);'>
            <div>
                <font size="5">FindContact<>GetCalendar</font><br><br>
            </div>
        </a>
        
        <a onclick='alert(totvstec.version);'>
            <div>
                <font size="5">Vers&atilde;o JS</font><br><br>
            </div>
        </a>

        <div style="background-color: #DB4437; width: 90%; height: 12px;">
            <font size="4">Testa os perifericos</font><br><br>
        </div>

        <a onclick='totvstec.testDevice(totvstec.BLUETOOTH_FEATURE, testDeviceSuccess)'>
            <div>
                <font size="5">Testa BlueTooth</font><br><br>
            </div>
        </a>
        <a onclick='totvstec.testDevice(totvstec.NFC_FEATURE, testDeviceSuccess)'>
            <div>
                <font size="5">Testa NFC</font><br><br>
            </div>
        </a>
        <a onclick='totvstec.testDevice(totvstec.WIFI_FEATURE, testDeviceSuccess)'>
            <div>
                <font size="5">Testa WIFI</font><br><br>
            </div>
        </a>
        <a onclick='totvstec.testDevice(totvstec.LOCATION_FEATURE, testDeviceSuccess)'>
            <div>
                <font size="5">Testa GPS</font><br><br>
            </div>
        </a>
        
        <a onclick='totvstec.testDevice(totvstec.CONNECTED_WIFI, testDeviceSuccess)'>
            <div>
                <font size="5">Conectado WIFI</font><br><br>
            </div>
        </a>
        <a onclick='totvstec.testDevice(totvstec.CONNECTED_MOBILE, testDeviceSuccess)'>
            <div>
                <font size="5">Conectado 3G</font><br><br>
            </div>
        </a>

        <div style="background-color: #DB4437; width: 90%; height: 12px;">
            <font size="4">Abre as configura&ccedil;&otilde;es</font><br><br>
        </div>

        <a onclick='totvstec.openSettings(totvstec.BLUETOOTH_FEATURE)'>
            <div>
                <font size="5">Abre BlueTooth</font><br><br>
            </div>
        </a>
        <a onclick='totvstec.openSettings(totvstec.NFC_FEATURE)'>
            <div>
                <font size="5">Abre NFC</font><br><br>
            </div>
        </a>
        <a onclick='totvstec.openSettings(totvstec.WIFI_FEATURE)'>
            <div>
                <font size="5">Abre WIFI</font><br><br>
            </div>
        </a>
        <a onclick='totvstec.openSettings(totvstec.LOCATION_FEATURE)'>
            <div>
                <font size="5">Abre GPS</font><br><br>
            </div>
        </a>

</body>

</html>