List of usage examples for android.database MatrixCursor MatrixCursor
public MatrixCursor(String[] columnNames)
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 v a2 s.c o 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:de.schildbach.wallet.goldcoin.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(); if (exchangeRates == null || now - lastUpdated > UPDATE_FREQ_MS) { Map<String, ExchangeRate> newExchangeRates = getBitcoinCharts();//getLitecoinCharts(); if (exchangeRates == null && newExchangeRates == null) newExchangeRates = getBlockchainInfo(); if (newExchangeRates == null) newExchangeRates = getLitecoinCharts(); if (newExchangeRates != null) { exchangeRates = newExchangeRates; lastUpdated = now;/*from w w w . j a v a2 s . co m*/ } } if (exchangeRates == null) return null; final MatrixCursor cursor = new MatrixCursor( new String[] { BaseColumns._ID, KEY_CURRENCY_CODE, KEY_RATE, KEY_SOURCE }); if (selection == null) { for (final Map.Entry<String, ExchangeRate> entry : exchangeRates.entrySet()) { final ExchangeRate rate = entry.getValue(); cursor.newRow().add(entry.getKey().hashCode()).add(rate.currencyCode).add(rate.rate.longValue()) .add(rate.source); } } else if (selection.equals(KEY_CURRENCY_CODE)) { final String code = selectionArgs[0]; final ExchangeRate rate = exchangeRates.get(code); try { cursor.newRow().add(code.hashCode()).add(rate.currencyCode).add(rate.rate.longValue()) .add(rate.source); } catch (NullPointerException e) { Log.e("GoldCoin", "Unable to add an exchange rate. NullPointerException."); } } return cursor; }
From source file:com.silentcircle.contacts.list.ProfileAndContactsLoader.java
/** * Loads the profile into a MatrixCursor. */// w ww.ja va2 s .c om private MatrixCursor loadProfile() { Cursor cursor = getContext().getContentResolver().query(RawContacts.CONTENT_URI, mProjection, RawContacts.CONTACT_TYPE + "=" + RawContacts.CONTACT_TYPE_OWN, null, null); if (cursor == null) { return null; } try { MatrixCursor matrix = new MatrixCursor(mProjection); Object[] row = new Object[mProjection.length]; while (cursor.moveToNext()) { for (int i = 0; i < row.length; i++) { row[i] = cursor.getString(i); } matrix.addRow(row); } return matrix; } finally { cursor.close(); } }
From source file:com.android.messaging.datamodel.MediaScratchFileProvider.java
@Override public Cursor query(final Uri uri, final String[] projection, final String selection, final String[] selectionArgs, final String sortOrder) { if (projection != null && projection.length > 0 && TextUtils.equals(projection[0], OpenableColumns.DISPLAY_NAME) && isMediaScratchSpaceUri(uri)) { // Retrieve the display name associated with a temp file. This is used by the Contacts // ImportVCardActivity to retrieve the name of the contact(s) being imported. String displayName;//from ww w . ja v a2s .c o m synchronized (sUriToDisplayNameMap) { displayName = sUriToDisplayNameMap.get(uri); } if (!TextUtils.isEmpty(displayName)) { MatrixCursor cursor = new MatrixCursor(new String[] { OpenableColumns.DISPLAY_NAME }); RowBuilder row = cursor.newRow(); row.add(displayName); return cursor; } } return null; }
From source file:com.raspi.chatapp.util.storage.file.LocalStorageProvider.java
@Override public Cursor queryRoots(final String[] projection) throws FileNotFoundException { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (getContext() == null || ContextCompat.checkSelfPermission(getContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { return null; }/*w w w. j a v a 2s . co 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_ROOT_PROJECTION); // Add Home directory File homeDir = Environment.getExternalStorageDirectory(); if (TextUtils.equals(Environment.getExternalStorageState(), Environment.MEDIA_MOUNTED)) { final MatrixCursor.RowBuilder row = result.newRow(); // These columns are required row.add(Root.COLUMN_ROOT_ID, homeDir.getAbsolutePath()); row.add(Root.COLUMN_DOCUMENT_ID, homeDir.getAbsolutePath()); row.add(Root.COLUMN_TITLE, getContext().getString(R.string.home)); row.add(Root.COLUMN_FLAGS, Root.FLAG_LOCAL_ONLY | Root.FLAG_SUPPORTS_CREATE | Root.FLAG_SUPPORTS_IS_CHILD); row.add(Root.COLUMN_ICON, R.mipmap.ic_launcher); // These columns are optional row.add(Root.COLUMN_SUMMARY, homeDir.getAbsolutePath()); row.add(Root.COLUMN_AVAILABLE_BYTES, new StatFs(homeDir.getAbsolutePath()).getAvailableBytes()); // Root.COLUMN_MIME_TYPE is another optional column and useful if you have multiple roots with different // types of mime types (roots that don't match the requested mime type are automatically hidden) } // Add SD card directory File sdCard = new File("/storage/extSdCard"); String storageState = EnvironmentCompat.getStorageState(sdCard); if (TextUtils.equals(storageState, Environment.MEDIA_MOUNTED) || TextUtils.equals(storageState, Environment.MEDIA_MOUNTED_READ_ONLY)) { final MatrixCursor.RowBuilder row = result.newRow(); // These columns are required row.add(Root.COLUMN_ROOT_ID, sdCard.getAbsolutePath()); row.add(Root.COLUMN_DOCUMENT_ID, sdCard.getAbsolutePath()); row.add(Root.COLUMN_TITLE, getContext().getString(R.string.sd_card)); // Always assume SD Card is read-only row.add(Root.COLUMN_FLAGS, Root.FLAG_LOCAL_ONLY); row.add(Root.COLUMN_ICON, R.drawable.ic_sd_card); row.add(Root.COLUMN_SUMMARY, sdCard.getAbsolutePath()); row.add(Root.COLUMN_AVAILABLE_BYTES, new StatFs(sdCard.getAbsolutePath()).getAvailableBytes()); } return result; } else return null; }
From source file:com.futureplatforms.kirin.test.DatabasesBackendTest_inactive.java
protected void setUp() throws Exception { mOpeningConfig = new JSONObject(); mOpeningConfig.put("filename", ":memory:"); mOpeningConfig.put("version", 1); txId = "tx." + mTxCounter; mTxCounter++;/*from ww w .j a va 2 s .c o m*/ mOpeningConfig.put("txId", txId); mOpeningConfig.put("onCreateToken", "onCreate"); mOpeningConfig.put("onUpdateToken", "onUpdate"); mOpeningConfig.put("onOpenedToken", "onOpened"); mOpeningConfig.put("onErrorToken", "onError"); /* * backend.beginTransaction_({ dbName: (string) databaseName, txId: * (string) transactionId, onSuccessToken: (string) * transaction_onSuccess_token, onErrorToken: (string) * transaction_onError_token, readOnly: (bool) readOnly }); */ mTransactionConfig = new JSONObject(); mTransactionConfig.put("dbName", "testDatabase"); mTransactionConfig.put("txId", txId); mResults = new Object[][] { new Object[] { 1, 2, 3 }, new Object[] { 4, 5, 6 } }; mKirinHelper = new DummyKirinHelper(); mPrefs = PreferenceManager.getDefaultSharedPreferences(getContext()); mExecutedSQL = new ArrayList<String>(); mOpenTransactions = 0; mBackend = new DatabasesBackend(getContext(), mPrefs, mKirinHelper, null, null) { @Override protected void beginNativeTransaction(SQLiteDatabase db) { mOpenTransactions++; } @Override protected void endNativeTransaction(SQLiteDatabase db) { mOpenTransactions--; } @Override protected void setNativeTransactionSuccessful(SQLiteDatabase db) { // NOP. } @Override protected Cursor rawQuery(SQLiteDatabase db, String sql, String[] params) { mExecutedSQL.add(sql); if (sql.contains("ERROR")) { throw new SQLException(); } mCursor = new MatrixCursor(new String[] { "foo", "bar", "baz" }); for (Object[] row : mResults) { mCursor.addRow(row); } return mCursor; } @Override protected void execSQL(SQLiteDatabase db, String sql, Object[] params) { mExecutedSQL.add(sql); if (sql.contains("ERROR")) { throw new SQLException(); } } }; }
From source file:com.gbozza.android.stockhawk.ui.StockFragment.java
@Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_stocks, container, false); ButterKnife.bind(this, rootView); mContext = getContext();/*from w w w . java 2 s. co m*/ mAdapter = new StockAdapter(mContext, new StockAdapter.StockAdapterOnClickHandler() { @Override public void onClick(String symbol, StockAdapter.StockViewHolder vh) { ((Callback) getActivity()).onItemSelected(symbol, vh); } }); mStockRecyclerView.setAdapter(mAdapter); mStockRecyclerView.setLayoutManager(new LinearLayoutManager(mContext)); if (null != savedInstanceState) { manageError(); if (savedInstanceState.containsKey(BUNDLE_STOCK_KEY)) { ArrayList<StockParcelable> stockList = savedInstanceState.getParcelableArrayList(BUNDLE_STOCK_KEY); MatrixCursor matrixCursor = new MatrixCursor(DetailFragment.DETAIL_COLUMNS); getActivity().startManagingCursor(matrixCursor); for (StockParcelable stock : stockList) { matrixCursor.addRow(new Object[] { stock.getId(), stock.getSymbol(), stock.getPrice(), stock.getAbsolute_change(), stock.getPercentage_change(), stock.getHistory() }); } mAdapter.setCursor(matrixCursor); } } else { mSwipeRefreshLayout.setOnRefreshListener(this); mSwipeRefreshLayout.setRefreshing(true); Intent inboundIntent = getActivity().getIntent(); if (null != inboundIntent && !inboundIntent.hasExtra(ListWidgetService.EXTRA_LIST_WIDGET_SYMBOL)) { QuoteSyncJob.initialize(mContext, QuoteSyncJob.PERIODIC_ID); onRefresh(); } getActivity().getSupportLoaderManager().initLoader(STOCK_LOADER, null, this); } FloatingActionButton addStockFab = (FloatingActionButton) rootView.findViewById(R.id.fab); addStockFab.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { new AddStockDialog().show(getActivity().getSupportFragmentManager(), "StockDialogFragment"); } }); new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.RIGHT) { @Override public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) { return false; } @Override public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) { String symbol = mAdapter.getSymbolAtPosition(viewHolder.getAdapterPosition()); PrefUtils.removeStock(mContext, symbol); mContext.getContentResolver().delete(Contract.Quote.makeUriForStock(symbol), null, null); } }).attachToRecyclerView(mStockRecyclerView); return rootView; }
From source file:com.rightscale.provider.rest.ServersResource.java
private Cursor buildCursor(JSONObject object) throws JSONException { MatrixCursor result = new MatrixCursor(COLUMNS); MatrixCursor.RowBuilder row = result.newRow(); buildRow(row, object);//from w ww.jav a 2 s. c om return result; }
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. java 2 s . 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; }
From source file:com.rightscale.provider.rest.ServersResource.java
private Cursor buildCursor(JSONArray array) throws JSONException { MatrixCursor result = new MatrixCursor(COLUMNS); for (Integer i : sortJsonArray(array, "nickname")) { JSONObject object = array.getJSONObject(i); /* /* www .j a va 2 s .c o m*/ * The API is glitchy for non-EC2 servers and returns an incomplete JSON object. * If the object lacks an href property, it is one of these and we skip it... */ if (object.has("href")) { MatrixCursor.RowBuilder row = result.newRow(); buildRow(row, object); } } return result; }