package com.amitness.photon;

import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

public class ReceiveActivity extends AppCompatActivity {

    private TextView mTextViewLightLabel;
    private SensorManager mSensorManager;
    private SensorEventListener mEventListenerLight;
    private float lastLightValue;
    private float bgValue = -1;

    private void updateUI() {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                char bit;
                if(bgValue == -1){
                    bgValue = lastLightValue;
                    Log.d("Background Intensity", String.valueOf(bgValue));
                }
                if(lastLightValue > bgValue) {
                    bit = '1';
                }
                else {
                    bit = '0';
                }
                mTextViewLightLabel.append(""+bit);
            }
        });
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_receive);

        mTextViewLightLabel = (TextView) findViewById(R.id.sensorValue);
        mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);

        mEventListenerLight = new SensorEventListener() {
            @Override
            public void onSensorChanged(SensorEvent event) {
                float[] values =event.values;

                lastLightValue = values[0];
                Log.d("Sensor Value", String.valueOf(lastLightValue));
                updateUI();
            }

            @Override
            public void onAccuracyChanged(Sensor sensor, int accuracy) {

            }
        };
    }

    @Override
    public void onResume() {
        super.onResume();
        mSensorManager.registerListener(mEventListenerLight, mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT),SensorManager.SENSOR_DELAY_NORMAL);
    }

    @Override
    public void onStop() {
        mSensorManager.unregisterListener(mEventListenerLight);
        super.onStop();
    }

    public void notifyStart(View v) {
        Log.d("startReceive", "Receive Started");
    }
}
@@ -335,16 +335,45 @@
 tView;%0A%0A
+import java.util.ArrayList;%0A%0A
 public c
@@ -624,16 +624,78 @@
 ue = -1;
+%0A    private ArrayList%3CFloat%3E values = new ArrayList%3CFloat%3E();
 %0A%0A    pr
@@ -1742,24 +1742,25 @@
     
-float%5B%5D v
+lastLightV
 alue
-s
  =
+ 
 even
@@ -1767,18 +1767,20 @@
 t.values
+%5B0%5D
 ;
-%0A
 %0A       
@@ -1780,32 +1780,43 @@
                 
+values.add(
 lastLightValue =
@@ -1817,20 +1817,9 @@
 alue
- = values%5B0%5D
+)
 ;%0A  
@@ -2319,24 +2319,83 @@
  onStop() %7B%0A
+        Log.d(%22Read all values:%22, String.valueOf(values));%0A
         mSen

Use ArrayList for storing sensor readings