Java Code Examples for android.content.ContentValues#valueSet()

The following examples show how to use android.content.ContentValues#valueSet() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestUtilities.java    From android-dev-challenge with Apache License 2.0 6 votes vote down vote up
/**
 * This method iterates through a set of expected values and makes various assertions that
 * will pass if our app is functioning properly.
 *
 * @param error          Message when an error occurs
 * @param valueCursor    The Cursor containing the actual values received from an arbitrary query
 * @param expectedValues The values we expect to receive in valueCursor
 */
static void validateCurrentRecord(String error, Cursor valueCursor, ContentValues expectedValues) {
    Set<Map.Entry<String, Object>> valueSet = expectedValues.valueSet();

    for (Map.Entry<String, Object> entry : valueSet) {
        String columnName = entry.getKey();
        int index = valueCursor.getColumnIndex(columnName);

        /* Test to see if the column is contained within the cursor */
        String columnNotFoundError = "Column '" + columnName + "' not found. " + error;
        assertFalse(columnNotFoundError, index == -1);

        /* Test to see if the expected value equals the actual value (from the Cursor) */
        String expectedValue = entry.getValue().toString();
        String actualValue = valueCursor.getString(index);

        String valuesDontMatchError = "Actual value '" + actualValue
                + "' did not match the expected value '" + expectedValue + "'. "
                + error;

        assertEquals(valuesDontMatchError,
                expectedValue,
                actualValue);
    }
}
 
Example 2
Source File: TestUtilities.java    From android-dev-challenge with Apache License 2.0 6 votes vote down vote up
/**
 * This method iterates through a set of expected values and makes various assertions that
 * will pass if our app is functioning properly.
 *
 * @param error          Message when an error occurs
 * @param valueCursor    The Cursor containing the actual values received from an arbitrary query
 * @param expectedValues The values we expect to receive in valueCursor
 */
static void validateCurrentRecord(String error, Cursor valueCursor, ContentValues expectedValues) {
    Set<Map.Entry<String, Object>> valueSet = expectedValues.valueSet();

    for (Map.Entry<String, Object> entry : valueSet) {
        String columnName = entry.getKey();
        int index = valueCursor.getColumnIndex(columnName);

        /* Test to see if the column is contained within the cursor */
        String columnNotFoundError = "Column '" + columnName + "' not found. " + error;
        assertFalse(columnNotFoundError, index == -1);

        /* Test to see if the expected value equals the actual value (from the Cursor) */
        String expectedValue = entry.getValue().toString();
        String actualValue = valueCursor.getString(index);

        String valuesDontMatchError = "Actual value '" + actualValue
                + "' did not match the expected value '" + expectedValue + "'. "
                + error;

        assertEquals(valuesDontMatchError,
                expectedValue,
                actualValue);
    }
}
 
Example 3
Source File: GPLog.java    From geopaparazzi with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Do an insert or throw with the proper error handling.
 *
 * @param table
 * @param values
 * @return
 * @throws IOException
 */
private static long insertOrThrow(SQLiteDatabase sqliteDatabase, String table, ContentValues values) throws Exception {
    if (sqliteDatabase == null || !sqliteDatabase.isOpen()) {
        throw new Exception("Database not ready!");
    }
    long id = sqliteDatabase.insertOrThrow(table, null, values);
    if (id == -1) {
        Set<Entry<String, Object>> valueSet = values.valueSet();
        StringBuilder sb = new StringBuilder();
        sb.append("Insert failed with: \n");
        for (Entry<String, Object> entry : valueSet) {
            sb.append("(").append(entry.getKey()).append(",");
            sb.append(entry.getValue()).append(")\n");
        }
        String message = sb.toString();
        throw new IOException(message);
    }
    return id;
}
 
Example 4
Source File: TestUtilities.java    From android-dev-challenge with Apache License 2.0 6 votes vote down vote up
/**
 * This method iterates through a set of expected values and makes various assertions that
 * will pass if our app is functioning properly.
 *
 * @param error          Message when an error occurs
 * @param valueCursor    The Cursor containing the actual values received from an arbitrary query
 * @param expectedValues The values we expect to receive in valueCursor
 */
