+ @SuppressWarnings("unused")
+ static public void setLongOption(String name, long value) {
+ setOption(name, String.valueOf(value));
+ }
+ @TargetApi(Build.VERSION_CODES.N)
+ public static void hookAutocompletionAdapter(final Context context,
+ final AutoCompleteTextView view,
+ final String table, final String field) {
+ hookAutocompletionAdapter(context, view, table, field, true, null, null);
+ }
+ @TargetApi(Build.VERSION_CODES.N)
+ public static void hookAutocompletionAdapter(final Context context,
+ final AutoCompleteTextView view,
+ final String table, final String field,
+ final boolean profileSpecific,
+ final DescriptionSelectedCallback callback,
+ final MobileLedgerProfile profile) {
+ 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 = constraint -> {
+ if (constraint == null)
+ return null;
+
+ String str = constraint.toString()
+ .toUpperCase();
+ debug("autocompletion", "Looking for " + str);
+
+ String sql;
+ String[] params;
+ if (profileSpecific) {
+ MobileLedgerProfile p = (profile == null) ? Data.profile.getValue() : profile;
+ if (p == null)
+ throw new AssertionError();
+ sql = String.format(
+ "SELECT rowid as _id, %s, CASE WHEN %s_upper LIKE ?||'%%' THEN 1 " +
+ "WHEN %s_upper LIKE '%%:'||?||'%%' then 2 " +
+ "WHEN %s_upper LIKE '%% '||?||'%%' THEN 3 " + "ELSE 9 END " + "FROM %s " +
+ "WHERE profile=? AND %s_upper LIKE '%%'||?||'%%' " +
+ "ORDER BY 3, %s_upper, 1;", field, field, field, field, table, field,
+ field);
+ params = new String[]{str, str, str, p.getUuid(), str};
+ }
+ else {
+ sql = String.format(
+ "SELECT rowid as _id, %s, CASE WHEN %s_upper LIKE ?||'%%' THEN 1 " +
+ "WHEN %s_upper LIKE '%%:'||?||'%%' THEN 2 " +
+ "WHEN %s_upper LIKE '%% '||?||'%%' THEN 3 " + "ELSE 9 END " + "FROM %s " +
+ "WHERE %s_upper LIKE '%%'||?||'%%' " + "ORDER BY 3, %s_upper, 1;", field,
+ field, field, field, table, field, field);
+ params = new String[]{str, str, str, str};
+ }
+ debug("autocompletion", sql);
+ SQLiteDatabase db = App.getDatabase();