Commit c7c1ba93 authored by Kristin Muterspaw's avatar Kristin Muterspaw
Browse files

Font, cursor and activated edit text for database actions activity is now more...

Font, cursor and activated edit text for database actions activity is now more visible. Removed BluetoothSensorFragment and BuiltinSensorsFragment since we don't need it anymore.
parent e4572697
......@@ -82,7 +82,7 @@ public class BluetoothSensor implements Parcelable {
// the GattClient class and anytime these functions are called in that class, the listener in
// this class are called as well. The GattClient class is used for communication with the
// actual bluetooth device. This is used for talking to the BluetoothService and
// BluetoothSensorFragment.
// SensorSampleService.
GattClient.Listener listener = new GattClient.Listener() {
@Override
public void onMessageReceived(byte[] data, BluetoothGattCharacteristic characteristic) {
......
package fieldscience.cs.earlham.edu.fieldday;
import android.app.Activity;
import android.app.ListFragment;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.ListView;
import java.util.ArrayList;
public class BluetoothSensorFragment extends ListFragment {
private static String response;
private static long senseInterval;
private ImageButton rereadButton;
private BluetoothLeService btService;
private BluetoothSensor btSensor;
private Handler btHandler;
Boolean connected, registered;
private Runnable btRunner, sensorRunner;
private ArrayAdapter<aSensor> adapter;
private ArrayList<aSensor> ourSensors;
SensorFragmentCommunication callback;
private static final String TAG = BluetoothSensorFragment.class.getSimpleName();
private ServiceConnection btServiceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
btService = ((BluetoothLeService.LocalBinder) service).getService();
if (!btService.initialize()) {
Log.e("Sensor Sample Activity", "Unable to initialize Bluetooth");
getActivity().finish();
}
boolean connection = btService.connect(btSensor);
if (!connection) {
Log.e("Sensor Sample Activity", "Unable to connect to device");
}
}
@Override
public void onServiceDisconnected(ComponentName name) {
btService = null;
}
};
private final BroadcastReceiver mGattUpdateReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if (BluetoothLeService.ACTION_GATT_CONNECTED.equals(action)) {
} else if (BluetoothLeService.ACTION_GATT_DISCONNECTED.equals(action)) {
btService = null;
btHandler.removeCallbacksAndMessages(btRunner);
} else if (BluetoothLeService.ACTION_GATT_SERVICES_DISCOVERED.equals(action)) {
btService.readMessage();
if (!registered) {
Log.d(TAG, "Services Discovered.");
btHandler.postDelayed(btRunner, 5000);
}
} else if (BluetoothLeService.ACTION_DATA_AVAILABLE.equals(action)) {
if (btService != null) {
if (BluetoothLeService.current_request.equals(BluetoothLeService.LIST_OF_SENSORS)) {
Log.d(TAG, "Receiving List of Sensors");
parseResponse(intent.getStringExtra(BluetoothLeService.EXTRA_DATA));
btHandler.removeCallbacksAndMessages(btRunner);
} else if (BluetoothLeService.current_request.equals(BluetoothLeService.SENSOR_VALUES)){
parseResponse(intent.getStringExtra(BluetoothLeService.EXTRA_DATA));
Log.d(TAG, "Receiving updated Sensor Values");
}
}
}
}
};
public BluetoothSensorFragment(){
//Empty Constructor
}
protected static BluetoothSensorFragment newInstance(BluetoothSensor bluetoothSensor) {
BluetoothSensorFragment fragment = new BluetoothSensorFragment();
Bundle args = new Bundle();
args.putParcelable(SensorSampleActivity.DEVICE, bluetoothSensor);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
if (getArguments() != null) {
btSensor = getArguments().getParcelable(SensorSampleActivity.DEVICE);
}
btHandler = new Handler();
btRunner = new Runnable() {
@Override
public void run() {
getSensorNames();
}
};
sensorRunner = new Runnable() {
@Override
public void run() {
getSensorValues();
}
};
response = "";
Intent gattServiceIntent = new Intent(getActivity().getApplicationContext(), BluetoothLeService.class);
getActivity().getApplicationContext().bindService(gattServiceIntent, btServiceConnection, Context.BIND_AUTO_CREATE);
getActivity().getApplicationContext().registerReceiver(mGattUpdateReceiver, makeGattUpdateIntentFilter());
ourSensors = new ArrayList<aSensor>();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View list = inflater.inflate(R.layout.sensor_list, container, false);
ListView mBluetoothSensors = (ListView) list.findViewById(android.R.id.list);
adapter = new SensorListAdapter(getActivity(), ourSensors);
mBluetoothSensors.setAdapter(adapter);
rereadButton = (ImageButton) list.findViewById(R.id.rereadButton);
rereadButton.setImageDrawable(getActivity().getResources().getDrawable(R.drawable.reread_unavailable, null));
rereadButton.setClickable(false);
rereadButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getSensorValues();
}
});
registered = false;
connected = false;
return list;
}
@Override
public void onAttach(Activity activity){
super.onAttach(activity);
try {
callback = (SensorFragmentCommunication) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement SensorFragmentCommunication");
}
getActivity().getApplicationContext().registerReceiver(mGattUpdateReceiver, makeGattUpdateIntentFilter());
}
@Override
public void onDetach(){
super.onDetach();
btHandler.removeCallbacksAndMessages(btRunner);
if (btService != null) {
btService.disconnect();
btService.close();
getActivity().getApplicationContext().unbindService(btServiceConnection);
getActivity().getApplicationContext().unregisterReceiver(mGattUpdateReceiver);
}
}
public void getSensorNames(){
String getSensors = "00";
byte b = 0x00;
byte[] tmp = getSensors.getBytes();
byte[] tx = new byte[tmp.length + 1];
tx[0] = b;
for (int i = 1; i < tmp.length + 1; i++) {
tx[i] = tmp[i - 1];
}
Log.d(TAG, "Writing message for sensor names.");
btService.writeMessage(tx, BluetoothLeService.LIST_OF_SENSORS);
btHandler.removeCallbacksAndMessages(btRunner);
}
public void getSensorValues() {
String getSensors = "vals";
byte b = 0x00;
byte[] tmp = getSensors.getBytes();
byte[] tx = new byte[tmp.length + 1];
tx[0] = b;
for (int i = 1; i < tmp.length + 1; i++) {
tx[i] = tmp[i - 1];
}
Log.d(TAG, "Updating Sensor Values");
btService.writeMessage(tx, BluetoothLeService.SENSOR_VALUES);
}
public void displayData() {
String sensor = "";
Log.d(TAG, "Response: " + response);
for (int i = 0; i < response.length(); i++) {
char c = response.charAt(i);
if (c == ';') {
String delims = "[,]";
String[] tokens = sensor.split(delims);
aSensor sens = getSensor(tokens[1]);
float[] value = {0, 0};
value[0] = Float.parseFloat(tokens[2]);
sens.setLastValue(value, 1);
sens.setLastValueQuality(0);
callback.setSensorList(ourSensors);
adapter.notifyDataSetChanged();
sensor = "";
} else {
sensor += c;
}
}
if (!connected) {
rereadButton.setClickable(true);
rereadButton.setImageDrawable(getActivity().getResources().getDrawable(R.drawable.reread_button, null));
callback.enableButtons();
connected = true;
}
}
public void updateSensorList() {
String sensor = "";
if (!registered) {
for (int i = 0; i < response.length(); i++) {
char c = response.charAt(i);
if (c == ';') {
String delims = "[,]";
String[] tokens = sensor.split(delims);
aSensor sens = new aSensor(tokens[1], tokens[0]);
sens.setPlatform(btSensor.getDeviceName());
ourSensors.add(sens);
sensor = "";
} else {
sensor += c;
}
}
registered = true;
adapter.notifyDataSetChanged();
getSensorValues();
}
}
public void parseResponse(String d){
response += d;
if (response.endsWith("done")) {
if (BluetoothLeService.current_request.equals(BluetoothLeService.LIST_OF_SENSORS)) {
updateSensorList();
} else {
displayData();
}
response = "";
}
}
public aSensor getSensor(String sensorID) {
for (aSensor s : ourSensors) {
String aSensorID = s.getID();
if (sensorID.equals(aSensorID)) {
return s;
}
}
return null;
}
private static IntentFilter makeGattUpdateIntentFilter() {
final IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(BluetoothLeService.ACTION_GATT_CONNECTED);
intentFilter.addAction(BluetoothLeService.ACTION_GATT_DISCONNECTED);
intentFilter.addAction(BluetoothLeService.ACTION_GATT_SERVICES_DISCOVERED);
intentFilter.addAction(BluetoothLeService.ACTION_DATA_AVAILABLE);
return intentFilter;
}
public void sensingControl(Boolean sensing, long interval){
senseInterval = interval;
if(!sensing){
btHandler.removeCallbacks(sensorRunner);
} else {
btHandler.postDelayed(sensorRunner, senseInterval);
}
}
}
package fieldscience.cs.earlham.edu.fieldday;
import android.app.Activity;
import android.app.ListFragment;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import java.util.ArrayList;
import java.util.List;
public class BuiltInSensorsFragment extends ListFragment implements SensorEventListener {
private SensorManager mSensorManager;
private Sensor mSensor;
private ArrayAdapter<aSensor> adapter;
private ArrayList<aSensor> ourSensors;
private List<Sensor> sensorList;
SensorFragmentCommunication callback;
public BuiltInSensorsFragment(){
// Required empty constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mSensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE);
sensorList = mSensorManager.getSensorList(Sensor.TYPE_ALL);
for (Sensor s : sensorList){
mSensorManager.registerListener(this, s, 100000000);
}
ourSensors = new ArrayList<aSensor>();
for (int i=0; i<sensorList.size(); i++) {
aSensor sens = new aSensor(sensorList.get(i));
// This is to figure out which sensors are uncalibrated
String delims = "[ .]+";
String[] tokens = sens.getStringType().split(delims);
sens.setName(tokens[2]);
ourSensors.add(sens);
}
}
@Override
public void onAttach(Activity activity){
super.onAttach(activity);
try {
callback = (SensorFragmentCommunication) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement SensorFragmentCommunication");
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View list = inflater.inflate(R.layout.builtin_list, container, false);
ListView mBuiltInSensors = (ListView) list.findViewById(android.R.id.list);
adapter = new SensorListAdapter(getActivity(), ourSensors);
mBuiltInSensors.setAdapter(adapter);
return list;
}
@Override
public void onDetach() {
super.onDetach();
for (Sensor s : sensorList) {
mSensorManager.unregisterListener(this, s);
}
callback = null;
}
@Override
public final void onAccuracyChanged(Sensor sensor, int accuracy) {
// Do something here if sensor accuracy changes.
}
@Override
public final void onSensorChanged(SensorEvent event) {
Sensor sensor = event.sensor;
aSensor sens = getSensor(sensor);
float[] values = event.values;
switch (sensor.getType()) {
case Sensor.TYPE_ACCELEROMETER:
sens.setLastValue(values, 3);
sens.setID("and1");
break;
case Sensor.TYPE_AMBIENT_TEMPERATURE:
sens.setLastValue(values, 3);
sens.setID("and2");
break;
case Sensor.TYPE_GAME_ROTATION_VECTOR:
sens.setLastValue(values, 3);
sens.setID("and3");
break;
case Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR:
sens.setLastValue(values, 3);
sens.setID("and4");
break;
case Sensor.TYPE_GRAVITY:
sens.setLastValue(values, 3);
sens.setUnits("r");
sens.setID("and5");
break;
case Sensor.TYPE_GYROSCOPE:
sens.setLastValue(values, 3);
sens.setID("and6");
break;
case Sensor.TYPE_GYROSCOPE_UNCALIBRATED:
sens.setLastValue(values, 3);
sens.setID("and7");
break;
case Sensor.TYPE_HEART_RATE:
sens.setLastValue(values, 3);
sens.setID("and8");
break;
case Sensor.TYPE_LIGHT:
sens.setLastValue(values, 1);
sens.setID("and9");
break;
case Sensor.TYPE_LINEAR_ACCELERATION:
sens.setLastValue(values, 3);
sens.setID("and10");
break;
case Sensor.TYPE_MAGNETIC_FIELD:
sens.setLastValue(values, 3);
sens.setID("and11");
break;
case Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED:
sens.setLastValue(values, 3);
sens.setID("and12");
break;
case Sensor.TYPE_PRESSURE:
sens.setLastValue(values, 3);
sens.setID("and13");
break;
case Sensor.TYPE_PROXIMITY:
sens.setLastValue(values, 3);
sens.setID("and14");
break;
case Sensor.TYPE_RELATIVE_HUMIDITY:
sens.setLastValue(values, 3);
sens.setID("and15");
break;
case Sensor.TYPE_ROTATION_VECTOR:
sens.setLastValue(values, 3);
sens.setID("and16");
break;
case Sensor.TYPE_SIGNIFICANT_MOTION:
sens.setLastValue(values, 3);
sens.setID("and17");
break;
case Sensor.TYPE_STEP_COUNTER:
sens.setLastValue(values, 3);
sens.setID("and18");
break;
case Sensor.TYPE_STEP_DETECTOR:
sens.setLastValue(values, 3);
sens.setID("and19");
break;
}
sens.setLastValueQuality(0);
callback.setSensorList(ourSensors);
adapter.notifyDataSetChanged();
}
public aSensor getSensor(Sensor sensor) {
for (aSensor s : ourSensors) {
String sensorType = sensor.getStringType();
String aSensorType = s.getStringType();
if (sensorType.equals(aSensorType)) {
return s;
}
}
return null;
}
}
......@@ -79,7 +79,6 @@ public class DatabaseActionsActivity extends Activity {
}
dbName = (EditText) findViewById(R.id.database);
dbName.setHintTextColor(getResources().getColor(R.color.text_green));
database = settings.getString("database_name", null);
dbName.setText(settings.getString("database_name", ""));
dbName.addTextChangedListener(new TextWatcher() {
......@@ -101,7 +100,6 @@ public class DatabaseActionsActivity extends Activity {
});
username = (EditText) findViewById(R.id.username);
username.setHintTextColor(getResources().getColor(R.color.text_green));
uname = settings.getString("username", null);
username.setText(settings.getString("username", ""));
username.addTextChangedListener(new TextWatcher() {
......@@ -124,7 +122,6 @@ public class DatabaseActionsActivity extends Activity {
});
password = (EditText) findViewById(R.id.password);
password.setHintTextColor(getResources().getColor(R.color.text_green));
pass = settings.getString("password", null);
password.setText(settings.getString("password", ""));
password.addTextChangedListener(new TextWatcher() {
......@@ -147,7 +144,6 @@ public class DatabaseActionsActivity extends Activity {
});
server = (EditText) findViewById(R.id.serverIp);
server.setHintTextColor(getResources().getColor(R.color.text_green));
host = settings.getString("host", null);
server.setText(settings.getString("host", ""));
server.addTextChangedListener(new TextWatcher() {
......@@ -170,7 +166,6 @@ public class DatabaseActionsActivity extends Activity {
});
port = (EditText) findViewById(R.id.port);
port.setHintTextColor(getResources().getColor(R.color.text_green));
port.setText(settings.getString("port", "5432"));
port.addTextChangedListener(new TextWatcher() {
@Override
......
......@@ -10,6 +10,9 @@
android:text=""
android:hint="@string/server_ip"
android:layout_alignParentTop="true"
android:textColorHint="@color/dark_gray_blue"
android:textColor="@color/dark_gray_blue"
android:textCursorDrawable="@null"
android:layout_centerHorizontal="true" />
<EditText
......@@ -18,6 +21,9 @@
android:id="@+id/database"
android:text=""
android:hint="@string/database_name"
android:textColorHint="@color/dark_gray_blue"
android:textColor="@color/dark_gray_blue"
android:textCursorDrawable="@null"
android:layout_below="@+id/serverIp"
android:layout_centerHorizontal="true" />
......@@ -27,6 +33,9 @@
android:id="@+id/username"
android:text=""
android:hint="@string/username"
android:textColorHint="@color/dark_gray_blue"
android:textColor="@color/dark_gray_blue"
android:textCursorDrawable="@null"
android:layout_below="@+id/database"
android:layout_centerHorizontal="true" />
......@@ -37,6 +46,9 @@
android:text=""
android:inputType="textPassword"
android:hint="@string/password"
android:textColorHint="@color/dark_gray_blue"
android:textColor="@color/dark_gray_blue"
android:textCursorDrawable="@null"
android:layout_below=<