List of usage examples for android.database Cursor getLong
long getLong(int columnIndex);
From source file:mobisocial.musubi.ui.fragments.FeedViewFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mInputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); mObserver = new ContentObserver(new Handler(mActivity.getMainLooper())) { @Override/*ww w . j a v a2s . co m*/ public void onChange(boolean selfChange) { if (mObjects == null || mObjects.getCursor() == null || !isAdded()) { return; } // XXX Move this to WizardStepHandler-- register a content observer // there only when required. if (WizardStepHandler.isCurrentTask(mActivity, WizardStepHandler.TASK_EDIT_PICTURE)) { Cursor c = mObjects.getCursor(); ObjectManager om = new ObjectManager(App.getDatabaseSource(mActivity)); AppManager am = new AppManager(App.getDatabaseSource(mActivity)); if (c.moveToFirst()) { while (!c.isAfterLast()) { long objId = c.getLong(c.getColumnIndexOrThrow(MObject.COL_ID)); MObject obj = om.getObjectForId(objId); if (obj != null && am.getAppIdentifier(obj.appId_).startsWith("musubi.sketch")) { WizardStepHandler.accomplishTask(mActivity, WizardStepHandler.TASK_EDIT_PICTURE); break; } c.moveToNext(); } } } if (DBG) Log.d(TAG, "-- contentObserver observed change"); getLoaderManager().restartLoader(0, getLoaderArgs(mTotal), FeedViewFragment.this); } }; if (savedInstanceState != null) { mTotal = savedInstanceState.getInt(EXTRA_NUM_ITEMS); Log.d(TAG, "setting total from instance: " + mTotal); } else { Log.d(TAG, "using total " + mTotal); } if (DBG) Log.d(TAG, "-- onCreated"); getLoaderManager().initLoader(0, getLoaderArgs(mTotal), this); }
From source file:com.rjfun.cordova.sms.SMSPlugin.java
private JSONObject getJsonFromCursor(Cursor cur) { JSONObject json = new JSONObject(); int nCol = cur.getColumnCount(); String keys[] = cur.getColumnNames(); try {/*from w ww. j a v a 2s .c om*/ for (int j = 0; j < nCol; j++) { switch (cur.getType(j)) { case Cursor.FIELD_TYPE_NULL: json.put(keys[j], null); break; case Cursor.FIELD_TYPE_INTEGER: json.put(keys[j], cur.getLong(j)); break; case Cursor.FIELD_TYPE_FLOAT: json.put(keys[j], cur.getFloat(j)); break; case Cursor.FIELD_TYPE_STRING: json.put(keys[j], cur.getString(j)); break; case Cursor.FIELD_TYPE_BLOB: json.put(keys[j], cur.getBlob(j)); break; } } } catch (Exception e) { return null; } return json; }
From source file:org.smap.smapTask.android.tasks.DownloadTasksTask.java
private Outcome submitCompletedForms() { String selection = InstanceColumns.SOURCE + "=? and (" + InstanceColumns.STATUS + "=? or " + InstanceColumns.STATUS + "=?)"; String selectionArgs[] = { Utilities.getSource(), InstanceProviderAPI.STATUS_COMPLETE, InstanceProviderAPI.STATUS_SUBMISSION_FAILED }; ArrayList<Long> toUpload = new ArrayList<Long>(); Cursor c = null; try {/* w w w . j av a2 s . c o m*/ c = Collect.getInstance().getContentResolver().query(InstanceColumns.CONTENT_URI, null, selection, selectionArgs, null); if (c != null && c.getCount() > 0) { c.move(-1); while (c.moveToNext()) { Long l = c.getLong(c.getColumnIndex(InstanceColumns._ID)); toUpload.add(Long.valueOf(l)); } } } catch (Exception e) { e.printStackTrace(); } finally { if (c != null) { c.close(); } } InstanceUploaderTask instanceUploaderTask = new InstanceUploaderTask(); publishProgress("Submitting " + toUpload.size() + " finalised surveys"); instanceUploaderTask.setUploaderListener((InstanceUploaderListener) mStateListener); Long[] toSendArray = new Long[toUpload.size()]; toUpload.toArray(toSendArray); Log.i(getClass().getSimpleName(), "Submitting " + toUpload.size() + " finalised surveys"); if (toUpload.size() > 0) { return instanceUploaderTask.doInBackground(toSendArray); // Already running a background task so call direct } else { return null; } }
From source file:com.android.emailcommon.provider.Account.java
@Override public void restore(Cursor cursor) { mId = cursor.getLong(CONTENT_ID_COLUMN); mBaseUri = CONTENT_URI;//from w w w. j a va 2s. c om mDisplayName = cursor.getString(CONTENT_DISPLAY_NAME_COLUMN); mEmailAddress = cursor.getString(CONTENT_EMAIL_ADDRESS_COLUMN); mSyncKey = cursor.getString(CONTENT_SYNC_KEY_COLUMN); mSyncLookback = cursor.getInt(CONTENT_SYNC_LOOKBACK_COLUMN); mSyncInterval = cursor.getInt(CONTENT_SYNC_INTERVAL_COLUMN); mHostAuthKeyRecv = cursor.getLong(CONTENT_HOST_AUTH_KEY_RECV_COLUMN); mHostAuthKeySend = cursor.getLong(CONTENT_HOST_AUTH_KEY_SEND_COLUMN); mFlags = cursor.getInt(CONTENT_FLAGS_COLUMN); mSenderName = cursor.getString(CONTENT_SENDER_NAME_COLUMN); mRingtoneUri = cursor.getString(CONTENT_RINGTONE_URI_COLUMN); mProtocolVersion = cursor.getString(CONTENT_PROTOCOL_VERSION_COLUMN); mSecuritySyncKey = cursor.getString(CONTENT_SECURITY_SYNC_KEY_COLUMN); mSignature = cursor.getString(CONTENT_SIGNATURE_COLUMN); mPolicyKey = cursor.getLong(CONTENT_POLICY_KEY_COLUMN); mPingDuration = cursor.getLong(CONTENT_PING_DURATION_COLUMN); }
From source file:com.sferadev.etic.tasks.DownloadTasksTask.java
private void cleanupTasks(FileDbAdapter fda, String source) throws Exception { Cursor taskListCursor = fda.fetchTasksForSource(source, false); taskListCursor.moveToFirst();//from w ww . j a va 2 s . com while (!taskListCursor.isAfterLast()) { if (isCancelled()) { return; } ; // Return if the user cancels String status = taskListCursor.getString(taskListCursor.getColumnIndex(FileDbAdapter.KEY_T_STATUS)); long id = taskListCursor.getLong(taskListCursor.getColumnIndex(FileDbAdapter.KEY_T_ID)); Log.i("cleanupTasks", "taskid:" + id + " -- status:" + status); if (status.equals(FileDbAdapter.STATUS_T_MISSED) || status.equals(FileDbAdapter.STATUS_T_CANCELLED)) { fda.deleteTask(id); } taskListCursor.moveToNext(); } taskListCursor.close(); }
From source file:io.n7.calendar.caldav.CalDAVService.java
private void doSyncCalendar(Account acc, long calid) throws Exception { // Get a list of local events String[] evproj1 = new String[] { Events._ID, Events._SYNC_ID, Events.DELETED, Events._SYNC_DIRTY }; HashMap<String, Long> localevs = new HashMap<String, Long>(); HashMap<String, Long> removedevs = new HashMap<String, Long>(); HashMap<String, Long> dirtyevs = new HashMap<String, Long>(); HashMap<String, Long> newdevevs = new HashMap<String, Long>(); Cursor c = mCR.query(EVENTS_URI, evproj1, Events.CALENDAR_ID + "=" + calid, null, null); long tid;/* w ww .j a va2s.c om*/ String tuid = null; if (c.moveToFirst()) { do { tid = c.getLong(0); tuid = c.getString(1); if (c.getInt(2) != 0) removedevs.put(tuid, tid); else if (tuid == null) { // generate a UUID tuid = UUID.randomUUID().toString(); newdevevs.put(tuid, tid); } else if (c.getInt(3) != 0) dirtyevs.put(tuid, tid); else localevs.put(tuid, tid); } while (c.moveToNext()); c.close(); } CalDAV4jIf caldavif = new CalDAV4jIf(getAssets()); caldavif.setCredentials(new CaldavCredential(acc.getProtocol(), acc.getHost(), acc.getPort(), acc.getHome(), acc.getCollection(), acc.getUser(), acc.getPassword())); //add new device events to server for (String uid : newdevevs.keySet()) addEventOnServer(uid, newdevevs.get(uid), caldavif); //delete the locally removed events on server for (String uid : removedevs.keySet()) { removeEventOnServer(uid, caldavif); // clean up provider DB? removeLocalEvent(removedevs.get(uid)); } //update the dirty events on server for (String uid : dirtyevs.keySet()) updateEventOnServer(uid, dirtyevs.get(uid), caldavif); // Get events from server VEvent[] evs = caldavif.getEvents(); // add/update to provider DB String[] evproj = new String[] { Events._ID }; ContentValues cv = new ContentValues(); String temp, durstr = null; for (VEvent v : evs) { cv.clear(); durstr = null; String uid = ICalendarUtils.getUIDValue(v); // XXX Some times the server seem to return the deleted event if we do get events immediately // after removing.. // So ignore the possibility of deleted event on server was modified on server, for now. if (removedevs.containsKey(uid)) continue; //TODO: put etag here cv.put(Events._SYNC_ID, uid); //UUID cv.put(Events._SYNC_DATA, uid); cv.put(Events.CALENDAR_ID, calid); cv.put(Events.TITLE, ICalendarUtils.getSummaryValue(v)); cv.put(Events.DESCRIPTION, ICalendarUtils.getPropertyValue(v, Property.DESCRIPTION)); cv.put(Events.EVENT_LOCATION, ICalendarUtils.getPropertyValue(v, Property.LOCATION)); String tzid = ICalendarUtils.getPropertyValue(v, Property.TZID); if (tzid == null) tzid = Time.getCurrentTimezone(); cv.put(Events.EVENT_TIMEZONE, tzid); long dtstart = parseDateTimeToMillis(ICalendarUtils.getPropertyValue(v, Property.DTSTART), tzid); cv.put(Events.DTSTART, dtstart); temp = ICalendarUtils.getPropertyValue(v, Property.DTEND); if (temp != null) cv.put(Events.DTEND, parseDateTimeToMillis(temp, tzid)); else { temp = ICalendarUtils.getPropertyValue(v, Property.DURATION); durstr = temp; if (temp != null) { cv.put(Events.DURATION, durstr); // We still need to calculate and enter DTEND. Otherwise, the Android is not displaying // the event properly Duration dur = new Duration(); dur.parse(temp); cv.put(Events.DTEND, dtstart + dur.getMillis()); } } //TODO add more fields //if the event is already present, update it otherwise insert it // TODO find if something changed on server using etag Uri euri; if (localevs.containsKey(uid) || dirtyevs.containsKey(uid)) { if (localevs.containsKey(uid)) { tid = localevs.get(uid); localevs.remove(uid); } else { tid = dirtyevs.get(uid); dirtyevs.remove(uid); } mCR.update(ContentUris.withAppendedId(EVENTS_URI, tid), cv, null, null); //clear sync dirty flag cv.clear(); cv.put(Events._SYNC_DIRTY, 0); mCR.update(ContentUris.withAppendedId(EVENTS_URI, tid), cv, null, null); Log.d(TAG, "Updated " + uid); } else if (!newdevevs.containsKey(uid)) { euri = mCR.insert(EVENTS_URI, cv); Log.d(TAG, "Inserted " + uid); } } // the remaining events in local and dirty event list are no longer on the server. So remove them. for (String uid : localevs.keySet()) removeLocalEvent(localevs.get(uid)); //XXX Is this possible? /* for (String uid: dirtyevs.keySet ()) removeLocalEvent (dirtyevs[uid]); */ }
From source file:com.dwdesign.tweetings.fragment.AccountsFragment.java
@Override public void onLoadFinished(final Loader<Cursor> loader, final Cursor data) { mCursor = data;/*from w w w . j a va2 s. co m*/ mAdapter.swapCursor(data); final SparseBooleanArray checked = new SparseBooleanArray(); data.moveToFirst(); //if (mSelectedIds.size() == 0) { while (!data.isAfterLast()) { final boolean is_activated = data.getInt(data.getColumnIndexOrThrow(Accounts.IS_ACTIVATED)) == 1; final long user_id = data.getLong(data.getColumnIndexOrThrow(Accounts.USER_ID)); //if (is_activated) { //mSelectedIds.add(user_id); //} //View v = (View) getListView().getItemAtPosition(data.getPosition()); //CheckBox cb = (CheckBox) v.findViewById(R.id.checkbox); //cb.setChecked(is_activated); //mAdapter.setItemChecked(data.getPosition(), is_activated); data.moveToNext(); } /*} else { while (!cursor.isAfterLast()) { final long user_id = cursor.getLong(cursor.getColumnIndexOrThrow(Accounts.ACCOUNT_ID)); if (mSelectedIds.contains(user_id)) { checked.put(cursor.getPosition(), true); mAdapter.setItemChecked(cursor.getPosition(), true); } cursor.moveToNext(); } }*/ }
From source file:com.klinker.android.twitter.utils.NotificationUtils.java
public static void favUsersNotification(int account, Context context) { ArrayList<String[]> tweets = new ArrayList<String[]>(); HomeDataSource data = HomeDataSource.getInstance(context); Cursor cursor = data.getUnreadCursor(account); FavoriteUsersDataSource favs = FavoriteUsersDataSource.getInstance(context); if (cursor.moveToFirst()) { do {//from w w w. jav a 2 s . c om String screenname = cursor.getString(cursor.getColumnIndex(HomeSQLiteHelper.COLUMN_SCREEN_NAME)); if (favs.isFavUser(account, screenname)) { String name = cursor.getString(cursor.getColumnIndex(HomeSQLiteHelper.COLUMN_NAME)); String text = cursor.getString(cursor.getColumnIndex(HomeSQLiteHelper.COLUMN_TEXT)); String time = cursor.getLong(cursor.getColumnIndex(HomeSQLiteHelper.COLUMN_TIME)) + ""; String picUrl = cursor.getString(cursor.getColumnIndex(HomeSQLiteHelper.COLUMN_PIC_URL)); String otherUrl = cursor.getString(cursor.getColumnIndex(HomeSQLiteHelper.COLUMN_URL)); String users = cursor.getString(cursor.getColumnIndex(HomeSQLiteHelper.COLUMN_USERS)); String hashtags = cursor.getString(cursor.getColumnIndex(HomeSQLiteHelper.COLUMN_HASHTAGS)); String id = cursor.getLong(cursor.getColumnIndex(HomeSQLiteHelper.COLUMN_TWEET_ID)) + ""; String profilePic = cursor.getString(cursor.getColumnIndex(HomeSQLiteHelper.COLUMN_PRO_PIC)); String otherUrls = cursor.getString(cursor.getColumnIndex(HomeSQLiteHelper.COLUMN_URL)); String userss = cursor.getString(cursor.getColumnIndex(HomeSQLiteHelper.COLUMN_USERS)); String hashtagss = cursor.getString(cursor.getColumnIndex(HomeSQLiteHelper.COLUMN_HASHTAGS)); String retweeter; try { retweeter = cursor.getString(cursor.getColumnIndex(HomeSQLiteHelper.COLUMN_RETWEETER)); } catch (Exception e) { retweeter = ""; } String link = ""; boolean displayPic = !picUrl.equals("") && !picUrl.contains("youtube"); if (displayPic) { link = picUrl; } else { link = otherUrls.split(" ")[0]; } tweets.add(new String[] { name, text, screenname, time, retweeter, link, displayPic ? "true" : "false", id, profilePic, userss, hashtagss, otherUrls }); } } while (cursor.moveToNext()); } cursor.close(); if (tweets.size() > 0) { if (tweets.size() == 1) { makeFavsNotificationToActivity(tweets, context); } else { AppSettings settings = AppSettings.getInstance(context); makeFavsNotification(tweets, context, settings.liveStreaming || settings.pushNotifications); } } }
From source file:io.n7.calendar.caldav.CalDAVService.java
private long getCalendarId(Account acc) { String[] calproj = { Calendars._ID }; String calacc = acc.getEmail(); Cursor c = mCR.query(Calendars.CONTENT_URI, calproj, Calendars._SYNC_ACCOUNT + "='" + calacc + "' AND " + Calendars._SYNC_ID + "='" + acc.getCollection() + "'", null, null); long calid;// w w w . j a va 2s . com if (c == null || !c.moveToFirst()) { calid = createCalendar(acc); } else { calid = c.getLong(0); } c.close(); return calid; }
From source file:com.groupe1.miage.ujf.tracestaroute.FetchTrackTask.java
/** * Helper method to handle insertion of a new location in the weather database. * * @param cityName A human-readable city name, e.g "Mountain View" * @param lat the latitude of the city/* w ww. ja v a2 s .com*/ * @param lon the longitude of the city * @return the row ID of the added location. */ long addLocation(String cityName, double lat, double lon) { long locationId; // On regarde si la location avec nom de ville, x et y existe dja Cursor locationCursor = mContext.getContentResolver().query(TrackContract.LocationEntry.CONTENT_URI, new String[] { TrackContract.LocationEntry._ID }, TrackContract.LocationEntry.COLUMN_LOC_CITY + " = ? AND " + TrackContract.LocationEntry.COLUMN_LOC_COORD_LAT + " = ? AND " + TrackContract.LocationEntry.COLUMN_LOC_COORD_LONG + " = ?", new String[] { cityName, String.valueOf(lat), String.valueOf(lon) }, null); if (locationCursor.moveToFirst()) { int locationIdIndex = locationCursor.getColumnIndex(TrackContract.LocationEntry._ID); locationId = locationCursor.getLong(locationIdIndex); } else { //Cration du lieu ContentValues locationValues = new ContentValues(); //Ajout des informations locationValues.put(TrackContract.LocationEntry.COLUMN_LOC_CITY, cityName); locationValues.put(TrackContract.LocationEntry.COLUMN_LOC_COORD_LAT, lat); locationValues.put(TrackContract.LocationEntry.COLUMN_LOC_COORD_LONG, lon); //Insertion dans la BD Uri insertedUri = mContext.getContentResolver().insert(TrackContract.LocationEntry.CONTENT_URI, locationValues); locationId = ContentUris.parseId(insertedUri); } locationCursor.close(); return locationId; }