static void validateCurrentRecord(String error, Cursor valueCursor, ContentValues expectedValues) {
    Set<Map.Entry<String, Object>> valueSet = expectedValues.valueSet();

    for (Map.Entry<String, Object> entry : valueSet) {
        String columnName = entry.getKey();
        int index = valueCursor.getColumnIndex(columnName);

        /* Test to see if the column is contained within the cursor */
        String columnNotFoundError = "Column '" + columnName + "' not found. " + error;
        assertFalse(columnNotFoundError, index == -1);

        /* Test to see if the expected value equals the actual value (from the Cursor) */
        String expectedValue = entry.getValue().toString();
        String actualValue = valueCursor.getString(index);

        String valuesDontMatchError = "Actual value '" + actualValue
                + "' did not match the expected value '" + expectedValue + "'. "
                + error;

        assertEquals(valuesDontMatchError,
                expectedValue,
                actualValue);
    }
}
 
Example 5
Source File: TestUtilities.java    From android-dev-challenge with Apache License 2.0 6 votes vote down vote up
/**
 * This method iterates through a set of expected values and makes various assertions that
 * will pass if our app is functioning properly.
 *
 * @param error          Message when an error occurs
 * @param valueCursor    The Cursor containing the actual values received from an arbitrary query
 * @param expectedValues The values we expect to receive in valueCursor
 */
static void validateCurrentRecord(String error, Cursor valueCursor, ContentValues expectedValues) {
    Set<Map.Entry<String, Object>> valueSet = expectedValues.valueSet();

    for (Map.Entry<String, Object> entry : valueSet) {
        String columnName = entry.getKey();
        int index = valueCursor.getColumnIndex(columnName);

        /* Test to see if the column is contained within the cursor */
        String columnNotFoundError = "Column '" + columnName + "' not found. " + error;
        assertFalse(columnNotFoundError, index == -1);

        /* Test to see if the expected value equals the actual value (from the Cursor) */
        String expectedValue = entry.getValue().toString();
        String actualValue = valueCursor.getString(index);

        String valuesDontMatchError = "Actual value '" + actualValue
                + "' did not match the expected value '" + expectedValue + "'. "
                + error;

        assertEquals(valuesDontMatchError,
                expectedValue,
                actualValue);
    }
}
 
Example 6
Source File: TestUtilities.java    From android-dev-challenge with Apache License 2.0 6 votes vote down vote up
/**
 * This method iterates through a set of expected values and makes various assertions that
 * will pass if our app is functioning properly.
 *
 * @param error          Message when an error occurs
 * @param valueCursor    The Cursor containing the actual values received from an arbitrary query
 * @param expectedValues The values we expect to receive in valueCursor
 */
static void validateCurrentRecord(String error, Cursor valueCursor, ContentValues expectedValues) {
    Set<Map.Entry<String, Object>> valueSet = expectedValues.valueSet();

    for (Map.Entry<String, Object> entry : valueSet) {
        String columnName = entry.getKey();
        int index = valueCursor.getColumnIndex(columnName);

        /* Test to see if the column is contained within the cursor */
        String columnNotFoundError = "Column '" + columnName + "' not found. " + error;
        assertFalse(columnNotFoundError, index == -1);

        /* Test to see if the expected value equals the actual value (from the Cursor) */
        String expectedValue = entry.getValue().toString();
        String actualValue = valueCursor.getString(index);

        String valuesDontMatchError = "Actual value '" + actualValue
                + "' did not match the expected value '" + expectedValue + "'. "
                + error;

        assertEquals(valuesDontMatchError,
                expectedValue,
                actualValue);
    }
}
 
Example 7
Source File: TestUtilities.java    From android-dev-challenge with Apache License 2.0 6 votes vote down vote up
/**
 * This method iterates through a set of expected values and makes various assertions that
 * will pass if our app is functioning properly.
 *
 * @param error          Message when an error occurs
 * @param valueCursor    The Cursor containing the actual values received from an arbitrary query
 * @param expectedValues The values we expect to receive in valueCursor
 */
