MainActivity

public class MainActivity extends AppCompatActivity

The MainActivity class contains, you guessed it, the main part of the code. This does basically EVERYTHING! It provides a UI, but that isn’t really functional anymore (I mean, you’re not going up with your high altitude balloon). It’s better explained in the chunks of code down below, because this whole thing is sort of an amalgamation of various bits of functionality and strokes of genius (maybe just strokes, idk).

Author:Alan Zhu, Joshua Morin-Baxter

Fields

ACTION_USB_PERMISSION

public static final String ACTION_USB_PERMISSION

aLin_x

float aLin_x

aLin_y

float aLin_y

aLin_z

float aLin_z

accelerometer

Sensor accelerometer

accelerometer2

Sensor accelerometer2

accelerometer2Listener

SensorEventListener accelerometer2Listener

accelerometerListener

SensorEventListener accelerometerListener

actualA_x

float actualA_x

actualA_y

float actualA_y

actualA_z

float actualA_z

arduinoInRecent

String arduinoInRecent

captureCallback

Camera.PictureCallback captureCallback

ch

byte ch

connection

UsbDeviceConnection connection

course

float course

dataPointArrayList

ArrayList<DataPoint> dataPointArrayList

device

UsbDevice device

editText

EditText editText

ext_alt

float ext_alt

ext_altEST

float ext_altEST

ext_lat

float ext_lat

ext_lon

float ext_lon

ext_p

float ext_p

ext_rh

float ext_rh

ext_temp

float ext_temp

flash

Camera flash

gps_speed

float gps_speed

gravity

Sensor gravity

gravityListener

SensorEventListener gravityListener

gravity_x

float gravity_x

gravity_y

float gravity_y

gravity_z

float gravity_z

humidity

Sensor humidity

humidityListener

SensorEventListener humidityListener

iterReading

int iterReading

mMediaRecorder

MediaRecorder mMediaRecorder

mVideoCamera

Camera mVideoCamera

magnet

Sensor magnet

magnetListener

SensorEventListener magnetListener

magnetic_x

float magnetic_x

magnetic_y

float magnetic_y

magnetic_z

float magnetic_z

mainCamera

Camera mainCamera

nTexture

int nTexture

pAsInPressure

float pAsInPressure

pressure

Sensor pressure

pressureListener

SensorEventListener pressureListener

rCamera

Runnable rCamera

rSensors

Runnable rSensors

relativeHumidity

float relativeHumidity

rootTest

Button rootTest

rot_x

float rot_x

rot_y

float rot_y

rot_z

float rot_z

rotation

Sensor rotation

rotationListener

SensorEventListener rotationListener

runnableManager

final Handler runnableManager

sensorFileName

Date sensorFileName

serialPort

UsbSerialDevice serialPort

startButton

Button startButton

stoppedN

int stoppedN

tAsInTemperature

float tAsInTemperature

tMinusBackup

public long tMinusBackup

temperature

Sensor temperature

temperatureListener

SensorEventListener temperatureListener

textView

TextView textView

usbManager

UsbManager usbManager

useThisOne

SurfaceTexture useThisOne

Methods

flashLightOff

public void flashLightOff(View view)

This one turns the flashlight off if the flashlight is on. It’s not called because flashLightOn(View) doesn’t work either and isn’t called.

Parameters:
  • view – Just in case you wanted to open call this method with a UI button, but passing in null is fine.

flashLightOn

public void flashLightOn(View view)

A piece of code that wrestles control of the camera from the main photo-taking thread before turning on the camera flashlight on the back, in order to make the payload easier to find at night. It is not used primarily because it’s so difficult to implement interlacing between the main camera and this flashlight camera, but hopefully it can be fixed at some point.

Parameters:
  • view – Just in case you wanted to open call this method with a UI button, but passing in null is fine.

getBatteryPercentage

public static int getBatteryPercentage(Context context)

Gets the current battery to be used for rCamera and rSensors in determining battery saving and to be saved for data analysis

Parameters:
  • context – the context of the application from which battery stats can be pulled
Returns:

the current percentage of the battery

getBatteryTemp

public static int getBatteryTemp(Context context)

Gets battery temperature to determine delay of rCamera and rSensors and to be recorded for data analysis

Parameters:
  • context – the context of the application from which battery stats are to be pulled
Returns:

battery temperature (deciCelsius?)

giveCameraBackToOtherThread

public void giveCameraBackToOtherThread()

In life, sometimes you’ve got to return things you’ve taken forcefully. Control of the camera is no exception. This is like the yin to the takeCameraFromOtherThread()’s yang. It makes the main camera active again and starts the rCamera runnable again.

hackInt

public int hackInt()

At some point, this was used in attempt to solve a problem with the camera of the Samsung Galaxy S4 in order to create SurfaceTextures from within a Runnable. It’s still used but not in the way it was originally intended.

Returns:an id to be used to initialize SurfaceTextures from within a runnable

onClickClear

public void onClickClear(View view)

Clears both the text of the incoming messages and outgoing messages for Arduino connection, meaning that it is no longer used but can be revived along with everything else.

Parameters:
  • view – can be called with null, used to support button clicks

onCreate

protected void onCreate(Bundle savedInstanceState)

Creates the activity and all of its parts. Better to read it than write a description.

Parameters:
  • savedInstanceState – past to the super function, maintaining the saved instance state

onStart

protected void onStart()

Initializes sensors and other things that should not be done in onCreate

onStop

protected void onStop()

de-initializes sensors and things that should be destroyed before onDestroyed

record

public void record(View view)

Starts recording data and taking photos at the start of the activity and in testing with the UI. It changes rates depending on heat to avoid overheating the phone at altitude. Some of this is better to read than to describe.

Parameters:
  • view – Used to allow for UI interaction to start the recording

recordButton

public void recordButton()

starts a recording - but isn’t called at all right now

rootTest

public boolean rootTest()

Tests if the phone is rooted, although that is unimportant to the app as of now. This could be used to further exploit the abilities of the phone being used.

Returns:True if root is available on the phone, False if not

setUiEnabled

public void setUiEnabled(boolean bool)

Code that enables/disables the Arduino connection UI. It is no longer used by the app but should be revived with the Arduino code when the time comes.

Parameters:
  • bool – state of the variables - if connected, it should be true

stopRecord

public void stopRecord(View view)

Stops all recording of sensors and photos.

Parameters:
  • view – to be used from UI

takeCameraFromOtherThread

public void takeCameraFromOtherThread()

This is the code that does the actual wrestling for flashLightOn(View). It kills the camera and opens it up to domination by another thread.