+ private void hook_text_change_listener(final TextView view) {
+ view.addTextChangedListener(new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+
+ }
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
+
+ }
+
+ @Override
+ public void afterTextChanged(Editable s) {
+// Log.d("input", "text changed");
+ check_transaction_submittable();
+ }
+ });
+
+ }
+
+ @TargetApi(Build.VERSION_CODES.N)
+ private void hook_autocompletion_adapter(final TableRow row) {
+ String[] from = {"name"};
+ int[] to = {android.R.id.text1};
+ SQLiteDatabase db = MobileLedgerDB.db;
+
+ AutoCompleteTextView acc = (AutoCompleteTextView) row.getChildAt(0);
+ SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_dropdown_item_1line, null, from, to, 0);
+ adapter.setStringConversionColumn(1);
+
+ FilterQueryProvider provider = new FilterQueryProvider() {
+ @Override
+ public Cursor runQuery(CharSequence constraint) {
+ if (constraint == null) return null;
+
+ String str = constraint.toString().toUpperCase();
+ Log.d("autocompletion", "Looking for "+str);
+ String[] col_names = {FontsContract.Columns._ID, "name"};
+ MatrixCursor c = new MatrixCursor(col_names);
+
+ Cursor matches = db.rawQuery("SELECT name FROM accounts WHERE UPPER(name) LIKE '%'||?||'%' ORDER BY name;", new String[]{str});
+
+ try {
+ int i = 0;
+ while (matches.moveToNext()) {
+ String name = matches.getString(0);
+ Log.d("autocompletion-match", name);
+ c.newRow().add(i++).add(name);
+ }
+ }
+ finally {
+ matches.close();
+ }
+
+ return c;
+
+ }
+ };
+
+ adapter.setFilterQueryProvider(provider);
+
+ acc.setAdapter(adapter);
+ }
+