Skip to content

Commit

Permalink
Added NPE where needed and add javadocs
Browse files Browse the repository at this point in the history
git-svn-id: https://android-motion-detection.googlecode.com/svn/trunk@20 996b93ed-3e4d-4b21-1044-74bd19560d1d
  • Loading branch information
[email protected] committed Oct 3, 2011
1 parent 891f971 commit 23bdbce
Show file tree
Hide file tree
Showing 8 changed files with 191 additions and 19 deletions.
34 changes: 32 additions & 2 deletions src/com/jwetherell/motion_detection/MotionDetectionActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public class MotionDetectionActivity extends Activity {

private static volatile AtomicBoolean processing = new AtomicBoolean(false);

/**
* {@inheritDoc}
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -62,18 +65,27 @@ public void onCreate(Bundle savedInstanceState) {
}
}

/**
* {@inheritDoc}
*/
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}

/**
* {@inheritDoc}
*/
@Override
public void onResume() {
super.onResume();

camera = Camera.open();
}

/**
* {@inheritDoc}
*/
@Override
public void onPause() {
super.onPause();
Expand All @@ -86,6 +98,9 @@ public void onPause() {
}

private PreviewCallback previewCallback = new PreviewCallback() {
/**
* {@inheritDoc}
*/
@Override
public void onPreviewFrame(byte[] data, Camera cam) {
if (data == null) return;
Expand All @@ -98,6 +113,9 @@ public void onPreviewFrame(byte[] data, Camera cam) {
};

private SurfaceHolder.Callback surfaceCallback=new SurfaceHolder.Callback() {
/**
* {@inheritDoc}
*/
@Override
public void surfaceCreated(SurfaceHolder holder) {
try {
Expand All @@ -108,6 +126,9 @@ public void surfaceCreated(SurfaceHolder holder) {
}
}

/**
* {@inheritDoc}
*/
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
Camera.Parameters parameters = camera.getParameters();
Expand All @@ -121,6 +142,9 @@ public void surfaceChanged(SurfaceHolder holder, int format, int width, int heig
inPreview=true;
}

/**
* {@inheritDoc}
*/
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
// Ignore
Expand Down Expand Up @@ -156,8 +180,11 @@ public DetectionThread(byte[] data, int width, int height) {
this.width = width;
this.height = height;
}

@Override

/**
* {@inheritDoc}
*/
@Override
public void run() {
if (!processing.compareAndSet(false, true)) return;

Expand Down Expand Up @@ -227,6 +254,9 @@ public void run() {
};

private class SavePhotoTask extends AsyncTask<Bitmap, Integer, Integer> {
/**
* {@inheritDoc}
*/
@Override
protected Integer doInBackground(Bitmap... data) {
for (int i=0; i<data.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public class AggregateLumaMotionDetection implements IMotionDetection {
private static int mPreviousHeight;
private static State mPreviousState = null;

/**
* {@inheritDoc}
*/
@Override
public int[] getPrevious() {
return ((mPrevious!=null)?mPrevious.clone():null);
}
Expand Down Expand Up @@ -54,7 +58,12 @@ protected static boolean isDifferent(int[] first, int width, int height) {

return different;
}


/**
* Detect motion using aggregate luma values.
* {@inheritDoc}
*/
@Override
public boolean detect(int[] luma, int width, int height) {
if (luma==null) throw new NullPointerException();

Expand Down
36 changes: 35 additions & 1 deletion src/com/jwetherell/motion_detection/detection/Comparer.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@ public Comparer(State s1, State s2, int xBoxes, int yBoxes, int leniency, int de
this.different = isDifferent(this.state1,this.state2);
}

// compare two images and populate the variance variable
/**
* Compare two images and populate the variance variable
* @param s1 State for image one.
* @param s2 State for image two.
* @return True is the two images are different.
* @throws NullPointerException if s1 or s2 is NULL.
*/
public boolean isDifferent(State s1, State s2) {
if (s1==null || s2==null)
throw new NullPointerException();
Expand Down Expand Up @@ -111,6 +117,11 @@ private int aggregateMapArea(int[] map, int xBox, int yBox) {
return (i/(xPix*yPix));
}

/**
* Given the int array of an image, paint the pixels that are different.
* @param data int array of an image.
* @throws NullPointerException if data int array is NULL.
*/
public void paintDifferences(int[] data) {
if (data==null) throw new NullPointerException();

Expand Down Expand Up @@ -141,26 +152,49 @@ private void paint(int[] data, int xBox, int yBox, int color) {
}
}

/**
* Number of X Boxes.
* @return int representing the number of X boxes.
*/
public int getCompareX() {
return xBoxes;
}

/**
* Number of Y Boxes.
* @return int representing the number of Y boxes.
*/
public int getCompareY() {
return yBoxes;
}

/**
* Leniency of the pixel comparison.
* @return int representing the leniency.
*/
public int getLeniency() {
return leniency;
}

/**
* Debug mode of the comparer.
* @return int representing the debug mode.
*/
public int getDebugMode() {
return debugMode;
}

/**
* Are the two States different.
* @return True is the States are different.
*/
public boolean isDifferent() {
return different;
}

/**
* {@inheritDoc}
*/
@Override
public String toString() {
int diff = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,19 @@
*/
public interface IMotionDetection {

/**
* Get the previous image in integer array format
* @return int array of previous image.
*/
public int[] getPrevious();


/**
* Detect motion.
* @param data integer array representing an image.
* @param width Width of the image.
* @param height Height of the image.
* @return boolean True is there is motion.
* @throws NullPointerException if data integer array is NULL.
*/
public boolean detect(int[] data, int width, int height);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public class LumaMotionDetection implements IMotionDetection {
private static int mPreviousWidth = 0;
private static int mPreviousHeight = 0;

/**
* {@inheritDoc}
*/
@Override
public int[] getPrevious() {
return ((mPrevious!=null)?mPrevious.clone():null);
}
Expand Down Expand Up @@ -65,7 +69,12 @@ protected static boolean isDifferent(int[] first, int width, int height) {

return different;
}


/**
* Detect motion using comparing luma values.
* {@inheritDoc}
*/
@Override
public boolean detect(int[] luma, int width, int height) {
if (luma==null) throw new NullPointerException();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ public class RgbMotionDetection implements IMotionDetection {
private static int[] mPrevious = null;
private static int mPreviousWidth = 0;
private static int mPreviousHeight = 0;


/**
* {@inheritDoc}
*/
@Override
public int[] getPrevious() {
return ((mPrevious!=null)?mPrevious.clone():null);
}
Expand Down Expand Up @@ -65,7 +69,12 @@ protected static boolean isDifferent(int[] first, int width, int height) {

return different;
}


/**
* Detect motion comparing RGB pixel values.
* {@inheritDoc}
*/
@Override
public boolean detect(int[] rgb, int width, int height) {
if (rgb==null) throw new NullPointerException();

Expand Down
15 changes: 15 additions & 0 deletions src/com/jwetherell/motion_detection/detection/State.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,33 @@ public State(int[] data, int width, int height) {
this.average = (this.average / (this.width * this.height));
}

/**
* Get Map of the State.
* @return integer array of the State.
*/
public int[] getMap() {
return map;
}

/**
* Get the width of the State.
* @return integer representing the width of the state.
*/
public int getWidth() {
return width;
}

/**
* Get the height of the State.
* @return integer representing the height of the state.
*/
public int getHeight() {
return height;
}

/**
* {@inheritDoc}
*/
@Override
public String toString() {
StringBuilder output = new StringBuilder();
Expand Down
Loading

0 comments on commit 23bdbce

Please sign in to comment.