Skip to content

Commit

Permalink
fix building apk. duplicated classes are removed and renamed.
Browse files Browse the repository at this point in the history
  • Loading branch information
kuri65536 committed Feb 8, 2017
1 parent e7cacc7 commit d627511
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 121 deletions.
Expand Up @@ -28,7 +28,7 @@
import com.googlecode.android_scripting.bt4facade.R;
import com.googlecode.android_scripting.Constants;
import com.googlecode.android_scripting.activity.CustomizeWindow;
import com.googlecode.android_scripting.bluetooth.BluetoothDiscoveryHelper.BluetoothDiscoveryListener;
import com.googlecode.android_scripting.bluetooth.facade.BluetoothDiscoveryHelper;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -78,7 +78,8 @@ protected void onListItemClick(android.widget.ListView l, View v, int position,
finish();
};

private class DeviceListAdapter extends BaseAdapter implements BluetoothDiscoveryListener {
private class DeviceListAdapter extends BaseAdapter
implements BluetoothDiscoveryHelper.BluetoothDiscoveryListener {
List<DeviceInfo> mmDeviceList;

public DeviceListAdapter() {
Expand Down

This file was deleted.

Expand Up @@ -77,8 +77,8 @@ public class Bluetooth4Facade extends RpcReceiver {
private static final Object mReceiverLock = new Object();
private BluetoothStateReceiver mMultiStateReceiver;
private final BleStateReceiver mBleStateReceiver;
private Map<String, BluetoothConnection> connections =
new HashMap<String, BluetoothConnection>();
private Map<String, Bluetooth4Connection> connections =
new HashMap<String, Bluetooth4Connection>();
private AndroidFacade mAndroidFacade;
private BluetoothAdapter mBluetoothAdapter;

Expand Down Expand Up @@ -223,7 +223,7 @@ public void bluetoothMakeConnectable() {
@Rpc(description = "Returns active Bluetooth connections.")
public Map<String, String> bluetoothActiveConnections() {
Map<String, String> out = new HashMap<String, String>();
for (Map.Entry<String, BluetoothConnection> entry : connections.entrySet()) {
for (Map.Entry<String, Bluetooth4Connection> entry : connections.entrySet()) {
if (entry.getValue().isConnected()) {
out.put(entry.getKey(), entry.getValue().getRemoteBluetoothAddress());
}
Expand All @@ -232,12 +232,12 @@ public Map<String, String> bluetoothActiveConnections() {
return out;
}

private BluetoothConnection getConnection(String connID) throws IOException {
BluetoothConnection conn = null;
private Bluetooth4Connection getConnection(String connID) throws IOException {
Bluetooth4Connection conn = null;
if (connID.trim().length() > 0) {
conn = connections.get(connID);
} else if (connections.size() == 1) {
conn = (BluetoothConnection) connections.values().toArray()[0];
conn = (Bluetooth4Connection) connections.values().toArray()[0];
}
if (conn == null) {
throw new IOException("Bluetooth not ready for this connID.");
Expand All @@ -250,7 +250,7 @@ public void bluetoothWriteBinary(
@RpcParameter(name = "base64", description = "A base64 encoded String of the bytes to be sent.") String base64,
@RpcParameter(name = "connID", description = "Connection id") @RpcDefault("") @RpcOptional String connID)
throws IOException {
BluetoothConnection conn = getConnection(connID);
Bluetooth4Connection conn = getConnection(connID);
try {
conn.write(Base64Codec.decodeBase64(base64));
} catch (IOException e) {
Expand All @@ -264,8 +264,7 @@ public String bluetoothReadBinary(
@RpcParameter(name = "bufferSize") @RpcDefault("4096") Integer bufferSize,
@RpcParameter(name = "connID", description = "Connection id") @RpcDefault("") @RpcOptional String connID)
throws IOException {

BluetoothConnection conn = getConnection(connID);
Bluetooth4Connection conn = getConnection(connID);
try {
return Base64Codec.encodeBase64String(conn.readBinary(bufferSize));
} catch (IOException e) {
Expand All @@ -274,7 +273,7 @@ public String bluetoothReadBinary(
}
}

private String addConnection(BluetoothConnection conn) {
private String addConnection(Bluetooth4Connection conn) {
String uuid = UUID.randomUUID().toString();
connections.put(uuid, conn);
conn.setUUID(uuid);
Expand All @@ -298,13 +297,13 @@ public String bluetoothConnect(
}
BluetoothDevice mDevice;
BluetoothSocket mSocket;
BluetoothConnection conn;
Bluetooth4Connection conn;
mDevice = mBluetoothAdapter.getRemoteDevice(address);
mSocket = mDevice.createRfcommSocketToServiceRecord(UUID.fromString(uuid));
// Always cancel discovery because it will slow down a connection.
mBluetoothAdapter.cancelDiscovery();
mSocket.connect();
conn = new BluetoothConnection(mSocket);
conn = new Bluetooth4Connection(mSocket);
return addConnection(conn);
}

Expand All @@ -317,7 +316,7 @@ public String bluetoothAccept(
mServerSocket =
mBluetoothAdapter.listenUsingRfcommWithServiceRecord(SDP_NAME, UUID.fromString(uuid));
BluetoothSocket mSocket = mServerSocket.accept(timeout.intValue());
BluetoothConnection conn = new BluetoothConnection(mSocket, mServerSocket);
Bluetooth4Connection conn = new Bluetooth4Connection(mSocket, mServerSocket);
return addConnection(conn);
}

Expand All @@ -343,7 +342,7 @@ public void bluetoothMakeDiscoverable(
public void bluetoothWrite(@RpcParameter(name = "ascii") String ascii,
@RpcParameter(name = "connID", description = "Connection id") @RpcDefault("") String connID)
throws IOException {
BluetoothConnection conn = getConnection(connID);
Bluetooth4Connection conn = getConnection(connID);
try {
conn.write(ascii);
} catch (IOException e) {
Expand All @@ -356,7 +355,7 @@ public void bluetoothWrite(@RpcParameter(name = "ascii") String ascii,
public Boolean bluetoothReadReady(
@RpcParameter(name = "connID", description = "Connection id") @RpcDefault("") @RpcOptional String connID)
throws IOException {
BluetoothConnection conn = getConnection(connID);
Bluetooth4Connection conn = getConnection(connID);
try {
return conn.readReady();
} catch (IOException e) {
Expand All @@ -370,7 +369,7 @@ public String bluetoothRead(
@RpcParameter(name = "bufferSize") @RpcDefault("4096") Integer bufferSize,
@RpcParameter(name = "connID", description = "Connection id") @RpcOptional @RpcDefault("") String connID)
throws IOException {
BluetoothConnection conn = getConnection(connID);
Bluetooth4Connection conn = getConnection(connID);
try {
return conn.read(bufferSize);
} catch (IOException e) {
Expand All @@ -383,7 +382,7 @@ public String bluetoothRead(
public String bluetoothReadLine(
@RpcParameter(name = "connID", description = "Connection id") @RpcOptional @RpcDefault("") String connID)
throws IOException {
BluetoothConnection conn = getConnection(connID);
Bluetooth4Connection conn = getConnection(connID);
try {
return conn.readLine();
} catch (IOException e) {
Expand Down Expand Up @@ -448,7 +447,7 @@ public int bluetoothGetScanMode() {
public String bluetoothGetConnectedDeviceName(
@RpcParameter(name = "connID", description = "Connection id") @RpcOptional @RpcDefault("") String connID)
throws IOException {
BluetoothConnection conn = getConnection(connID);
Bluetooth4Connection conn = getConnection(connID);
return conn.getConnectedDeviceName();
}

Expand Down Expand Up @@ -498,7 +497,7 @@ public Boolean toggleBluetoothState(
@Rpc(description = "Stops Bluetooth connection.")
public void bluetoothStop(
@RpcParameter(name = "connID", description = "Connection id") @RpcOptional @RpcDefault("") String connID) {
BluetoothConnection conn;
Bluetooth4Connection conn;
try {
conn = getConnection(connID);
} catch (IOException e) {
Expand Down Expand Up @@ -653,15 +652,15 @@ public boolean bluetoothStopListeningForAdapterStateChange() {

@Override
public void shutdown() {
for (Map.Entry<String, BluetoothConnection> entry : connections.entrySet()) {
for (Map.Entry<String, Bluetooth4Connection> entry : connections.entrySet()) {
entry.getValue().stop();
}
if (mMultiStateReceiver != null ) bluetoothStopListeningForAdapterStateChange();
connections.clear();
}
}

class BluetoothConnection {
class Bluetooth4Connection {
private BluetoothSocket mSocket;
private BluetoothDevice mDevice;
private OutputStream mOutputStream;
Expand All @@ -670,11 +669,11 @@ class BluetoothConnection {
private BluetoothServerSocket mServerSocket;
private String UUID;

public BluetoothConnection(BluetoothSocket mSocket) throws IOException {
public Bluetooth4Connection(BluetoothSocket mSocket) throws IOException {
this(mSocket, null);
}

public BluetoothConnection(BluetoothSocket mSocket, BluetoothServerSocket mServerSocket)
public Bluetooth4Connection(BluetoothSocket mSocket, BluetoothServerSocket mServerSocket)
throws IOException {
this.mSocket = mSocket;
mOutputStream = mSocket.getOutputStream();
Expand Down

0 comments on commit d627511

Please sign in to comment.