aboutsummaryrefslogtreecommitdiffstats
path: root/cgeo-calendar
diff options
context:
space:
mode:
authorBananeweizen <bananeweizen@gmx.de>2014-08-23 15:14:41 +0200
committerBananeweizen <bananeweizen@gmx.de>2014-08-23 15:14:41 +0200
commit08dc24ae950d24c241be674091b64ce4be867058 (patch)
tree387aab972557e090518a519ce429d5708cd2db7f /cgeo-calendar
parenta3efd8b0018b59f5bbb83b5e136272802c3c7dcf (diff)
downloadcgeo-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.java75
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);