List of usage examples for android.database MatrixCursor addRow
public void addRow(Iterable<?> columnValues)
From source file:com.futureplatforms.kirin.test.DatabasesBackendTest_inactive.java
public void testCoerceToJSONObject() throws JSONException { String[] columnNames = new String[] { "foo", "bar", "baz" }; MatrixCursor cursor = new MatrixCursor(columnNames); cursor.addRow(new Object[] { 1, 2, 3 }); cursor.moveToFirst();/*from ww w. ja va2 s . co m*/ JSONObject obj = mBackend.coerceToJSONObject(columnNames, cursor); assertEquals(1, obj.getInt("foo")); assertEquals(2, obj.getInt("bar")); assertEquals(3, obj.getInt("baz")); }
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 {/*from ww w . ja v a 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:com.futureplatforms.kirin.test.DatabasesBackendTest_inactive.java
public void testCoerceToJSONArray() throws JSONException { String[] columnNames = new String[] { "foo", "bar", "baz" }; MatrixCursor cursor = new MatrixCursor(columnNames); cursor.addRow(new Object[] { 1, 2, 3 }); cursor.addRow(new Object[] { 4, 5, 6 }); cursor.addRow(new Object[] { 7, 8, 9 }); cursor.moveToFirst();// w ww . j a va 2 s. c o m JSONArray array = mBackend.coerceToJSONArray(columnNames, cursor); assertEquals(3, array.length()); JSONObject obj = array.getJSONObject(0); assertEquals(1, obj.getInt("foo")); assertEquals(2, obj.getInt("bar")); assertEquals(3, obj.getInt("baz")); obj = array.getJSONObject(1); assertEquals(4, obj.getInt("foo")); assertEquals(5, obj.getInt("bar")); assertEquals(6, obj.getInt("baz")); obj = array.getJSONObject(2); assertEquals(7, obj.getInt("foo")); assertEquals(8, obj.getInt("bar")); assertEquals(9, obj.getInt("baz")); }
From source file:com.bamalearn.bamalearnburmese.DrawerMainActivity.java
private void populateAdapter(String query) { final MatrixCursor c = new MatrixCursor(new String[] { BaseColumns._ID, "cityName" }); for (int i = 0; i < SUGGESTIONS.length; i++) { if (SUGGESTIONS[i].toLowerCase().startsWith(query.toLowerCase())) c.addRow(new Object[] { i, SUGGESTIONS[i] }); }/*www .j a va 2 s. c o m*/ mAdapter.changeCursor(c); }
From source file:org.sufficientlysecure.keychain.ui.ImportKeysSearchFragment.java
private void updateAdapter(String query) { mCurrentSuggestions.clear();/*from w w w. java 2 s . c o m*/ MatrixCursor c = new MatrixCursor(new String[] { BaseColumns._ID, CURSOR_SUGGESTION }); for (int i = 0; i < mNamesAndEmails.size(); i++) { String s = mNamesAndEmails.get(i); if (s.toLowerCase().startsWith(query.toLowerCase())) { mCurrentSuggestions.add(s); c.addRow(new Object[] { i, s }); } } mSearchAdapter.changeCursor(c); }
From source file:osu.appclub.corvallisbus.MainActivity.java
@Override public void searchComplete(Cursor cursor) { Log.d("osu.appclub", "Found " + cursor.getCount() + " results"); if (cursor.getCount() == 0) { MatrixCursor placeholder = new MatrixCursor(new String[] { "_id" }); placeholder.addRow(new Object[] { 0 }); searchView.setSuggestionsAdapter(new CursorAdapter(this, placeholder, false) { @Override/*from ww w . j a va 2 s. c o m*/ public View newView(Context context, Cursor cursor, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(android.R.layout.simple_list_item_1, parent, false); return view; } @Override public void bindView(View view, Context context, Cursor cursor) { TextView text = (TextView) view.findViewById(android.R.id.text1); text.setText(R.string.search_no_results); view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // no-op } }); } }); } else { searchView.setSuggestionsAdapter(new CursorAdapter(this, cursor, false) { @Override public View newView(Context context, Cursor cursor, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(android.R.layout.simple_list_item_2, parent, false); return view; } @SuppressLint("DefaultLocale") @Override public void bindView(View view, Context context, Cursor cursor) { final int stopID = cursor.getInt(0); view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { searchView.clearFocus(); enqueueBusStop(stopID); } }); TextView textStopName = (TextView) view.findViewById(android.R.id.text1); textStopName.setText(cursor.getString(1)); TextView textDistance = (TextView) view.findViewById(android.R.id.text2); if (cursor.getType(2) == Cursor.FIELD_TYPE_NULL) { textDistance.setText(""); } else { textDistance.setText(String.format("%.1f miles", cursor.getDouble(2))); } } }); } }
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 www. j ava2 s.com*/ 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:com.sage42.androidappaddicts.app.main.MainActivity.java
/** * Dummy code for searchview suggestion list. * //w w w. j av a 2 s . co 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.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. j a va2 s . c o 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.dmsl.anyplace.nav.AnyPlaceSeachingHelper.java
public static Cursor prepareSearchViewCursor(List<? extends IPoisClass> places, String query) { String req_columns[] = { BaseColumns._ID, SearchManager.SUGGEST_COLUMN_TEXT_1, SearchManager.SUGGEST_COLUMN_INTENT_DATA }; MatrixCursor mcursor = new MatrixCursor(req_columns); int i = 0;/*w w w . ja v a2s . c o m*/ if (places != null) { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.registerTypeAdapter(IPoisClass.class, new IPoisClass.MyInterfaceAdapter()); Gson gson = gsonBuilder.create(); // Better Use AndroidUtils.fillTextBox instead of regular expression // Regular expression // ?i ignore case Pattern patternTitle = Pattern.compile(String.format("((?i)%s)", query)); // Matches X words before query and Y words after Pattern patternDescription = Pattern.compile( String.format("(([^\\s]+\\s+){0,%d}[^\\s]*)((?i)%s)([^\\s]*(\\s+[^\\s]+){0,%d})", 2, query, 2)); for (IPoisClass p : places) { String name = "", description = ""; Matcher m; m = patternTitle.matcher(p.name()); // Makes matched query bold using HTML format // $1 returns the regular's expression outer parenthesis value name = m.replaceAll("<b>$1</b>"); m = patternDescription.matcher(p.description()); if (m.find()) { // Makes matched query bold using HTML format description = String.format(" %s<b>%s</b>%s", m.group(1), m.group(3), m.group(4)); } mcursor.addRow(new String[] { Integer.toString(i++), name + description, gson.toJson(p, IPoisClass.class) }); } } return mcursor; }