Search in sources :

Example 41 with SQLiteException

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;
}
Also used : ContentValues(android.content.ContentValues) SQLException(android.database.SQLException) Intent(android.content.Intent) SQLiteException(android.database.sqlite.SQLiteException) HandlerThread(android.os.HandlerThread)

Example 42 with SQLiteException

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;
}
Also used : ContentValues(android.content.ContentValues) SQLException(android.database.SQLException) Intent(android.content.Intent) SQLiteException(android.database.sqlite.SQLiteException) HandlerThread(android.os.HandlerThread)

Example 43 with SQLiteException

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;
}
Also used : ContentValues(android.content.ContentValues) SQLException(android.database.SQLException) Intent(android.content.Intent) SQLiteException(android.database.sqlite.SQLiteException) HandlerThread(android.os.HandlerThread)

Example 44 with SQLiteException

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));
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLiteException(android.database.sqlite.SQLiteException)

Example 45 with SQLiteException

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);
    }
}
Also used : Cursor(android.database.Cursor) SQLiteException(android.database.sqlite.SQLiteException)

Aggregations

SQLiteException (android.database.sqlite.SQLiteException)122 Cursor (android.database.Cursor)72 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)36 ContentValues (android.content.ContentValues)28 SQLException (android.database.SQLException)17 Intent (android.content.Intent)14 HandlerThread (android.os.HandlerThread)10 File (java.io.File)10 HashMap (java.util.HashMap)8 Account (android.accounts.Account)7 SQLiteQueryBuilder (android.database.sqlite.SQLiteQueryBuilder)7 SyncStatusInfo (android.content.SyncStatusInfo)6 SQLiteDiskIOException (android.database.sqlite.SQLiteDiskIOException)6 BufferedWriter (java.io.BufferedWriter)6 FileWriter (java.io.FileWriter)6 Uri (android.net.Uri)5 ArrayList (java.util.ArrayList)5 SuppressLint (android.annotation.SuppressLint)4 SQLiteStatement (android.database.sqlite.SQLiteStatement)3 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)3