Example usage for android.database MatrixCursor addRow

List of usage examples for android.database MatrixCursor addRow

Introduction

In this page you can find the example usage for android.database MatrixCursor addRow.

Prototype

public void addRow(Iterable<?> columnValues) 

Source Link

Document

Adds a new row to the end with the given column values.

Usage

From source file:de.vanita5.twittnuker.provider.TwidereDataProvider.java

private static Cursor getPreferencesCursor(final SharedPreferencesWrapper preferences, final String key) {
    final MatrixCursor c = new MatrixCursor(TwidereDataStore.Preferences.MATRIX_COLUMNS);
    final Map<String, Object> map = new HashMap<>();
    final Map<String, ?> all = preferences.getAll();
    if (key == null) {
        map.putAll(all);/*from w w  w  . j a v  a 2 s  .c om*/
    } else {
        map.put(key, all.get(key));
    }
    for (final Map.Entry<String, ?> item : map.entrySet()) {
        final Object value = item.getValue();
        final int type = getPreferenceType(value);
        c.addRow(new Object[] { item.getKey(), ParseUtils.parseString(value), type });
    }
    return c;
}

From source file:org.cdmckay.android.provider.MediaWikiProvider.java

private Cursor parseJsonSearch(String apiUrl, String search) {
    final MatrixCursor cursor = new MatrixCursor(SEARCH_COLUMN_NAMES);

    try {/*from   www . java 2s.c  o m*/
        final JSONArray titles = new JSONArray(search).getJSONArray(1);
        for (int i = 0; i < titles.length(); i++) {
            final String title = titles.getString(i);
            cursor.addRow(new Object[] { i, title, "", apiUrl + "/" + title });
        }
    } catch (JSONException e) {
        Log.e(TAG, e.toString());
        throw new RuntimeException(e);
    }

    return cursor;
}

From source file:com.teocci.utubinbg.MainActivity.java

/**
 * Options menu in action bar//from  w w  w  . ja v a  2s .  c  o m
 *
 * @param menu
 * @return
 */
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);

    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);

    final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    if (searchView != null) {
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    }

    //suggestions
    final CursorAdapter suggestionAdapter = new SimpleCursorAdapter(this, R.layout.dropdown_menu, null,
            new String[] { SearchManager.SUGGEST_COLUMN_TEXT_1 }, new int[] { android.R.id.text1 }, 0);
    final List<String> suggestions = new ArrayList<>();

    searchView.setSuggestionsAdapter(suggestionAdapter);

    searchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() {
        @Override
        public boolean onSuggestionSelect(int position) {
            return false;
        }

        @Override
        public boolean onSuggestionClick(int position) {
            searchView.setQuery(suggestions.get(position), false);
            searchView.clearFocus();

            Intent suggestionIntent = new Intent(Intent.ACTION_SEARCH);
            suggestionIntent.putExtra(SearchManager.QUERY, suggestions.get(position));
            handleIntent(suggestionIntent);

            return true;
        }
    });

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String s) {
            return false; //if true, no new intent is started
        }

        @Override
        public boolean onQueryTextChange(String suggestion) {
            // check network connection. If not available, do not query.
            // this also disables onSuggestionClick triggering
            if (suggestion.length() > 2) { //make suggestions after 3rd letter

                if (networkConf.isNetworkAvailable()) {

                    new JsonAsyncTask(new JsonAsyncTask.AsyncResponse() {
                        @Override
                        public void processFinish(ArrayList<String> result) {
                            suggestions.clear();
                            suggestions.addAll(result);
                            String[] columns = { BaseColumns._ID, SearchManager.SUGGEST_COLUMN_TEXT_1 };
                            MatrixCursor cursor = new MatrixCursor(columns);

                            for (int i = 0; i < result.size(); i++) {
                                String[] tmp = { Integer.toString(i), result.get(i) };
                                cursor.addRow(tmp);
                            }
                            suggestionAdapter.swapCursor(cursor);

                        }
                    }).execute(suggestion);
                    return true;
                }
            }
            return false;
        }
    });

    return true;
}

From source file:com.esri.arcgisruntime.sample.findaddress.MainActivity.java

/**
 * Sets up the address SearchView. Uses MatrixCursor to show suggestions to the user as the user inputs text.
 *//* w  w w.ja  v a 2  s  .c  om*/
