Finish off SlamController
This commit is contained in:
@@ -2,6 +2,10 @@ package com.example.carcontroller.SLAM;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.SurfaceHolder;
|
||||
import android.view.SurfaceView;
|
||||
@@ -13,12 +17,12 @@ import com.google.protobuf.ByteString;
|
||||
|
||||
public class SlamView extends SurfaceView implements SlamUpdater.MapChangedListener {
|
||||
|
||||
SlamUpdater slam;
|
||||
Thread mapThread;
|
||||
Context context;
|
||||
private SlamUpdater slam;
|
||||
private Thread mapThread;
|
||||
private Context context;
|
||||
private int width;
|
||||
private int height;
|
||||
private SurfaceHolder surfaceHolder;
|
||||
private Paint paint;
|
||||
|
||||
public SlamView(Context context) {
|
||||
super(context);
|
||||
@@ -44,6 +48,9 @@ public class SlamView extends SurfaceView implements SlamUpdater.MapChangedListe
|
||||
String port = prefs.getString("zmqPort", "5050");
|
||||
slam = new ZmqSlamUpdater(host, port);
|
||||
slam.addMapChangedListener(this);
|
||||
surfaceHolder = getHolder();
|
||||
paint = new Paint();
|
||||
paint.setColor(Color.BLUE);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,6 +73,27 @@ public class SlamView extends SurfaceView implements SlamUpdater.MapChangedListe
|
||||
|
||||
@Override
|
||||
public void mapChanged(ByteString map, SlamLocation location) {
|
||||
if (surfaceHolder.getSurface().isValid()) {
|
||||
Canvas canvas = surfaceHolder.lockCanvas();
|
||||
canvas.save();
|
||||
canvas.drawColor(Color.WHITE);
|
||||
// Using width as we want square.
|
||||
Bitmap bitmap = Bitmap.createBitmap(width, width, Bitmap.Config.ALPHA_8);
|
||||
for (int i = 0; i < width; i++) {
|
||||
for (int j = 0; j < width; j++) {
|
||||
// 0-255 is appropriate for the config used.
|
||||
bitmap.setPixel(i, j, map.byteAt(i * width + j));
|
||||
}
|
||||
}
|
||||
canvas.drawBitmap(bitmap, 0, 0, paint);
|
||||
canvas.restore();
|
||||
surfaceHolder.unlockCanvasAndPost(canvas);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(int w, int b, int oldW, int oldB) {
|
||||
super.onSizeChanged(w, b, oldW, oldB);
|
||||
width = w;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user