List of usage examples for android.content ContentValues getAsLong
public Long getAsLong(String key)
From source file:com.sonetel.service.SipNotifications.java
public void showNotificationForMissedCall(ContentValues callLog) { int icon = android.R.drawable.stat_notify_missed_call; CharSequence tickerText = context.getText(R.string.missed_call); long when = System.currentTimeMillis(); if (missedCallNotification == null) { missedCallNotification = new NotificationCompat.Builder(context); missedCallNotification.setSmallIcon(icon); missedCallNotification.setTicker(tickerText); missedCallNotification.setWhen(when); missedCallNotification.setOnlyAlertOnce(true); missedCallNotification.setAutoCancel(true); missedCallNotification.setDefaults(Notification.DEFAULT_ALL); }// ww w .j a v a 2s . co m Intent notificationIntent = new Intent(SipManager.ACTION_SIP_CALLLOG); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); String remoteContact = callLog.getAsString(CallLog.Calls.NUMBER); long accId = callLog.getAsLong(SipManager.CALLLOG_PROFILE_ID_FIELD); missedCallNotification.setContentTitle(formatNotificationTitle(R.string.missed_call, accId)); missedCallNotification.setContentText(formatRemoteContactString(remoteContact)); missedCallNotification.setContentIntent(contentIntent); notificationManager.notify(CALLLOG_NOTIF_ID, missedCallNotification.getNotification()); }
From source file:org.kontalk.provider.UsersProvider.java
private Uri insertOrUpdateKey(String jid, String fingerprint, ContentValues values, boolean insertOnly) { SQLiteDatabase db = dbHelper.getWritableDatabase(); if (jid == null || fingerprint == null) throw new IllegalArgumentException("either JID or fingerprint not provided"); int rows = 0; try {/*from w w w.j av a 2 s . c om*/ // try to insert the key with the provided values ContentValues insertValues = new ContentValues(values); insertValues.put(Keys.JID, jid); insertValues.put(Keys.FINGERPRINT, fingerprint); // use current timestamp if the caller didn't provide any long timestamp = values.containsKey(Keys.TIMESTAMP) ? values.getAsLong(Keys.TIMESTAMP) : System.currentTimeMillis(); insertValues.put(Keys.TIMESTAMP, timestamp); db.insertOrThrow(TABLE_KEYS, null, insertValues); rows = 1; } catch (SQLiteConstraintException e) { if (!insertOnly) { // we got a duplicated key, update the requested values rows = db.update(TABLE_KEYS, values, Keys.JID + "=? AND " + Keys.FINGERPRINT + "=?", new String[] { jid, fingerprint }); } } if (rows >= 0) return Keys.CONTENT_URI.buildUpon().appendPath(jid).appendPath(fingerprint).build(); return null; }
From source file:com.partypoker.poker.engagement.reach.EngagementReachAgent.java
/** * Get content by its local identifier.// w w w . j a va 2 s . c om * @param localId the content local identifier. * @return the content if found, null otherwise. */ @SuppressWarnings("unchecked") public <T extends EngagementReachContent> T getContent(long localId) { /* Return content from cache if possible */ EngagementReachContent cachedContent = mContentCache.get(localId); if (cachedContent != null) try { return (T) cachedContent; } catch (ClassCastException cce) { /* Invalid type */ return null; } /* * Otherwise fetch in SQLite: required if the application process has been killed while clicking * on a system notification or while fetching another content than the current one. */ else { /* Fetch from storage */ ContentValues values = mDB.get(localId); if (values != null) try { return (T) parseContentFromStorage(values); } catch (ClassCastException cce) { /* Invalid type */ } catch (Exception e) { /* * Delete content that cannot be parsed, may be corrupted data, we cannot send "dropped" * feedback as we need the Reach contentId and kind. */ deleteContent(localId, values.getAsLong(DOWNLOAD_ID)); } /* Not found, invalid type or an error occurred */ return null; } }
From source file:de.vanita5.twittnuker.provider.TwidereDataProvider.java
@Override public Uri insert(final Uri uri, final ContentValues values) { try {/*from w ww . j a v a 2s . c o m*/ final int tableId = getTableId(uri); final String table = getTableNameById(tableId); switch (tableId) { case TABLE_ID_DIRECT_MESSAGES_CONVERSATION: case TABLE_ID_DIRECT_MESSAGES: case TABLE_ID_DIRECT_MESSAGES_CONVERSATIONS_ENTRIES: return null; } if (table == null) return null; final long rowId; if (tableId == TABLE_ID_CACHED_USERS) { final Expression where = Expression.equals(CachedUsers.USER_ID, values.getAsLong(CachedUsers.USER_ID)); mDatabaseWrapper.update(table, values, where.getSQL(), null); rowId = mDatabaseWrapper.insertWithOnConflict(table, null, values, SQLiteDatabase.CONFLICT_IGNORE); } else if (tableId == TABLE_ID_SEARCH_HISTORY) { values.put(SearchHistory.RECENT_QUERY, System.currentTimeMillis()); final Expression where = Expression.equalsArgs(SearchHistory.QUERY); final String[] args = { values.getAsString(SearchHistory.QUERY) }; mDatabaseWrapper.update(table, values, where.getSQL(), args); rowId = mDatabaseWrapper.insertWithOnConflict(table, null, values, SQLiteDatabase.CONFLICT_IGNORE); } else if (tableId == TABLE_ID_CACHED_RELATIONSHIPS) { final long accountId = values.getAsLong(CachedRelationships.ACCOUNT_ID); final long userId = values.getAsLong(CachedRelationships.USER_ID); final Expression where = Expression.and( Expression.equals(CachedRelationships.ACCOUNT_ID, accountId), Expression.equals(CachedRelationships.USER_ID, userId)); if (mDatabaseWrapper.update(table, values, where.getSQL(), null) > 0) { final String[] projection = { CachedRelationships._ID }; final Cursor c = mDatabaseWrapper.query(table, projection, where.getSQL(), null, null, null, null); if (c.moveToFirst()) { rowId = c.getLong(0); } else { rowId = 0; } c.close(); } else { rowId = mDatabaseWrapper.insertWithOnConflict(table, null, values, SQLiteDatabase.CONFLICT_IGNORE); } } else if (shouldReplaceOnConflict(tableId)) { rowId = mDatabaseWrapper.insertWithOnConflict(table, null, values, SQLiteDatabase.CONFLICT_REPLACE); } else { rowId = mDatabaseWrapper.insert(table, null, values); } onDatabaseUpdated(tableId, uri); onNewItemsInserted(uri, tableId, values, rowId); return Uri.withAppendedPath(uri, String.valueOf(rowId)); } catch (final SQLException e) { throw new IllegalStateException(e); } }
From source file:com.adkdevelopment.earthquakesurvival.data.syncadapter.SyncAdapter.java
/** * Raises a notification with a biggest earthquake with each sync * * @param notifyValues data with the biggest recent earthquake *//* w w w . ja v a 2 s . c o m*/ private void sendNotification(ContentValues notifyValues) { Context context = getContext(); if (Utilities.getNotificationsPrefs(context) && !Utilities.checkForeground(context)) { //checking the last update and notify if it' the first of the day SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); String lastNotificationKey = context.getString(R.string.sharedprefs_key_lastnotification); long lastSync = prefs.getLong(lastNotificationKey, 0); if (System.currentTimeMillis() - lastSync >= DateUtils.DAY_IN_MILLIS) { Intent intent = new Intent(context, DetailActivity.class); double latitude = notifyValues.getAsDouble(EarthquakeColumns.LATITUDE); double longitude = notifyValues.getAsDouble(EarthquakeColumns.LONGITUDE); LatLng latLng = new LatLng(latitude, longitude); String distance = context.getString(R.string.earthquake_distance, LocationUtils.getDistance(latLng, LocationUtils.getLocation(context))); String magnitude = context.getString(R.string.earthquake_magnitude, notifyValues.getAsDouble(EarthquakeColumns.MAG)); String date = Utilities.getRelativeDate(notifyValues.getAsLong(EarthquakeColumns.TIME)); double depth = notifyValues.getAsDouble(EarthquakeColumns.DEPTH); intent.putExtra(Feature.MAGNITUDE, notifyValues.getAsDouble(EarthquakeColumns.MAG)); intent.putExtra(Feature.PLACE, notifyValues.getAsString(EarthquakeColumns.PLACE)); intent.putExtra(Feature.DATE, date); intent.putExtra(Feature.LINK, notifyValues.getAsString(EarthquakeColumns.URL)); intent.putExtra(Feature.LATLNG, latLng); intent.putExtra(Feature.DISTANCE, distance); intent.putExtra(Feature.DEPTH, depth); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(context, EarthquakeObject.NOTIFICATION_ID_1, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(context); Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher); builder.setDefaults(Notification.DEFAULT_ALL).setAutoCancel(true) .setContentTitle(context.getString(R.string.earthquake_statistics_largest)) .setContentText(context.getString(R.string.earthquake_magnitude, notifyValues.get(EarthquakeColumns.MAG))) .setContentIntent(pendingIntent).setSmallIcon(R.drawable.ic_info_black_24dp) .setLargeIcon(largeIcon).setTicker(context.getString(R.string.app_name)) .setStyle(new NotificationCompat.BigTextStyle() .bigText(notifyValues.get(EarthquakeColumns.PLACE).toString() + "\n" + magnitude + "\n" + context.getString(R.string.earthquake_depth, depth) + "\n" + distance + "\n" + date)) .setGroup(EarthquakeObject.NOTIFICATION_GROUP).setGroupSummary(true); NotificationManagerCompat managerCompat = NotificationManagerCompat.from(context); managerCompat.notify(EarthquakeObject.NOTIFICATION_ID_1, builder.build()); //refreshing last sync boolean success = prefs.edit().putLong(lastNotificationKey, System.currentTimeMillis()).commit(); } } }
From source file:org.runnerup.view.DetailActivity.java
void requery() { {//from w w w . j ava 2 s . c o m /** * Laps */ String[] from = new String[] { "_id", DB.LAP.LAP, DB.LAP.INTENSITY, DB.LAP.TIME, DB.LAP.DISTANCE, DB.LAP.PLANNED_TIME, DB.LAP.PLANNED_DISTANCE, DB.LAP.PLANNED_PACE, DB.LAP.AVG_HR }; Cursor c = mDB.query(DB.LAP.TABLE, from, DB.LAP.ACTIVITY + " == " + mID, null, null, null, "_id", null); laps = DBHelper.toArray(c); c.close(); lapHrPresent = false; for (ContentValues v : laps) { if (v.containsKey(DB.LAP.AVG_HR) && v.getAsInteger(DB.LAP.AVG_HR) > 0) { lapHrPresent = true; break; } } } { /** * Accounts/reports */ String sql = new String("SELECT DISTINCT " + " acc._id, " // 0 + (" acc." + DB.ACCOUNT.NAME + ", ") + (" acc." + DB.ACCOUNT.DESCRIPTION + ", ") + (" acc." + DB.ACCOUNT.FLAGS + ", ") + (" acc." + DB.ACCOUNT.AUTH_METHOD + ", ") + (" acc." + DB.ACCOUNT.AUTH_CONFIG + ", ") + (" acc." + DB.ACCOUNT.ENABLED + ", ") + (" rep._id as repid, ") + (" rep." + DB.EXPORT.ACCOUNT + ", ") + (" rep." + DB.EXPORT.ACTIVITY + ", ") + (" rep." + DB.EXPORT.STATUS) + (" FROM " + DB.ACCOUNT.TABLE + " acc ") + (" LEFT OUTER JOIN " + DB.EXPORT.TABLE + " rep ") + (" ON ( acc._id = rep." + DB.EXPORT.ACCOUNT) + (" AND rep." + DB.EXPORT.ACTIVITY + " = " + mID + " )") + (" WHERE acc." + DB.ACCOUNT.ENABLED + " != 0 ") + (" AND acc." + DB.ACCOUNT.AUTH_CONFIG + " is not null")); Cursor c = mDB.rawQuery(sql, null); alreadyUploadedUploaders.clear(); pendingUploaders.clear(); reports.clear(); if (c.moveToFirst()) { do { ContentValues tmp = DBHelper.get(c); Uploader uploader = uploadManager.add(tmp); if (!uploader.checkSupport(Feature.UPLOAD)) { continue; } reports.add(tmp); if (tmp.containsKey("repid")) { alreadyUploadedUploaders.add(tmp.getAsString(DB.ACCOUNT.NAME)); } else if (tmp.containsKey(DB.ACCOUNT.FLAGS) && Bitfield.test(tmp.getAsLong(DB.ACCOUNT.FLAGS), DB.ACCOUNT.FLAG_UPLOAD)) { pendingUploaders.add(tmp.getAsString(DB.ACCOUNT.NAME)); } } while (c.moveToNext()); } c.close(); } if (mode == MODE_DETAILS) { if (pendingUploaders.isEmpty()) { uploadButton.setVisibility(View.GONE); } else { uploadButton.setVisibility(View.VISIBLE); } } for (BaseAdapter a : adapters) { a.notifyDataSetChanged(); } }
From source file:com.partypoker.poker.engagement.reach.EngagementReachAgent.java
/** * Scan reach database and notify the first content that match the current U.I context * @param replaySystemNotifications true iff system notifications must be replayed. */// www . j av a 2 s .c om private void scanContent(boolean replaySystemNotifications) { /* Change state */ mScanning = true; /* For all database rows */ Scanner scanner = mDB.getScanner(); for (ContentValues values : scanner) { /* Parsing may fail */ EngagementReachContent content = null; try { /* Parse content */ content = parseContentFromStorage(values); /* Possibly generate a notification */ notifyContent(content, replaySystemNotifications); } catch (Exception e) { /* * If the content was parsed but an error occurred while notifying, send "dropped" feedback * and delete */ if (content != null) content.dropContent(mContext); /* Otherwise we just delete */ else deleteContent(values.getAsLong(OID), values.getAsLong(DOWNLOAD_ID)); /* In any case we continue parsing */ } } /* Close scanner */ scanner.close(); /* Scan finished */ mScanning = false; }
From source file:org.getlantern.firetweet.provider.FiretweetDataProvider.java
@Override public Uri insert(final Uri uri, final ContentValues values) { try {//from w ww . j av a2 s . c o m final int tableId = getTableId(uri); final String table = getTableNameById(tableId); checkWritePermission(tableId, table); switch (tableId) { case TABLE_ID_DIRECT_MESSAGES_CONVERSATION: case TABLE_ID_DIRECT_MESSAGES: case TABLE_ID_DIRECT_MESSAGES_CONVERSATIONS_ENTRIES: return null; } if (table == null) return null; final long rowId; if (tableId == TABLE_ID_CACHED_USERS) { final Expression where = Expression.equals(CachedUsers.USER_ID, values.getAsLong(CachedUsers.USER_ID)); mDatabaseWrapper.update(table, values, where.getSQL(), null); rowId = mDatabaseWrapper.insertWithOnConflict(table, null, values, SQLiteDatabase.CONFLICT_IGNORE); } else if (tableId == TABLE_ID_SEARCH_HISTORY) { values.put(SearchHistory.RECENT_QUERY, System.currentTimeMillis()); final Expression where = Expression.equalsArgs(SearchHistory.QUERY); final String[] args = { values.getAsString(SearchHistory.QUERY) }; mDatabaseWrapper.update(table, values, where.getSQL(), args); rowId = mDatabaseWrapper.insertWithOnConflict(table, null, values, SQLiteDatabase.CONFLICT_IGNORE); } else if (tableId == TABLE_ID_CACHED_RELATIONSHIPS) { final long accountId = values.getAsLong(CachedRelationships.ACCOUNT_ID); final long userId = values.getAsLong(CachedRelationships.USER_ID); final Expression where = Expression.and( Expression.equals(CachedRelationships.ACCOUNT_ID, accountId), Expression.equals(CachedRelationships.USER_ID, userId)); if (mDatabaseWrapper.update(table, values, where.getSQL(), null) > 0) { final String[] projection = { CachedRelationships._ID }; final Cursor c = mDatabaseWrapper.query(table, projection, where.getSQL(), null, null, null, null); if (c.moveToFirst()) { rowId = c.getLong(0); } else { rowId = 0; } c.close(); } else { rowId = mDatabaseWrapper.insertWithOnConflict(table, null, values, SQLiteDatabase.CONFLICT_IGNORE); } } else if (shouldReplaceOnConflict(tableId)) { rowId = mDatabaseWrapper.insertWithOnConflict(table, null, values, SQLiteDatabase.CONFLICT_REPLACE); } else { rowId = mDatabaseWrapper.insert(table, null, values); } onDatabaseUpdated(tableId, uri); onNewItemsInserted(uri, tableId, values, rowId); return Uri.withAppendedPath(uri, String.valueOf(rowId)); } catch (final SQLException e) { Crashlytics.logException(e); throw new IllegalStateException(e); } }
From source file:net.kourlas.voipms_sms.Database.java
/** * Adds a message to the database. If a record with the message's database ID or VoIP.ms ID already exists, that * record is replaced. Otherwise, a new record is created. * * @param message The message to be added to the database. * @return The database ID of the newly added message. *//* w w w.j a va2 s . c o m*/ public synchronized long insertMessage(Message message) { ContentValues values = new ContentValues(); if (message.getDatabaseId() != null) { values.put(COLUMN_DATABASE_ID, message.getDatabaseId()); } else if (message.getVoipId() != null) { Long databaseId = getDatabaseIdForVoipId(message.getDid(), message.getVoipId()); if (databaseId != null) { values.put(COLUMN_DATABASE_ID, databaseId); } } values.put(COLUMN_VOIP_ID, message.getVoipId()); values.put(COLUMN_DATE, message.getDateInDatabaseFormat()); values.put(COLUMN_TYPE, message.getTypeInDatabaseFormat()); values.put(COLUMN_DID, message.getDid()); values.put(COLUMN_CONTACT, message.getContact()); values.put(COLUMN_MESSAGE, message.getText()); values.put(COLUMN_UNREAD, message.isUnreadInDatabaseFormat()); values.put(COLUMN_DELETED, message.isDeletedInDatabaseFormat()); values.put(COLUMN_DELIVERED, message.isDeliveredInDatabaseFormat()); values.put(COLUMN_DELIVERY_IN_PROGRESS, message.isDeliveryInProgressInDatabaseFormat()); if (values.getAsLong(COLUMN_DATABASE_ID) != null) { return database.replace(TABLE_MESSAGE, null, values); } else { return database.insert(TABLE_MESSAGE, null, values); } }