private void setupAddressSearchView() {

    mAddressGeocodeParameters = new GeocodeParameters();
    // get place name and address attributes
    mAddressGeocodeParameters.getResultAttributeNames().add("PlaceName");
    mAddressGeocodeParameters.getResultAttributeNames().add("StAddr");
    // return only the closest result
    mAddressGeocodeParameters.setMaxResults(1);
    mAddressSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String address) {
            // geocode typed address
            geoCodeTypedAddress(address);
            // clear focus from search views
            mAddressSearchView.clearFocus();
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            // as long as newText isn't empty, get suggestions from the locatorTask
            if (!newText.equals("")) {
                final ListenableFuture<List<SuggestResult>> suggestionsFuture = mLocatorTask
                        .suggestAsync(newText);
                suggestionsFuture.addDoneListener(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            // get the results of the async operation
                            List<SuggestResult> suggestResults = suggestionsFuture.get();
                            MatrixCursor suggestionsCursor = new MatrixCursor(mColumnNames);
                            int key = 0;
                            // add each address suggestion to a new row
                            for (SuggestResult result : suggestResults) {
                                suggestionsCursor.addRow(new Object[] { key++, result.getLabel() });
                            }
                            // define SimpleCursorAdapter
                            String[] cols = new String[] { COLUMN_NAME_ADDRESS };
                            int[] to = new int[] { R.id.suggestion_address };
                            final SimpleCursorAdapter suggestionAdapter = new SimpleCursorAdapter(
                                    MainActivity.this, R.layout.suggestion, suggestionsCursor, cols, to, 0);
                            mAddressSearchView.setSuggestionsAdapter(suggestionAdapter);
                            // handle an address suggestion being chosen
                            mAddressSearchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() {
                                @Override
                                public boolean onSuggestionSelect(int position) {
                                    return false;
                                }

                                @Override
                                public boolean onSuggestionClick(int position) {
                                    // get the selected row
                                    MatrixCursor selectedRow = (MatrixCursor) suggestionAdapter
                                            .getItem(position);
                                    // get the row's index
                                    int selectedCursorIndex = selectedRow.getColumnIndex(COLUMN_NAME_ADDRESS);
                                    // get the string from the row at index
                                    String address = selectedRow.getString(selectedCursorIndex);
                                    // use clicked suggestion as query
                                    mAddressSearchView.setQuery(address, true);
                                    return true;
                                }
                            });
                        } catch (Exception e) {
                            Log.e(TAG, "Geocode suggestion error: " + e.getMessage());
                        }
                    }
                });
            }
            return true;
        }
    });
}

From source file:org.cdmckay.android.provider.MediaWikiProvider.java

