Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

cleanup, mostly final local vars

  • Loading branch information...
commit 13c885e5d24e5c69a6687d617409d254681ab606 1 parent c917294
@jonasb jonasb authored
View
1  AutomatonBrain.iml
@@ -32,6 +32,7 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/gen" isTestSource="false" />
+ <excludeFolder url="file://$MODULE_DIR$/ffmpeg-android" />
</content>
<orderEntry type="jdk" jdkName="Android 2.3.3 Google APIs" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
View
30 src/se/forskningsavd/Communicator.java
@@ -37,23 +37,23 @@ public ReceiverThread(DatagramSocket socket, SenderThread senderThread, Decoder
@Override
public void run() {
- byte[] buf = new byte[3000];
+ final byte[] buf = new byte[3000];
while (mRunning) {
try {
- DatagramPacket dp = new DatagramPacket(buf, buf.length);
+ final DatagramPacket dp = new DatagramPacket(buf, buf.length);
mSocket.receive(dp);
- StringBuilder debug = new StringBuilder();
+ final StringBuilder debug = new StringBuilder();
final int length = dp.getLength();
if (length < 1000) {
for (int i = 0; i < length; i++) {
debug.append(String.format("%02x", dp.getData()[i]));
}
}
- String rcvd = "rcvd from " + dp.getAddress() + ", " + dp.getPort() + ", " + length + " bytes : "
+ final String rcvd = "rcvd from " + dp.getAddress() + ", " + dp.getPort() + ", " + length + " bytes : "
+ debug;
Log.d("XXX", rcvd);
- ByteBuffer data = ByteBuffer.wrap(dp.getData());
+ final ByteBuffer data = ByteBuffer.wrap(dp.getData());
if (data.get(0) == 0 &&
data.get(1) == 0 &&
data.get(2) == 0 &&
@@ -68,7 +68,7 @@ public void run() {
// TODO signed vs unsigned
final byte trustServer = data.get(4);
final byte trustClient = data.get(5);
- int timer = data.getInt(6);
+ final int timer = data.getInt(6);
mSenderThread.onServerData(trustServer, trustClient);
//TODO handle server trusted data
@@ -106,13 +106,13 @@ public SenderThread(DatagramSocket socket, Navigator navigator) {
@Override
public void run() {
- InetAddress hostAddress;
+ final InetAddress hostAddress;
try {
hostAddress = InetAddress.getByName(Settings.HOST);
final String message = "HELO";
- byte[] buf = message.getBytes();
+ final byte[] buf = message.getBytes();
- DatagramPacket out = new DatagramPacket(buf, buf.length, hostAddress, Settings.PORT);
+ final DatagramPacket out = new DatagramPacket(buf, buf.length, hostAddress, Settings.PORT);
mSocket.send(out);
} catch (IOException e) {
e.printStackTrace();
@@ -132,7 +132,7 @@ public void run() {
if (mNavigator.down)
kb |= 1 << 3;
//TODO reuse buffer/modify the data
- ByteBuffer buffer = ByteBuffer.allocate(1024);
+ final ByteBuffer buffer = ByteBuffer.allocate(1024);
buffer.order(ByteOrder.LITTLE_ENDIAN);
buffer.put("CTRL".getBytes());
buffer.put(mTrustServer);
@@ -165,10 +165,10 @@ public void run() {
}
}
- DatagramPacket out = new DatagramPacket(buffer.array(), buffer.position(), hostAddress, 6979);
+ final DatagramPacket out = new DatagramPacket(buffer.array(), buffer.position(), hostAddress, 6979);
try {
mSocket.send(out);
- StringBuilder debug = new StringBuilder();
+ final StringBuilder debug = new StringBuilder();
for (int i = 0; i < buffer.position(); i++) {
debug.append(String.format("%02x", buffer.get(i)));
}
@@ -207,7 +207,7 @@ public void onServerData(byte trustServer, byte trustClient) {
}
public void addTrustedMessage(byte[] ident, byte[] message) {
- ByteBuffer buf = ByteBuffer.allocate(ident.length + 1 + message.length);
+ final ByteBuffer buf = ByteBuffer.allocate(ident.length + 1 + message.length);
buf.put(ident);
buf.put((byte) message.length);
buf.put(message);
@@ -244,8 +244,8 @@ public void connect() {
mSenderThread = new SenderThread(socket, mNavigator);
mSenderThread.start();
- Decoder d = new Decoder();
- Log.d("decode", "init(): " + d.init());
+ final Decoder d = new Decoder();
+ d.init();
final Handler handler = new Handler(new Handler.Callback() {
public boolean handleMessage(Message message) {
View
2  src/se/forskningsavd/Decoder.java
@@ -2,7 +2,7 @@
import android.graphics.Bitmap;
-public class Decoder {
+class Decoder {
public native boolean init();
public native boolean decode(byte[] frame, Bitmap target);
View
12 src/se/forskningsavd/MainActivity.java
@@ -19,15 +19,15 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final ImageView video = new ImageView(this);
- Navigator nav = new Navigator();
- Bitmap target = Bitmap.createBitmap(320, 240, Bitmap.Config.ARGB_8888);
+ final Navigator nav = new Navigator();
+ final Bitmap target = Bitmap.createBitmap(320, 240, Bitmap.Config.ARGB_8888);
mCommunicator = new Communicator(nav, target, new Communicator.Callback() {
public void onTargetImageChanged(Bitmap bitmap) {
video.invalidate();
}
});
- LinearLayout layout = new LinearLayout(this);
+ final LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
final Button button = new Button(this);
@@ -40,7 +40,7 @@ public void onClick(View view) {
});
layout.addView(button);
- Button helloWorld = new Button(this);
+ final Button helloWorld = new Button(this);
helloWorld.setText("Automaton brain");
helloWorld.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
@@ -50,12 +50,12 @@ public void onClick(View view) {
});
layout.addView(helloWorld);
- FrameLayout frame = new FrameLayout(this);
+ final FrameLayout frame = new FrameLayout(this);
video.setImageBitmap(target);
frame.addView(video);
- NavigationView navigationView = new NavigationView(this, nav);
+ final NavigationView navigationView = new NavigationView(this, nav);
frame.addView(navigationView);
layout.addView(frame, MATCH_PARENT, MATCH_PARENT);
Please sign in to comment.
Something went wrong with that request. Please try again.