List of usage examples for android.database Cursor isAfterLast
boolean isAfterLast();
From source file:de.yaacc.upnp.server.YaaccHttpService.java
/** * Lookup content in the mediastore/*from ww w . j a v a 2s . c om*/ * * @param albumId the id of the album * @return the content description */ private ContentHolder lookupAlbumArt(String albumId) { ContentHolder result = new ContentHolder(MimeType.valueOf("image/png"), getDefaultIcon()); if (albumId == null) { return null; } Log.d(getClass().getName(), "System media store lookup album: " + albumId); String[] projection = { MediaStore.Audio.Albums._ID, // FIXME what is the right mime type? // MediaStore.Audio.Albums.MIME_TYPE, MediaStore.Audio.Albums.ALBUM_ART }; String selection = MediaStore.Audio.Albums._ID + "=?"; String[] selectionArgs = { albumId }; Cursor cursor = getContext().getContentResolver().query(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, projection, selection, selectionArgs, null); if (cursor != null) { cursor.moveToFirst(); while (!cursor.isAfterLast()) { String dataUri = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Albums.ALBUM_ART)); // String mimeTypeStr = null; // FIXME mime type resolving cursor // .getString(cursor // .getColumnIndex(MediaStore.Files.FileColumns.MIME_TYPE)); MimeType mimeType = MimeType.valueOf("image/png"); // if (mimeTypeStr != null) { // mimeType = MimeType.valueOf(mimeTypeStr); // } if (dataUri != null) { Log.d(getClass().getName(), "Content found: " + mimeType + " Uri: " + dataUri); result = new ContentHolder(mimeType, dataUri); } cursor.moveToNext(); } } else { Log.d(getClass().getName(), "System media store is empty."); } cursor.close(); return result; }
From source file:com.money.manager.ex.reports.PayeeReportFragment.java
public void showChart() { PayeeReportAdapter adapter = (PayeeReportAdapter) getListAdapter(); if (adapter == null) return;//from w ww. ja va 2s . c om Cursor cursor = adapter.getCursor(); if (cursor == null) return; if (!cursor.moveToFirst()) return; ArrayList<ValuePieEntry> arrayList = new ArrayList<ValuePieEntry>(); while (!cursor.isAfterLast()) { ValuePieEntry item = new ValuePieEntry(); // total double total = Math.abs(cursor.getDouble(cursor.getColumnIndex("TOTAL"))); if (!TextUtils.isEmpty(cursor.getString(cursor.getColumnIndex(ViewMobileData.PAYEE)))) { item.setText(cursor.getString(cursor.getColumnIndex(ViewMobileData.PAYEE))); } else { item.setText(getString(R.string.empty_payee)); } item.setValue(total); CurrencyService currencyService = new CurrencyService(getContext()); item.setValueFormatted(currencyService.getBaseCurrencyFormatted(MoneyFactory.fromDouble(total))); // add element arrayList.add(item); // move to next record cursor.moveToNext(); } Bundle args = new Bundle(); args.putSerializable(PieChartFragment.KEY_CATEGORIES_VALUES, arrayList); //get fragment manager FragmentManager fragmentManager = getActivity().getSupportFragmentManager(); if (fragmentManager != null) { PieChartFragment fragment; fragment = (PieChartFragment) fragmentManager .findFragmentByTag(IncomeVsExpensesChartFragment.class.getSimpleName()); if (fragment == null) { fragment = new PieChartFragment(); } fragment.setChartArguments(args); fragment.setDisplayHomeAsUpEnabled(true); if (fragment.isVisible()) fragment.onResume(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); if (((PayeesReportActivity) getActivity()).mIsDualPanel) { fragmentTransaction.replace(R.id.fragmentChart, fragment, PieChartFragment.class.getSimpleName()); } else { fragmentTransaction.replace(R.id.fragmentMain, fragment, PieChartFragment.class.getSimpleName()); fragmentTransaction.addToBackStack(null); } try { fragmentTransaction.commit(); } catch (IllegalStateException e) { Timber.e(e, "adding fragment"); } } }
From source file:ch.ethz.twimight.net.tds.TDSRequestMessage.java
/** * creates JSONObject to push Statistics to the TDS * //from w ww .j ava2 s . c om * @param * @return JSON Object * @throws JSONException */ public void createStatisticObject(Cursor stats, long follCount) throws JSONException { if (stats != null) { statisticObject = new JSONObject(); JSONArray statisticArray = new JSONArray(); while (!stats.isAfterLast()) { JSONObject row = new JSONObject(); row.put("latitude", Double .toString(stats.getDouble(stats.getColumnIndex(StatisticsDBHelper.KEY_LOCATION_LAT)))); row.put("longitude", Double .toString(stats.getDouble(stats.getColumnIndex(StatisticsDBHelper.KEY_LOCATION_LNG)))); row.put("accuracy", Integer .toString(stats.getInt(stats.getColumnIndex(StatisticsDBHelper.KEY_LOCATION_ACCURACY)))); row.put("provider", stats.getString(stats.getColumnIndex(StatisticsDBHelper.KEY_LOCATION_PROVIDER))); row.put("timestamp", Long.toString(stats.getLong(stats.getColumnIndex(StatisticsDBHelper.KEY_TIMESTAMP)))); row.put("network", stats.getString(stats.getColumnIndex(StatisticsDBHelper.KEY_NETWORK))); row.put("event", stats.getString(stats.getColumnIndex(StatisticsDBHelper.KEY_EVENT))); row.put("link", stats.getString(stats.getColumnIndex(StatisticsDBHelper.KEY_LINK))); row.put("isDisaster", Integer.toString(stats.getInt(stats.getColumnIndex(StatisticsDBHelper.KEY_ISDISASTER)))); row.put("followers_count", follCount); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); row.put("dis_mode_used", Preferences.getBoolean(context, R.string.pref_key_disastermode_has_been_used, false)); statisticArray.put(row); stats.moveToNext(); } stats.close(); statisticObject.put("content", statisticArray); } }
From source file:de.yaacc.upnp.server.YaaccHttpService.java
/** * Lookup content in the mediastore/*w w w . ja v a2 s .c o m*/ * * @param contentId the id of the content * @return the content description */ private ContentHolder lookupContent(String contentId) { ContentHolder result = null; if (contentId == null) { return null; } Log.d(getClass().getName(), "System media store lookup: " + contentId); String[] projection = { MediaStore.Files.FileColumns._ID, MediaStore.Files.FileColumns.MIME_TYPE, MediaStore.Files.FileColumns.DATA }; String selection = MediaStore.Files.FileColumns._ID + "=?"; String[] selectionArgs = { contentId }; Cursor mFilesCursor = getContext().getContentResolver().query(MediaStore.Files.getContentUri("external"), projection, selection, selectionArgs, null); if (mFilesCursor != null) { mFilesCursor.moveToFirst(); while (!mFilesCursor.isAfterLast()) { String dataUri = mFilesCursor .getString(mFilesCursor.getColumnIndex(MediaStore.Files.FileColumns.DATA)); String mimeTypeStr = mFilesCursor .getString(mFilesCursor.getColumnIndex(MediaStore.Files.FileColumns.MIME_TYPE)); MimeType mimeType = MimeType.valueOf("*/*"); if (mimeTypeStr != null) { mimeType = MimeType.valueOf(mimeTypeStr); } Log.d(getClass().getName(), "Content found: " + mimeType + " Uri: " + dataUri); result = new ContentHolder(mimeType, dataUri); mFilesCursor.moveToNext(); } } else { Log.d(getClass().getName(), "System media store is empty."); } mFilesCursor.close(); return result; }
From source file:com.andrew.apollo.menu.CreateNewPlaylist.java
private String makePlaylistName() { final String template = getString(R.string.new_playlist_name_template); int num = 1;//w w w .j av a2 s . c om final String[] projection = new String[] { MediaStore.Audio.Playlists.NAME }; final ContentResolver resolver = getActivity().getContentResolver(); final String selection = MediaStore.Audio.Playlists.NAME + " != ''"; Cursor cursor = resolver.query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, projection, selection, null, MediaStore.Audio.Playlists.NAME); if (cursor == null) { return null; } String suggestedName; suggestedName = String.format(template, num++); boolean done = false; while (!done) { done = true; cursor.moveToFirst(); while (!cursor.isAfterLast()) { final String playlistName = cursor.getString(0); if (playlistName.compareToIgnoreCase(suggestedName) == 0) { suggestedName = String.format(template, num++); done = false; } cursor.moveToNext(); } } cursor.close(); return suggestedName; }
From source file:org.mariotaku.twidere.util.DataStoreUtils.java
@WorkerThread public static void updateActivity(ContentResolver cr, Uri uri, String where, String[] whereArgs, UpdateActivityAction action) {/*from w w w .j a va2 s . c o m*/ final Cursor c = cr.query(uri, Activities.COLUMNS, where, whereArgs, null); if (c == null) return; LongSparseArray<ContentValues> values = new LongSparseArray<>(); try { ParcelableActivityCursorIndices ci = new ParcelableActivityCursorIndices(c); c.moveToFirst(); while (!c.isAfterLast()) { final ParcelableActivity activity = ci.newObject(c); action.process(activity); values.put(activity._id, ParcelableActivityValuesCreator.create(activity)); c.moveToNext(); } } finally { c.close(); } String updateWhere = Expression.equalsArgs(Activities._ID).getSQL(); String[] updateWhereArgs = new String[1]; for (int i = 0, j = values.size(); i < j; i++) { updateWhereArgs[0] = String.valueOf(values.keyAt(i)); cr.update(uri, values.valueAt(i), updateWhere, updateWhereArgs); } }
From source file:curso.android.DAO.RespostaDAO.java
public static List<Resposta> readAll() { Cursor cursor = null; try {/*from w w w .j a v a 2 s. c o m*/ List<Resposta> all = new ArrayList<Resposta>(); cursor = Const.db.rawQuery("SELECT * FROM resposta", null); if (cursor.getCount() > 0) { int idIndex = cursor.getColumnIndex("asw_id"); int askIndex = cursor.getColumnIndex("ask_id"); int userIndex = cursor.getColumnIndex("user_id"); int respostaIndex = cursor.getColumnIndex("asw_resposta"); int nameIndex = cursor.getColumnIndex("user_name"); cursor.moveToFirst(); do { Long id = Long.valueOf(cursor.getInt(idIndex)); Long ask = Long.valueOf(cursor.getString(askIndex)); Long user = Long.valueOf(cursor.getString(userIndex)); String pergunta = cursor.getString(respostaIndex); String user_name = cursor.getString(nameIndex); Resposta asw = new Resposta(); asw.setAsw_id(id); asw.setAsk_id(ask); asw.setUser_id(user); asw.setAsw_resposta(pergunta); asw.setUser_name(user_name); all.add(asw); cursor.moveToNext(); } while (!cursor.isAfterLast()); } return all; } finally { if (cursor != null) { cursor.close(); } } }
From source file:gov.wa.wsdot.android.wsdot.service.FerriesSchedulesSyncService.java
/** * Check the ferries schedules table for any starred entries. If we find some, save them * to a list so we can re-star those after we flush the database. */// w w w .ja va2s .co m private List<Integer> getStarred() { ContentResolver resolver = getContentResolver(); Cursor cursor = null; List<Integer> starred = new ArrayList<Integer>(); try { cursor = resolver.query(FerriesSchedules.CONTENT_URI, new String[] { FerriesSchedules.FERRIES_SCHEDULE_ID }, FerriesSchedules.FERRIES_SCHEDULE_IS_STARRED + "=?", new String[] { "1" }, null); if (cursor != null && cursor.moveToFirst()) { while (!cursor.isAfterLast()) { starred.add(cursor.getInt(0)); cursor.moveToNext(); } } } finally { if (cursor != null) { cursor.close(); } } return starred; }
From source file:org.mariotaku.twidere.util.DataStoreUtils.java
public static List<ParcelableCredentials> getCredentialsList(final Context context, final boolean activatedOnly, final boolean officialKeyOnly) { if (context == null) return Collections.emptyList(); final ArrayList<ParcelableCredentials> accounts = new ArrayList<>(); final String selection = activatedOnly ? Accounts.IS_ACTIVATED + " = 1" : null; final Cursor cur = context.getContentResolver().query(Accounts.CONTENT_URI, Accounts.COLUMNS, selection, null, Accounts.SORT_POSITION); if (cur == null) return accounts; ParcelableCredentialsCursorIndices indices = new ParcelableCredentialsCursorIndices(cur); cur.moveToFirst();//from w w w . ja va 2 s.c om while (!cur.isAfterLast()) { if (officialKeyOnly) { final String consumerKey = cur.getString(indices.consumer_key); final String consumerSecret = cur.getString(indices.consumer_secret); if (TwitterContentUtils.isOfficialKey(context, consumerKey, consumerSecret)) { accounts.add(indices.newObject(cur)); } } else { accounts.add(indices.newObject(cur)); } cur.moveToNext(); } cur.close(); return accounts; }
From source file:fr.eoit.activity.fragment.blueprint.RequiredSkillInventionFragment.java
@Override public void onLoadFinished(Cursor cursor) { if (DbUtil.hasAtLeastOneRow(cursor)) { short encryptionSkillLevel = -1; int encryptionSkillId = -1; short datacore1SkillLevel = -1; short datacore2SkillLevel = -1; List<Map<String, Object>> data = new ArrayList<Map<String, Object>>(); boolean datacore1SkillSet = false; while (!cursor.isAfterLast()) { Map<String, Object> dataLine = new HashMap<String, Object>(); int skillId = cursor.getInt(cursor.getColumnIndexOrThrow(InventionMapping.COLUMN_NAME_SKILL_ID)); String skillName = cursor.getString(cursor.getColumnIndexOrThrow(Item.COLUMN_NAME_NAME)); int skillLevel = 1; short userSkillLevel = Skills.getSkill(skillId); if (Skills.isEncryptionSkill(skillId)) { encryptionSkillLevel = userSkillLevel; encryptionSkillId = skillId; } else { if (datacore1SkillSet) { datacore2SkillLevel = userSkillLevel; } else { datacore1SkillLevel = userSkillLevel; datacore1SkillSet = true; }/* ww w . j a v a 2 s .co m*/ } boolean learnt = userSkillLevel >= skillLevel; dataLine.put(InventionMapping.COLUMN_NAME_LEARNT, learnt); dataLine.put(Item.COLUMN_NAME_NAME, skillName); dataLine.put(InventionMapping.COLUMN_NAME_SKILL_LEVEL, userSkillLevel); data.add(dataLine); cursor.moveToNext(); } SimpleAdapter adapter = new SimpleAdapter(getActivity(), data, R.layout.required_skills_row, FROM, TO); adapter.setViewBinder(new RequiredSkillsViewBinder()); ListView listView = (ListView) getView().findViewById(R.id.REQUIRED_SKILLS_LIST); listView.setAdapter(adapter); int count = cursor.getCount(); int width = count * ((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 26, getResources().getDisplayMetrics())); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, width); listView.setLayoutParams(lp); if (fragmentReference != null && fragmentReference.get() != null) { fragmentReference.get().updateInventionChances(encryptionSkillLevel, datacore1SkillLevel, datacore2SkillLevel); fragmentReference.get().setEncryptionSkillId(encryptionSkillId); } } }