-
- static public String get_option_value(Context context, String name, String default_value) {
- Log.d("db", "about to fetch option " + name);
- try (SQLiteDatabase db = getReadableDatabase(context)) {
- try (Cursor cursor = db
- .rawQuery("select value from options where name=?", new String[]{name}))
- {
- if (cursor.moveToFirst()) {
- String result = cursor.getString(0);
-
- if (result == null) result = default_value;
-
- Log.d("db", "option " + name + "=" + result);
- return result;
- }
- else return default_value;
- }
- catch (Exception e) {
- Log.d("db", "returning default value for " + name, e);
- return default_value;
- }
- }
- }
-
- static public void set_option_value(Context context, String name, String value) {
- Log.d("db", "setting option " + name + "=" + value);
- try (SQLiteDatabase db = getWritableDatabase(context)) {
- db.execSQL("insert or replace into options(name, value) values(?, ?);",
- new String[]{name, value});
- }
- }
-
- static public void set_option_value(Context context, String name, long value) {
- set_option_value(context, name, String.valueOf(value));
- }
- @TargetApi(Build.VERSION_CODES.N)
- public static void hook_autocompletion_adapter(final Context context,
- final AutoCompleteTextView view,
- final String table, final String field) {
- String[] from = {field};
- int[] to = {android.R.id.text1};
- SimpleCursorAdapter adapter =
- new SimpleCursorAdapter(context, android.R.layout.simple_dropdown_item_1line, null,
- from, to, 0);
- adapter.setStringConversionColumn(1);
-
- FilterQueryProvider provider = new FilterQueryProvider() {