List of usage examples for android.database MatrixCursor MatrixCursor
public MatrixCursor(String[] columnNames)
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 {/* w w w . ja v a2s . c om*/ 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.mygeopay.wallet.ExchangeRatesProvider.java
@Override public Cursor query(final Uri uri, final String[] projection, final String selection, final String[] selectionArgs, final String sortOrder) { final long now = System.currentTimeMillis(); final List<String> pathSegments = uri.getPathSegments(); if (pathSegments.size() != 2) { throw new IllegalArgumentException("Unrecognized URI: " + uri); }/*from w w w . j ava2s .c o m*/ final boolean offline = uri.getQueryParameter(QUERY_PARAM_OFFLINE) != null; long lastUpdated; // TODO Add rate values for other Altcoins final String symbol; final boolean isLocalToCrypto; if (pathSegments.get(0).equals("to-crypto")) { isLocalToCrypto = true; symbol = pathSegments.get(1); lastUpdated = symbol.equals(lastLocalCurrency) ? localToCryptoLastUpdated : 0; } else if (pathSegments.get(0).equals("to-local")) { isLocalToCrypto = false; symbol = pathSegments.get(1); lastUpdated = symbol.equals(lastCryptoCurrency) ? cryptoToLocalLastUpdated : 0; } else { throw new IllegalArgumentException("Unrecognized URI path: " + uri); } // TODO Add rate values for other Altcoins if (!offline && (lastUpdated == 0 || now - lastUpdated > Constants.RATE_UPDATE_FREQ_MS)) { URL url; try { if (isLocalToCrypto) { url = new URL(String.format(TO_CRYPTO_URL, symbol)); } else { url = new URL(String.format(TO_LOCAL_URL, symbol)); } } catch (final MalformedURLException x) { throw new RuntimeException(x); // Should not happen } JSONObject newExchangeRatesJson = requestExchangeRatesJson(url); Map<String, ExchangeRate> newExchangeRates = parseExchangeRates(newExchangeRatesJson, symbol, isLocalToCrypto); if (newExchangeRates != null) { if (isLocalToCrypto) { localToCryptoRates = newExchangeRates; localToCryptoLastUpdated = now; lastLocalCurrency = symbol; config.setCachedExchangeRates(lastLocalCurrency, newExchangeRatesJson); } else { cryptoToLocalRates = newExchangeRates; cryptoToLocalLastUpdated = now; lastCryptoCurrency = symbol; } } } Map<String, ExchangeRate> exchangeRates = isLocalToCrypto ? localToCryptoRates : cryptoToLocalRates; if (exchangeRates == null) return null; final MatrixCursor cursor = new MatrixCursor(new String[] { BaseColumns._ID, KEY_CURRENCY_ID, KEY_RATE_COIN, KEY_RATE_COIN_CODE, KEY_RATE_FIAT, KEY_RATE_FIAT_CODE, KEY_SOURCE }); if (selection == null) { for (final Map.Entry<String, ExchangeRate> entry : exchangeRates.entrySet()) { final ExchangeRate exchangeRate = entry.getValue(); addRow(cursor, exchangeRate); } } else if (selection.equals(KEY_CURRENCY_ID)) { final ExchangeRate exchangeRate = exchangeRates.get(selectionArgs[0]); if (exchangeRate != null) { addRow(cursor, exchangeRate); } } return cursor; }
From source file:com.sage42.androidappaddicts.app.main.MainActivity.java
/** * Dummy code for searchview suggestion list. * /*from w ww .j a v a2 s . c o m*/ * @return */ @SuppressWarnings("resource") public SimpleCursorAdapter getData() { final String[] columnNames = { "_id", "suggestion_applist_title" }; //$NON-NLS-1$//$NON-NLS-2$ final MatrixCursor cursor = new MatrixCursor(columnNames); final String[] temp = new String[2]; int id = 0; for (final String item : this.mArray) { temp[0] = Integer.toString(id++); temp[1] = item; cursor.addRow(temp); } final String[] from = { "suggestion_applist_title" }; //$NON-NLS-1$ final int[] to = { R.id.suggestion_applist_title }; return new SimpleCursorAdapter(this, R.layout.suggestion_applist_item, cursor, from, to, 1); }
From source file:com.seafile.seadroid2.provider.SeafileProvider.java
@Override public Cursor queryDocument(String documentId, String[] projection) throws FileNotFoundException { Log.d(DEBUG_TAG, "queryDocument: " + documentId); String[] netProjection = netProjection(projection, SUPPORTED_DOCUMENT_PROJECTION); MatrixCursor result = new MatrixCursor(netProjection); DataManager dm = createDataManager(documentId); String repoId = DocumentIdParser.getRepoIdFromId(documentId); if (repoId.isEmpty()) { // the user has asked for the base document_id for a root includeDocIdRoot(result, dm.getAccount()); return result; }//from w ww .ja va 2 s .c o m // the android API asks us to be quick, so just use the cache. SeafRepo repo = dm.getCachedRepoByID(repoId); if (repo == null) throw new FileNotFoundException(); String path = DocumentIdParser.getPathFromId(documentId); if (docIdParser.isStarredFiles(documentId)) { includeStarredFilesRepo(result, dm.getAccount()); } else if (path.equals(Utils.PATH_SEPERATOR)) { // this is the base of the repository. this is special, as we give back the information // about the repository itself, not some directory in it. includeRepo(result, dm.getAccount(), repo); } else { // the general case. a query about a file/directory in a repository. // again we only use cached info in this function. that shouldn't be an issue, as // very likely there has been a SeafileProvider.queryChildDocuments() call just moments // earlier. String parentPath = Utils.getParentPath(path); List<SeafDirent> dirents = dm.getCachedDirents(repo.getID(), parentPath); List<SeafStarredFile> starredFiles = dm.getCachedStarredFiles(); if (dirents != null) { // the file is in the dirent of the parent directory // look for the requested file in the dirents of the parent dir for (SeafDirent entry : dirents) { if (entry.getTitle().equals(Utils.fileNameFromPath(path))) { includeDirent(result, dm, repo.getID(), parentPath, entry); } } } else if (starredFiles != null) { //maybe the requested file is a starred file? // look for the requested file in the list of starred files for (SeafStarredFile file : starredFiles) { if (file.getPath().equals(path)) { includeStarredFileDirent(result, dm, file); } } } } return result; }
From source file:com.raspi.chatapp.util.storage.file.LocalStorageProvider.java
@Override public Cursor queryChildDocuments(final String parentDocumentId, final String[] projection, final String sortOrder) throws FileNotFoundException { if (LocalStorageProvider.isMissingPermission(getContext())) { return null; }//from w w w . j av a 2 s. c o m // Create a cursor with either the requested fields, or the default projection if "projection" is null. final MatrixCursor result = new MatrixCursor(projection != null ? projection : DEFAULT_DOCUMENT_PROJECTION); final File parent = new File(parentDocumentId); for (File file : parent.listFiles()) { // Don't show hidden files/folders if (!file.getName().startsWith(".")) { // Adds the file's display name, MIME type, size, and so on. includeFile(result, file); } } return result; }
From source file:com.peaceworld.wikisms.view.newui.BaseActivity.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) private void loadData(String query) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // Load data from list to cursor String[] columns = new String[] { "_id", "text", "cid" }; Object[] temp = new Object[] { 0, "name", -1l }; MatrixCursor cursor = new MatrixCursor(columns); int index = 0; for (int i = 0; i < items.size(); i++) { if (query == null || items.get(i).getName().contains(query.trim())) { temp[0] = index;/* ww w . java 2 s .co m*/ temp[1] = items.get(i).getName(); temp[2] = items.get(i).getId(); cursor.addRow(temp); index++; } } temp[0] = index; temp[1] = " " + " \"" + query + "\" "; temp[2] = query.trim(); cursor.addRow(temp); SearchManager manager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); final SearchView search = (SearchView) menu.findItem(R.id.menu_search).getActionView(); search.setSearchableInfo(manager.getSearchableInfo(getComponentName())); ActionBarSearchAdapter adapter = new ActionBarSearchAdapter(this, cursor, this, search); search.setSuggestionsAdapter(adapter); } }
From source file:be.brunoparmentier.openbikesharing.app.activities.StationsListActivity.java
private void loadData(String query) { ArrayList<Station> queryStations = new ArrayList<>(); String[] columns = new String[] { "_id", "text" }; Object[] temp = new Object[] { 0, "default" }; MatrixCursor cursor = new MatrixCursor(columns); if (stations != null) { for (int i = 0; i < stations.size(); i++) { Station station = stations.get(i); if (station.getName().toLowerCase().contains(query.toLowerCase())) { temp[0] = i;//from w ww . j a v a2 s . c o m temp[1] = station.getName(); cursor.addRow(temp); queryStations.add(station); } } } searchView.setSuggestionsAdapter(new SearchStationAdapter(this, cursor, queryStations)); }
From source file:com.ffmpegtest.VideoActivity.java
@Override public void onFFDataSourceLoaded(FFmpegError err, FFmpegStreamInfo[] streams) { if (err != null) { String format = getResources().getString(R.string.main_could_not_open_stream); String message = String.format(format, err.getMessage()); Builder builder = new AlertDialog.Builder(VideoActivity.this); builder.setTitle(R.string.app_name).setMessage(message) .setOnCancelListener(new DialogInterface.OnCancelListener() { @Override/* w w w. ja v a 2 s .c o m*/ public void onCancel(DialogInterface dialog) { VideoActivity.this.finish(); } }).show(); return; } mPlayPauseButton.setBackgroundResource(android.R.drawable.ic_media_play); mPlayPauseButton.setEnabled(true); this.mControlsView.setVisibility(View.VISIBLE); this.mStreamsView.setVisibility(View.VISIBLE); this.mLoadingView.setVisibility(View.GONE); this.mVideoView.setVisibility(View.VISIBLE); MatrixCursor audio = new MatrixCursor(PROJECTION); MatrixCursor subtitles = new MatrixCursor(PROJECTION); subtitles.addRow(new Object[] { "None", FFmpegPlayer.NO_STREAM }); for (FFmpegStreamInfo streamInfo : streams) { CodecType mediaType = streamInfo.getMediaType(); Locale locale = streamInfo.getLanguage(); String languageName = locale == null ? getString(R.string.unknown) : locale.getDisplayLanguage(); if (FFmpegStreamInfo.CodecType.AUDIO.equals(mediaType)) { audio.addRow(new Object[] { languageName, streamInfo.getStreamNumber() }); } else if (FFmpegStreamInfo.CodecType.SUBTITLE.equals(mediaType)) { subtitles.addRow(new Object[] { languageName, streamInfo.getStreamNumber() }); } } mLanguageAdapter.swapCursor(audio); mSubtitleAdapter.swapCursor(subtitles); }
From source file:com.raspi.chatapp.util.storage.file.LocalStorageProvider.java
@Override public Cursor queryDocument(final String documentId, final String[] projection) throws FileNotFoundException { if (LocalStorageProvider.isMissingPermission(getContext())) { return null; }/*from w w w. j a v a 2 s. c o m*/ // Create a cursor with either the requested fields, or the default projection if "projection" is null. final MatrixCursor result = new MatrixCursor(projection != null ? projection : DEFAULT_DOCUMENT_PROJECTION); includeFile(result, new File(documentId)); return result; }
From source file:net.smart_json_database.JSONDatabase.java
public Cursor fetchCursorByType(String type, Order order) { if (Util.IsNullOrEmpty(type)) return new MatrixCursor(null); SQLiteDatabase db = dbHelper.getReadableDatabase(); return fetchCursorByRawSQL(db, "SELECT json_uid as _id, * FROM " + TABLE_JSON_DATA + " WHERE type = ?", new String[] { type }, order); }