static void validateCurrentRecord(String error, Cursor valueCursor, ContentValues expectedValues) {
    Set<Map.Entry<String, Object>> valueSet = expectedValues.valueSet();

    for (Map.Entry<String, Object> entry : valueSet) {
        String columnName = entry.getKey();
        int index = valueCursor.getColumnIndex(columnName);

        /* Test to see if the column is contained within the cursor */
        String columnNotFoundError = "Column '" + columnName + "' not found. " + error;
        assertFalse(columnNotFoundError, index == -1);

        /* Test to see if the expected value equals the actual value (from the Cursor) */
        String expectedValue = entry.getValue().toString();
        String actualValue = valueCursor.getString(index);

        String valuesDontMatchError = "Actual value '" + actualValue
                + "' did not match the expected value '" + expectedValue + "'. "
                + error;

        assertEquals(valuesDontMatchError,
                expectedValue,
                actualValue);
    }
}
 
Example 8
Source File: TestUtilities.java    From android-dev-challenge with Apache License 2.0 6 votes vote down vote up
/**
 * This method iterates through a set of expected values and makes various assertions that
 * will pass if our app is functioning properly.
 *
 * @param error          Message when an error occurs
 * @param valueCursor    The Cursor containing the actual values received from an arbitrary query
 * @param expectedValues The values we expect to receive in valueCursor
 */
static void validateCurrentRecord(String error, Cursor valueCursor, ContentValues expectedValues) {
    Set<Map.Entry<String, Object>> valueSet = expectedValues.valueSet();

    for (Map.Entry<String, Object> entry : valueSet) {
        String columnName = entry.getKey();
        int index = valueCursor.getColumnIndex(columnName);

        /* Test to see if the column is contained within the cursor */
        String columnNotFoundError = "Column '" + columnName + "' not found. " + error;
        assertFalse(columnNotFoundError, index == -1);

        /* Test to see if the expected value equals the actual value (from the Cursor) */
        String expectedValue = entry.getValue().toString();
        String actualValue = valueCursor.getString(index);

        String valuesDontMatchError = "Actual value '" + actualValue
                + "' did not match the expected value '" + expectedValue + "'. "
                + error;

        assertEquals(valuesDontMatchError,
                expectedValue,
                actualValue);
    }
}
 
Example 9
Source File: TestUtilities.java    From android-dev-challenge with Apache License 2.0 6 votes vote down vote up
/**
 * This method iterates through a set of expected values and makes various assertions that
 * will pass if our app is functioning properly.
 *
 * @param error          Message when an error occurs
 * @param valueCursor    The Cursor containing the actual values received from an arbitrary query
 * @param expectedValues The values we expect to receive in valueCursor
 */
static void validateCurrentRecord(String error, Cursor valueCursor, ContentValues expectedValues) {
    Set<Map.Entry<String, Object>> valueSet = expectedValues.valueSet();

    for (Map.Entry<String, Object> entry : valueSet) {
        String columnName = entry.getKey();
        int index = valueCursor.getColumnIndex(columnName);

        /* Test to see if the column is contained within the cursor */
        String columnNotFoundError = "Column '" + columnName + "' not found. " + error;
        assertFalse(columnNotFoundError, index == -1);

        /* Test to see if the expected value equals the actual value (from the Cursor) */
        String expectedValue = entry.getValue().toString();
        String actualValue = valueCursor.getString(index);

        String valuesDontMatchError = "Actual value '" + actualValue
                + "' did not match the expected value '" + expectedValue + "'. "
                + error;

        assertEquals(valuesDontMatchError,
                expectedValue,
                actualValue);
    }
}
 
Example 10
Source File: TestUtilities.java    From android-dev-challenge with Apache License 2.0 6 votes vote down vote up
/**
 * This method iterates through a set of expected values and makes various assertions that
 * will pass if our app is functioning properly.
 *
 * @param error          Message when an error occurs
 * @param valueCursor    The Cursor containing the actual values received from an arbitrary query
 * @param expectedValues The values we expect to receive in valueCursor
 */
