📄 bluetoothservicerecordcanvas.java
字号:
elm2 = (DataElement) e.nextElement();
if (elm2.getDataType() == DataElement.DATSEQ) {
/* Get enumeration to the "inner" DATSEQ */
Enumeration e2 = (Enumeration) elm2.getValue();
elm3 = (DataElement) e2.nextElement();
/* The first element should be a UUID */
if (elm3.getDataType() == DataElement.UUID) {
uuid = (UUID) elm3.getValue();
/* Get short UUID */
int id = BTUUIDTool.shortUUID(uuid);
if (id != -1) {
out = BTUUIDTool.toHexString(id) + ", "
+ BTProtocol.protocolName(id);
} else {
out = "0x" + uuid.toString();
}
y += CanvasHelper.printString(out, X2, y, anchor,
plain, canvasWidth - X2, g);
/*
* If the protocol is L2CAP or RFCOMM, an optional
* parameter is set, the PSM for L2CAP or the
* channel number for RFCOMM.
*/
if ((id == BTProtocol.L2CAP || id == BTProtocol.RFCOMM)
&& e2.hasMoreElements()) {
elm3 = (DataElement) e2.nextElement();
int type = elm3.getDataType();
/*
* The PSM or channel number is expected to be
* an int of some kind
*/
if (type >= DataElement.U_INT_1
&& type <= DataElement.INT_16) {
if (id == BTProtocol.L2CAP) {
out = "PSM: " + elm3.getLong();
} else {
out = "Channel: " + elm3.getLong();
}
y += CanvasHelper.printString(out, X3, y,
anchor, plain, canvasWidth - X3, g);
}
}// End check for protocols and elements in
// DatSeq
} // End check if elm3 is UUID
}// End check for Initial element == DatSeq
}
} catch (ClassCastException cce) {
y += CanvasHelper.printString("Unpredicted object", X3, y,
anchor, plain, canvasWidth - X3, g);
}
}
if (y > canvasHeight)
return;
/* Get the BluetoothProfileDescriptorList */
elm = (DataElement) sr
.getAttributeValue(BTServiceAttributeId.SDP_BLUETOOTHPROFILEDESCRIPTORLIST);
if (elm != null && elm.getDataType() == DataElement.DATSEQ
&& offset++ >= 0) {
y += CanvasHelper.printString("ProfileDescriptorList:", X1, y,
anchor, bold, canvasWidth - X1, g);
/*
* elm should be a DATSEQ of DATSEQ pairs with a UUID and a version
* number
*/
DataElement elm2 = null;
DataElement elm3 = null;
UUID uuid = null;
long version = 0;
try {
/* Iterate through the "outer" DataElement sequence */
Enumeration e = (Enumeration) elm.getValue();
while (e.hasMoreElements()) {
elm2 = (DataElement) e.nextElement();
if (elm2.getDataType() == DataElement.DATSEQ) {
/* Enumerate the "inner" DataElement sequence */
Enumeration e2 = (Enumeration) elm2.getValue();
/*
* This is a Dataelement pair. First DataElement is
* UUID.
*/
elm3 = (DataElement) e2.nextElement();
if (elm3.getDataType() == DataElement.UUID) {
uuid = (UUID) elm3.getValue();
shortUUID = BTUUIDTool.shortUUID(uuid);
if (shortUUID != -1) {
out = BTUUIDTool.toHexString(shortUUID)
+ ", "
+ BTServiceClass
.serviceClassName(shortUUID);
} else {
out = "0x" + uuid.toString();
}
y += CanvasHelper.printString(out, X2, y, anchor,
plain, canvasWidth - X2, g);
}
/*
* The second DataElement is the version number,
* probably stored as an int.
*/
elm3 = (DataElement) e2.nextElement();
int type = elm3.getDataType();
if (type >= DataElement.U_INT_1
&& type <= DataElement.INT_16) {
version = elm3.getLong();
out = "Version";
out += (version <= 0 ? " unknown" : ": " + version);
y += CanvasHelper.printString(out, X3, y, anchor,
plain, canvasWidth - X3, g);
} // End version check
}// End check of "inner" DataElement sequence
}// End iteration through "outer" DataElement sequence
} catch (ClassCastException cce) {
y += CanvasHelper.printString("Unpredicted object", X3, y,
anchor, plain, canvasWidth - X3, g);
}
} // End BluetoothProfileDescriptorList
if (y > canvasHeight)
return;
/* Get the serviceInfoTimeToLive */
elm = (DataElement) sr
.getAttributeValue(BTServiceAttributeId.SDP_SERVICEINFOTIMETOLIVE);
if (elm != null && elm.getDataType() == DataElement.U_INT_4
&& offset++ >= 0) {
long var = elm.getLong();
out = Long.toString(var) + " seconds";
/* Print ServiceInfoTimeToLive */
y += CanvasHelper.printString("ServiceInfoTimeToLive:", X1, y,
anchor, bold, canvasWidth - X1, g);
y += CanvasHelper.printString(out, X2, y, anchor, plain,
canvasWidth - X2, g);
}
if (y > canvasHeight)
return;
/* Get the serviceAvailability */
elm = (DataElement) sr
.getAttributeValue(BTServiceAttributeId.SDP_SERVICEAVAILABILITY);
if (elm != null && elm.getDataType() == DataElement.U_INT_1
&& offset++ >= 0) {
long var = elm.getLong();
out = Long.toString(var) + "/255";
/* Print ServiceAvailability */
y += CanvasHelper.printString("ServiceAvailability:", X1, y,
anchor, bold, canvasWidth - X1, g);
y += CanvasHelper.printString(out, X2, y, anchor, plain,
canvasWidth - X2, g);
}
if (y > canvasHeight)
return;
/* Get the DocumentationURL */
elm = (DataElement) sr
.getAttributeValue(BTServiceAttributeId.SDP_DOCUMENTATIONURL);
if (elm != null && elm.getDataType() == DataElement.URL
&& offset++ >= 0) {
documentationURL = (String) elm.getValue();
/* Print DocumentationURL */
y += CanvasHelper.printString("Documentation URL:", X1, y, anchor,
bold, canvasWidth - X1, g);
y += CanvasHelper.printString(documentationURL, X2, y, anchor,
plain, canvasWidth - X2, g);
}
if (y > canvasHeight)
return;
/* Get the clientExecutableURL */
elm = (DataElement) sr
.getAttributeValue(BTServiceAttributeId.SDP_CLIENTEEXECUTABLEURL);
if (elm != null && elm.getDataType() == DataElement.URL
&& offset++ >= 0) {
clientExecutableURL = (String) elm.getValue();
/* Print clientExecutableURL */
y += CanvasHelper.printString("Client Executable URL:", X1, y,
anchor, bold, canvasWidth - X1, g);
y += CanvasHelper.printString(clientExecutableURL, X2, y, anchor,
plain, canvasWidth - X2, g);
}
if (y > canvasHeight)
return;
/* Get the iconURL */
elm = (DataElement) sr
.getAttributeValue(BTServiceAttributeId.SDP_ICONURL);
if (elm != null && elm.getDataType() == DataElement.URL
&& offset++ >= 0) {
out = (String) elm.getValue();
/* Print Icon URL */
y += CanvasHelper.printString("Icon URL:", X1, y, anchor, bold,
canvasWidth - X1, g);
y += CanvasHelper.printString(out, X2, y, anchor, plain,
canvasWidth - X2, g);
}
}
public void setServiceRecord(ServiceRecord s) {
// TODO Auto-generated method stub
this.sr = s;
clientExecutableURL = null;
documentationURL = null;
attrOffset = 0;
repaint();
}
public String getDocumentationURL() {
// TODO Auto-generated method stub
return documentationURL;
}
public String getClientExecutableURL() {
// TODO Auto-generated method stub
return clientExecutableURL;
}
protected void keyPressed(int keyCode) {
if (keyCode == downKey && y > canvasHeight) {
/*
* Show one attribute less in the top of the canvas, which gives one
* attribute more in the bottom of the canvas.
*/
attrOffset--;
} else if (keyCode == upKey && attrOffset < 0) {
/*
* Show one attribute more in the top of the canvas, which gives one
* attribute less in the bottom of the canvas.
*/
attrOffset++;
}
repaint();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -