List of usage examples for android.database MatrixCursor addRow
public void addRow(Iterable<?> columnValues)
From source file:org.sufficientlysecure.keychain.ui.adapter.KeySectionedListAdapter.java
@Override public KeyListCursor swapCursor(KeyListCursor cursor) { if (cursor != null && (mQuery == null || TextUtils.isEmpty(mQuery))) { boolean isSecret = cursor.moveToFirst() && cursor.isSecret(); if (!isSecret) { MatrixCursor headerCursor = new MatrixCursor(KeyListCursor.PROJECTION); Long[] row = new Long[KeyListCursor.PROJECTION.length]; row[cursor.getColumnIndex(KeychainContract.KeyRings.HAS_ANY_SECRET)] = 1L; row[cursor.getColumnIndex(KeychainContract.KeyRings.MASTER_KEY_ID)] = 0L; headerCursor.addRow(row); Cursor[] toMerge = { headerCursor, cursor.getWrappedCursor() }; cursor = KeyListCursor.wrap(new MergeCursor(toMerge)); }/*from w w w . j a va 2 s. com*/ } return super.swapCursor(cursor); }
From source file:de.nware.app.hsDroid.provider.onlineService2Provider.java
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { Cursor cursor = null;//from w w w . ja v a 2 s. c om switch (mUriMatcher.match(uri)) { case EXAMS: SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); qb.setTables(mOpenHelper.getTableName()); qb.setProjectionMap(examsProjectionMap); SQLiteDatabase db = mOpenHelper.getReadableDatabase(); try { cursor = qb.query(db, projection, selection, selectionArgs, null, null, sortOrder); } catch (SQLException e) { e.printStackTrace(); Log.d(TAG, "SqlError: " + e.getMessage()); } cursor.setNotificationUri(getContext().getContentResolver(), uri); break; case EXAMS_UPDATE: MatrixCursor cur = new MatrixCursor(EXAMS_UPDATE_COLUMNS); Integer[] columnValues = updateGrades(); cur.addRow(new Object[] { 0, columnValues[0], columnValues[1] }); return cur; case EXAMINFOS: cursor = getExamInfos(selectionArgs[0], selectionArgs[1], false); break; case CERTIFICATIONS: cursor = getCertifications(); break; default: throw new IllegalArgumentException("Unbekannte URI " + uri); } return cursor; }
From source file:org.thoughtcrime.securesms.contacts.ContactAccessor.java
public Cursor getCursorForContactsWithPush(Context context) { final ContentResolver resolver = context.getContentResolver(); final String[] inProjection = new String[] { PhoneLookup._ID, PhoneLookup.DISPLAY_NAME }; final String[] outProjection = new String[] { PhoneLookup._ID, PhoneLookup.DISPLAY_NAME, PUSH_COLUMN }; MatrixCursor cursor = new MatrixCursor(outProjection); List<String> pushNumbers = Directory.getInstance(context).getActiveNumbers(); for (String pushNumber : pushNumbers) { Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(pushNumber)); Cursor lookupCursor = resolver.query(uri, inProjection, null, null, null); try {//from ww w . ja va 2 s. co m if (lookupCursor != null && lookupCursor.moveToFirst()) { cursor.addRow(new Object[] { lookupCursor.getLong(0), lookupCursor.getString(1), 1 }); } } finally { if (lookupCursor != null) lookupCursor.close(); } } return cursor; }
From source file:com.esri.arcgisruntime.sample.findplace.MainActivity.java
/** * Sets up the POI SearchView. Uses MatrixCursor to show suggestions to the user as the user inputs text. *//*from ww w . j a v a 2s .c o m*/ private void setupPoi() { mPoiSuggestParameters = new SuggestParameters(); // filter categories for POI mPoiSuggestParameters.getCategories().add("POI"); mPoiGeocodeParameters = new GeocodeParameters(); // get all attributes mPoiGeocodeParameters.getResultAttributeNames().add("*"); mPoiSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String address) { // if proximity SearchView text box is empty, use the device location if (mProximitySearchViewEmpty) { mPreferredSearchProximity = mLocationDisplay.getMapLocation(); mProximitySearchView.setQuery("Using current location...", false); } // keep track of typed address mPoiAddress = address; // geocode typed address geoCodeTypedAddress(address); // clear focus from search views mPoiSearchView.clearFocus(); mProximitySearchView.clearFocus(); return true; } @Override public boolean onQueryTextChange(final String newText) { // as long as newText isn't empty, get suggestions from the locatorTask if (!newText.equals("")) { mPoiSuggestParameters.setSearchArea(mCurrentExtentGeometry); final ListenableFuture<List<SuggestResult>> suggestionsFuture = mLocatorTask .suggestAsync(newText, mPoiSuggestParameters); suggestionsFuture.addDoneListener(new Runnable() { @Override public void run() { try { // get the results of the async operation List<SuggestResult> suggestResults = suggestionsFuture.get(); if (!suggestResults.isEmpty()) { MatrixCursor suggestionsCursor = new MatrixCursor(mColumnNames); int key = 0; // add each poi_suggestion result 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); mPoiSearchView.setSuggestionsAdapter(suggestionAdapter); // handle a poi_suggestion being chosen mPoiSearchView.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 mPoiAddress = selectedRow.getString(selectedCursorIndex); mPoiSearchView.setQuery(mPoiAddress, true); return true; } }); } else { mPoiAddress = newText; } } catch (Exception e) { Log.e(TAG, "Geocode suggestion error: " + e.getMessage()); } } }); } return true; } }); }
From source file:com.esri.arcgisruntime.sample.findplace.MainActivity.java
/** * Sets up the proximity SearchView. Uses MatrixCursor to show suggestions to the user as the user inputs text. *///from ww w. j a v a 2 s. co m private void setupProximity() { mProximitySuggestParameters = new SuggestParameters(); mProximitySuggestParameters.getCategories().add("Populated Place"); mProximityGeocodeParameters = new GeocodeParameters(); // get all attributes mProximityGeocodeParameters.getResultAttributeNames().add("*"); mProximitySearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String address) { geoCodeTypedAddress(address); // clear focus from search views mPoiSearchView.clearFocus(); mProximitySearchView.clearFocus(); return true; } @Override public boolean onQueryTextChange(String newText) { // as long as newText isn't empty, get suggestions from the locatorTask if (!newText.equals("")) { mProximitySearchViewEmpty = false; final ListenableFuture<List<SuggestResult>> suggestionsFuture = mLocatorTask .suggestAsync(newText, mProximitySuggestParameters); suggestionsFuture.addDoneListener(new Runnable() { @Override public void run() { try { // get the list of suggestions List<SuggestResult> suggestResults = suggestionsFuture.get(); MatrixCursor suggestionsCursor = new MatrixCursor(mColumnNames); int key = 0; // add each SuggestResult 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); mProximitySearchView.setSuggestionsAdapter(suggestionAdapter); mProximitySearchView.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 final String address = selectedRow.getString(selectedCursorIndex); mLocatorTask.addDoneLoadingListener(new Runnable() { @Override public void run() { if (mLocatorTask.getLoadStatus() == LoadStatus.LOADED) { // geocode the selected address to get location of address final ListenableFuture<List<GeocodeResult>> geocodeFuture = mLocatorTask .geocodeAsync(address, mProximityGeocodeParameters); geocodeFuture.addDoneListener(new Runnable() { @Override public void run() { try { // Get the results of the async operation List<GeocodeResult> geocodeResults = geocodeFuture .get(); if (geocodeResults.size() > 0) { // use geocodeResult to focus search area GeocodeResult geocodeResult = geocodeResults .get(0); // update preferred search area to the geocode result mPreferredSearchProximity = geocodeResult .getDisplayLocation(); mPoiGeocodeParameters.setSearchArea( mPreferredSearchProximity); // set the address string to the SearchView, but don't submit as a query mProximitySearchView.setQuery(address, false); // call POI search query mPoiSearchView.setQuery(mPoiAddress, true); // clear focus from search views mProximitySearchView.clearFocus(); mPoiSearchView.clearFocus(); } else { Toast.makeText(getApplicationContext(), getString(R.string.location_not_found) + address, Toast.LENGTH_LONG).show(); } } catch (InterruptedException | ExecutionException e) { Log.e(TAG, "Geocode error: " + e.getMessage()); Toast.makeText(getApplicationContext(), getString(R.string.geo_locate_error), Toast.LENGTH_LONG).show(); } } }); } } }); return true; } }); } catch (Exception e) { Log.e(TAG, "Geocode suggestion error: " + e.getMessage()); } } }); // if search view is empty, set flag } else { mProximitySearchViewEmpty = true; } return true; } }); }
From source file:monakhv.android.samlib.AuthorListFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { int sel = item.getItemId(); if (sel == android.R.id.home) { //mCallbacks.onOpenPanel(); if (getSelection() != null) { refresh(null, null);//from w w w . j a v a 2 s. com mCallbacks.onTitleChange(getString(R.string.app_name)); } } if (sel == R.id.menu_refresh) { startRefresh(); } if (sel == R.id.sort_option_item_books) { mCallbacks.selectBookSortOrder(); } if (sel == R.id.sort_option_item) { AdapterView.OnItemClickListener listener = new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { SortOrder so = SortOrder.values()[position]; mCallbacks.onAuthorSelected(0); setSortOrder(so); sortDialog.dismiss(); } }; sortDialog = SingleChoiceSelectDialog.getInstance(SortOrder.getTitles(getActivity()), listener, this.getString(R.string.dialog_title_sort_author), getSortOrder().ordinal()); sortDialog.show(getActivity().getSupportFragmentManager(), "DoSortDialog"); } if (sel == R.id.add_option_item) { View v = getActivity().findViewById(R.id.add_author_panel); v.setVisibility(View.VISIBLE); String txt = null; try { txt = getClipboardText(getActivity()); } catch (Exception ex) { Log.e(DEBUG_TAG, "Clipboard Error!", ex); } if (txt != null) { if (SamLibConfig.getParsedUrl(txt) != null) { EditText editText = (EditText) getActivity().findViewById(R.id.addUrlText); editText.setText(txt); } } } if (sel == R.id.settings_option_item) { Log.d(DEBUG_TAG, "go to Settings"); Intent prefsIntent = new Intent(getActivity().getApplicationContext(), SamlibPreferencesActivity.class); //prefsIntent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); getActivity().startActivityForResult(prefsIntent, MainActivity.PREFS_ACTIVITY); } if (sel == R.id.archive_option_item) { Log.d(DEBUG_TAG, "go to Archive"); Intent prefsIntent = new Intent(getActivity().getApplicationContext(), ArchiveActivity.class); //prefsIntent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); //startActivityForResult must be called via getActivity direct call produce wrong requestCode getActivity().startActivityForResult(prefsIntent, MainActivity.ARCHIVE_ACTIVITY); } if (sel == R.id.selected_option_item) { Log.d(DEBUG_TAG, "go to Selected"); cleanSelection(); mCallbacks.onAuthorSelected(SamLibConfig.SELECTED_BOOK_ID); } if (sel == R.id.menu_filter) { Log.d(DEBUG_TAG, "go to Filter"); Cursor tags = getActivity().getContentResolver().query(AuthorProvider.TAG_URI, null, null, null, SQLController.COL_TAG_NAME); MatrixCursor extras = new MatrixCursor( new String[] { SQLController.COL_ID, SQLController.COL_TAG_NAME }); extras.addRow(new String[] { Integer.toString(SamLibConfig.TAG_AUTHOR_ALL), getText(R.string.filter_all).toString() }); extras.addRow(new String[] { Integer.toString(SamLibConfig.TAG_AUTHOR_NEW), getText(R.string.filter_new).toString() }); Cursor[] cursors = { extras, tags }; final Cursor extendedCursor = new MergeCursor(cursors); AdapterView.OnItemClickListener listener = new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { extendedCursor.moveToPosition(position); int tag_id = extendedCursor.getInt(extendedCursor.getColumnIndex(SQLController.COL_ID)); String tg_name = extendedCursor .getString(extendedCursor.getColumnIndex(SQLController.COL_TAG_NAME)); filterDialog.dismiss(); selection = SQLController.TABLE_TAGS + "." + SQLController.COL_ID + "=" + tag_id; if (tag_id == SamLibConfig.TAG_AUTHOR_ALL) { selection = null; mCallbacks.onTitleChange(getActivity().getText(R.string.app_name).toString()); } else { mCallbacks.onTitleChange(tg_name); } if (tag_id == SamLibConfig.TAG_AUTHOR_NEW) { selection = SQLController.TABLE_AUTHOR + "." + SQLController.COL_isnew + "=1"; } Log.i(DEBUG_TAG, "WHERE " + selection); refresh(selection, null); mCallbacks.onAuthorSelected(0); } }; filterDialog = FilterSelectDialog.getInstance(extendedCursor, listener, getText(R.string.dialog_title_filtr).toString()); filterDialog.show(getActivity().getSupportFragmentManager(), "FilterDialogShow"); } return super.onOptionsItemSelected(item); }
From source file:de.nware.app.hsDroid.provider.onlineService2Provider.java
/** * Gibt certifications.// www . j av a2s.c o m * * @return Der/Die/das certifications */ private Cursor getCertifications() { final MatrixCursor cursor = new MatrixCursor(CERTIFICATIONS_COLUMNS); int count = 0; for (String certType : certificationType2) { String downloadUrl = String.format(certificationURLTmpl2, urlBase, certType, StaticSessionData.asiKey); cursor.addRow(new Object[] { count, certificationName[count], downloadUrl }); count++; } return cursor; }
From source file:de.janrenz.app.mediathek.ArdMediathekProvider.java
private Cursor processResultForBroadcast(String result) { MatrixCursor cursor = new MatrixCursor(new String[] { "_id", "title", "subtitle", "image", "extId", "startTime", "startTimeAsTimestamp", "isLive", "description", "timeinfo" }); try {/*w w w. j a va 2 s .c o m*/ // TODO Auto-generated catch block JSONArray jsonArray = new JSONArray(result); for (int i = 0; i < jsonArray.length(); i++) { JSONObject json_data = jsonArray.getJSONObject(i); // build the Headline String t1 = android.text.Html.fromHtml(json_data.getString("Title1")).toString(); String t2 = android.text.Html.fromHtml(json_data.getString("Title3")).toString(); String t3 = android.text.Html.fromHtml(json_data.getString("Title2")).toString(); cursor.addRow(new Object[] { i, t1, t3, json_data.getString("ImageUrl").toString(), json_data.getString("VId"), json_data.getString("BTimeF").toString(), json_data.getString("BTime").toString(), "true", android.text.Html.fromHtml(json_data.getString("Teasertext").toString()).toString(), android.text.Html.fromHtml(json_data.getString("Title5").toString()).toString() }); } } catch (JSONException e) { e.printStackTrace(); } return (Cursor) cursor; }
From source file:de.nware.app.hsDroid.provider.onlineService2Provider.java
/** * Parses the exam info./*w ww. jav a 2 s . c om*/ * * @param htmlContentString * der/die/das html content string * @return der/die/das cursor * @throws SAXException */ private Cursor parseExamInfo(String htmlContentString) throws SAXException { final MatrixCursor cursor = new MatrixCursor(EXAM_INFOS_COLUMNS); try { ExamInfoParser handler = new ExamInfoParser(); System.out.println("content exam info: " + htmlContentString); Xml.parse(htmlContentString, handler); ExamInfo exInfos = handler.getExamInfos(); cursor.addRow(new Object[] { 0, exInfos.getSehrGutAmount(), exInfos.getGutAmount(), exInfos.getBefriedigendAmount(), exInfos.getAusreichendAmount(), exInfos.getNichtAusreichendAmount(), exInfos.getAttendees(), exInfos.getAverage() }); } catch (SAXException e) { Log.e("read:SAXException:", e.getMessage()); e.printStackTrace(); throw new SAXException(e); } return cursor; }
From source file:org.cdmckay.android.provider.MediaWikiProvider.java
private Cursor parseJsonPage(String apiUrl, String pageString) { final MatrixCursor cursor = new MatrixCursor(PAGE_COLUMN_NAMES); try {// ww w . java2 s .c o m final JSONObject query = new JSONObject(pageString).getJSONObject("query"); final JSONObject pages = query.getJSONObject("pages"); @SuppressWarnings("unchecked") final Iterator<String> keys = (Iterator<String>) pages.keys(); while (keys.hasNext()) { final String key = (String) keys.next(); final JSONObject page = pages.getJSONObject(key); final String content = page.getJSONArray("revisions").getJSONObject(0) // TODO This should be "parsetree" later. .getString("*"); cursor.addRow(new Object[] { page.getLong("pageid"), page.getLong("ns"), page.getString("title"), content }); } } catch (JSONException e) { Log.e(TAG, e.toString()); throw new RuntimeException(e); } return cursor; }