static void validateCurrentRecord(String error, Cursor valueCursor, ContentValues expectedValues) {
    Set<Map.Entry<String, Object>> valueSet = expectedValues.valueSet();

    for (Map.Entry<String, Object> entry : valueSet) {
        String columnName = entry.getKey();
        int index = valueCursor.getColumnIndex(columnName);

        /* Test to see if the column is contained within the cursor */
        String columnNotFoundError = "Column '" + columnName + "' not found. " + error;
        assertFalse(columnNotFoundError, index == -1);

        /* Test to see if the expected value equals the actual value (from the Cursor) */
        String expectedValue = entry.getValue().toString();
        String actualValue = valueCursor.getString(index);

        String valuesDontMatchError = "Actual value '" + actualValue
                + "' did not match the expected value '" + expectedValue + "'. "
                + error;

        assertEquals(valuesDontMatchError,
                expectedValue,
                actualValue);
    }
}
 
Example 11
Source File: TestUtilities.java    From android-dev-challenge with Apache License 2.0 6 votes vote down vote up
/**
 * This method iterates through a set of expected values and makes various assertions that
 * will pass if our app is functioning properly.
 *
 * @param error          Message when an error occurs
 * @param valueCursor    The Cursor containing the actual values received from an arbitrary query
 * @param expectedValues The values we expect to receive in valueCursor
 */
static void validateCurrentRecord(String error, Cursor valueCursor, ContentValues expectedValues) {
    Set<Map.Entry<String, Object>> valueSet = expectedValues.valueSet();

    for (Map.Entry<String, Object> entry : valueSet) {
        String columnName = entry.getKey();
        int index = valueCursor.getColumnIndex(columnName);

        /* Test to see if the column is contained within the cursor */
        String columnNotFoundError = "Column '" + columnName + "' not found. " + error;
        assertFalse(columnNotFoundError, index == -1);

        /* Test to see if the expected value equals the actual value (from the Cursor) */
        String expectedValue = entry.getValue().toString();
        String actualValue = valueCursor.getString(index);

        String valuesDontMatchError = "Actual value '" + actualValue
                + "' did not match the expected value '" + expectedValue + "'. "
                + error;

        assertEquals(valuesDontMatchError,
                expectedValue,
                actualValue);
    }
}
 
Example 12
Source File: TestUtilities.java    From android-dev-challenge with Apache License 2.0 6 votes vote down vote up
/**
 * This method iterates through a set of expected values and makes various assertions that
 * will pass if our app is functioning properly.
 *
 * @param error          Message when an error occurs
 * @param valueCursor    The Cursor containing the actual values received from an arbitrary query
 * @param expectedValues The values we expect to receive in valueCursor
 */
static void validateCurrentRecord(String error, Cursor valueCursor, ContentValues expectedValues) {
    Set<Map.Entry<String, Object>> valueSet = expectedValues.valueSet();

    for (Map.Entry<String, Object> entry : valueSet) {
        String columnName = entry.getKey();
        int index = valueCursor.getColumnIndex(columnName);

        /* Test to see if the column is contained within the cursor */
        String columnNotFoundError = "Column '" + columnName + "' not found. " + error;
        assertFalse(columnNotFoundError, index == -1);

        /* Test to see if the expected value equals the actual value (from the Cursor) */
        String expectedValue = entry.getValue().toString();
        String actualValue = valueCursor.getString(index);

        String valuesDontMatchError = "Actual value '" + actualValue
                + "' did not match the expected value '" + expectedValue + "'. "
                + error;

        assertEquals(valuesDontMatchError,
                expectedValue,
                actualValue);
    }
}
 
Example 13
Source File: TestUtilities.java    From android-dev-challenge with Apache License 2.0 6 votes vote down vote up
/**
 * This method iterates through a set of expected values and makes various assertions that
 * will pass if our app is functioning properly.
 *
 * @param error          Message when an error occurs
 * @param valueCursor    The Cursor containing the actual values received from an arbitrary query
 * @param expectedValues The values we expect to receive in valueCursor
 */
