Multi-threaded Android application for ceg4912's Capstone Project. Navigable entirely through voice command.
hbina / capstoneandroidapp Goto Github PK
View Code? Open in Web Editor NEWAndroid application for ceg4912's capstone project
Android application for ceg4912's capstone project
Sorry for busting in with unsolicited suggestion but I was reading the code and saw the TODO comment to simplify the code. I figured I might be able to provide some general suggestions.
Change from
To
@Override
public void run() {
super.run();
// TODO: Rewrite this...make it a lot simpler than this...
while (isRunning.get()) {
try {
if (BluetoothConnector.getInputStream() == null) {
continue;
}
int availableBytes = BluetoothConnector.getInputStream().available();
if (availableBytes <= 0) {
continue;
}
Log.d(TAG, String.format("Received something from Bluetooth of size:%d", availableBytes));
byte[] rawBytes = new byte[availableBytes];
final int receivedLength = BluetoothConnector.getInputStream().read(rawBytes);
final String receivedString = filterBluetooth((new String(rawBytes, StandardCharsets.UTF_8)));
if (receivedLength <= 1) {
Log.d(TAG, "Delta string recevied => " + receivedString);
continue;
}
Log.d(TAG, "receivedString:" + receivedString);
currentLocation = receivedString;
if (nodesInPath.isEmpty()) {
SpeechServices.addText("Please enter a destination...");
callerActivity.TEXT_VIEW_PATH.setText(nodesInPath.toString());
continue;
}
if (nodesInPath.size() == 1) {
SpeechServices.addText("Congratulation, you have arrived at " + nodesInPath.poll());
callerActivity.TEXT_VIEW_PATH.setText(nodesInPath.toString());
continue;
}
if (!currentLocation.equals(decodeNodeNameToId(nodesInPath.peekFirst()))) {
Log.d(TAG, String.format("currentLocation:%s peekFirst:%s", currentLocation, nodesInPath.peekFirst()));
continue;
}
SpeechServices.addText("You have arrived at " + encodeIdToName(receivedString));
nodesInPath.removeFirst();
BearingRequest bearingRequest = new BearingRequest(currentLocation, nodesInPath.peekFirst(), BearingListener.getBearing());
RequestServices.addBearingRequest(bearingRequest);
callerActivity.TEXT_VIEW_PATH.setText(nodesInPath.toString());
} catch (
IOException exception) {
Log.e(TAG, exception.getMessage());
}
}
Log.d(TAG, "Thread have finished running");
}
The logic is exactly the same but the idea here is to reorganize the main branch to as left as possible to avoid nested conditionals. Nested conditionals are generally more difficult to understand.
Hope this is useful.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.