Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions BTDemo/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.codename1</groupId>
<artifactId>cn1-bluetooth</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.codename1.btle</groupId>
<artifactId>BTDemo</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>BTDemo</name>

<dependencies>
<dependency>
<groupId>com.codenameone</groupId>
<artifactId>codenameone-core</artifactId>
<version>${cn1.version}</version>
</dependency>
<dependency>
<groupId>com.codenameone</groupId>
<artifactId>codenameone-javase</artifactId>
<version>${cn1.version}</version>
</dependency>
<dependency>
<groupId>com.codename1</groupId>
<artifactId>cn1-bluetooth-lib</artifactId>
<version>${project.version}</version>
<type>pom</type>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>com.codenameone</groupId>
<artifactId>codenameone-maven-plugin</artifactId>
<version>${cn1.plugin.version}</version>
<configuration>
<mainClassName>com.codename1.btle.BTDemo</mainClassName>
</configuration>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.codename1.btle;

import ca.weblite.codename1.json.JSONException;
import ca.weblite.codename1.json.JSONObject;
import com.codename1.bluetoothle.Bluetooth;
import com.codename1.components.MultiButton;
import com.codename1.ui.Display;
Expand Down Expand Up @@ -96,19 +94,17 @@ public void actionPerformed(ActionEvent evt) {

@Override
public void actionPerformed(ActionEvent evt) {
try {
JSONObject res = (JSONObject) evt.getSource();
System.out.println("response " + res);

if (res.getString("status").equals("scanResult")) {
//if this is a new device add it
if (!devices.containsKey(res.getString("address"))) {
devices.put(res.getString("address"), res);
updateUI();
}
Map res = (Map) evt.getSource();
System.out.println("response " + res);

String status = (String) res.get("status");
if ("scanResult".equals(status)) {
//if this is a new device add it
String address = (String) res.get("address");
if (!devices.containsKey(address)) {
devices.put(address, res);
updateUI();
}
} catch (JSONException ex) {
ex.printStackTrace();
}
}
}, null, true, Bluetooth.SCAN_MODE_LOW_POWER, Bluetooth.MATCH_MODE_STICKY,
Expand Down Expand Up @@ -147,13 +143,13 @@ public void stop() {
public void destroy() {
}

private void updateUI() throws JSONException {
private void updateUI() {
devicesCnt.removeAll();
Set keys = devices.keySet();
for (Iterator iterator = keys.iterator(); iterator.hasNext();) {
String address = (String) iterator.next();
JSONObject obj = (JSONObject) devices.get(address);
MultiButton mb = new MultiButton(obj.getString("name"));
Map obj = (Map) devices.get(address);
MultiButton mb = new MultiButton((String) obj.get("name"));
mb.setTextLine2(address);
devicesCnt.add(mb);
}
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
<module>javase</module>
<module>win</module>
<module>lib</module>
<module>BTDemo</module>
</modules>
<dependencyManagement>
<dependencies>
Expand Down