static void validateCurrentRecord(String error, Cursor valueCursor, ContentValues expectedValues) {
    Set<Map.Entry<String, Object>> valueSet = expectedValues.valueSet();

    for (Map.Entry<String, Object> entry : valueSet) {
        String columnName = entry.getKey();
        int index = valueCursor.getColumnIndex(columnName);

        /* Test to see if the column is contained within the cursor */
        String columnNotFoundError = "Column '" + columnName + "' not found. " + error;
        assertFalse(columnNotFoundError, index == -1);

        /* Test to see if the expected value equals the actual value (from the Cursor) */
        String expectedValue = entry.getValue().toString();
        String actualValue = valueCursor.getString(index);

        String valuesDontMatchError = "Actual value '" + actualValue
                + "' did not match the expected value '" + expectedValue + "'. "
                + error;

        assertEquals(valuesDontMatchError,
                expectedValue,
                actualValue);
    }
}
 
Example 14
Source File: TestUtilities.java    From android-dev-challenge with Apache License 2.0 6 votes vote down vote up
/**
 * This method iterates through a set of expected values and makes various assertions that
 * will pass if our app is functioning properly.
 *
 * @param error          Message when an error occurs
 * @param valueCursor    The Cursor containing the actual values received from an arbitrary query
 * @param expectedValues The values we expect to receive in valueCursor
 */
static void validateCurrentRecord(String error, Cursor valueCursor, ContentValues expectedValues) {
    Set<Map.Entry<String, Object>> valueSet = expectedValues.valueSet();

    for (Map.Entry<String, Object> entry : valueSet) {
        String columnName = entry.getKey();
        int index = valueCursor.getColumnIndex(columnName);

        /* Test to see if the column is contained within the cursor */
        String columnNotFoundError = "Column '" + columnName + "' not found. " + error;
        assertFalse(columnNotFoundError, index == -1);

        /* Test to see if the expected value equals the actual value (from the Cursor) */
        String expectedValue = entry.getValue().toString();
        String actualValue = valueCursor.getString(index);

        String valuesDontMatchError = "Actual value '" + actualValue
                + "' did not match the expected value '" + expectedValue + "'. "
                + error;

        assertEquals(valuesDontMatchError,
                expectedValue,
                actualValue);
    }
}
 
Example 15
Source File: TestUtilities.java    From Popular-Movies-App with Apache License 2.0 5 votes vote down vote up
static void validateCurrentRecord(String error, Cursor valueCursor, ContentValues expectedValues) {
    Set<Map.Entry<String, Object>> valueSet = expectedValues.valueSet();
    for (Map.Entry<String, Object> entry : valueSet) {
        String columnName = entry.getKey();
        int idx = valueCursor.getColumnIndex(columnName);
        assertFalse("Column '" + columnName + "' not found. " + error, idx == -1);
        String expectedValue = entry.getValue().toString();
        assertEquals("Value '" + entry.getValue().toString() +
                "' did not match the expected value '" +
                expectedValue + "'. " + error, expectedValue, valueCursor.getString(idx));
    }
}
 
Example 16
Source File: TestUtilities.java    From Advanced_Android_Development with Apache License 2.0 5 votes vote down vote up
static void validateCurrentRecord(String error, Cursor valueCursor, ContentValues expectedValues) {
    Set<Map.Entry<String, Object>> valueSet = expectedValues.valueSet();
    for (Map.Entry<String, Object> entry : valueSet) {
        String columnName = entry.getKey();
        int idx = valueCursor.getColumnIndex(columnName);
        assertFalse("Column '" + columnName + "' not found. " + error, idx == -1);
        String expectedValue = entry.getValue().toString();
        assertEquals("Value '" + entry.getValue().toString() +
                "' did not match the expected value '" +
                expectedValue + "'. " + error, expectedValue, valueCursor.getString(idx));
    }
}
 
