Commit 8df68108 authored by Kristin Muterspaw's avatar Kristin Muterspaw
Browse files

Built in sensors now works with more than a Google device.

parent 37c70b07
......@@ -59,7 +59,11 @@
android:label="My Documents Viewer"
android:theme="@style/MainTheme">
</activity>
<activity
android:name=".BenchSampleActivity"
android:label="Bench Sampling"
android:theme="@style/MainTheme">
</activity>
<service
android:name=".BluetoothLeService"
android:enabled="true" />
......
......@@ -79,6 +79,10 @@ public class MainScreenActivity extends Activity {
i.putExtra(SensorSampleActivity.WHICH_SENSOR, "built-in");
checkDatabase(i);
break;
case R.id.buttonBenchSample:
i = new Intent(context, BenchSampleActivity.class);
checkDatabase(i);
break;
}
}
......
......@@ -27,6 +27,8 @@ public class ReadingsDatabase extends SQLiteOpenHelper {
// Name of database
public static final String DB_NAME = "readings.db";
private static final String TAG = ReadingsDatabase.class.getSimpleName();
// Name of tables
public static final String T_TRIP = "fieldday_trip";
public static final String T_SITE = "fieldday_site";
......@@ -416,11 +418,47 @@ public class ReadingsDatabase extends SQLiteOpenHelper {
db.close();
}
public List<String> getSectors(){
public List<String> getSpots(String site, String sector){
SQLiteDatabase db = this.getReadableDatabase();
String[] columns = {"sectorName"};
Cursor c = db.query(T_SECTOR, columns, null, null, null, null, null);
List<String> values = new ArrayList<String>();
Cursor c = null;
List<String> values = new ArrayList<>();
if ((site != null) && (sector != null)){
c = db.query(T_SECTOR, new String[]{C_SECTORID}, "sectorName = ?", new String[]{sector},
null, null, null);
c.moveToFirst();
int sectorid = c.getInt(c.getColumnIndex(C_SECTORID));
c.close();
c = db.query(T_SITE, new String[]{C_SITEID}, "siteName = ?", new String[]{site},
null, null, null);
c.moveToFirst();
int siteid = c.getInt(c.getColumnIndex(C_SITEID));
c.close();
c = db.query(T_SPOT, new String[] {C_SPOTID}, "siteID = ? and sectorID = ?",
new String[]{Integer.toString(siteid), Integer.toString(sectorid)},
null, null, null);
}
while(c.moveToNext()){
values.add(Integer.toString(c.getInt(c.getColumnIndex(C_SPOTID))));
}
c.close();
return values;
}
public List<String> getSectors(String site){
SQLiteDatabase db = this.getReadableDatabase();
Cursor c = null;
List<String> values = new ArrayList<>();
if (site != null){
c = db.query(T_SITE, new String[]{C_SITEID}, "siteName = ?", new String[]{site},
null, null, null);
c.moveToFirst();
int id = c.getInt(c.getColumnIndex(C_SITEID));
c.close();
c = db.query(T_SECTOR, new String[]{C_SECTORNAME}, "siteID = ?", new String[]{Integer.toString(id)},
null, null, null);
} else {
c = db.query(T_SECTOR, new String[]{C_SECTORNAME}, null, null, null, null, null);
}
while (c.moveToNext()) {
values.add(c.getString(c.getColumnIndex("sectorName")));
}
......@@ -428,7 +466,7 @@ public class ReadingsDatabase extends SQLiteOpenHelper {
return values;
}
public List<String> getSites(){
public List<String> getSites(String trip){
SQLiteDatabase db = this.getReadableDatabase();
String[] columns = {"siteName"};
Cursor c = db.query(T_SITE, columns, null, null, null, null, null);
......@@ -440,6 +478,40 @@ public class ReadingsDatabase extends SQLiteOpenHelper {
return values;
}
public List<String> getPlatforms(){
SQLiteDatabase db = this.getReadableDatabase();
Cursor c = db.query(T_PLATFORM, new String[]{C_PLATFORMNAME}, null, null, null, null, null);
List<String> values = new ArrayList<>();
while (c.moveToNext()){
values.add(c.getString(c.getColumnIndex("platformName")));
}
c.close();
return values;
}
public List<String> getSensors(String platform){
SQLiteDatabase db = this.getReadableDatabase();
List<String> values = new ArrayList<>();
Cursor c = null;
if (platform != null){
c = db.query(T_PLATFORM, new String[]{C_PLATFORMID}, "platformName = ?", new String[]{platform},
null, null, null);
c.moveToFirst();
String platformId = c.getString(c.getColumnIndex(C_PLATFORMID));
Log.d(TAG, platformId);
c.close();
c = db.query(T_SENSOR, new String[]{C_SENSORTYPE}, "platformID = ?", new String[]{platformId},
null, null, null);
} else {
c = db.query(T_SENSOR, new String[]{C_SENSORTYPE}, null, null, null, null, null);
}
while (c.moveToNext()){
values.add(c.getString(c.getColumnIndex("sensorType")));
}
c.close();
return values;
}
public long getSize() {
return dbPath.length();
}
......@@ -453,7 +525,7 @@ public class ReadingsDatabase extends SQLiteOpenHelper {
// Empty database
if (getSize() == 0){
return 0;
} else if (getSites().size() != 0) {
} else if (getSites(null).size() != 0) {
if (readings != 0) {
if (streaming == 0) {
// Just readings populated
......
......@@ -387,8 +387,8 @@ public class SensorSampleActivity extends Activity {
List<String> siteList = new ArrayList<String>();
List<String> sectorList = new ArrayList<String>();
if (remote_db){
siteList = db.getSites();
sectorList = db.getSectors();
siteList = db.getSites(null);
sectorList = db.getSectors(null);
} else {
siteList.clear();
sectorList.clear();
......@@ -396,7 +396,8 @@ public class SensorSampleActivity extends Activity {
ArrayAdapter<String> siteAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, siteList);
android.R.layout.simple_spinner_item, siteList);
siteAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
siteSpinner.setAdapter(siteAdapter);
siteSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
......@@ -414,7 +415,8 @@ public class SensorSampleActivity extends Activity {
});
ArrayAdapter<String> sectorAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, sectorList);
android.R.layout.simple_spinner_item, sectorList);
sectorAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
sectorSpinner.setAdapter(sectorAdapter);
sectorSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
......
......@@ -346,16 +346,28 @@ public class SensorSampleService extends Service implements SensorEventListener
builtinList = mSensorManager.getSensorList(Sensor.TYPE_ALL);
for (Sensor s : builtinList){
mSensorManager.registerListener(this, s, 100000000);
Log.d(TAG, "sensor in built in list: " + s.getName());
Log.d(TAG, "sensor in built in list type: " + s.getStringType());
if (s.getStringType().contains("android")){
if (!s.getName().contains("Secondary")){
mSensorManager.registerListener(this, s, 100000000);
}
}
}
for (int i=0; i<builtinList.size(); i++) {
aSensor sens = new aSensor(builtinList.get(i));
// This is to figure out which sensors are uncalibrated
String delims = "[ .]+";
String[] tokens = sens.getStringType().split(delims);
sens.setName(tokens[2]);
sensorList.add(sens);
if (builtinList.get(i).getStringType().startsWith("android")){
if (!builtinList.get(i).getName().contains("Secondary")) {
aSensor sens = new aSensor(builtinList.get(i));
String[] tokens = sens.getStringType().split(delims);
sens.setName(tokens[2]);
Log.d(TAG, "Setting aSensor name: " + tokens[2]);
Log.d(TAG, "aSensor type: " + sens.getStringType());
sensorList.add(sens);
}
}
}
}
}
......@@ -492,7 +504,6 @@ public class SensorSampleService extends Service implements SensorEventListener
break;
case Sensor.TYPE_GRAVITY:
sens.setLastValue(values, 3);
sens.setUnits("r");
sens.setID("and5");
break;
case Sensor.TYPE_GYROSCOPE:
......
......@@ -9,7 +9,7 @@ public class aSensor implements Parcelable {
private float[] lastValues;
private float quality;
private Integer numberValues;
private String type, platform, name, id, units;
private String type, platform, name, id;
private Sensor sensor;
// Using Built In sensors
......@@ -96,8 +96,6 @@ public class aSensor implements Parcelable {
public void setPlatform(String platformName){ platform = platformName; }
public void setUnits(String sensorUnits) { units = sensorUnits; }
public void setName(String sensorName){
name = sensorName;
}
......
......@@ -152,8 +152,8 @@
android:layout_height="wrap_content"
android:contentDescription="@string/export"
android:src="@drawable/export_button"
android:layout_below="@android:id/list"
android:layout_alignStart="@android:id/list" />
android:layout_alignParentBottom="true"
android:layout_toStartOf="@+id/streamButton" />
<ImageButton
android:layout_width="wrap_content"
......@@ -162,8 +162,8 @@
android:background="@null"
android:contentDescription="@string/stream"
android:src="@drawable/stream_button"
android:layout_alignParentBottom="true"
android:layout_alignStart="@+id/longandlat" />
android:layout_alignTop="@+id/sampleButton"
android:layout_centerHorizontal="true" />
<ImageButton
android:layout_width="wrap_content"
......@@ -172,7 +172,7 @@
android:background="@null"
android:contentDescription="@string/sample"
android:src="@drawable/sample_button"
android:layout_alignParentBottom="true"
android:layout_toEndOf="@+id/longandlat" />
android:layout_alignTop="@+id/exportDbButton"
android:layout_toEndOf="@+id/interval" />
</RelativeLayout>
\ No newline at end of file
......@@ -44,6 +44,14 @@
android:contentDescription="@string/databaseActions"
android:background="@null"
android:onClick="startSampleActivity" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="@string/benchSample"
android:contentDescription="@string/benchSample"
android:id="@+id/buttonBenchSample"
android:onClick="startSampleActivity" />
</LinearLayout>
</LinearLayout>
\ No newline at end of file
......@@ -62,6 +62,7 @@
<string name="bluetoothSensor">Take a sample with Bluetooth Sensors</string>
<string name="builtinSensors">Take a sample with built in sensors</string>
<string name="databaseActions">Work with database</string>
<string name="benchSample">Bench sample</string>
<!--Bluetooth Sensor String -->
<string name="reread">Re-read connected sensor</string>
......@@ -69,7 +70,10 @@
<!-- Sensor Strings -->
<string name="built_in_sensor">"%1$s: "</string>
<string name="sensorName">Sensor Name</string>
<string name="sensorValue">Sensor Value</string>
<string name="sensorValue">Sensor Value: </string>
<string name="readingNotes">Reading Notes </string>
<string name="sensorQuality">Quality: </string>
<string name="recordButton">Record</string>
<!-- Bluetooth related strings -->
<string name="ble_not_supported">Bluetooth Low Energy (LE) is not supported on this device.</string>
......
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MainTheme" parent="@android:style/Theme.Material.NoActionBar.Fullscreen">
<style name="MainTheme" parent="@android:style/Theme.Holo.Light.NoActionBar">
<item name="android:windowBackground">@drawable/background</item>
<item name="android:colorControlActivated">@color/dark_gray_blue</item>
</style>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment