diff options
author | Bananeweizen <bananeweizen@gmx.de> | 2014-08-23 15:14:41 +0200 |
---|---|---|
committer | Bananeweizen <bananeweizen@gmx.de> | 2014-08-23 15:14:41 +0200 |
commit | 08dc24ae950d24c241be674091b64ce4be867058 (patch) | |
tree | 387aab972557e090518a519ce429d5708cd2db7f /cgeo-calendar | |
parent | a3efd8b0018b59f5bbb83b5e136272802c3c7dcf (diff) | |
download | cgeo-08dc24ae950d24c241be674091b64ce4be867058.zip cgeo-08dc24ae950d24c241be674091b64ce4be867058.tar.gz cgeo-08dc24ae950d24c241be674091b64ce4be867058.tar.bz2 |
avoid deprecated managedQuery call
Diffstat (limited to 'cgeo-calendar')
-rw-r--r-- | cgeo-calendar/src/cgeo/calendar/CalendarActivity.java | 75 |
1 files changed, 43 insertions, 32 deletions
diff --git a/cgeo-calendar/src/cgeo/calendar/CalendarActivity.java b/cgeo-calendar/src/cgeo/calendar/CalendarActivity.java index 2fbfd05..14d71b4 100644 --- a/cgeo-calendar/src/cgeo/calendar/CalendarActivity.java +++ b/cgeo-calendar/src/cgeo/calendar/CalendarActivity.java @@ -47,38 +47,7 @@ public final class CalendarActivity extends Activity { * @param entry */ private void selectCalendarForAdding(final CalendarEntry entry) { - final String[] projection = new String[] { "_id", "displayName" }; - final Uri calendarProvider = Compatibility.getCalendarProviderURI(); - - final Cursor cursor = managedQuery(calendarProvider, projection, "selected=1", null, null); - - if (cursor == null || cursor.getCount() <= 0) { - showToast(R.string.event_fail); - finish(); - return; - } - - final SparseArray<String> calendars = new SparseArray<>(); - cursor.moveToFirst(); - - final int indexId = cursor.getColumnIndex("_id"); - final int indexName = cursor.getColumnIndex("displayName"); - - do { - final String idString = cursor.getString(indexId); - if (idString != null) { - try { - int id = Integer.parseInt(idString); - final String calName = cursor.getString(indexName); - - if (id > 0 && calName != null) { - calendars.put(id, calName); - } - } catch (NumberFormatException e) { - Log.e(LOG_TAG, "CalendarActivity.selectCalendarForAdding", e); - } - } - } while (cursor.moveToNext()); + final SparseArray<String> calendars = queryCalendars(); if (calendars.size() == 0) { showToast(R.string.event_fail); @@ -110,6 +79,48 @@ public final class CalendarActivity extends Activity { builder.create().show(); } + private SparseArray<String> queryCalendars() { + final SparseArray<String> calendars = new SparseArray<>(); + + final String[] projection = new String[] { "_id", "displayName" }; + final Uri calendarProvider = Compatibility.getCalendarProviderURI(); + + Cursor cursor = null; + try { + cursor = getContentResolver().query(calendarProvider, projection, "selected=1", null, null); + + if (cursor == null) { + return calendars; + } + + cursor.moveToFirst(); + + final int indexId = cursor.getColumnIndex("_id"); + final int indexName = cursor.getColumnIndex("displayName"); + + do { + final String idString = cursor.getString(indexId); + if (idString != null) { + try { + int id = Integer.parseInt(idString); + final String calName = cursor.getString(indexName); + + if (id > 0 && calName != null) { + calendars.put(id, calName); + } + } catch (NumberFormatException e) { + Log.e(LOG_TAG, "CalendarActivity.selectCalendarForAdding", e); + } + } + } while (cursor.moveToNext()); + } finally { + if (cursor != null) { + cursor.close(); + } + } + return calendars; + } + public final void showToast(final int res) { final String text = getResources().getString(res); final Toast toast = Toast.makeText(this, text, Toast.LENGTH_LONG); |