List of usage examples for android.database MatrixCursor MatrixCursor
public MatrixCursor(String[] columnNames)
From source file:com.xbm.android.matisse.internal.loader.AlbumLoader.java
@Override public Cursor loadInBackground() { Cursor albums = super.loadInBackground(); MatrixCursor allAlbum = new MatrixCursor(COLUMNS); int totalCount = 0; String allAlbumCoverPath = ""; if (albums != null) { while (albums.moveToNext()) { totalCount += albums.getInt(albums.getColumnIndex(COLUMN_COUNT)); }/*from ww w .ja v a2 s. c o m*/ if (albums.moveToFirst()) { allAlbumCoverPath = albums.getString(albums.getColumnIndex(MediaStore.MediaColumns.DATA)); } } allAlbum.addRow(new String[] { Album.ALBUM_ID_ALL, Album.ALBUM_ID_ALL, Album.ALBUM_NAME_ALL, allAlbumCoverPath, String.valueOf(totalCount) }); return new MergeCursor(new Cursor[] { allAlbum, albums }); }
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);/* w w w. j a v a 2 s . com*/ Cursor[] toMerge = { headerCursor, cursor.getWrappedCursor() }; cursor = KeyListCursor.wrap(new MergeCursor(toMerge)); } } return super.swapCursor(cursor); }
From source file:fr.eoit.activity.fragment.blueprint.RequiredDecryptorFragment.java
@Override public void onLoadFinished(Cursor cursor) { if (DbUtil.hasAtLeastOneRow(cursor)) { String[] from = new String[] { Item.COLUMN_NAME_NAME, "decryptorDesc" }; int[] to = new int[] { android.R.id.text1, android.R.id.text2 }; MatrixCursor decryptorCursor = new MatrixCursor( new String[] { Item._ID, Item.COLUMN_NAME_NAME, "decryptorDesc" }); DbUtil.addRowToMatrixCursor(decryptorCursor, 0L, "None", ""); cursor.moveToFirst();//from w w w. j a v a 2 s . co m int selectedItem = 0; while (!cursor.isAfterLast()) { long itemId = cursor.getLong(cursor.getColumnIndexOrThrow(Item._ID)); DbUtil.addRowToMatrixCursor(decryptorCursor, itemId, cursor.getString(cursor.getColumnIndexOrThrow(Item.COLUMN_NAME_NAME)), getDecryptorDescription(DecryptorUtil.getDecryptorBonuses(itemId), getActivity().getResources())); if (itemId == decryptorId) { selectedItem = cursor.getPosition() + 1; } cursor.moveToNext(); } SimpleCursorAdapter adapter = new SimpleCursorAdapter(getActivity(), android.R.layout.simple_spinner_item, decryptorCursor, from, to, SimpleCursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER); Spinner spinner = (Spinner) getActivity().findViewById(R.id.DECRYPTOR_SPINNER); adapter.setDropDownViewResource(R.layout.decryptor_drop_down_item); spinner.setAdapter(adapter); spinner.setOnItemSelectedListener(new SpinnerDecryptorOnItemSelectedListener()); spinner.setSelection(selectedItem); } }
From source file:de.janrenz.app.mediathek.ArdMediathekProvider.java
@Override public Cursor query(Uri uri, String[] strings, String s, String[] strings1, String s1) { String url = ""; String queryparam = uri.getQueryParameter("timestamp"); ;// ww w .j ava 2 s . c o m Integer timestamp = null; if (queryparam == null) { Date dt = new Date(); timestamp = dt.getSeconds(); } else { timestamp = Integer.parseInt(queryparam); } String queryparammethod = uri.getQueryParameter("method"); if (queryparammethod == null) { queryparammethod = "list"; url = "http://m-service.daserste.de/appservice/1.4.2/video/list/" + timestamp + "?func=getVideoList&unixTimestamp=" + timestamp; } else if (queryparammethod.equalsIgnoreCase("search")) { // url = /appservice/1.4.1/search/heiter/0/25?func=getSearchResultList&searchPattern=heiter&searchOffset=0&searchLength=25 String searchQuery = uri.getQueryParameter("query"); //!TODO make this url safe url = "http://m-service.daserste.de/appservice/1.4.2/search/" + URLEncoder.encode(searchQuery) + "/0/50?func=getSearchResultList&searchPattern=" + URLEncoder.encode(searchQuery) + "&searchOffset=0&searchLength=50"; } else if (queryparammethod.equalsIgnoreCase("broadcast")) { url = "http://m-service.daserste.de/appservice/1.4.2/broadcast/current/" + timestamp + "?func=getCurrentBroadcast&unixTimestamp=" + timestamp; } else { // oh oh } String queryparamReload = uri.getQueryParameter("reload"); String queryExtReload = ""; if (queryparamReload != null) { queryExtReload = "&reload=" + Math.random(); } String result = ""; result = readJSONFeed(url); MatrixCursor cursor = new MatrixCursor(new String[] { "_id", "title", "subtitle", "image", "extId", "startTime", "startTimeAsTimestamp", "isLive" }); if (result == "") { return cursor; } if (queryparammethod.equalsIgnoreCase("broadcast")) { cursor = (MatrixCursor) processResultForBroadcast(result); } else if (queryparammethod.equalsIgnoreCase("search")) { cursor = (MatrixCursor) processResultForList(result, true); } else { Boolean orderParam = false; try { SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext()); Boolean reverse = sharedPref.getBoolean(SettingsActivity.REVERSE_LIST_ORDER, false); //reverse is menat by user perspective here, by default its false if (reverse == true) { orderParam = true; } } catch (Exception e) { // use the default if we cant fetch it } //Log.e("order Param", orderParam.toString()); cursor = (MatrixCursor) processResultForList(result, orderParam); } return (Cursor) cursor; }
From source file:ro.expectations.expenses.ui.overview.OverviewActivity.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { MatrixCursor matrixCursor = new MatrixCursor( new String[] { ExpensesContract.Accounts._ID, ExpensesContract.Accounts.TITLE }); matrixCursor.addRow(new Object[] { "0", getString(R.string.all_accounts) }); MergeCursor mergeCursor = new MergeCursor(new Cursor[] { matrixCursor, data }); mSectionsPagerAdapter.swapCursor(mergeCursor); mTabLayout.setupWithViewPager(mViewPager); }
From source file:org.deafsapps.sordomartinezpabloluismarspics.util.MarsPicsApiParser.java
@Nullable private static MatrixCursor parseJsonString(String jsonString) { final MatrixCursor matrixCursor = new MatrixCursor(new String[] { MarsPicsContract.PicItemEntry._ID, MarsPicsContract.PicItemEntry.COLUMN_ITEM_TAG, MarsPicsContract.PicItemEntry.COLUMN_ITEM_DATE, MarsPicsContract.PicItemEntry.COLUMN_ITEM_CAMERA_FULL_NAME, MarsPicsContract.PicItemEntry.COLUMN_ITEM_IMAGE_LINK }); try {// w w w . ja va 2 s . c om JSONObject nasaJson = new JSONObject(jsonString); JSONArray photosArray = nasaJson.getJSONArray(NASA_API_LIST); if (BuildConfig.DEBUG) { Log.d(TAG_MARS_PICS_API_PARSER, "JSON array size: " + String.valueOf(photosArray.length())); } // looping through all photos for (int idx = 0; idx < photosArray.length(); idx++) { int tag; String earthDate; String image; String cameraFullName; JSONObject photoObject = photosArray.getJSONObject(idx); tag = photoObject.getInt(NASA_API_TAG); earthDate = photoObject.getString(NASA_API_DATE); image = photoObject.getString(NASA_API_IMG); JSONObject cameraDetails = photoObject.getJSONObject(NASA_API_CAMERA); cameraFullName = cameraDetails.getString(NASA_API_FULL_NAME); matrixCursor.addRow(new Object[] { idx, tag, earthDate, cameraFullName, image }); } return matrixCursor; } catch (JSONException e) { e.printStackTrace(); } return null; }
From source file:fr.eoit.activity.fragment.blueprint.RequiredBlueprintCopyInventionFragment.java
@Override protected void onLoadFinishedAdapteur(Cursor cursor, SimpleCursorAdapter adapter) { cursor.moveToFirst();//from www .j av a 2 s . c om long id = cursor.getLong(cursor.getColumnIndexOrThrow(Blueprint._ID)); int maxProductionLimit = (this.maxProdLimit / 10) > 1 ? cursor.getInt(cursor.getColumnIndexOrThrow(Blueprint.COLUMN_NAME_MAX_PRODUCTION_LIMIT)) : 1; int baseCopyTime = cursor.getInt(cursor.getColumnIndexOrThrow(Blueprint.COLUMN_NAME_RESEARCH_COPY_TIME)); double price = FormulaCalculator.calculateMaxRunsCopyCost(baseCopyTime, 1000, 4343, 1.5F, 0.5F); MatrixCursor blueprintCopyCursor = new MatrixCursor(new String[] { Blueprint._ID, Blueprint.COLUMN_NAME_NAME, ItemMaterials.COLUMN_NAME_QUANTITY, Prices.COLUMN_NAME_PRODUCE_PRICE }); String name = String.valueOf(maxProductionLimit) + " " + getResources().getText(R.string.blueprint_copy_str1) + " " + cursor.getString(cursor.getColumnIndexOrThrow(Blueprint.COLUMN_NAME_NAME)); DbUtil.addRowToMatrixCursor(blueprintCopyCursor, id, name, numberOfChances, price); refreshAdapteur(new SimpleCursorAdapter(getActivity(), R.layout.item_row_small, blueprintCopyCursor, dataColumns, viewIDs, SimpleCursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER)); getAdapter().setViewBinder(new ItemListViewBinder(RedQuantityBehavior.PRICE)); if (fragmentReference.get() != null) { fragmentReference.get().setSingleBlueprintCopyPrice(price); } }
From source file:com.rightscale.provider.rest.ServerTemplateExecutablesResource.java
private Cursor buildCursor(String serverTemplateId, JSONArray array) throws JSONException, ProtocolError { int nServerTemplateId = Integer.parseInt(serverTemplateId); MatrixCursor result = new MatrixCursor(COLUMNS); for (int i = 0; i < array.length(); i++) { JSONObject object = array.getJSONObject(i); MatrixCursor.RowBuilder row = result.newRow(); buildRow(nServerTemplateId, row, object); }/* ww w .j a v a2 s . c om*/ return result; }
From source file:org.totschnig.myexpenses.dialog.SelectMainCategoryDialogFragment.java
@Override public void onLoadFinished(Loader<Cursor> arg0, Cursor data) { if (getArguments().getBoolean(KEY_WITH_ROOT)) { MatrixCursor extras = new MatrixCursor(projection); extras.addRow(new String[] { "0", getString(R.string.transform_subcategory_to_main), }); mCursor = new MergeCursor(new Cursor[] { extras, data }); } else {/*from w ww.java 2s .co m*/ mCursor = data; } mAdapter.swapCursor(mCursor); }
From source file:hashengineering.digitalcoin.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(); if (exchangeRates == null || now - lastUpdated > UPDATE_FREQ_MS) { Map<String, ExchangeRate> newExchangeRates = getBitcoinCharts(); if (exchangeRates == null && newExchangeRates == null) newExchangeRates = getBlockchainInfo(); if (newExchangeRates != null) { exchangeRates = newExchangeRates; lastUpdated = now;/*from w w w .j a va2 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(rate.currencyCode.hashCode()).add(rate.currencyCode).add(rate.rate.longValue()) .add(rate.source); } } else if (selection.equals(KEY_CURRENCY_CODE)) { final String selectedCode = selectionArgs[0]; ExchangeRate rate = selectedCode != null ? exchangeRates.get(selectedCode) : null; if (rate == null) { final String defaultCode = defaultCurrencyCode(); rate = defaultCode != null ? exchangeRates.get(defaultCode) : null; if (rate == null) { rate = exchangeRates.get(Constants.DEFAULT_EXCHANGE_CURRENCY); if (rate == null) return null; } } cursor.newRow().add(rate.currencyCode.hashCode()).add(rate.currencyCode).add(rate.rate.longValue()) .add(rate.source); } return cursor; }