use of android.database.SQLException in project aware-client by denzilferreira.
the class Aware method setSetting.
/**
* Insert / Update settings of the framework
*
* @param key
* @param value
*/
public static void setSetting(Context context, String key, Object value) {
boolean is_global;
ArrayList<String> global_settings = new ArrayList<String>();
global_settings.add(Aware_Preferences.DEBUG_FLAG);
global_settings.add(Aware_Preferences.DEBUG_TAG);
global_settings.add(Aware_Preferences.DEVICE_ID);
global_settings.add(Aware_Preferences.DEVICE_LABEL);
global_settings.add(Aware_Preferences.STATUS_WEBSERVICE);
global_settings.add(Aware_Preferences.FREQUENCY_WEBSERVICE);
global_settings.add(Aware_Preferences.WEBSERVICE_WIFI_ONLY);
global_settings.add(Aware_Preferences.WEBSERVICE_SERVER);
global_settings.add(Aware_Preferences.WEBSERVICE_SIMPLE);
global_settings.add(Aware_Preferences.WEBSERVICE_REMOVE_DATA);
global_settings.add(Aware_Preferences.WEBSERVICE_SILENT);
global_settings.add(Aware_Preferences.STATUS_APPLICATIONS);
global_settings.add(Applications.STATUS_AWARE_ACCESSIBILITY);
// allow standalone apps to react to MQTT
if (context.getResources().getBoolean(R.bool.standalone)) {
global_settings.add(Aware_Preferences.STATUS_MQTT);
global_settings.add(Aware_Preferences.MQTT_USERNAME);
global_settings.add(Aware_Preferences.MQTT_PASSWORD);
global_settings.add(Aware_Preferences.MQTT_SERVER);
global_settings.add(Aware_Preferences.MQTT_PORT);
global_settings.add(Aware_Preferences.MQTT_KEEP_ALIVE);
global_settings.add(Aware_Preferences.MQTT_QOS);
}
is_global = global_settings.contains(key);
if (context.getResources().getBoolean(R.bool.standalone))
is_global = false;
// We already have a Device ID, do nothing!
if (key.equals(Aware_Preferences.DEVICE_ID) && Aware.getSetting(context, Aware_Preferences.DEVICE_ID).length() > 0) {
Log.d(Aware.TAG, "AWARE UUID: " + Aware.getSetting(context, Aware_Preferences.DEVICE_ID) + " in " + context.getPackageName());
return;
}
if (key.equals(Aware_Preferences.DEVICE_LABEL) && ((String) value).length() > 0) {
ContentValues newLabel = new ContentValues();
newLabel.put(Aware_Provider.Aware_Device.LABEL, (String) value);
context.getApplicationContext().getContentResolver().update(Aware_Provider.Aware_Device.CONTENT_URI, newLabel, Aware_Provider.Aware_Device.DEVICE_ID + " LIKE '" + Aware.getSetting(context, Aware_Preferences.DEVICE_ID) + "'", null);
}
ContentValues setting = new ContentValues();
setting.put(Aware_Settings.SETTING_KEY, key);
setting.put(Aware_Settings.SETTING_VALUE, value.toString());
if (is_global) {
setting.put(Aware_Settings.SETTING_PACKAGE_NAME, "com.aware.phone");
} else {
setting.put(Aware_Settings.SETTING_PACKAGE_NAME, context.getPackageName());
}
Cursor qry = context.getApplicationContext().getContentResolver().query(Aware_Settings.CONTENT_URI, null, Aware_Settings.SETTING_KEY + " LIKE '" + key + "' AND " + Aware_Settings.SETTING_PACKAGE_NAME + " LIKE " + ((is_global) ? "'com.aware.phone'" : "'" + context.getPackageName() + "'"), null, null);
// update
if (qry != null && qry.moveToFirst()) {
try {
if (!qry.getString(qry.getColumnIndex(Aware_Settings.SETTING_VALUE)).equals(value.toString())) {
context.getApplicationContext().getContentResolver().update(Aware_Settings.CONTENT_URI, setting, Aware_Settings.SETTING_ID + "=" + qry.getInt(qry.getColumnIndex(Aware_Settings.SETTING_ID)), null);
if (Aware.DEBUG)
Log.d(Aware.TAG, "Updated: " + key + "=" + value);
}
} catch (SQLiteException e) {
if (Aware.DEBUG)
Log.d(TAG, e.getMessage());
} catch (SQLException e) {
if (Aware.DEBUG)
Log.d(TAG, e.getMessage());
}
// insert
} else {
try {
context.getApplicationContext().getContentResolver().insert(Aware_Settings.CONTENT_URI, setting);
if (Aware.DEBUG)
Log.d(Aware.TAG, "Added: " + key + "=" + value);
} catch (SQLiteException e) {
if (Aware.DEBUG)
Log.d(TAG, e.getMessage());
} catch (SQLException e) {
if (Aware.DEBUG)
Log.d(TAG, e.getMessage());
}
}
if (qry != null && !qry.isClosed())
qry.close();
}
use of android.database.SQLException in project aware-client by denzilferreira.
the class Gyroscope 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(Gyroscope_Provider.Gyroscope_Data.CONTENT_URI, data_buffer);
Intent newData = new Intent(ACTION_AWARE_GYROSCOPE);
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] };
// Proceed with saving as usual.
ContentValues rowData = new ContentValues();
rowData.put(Gyroscope_Data.DEVICE_ID, Aware.getSetting(getApplicationContext(), Aware_Preferences.DEVICE_ID));
rowData.put(Gyroscope_Data.TIMESTAMP, TS);
rowData.put(Gyroscope_Data.VALUES_0, event.values[0]);
rowData.put(Gyroscope_Data.VALUES_1, event.values[1]);
rowData.put(Gyroscope_Data.VALUES_2, event.values[2]);
rowData.put(Gyroscope_Data.ACCURACY, event.accuracy);
rowData.put(Gyroscope_Data.LABEL, LABEL);
if (awareSensor != null)
awareSensor.onGyroscopeChanged(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(Gyroscope_Provider.Gyroscope_Data.CONTENT_URI, data_buffer);
Intent newData = new Intent(ACTION_AWARE_GYROSCOPE);
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.SQLException 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.SQLException 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.SQLException 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;
}
Aggregations