List of usage examples for android.database Cursor getLong
long getLong(int columnIndex);
From source file:com.test.onesignal.GenerateNotificationRunner.java
@Test public void shouldHandleBasicNotifications() throws Exception { // Make sure the notification got posted and the content is correct. Bundle bundle = getBaseNotifBundle(); NotificationBundleProcessor_ProcessFromGCMIntentService(blankActivity, bundle, null); Assert.assertEquals(notifMessage, ShadowRoboNotificationManager.getLastShadowNotif().getContentText()); Assert.assertEquals(1, ShadowBadgeCountUpdater.lastCount); // Should have 1 DB record with the correct time stamp SQLiteDatabase readableDb = OneSignalDbHelper.getInstance(blankActivity).getReadableDatabase(); Cursor cursor = readableDb.query(NotificationTable.TABLE_NAME, new String[] { "created_time" }, null, null, null, null, null);/* w w w .j a va 2s. com*/ Assert.assertEquals(1, cursor.getCount()); // Time stamp should be set and within a small range. long currentTime = System.currentTimeMillis() / 1000; cursor.moveToFirst(); Assert.assertTrue(cursor.getLong(0) > currentTime - 2 && cursor.getLong(0) <= currentTime); cursor.close(); // Should get marked as opened. NotificationOpenedProcessor_processFromContext(blankActivity, createOpenIntent(bundle)); cursor = readableDb.query(NotificationTable.TABLE_NAME, new String[] { "opened", "android_notification_id" }, null, null, null, null, null); cursor.moveToFirst(); Assert.assertEquals(1, cursor.getInt(0)); Assert.assertEquals(0, ShadowBadgeCountUpdater.lastCount); cursor.close(); // Should not display a duplicate notification, count should still be 1 NotificationBundleProcessor_ProcessFromGCMIntentService(blankActivity, bundle, null); readableDb = OneSignalDbHelper.getInstance(blankActivity).getReadableDatabase(); cursor = readableDb.query(NotificationTable.TABLE_NAME, null, null, null, null, null, null); Assert.assertEquals(1, cursor.getCount()); Assert.assertEquals(0, ShadowBadgeCountUpdater.lastCount); cursor.close(); // Display a second notification bundle = getBaseNotifBundle("UUID2"); NotificationBundleProcessor_ProcessFromGCMIntentService(blankActivity, bundle, null); // Go forward 4 weeks // Note: Does not effect the SQL function strftime ShadowSystemClock.setCurrentTimeMillis(System.currentTimeMillis() + 2419201L * 1000L); // Display a 3rd notification // Should of been added for a total of 2 records now. // First opened should of been cleaned up, 1 week old non opened notification should stay, and one new record. bundle = getBaseNotifBundle("UUID3"); NotificationBundleProcessor_ProcessFromGCMIntentService(blankActivity, bundle, null); readableDb = OneSignalDbHelper.getInstance(blankActivity).getReadableDatabase(); cursor = readableDb.query(NotificationTable.TABLE_NAME, new String[] { "android_notification_id", "created_time" }, null, null, null, null, null); Assert.assertEquals(1, cursor.getCount()); Assert.assertEquals(1, ShadowBadgeCountUpdater.lastCount); cursor.close(); }
From source file:br.ufc.mdcc.benchimage2.dao.ResultDao.java
private ArrayList<ResultImage> queryResultImage(String sql) throws JSONException, ParseException { openDatabase();/*from w w w .j ava 2 s. c om*/ Cursor cursor = database.rawQuery(sql, null); ArrayList<ResultImage> lista = new ArrayList<ResultImage>(); // obtem todos os indices das colunas da tabela int idx_id = cursor.getColumnIndex(F_ID); int idx_date = cursor.getColumnIndex(F_DATE); int idx_photo_name = cursor.getColumnIndex(F_PHOTO_NAME); int idx_filter_name = cursor.getColumnIndex(F_FILTER_NAME); int idx_local = cursor.getColumnIndex(F_LOCAL); int idx_size = cursor.getColumnIndex(F_SIZE); int idx_cpu_time = cursor.getColumnIndex(F_EXECUTION_CPU_TIME); int idx_up_time = cursor.getColumnIndex(F_UPLOAD_TIME); int idx_down_time = cursor.getColumnIndex(F_DOWNLOAD_TIME); int idx_total_time = cursor.getColumnIndex(F_TOTAL_TIME); int idx_down_size = cursor.getColumnIndex(F_DOWN_SIZE); int idx_up_size = cursor.getColumnIndex(F_UP_SIZE); if (cursor != null && cursor.moveToFirst()) { do { ResultImage result = new ResultImage(); result.setId(cursor.getInt(idx_id)); result.setDate(simpleDateFormat.parse(cursor.getString(idx_date))); result.setTotalTime(cursor.getLong(idx_total_time)); AppConfiguration config = new AppConfiguration(); config.setImage(cursor.getString(idx_photo_name)); config.setFilter(cursor.getString(idx_filter_name)); config.setLocal(cursor.getString(idx_local)); config.setSize(cursor.getString(idx_size)); result.setConfig(config); RpcProfile profile = new RpcProfile(); profile.setDonwloadTime(cursor.getLong(idx_down_time)); profile.setDownloadSize(cursor.getInt(idx_down_size)); profile.setUploadTime(cursor.getLong(idx_up_time)); profile.setUploadSize(cursor.getInt(idx_up_size)); profile.setExecutionCpuTime(cursor.getLong(idx_cpu_time)); result.setRpcProfile(profile); lista.add(result); } while (cursor.moveToNext()); } cursor.close(); closeDatabase(); return lista; }
From source file:com.rukman.emde.smsgroups.syncadapter.SyncAdapter.java
private void deleteUnsyncedItems(ContentProviderClient provider, Account account, SyncResult syncResult) throws RemoteException, JSONException { Log.d(TAG, "Delete unsynced items before count: " + syncResult.stats.numDeletes); ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(); ContentProviderOperation op;/*from ww w .j av a2 s .c om*/ ContentProviderResult[] results; // This is the good part Cursor unsyncedGroupsCursor = null; try { final String SELECT = GMSGroup.STATUS + " ISNULL OR " + GMSGroup.STATUS + " != " + GMSGroup.STATUS_SYNCED; unsyncedGroupsCursor = provider.query(GMSGroups.CONTENT_URI, new String[] { GMSGroup._ID, GMSGroup.CLOUD_ID, GMSGroup.STATUS, GMSGroup.NAME, GMSGroup.RAW_CONTACT_ID }, SELECT, null, null); ContentProviderClient contactsProvider; if (unsyncedGroupsCursor.moveToFirst()) { contactsProvider = getContext().getContentResolver() .acquireContentProviderClient(ContactsContract.AUTHORITY); do { long groupId = unsyncedGroupsCursor.getLong(0); long groupRawContactId = unsyncedGroupsCursor.getLong(4); Cursor memberCursor = null; try { memberCursor = provider.query(GMSContacts.CONTENT_URI, new String[] { GMSContact._ID, GMSContact.GROUP_ID }, GMSContact.GROUP_ID + "=?", new String[] { String.valueOf(groupId) }, null); while (memberCursor.moveToNext()) { op = ContentProviderOperation.newDelete( ContentUris.withAppendedId(GMSContacts.CONTENT_URI, memberCursor.getLong(0))) .build(); ops.add(op); } } finally { if (memberCursor != null) { memberCursor.close(); } } op = ContentProviderOperation .newDelete(ContentUris.withAppendedId(GMSGroups.CONTENT_URI, groupId)).build(); ops.add(op); if (groupRawContactId <= 0) { Cursor accountContactsCursor = null; try { String sourceId = unsyncedGroupsCursor.getString(1); Log.d(TAG, String.format("Unsynced Group Id: %1$d, SourceId: %2$s", groupId, sourceId)); accountContactsCursor = GMSContactOperations.findGroupInContacts(contactsProvider, account, sourceId); if (accountContactsCursor != null && accountContactsCursor.moveToFirst()) { groupRawContactId = accountContactsCursor.getLong(0); } } finally { if (accountContactsCursor != null) { accountContactsCursor.close(); } } GMSContactOperations.removeGroupFromContacts(contactsProvider, account, groupRawContactId, syncResult); } } while (unsyncedGroupsCursor.moveToNext()); } } finally { if (unsyncedGroupsCursor != null) { unsyncedGroupsCursor.close(); } } // Now delete any unsynced contacts from the local provider op = ContentProviderOperation.newDelete(GMSContacts.CONTENT_URI) .withSelection( GMSContact.STATUS + " ISNULL OR " + GMSContact.STATUS + " != " + GMSContact.STATUS_SYNCED, null) .build(); ops.add(op); op = ContentProviderOperation.newUpdate(GMSGroups.CONTENT_URI).withValue(GMSGroup.STATUS, null).build(); ops.add(op); op = ContentProviderOperation.newUpdate(GMSContacts.CONTENT_URI).withValue(GMSContact.STATUS, null).build(); ops.add(op); try { results = provider.applyBatch(ops); int numResults = results.length; for (int i = 0; i < numResults; ++i) { // The first first N-2 results were deletes if (i < numResults - 2) { syncResult.stats.numDeletes += results[i].count; } else { // The last two results were updates syncResult.stats.numEntries += results[i].count; } } Log.d(TAG, String.format("Delete unsynced items after count: %1$d, entries: %2$d", syncResult.stats.numDeletes, syncResult.stats.numEntries)); } catch (OperationApplicationException e) { syncResult.stats.numSkippedEntries++; e.printStackTrace(); } }
From source file:org.mythtv.android.db.dvr.ProgramHelperV27.java
private Program convertCursorToProgram(Cursor cursor, final String table) { // Log.v( TAG, "convertCursorToProgram : enter" ); DateTime startTime = null, endTime = null, lastModified = null, airDate = null; String title = "", subTitle = "", category = "", categoryType = "", seriesId = "", programId = "", hostname = "", filename = "", description = "", inetref = ""; int repeat = -1, videoProps = -1, audioProps = -1, subProps = -1, programFlags = -1, season = -1, episode = -1;//from w ww.j a v a 2 s .c o m long fileSize = -1; double stars = 0.0f; ChannelInfo channelInfo = null; RecordingInfo recording = null; if (cursor.getColumnIndex(ProgramConstants.FIELD_START_TIME) != -1) { startTime = new DateTime(cursor.getLong(cursor.getColumnIndex(ProgramConstants.FIELD_START_TIME))); } if (cursor.getColumnIndex(ProgramConstants.FIELD_END_TIME) != -1) { endTime = new DateTime(cursor.getLong(cursor.getColumnIndex(ProgramConstants.FIELD_END_TIME))); } if (cursor.getColumnIndex(ProgramConstants.FIELD_TITLE) != -1) { title = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_TITLE)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_SUB_TITLE) != -1) { subTitle = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_SUB_TITLE)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_CATEGORY) != -1) { category = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_CATEGORY)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_CATEGORY_TYPE) != -1) { categoryType = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_CATEGORY_TYPE)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_REPEAT) != -1) { repeat = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_REPEAT)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_VIDEO_PROPS) != -1) { videoProps = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_VIDEO_PROPS)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_AUDIO_PROPS) != -1) { audioProps = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_AUDIO_PROPS)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_SUB_PROPS) != -1) { subProps = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_SUB_PROPS)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_SERIES_ID) != -1) { seriesId = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_SERIES_ID)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_PROGRAM_ID) != -1) { programId = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_PROGRAM_ID)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_STARS) != -1) { stars = cursor.getDouble(cursor.getColumnIndex(ProgramConstants.FIELD_STARS)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_FILE_SIZE) != -1) { fileSize = cursor.getLong(cursor.getColumnIndex(ProgramConstants.FIELD_FILE_SIZE)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_LAST_MODIFIED) != -1) { lastModified = new DateTime( cursor.getLong(cursor.getColumnIndex(ProgramConstants.FIELD_LAST_MODIFIED))); } if (cursor.getColumnIndex(ProgramConstants.FIELD_PROGRAM_FLAGS) != -1) { programFlags = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_PROGRAM_FLAGS)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_HOSTNAME) != -1) { hostname = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_HOSTNAME)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_FILENAME) != -1) { filename = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_FILENAME)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_AIR_DATE) != -1) { try { airDate = DateUtils.dateFormatter .parseDateTime(cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_AIR_DATE))); } catch (Exception e) { Log.w(TAG, "AirDate could not be parsed"); } } if (cursor.getColumnIndex(ProgramConstants.FIELD_DESCRIPTION) != -1) { description = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_DESCRIPTION)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_INETREF) != -1) { inetref = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_INETREF)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_SEASON) != -1) { season = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_SEASON)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_EPISODE) != -1) { episode = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_EPISODE)); } Program program = new Program(); program.setStartTime(startTime); program.setEndTime(endTime); program.setTitle(title); program.setSubTitle(subTitle); program.setCategory(category); program.setCatType(categoryType); program.setRepeat(repeat == 1 ? true : false); program.setVideoProps(videoProps); program.setAudioProps(audioProps); program.setSubProps(subProps); program.setSeriesId(seriesId); program.setProgramId(programId); program.setStars(stars); program.setFileSize(fileSize); program.setLastModified(lastModified); program.setProgramFlags(programFlags); program.setHostName(hostname); program.setFileName(filename); program.setAirdate(null != airDate ? airDate.toLocalDate() : null); program.setDescription(description); program.setInetref(inetref); program.setSeason(season); program.setEpisode(episode); program.setChannel(channelInfo); program.setRecording(recording); // Log.v( TAG, "convertCursorToProgram : exit" ); return program; }
From source file:com.hichinaschool.flashcards.libanki.Finder.java
private String _findField(String field, String val) { val = val.replace("*", "%"); // find models that have that field Map<Long, Object[]> mods = new HashMap<Long, Object[]>(); try {/* w ww .j a v a 2s . c o m*/ for (JSONObject m : mCol.getModels().all()) { JSONArray flds = m.getJSONArray("flds"); for (int fi = 0; fi < flds.length(); ++fi) { JSONObject f = flds.getJSONObject(fi); if (f.getString("name").equalsIgnoreCase(field)) { mods.put(m.getLong("id"), new Object[] { m, f.getInt("ord") }); } } } } catch (JSONException e) { throw new RuntimeException(e); } if (mods.isEmpty()) { // nothing has that field return ""; } // gather nids // Pattern.quote escapes the meta characters with \Q \E String regex = Pattern.quote(val).replace("\\Q_\\E", ".").replace("\\Q%\\E", ".*"); LinkedList<Long> nids = new LinkedList<Long>(); Cursor cur = null; try { cur = mCol.getDb().getDatabase() .rawQuery("select id, mid, flds from notes where mid in " + Utils.ids2str(new LinkedList<Long>(mods.keySet())) + " and flds like ? escape '\\'", new String[] { "%" + val + "%" }); while (cur.moveToNext()) { String[] flds = Utils.splitFields(cur.getString(2)); int ord = (Integer) mods.get(cur.getLong(1))[1]; String strg = flds[ord]; if (Pattern.compile(regex, Pattern.CASE_INSENSITIVE).matcher(strg).matches()) { nids.add(cur.getLong(0)); } } } finally { if (cur != null) { cur.close(); } } if (nids.isEmpty()) { return ""; } return "n.id in " + Utils.ids2str(nids); }
From source file:org.mythtv.service.dvr.v25.ProgramHelperV25.java
private Program convertCursorToProgram(Cursor cursor, final String table) { // Log.v( TAG, "convertCursorToProgram : enter" ); DateTime startTime = null, endTime = null, lastModified = null, airDate = null; String title = "", subTitle = "", category = "", categoryType = "", seriesId = "", programId = "", hostname = "", filename = "", description = "", inetref = ""; int repeat = -1, videoProps = -1, audioProps = -1, subProps = -1, programFlags = -1, season = -1, episode = -1;/*from w w w . ja va2s. com*/ long fileSize = -1; double stars = 0.0f; ChannelInfo channelInfo = null; RecordingInfo recording = null; if (cursor.getColumnIndex(ProgramConstants.FIELD_START_TIME) != -1) { startTime = new DateTime(cursor.getLong(cursor.getColumnIndex(ProgramConstants.FIELD_START_TIME))); } if (cursor.getColumnIndex(ProgramConstants.FIELD_END_TIME) != -1) { endTime = new DateTime(cursor.getLong(cursor.getColumnIndex(ProgramConstants.FIELD_END_TIME))); } if (cursor.getColumnIndex(ProgramConstants.FIELD_TITLE) != -1) { title = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_TITLE)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_SUB_TITLE) != -1) { subTitle = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_SUB_TITLE)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_CATEGORY) != -1) { category = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_CATEGORY)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_CATEGORY_TYPE) != -1) { categoryType = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_CATEGORY_TYPE)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_REPEAT) != -1) { repeat = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_REPEAT)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_VIDEO_PROPS) != -1) { videoProps = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_VIDEO_PROPS)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_AUDIO_PROPS) != -1) { audioProps = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_AUDIO_PROPS)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_SUB_PROPS) != -1) { subProps = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_SUB_PROPS)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_SERIES_ID) != -1) { seriesId = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_SERIES_ID)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_PROGRAM_ID) != -1) { programId = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_PROGRAM_ID)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_STARS) != -1) { stars = cursor.getDouble(cursor.getColumnIndex(ProgramConstants.FIELD_STARS)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_FILE_SIZE) != -1) { fileSize = cursor.getLong(cursor.getColumnIndex(ProgramConstants.FIELD_FILE_SIZE)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_LAST_MODIFIED) != -1) { lastModified = new DateTime( cursor.getLong(cursor.getColumnIndex(ProgramConstants.FIELD_LAST_MODIFIED))); } if (cursor.getColumnIndex(ProgramConstants.FIELD_PROGRAM_FLAGS) != -1) { programFlags = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_PROGRAM_FLAGS)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_HOSTNAME) != -1) { hostname = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_HOSTNAME)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_FILENAME) != -1) { filename = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_FILENAME)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_AIR_DATE) != -1) { try { airDate = DateUtils.dateFormatter .parseDateTime(cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_AIR_DATE))); } catch (Exception e) { Log.w(TAG, "AirDate could not be parsed"); } } if (cursor.getColumnIndex(ProgramConstants.FIELD_DESCRIPTION) != -1) { description = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_DESCRIPTION)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_INETREF) != -1) { inetref = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_INETREF)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_SEASON) != -1) { season = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_SEASON)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_EPISODE) != -1) { episode = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_EPISODE)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_CHANNEL_ID) != -1) { channelInfo = ChannelHelperV25.getInstance().convertCursorToChannelInfo(cursor); } if (cursor.getColumnIndex(RecordingConstants.ContentDetails.getValueFromParent(table).getTableName() + "_" + RecordingConstants.FIELD_RECORD_ID) != -1) { recording = RecordingHelperV25.getInstance().convertCursorToRecording(cursor, table); } Program program = new Program(); program.setStartTime(startTime); program.setEndTime(endTime); program.setTitle(title); program.setSubTitle(subTitle); program.setCategory(category); program.setCatType(categoryType); program.setRepeat(repeat == 1 ? true : false); program.setVideoProps(videoProps); program.setAudioProps(audioProps); program.setSubProps(subProps); program.setSeriesId(seriesId); program.setProgramId(programId); program.setStars(stars); program.setFileSize(fileSize); program.setLastModified(lastModified); program.setProgramFlags(programFlags); program.setHostName(hostname); program.setFileName(filename); program.setAirdate(null != airDate ? airDate.toLocalDate() : null); program.setDescription(description); program.setInetref(inetref); program.setSeason(season); program.setEpisode(episode); program.setChannel(channelInfo); program.setRecording(recording); // Log.v( TAG, "convertCursorToProgram : exit" ); return program; }
From source file:org.mythtv.service.dvr.v26.ProgramHelperV26.java
private Program convertCursorToProgram(Cursor cursor, final String table) { // Log.v( TAG, "convertCursorToProgram : enter" ); DateTime startTime = null, endTime = null, lastModified = null, airDate = null; String title = "", subTitle = "", category = "", categoryType = "", seriesId = "", programId = "", hostname = "", filename = "", description = "", inetref = ""; int repeat = -1, videoProps = -1, audioProps = -1, subProps = -1, programFlags = -1, season = -1, episode = -1;/* www .ja v a2s.co m*/ long fileSize = -1; double stars = 0.0f; ChannelInfo channelInfo = null; RecordingInfo recording = null; if (cursor.getColumnIndex(ProgramConstants.FIELD_START_TIME) != -1) { startTime = new DateTime(cursor.getLong(cursor.getColumnIndex(ProgramConstants.FIELD_START_TIME))); } if (cursor.getColumnIndex(ProgramConstants.FIELD_END_TIME) != -1) { endTime = new DateTime(cursor.getLong(cursor.getColumnIndex(ProgramConstants.FIELD_END_TIME))); } if (cursor.getColumnIndex(ProgramConstants.FIELD_TITLE) != -1) { title = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_TITLE)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_SUB_TITLE) != -1) { subTitle = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_SUB_TITLE)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_CATEGORY) != -1) { category = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_CATEGORY)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_CATEGORY_TYPE) != -1) { categoryType = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_CATEGORY_TYPE)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_REPEAT) != -1) { repeat = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_REPEAT)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_VIDEO_PROPS) != -1) { videoProps = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_VIDEO_PROPS)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_AUDIO_PROPS) != -1) { audioProps = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_AUDIO_PROPS)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_SUB_PROPS) != -1) { subProps = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_SUB_PROPS)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_SERIES_ID) != -1) { seriesId = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_SERIES_ID)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_PROGRAM_ID) != -1) { programId = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_PROGRAM_ID)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_STARS) != -1) { stars = cursor.getDouble(cursor.getColumnIndex(ProgramConstants.FIELD_STARS)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_FILE_SIZE) != -1) { fileSize = cursor.getLong(cursor.getColumnIndex(ProgramConstants.FIELD_FILE_SIZE)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_LAST_MODIFIED) != -1) { lastModified = new DateTime( cursor.getLong(cursor.getColumnIndex(ProgramConstants.FIELD_LAST_MODIFIED))); } if (cursor.getColumnIndex(ProgramConstants.FIELD_PROGRAM_FLAGS) != -1) { programFlags = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_PROGRAM_FLAGS)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_HOSTNAME) != -1) { hostname = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_HOSTNAME)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_FILENAME) != -1) { filename = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_FILENAME)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_AIR_DATE) != -1) { try { airDate = DateUtils.dateFormatter .parseDateTime(cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_AIR_DATE))); } catch (Exception e) { Log.w(TAG, "AirDate could not be parsed"); } } if (cursor.getColumnIndex(ProgramConstants.FIELD_DESCRIPTION) != -1) { description = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_DESCRIPTION)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_INETREF) != -1) { inetref = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_INETREF)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_SEASON) != -1) { season = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_SEASON)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_EPISODE) != -1) { episode = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_EPISODE)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_CHANNEL_ID) != -1) { channelInfo = ChannelHelperV26.getInstance().convertCursorToChannelInfo(cursor); } if (cursor.getColumnIndex(RecordingConstants.ContentDetails.getValueFromParent(table).getTableName() + "_" + RecordingConstants.FIELD_RECORD_ID) != -1) { recording = RecordingHelperV26.getInstance().convertCursorToRecording(cursor, table); } Program program = new Program(); program.setStartTime(startTime); program.setEndTime(endTime); program.setTitle(title); program.setSubTitle(subTitle); program.setCategory(category); program.setCatType(categoryType); program.setRepeat(repeat == 1 ? true : false); program.setVideoProps(videoProps); program.setAudioProps(audioProps); program.setSubProps(subProps); program.setSeriesId(seriesId); program.setProgramId(programId); program.setStars(stars); program.setFileSize(fileSize); program.setLastModified(lastModified); program.setProgramFlags(programFlags); program.setHostName(hostname); program.setFileName(filename); program.setAirdate(null != airDate ? airDate.toLocalDate() : null); program.setDescription(description); program.setInetref(inetref); program.setSeason(season); program.setEpisode(episode); program.setChannel(channelInfo); program.setRecording(recording); // Log.v( TAG, "convertCursorToProgram : exit" ); return program; }
From source file:org.mythtv.service.dvr.v27.ProgramHelperV27.java
private Program convertCursorToProgram(Cursor cursor, final String table) { // Log.v( TAG, "convertCursorToProgram : enter" ); DateTime startTime = null, endTime = null, lastModified = null, airDate = null; String title = "", subTitle = "", category = "", categoryType = "", seriesId = "", programId = "", hostname = "", filename = "", description = "", inetref = ""; int repeat = -1, videoProps = -1, audioProps = -1, subProps = -1, programFlags = -1, season = -1, episode = -1;/*from www .j av a 2 s .c o m*/ long fileSize = -1; double stars = 0.0f; ChannelInfo channelInfo = null; RecordingInfo recording = null; if (cursor.getColumnIndex(ProgramConstants.FIELD_START_TIME) != -1) { startTime = new DateTime(cursor.getLong(cursor.getColumnIndex(ProgramConstants.FIELD_START_TIME))); } if (cursor.getColumnIndex(ProgramConstants.FIELD_END_TIME) != -1) { endTime = new DateTime(cursor.getLong(cursor.getColumnIndex(ProgramConstants.FIELD_END_TIME))); } if (cursor.getColumnIndex(ProgramConstants.FIELD_TITLE) != -1) { title = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_TITLE)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_SUB_TITLE) != -1) { subTitle = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_SUB_TITLE)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_CATEGORY) != -1) { category = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_CATEGORY)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_CATEGORY_TYPE) != -1) { categoryType = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_CATEGORY_TYPE)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_REPEAT) != -1) { repeat = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_REPEAT)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_VIDEO_PROPS) != -1) { videoProps = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_VIDEO_PROPS)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_AUDIO_PROPS) != -1) { audioProps = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_AUDIO_PROPS)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_SUB_PROPS) != -1) { subProps = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_SUB_PROPS)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_SERIES_ID) != -1) { seriesId = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_SERIES_ID)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_PROGRAM_ID) != -1) { programId = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_PROGRAM_ID)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_STARS) != -1) { stars = cursor.getDouble(cursor.getColumnIndex(ProgramConstants.FIELD_STARS)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_FILE_SIZE) != -1) { fileSize = cursor.getLong(cursor.getColumnIndex(ProgramConstants.FIELD_FILE_SIZE)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_LAST_MODIFIED) != -1) { lastModified = new DateTime( cursor.getLong(cursor.getColumnIndex(ProgramConstants.FIELD_LAST_MODIFIED))); } if (cursor.getColumnIndex(ProgramConstants.FIELD_PROGRAM_FLAGS) != -1) { programFlags = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_PROGRAM_FLAGS)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_HOSTNAME) != -1) { hostname = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_HOSTNAME)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_FILENAME) != -1) { filename = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_FILENAME)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_AIR_DATE) != -1) { try { airDate = DateUtils.dateFormatter .parseDateTime(cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_AIR_DATE))); } catch (Exception e) { Log.w(TAG, "AirDate could not be parsed"); } } if (cursor.getColumnIndex(ProgramConstants.FIELD_DESCRIPTION) != -1) { description = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_DESCRIPTION)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_INETREF) != -1) { inetref = cursor.getString(cursor.getColumnIndex(ProgramConstants.FIELD_INETREF)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_SEASON) != -1) { season = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_SEASON)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_EPISODE) != -1) { episode = cursor.getInt(cursor.getColumnIndex(ProgramConstants.FIELD_EPISODE)); } if (cursor.getColumnIndex(ProgramConstants.FIELD_CHANNEL_ID) != -1) { channelInfo = ChannelHelperV27.getInstance().convertCursorToChannelInfo(cursor); } if (cursor.getColumnIndex(RecordingConstants.ContentDetails.getValueFromParent(table).getTableName() + "_" + RecordingConstants.FIELD_RECORD_ID) != -1) { recording = RecordingHelperV27.getInstance().convertCursorToRecording(cursor, table); } Program program = new Program(); program.setStartTime(startTime); program.setEndTime(endTime); program.setTitle(title); program.setSubTitle(subTitle); program.setCategory(category); program.setCatType(categoryType); program.setRepeat(repeat == 1 ? true : false); program.setVideoProps(videoProps); program.setAudioProps(audioProps); program.setSubProps(subProps); program.setSeriesId(seriesId); program.setProgramId(programId); program.setStars(stars); program.setFileSize(fileSize); program.setLastModified(lastModified); program.setProgramFlags(programFlags); program.setHostName(hostname); program.setFileName(filename); program.setAirdate(null != airDate ? airDate.toLocalDate() : null); program.setDescription(description); program.setInetref(inetref); program.setSeason(season); program.setEpisode(episode); program.setChannel(channelInfo); program.setRecording(recording); // Log.v( TAG, "convertCursorToProgram : exit" ); return program; }
From source file:com.android.providers.downloads.DownloadService.java
/** * Update {@link #mDownloads} to match {@link DownloadProvider} state. * Depending on current download state it may enqueue {@link DownloadThread} * instances, request {@link DownloadScanner} scans, update user-visible * notifications, and/or schedule future actions with {@link AlarmManager}. * <p>/*from ww w .j a v a 2s. c om*/ * Should only be called from {@link #mUpdateThread} as after being * requested through {@link #enqueueUpdate()}. * * @return If there are active tasks being processed, as of the database * snapshot taken in this update. */ private boolean updateLocked() { final long now = mSystemFacade.currentTimeMillis(); boolean isActive = false; long nextActionMillis = Long.MAX_VALUE; final Set<Long> staleIds = Sets.newHashSet(mDownloads.keySet()); final ContentResolver resolver = getContentResolver(); Cursor cursor = null; try { cursor = resolver.query(Downloads.Impl.ALL_DOWNLOADS_CONTENT_URI, null, null, null, null); final DownloadInfo.Reader reader = new DownloadInfo.Reader(resolver, cursor); final int idColumn = cursor.getColumnIndexOrThrow(Downloads.Impl._ID); while (cursor.moveToNext()) { final long id = cursor.getLong(idColumn); long currentDownloadNextActionMillis = Long.MAX_VALUE; DownloadInfo info = mDownloads.get(id); if (info != null) { updateDownload(reader, info, now); } else { // Check xunlei engine status when create a new task info = insertDownloadLocked(reader, now); } if (info.mDeleted) { // Delete download if requested, but only after cleaning up if (!TextUtils.isEmpty(info.mMediaProviderUri)) { resolver.delete(Uri.parse(info.mMediaProviderUri), null, null); } // if download has been completed, delete xxx, else delete xxx.midownload if (info.mStatus == Downloads.Impl.STATUS_SUCCESS) { if (info.mFileName != null) { deleteFileIfExists(info.mFileName); } } else { if (info.mFileName != null) { deleteFileIfExists(info.mFileName + Helpers.sDownloadingExtension); } } resolver.delete(info.getAllDownloadsUri(), null, null); } else { staleIds.remove(id); // Kick off download task if ready String pkg = TextUtils.isEmpty(info.mPackage) ? sUnknownPackage : info.mPackage; final boolean activeDownload = info.startDownloadIfReady(MyExecutor.getExecutorInstance(pkg)); // Kick off media scan if completed final boolean activeScan = info.startScanIfReady(mScanner); // get current download task's next action millis currentDownloadNextActionMillis = info.nextActionMillis(now); XLConfig.LOGD("Download " + info.mId + ": activeDownload=" + activeDownload + ", activeScan=" + activeScan); isActive |= activeDownload; isActive |= activeScan; // if equals 0, keep download service on. isActive |= (currentDownloadNextActionMillis == 0); } // Keep track of nearest next action nextActionMillis = Math.min(currentDownloadNextActionMillis, nextActionMillis); } } catch (SQLiteDiskIOException e) { XLConfig.LOGD("error when updateLocked: ", e); } catch (Exception e) { XLConfig.LOGD("error when updateLocked: ", e); } finally { if (cursor != null) { cursor.close(); } } // Clean up stale downloads that disappeared for (Long id : staleIds) { deleteDownloadLocked(id); } // Update notifications visible to user mNotifier.updateWith(mDownloads.values()); // Set alarm when next action is in future. It's okay if the service // continues to run in meantime, since it will kick off an update pass. if (nextActionMillis > 0 && nextActionMillis < Long.MAX_VALUE) { XLConfig.LOGD("scheduling start in " + nextActionMillis + "ms"); final Intent intent = new Intent(Constants.ACTION_RETRY); intent.setClass(this, DownloadReceiver.class); mAlarmManager.set(AlarmManager.RTC_WAKEUP, now + nextActionMillis, PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_ONE_SHOT)); } return isActive; }
From source file:alaindc.memenguage.View.MainActivity.java
private void updateWordsList() { wordsListview = (ListView) findViewById(R.id.wordslistview); adapter = new WordsAdapter(this, crs, 0); adapter.setFilterQueryProvider(new FilterQueryProvider() { public Cursor runQuery(CharSequence constraint) { return dbmanager.getMatchingWords(String.valueOf(constraint)); }//from www.j av a 2 s.c o m }); wordsListview.setAdapter(adapter); wordsListview.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int pos, long id) { Intent createWordIntentActivity = new Intent(MainActivity.this, CreateEditActivity.class); createWordIntentActivity.setAction(Constants.ACTION_EDIT_WORD); Cursor crs = (Cursor) arg0.getItemAtPosition(pos); createWordIntentActivity.putExtra(Constants.EXTRA_EDIT_ITA, crs.getString(crs.getColumnIndex(Constants.FIELD_ITA))); createWordIntentActivity.putExtra(Constants.EXTRA_EDIT_ENG, crs.getString(crs.getColumnIndex(Constants.FIELD_ENG))); createWordIntentActivity.putExtra(Constants.EXTRA_EDIT_ID, id); MainActivity.this.startActivity(createWordIntentActivity); return true; } }); wordsListview.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long id) { crs = (Cursor) arg0.getItemAtPosition(pos); String text = "Memory level: " + crs.getInt(crs.getColumnIndex(Constants.FIELD_RATING)) + "/5"; text = text + "\nLast edit: " + Utils.getDate(crs.getLong(crs.getColumnIndex(Constants.FIELD_TIMESTAMP))); crs = dbmanager.getContextById(id); if (crs != null && crs.getCount() > 0) { crs.moveToFirst(); String cont = crs.getString(crs.getColumnIndex(Constants.FIELD_CONTEXT)); text = text + "\n\n" + ((cont.equals("")) ? "Add a context sentence" : "Context:\n" + cont); } Toast t = Toast.makeText(getApplicationContext(), text, Toast.LENGTH_LONG); t.setGravity(Gravity.TOP, 0, 250); t.show(); } }); //Toast.makeText(getApplicationContext(), adapter.getCount()+" words in Memenguage", Toast.LENGTH_SHORT).show(); }