use of android.database.sqlite.SQLiteException in project aware-client by denzilferreira.
the class Light method onSensorChanged.
@Override
public void onSensorChanged(SensorEvent event) {
long TS = System.currentTimeMillis();
if (ENFORCE_FREQUENCY && TS < LAST_TS + FREQUENCY / 1000)
return;
if (LAST_VALUE != null && THRESHOLD > 0 && Math.abs(event.values[0] - LAST_VALUE) < THRESHOLD) {
return;
}
LAST_TS = TS;
LAST_VALUE = event.values[0];
ContentValues rowData = new ContentValues();
rowData.put(Light_Data.DEVICE_ID, Aware.getSetting(getApplicationContext(), Aware_Preferences.DEVICE_ID));
rowData.put(Light_Data.TIMESTAMP, TS);
rowData.put(Light_Data.LIGHT_LUX, event.values[0]);
rowData.put(Light_Data.ACCURACY, event.accuracy);
rowData.put(Light_Data.LABEL, LABEL);
if (awareSensor != null)
awareSensor.onLightChanged(rowData);
data_values.add(rowData);
LAST_TS = TS;
if (data_values.size() < 250 && TS < LAST_SAVE + 300000) {
return;
}
final ContentValues[] data_buffer = new ContentValues[data_values.size()];
data_values.toArray(data_buffer);
try {
if (!Aware.getSetting(getApplicationContext(), Aware_Preferences.DEBUG_DB_SLOW).equals("true")) {
new Thread(new Runnable() {
@Override
public void run() {
getContentResolver().bulkInsert(Light_Provider.Light_Data.CONTENT_URI, data_buffer);
Intent newData = new Intent(ACTION_AWARE_LIGHT);
sendBroadcast(newData);
}
}).run();
}
} catch (SQLiteException e) {
if (Aware.DEBUG)
Log.d(TAG, e.getMessage());
} catch (SQLException e) {
if (Aware.DEBUG)
Log.d(TAG, e.getMessage());
}
data_values.clear();
LAST_SAVE = TS;
}
use of android.database.sqlite.SQLiteException in project aware-client by denzilferreira.
the class LinearAccelerometer method onSensorChanged.
@Override
public void onSensorChanged(SensorEvent event) {
if (SignificantMotion.isSignificantMotionActive && !SignificantMotion.CURRENT_SIGMOTION_STATE) {
if (data_values.size() > 0) {
final ContentValues[] data_buffer = new ContentValues[data_values.size()];
data_values.toArray(data_buffer);
try {
if (!Aware.getSetting(getApplicationContext(), Aware_Preferences.DEBUG_DB_SLOW).equals("true")) {
new Thread(new Runnable() {
@Override
public void run() {
getContentResolver().bulkInsert(Linear_Accelerometer_Provider.Linear_Accelerometer_Data.CONTENT_URI, data_buffer);
Intent newData = new Intent(ACTION_AWARE_LINEAR_ACCELEROMETER);
sendBroadcast(newData);
}
}).run();
}
} catch (SQLiteException e) {
if (Aware.DEBUG)
Log.d(TAG, e.getMessage());
} catch (SQLException e) {
if (Aware.DEBUG)
Log.d(TAG, e.getMessage());
}
data_values.clear();
}
return;
}
long TS = System.currentTimeMillis();
if (ENFORCE_FREQUENCY && TS < LAST_TS + FREQUENCY / 1000)
return;
if (LAST_VALUES != null && THRESHOLD > 0 && Math.abs(event.values[0] - LAST_VALUES[0]) < THRESHOLD && Math.abs(event.values[1] - LAST_VALUES[1]) < THRESHOLD && Math.abs(event.values[2] - LAST_VALUES[2]) < THRESHOLD) {
return;
}
LAST_VALUES = new Float[] { event.values[0], event.values[1], event.values[2] };
ContentValues rowData = new ContentValues();
rowData.put(Linear_Accelerometer_Data.DEVICE_ID, Aware.getSetting(getApplicationContext(), Aware_Preferences.DEVICE_ID));
rowData.put(Linear_Accelerometer_Data.TIMESTAMP, TS);
rowData.put(Linear_Accelerometer_Data.VALUES_0, event.values[0]);
rowData.put(Linear_Accelerometer_Data.VALUES_1, event.values[1]);
rowData.put(Linear_Accelerometer_Data.VALUES_2, event.values[2]);
rowData.put(Linear_Accelerometer_Data.ACCURACY, event.accuracy);
rowData.put(Linear_Accelerometer_Data.LABEL, LABEL);
data_values.add(rowData);
LAST_TS = TS;
if (awareSensor != null)
awareSensor.onLinearAccelChanged(rowData);
if (data_values.size() < 250 && TS < LAST_SAVE + 300000) {
return;
}
final ContentValues[] data_buffer = new ContentValues[data_values.size()];
data_values.toArray(data_buffer);
try {
if (!Aware.getSetting(getApplicationContext(), Aware_Preferences.DEBUG_DB_SLOW).equals("true")) {
new Thread(new Runnable() {
@Override
public void run() {
getContentResolver().bulkInsert(Linear_Accelerometer_Provider.Linear_Accelerometer_Data.CONTENT_URI, data_buffer);
Intent newData = new Intent(ACTION_AWARE_LINEAR_ACCELEROMETER);
sendBroadcast(newData);
}
}).run();
}
} catch (SQLiteException e) {
if (Aware.DEBUG)
Log.d(TAG, e.getMessage());
} catch (SQLException e) {
if (Aware.DEBUG)
Log.d(TAG, e.getMessage());
}
data_values.clear();
LAST_SAVE = TS;
}
use of android.database.sqlite.SQLiteException in project aware-client by denzilferreira.
the class Accelerometer method onSensorChanged.
@Override
public void onSensorChanged(SensorEvent event) {
if (SignificantMotion.isSignificantMotionActive && !SignificantMotion.CURRENT_SIGMOTION_STATE) {
if (data_values.size() > 0) {
final ContentValues[] data_buffer = new ContentValues[data_values.size()];
data_values.toArray(data_buffer);
try {
if (!Aware.getSetting(getApplicationContext(), Aware_Preferences.DEBUG_DB_SLOW).equals("true")) {
new Thread(new Runnable() {
@Override
public void run() {
getContentResolver().bulkInsert(Accelerometer_Data.CONTENT_URI, data_buffer);
Intent accelData = new Intent(ACTION_AWARE_ACCELEROMETER);
sendBroadcast(accelData);
}
}).run();
}
} catch (SQLiteException e) {
if (Aware.DEBUG)
Log.d(TAG, e.getMessage());
} catch (SQLException e) {
if (Aware.DEBUG)
Log.d(TAG, e.getMessage());
}
data_values.clear();
}
return;
}
long TS = System.currentTimeMillis();
if (ENFORCE_FREQUENCY && TS < LAST_TS + FREQUENCY / 1000)
return;
if (LAST_VALUES != null && THRESHOLD > 0 && Math.abs(event.values[0] - LAST_VALUES[0]) < THRESHOLD && Math.abs(event.values[1] - LAST_VALUES[1]) < THRESHOLD && Math.abs(event.values[2] - LAST_VALUES[2]) < THRESHOLD) {
return;
}
LAST_VALUES = new Float[] { event.values[0], event.values[1], event.values[2] };
ContentValues rowData = new ContentValues();
rowData.put(Accelerometer_Data.DEVICE_ID, Aware.getSetting(getApplicationContext(), Aware_Preferences.DEVICE_ID));
rowData.put(Accelerometer_Data.TIMESTAMP, TS);
rowData.put(Accelerometer_Data.VALUES_0, event.values[0]);
rowData.put(Accelerometer_Data.VALUES_1, event.values[1]);
rowData.put(Accelerometer_Data.VALUES_2, event.values[2]);
rowData.put(Accelerometer_Data.ACCURACY, event.accuracy);
rowData.put(Accelerometer_Data.LABEL, LABEL);
if (awareSensor != null)
awareSensor.onAccelerometerChanged(rowData);
data_values.add(rowData);
LAST_TS = TS;
if (data_values.size() < 250 && TS < LAST_SAVE + 300000) {
return;
}
final ContentValues[] data_buffer = new ContentValues[data_values.size()];
data_values.toArray(data_buffer);
try {
if (!Aware.getSetting(getApplicationContext(), Aware_Preferences.DEBUG_DB_SLOW).equals("true")) {
new Thread(new Runnable() {
@Override
public void run() {
getContentResolver().bulkInsert(Accelerometer_Data.CONTENT_URI, data_buffer);
Intent accelData = new Intent(ACTION_AWARE_ACCELEROMETER);
sendBroadcast(accelData);
}
}).run();
}
} catch (SQLiteException e) {
if (Aware.DEBUG)
Log.d(TAG, e.getMessage());
} catch (SQLException e) {
if (Aware.DEBUG)
Log.d(TAG, e.getMessage());
}
data_values.clear();
LAST_SAVE = TS;
}
use of android.database.sqlite.SQLiteException in project 360-Engine-for-Android by 360.
the class NowPlusStateTableTest method testLastTimelineUpdate.
/*
* Test fetch and modify LastTimelineUpdate.
*/
public void testLastTimelineUpdate() {
mTestStep = 1;
SQLiteDatabase writableDb = mTestDatabase.getWritableDatabase();
SQLiteDatabase readableDb = mTestDatabase.getReadableDatabase();
long myLastTimelineUpdate = TestModule.generateRandomLong();
try {
StateTable.modifyLatestPhoneCallTime(myLastTimelineUpdate, writableDb);
fail("Expecting a SQLiteException, because the table has not yet been created");
} catch (SQLiteException e) {
assertTrue(true);
}
try {
StateTable.fetchLatestPhoneCallTime(readableDb);
fail("Expecting a SQLiteException, because the table has not yet been created");
} catch (SQLiteException e) {
assertTrue(true);
}
createTable();
assertEquals(0, StateTable.fetchLatestPhoneCallTime(readableDb));
assertEquals(ServiceStatus.SUCCESS, StateTable.modifyLatestPhoneCallTime(myLastTimelineUpdate, writableDb));
assertEquals(myLastTimelineUpdate, StateTable.fetchLatestPhoneCallTime(readableDb));
}
use of android.database.sqlite.SQLiteException in project 360-Engine-for-Android by 360.
the class DatabaseHelper method fetchContactDetail.
/**
* Fetches a contact detail from the database.
*
* @param localDetailId The local ID of the detail to fetch
* @param detail A empty {@link ContactDetail} object which will be filled
* with the data
* @return SUCCESS or a suitable error code
*/
public synchronized ServiceStatus fetchContactDetail(long localDetailId, ContactDetail detail) {
if (Settings.ENABLED_DATABASE_TRACE) {
trace(false, "DatabaseHelper.fetchContactDetail() localDetailId[" + localDetailId + "]");
}
Cursor cursor = null;
try {
try {
String[] args = { String.format("%d", localDetailId) };
cursor = getReadableDatabase().rawQuery(ContactDetailsTable.getQueryStringSql(ContactDetailsTable.Field.DETAILLOCALID + " = ?"), args);
} catch (SQLiteException e) {
LogUtils.logE("DatabaseHelper.fetchContactDetail() Unable to fetch contact detail", e);
return ServiceStatus.ERROR_DATABASE_CORRUPT;
}
if (!cursor.moveToFirst()) {
return ServiceStatus.ERROR_NOT_FOUND;
}
detail.copy(ContactDetailsTable.getQueryData(cursor));
return ServiceStatus.SUCCESS;
} finally {
CloseUtils.close(cursor);
}
}
Aggregations