Example 17
Source File: TestUtilities.java    From android-weather with MIT License 5 votes vote down vote up
static void validateCurrentRecord(String error, Cursor valueCursor, ContentValues expectedValues) {
    Set<Map.Entry<String, Object>> valueSet = expectedValues.valueSet();
    for (Map.Entry<String, Object> entry : valueSet) {
        String columnName = entry.getKey();
        int idx = valueCursor.getColumnIndex(columnName);
        assertFalse("Column '" + columnName + "' not found. " + error, idx == -1);
        String expectedValue = entry.getValue().toString();
        assertEquals("Value '" + entry.getValue().toString() +
                "' did not match the expected value '" +
                expectedValue + "'. " + error, expectedValue, valueCursor.getString(idx));
    }
}
 
Example 18
Source File: SqlUtils.java    From Meteorite with Apache License 2.0 5 votes vote down vote up
/**
 * Adds {@link ContentValues} to the specified {@link OperatorGroup}.
 *
 * @param contentValues The content values to convert.
 * @param operatorGroup The group to put them into as {@link Operator}.
 */
public static void addContentValues(@NonNull ContentValues contentValues, @NonNull OperatorGroup operatorGroup) {
    java.util.Set<Map.Entry<String, Object>> entries = contentValues.valueSet();

    for (Map.Entry<String, Object> entry : entries) {
        String key = entry.getKey();
        operatorGroup.and(Operator.op(new NameAlias.Builder(key).build())
            .is(contentValues.get(key)));
    }
}
 
Example 19
Source File: Insert.java    From Meteorite with Apache License 2.0 5 votes vote down vote up
@NonNull
public Insert<TModel> columnValues(@NonNull ContentValues contentValues) {
    java.util.Set<Map.Entry<String, Object>> entries = contentValues.valueSet();
    int count = 0;
    String[] columns = new String[contentValues.size()];
    Object[] values = new Object[contentValues.size()];
    for (Map.Entry<String, Object> entry : entries) {
        String key = entry.getKey();
        columns[count] = key;
        values[count] = contentValues.get(key);
        count++;
    }

    return columns(columns).values(values);
}
 
Example 20
Source File: StubProvider.java    From aptoide-client with GNU General Public License v2.0 4 votes vote down vote up
@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {

    int uid = Binder.getCallingUid();

    PackageManager pm = getContext().getPackageManager();
    String callerPackage = pm.getPackagesForUid(uid)[0];

    Log.d("AptoideDebug", "Someone is trying to update preferences");

    int result = pm.checkSignatures(callerPackage, getContext().getPackageName());

    if(result == PackageManager.SIGNATURE_MATCH) {
        switch (uriMatcher.match(uri)) {
            case CHANGE_PREFERENCE:

                SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getContext());
                SharedPreferences.Editor edit = preferences.edit();
                int changed = 0;
                for (final Map.Entry<String, Object> entry : values.valueSet()) {
                    Object value = entry.getValue();
                    if (value instanceof String) {
                        edit.putString(entry.getKey(), (String) value);
                    } else if (value instanceof Integer) {
                        edit.putInt(entry.getKey(), (Integer) value);
                    } else if (value instanceof Long) {
                        edit.putLong(entry.getKey(), (Long) value);
                    } else if (value instanceof Boolean) {

                        if(entry.getKey().equals("debugmode")){
                            Aptoide.DEBUG_MODE = (Boolean) entry.getValue();
                        }

                        edit.putBoolean(entry.getKey(), (Boolean) value);
                    } else if (value instanceof Float) {
                        edit.putFloat(entry.getKey(), (Float) value);
                    }
                    changed++;
                    Handler handler = new Handler(Looper.getMainLooper());
                    handler.post(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(Aptoide.getContext(), "Preference set: " + entry.getKey() + "=" + entry.getValue(), Toast.LENGTH_LONG).show();
                        }
                    });
                }



                Log.d("AptoideDebug", "Commited");

                edit.commit();
                return changed;
            default:
                return 0;
        }

    }
    return 0;
}