private Cursor parseXmlPage(String apiUrl, String pageString) {
    final MatrixCursor cursor = new MatrixCursor(PAGE_COLUMN_NAMES);

    try {/*from   ww w . j av a  2 s.c om*/
        final PageHandler handler = new PageHandler();
        Xml.parse(pageString, handler);

        final List<PageHandler.Result> results = handler.getResults();
        for (PageHandler.Result result : results) {
            cursor.addRow(new Object[] { result.pageId, result.namespace, result.title, result.content });
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    return cursor;
}

From source file:org.cdmckay.android.provider.MediaWikiProvider.java

private Cursor parseXmlSearch(String apiUrl, String search) {
    final MatrixCursor cursor = new MatrixCursor(SEARCH_COLUMN_NAMES);

    try {/*from  w w w . j  a v a  2  s. c o  m*/
        final OpenSearchHandler handler = new OpenSearchHandler();
        Xml.parse(search, handler);

        final List<OpenSearchHandler.Result> results = handler.getResults();
        for (OpenSearchHandler.Result result : results) {
            cursor.addRow(new Object[] { result.id, result.title, result.description, result.url });
        }
    } catch (Exception e) {
        Log.e(TAG, e.toString());
        throw new RuntimeException(e);
    }

    return cursor;
}

From source file:com.csipsimple.ui.favorites.FavLoader.java

/**
 * Creates a cursor that contains a single row and maps the section to the
 * given value./*from   w w  w. j a v a  2s  .  c  om*/
 */
private Cursor createHeaderCursorFor(SipProfile account) {
    MatrixCursor matrixCursor = new MatrixCursor(
            new String[] { BaseColumns._ID, ContactsWrapper.FIELD_TYPE, SipProfile.FIELD_DISPLAY_NAME,
                    SipProfile.FIELD_WIZARD, SipProfile.FIELD_ANDROID_GROUP, SipProfile.FIELD_PUBLISH_ENABLED,
                    SipProfile.FIELD_REG_URI, SipProfile.FIELD_PROXY, SipProfile.FIELD_ACC_ID });
    String proxies = "";
    if (account.proxies != null) {
        proxies = TextUtils.join(SipProfile.PROXIES_SEPARATOR, account.proxies);
    }
    matrixCursor
            .addRow(new Object[] { account.id, ContactsWrapper.TYPE_GROUP, account.display_name, account.wizard,
                    account.android_group, account.publish_enabled, account.reg_uri, proxies, account.acc_id });
    return matrixCursor;
}

From source file:com.roamprocess1.roaming4world.ui.favorites.FavLoader.java

/**
 * Creates a cursor that contains a single row and maps the section to the
 * given value./*from  w  ww . j ava  2  s  .com*/
 */
private Cursor createHeaderCursorFor(SipProfile account) {
    MatrixCursor matrixCursor = new MatrixCursor(
            new String[] { BaseColumns._ID, ContactsWrapper.FIELD_TYPE, SipProfile.FIELD_DISPLAY_NAME,
                    SipProfile.FIELD_WIZARD, SipProfile.FIELD_ANDROID_GROUP, SipProfile.FIELD_PUBLISH_ENABLED,
                    SipProfile.FIELD_REG_URI, SipProfile.FIELD_PROXY, SipProfile.FIELD_ACC_ID });
    String proxies = "";
    if (account.proxies != null) {
        proxies = TextUtils.join(SipProfile.PROXIES_SEPARATOR, account.proxies);
    }
    matrixCursor
            .addRow(new Object[] { account.id, ContactsWrapper.TYPE_GROUP, account.display_name, account.wizard,
                    account.android_group, account.publish_enabled, account.reg_uri, proxies, account.acc_id });

    return matrixCursor;
}

From source file:com.smedic.tubtub.Pane.java

private Loader suggestionLoader(final List<String> suggestions, final CursorAdapter suggestionAdapter,
        final String query) {
    return getSupportLoaderManager().restartLoader(4, null, new LoaderManager.LoaderCallbacks<List<String>>() {
        @Override//w  w  w.ja  va  2  s .  c  o  m
        public Loader<List<String>> onCreateLoader(final int id, final Bundle args) {
            return new SuggestionsLoader(getApplicationContext(), query);
        }

        @Override
        public void onLoadFinished(Loader<List<String>> loader, List<String> data) {
            if (data == null)
                return;
            suggestions.clear();
            suggestions.addAll(data);
            String[] columns = { BaseColumns._ID, SearchManager.SUGGEST_COLUMN_TEXT_1 };
            MatrixCursor cursor = new MatrixCursor(columns);

            for (int i = 0; i < data.size(); i++) {
                String[] tmp = { Integer.toString(i), data.get(i) };
                cursor.addRow(tmp);
            }
            suggestionAdapter.swapCursor(cursor);
        }

        @Override
        public void onLoaderReset(Loader<List<String>> loader) {
            suggestions.clear();
            suggestions.addAll(Collections.<String>emptyList());
        }
    });
}

From source file:com.ibm.commerce.worklight.android.search.SearchSuggestionsProvider.java

/**
 * Performs the search by projections and selection arguments
 * @param uri The URI to be used//from   w w w .  j  av  a2s.co  m
 * @param projection The string array for the search
 * @param selection The selection string
 * @param selectionArgs The selection arguments
 * @param sortOrder The sort order
 * @return The cursor containing the suggestions
 */
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    final String METHOD_NAME = CLASS_NAME + ".query()";
    boolean loggingEnabled = Log.isLoggable(LOG_TAG, Log.DEBUG);
    if (loggingEnabled) {
        Log.d(METHOD_NAME, "ENTRY");
    }

    int id = 1;
    MatrixCursor suggestionCursor = new MatrixCursor(COLUMNS);
    Cursor recentSearchCursor = null;

    try {
        recentSearchCursor = super.query(uri, projection, selection, selectionArgs, sortOrder);
        // get search history
        if (recentSearchCursor != null) {
            int searchTermIndex = recentSearchCursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_1);
            while (recentSearchCursor.moveToNext() && id <= MAX_RECENT_TERM) {
                suggestionCursor.addRow(createRecentRow(id, recentSearchCursor.getString(searchTermIndex)));
                id++;
            }
        }
    } finally {
        if (recentSearchCursor != null) {
            recentSearchCursor.close();
            recentSearchCursor = null;
        }
    }

    // get search suggestion
    if (selectionArgs[0] != null && !selectionArgs[0].equals("")) {
        List<String> suggestionList = getSearchTermSuggestions(selectionArgs[0]);
        if (suggestionList != null) {
            for (String aSuggestion : suggestionList) {
                suggestionCursor.addRow(createSuggestionRow(id, aSuggestion));
                id++;
            }
        }
    }

    if (loggingEnabled) {
        Log.d(METHOD_NAME, "EXIT");
    }

    return suggestionCursor;
}