O documento resume os principais pacotes e funcionalidades do framework TotalCross, incluindo classes para geração e leitura de barcode, conectividade bluetooth e GPS, câmera, mapas, criptografia, entrada/saída, JSON, linguagem, rede, telefone, sistema, teste unitário, utilitários e XML.
1. 1
Webinar 2 – Classes TotalCrossWebinar 2 – Classes TotalCross
Barcode (exibição e leitura)
Conectividade via bluetooth
GPS
Camera
Maps
Demais pacotes
2. 2
Barcode (exibição e leitura)Barcode (exibição e leitura)
• Exibição de barcode:
Image bc =
Barcode.createImage(Barcode.TYPE_INTERLEAVED2OF5, "34191
09107 30053 320054 44505 490001 1 67420000139055", barH,
Font.DEFAULT, -1, false, Barcode.ALIGN_LEFT, false,
Color.BLACK, -1, 3, 0);
• Leitura de barcode:
•Android (zxing)
Scanner.readBarcode("mode=1D&msg=Barcode");
3. 3
Barcode (exibição e leitura)Barcode (exibição e leitura)
• Leitura de barcode
• Windows Mobile – Motorola, Dolphin, Intermec,
Pidion
if (Scanner.activate()) {
Scanner.setBarcodeParam(Scanner.BARUPCE, true);
Scanner.commitBarcodeParams();
}
public void onEvent(Event event) {
switch (event.type) {
case ScanEvent.SCANNED:
barCode = ((ScanEvent)event).data;
4. 4
Conectividade via BluetoothConectividade via Bluetooth
• O bluetooth pode ser usado para:
• Conectar a um GPS separado
• Transferir arquivos
• BtTransfer
• Enviar dados para uma impressora
• PrinterSampleCitizen
• PrinterSampleMPT
• PrinterSampleZebra
RadioDevice.setState(RadioDevice.BLUETOOTH,
RadioDevice.RADIO_STATE_ENABLED);
Stream btsocket =
(Stream)Connector.open("btspp://"+mac+":0;uuid="+UUID);
DataStream ds = new DataStream(btsocket);
ds.writeBytes / readBytes
5. 5
GPSGPS
• Acessa o GPS no Android, iOS e Windows Phone
• Normalmente usa-se uma thread
GPS gps = null;
try {
gps = new GPS();
int ini = Vm.getTimeStamp();
for (int i = 0; i < 60 && gps.location[0] == GPS.INVALID; i++) {
Vm.safeSleep(1000);
gps.retrieveGPSData();
}
}
catch (GPSDisabledException gde) {
Toast.show("GPS is disabled, please enable it!",2000);
}
catch (Exception ioe) {
MessageBox.showException(ioe, true);
}
finally {
if (gps != null)
gps.stop();
}
6. 6
CameraCamera
• Permite tirar fotos, filmar, ou escolher da galeria
• No desktop, abre o FileChooserBox para
selecionar uma foto (com pré-visualização)
Camera c = new Camera();
c.defaultFileName = "os"+new Time().getTimeLong()+".jpg";
//String[] res = Camera.getSupportedResolutions();
c.resolutionWidth = 800;
c.resolutionHeight = 600;
c.stillQuality = Camera.CAMERACAPTURE_STILLQUALITY_NORMAL;
c.cameraType = Camera.CAMERA_FROM_GALLERY // Camera.CAMERA_NATIVE,
Camera.CAMERA_CUSTOM;
ret = c.click();
if (ret != null)
{
Image img = new Image(ret);
...
7. 7
MapsMaps
• Suporte ao GoogleMaps
– iOS, Android e Windows Phone
• No Android permite desenhar
GoogleMaps.showAddress(GoogleMaps.getLocation("Av
Norte 2920, Luciano Cavalcante, Fortaleza, CE,
Brasil"), chSat.isChecked());
• Suporta também o Waze (iOS e android)
GoogleMaps.showRoute(endereco,null,null,GoogleMaps.USE_WAZE);
10. 10
Pacote totalcross.jsonPacote totalcross.json
• Porte da biblioteca json em Java
• Leitura e escrita
String line =
"[{"name":"Mary","date":61395803160000,"text":"
My first post","likes":1},
{"name":"John","date":61395803820000,"text":"I
like TotalCross","likes":200}]";
FacebookPost[] posts = JSONFactory.parse(line,
FacebookPost[].class);
11. 11
Pacote totalcross.langPacote totalcross.lang
• Compatível até Java 7
– Possui suporte a reflection e generics
– Não possui suporte a annotation
• Subconjunto do java.lang
– TotalCross: 49 classes
– Java 7: 103 classes
• Não se importa o totalcross.lang